Published
Edited
Apr 6, 2019
6 forks
15 stars
Insert cell
Insert cell
Insert cell
scene = {
const scene = new THREE.Scene()
scene.background = new THREE.Color('#fff')
// add cube outline
const box = new THREE.BoxGeometry(x, y, z)
var geo = new THREE.EdgesGeometry( box );
var mat = new THREE.LineBasicMaterial( { color: 0xdddddd, linewidth: 1 } );
var wireframe = new THREE.LineSegments( geo, mat );
scene.add( wireframe );
// add map
scene.add(map);
// add plot
for (var i = 0; i < data.length; i++) {
var coord = project3D([data[i].lon, data[i].lat], data[i].date)
var geo = new THREE.SphereGeometry( 0.15, 8, 8 );
var mat = new THREE.MeshBasicMaterial({color: d3.interpolateRdYlBu(Math.random())})
var cube = new THREE.Mesh(geo, mat)
cube.position.x = coord.x
cube.position.y = coord.y
cube.position.z = coord.z
scene.add(cube)
}
return scene
}
Insert cell
Insert cell
map = {
const mesh = topojson.mesh(world, world.objects.countries);
const material = new THREE.LineBasicMaterial({color: 0xbbbbbb, linewidth: 1});

const geometry = new THREE.Geometry();
for (const P of mesh.coordinates) {
for (let p0, p1 = project3D(P[0]), i = 1; i < P.length; ++i) {
geometry.vertices.push(p0 = p1, p1 = project3D(P[i]));
}
}
return new THREE.LineSegments(geometry, material);
}
Insert cell
Insert cell
function project3D(coord, t = minDate) {
const proj = projection(coord);
const time = timeScale(t)
return new THREE.Vector3(
proj[1],
time,
-proj[0]
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
var d = []
for (var i = 0; i < 200; i++) {
d.push({
lat: (Math.random() * 170 - 85),
lon: (Math.random() * 360 - 180),
date: (new Date(Math.random() * (maxDate.getTime() - minDate.getTime()) + minDate.getTime())),
value: Math.random()
})
}
return d
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more