-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathplots.js
429 lines (414 loc) · 13.5 KB
/
plots.js
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
$(document).ready(function() {
loadJSON(function(response) {
var config = JSON.parse(response);
dataversesToMonth(config);
dataversesByCategory(config);
datasetsToMonth(config);
datasetsBySubject(config);
filesToMonth(config);
downloadsToMonth(config);
populateInstallations(config);
versions(config);
versionsBar(config);
},
"config.json");
});
function dataversesToMonth(config) {
var color = config["colors"]["dataverses/toMonth"];
var month_filter_enabled = config["month_filter_enabled"];
d3.tsv("dataverses-toMonth.tsv", function(error, data) {
if (error) return console.error(error);
if (month_filter_enabled) {
data = data.filter(function(d) {
return parseInt(d.month.split('-')[1]) % 2 == 0;
})
}
coerceToNumeric(data);
var yLabel = "Number of Dataverses";
var visualization = d3plus.viz()
.data(data)
.title("Total Dataverses")
.container("#dataverses-to-month")
.type("bar")
.id("month")
.x({
"value": "month",
"label": "Month"
})
.y({
//"range": yAxisTruncation(data, 500),
"range": [0, data[data.length - 1].count * 1.3],
"value": "count",
"label": yLabel
})
.color(function(d) {
return color;
})
.format({
"text": function(text, params) {
if (text === "count") {
return yLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.resize(true)
.draw();
});
}
function dataversesByCategory(config) {
var colors = config["colors"]["dataverses/byCategory"];
d3.tsv("dataverses-byCategory.tsv", function(error, data) {
if (error) return console.error(error);
var tileLabel = "Number of Dataverses";
coerceToNumeric(data);
var visualization = d3plus.viz()
.data(data)
.title("Dataverses by Category")
.title({
"total": true
})
.container("#dataverses-by-category")
.type("tree_map")
.id("name")
.size("count")
.color({
value: "count",
heatmap: colors.reverse()
})
.format({
"text": function(text, params) {
if (text === "count") {
return tileLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.legend(false)
.resize(true)
.draw();
});
}
function datasetsToMonth(config) {
var color = config["colors"]["datasets/toMonth"];
var month_filter_enabled = config["month_filter_enabled"];
d3.tsv("datasets-toMonth.tsv", function(error, data) {
if (error) return console.error(error);
if (month_filter_enabled) {
data = data.filter(function(d) {
return parseInt(d.month.split('-')[1]) % 2 == 0;
})
}
coerceToNumeric(data);
var yLabel = "Number of Datasets";
var visualization = d3plus.viz()
.data(data)
.title("Total Datasets")
.title({
"sub": "Due to an aggregation issue, current count does not include ~82,000 datasets from https://data.inrae.fr"
})
.container("#datasets-to-month")
.type("bar")
.id("month")
.x({
"value": "month",
"label": "Month"
})
.y({
//"range": yAxisTruncation(data, 10000),
"range": [0, data[data.length - 1].count * 1.3],
"value": "count",
"label": yLabel
})
.color(function(d) {
return color;
})
.format({
"text": function(text, params) {
if (text === "count") {
return yLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.resize(true)
.draw();
});
}
function datasetsBySubject(config) {
var subjectBlacklist = config["blacklists"]["datasets/bySubject"];
var colors = config["colors"]["datasets/bySubject"];
d3.tsv("datasets-bySubject.tsv", function(error, data) {
if (error) return console.error(error);
var tileLabel = "Number of Datasets";
coerceToNumeric(data);
var visualization = d3plus.viz()
.data(data)
.title("Datasets by Most Common Subject")
.title({
"total": true
})
.container("#datasets-by-subject")
.type("tree_map")
.id("name")
.id({
"mute": subjectBlacklist
})
.size("count")
.color({
value: "count",
heatmap: colors.reverse()
})
.format({
"text": function(text, params) {
if (text === "count") {
return tileLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.legend(false)
.resize(true)
.draw();
});
}
function filesToMonth(config) {
var color = config["colors"]["files/toMonth"];
var month_filter_enabled = config["month_filter_enabled"];
d3.tsv("files-toMonth.tsv", function(error, data) {
if (error) return console.error(error);
if (month_filter_enabled) {
data = data.filter(function(d) {
return parseInt(d.month.split('-')[1]) % 2 == 0;
})
}
coerceToNumeric(data);
var yLabel = "Number of Files";
var visualization = d3plus.viz()
.data(data)
.title("Total Files")
.container("#files-to-month")
.type("bar")
.id("month")
.x({
"value": "month",
"label": "Month"
})
.y({
//"range": yAxisTruncation(data, 20000),
"range": [0, data[data.length - 1].count * 1.3],
"value": "count",
"label": yLabel
})
.color(function(d) {
return color;
})
.format({
"text": function(text, params) {
if (text === "count") {
return yLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.resize(true)
.draw();
});
}
function downloadsToMonth(config) {
var color = config["colors"]["downloads/toMonth"];
var month_filter_enabled = config["month_filter_enabled"];
d3.tsv("downloads-toMonth.tsv", function(error, data) {
if (error) return console.error(error);
if (month_filter_enabled) {
data = data.filter(function(d) {
return parseInt(d.month.split('-')[1]) % 2 == 0;
})
}
coerceToNumeric(data);
var yLabel = "Number of File Downloads";
var visualization = d3plus.viz()
.data(data)
.title("Total File Downloads")
.container("#downloads-to-month")
.type("bar")
.id("month")
.x({
"value": "month",
"label": "Month"
})
.y({
//"range": yAxisTruncation(data, 1000000),
"range": [0, data[data.length - 1].count * 1.3],
"value": "count",
"label": yLabel
})
.color(function(d) {
return color;
})
.format({
"text": function(text, params) {
if (text === "count") {
return yLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.resize(true)
.draw();
});
}
function versions(config) {
var colors = config["colors"]["versions"];
d3.tsv("version.tsv", function(error, data) {
if (error) return console.error(error);
var tileLabel = "Number of Instances";
coerceToNumeric(data);
var visualization = d3plus.viz()
.data(data)
.title("Instances by Version")
.title({
"total": true
})
.container("#versions")
.type("tree_map")
.id("name")
.size("count")
.color({
value: "count",
heatmap: colors.reverse()
})
.format({
"text": function(text, params) {
if (text === "count") {
return tileLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.legend(false)
.resize(true)
.draw();
});
}
function versionsBar(config) {
var color = config["colors"]["versionsBar"];
d3.tsv("version.tsv", function(error, data) {
if (error) return console.error(error);
var yLabel = "Number of Instances";
coerceToNumeric(data);
var visualization = d3plus.viz()
.data(data)
.title("Instances by Version")
.container("#versionsBar")
.type("bar")
.id("name")
.x({
"value": "name",
"label": "Version"
})
.order(function(d) {
var ind=d.name.indexOf("-");
var name=d.name;
if(ind>0) {
// name = d.name.substring(0,ind);
}
if(d.name.startsWith("V")) {
name = name.substring(1);
}
return 16-["4.6", "4.6.1", "4.8.5", "4.9.2", "4.9.4", "4.10.1","4.13", "4.14", "4.15.1", "4.16","4.17", "4.18.1", "4.19", "4.19.3", "4.20", "5.0"].indexOf(name);
})
.y({
"range": yAxisTruncation(data, 10),
//"range": [0, data[data.length - 1].count * 1.3],
"value": "count",
"label": yLabel
})
.color(function(d) {
return color;
})
.format({
"text": function(text, params) {
if (text === "count") {
return yLabel;
} else {
return d3plus.string.title(text, params);
}
}
})
.resize(true)
.draw();
});
}
function coerceToNumeric(data) {
data.forEach(function(d) {
d3.keys(d).forEach(function(k) {
if (k == "count") {
d[k] = +d[k];
}
});
});
return data;
}
function yAxisTruncation(metricArray, modNum) {
var min = metricArray[0].count;
var max = metricArray[metricArray.length - 1].count;
if (min < modNum) {
return [0, max + 10];
}
var rangeStart = min - (min % modNum);
var rangeEnd = max - (max % modNum) + modNum;
return [rangeStart, rangeEnd];
}
function populateInstallations(config) {
loadJSON(function(response) {
var allInstallations = JSON.parse(response);
if (config.installations.length === 1) {
document.getElementById("discrepancies").hidden = true;
}
document.getElementById("installations").innerHTML = createListOfInstallations(config, allInstallations);
},
"all-dataverse-installations.json");
}
function createListOfInstallations(config, allInstallations) {
var all = allInstallations.installations;
var polled = config.installations;
var polledHostnames = [];
for (var i = 0; i < polled.length; ++i) {
var url = new URL(polled[i]);
var hostname = url.hostname;
polledHostnames.push(hostname);
}
var list = "<ul>";
for (var i = 0; i < all.length; ++i) {
var hostname = all[i].hostname;
var name = all[i].name;
if (polledHostnames.includes(hostname)) {
list += "<li>";
list += "<a href=\"http://" + hostname + "\" target=\"_blank\">" + name + "</a>";
list += "</li>";
}
}
list += "</ul>";
return list;
}
// https://codepen.io/KryptoniteDove/post/load-json-file-locally-using-pure-javascript
function loadJSON(callback, jsonFile) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', jsonFile, true);
xobj.onreadystatechange = function() {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}