Published
Edited
Jun 21, 2020
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
side = 1000 // Change here the size of the visualization (it's a square).
Insert cell
backgroundDotsNumber = 2500 // Change here the number of dots randomly positioned in the background.
Insert cell
opacity = 0.8 // Change here the opacity of circles.
Insert cell
red = "#FF5555" // This is IXT red.
Insert cell
Insert cell
Insert cell
pathToSample = `<path d="M554,500 C460.663877,500 385,424.336123 385,331 C385,237.663877 460.663877,162 554,162 C647.336123,162 723,237.663877 723,331 C723,424.336123 647.336123,500 554,500 Z M276.5,493 L276.5,169.962788 L276.5,493 Z"></path>`
Insert cell
M = 400 // Change here the number of points along the path to sample: the more dots, the denser it will look!
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
Insert cell
shape = svg`<svg style="width:${side}px; height:${side}px; display: block;" viewBox="0 0 ${side} ${side}">
${pathToSample}
</svg>`

Insert cell
path = shape.querySelector("path")
Insert cell
// from https://observablehq.com/@mbostock/fourier-series-path-sampling
linearSamples = {
const L = path.getTotalLength();
return Array.from({length: M}, (_, i) => {
const {x, y} = path.getPointAtLength(i / M * L);
return [x, y];
});
}
Insert cell
html`<svg style="width:${side}px; height:${side}px; display: block;" viewBox="0 0 ${side} ${side}">
${linearSamples.map(([x, y]) => svg`<circle cx=${x} cy=${y} r=1>`)}
</svg>`
Insert cell
width = side
Insert cell
height = side
Insert cell
margin = ({top: 0, right: 0, bottom: 0, left: 0})
Insert cell
small = 2
Insert cell
medium = 3
Insert cell
big = 4
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(data, d => d.x))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.y))
.range([margin.top,height - margin.bottom])
Insert cell
data = Array.from({length: backgroundDotsNumber}, () => ({x:Math.floor(Math.random() * side), y:Math.floor(Math.random() * side)}));

Insert cell
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {color} from "@jashkenas/inputs"
Insert cell
d3 = require("d3@5")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more