-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
161 lines (127 loc) · 5.29 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
<html>
<head>
<script src="https://cdn.anychart.com/releases/8.12.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.12.0/js/anychart-graph.min.js"></script>
<style type="text/css">
html,
body,
#container {
background-color: rgb(17, 18, 24);
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="container"></div>
<script>
anychart.onDocumentReady(function () {
// create a chart from the loaded data
const queryString = window.location.search;
if (window.location.hash) {
const base64Data = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
const data = JSON.parse(atob(base64Data));
console.log(data)
data.nodes.forEach((node, index) => {
if (index === 0) {
data.nodes[index].height = 30
}
data.nodes[index].fill = rainbow(data.nodes.length, "rgb", false)[index];
if (data.nodes[index].nodeState) {
data.nodes[index].nodeState = `${decodeURIComponent(data.nodes[index].name)} \n\n ${JSON.stringify(data.nodes[index].nodeState, null, 2)}`
} else {
data.nodes[index].nodeState = decodeURIComponent(data.nodes[index].name);
}
data.nodes[index].name = decodeURIComponent(data.nodes[index].name);
});
console.log(data)
// create chart
var chart = anychart.graph(data);
var nodes = chart.nodes();
nodes.tooltip().format("{%nodeState}");
nodes.labels().enabled(true);
nodes.labels().format("{%name}");
nodes.labels().fontColor("white");
var router = chart.group("router");
var coordinator = chart.group("coordinator");
var endDevice = chart.group("enddevice");
if (router && router.normal()) {
router.normal().shape("circle");
router.normal().height(23);
router.hovered().height(30);
router.selected().height(30);
}
if (coordinator && coordinator.normal()) {
coordinator.normal().shape("diamond");
}
if (endDevice && endDevice.normal()) {
endDevice.normal().shape("square");
endDevice.normal().height(15);
endDevice.hovered().height(20);
endDevice.selected().height(20);
}
nodes.normal().stroke("white");
nodes.hovered().stroke("white");
nodes.selected().stroke("white");
// set the title
chart.title("Homey Route Map");
chart.background().fill("#2b2b2b");
chart.interactivity().edges(false)
chart.container("container").draw();
} else {
alert('invalid data')
}
});
function rgbToHex (r, g, b) {
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
function rgbToHsl (r, g, b) {
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0; // achromatic
} else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return { "h": h, "s": s, "l": l };
}
const rainbow = function (len, type, pastel) {
var eq1 = 127
var eq2 = 128
if (len == undefined) { len = 24 };
if (type == undefined) { type = "rgb" };
if (pastel == true) { eq1 = 55; eq2 = 200 };
frequency = Math.PI * 2 / len;
var cvparr = [];
for (var i = 0; i < len; ++i) {
red = Math.sin(frequency * i + 2) * eq1 + eq2
green = Math.sin(frequency * i + 0) * eq1 + eq2
blue = Math.sin(frequency * i + 4) * eq1 + eq2
switch (type) {
case "hex":
cvparr.push({ "hex": rgbToHex(Math.round(red), Math.round(green), Math.round(blue)) });
break;
case "rgb":
cvparr.push(`rgb(${red},${green},${blue})`);
break;
case "hsl":
cvparr.push(rgbToHsl(Math.round(red), Math.round(green), Math.round(blue)));
break;
}
}
return cvparr;
}
</script>
</body>
</html>