Published
Edited
Jul 6, 2020
1 star
Insert cell
Insert cell
chart = {
const svg = d3.create('svg')
.attr('viewBox', [0, 0, 960, 600])
.style('background-color', '#314d7a');
svg.append('path')
.datum(basemap)
.attr('d', path)
.attr('fill', '#357a31')
.attr('stroke', 'white')
.attr('stroke-width', '0.2px')
.attr('stroke-linejoin', 'round');
svg.append('path')
.datum(graticule)
.attr('d', path)
.attr('stroke', 'white')
.attr('stroke-width', '0.3px')
.attr('stroke-opacity', 0.5);
svg.append('path')
.datum(data)
.attr('d', path)
.attr('fill', 'none')
.attr('stroke', '#333333');
svg.append('g')
.selectAll('circle')
.data(data.coordinates)
.join('circle')
.attr('transform', d => `translate(${projection(d)})`)
.attr('r', 3)
.attr('fill', (d, i) => color(data.intensity[i]))
.append('title')
.text((d, i) => data.time[i] + '\n' + data.intensity[i] + ' kts');
svg.append('g')
.attr('transform', 'translate(20, 10)')
.attr('opacity', 0.8)
.append(() => legend({color,
title: 'Intensity (kts)',
tickSize: 0,
width: 180
}));
/*
Don't really need this yGraticule Label, since the parallels seem pretty self-explanatory.
const yGraticuleG = svg.append('g')
.attr('font-size', 10)
.attr('font-family', 'sans-serif')
.attr('fill', 'white')
.attr('opacity', 0.3)
.attr('text-anchor', 'end');
latitude.map(y => {
yGraticuleG.append('text')
.attr('transform', `translate(${projection([185, y]) + ""})`)
.text(formatLatitude(y))
.attr('y', -4)
})
*/
const xGraticuleG = svg.append('g')
.attr('font-size', 10)
.attr('font-family', 'sans-serif')
.attr('fill', 'white')
.attr('opacity', 0.25)
.attr('text-anchor', 'start');
longitude.map(x => {
xGraticuleG.append('text')
.attr('transform', `translate(${projection([x, -7]) + ""}) rotate(-90)`)
.text(formatLongitude(x))
.attr('y', 11)
})
return svg.node();
}
Insert cell
formatLongitude = x => `${Math.abs(x)}°${x < 0 ? 'W' : 'E'}`
Insert cell
formatLatitude = y => `${Math.abs(y)}°${y < 0 ? 'S' : 'N'}`
Insert cell
formatTime = d3.timeFormat('%B %d, %Y %H:%M')
Insert cell
color = d3.scaleThreshold()
.domain([34, 48, 64, 85, 105])
.range(['#8299d9', '#4d63a1', '#e3ce71', '#e0ae51', '#e69035', '#e05f34'])
Insert cell
graticule = d3.geoGraticule10()
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
/* Rotate according to the longitude offset,
and center the graph based on the latitude offset. */
projection = d3.geoMercator()
.rotate([-140, 0])
.center([0, 25])
.scale([600])
Insert cell
basemap = d3.json('https://unpkg.com/world-atlas@1.1.4/world/50m.json').then(data => {
return topojson.feature(data, data.objects.countries)
})
Insert cell
data = FileAttachment('point-data.json').json().then(d => {
const rawData = d['1919'];
return {
'type': "LineString",
'coordinates': rawData.map(d2 => d2.location),
'intensity': rawData.map(d2 => d2.intensity),
'time': rawData.map(d2 => formatTime(new Date(d2.time)))
}
})
Insert cell
latitude = d3.range(0, 41, 10)
Insert cell
longitude = d3.range(100, 181, 20)
Insert cell
topojson = require("topojson-client@3")
Insert cell
import {legend} from '@d3/color-legend'
Insert cell
d3 = require('d3@5')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more