-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsunburst.js
56 lines (48 loc) · 1.45 KB
/
sunburst.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
requirejs(['db', 'transform'], function (db, transform) {
let url = new URL(document.location.href);
let collection = url.searchParams.get('c');
let docname = url.searchParams.get('d');
if (!collection) {
collection = 'sequences_statistic';
}
if (!docname) {
docname = 'resultDocument--2019-01-28T14-38-35UTC';
}
let chart;
let results = [];
nv.addGraph(function () {
chart = nv.models.sunburstChart();
chart.color(['gray']);
chart.groupColorByParent(false);
chart.showLabels(true);
chart.mode('value');
chart.groupColorByParent(true);
chart.labelFormat(function (d) {
if (typeof d.children === 'undefined') {
return ' ' + d.parent.name + " > " + d.name + ' ' + Math.round(100 * d.value) / 100;
}
// TODO: don't use collection name here
if (d.depth === 1 && collection !== 'resistant_sequences_statistic') {
return d.name + ' ' + Math.round(100 * d.value) / 100;
}
return null;
});
chart.labelThreshold(0.05);
chart.tooltip.valueFormatter(function (d) {
return Math.round(100 * d) / 100;
});
d3.select('#chart')
.datum(results)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
// real-time updates
db.collection(collection).doc(docname)
.onSnapshot(function (doc) {
results = transform(doc.data());
d3.select('#chart')
.datum(results)
.call(chart);
});
});