Repository navigation
Expand file tree
/
Copy pathlight.html
More file actions
60 lines (56 loc) · 2.06 KB
/
Copy pathlight.html
File metadata and controls
60 lines (56 loc) · 2.06 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>VivaGraph: light and dark</title>
<link rel="icon" href="data:,">
<style>
#switch {position: fixed; left: 12px; top: 12px; font: 13px system-ui, sans-serif; padding: 5px 10px; border-radius: 6px; border: 1px solid; background: none; color: inherit; cursor: pointer}
</style>
</head>
<body>
<button id="switch"></button>
<script src="../dist/vivagraph.min.js"></script>
<script>
// Five trees that grow from one root, a color for each
const branches = ['Oak', 'Pine', 'Birch', 'Maple', 'Willow'];
const graph = Viva.createGraph();
const random = seededRandom(3);
graph.addNode('Root');
branches.forEach(branch => {
const grown = [branch];
graph.addNode(branch, {branch});
graph.addLink('Root', branch);
for (let i = 1; i < 60; i++) {
const id = `${branch} ${i}`;
graph.addNode(id, {branch});
// New twigs prefer the newer end of the tree, so branches grow long
graph.addLink(grown[Math.max(0, grown.length - 1 - Math.floor(random() * random() * grown.length))], id);
grown.push(id);
}
});
// The background is the whole setting: on a light one links, names, rings, the tooltip and
// the search box (press /) are dark on light.
const BACKGROUND = {light: '#ffffff', dark: '#0e1624'};
let now = 'light';
const viva = Viva.render(graph, {background: BACKGROUND[now], style: {colorBy: 'branch'}});
const button = document.getElementById('switch');
button.onclick = () => {
now = now === 'light' ? 'dark' : 'light';
viva.setBackground(BACKGROUND[now]);
paint();
};
paint();
// The page's own parts
function paint() {
document.documentElement.style.background = BACKGROUND[now];
document.body.style.color = now === 'light' ? '#1b2433' : '#e6ebf2';
button.textContent = now === 'light' ? 'Dark' : 'Light';
}
function seededRandom(seed) {
return () => { seed = (seed * 1664525 + 1013904223) >>> 0; return seed / 4294967296; };
}
</script>
</body>
</html>