/
demo.html
120 lines (101 loc) · 3.12 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
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
<!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>programmatic example</h2>
<p>Nodes and edges are created via API. See code below.</p>
<p>
The GHOST button set the <code>ghost</code> attribute to few items, it makes them semi transparent. The NORMAL
button reset them.
</p>
<div class="container">
<flow-view id="element"></flow-view>
</div>
<div class="controls">
<button id="ghost">ghost</button>
<button id="normal">normal</button>
</div>
<p>Nodes and edges are created with the following code.</p>
<pre><code>import { FlowView } from 'https://unpkg.com/flow-view';
const flowView = new FlowView({
element: document.getElementById('element')
});
const node1 = flowView.newNode({
text: 'Hello', ins:[{}, {}], outs: [{ id: 'output1' }], x: 100, y: 100
});
const node2 = flowView.newNode({
text: 'World', ins:[{ id: 'input1' }, { id: 'ghost' }], x: 250, y: 400
});
const node3 = flowView.newNode({
text: 'ciao', outs:[{ id: 'saluto' }], x: 400, y: 280
});
const edge1 = flowView.newEdge({
from: [node1.id, 'output1'],
to: [node2.id, 'input1']
});
const edge2 = flowView.newEdge({
from: [node3.id, 'saluto'],
to: [node2.id, 'ghost']
});</code></pre>
</main>
<script type="module">
// import { FlowView } from 'https://unpkg.com/flow-view';
import { FlowView } from "../../index.js"
const flowView = new FlowView(document.getElementById("element"))
const node1 = flowView.newNode({
text: "Hello",
ins: [{}, {}],
outs: [{ id: "output1" }],
x: 100,
y: 100
})
const node2 = flowView.newNode({
text: "World",
ins: [{ id: "input1" }, { id: "ghost" }],
x: 250,
y: 400
})
const node3 = flowView.newNode({
text: "ciao",
outs: [{ id: "saluto" }],
x: 400,
y: 280
})
const edge1 = flowView.newEdge({
from: [node1.id, "output1"],
to: [node2.id, "input1"]
})
const edge2 = flowView.newEdge({
from: [node3.id, "saluto"],
to: [node2.id, "ghost"]
})
flowView.onChange(({ action, data }) => {
console.log(action, data)
})
// Controls
const ghostButton = document.querySelector("button#ghost")
ghostButton.addEventListener("click", () => {
node1.ghost = true
node2.input("ghost").ghost = true
edge2.ghost = true
})
const normalButton = document.querySelector("button#normal")
normalButton.addEventListener("click", () => {
node1.ghost = false
node2.input("ghost").ghost = false
edge2.ghost = false
})
</script>
<footer>
Source code <a href="https://github.com/fibo/flow-view/blob/main/examples/programmatic/demo.html">here</a>.
</footer>
</body>
</html>