Published
Edited
Oct 16, 2019
Insert cell
Insert cell
Insert cell
graph = {
const context = DOM.context2d(width, height);
context.clearRect(0, 0, width, height);
context.canvas.style.background = "#eff";

context.lineCap = 'round';
context.strokeStyle = "#ccc";
context.lineWidth = 1;

// Set grid origin to center of canvas
context.translate(width / 2, height / 2);

context.beginPath();
context.moveTo(0, 0);

context.lineTo(100, 100);
context.stroke();
context.lineTo(-50, -75);
context.stroke();

for (let θ = 0; θ < 2 * Math.PI; θ += Math.PI / 3) {
let point = polar_to_cartesian([scale, θ]);
context.ellipse(...point, 2, 2, 0, 0, 2 * Math.PI);
context.lineTo(...point);
context.stroke();
}
return context.canvas;
}
Insert cell
polar_to_cartesian = ([r, θ]) => {
return [r * Math.cos(θ), r * Math.sin(θ)];
}
Insert cell
height = 400
Insert cell
import { slider } from "@jashkenas/inputs"
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