-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scatterplot.html
394 lines (354 loc) · 14.7 KB
/
Scatterplot.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multiple Slider Color Change</title>
<!-- Load bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v7.js"></script>
<!-- Load noUiSlider -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/14.7.0/nouislider.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/14.7.0/nouislider.min.js"></script>
<style>
/* CSS style to position the scatter plot and range selection */
.app-container {
margin-top: 30px;
}
.scatterplot-container {
padding-top: 20px;
padding-bottom: 25px;
}
.settings-row {
padding: 30px;
}
.svg {
display: block;
margin: auto;
border-style: solid;
border-width: 2px;
}
.legend {
margin-left: 20px;
margin-right: 20px;
}
.legend-element {
display: inline-flex;
align-items: center;
margin-right: 1em;
}
.legend-element::before {
content: "";
width: 10px;
height: 10px;
margin-right: 0.5em;
background: var(--color);
}
/* Round slider handles */
.range-slider {
height: 9px;
}
.range-slider .noUi-handle {
height: 18px;
width: 18px;
top: -5px;
right: -9px;
/* half the width */
border-radius: 9px;
}
/* Hide markers on slider handles */
.range-slider .noUi-handle::before,
.range-slider .noUi-handle::after {
display: none;
}
/* Show tooltips only while sliding */
.range-slider .noUi-tooltip {
display: none;
}
.range-slider .noUi-active .noUi-tooltip {
display: block;
}
</style>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy"
crossorigin="anonymous"></script>
<!-- <script src="js/view.js"></script> -->
<div class="container-fluid">
<div class="row flex-nowrap">
<div class="d-flex flex-column flex-shrink-0 p-3 bg-white" style="width: 280px;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-decoration-none">
<!-- <svg class="bi me-2" width="40" height="32"><use xlink:href="#bootstrap"></use></svg> -->
<span class="fs-4">Menu</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<button class="nav-link btn btn-toggle align-items-center rounded" aria-expanded="true">
<i class="fs-4 bi-clipboard-data"></i> <span
class="ms-1 d-none d-sm-inline text-muted">Datasets</span>
</button>
<div id="settings-collapse" class="collapse show" style="margin-left: 40px;">
<div class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
<div class="row d-flex align-items-center">
<select id="dataset-selection" class="form-select"
aria-label="Default select"></select>
</div>
<!-- <div class="row d-flex align-items-center">
<button class="btn btn-toggle align-items-center rounded" aria-expanded="true">
<i class="fs-4 bi-file-arrow-up"></i> <span
class="ms-1 d-none d-sm-inline text-muted">Upload CSV</span>
</button>
</div> -->
</div>
</div>
</li>
<li class="nav-item">
<button class="nav-link btn btn-toggle align-items-center rounded" data-bs-toggle="collapse"
data-bs-target="#settings-collapse" aria-expanded="true">
<i class="fs-4 bi-wrench"></i> <span
class="ms-1 d-none d-sm-inline text-muted">Settings</span>
</button>
<div id="settings-collapse" class="collapse show" style="margin-left: 40px;">
<div class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
<div class="row d-flex align-items-center">
<div class="col-md-5 my-auto">
Category
</div>
<div class="col">
<select id="category-selection" class="form-select form-select-sm"
aria-label="Default select"></select>
</div>
</div>
<hr>
<div class="row d-flex align-items-center">
<div class="col-md-5 my-auto">
Plot Size
</div>
<div class="col">
<div id="plot-size-slider" class="range-slider"></div>
</div>
</div>
<div class="row d-flex align-items-center">
<div class="col-md-5 my-auto">
Point Size
</div>
<div class="col">
<div id="point-size-slider" class="range-slider"></div>
</div>
</div>
</div>
</div>
</li>
</ul>
<hr>
</div>
<!-- Plots -->
<div class="col app-container">
<div class="row d-inline-flex flex-nowrap" id="container"></div>
<div class="row legend card" id="legend" style="max-width: fit-content;"></div>
</div>
</div>
</div>
<script type="module">
import ScatterplotGrid from "./js/ScatterplotGrid.js";
// SETTINGS
///////////
const PLOT_SIZE = 400;
const POINT_SIZE = 2.5;
// DATASETS
///////////
const DATASETS = [
{
name: "7 Categories",
path: "data/results_seven_categories_learning_rate_250.csv",
mapping: {
x: 'x',
y: 'y',
metricOne: 'Neighborhood_Hit',
metricTwo: 'accuracy',
label: 'Names',
},
categoricalVariables: ["subject"],
defaultCategory: "subject",
metricOneName: "kNN hit",
metricTwoName: "Accuracy"
},
{
name: "Decoding Food",
path: "data/DecodingFood.csv",
mapping: {
x: 'x',
y: 'y',
metricOne: 'Neighborhood_Hit',
metricTwo: 'accuracy',
label: 'Name',
},
categoricalVariables: ["category"],
defaultCategory: "category",
metricOneName: "kNN hit",
metricTwoName: "Accuracy"
},
{
name: "MNIST",
path: "data/results_mnist.csv",
mapping: {
x: 'x',
y: 'y',
metricOne: 'Neighborhood_Hit',
metricTwo: 'accuracy',
label: 'Name',
},
categoricalVariables: ["label"],
defaultCategory: "label",
metricOneName: "kNN hit",
metricTwoName: "Accuracy"
},
{
name: "Kaggle Food Data",
path: "data/FoodData.csv",
mapping: {
x: 'x',
y: 'y',
metricOne: 'kNN_hit',
metricTwo: 'kNN_hit',
label: 'category',
},
categoricalVariables: ["category"],
defaultCategory: "category",
metricOneName: "kNN hit",
metricTwoName: "Accuracy"
},
{
name: "DecodingFood Minimal",
path: "data/DecodingFood_minimal.csv",
mapping: {
x: "x1",
y: "x2",
metricOne: "kNN_hit",
metricTwo: "accuracy",
label: "Name"
},
categoricalVariables: ["Vegetarian", "Organic", "Kosher", "Halal"],
defaultCategory: "Vegetarian",
metricOneName: "kNN hit",
metricTwoName: "Accuracy"
},
// {
// path: "data/DecodingFood-Ingredients.csv",
// mapping: {
// x: 'x',
// y: 'y',
// category: 'category',
// kNN_hit: 'kNN_hit',
// label: 'category',
// },
// categoricalVariables: ["category"],
// defaultCategory: "category"
// }
]
const defaultDataset = DATASETS[0];
// TODO: whats with undefincd acc? just wait for datasets?
// Dataset control
const datasetSelection = d3.select("#dataset-selection")
DATASETS.forEach((d) => {
var option = datasetSelection.append("option").attr("value", d.name).text(d.name);
if (d.name == defaultDataset.name) {
option.attr("selected", true)
}
});
datasetSelection.on("change", (e) => {
const selectedName = e.target.value;
const dataset = DATASETS.filter(d => {
return d.name === selectedName;
})[0];
loadDataset(dataset)
// grid.changeCategory(selectedCategory);
});
// APP
//////
const grid = new ScatterplotGrid(
d3.select("#container"),
d3.select("#legend"),
PLOT_SIZE,
POINT_SIZE,
);
// plot size slider
var slider = document.getElementById("plot-size-slider");
noUiSlider.create(slider, {
start: [400],
step: 50,
range: {
'min': [100],
'max': [500]
},
tooltips: [{ to: function (value) { return '❤️ ' + value + " px"; } }]
});
slider.noUiSlider.on('change', (values) => {
const [plotSize] = values;
grid.changePlotSize(plotSize);
});
// point size slider
var slider = document.getElementById("point-size-slider");
noUiSlider.create(slider, {
start: [POINT_SIZE],
step: 0.5,
range: {
'min': [1],
'max': [5]
},
tooltips: [{ to: function (value) { return '❤️ ' + value; } }]
});
slider.noUiSlider.on('change', (values) => {
const [pointSize] = values;
grid.changePointSize(pointSize);
});
loadDataset(defaultDataset);
function loadDataset(dataset) {
// reset
grid.reset();
// Load default dataset
d3.csv(dataset.path, (d) => {
var mapping = dataset.mapping;
var datapoint = {
x: +d[mapping.x],
y: +d[mapping.y],
category: d[mapping.category],
metricOne: +d[mapping.metricOne],
metricTwo: +d[mapping.metricTwo],
label: d[mapping.label],
}
dataset.categoricalVariables.forEach((c) => {
datapoint[c] = d[c];
});
return datapoint;
}).then(function (data) {
grid.initDataset(data, dataset);
}).then(() => {
// category selection
const categorySelection = d3.select("#category-selection")
categorySelection.html("");
dataset.categoricalVariables.forEach((c) => {
var option = categorySelection.append("option").attr("value", c).text(c);
if (c == dataset.defaultCategory) {
option.attr("selected", true)
}
});
categorySelection.on("change", (e) => {
const selectedCategory = e.target.value;
grid.changeCategory(selectedCategory);
});
});
}
</script>
</body>
</html>