Public
Edited
Feb 3, 2023
2 forks
2 stars
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
canvasSize = Math.min(560, width);
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
height
Insert cell
Insert cell
(length + margin) *1
Insert cell
function translateS(d, i) {
return `translate(${(length/2 + marginS)*i * 2}, ${-height/2})`;
}
Insert cell
timeResponse = {
let countries = Array.from(new Set(time.map(row => row.country)));
let df = {};
countries.map(row => {
let subdf = time.filter(d => d['country'] === row);
let numOwn = subdf.filter(row => row['own_transport'] === 'Yes').length;
let numNOwn = subdf.filter(row => row['own_transport'] === 'No').length;
df[row + '_' + 'num_own'] = numOwn;
df[row + '_' + 'num_no_own'] = numNOwn;
});
// let numOwn = time.filter(row => row['own_transport'] === 'Yes').length;
// let numNOwn = time.filter(row => row['own_transport'] === 'No').length;

return df;//{'own_transport': numOwn, 'no_own_transport': numNOwn};
}
Insert cell
distResponse = {
let countries = Array.from(new Set(distance.map(row => row.country)));
let df = {};
countries.map(row => {
let subdf = distance.filter(d => d['country'] === row);
let numOwn = subdf.filter(row => row['own_transport'] === 'Yes').length;
let numNOwn = subdf.filter(row => row['own_transport'] === 'No').length;
df[row + '_' + 'num_own'] = numOwn;
df[row + '_' + 'num_no_own'] = numNOwn;
});
// let numOwn = time.filter(row => row['own_transport'] === 'Yes').length;
// let numNOwn = time.filter(row => row['own_transport'] === 'No').length;

return df;//{'own_transport': numOwn, 'no_own_transport': numNOwn};
}
Insert cell
Insert cell
function deg2rad(deg) { return deg * Math.PI / 180 }
Insert cell
svgWidth = 960
Insert cell
svgHeight = 300
Insert cell
height = 150
Insert cell
cols = 5
Insert cell
margin = 4 //between individual charts
Insert cell
function translate(d, i) {
return `translate(${(radius+margin)*(2*(i%cols)+1)}, ${(radius+margin)*((2*Math.floor(i/cols))+1.25)})`;
}
Insert cell
Insert cell
spiralScale = d3.scaleLinear().domain([0, maxTime]).range([0, 100])
Insert cell
function axisSpiral(length) {
return d3.lineRadial()
.angle((d, i) => Math.PI / _precision * i)
.radius((d, i) => i * (outerR - innerR) / length + innerR)({ length });
}
Insert cell
maxTime = d3.extent(time.map(row => row['time_travelled']))[1];
Insert cell
maxDist = d3.extent(distance.map(row => row['distance_travelled']))[1];
Insert cell
distanceCountries = Array.from(new Set(distance.map(row=> row['country'])));
Insert cell
timeCountries = Array.from(new Set(time.map(row=> row['country'])));
Insert cell
distance = FileAttachment("distance-travelled.csv").csv({typed: true})
Insert cell
time = FileAttachment("time-travelled.csv").csv({typed: true})
Insert cell
import {select, slider, text} from "@jashkenas/inputs"
Insert cell
d3 = require('d3', 'd3-radial-axis')
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