/
multi.html
101 lines (96 loc) · 2.08 KB
/
multi.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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script src="d3.js"></script>
<script src="lib/sticker.js"></script>
<script src="lib/simple.js"></script>
<style>
#example {
fill: none;
stroke: #00f;
stroke-width: 4px;
}
.pipe {
fill: none;
stroke: #000;
}
.flow {
fill: none;
stroke: #0f0;
}
</style>
</head>
<body>
<div id="content">
<button id="start">start</button>
<button id="pause">pause</button>
<svg id="surface" width=850 height=350>
<path id="example" d="M100 100,L400 100,L400 120,L800 120">
</svg>
</div>
<script>
var duration = 20000;
var w = 10;
var h = 4;
var spacing = 0.1;
var data = [
1, 1, 2, 3, 5, 8, 13
]
var flows = data.map(function(d) {
console.log("d", d);
return d3.flow.simple()
.v(d)
.w(w)
.h(h)
.duration(duration)
.spacing(spacing)
.path("#example")
})
var svg = d3.select("svg#surface")
svg.selectAll("g.flows")
.data(flows)
.enter()
.append("g").classed("flows", true)
.each(function(flow) {
flow(d3.select(this));
})
.attr("transform", function(d, i) {
return "translate(" + [0, i * 30] + ")";
})
//manage state of the flow.
var running = false;
var paused = false;
d3.select("#start").on("click", function() {
flows.forEach(function(flow) {
if(!running) {
flow.start();
} else {
flow.stop();
}
});
if(!running) {
running = true;
d3.select(this).html("stop")
} else {
running = false;
d3.select(this).html("start")
}
})
d3.select("#pause").on("click", function() {
flows.forEach(function(flow) {
if(!paused) {
flow.pause();
} else {
flow.resume();
}
});
if(!paused) {
paused = true;
d3.select(this).html("resume")
} else {
paused = false;
d3.select(this).html("pause")
}
})
</script>
</body>