Public
Edited
Mar 19, 2023
12 stars
Insert cell
Insert cell
sales = [
{ units: 10, fruit: "fig" },
{ units: 20, fruit: "date" },
{ units: 40, fruit: "plum" },
{ units: 30, fruit: "Siberian apricot" }
]
Insert cell
Plot.dot(sales, { x: "units", y: "fruit" }).plot()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
length = measureText(string, fontSize)
Insert cell
Insert cell
d3.max(sales, (d) => measureText(d.fruit, 10))
Insert cell
Insert cell
Plot.dot(sales, { x: "units", y: "fruit" }).plot({
marginLeft: d3.max(sales, (d) => measureText(d.fruit, 10))
})
Insert cell
Insert cell
tickLabelPadding = 9 + 10
Insert cell
Plot.dot(sales, { x: "units", y: "fruit" }).plot({
marginLeft: d3.max(sales, (d) => measureText(d.fruit, 10)) + tickLabelPadding
})
Insert cell
Insert cell
autoMargin = (data, accessor) =>
d3.max(Plot.valueof(data, accessor), (d) => measureText(d, 10)) + tickLabelPadding
Insert cell
Plot.dot(sales, { x: "units", y: "fruit" }).plot({
marginLeft: autoMargin(sales, "fruit")
})
Insert cell
Insert cell
measureText = (str, fontSize = 10) =>
d3.sum(str, (cur) => characterWidths[cur.charCodeAt(0)] ?? avg) * fontSize
Insert cell
avg = d3.mean(characterWidths.filter((d) => d))
Insert cell
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