Public
Edited
Feb 17, 2023
Importers
Insert cell
Insert cell
Insert cell
viewof numPoints = Inputs.range([1, Math.pow(4, order)], { step: 1, value: Math.pow(4, order), label: "Number of Points" })
Insert cell
Plot.plot({
marks: [
Plot.line(points, { x: "x", y: "y", stroke }),
Plot.dot(points, { x: "x", y: "y", r: 1, fill: "white", stroke })
],
x: { axis: false, type: "point" },
y: { axis: false, type: "point" },
marginLeft: 20,
marginTop: 20,
marginBottom: 20,
marginRight: 20,
width: 650,
height: 650
})
Insert cell
Insert cell
points = makePoints(order)
Insert cell
makePoints = (order) => {
let hilbert = d3hilbert.hilbert().order(order)
return d3.range(numPoints).map(i => {
let xy = hilbert.getXyAtVal(i)
return { x: xy[0], y: xy[1], i }
})
}
Insert cell
Math.pow(4, order)
Insert cell
numPoints
Insert cell
Insert cell
html`<svg width=${chartSize} height=${chartSize}>${d3.range(2,5).reverse().map(i => Plot.plot({ marks: makeMarks(i), ...options }))}</svg>`
Insert cell
makeMarks = (order) => [
Plot.line(makePoints(order), { x: "x", y: "y", stroke: colors[order - 1] }),
Plot.dot(makePoints(order), { x: "x", y: "y", r: 10, fill: "white", stroke: colors[order - 1] }),
Plot.text(makePoints(order), { x: "x", y: "y", text: "i", dx: 0, textAnchor: "middle", fontSize: 9, fill: colors[order - 1] })
]
Insert cell
Insert cell
html`<svg width=${chartSize} height=${chartSize}>${d3.range(2,7).reverse().map(i => Plot.plot({ marks: makeMarks2(i), ...options }))}</svg>`
Insert cell
makeMarks2 = (order) => {
let color = colors2[order - 2]
return [
Plot.line(makePoints(order), { x: "x", y: "y", stroke: color, strokeWidth: 3 }),
Plot.dot(makePoints(order), { x: "x", y: "y", r: 3, fill: color, stroke: color }),
]
}
Insert cell
options = ({
x: { axis: false, type: "point" },
y: { axis: false, type: "point" },
marginLeft: 20,
marginTop: 20,
marginBottom: 20,
marginRight: 20,
width: chartSize,
height: chartSize
})
Insert cell
chartSize = width
Insert cell
Insert cell
colors = [yellow, orange, blue, green, brown]
Insert cell
colors2 = [red,yellow, orange, purple, lightgreen, brown]
Insert cell
blue = "#0039A6"
Insert cell
red = "#EE352E"
Insert cell
green = "#00933C"
Insert cell
lightgreen = "#6CBE45"
Insert cell
brown = "#996633"
Insert cell
yellow = "#FCCC0A"
Insert cell
orange = "#FF6319"
Insert cell
purple = "#B933AD"
Insert cell
strokep = "#bfc1c2"
Insert cell
Plot.plot({
marks: [
Plot.line(pendantPoints, { x: "x", y: "y", stroke: strokep, strokeWidth: 12 }),
Plot.dot(pendantPoints, Plot.selectFirst({ x: "x", y: "y", r: 15, fill: "white", stroke: strokep, strokeWidth: 10 })),
Plot.dot(pendantPoints, Plot.selectLast({ x: "x", y: "y", r: 15, fill: "white", stroke: strokep, strokeWidth: 10 })),
],
x: { axis: false, type: "point" },
y: { axis: false, type: "point" },
marginLeft: 20,
marginTop: 20,
marginBottom: 20,
marginRight: 20,
width: 650,
height: 650,
style: {
strokeLinejoin: "round"
}
})
Insert cell
Plot.plot({
marks: [
Plot.line(pendantPoints, { x: "x", y: "y", stroke: "black", strokeWidth: 32 }),
// Plot.dot(pendantPoints, Plot.selectFirst({ x: "x", y: "y", r: 15, fill: "white", stroke: strokep, strokeWidth: 10 })),
// Plot.dot(pendantPoints, Plot.selectLast({ x: "x", y: "y", r: 15, fill: "white", stroke: strokep, strokeWidth: 10 })),
],
x: { axis: false, type: "point" },
y: { axis: false, type: "point" },
marginLeft: 20,
marginTop: 20,
marginBottom: 20,
marginRight: 20,
width: 650,
height: 650,
style: {
strokeLinejoin: "round"
}
})
Insert cell
pendantPoints = makePoints(3)
Insert cell
Insert cell
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