/
demo.html
80 lines (66 loc) · 2.49 KB
/
demo.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="data:;base64,=" />
<meta name="viewport" content="width=device-width" />
<title>flow-view example</title>
<link rel="stylesheet" href="../../style.css" />
</head>
<body>
<main>
<h1>flow-view</h1>
<h2>color schemes example</h2>
<p>
The TOGGLE ERROR button switchs the <code>hasError</code> attribute of all items, which highlights them with
error color.
</p>
<div style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 1em">
<div class="container--small" style="flex-grow: 1">
<flow-view light id="element-1"></flow-view>
</div>
<div class="container--small" style="flex-grow: 1">
<flow-view dark id="element-2"></flow-view>
</div>
</div>
<div class="controls">
<button id="toggle-error">Toggle Error</button>
</div>
</main>
<script type="module">
// import { FlowView } from 'https://unpkg.com/flow-view';
import { FlowView } from "../../index.js"
const flowViewLight = new FlowView(document.getElementById("element-1"))
const flowViewDark = new FlowView(document.getElementById("element-2"))
flowViewLight.loadGraph({
nodes: [
{ id: "a", text: "light", x: 100, y: 80, outs: [{ id: "o" }] },
{ id: "b", text: "scheme", x: 150, y: 170, ins: [{ id: "i" }] }
],
edges: [{ id: "e", from: ["a", "o"], to: ["b", "i"] }]
})
flowViewDark.loadGraph({
nodes: [
{ id: "a", text: "dark", x: 170, y: 80, outs: [{ id: "o" }] },
{ id: "b", text: "scheme", x: 120, y: 170, ins: [{ id: "i" }] }
],
edges: [{ id: "e", from: ["a", "o"], to: ["b", "i"] }]
})
// Controls
const toggleErrorButton = document.querySelector("button#toggle-error")
let hasError = false
toggleErrorButton.addEventListener("click", () => {
hasError = !hasError
flowViewLight.node("a").hasError = hasError
flowViewLight.node("b").hasError = hasError
flowViewLight.edge("e").hasError = hasError
flowViewDark.node("a").hasError = hasError
flowViewDark.node("b").hasError = hasError
flowViewDark.edge("e").hasError = hasError
})
</script>
<footer>
Source code <a href="https://github.com/fibo/flow-view/blob/main/examples/color-schemes/demo.html">here</a>.
</footer>
</body>
</html>