-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtransition.js
111 lines (92 loc) · 2.71 KB
/
transition.js
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
import { tableFromIPC } from 'apache-arrow';
import createScatterplot from '../src';
import createMenu from './menu';
import { checkSupport, showModal, closeModal } from './utils';
const CLASS_COLORS = [
'#FFFF00', // bright yellow
'#1CFFD9', // turrtoise
'#FF34FF', // pink/purple
'#FF4A46', // pale red
'#008941', // forrest green
'#1966FF', // dark blue
'#C00069', // violette
'#FFDBE5', // almost white
'#FF9900', // yellow
'#8148D5', // grass green
];
/**
* Load Embedding Example
*/
const whenData = fetch(
'https://storage.googleapis.com/flekschas/regl-scatterplot/cities.arrow'
);
/**
* Modal
*/
showModal('Loading...');
/**
* Add info to footer
*/
const footer = document.querySelector('#footer');
footer.classList.remove('hidden');
const infoContent = document.querySelector('#info-content');
infoContent.innerHTML = `
<p><a href="https://www.geonames.org/about.html" target="_blank">GeoNames – Cities Dataset</a> visualized in three: by the cities' geographic location, by the total population across contintents, and by the citie's latitude distribution.</p>
`;
const canvas = document.querySelector('#canvas');
let pointSize = 1.5;
const scatterplot = createScatterplot({
canvas,
pointSize,
lassoOnLongPress: true,
});
checkSupport(scatterplot);
console.log(`Scatterplot v${scatterplot.get('version')}`);
createMenu({ scatterplot, opacityChangesDisabled: true });
whenData
.then((data) => tableFromIPC(data))
.then((table) => {
closeModal();
const columnValues = table.data[0].children.map((data) => data.values);
const population = columnValues[columnValues.length - 2];
const continents = columnValues[columnValues.length - 1];
const staticOpacity = new Float32Array(population.length);
for (let i = 0; i < population.length; i++) {
staticOpacity[i] = 1;
}
scatterplot.draw({
x: columnValues[0],
y: columnValues[1],
z: continents,
w: population,
});
scatterplot.set({
colorBy: 'z',
pointColor: CLASS_COLORS,
opacityBy: 'w',
opacity: Array.from({ length: 10 }, (_, i) => 0.33 + (i / 9) * 0.33),
});
let i = 0;
const transitionPoints = () => {
i++;
const startCol = (i % 3) * 2;
scatterplot
.draw(
{
x: columnValues[startCol],
y: columnValues[startCol + 1],
z: continents,
w: [population, staticOpacity, staticOpacity][i % 3],
},
{
transition: true,
transitionDuration: 750,
transitionEasing: 'quadInOut',
}
)
.then(() => {
setTimeout(transitionPoints, 2500);
});
};
setTimeout(transitionPoints, 2500);
});