-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimelineHeatmap.html
266 lines (243 loc) · 9.72 KB
/
TimelineHeatmap.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!doctype html>
<html>
<head>
<title>Timeline Heatmap</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,600,300" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,500" rel="stylesheet" type="text/css">
<link href="TimelineHeatmap.css" media="screen" rel="stylesheet" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="TimelineHeatmap.js" type="text/javascript"></script>
<style>
.chart-container {
position: absolute;
left: 0;
right: 0;
top: auto;
height: 75px;
width: auto;
overflow-x: scroll;
background-color: white;
}
#chart-1-update-data-btn {
bottom: 5px;
left: 5px;
position: absolute;
width: 150px;
height: 30px;
cursor: pointer;
}
#chart-container-1 {
bottom: 50px;
}
#chart-container-2 {
bottom: 150px;
}
#chart-container-3 {
bottom: 250px;
}
#chart-container-4 {
bottom: 350px;
}
#chart-container-5 {
bottom: 450px;
}
#chart-container-6 {
bottom: 550px;
}
#chart-container-7 {
bottom: 650px;
}
.noselect {
-webkit-touch-callout: none;
/* iOS Safari */
-webkit-user-select: none;
/* Chrome/Safari/Opera */
-khtml-user-select: none;
/* Konqueror */
-moz-user-select: none;
/* Firefox */
-ms-user-select: none;
/* Internet Explorer/Edge */
user-select: none;
/* Non-prefixed version, currently not supported by any browser */
}
</style>
<script type="text/javascript">
jQuery.support.cors = true;
function init() {
var data1, data2, data3;
var data_flag = 1;
$.when(
$.getJSON("TimelineHeatmapData1.json", function (json) {
data1 = json;
}).fail(function (response) {
console.log("server error when loading data:", response);
}),
$.getJSON("TimelineHeatmapData2.json", function (json) {
data2 = json;
}).fail(function (response) {
console.log("server error when loading data:", response);
}),
$.getJSON("TimelineHeatmapData3.json", function (json) {
data3 = json;
}).fail(function (response) {
console.log("server error when loading data:", response);
})
).then(function () {
// 3D data with gray-scale color
var chart_settings_1 = {
click: function ($e, obj) {
console.log("click", $e.data(), obj);
},
select: function ($e, obj) {
console.log("select", $e.data(), obj);
},
data: data1["data"],
columnNames: data1["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
addLeftArrow: function (obj) {
console.log("Add new data");
var date_str = obj.getFirstBlockData()["custom_field"];
obj.hideLeftArrow();
// Simulate ajax calls
setTimeout(function () {
if (date_str == "03/01/2018") {
obj.prependBlocks(data2["data"]);
} else {
obj.prependBlocks(data1["data"]);
}
obj.selectFirstBlock();
obj.showLeftArrow();
}, 1000);
},
leftArrowLabel: "More"
};
chart_1 = new edaplotjs.TimelineHeatmap("chart-container-1", chart_settings_1);
chart_1.selectFirstBlock();
// Set the button to update chart_1
$("#chart-1-update-data-btn").on("click", function () {
if (data_flag == 1) {
chart_1.updateBlocks(data2["data"]);
chart_1.selectFirstBlock();
data_flag = 2;
} else {
chart_1.updateBlocks(data1["data"]);
chart_1.selectFirstBlock();
data_flag = 1;
}
});
// 3D data with color
var chart_settings_2 = {
data: data1["data"],
columnNames: data1["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
useColorQuantiles: true, // use quantile color scale instead of the default linear one
noColorForSelectedBlock: true,
colorBin: [0, 2, 4, 8, 16],
colorRange: ["#dcdcdc", "#52b947", "#f3ec19", "#f57e20", "#ed1f24", "#991b4f"]
};
chart_2 = new edaplotjs.TimelineHeatmap("chart-container-2", chart_settings_2);
// 3D data with color and height
var chart_settings_3 = {
data: data1["data"],
columnNames: data1["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
dataIndexForHeights: 2, // columnNames[2] is used for the height of the block
useColorQuantiles: true, // use quantile color scale instead of the default linear one
noColorForSelectedBlock: true,
colorBin: [0, 2, 4, 8, 16],
colorRange: ["#dcdcdc", "#52b947", "#f3ec19", "#f57e20", "#ed1f24", "#991b4f"],
heightBin: [10, 40],
heightRange: ["33%", "66%", "100%"]
};
chart_3 = new edaplotjs.TimelineHeatmap("chart-container-3", chart_settings_3);
chart_3.selectLastBlock();
// 2D data with gray-scale color
var chart_settings_4 = {
data: data2["data"],
columnNames: data2["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
addLeftArrow: function (obj) {
console.log("Add new data");
var date_str = obj.getFirstBlockData()["custom_field"];
obj.hideLeftArrow();
// Simulate ajax calls
setTimeout(function () {
if (date_str == "03/01/2018") {
obj.prependBlocks(data2["data"]);
} else {
obj.prependBlocks(data1["data"]);
}
obj.selectFirstBlock();
obj.showLeftArrow();
}, 1000);
}
};
chart_4 = new edaplotjs.TimelineHeatmap("chart-container-4", chart_settings_4);
chart_4.selectFirstBlock();
// 2D data with color
var chart_settings_5 = {
data: data2["data"],
columnNames: data2["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
useColorQuantiles: true, // use quantile color scale instead of the default linear one
noColorForSelectedBlock: true,
colorBin: [0, 2, 4, 8, 16],
colorRange: ["#dcdcdc", "#52b947", "#f3ec19", "#f57e20", "#ed1f24", "#991b4f"]
};
chart_5 = new edaplotjs.TimelineHeatmap("chart-container-5", chart_settings_5);
// 2D data with color and height
var chart_settings_6 = {
data: data2["data"],
columnNames: data2["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
dataIndexForHeights: 2, // columnNames[2] is used for the height of the block
useColorQuantiles: true, // use quantile color scale instead of the default linear one
noColorForSelectedBlock: true,
colorBin: [0, 2, 4, 8, 16],
colorRange: ["#dcdcdc", "#52b947", "#f3ec19", "#f57e20", "#ed1f24", "#991b4f"],
heightBin: [10, 40],
heightRange: ["33%", "66%", "100%"]
};
chart_6 = new edaplotjs.TimelineHeatmap("chart-container-6", chart_settings_6);
chart_6.selectLastBlock();
// 2D data with binned gray-scale color only
var chart_settings_7 = {
data: data3["data"],
columnNames: data3["columnNames"],
dataIndexForLabels: 0, // columnNames[0] is used for the label of the block
dataIndexForColors: 1, // columnNames[1] is used for the color of the block
useColorQuantiles: true, // use quantile color scale instead of the default linear one
noColorForSelectedBlock: true,
colorBin: [0, 2, 4, 8, 16],
colorRange: ["#ffffff", "#52b947", "#f3ec19", "#f57e20", "#ed1f24", "#991b4f"],
noEventWhenColorValueZero: true, // do not add event to a block when its color value is zero
select: function ($e, obj) {
console.log("select", $e.data(), obj);
}
};
chart_7 = new edaplotjs.TimelineHeatmap("chart-container-7", chart_settings_7);
chart_7.selectLastBlock();
});
}
$(init);
</script>
</head>
<body>
<button id="chart-1-update-data-btn">Update Chart Data</button>
<div id="chart-container-1" class="noselect chart-container"></div>
<div id="chart-container-2" class="noselect chart-container"></div>
<div id="chart-container-3" class="noselect chart-container"></div>
<div id="chart-container-4" class="noselect chart-container"></div>
<div id="chart-container-5" class="noselect chart-container"></div>
<div id="chart-container-6" class="noselect chart-container"></div>
<div id="chart-container-7" class="noselect chart-container"></div>
</body>
</html>