Public
Edited
Jun 7, 2023
Fork of Vector field
Importers
Insert cell
Insert cell
viewof floor = Inputs.radio([1, 2], {label: "Select floor", value: "floor"})
Insert cell
viewof maptype = Inputs.radio([1, 5], {label: "Select map", value: "maptype"})
Insert cell
viewof hour = Inputs.range([0, 23], {label: "hour", step: 1,value:'hour'})
Insert cell
function map(floor,hour){
const context = DOM.context2d(1751, 925);
context.canvas.style.maxWidth = "100%";
//context.fillRect(0, 0, width, height);
//context.strokeStyle = "#eee";
//context.lineWidth = 1.5;
//context.lineJoin = "round";
context.drawImage( floor == 1 ? land : land2,0,0);
const real_data =floor == 1 ? data : data;
const real_scalealpha =floor == 1 ? scalealpha : scalealpha;
const real_mapscale = floor==1?mapscale:mapscale2;
const real_scale = floor==1?scale:scale;
for (const {longitude, latitude, speed, dir,hour_arrow,floor_arrow} of real_data) {
if(hour==hour_arrow && floor==floor_arrow){
context.save();
context.translate(longitude*real_mapscale, latitude*real_mapscale);
context.scale(real_scale(speed), real_scale(speed));
context.rotate(dir * Math.PI / 180);
context.beginPath();
context.moveTo(-2, -2);
context.lineTo(2, -2);
context.lineTo(0, 8);
context.closePath();
context.fillStyle = color(100+speed/(d3.max(real_data, d => d.speed)));
context.globalAlpha=real_scalealpha(speed);
context.fill();
context.restore();}
}
return context.canvas;
}
Insert cell
map2 = {
const context = DOM.context2d(1725, 914);
context.canvas.style.maxWidth = "100%";
//context.fillRect(0, 0, width, height);
//context.strokeStyle = "#eee";
//context.lineWidth = 1.5;
//context.lineJoin = "round";
context.drawImage(land2,0,0)
for (const {longitude, latitude, speed, dir} of data2) {
context.save();
context.translate(longitude*mapscale2, latitude*mapscale2);
context.scale(scale2(speed), scale2(speed));
context.rotate(dir * Math.PI / 180);
context.beginPath();
context.moveTo(-2, -2);
context.lineTo(2, -2);
context.lineTo(0, 8);
context.closePath();
context.fillStyle = color(100+speed/(d3.max(data2, d => d.speed)));
context.globalAlpha=scalealpha2(speed);
context.fill();
context.restore();
}
return context.canvas;
}
Insert cell
scale2 = d3.scaleSqrt([0, d3.max(data, d => d.speed)], [0, 9])
Insert cell
scale = d3.scaleSqrt([0, d3.max(data, d => d.speed)], [0, 20])
Insert cell
mapscale2=1735/30;
Insert cell
mapscale=1751/30;
Insert cell
scalealpha2 = d3.scaleSqrt([0, d3.max(data, d => d.speed)], [0.3, 1])
Insert cell
scalealpha = d3.scaleSqrt([0, d3.max(data, d => d.speed)], [0.3, 1])
Insert cell
color = d3.scaleSequential([0, 360], d3.interpolateRainbow)
Insert cell
data2 = d3.csvParse(await FileAttachment("arrow_2@3.csv").text(), d3.autoType)
Insert cell
data = d3.csvParse(await FileAttachment("arrow@6.csv").text(), d3.autoType)
Insert cell
projection = d3.geoEquirectangular()
Insert cell
width = 975
Insert cell
import {chart} from "@yomi/radial-stacked-bar-chart"
Insert cell
chart
Insert cell
margin = 10
Insert cell
land = FileAttachment("Map-Floor 1.png").image({width: 400, style: "border: 1px solid black"})
Insert cell
land2 = FileAttachment("Map-Floor 2.png").image({width: 400, style: "border: 1px solid black"})
Insert cell
world = d3.json("https://cdn.jsdelivr.net/npm/world-atlas@2/land-50m.json")
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@6")
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