Public
Edited
Oct 24, 2023
11 stars
Insert cell
Insert cell
Insert cell
piecewiseColor = d3.piecewise(d3.interpolateHsl, ["red", "orange", "yellow", "lime", "green"])
Insert cell
ramp(piecewiseColor)
Insert cell
piecewiseColor(0.55)
Insert cell
Insert cell
piecewiseNumber = d3.piecewise(d3.interpolateRound, [0, 1, 10, 100, 1000])
Insert cell
d3.quantize(piecewiseNumber, 20)
Insert cell
Insert cell
piecewiseObject = d3.piecewise([
{ opacity: 0.1, r: 1, cx: 0, cy: 0, fill: "red" },
{ r: 10, opacity: 0.5, cx: 150, cy: 100, fill: "orange" },
{ r: 100, opacity: 1, cx: 120, cy: 110, fill: "yellow" },
{ r: 200, opacity: 0.1, cx: 300, cy: 50, fill: "lime" }
])
Insert cell
viewof t = Inputs.range([0, 1], { label: "parameter t" })
Insert cell
shape = piecewiseObject(t)
Insert cell
svg`<svg style="overflow: visible"><circle
r=${shape.r}
opacity=${shape.opacity}
cx=${shape.cx}
cy=${shape.cy}
fill="${shape.fill}"
>`
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3-interpolate@3")
Insert cell
import {ramp} from "@mbostock/color-ramp"
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