Public
Edited
Apr 11, 2023
2 forks
1 star
Insert cell
Insert cell
viewof radiusRange = rangeSlider({
min: 0.0005,
max: 50,
// Note that values must be specified as array of length 2.
value: this ? this.value : [1, 25],
// Custom slider CSS, replaces all styles.
// theme: themes[theme],
// Overrides the range color. Support for range colors is up to the theme.
title: 'Circle radius',
description: 'Control minimum and maximum radius',
})
Insert cell
map = {
worldMap.select("#cities").remove()
worldMap.select("#connections").remove()
worldMap.select("#names").remove()

worldMap.append("g")
.attr("id", "cities")
.selectAll("circle")
.data(data)
.join("circle")
.attr("transform", d => `translate(${mapProjection([d[lngBase], d[latBase]])})`)
.attr('r', d => radiusFxn(d[radBase]))
.attr('fill', d => d['pc_change'] < 0 ? '#FF924C' : '#5DD39E')
.attr("stroke", 'white')//d => colorScale(d[colorBase]) === '#000000' ? 'white' : 'black')
.attr("stroke-width", 0.5)

return worldMap.node()
}
Insert cell
Insert cell
radiusFxn = d3.scaleLinear().domain(radDomain).range(radiusRange)
Insert cell
radDomain = {
return d3.extent(data.map(row => row[base]));
}
Insert cell
radBase = 'abs_pc_change'
Insert cell
base = 'abs_pc_change'
Insert cell
latBase = 'city_lat'
Insert cell
lngBase = 'city_lng'
Insert cell
Insert cell
data[0]
Insert cell
Insert cell
data.sort((a, b) => b[base] - a[base]).slice(0, 20).map(row => row.id);
Insert cell
data = FileAttachment("world-scale-change@2.csv").csv({typed: true})
Insert cell
import {legend, Swatches} from "@d3/color-legend"
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {mapProjection, mapPath, activeColorScheme, worldMap} from "b3a0a78984d6df2e"
Insert cell
import {rangeSlider} from '@mootari/range-slider'
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