forked from qvvdata/force-radar-scatterplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
165 lines (128 loc) · 4.89 KB
/
index.html
File metadata and controls
165 lines (128 loc) · 4.89 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
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
<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="startLoop">Start 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.
const ForceRadarScatterplotInstance = new ForceRadarScatterplot(document, '#chart-holder', settings);
ForceRadarScatterplotInstance.init()
.fillWithRandomData()
.render();
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('#startLoop').addEventListener('click', () => {
ForceRadarScatterplotInstance.startRandomLoopingAnimation(getDelay());
});
window.document.querySelector('#stopLoop').addEventListener('click', () => {
ForceRadarScatterplotInstance.stopRandomLoopingAnimation();
});
</script>
</body>
</html>