-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
206 lines (158 loc) · 6.28 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Force Radar Scatterplot example</title>
<link rel="stylesheet" href="./example/css/example-app.css"/>
</head>
<body>
<div id="controls">
<button id="toggleFloatingLabels">Toggle Floating Labels</button>
<button id="reinit">Re-init</button>
<button id="startRandomLoop">Start Random Loop animation</button>
<button id="startRandomCenterLoop">Start Random Center Loop animation</button>
<button id="stopLoop">Stop loop animation</button>
<button id="movePointsRandomly">Move points randomly</button>
<button id="movePointsToRandomTarget">Move all points</button>
<button id="moveSomePoints">Move some points</button>
<button id="movePointsToCenter">Move points to center</button>
<button id="updateState">updateState</button>
<button id="toggleActivity">toggleActivity</button>
<button id="changeColours">Change colours</button>
<div id="delay-holder">
<span>Delay (ms)</span>
<input id="delay" value="0"/>
</div>
</div>
<div id="chart-holder"></div>
<script type="module">
import './dist/ForceRadarScatterplot.js';
const settings = {
tooltip: {
show: true,
formatter: function a(point) {
// <h3>${d.name}</h3>
// <p>Kabinette: ${d.kabinette}</p>
// <p>Wechsel: ${d.wechsel_pretty} – ${d.beschreibung}</p>
// ${d['Partei des Kabinetts'] != 'uneindeutig'?`<p>Arbeitete nur in Kabinetten der ${d['Partei des Kabinetts']}</p>`:``}
const text = `
<h6>${point.id}</h6>
<p>Kabinnete: ${point.id}</p>
<p>Wechsel: ${point.id} – ${point.id}</p>
`;
return text;
}
}
};
// Create instance.
let ForceRadarScatterplotInstance = new ForceRadarScatterplot(document, '#chart-holder', settings);
ForceRadarScatterplotInstance.init()
.fillWithRandomData()
.render();
console.log(ForceRadarScatterplotInstance);
function getDelay() {
return parseInt(document.getElementById('delay').value, 10);
}
window.document.querySelector('#movePointsRandomly').addEventListener('click', () => {
ForceRadarScatterplotInstance.movePointsRandomly(getDelay());
});
window.document.querySelector('#movePointsToRandomTarget').addEventListener('click', () => {
ForceRadarScatterplotInstance.movePointsToRandomTarget(getDelay());
});
window.document.querySelector('#moveSomePoints').addEventListener('click', () => {
const newStates = [];
const min = 15;
const max = 35;
const limit = min + Math.floor(Math.random() * max);
let count = 0;
const target = ForceRadarScatterplotInstance.getRandomTarget();
ForceRadarScatterplotInstance.points.forEach(point => {
if (count < limit && point.target.getId() === 'FRC_CENTER_TARGET') {
newStates.push({
id: point.getId(),
target: target.getId()
});
count++;
}
});
ForceRadarScatterplotInstance.updatePoints(newStates, 2);
});
window.document.querySelector('#movePointsToCenter').addEventListener('click', () => {
// ForceRadarScatterplotInstance.movePointsToCenter(point => {
// if (point.getId() === 'point-0' || point.getId() === 'point-1') return true;
// }, getDelay());
ForceRadarScatterplotInstance.movePointsToCenter(null, getDelay());
});
window.document.querySelector('#changeColours').addEventListener('click', () => {
const colors = [
'#F00',
'#0F0',
'#FF0',
'#00F',
'#0FF',
'#3FC',
'#F90'
];
const color = colors[Math.floor(Math.random() * colors.length - 1)];
ForceRadarScatterplotInstance.setColorToAllPoints(color);
// Set one point to be different.
ForceRadarScatterplotInstance.setColorToPoint('point-0', '#F0F');
});
window.document.querySelector('#updateState').addEventListener('click', () => {
const newStates = [];
ForceRadarScatterplotInstance.points.forEach(point => {
newStates.push({
id: point.getId(),
isActive: !point.isActive,
target: ForceRadarScatterplotInstance.getRandomTarget()
});
});
// Set one point to be different.
ForceRadarScatterplotInstance.updatePoints(newStates, 2, 0.12);
});
window.document.querySelector('#toggleActivity').addEventListener('click', () => {
const newStates = [];
ForceRadarScatterplotInstance.points.forEach(point => {
newStates.push({
id: point.getId(),
isActive: !point.isActive
});
});
// Set one point to be different.
ForceRadarScatterplotInstance.updatePoints(newStates, 2, false);
});
window.document.querySelector('#startRandomLoop').addEventListener('click', () => {
ForceRadarScatterplotInstance.startRandomLoopingAnimation(getDelay());
});
window.document.querySelector('#startRandomCenterLoop').addEventListener('click', () => {
ForceRadarScatterplotInstance.startRandomCenterLoopAnimation(getDelay());
});
window.document.querySelector('#stopLoop').addEventListener('click', () => {
ForceRadarScatterplotInstance.stopRandomLoopingAnimation();
});
window.document.querySelector('#reinit').addEventListener('click', () => {
ForceRadarScatterplotInstance = null;
ForceRadarScatterplotInstance = new ForceRadarScatterplot(document, '#chart-holder', settings);
// ForceRadarScatterplotInstance = ForceRadarScatterplotInstance2;
ForceRadarScatterplotInstance.init()
.fillWithRandomData(
2 + Math.floor(Math.random() * 10),
1 + Math.floor(Math.random() * 7))
.render();
});
window.document.querySelector('#toggleFloatingLabels').addEventListener('click', () => {
const newTargetStates = [];
ForceRadarScatterplotInstance.targets.forEach(target => {
newTargetStates.push({
id: target.settings.id,
showFloatingLabel: !target.settings.showFloatingLabel,
floatingLabelText: Math.round(Math.random() * 100) + '%'
});
});
ForceRadarScatterplotInstance.setState({
targets: newTargetStates
});
});
</script>
</body>
</html>