-
Notifications
You must be signed in to change notification settings - Fork 61
/
vietnam2.html
240 lines (219 loc) · 5.32 KB
/
vietnam2.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
<head>
<style>
.ttooltip {
z-index: 99;
min-width: 500px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
dl {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
dt {
font-weight: bold;
color: rgb(128, 19, 0);
}
dt::after {
content: ':';
}
dd {
margin: 0 0 0 10px;
padding: 0 0 0.5em 0;
width: 180px;
}
#date {
width: 100%;
}
</style>
</head>
<body>
<h1>Vietnam</h1>
<div id="datestring"></div>
<input id="date" title="date selector" type="range" min="-1800" max="1500" />
<div id="deepscatter">
<div>
<div id="left-overlay" class="overlay"></div>
<div id="color-legend" class="overlay"></div>
</div>
</div>
</body>
<script type="module" lang="ts">
import {Scatterplot} from './src/deepscatter';
import { select } from 'd3-selection';
window.select = select; // For the click function below.
const prefs = {
source_url: 'https://bmschmidt.github.io/vietnam_war/',
max_points: 1000,
alpha: 10.12, // Target saturation for the full page.
zoom_balance: 0.12, // 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: '#112233',
click_function:
"select('#ident').html(JSON.stringify(datum, undefined, 2))",
zoom: {
bbox: {
x: [99.15172120932304, 114.17888963818825],
y: [7.0849741134400706, 23.626158008070647],
},
},
encoding: {
jitter_radius: {
constant: 0.001,
method: 'normal',
},
color: {
field: 'MILSERVICE',
domain: ['VNAF', 'USAF', 'USN', 'USMC', 'RLAF', 'RAAF', 'KAF', 'USA'],
range: [
'steelblue',
'green',
'navy',
'green',
'orange',
'gray',
'blue',
'red',
],
// range: 'okabe',
// domain: [-2047, 2047],
},
x: {
field: 'x',
transform: 'literal',
},
y: {
field: 'y',
transform: 'literal',
},
},
};
const scatterplot = new Scatterplot('#deepscatter');
const first_draw = scatterplot.plotAPI(prefs);
window.plot = scatterplot; // For debugging
first_draw.then(async (d) => {
await scatterplot.add_labels_from_url(
'/tests/TAKEOFFLOCATION.geojson',
'takeoff',
'TAKEOFFLOCATION',
undefined, // no size field
{ draggable_labels: true, useColorScale: true }
);
});
// Simple animation demonstration.
let cycle = 0;
const width = 600;
function redo_scale() {
const scale = scatterplot._renderer.aes.store.color.current.scale;
const domain = scale.domain();
const range = scale.range();
select('#color-legend')
.selectAll('div')
.data(domain.slice(0, 15))
.join('div')
.attr('class', 'legend-div')
.text((d) => d)
.style('background-color', (d) => scale(d));
}
first_draw.then(() => {
const holder = select('#left-overlay');
const buttons = holder
.selectAll('button')
.data([
'MILSERVICE',
'PERIODOFDAY',
'UNIT',
'GEOZONE',
'AIRFORCEGROUP',
'TGTTYPE',
'MFUNC_DESC',
'TAKEOFFLOCATION',
]);
redo_scale();
buttons
.enter()
.append('div')
.style('display', 'flex')
.style('flex', 'row')
.append('button')
.text((d) => d)
.on('click', function (d) {
const button = select(this);
const field = button.text();
scatterplot
.plotAPI({
duration: 0.5,
labels: {
url: `/tests/${field}.geojson`,
name: undefined,
label_field: field,
size_field: undefined,
},
encoding: {
color: {
field: field,
range: 'okabe',
domain: [-2047, 2047],
},
},
})
.then(redo_scale);
});
select('#date').on('input', function (a, b) {
console.log(this, a, b);
const date1 = new Date(1970, 0, this.valueAsNumber - 15);
const date2 = new Date(1970, 0, this.valueAsNumber + 15);
document.getElementById('datestring').innerHTML =
date1.toDateString() + ' to ' + date2.toDateString();
scatterplot
.plotAPI({
alpha: 3.5,
max_points: 1000,
point_size: 5,
duration: 0.1,
encoding: {
filter: {
field: 'MSNDATE',
op: 'within',
a: 15,
b: this.valueAsNumber,
},
},
})
.then(redo_scale);
});
});
</script>
<style>
#deepscatter {
position: relative;
}
.overlay {
position: absolute;
top: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 99;
}
#left-overlay {
left: 0;
}
#color-legend {
right: 0;
display: flex;
flex-direction: column;
align-items: right;
justify-content: right;
}
.legend-div {
margin: 5px;
padding: 5px 15px;
}
button {
margin: 0.1em;
}
button:hover {
background-color: #eee;
}
</style>