-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
tree.html
58 lines (57 loc) · 1.66 KB
/
tree.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
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/chart.js@3.8.0/dist/chart.js"></script>
<script src="../build/index.umd.js"></script>
</head>
<body>
<div style="width: 75%">
<canvas id="canvas"></canvas>
<select id="mode" value="dendrogram">
<option>dendrogram</option>
<option>tree</option>
</select>
<select id="orientation" value="horizontal">
<option>horizontal</option>
<option>vertical</option>
<option>radial</option>
</select>
</div>
<script>
fetch('./tree.json')
.then((r) => r.json())
.then((nodes) => {
const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
type: 'dendrogram',
data: {
labels: nodes.map((d) => d.name),
datasets: [
{
pointBackgroundColor: 'steelblue',
pointRadius: 5,
// stepped: 'middle',
data: nodes,
},
],
},
options: {
// animation: false,
legend: {
display: false,
},
},
});
document.getElementById('mode').onchange = (evt) => {
chart.getDatasetMeta(0).controller.reLayout({
mode: evt.currentTarget.value,
});
};
document.getElementById('orientation').onchange = (evt) => {
chart.getDatasetMeta(0).controller.reLayout({
orientation: evt.currentTarget.value,
});
};
});
</script>
</body>
</html>