Published
Edited
Aug 28, 2020
1 fork
1 star
Insert cell
Insert cell
chart = {
const canvas = d3
.create("canvas")
.attr("width", width + "px")
.attr("height", height + "px")
.call(
d3
.zoom()
.scaleExtent([1, 8])
.on("zoom", zoom)
),
context = canvas.node().getContext("2d");

scaleCanvas(canvas.node(), context);

function zoom(event) {
context.clearRect(0, 0, width, height);
draw(event.transform);
}

function draw(transform) {
var i = -1,
n = data.length,
d;

context.fillStyle = "steelblue";
context.beginPath();
while (++i < n) {
d = transform.apply(data[i]);
context.moveTo(d[0], d[1]);
context.arc(d[0], d[1], 2.5, 0, 2 * Math.PI);
}
context.fill();
}

draw(d3.zoomIdentity);

return canvas.node();
}
Insert cell
data = {
const randomX = d3.randomNormal(width / 2, 80),
randomY = d3.randomNormal(height / 2, 80);
return d3.range(2000).map(() => [randomX(), randomY()]);
}
Insert cell
height = width * 0.6
Insert cell
d3 = require("d3@6")
Insert cell
import { scaleCanvas } from "@john-guerra/canvas-retina-display"
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