-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathindex.html
132 lines (123 loc) · 3.17 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
<style>
.ttooltip {
z-index: 99
}
</style>
<body>
<h1>Welcome to a demo/test page.</h1>
<div id="deepscatter"></div>
<div id="controls" style="z-index:99;position:fixed;">
<input type="range" min=0 max=.5 step=.01 id="jitter" value=.05 />
<button id="flip">Change encoding</button>
<button id="html">Change tooltip HTML</button>
<pre id="ident"></pre>
</div>
</body>
<head>
<style>
dt {
float: left;
clear: left;
width: 90px;
font-weight: bold;
color: rgb(128, 19, 0);
}
dt::after {
content: ":";
}
dd {
margin: 0 0 0 80px;
padding: 0 0 0.5em 0;
width: 180px;
}
</style>
</head>
<script type="module">
import Scatterplot from './src/deepscatter';
import { select } from 'd3-selection';
window.select = select; // For the click function below.
const prefs = {
"source_url" : "/tiles",
"max_points" : 10000, // a full cap.
"alpha" : .9, // Target saturation for the full page.
"zoom_balance" : 0.09, // Rate at which points increase size. https://observablehq.com/@bmschmidt/zoom-strategies-for-huge-scatterplots-with-three-js
"point_size": 2, // Default point size before application of size scaling
"background_color": "#EEEDDE",
"click_function": "select('#ident').html(JSON.stringify(datum, undefined, 2))",
"encoding": {
"color": {
"field": "class",
"range": "category10",
"domain": [-2047, 2047]
},
"x": {
field: "x",
transform: "literal"
},
"jitter_radius": {
method: "uniform",
constant: .01
},
"y": {
field: "y",
transform: "literal"
},
"filter": {
field: "class",
lambda: "d => d !== 'Strawberry'"
},
"size": {
"field": "quantity",
"transform": "sqrt",
"domain": [0, 3],
"range": [0, 4]
}
}
};
const colors = [
// JSON.parse(JSON.stringify(prefs.encoding.color)),
{
"field": "quantity",
"range": "viridis",
"domain": [0, 1]
},
{
"field": "x",
"range": "viridis",
"domain": [-3, 3]
}
]
const scatterplot = new Scatterplot("#deepscatter")
scatterplot.plotAPI(prefs).then(d => scatterplot.plotAPI(prefs));
window.plot = scatterplot; // For debugging
console.log(scatterplot.database)
// Simple animation demonstration.
let cycle = 0;
select("#jitter").on("change", (event) => {
scatterplot.plotAPI({
'encoding': {
'jitter_radius': {
'method': 'uniform',
'constant': +event.target.value
}
}
})
})
let weird = false;
select("#html").on("click", () => {
scatterplot.tooltip_html = (datum) => {
return `This is point number <span style="color:blue">${datum.ix}</span>`;
}
})
select("#flip").on("click", () => {
cycle += 1
const new_coding = {
"encoding": {
"x": {"field": cycle % 2 == 0 ? "x": "y"},
"y": {"field": cycle % 2 == 0 ? "y": "x"},
"color": colors[cycle % colors.length]
}
}
scatterplot.plotAPI(new_coding)
})
</script>