-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
228 lines (212 loc) · 8.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>D3 TreeHeatmap</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div id="controls">
<div class="depth">
<span>Depth Levels:</span>
<select onchange="depth_changed(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="4">4</option>
</select>
</div>
<div class="values">
<span>Values:</span>
<select onchange="values_changed(this)">
<option value="0" selected>Revenues</option>
<option value="1">Cost</option>
</select>
</div>
<div class="units">
<span>Unit:</span>
<select onchange="unit_changed(this)">
<option value="NONE">None</option>
<option value="CURRENCY" selected>USD</option>
<option value="PERCENT">%</option>
</select>
</div>
</div>
<div id="chart"></div>
<script src="vendor/jquery-1.7.2.min.js"></script>
<script src="vendor/d3.min.js"></script>
<script src="vendor/underscore-min.js"></script>
<script src="js/heatmap.js"></script>
<script>
var data, options, heatmap;
data = {
label_short:'Acme',
label_long:'Acme',
children:[
{
label_short:'NA',
label_long:'North America',
children:[
{
label_short:'US',
label_long:'United States',
children:[
{
label_short:'NY',
label_long:'New York',
values:[200, 45],
},
{
label_short:'SF',
label_long:'San Francisco',
values:[300, 12],
},
{
label_short:'OTH',
label_long:'Other',
values:[100, 79],
}
]
},
{
label_short:'CA',
label_long:'Canada',
children:[
{
label_short:'MO',
label_long:'Montreal',
values:[60, 32],
},
{
label_short:'VA',
label_long:'Vancouver',
values:[20, 33],
},
{
label_short:'OTH',
label_long:'Other',
values:[40, 19],
}
]
},
{
label_short:'MEX',
label_long:'Mexico',
children:[
{
label_short:'MC',
label_long:'Mexico City',
values:[60, 90],
},
{
label_short:'OTH',
label_long:'Other',
values:[20, 28],
}
]
}
]
},
{
label_short:'EU',
label_long:'Europe',
children:[
{
label_short:'FRA',
label_long:'France',
children:[
{
label_short:'PA',
label_long:'Paris',
values:[80, 14],
},
{
label_short:'MA',
label_long:'Marseille',
values:[10, 61],
},
{
label_short:'LY',
label_long:'Lyon',
values:[8, 63],
},
{
label_short:'OTH',
label_long:'Other',
values:[22, 45],
}
]
},
{
label_short:'GER',
label_long:'Germany',
children:[
{
label_short:'BE',
label_long:'Berlin',
values:[100, 81],
},
{
label_short:'MU',
label_long:'Munich',
values:[30, 30],
},
{
label_short:'OTH',
label_long:'Other',
values:[50, 11],
}
]
}
]
}
]
};
function build_parent_links(node, parent) {
node.parent = parent;
if (node.children !== undefined)
_.each(node.children, function(child){ build_parent_links(child, node); });
}
function aggregate_values(node) {
if (node.values === undefined) {
node.values = [0,0];
_.each(node.children, function(child){
_.each(aggregate_values(child), function(value, index) { node.values[index] += value; });
});
}
return node.values;
}
build_parent_links(data, null);
aggregate_values(data);
options = {
title: 'Company Results',
unit: 'CURRENCY',
depth: 3,
max_cell_width: 500,
click_handler: click_handler,
};
heatmap = createTreeHeatmap( $('#chart').get(0), data, options );
function unit_changed(e) {
var unitValue = e.options[e.selectedIndex].value;
heatmap.change_unit(unitValue);
}
function depth_changed(e) {
var depthValue = parseInt(e.options[e.selectedIndex].value);
heatmap.change_depth(depthValue);
}
function values_changed(e) {
var value = parseInt(e.options[e.selectedIndex].value);
heatmap.change_value_index(value);
}
function click_handler(is_drill_down, root_node, hit_node) {
if (is_drill_down)
heatmap.change_root_node(hit_node);
else
heatmap.change_root_node(root_node.parent);
}
</script>
</body>
</html>