Unlisted
Edited
Dec 6
Insert cell
Insert cell
Insert cell
Plot.rectY(fakeData, {
x: "date",
y: "value",
interval: "day"
}).plot({
title:
"This is the ideal output Plot, but I don't actually know what the interval may be"
})
Insert cell
viewof range = Inputs.range([10, 1000], { label: "Num days", step: 1 })
Insert cell
Plot.rectY(
fakeData,
Plot.binX(
{ y: "sum" },
{
x: "date",
y: "value",
tip: true
}
)
).plot({
title:
"This is the ideal output Plot, but I don't actually know what the interval may be"
})
Insert cell
Plot.barY(fakeData, {
x: "date",
y: "value"
}).plot({ title: "With BarY, You can't see the dates that are missing!" })
Insert cell
Plot.rectY(
fakeData,
Plot.binX(
{ y: "sum" },
{
x: "date",
y: "value",
thresholds: fakeData.length
}
)
).plot({
title: 'Pass a number to threshold, but it\'s only a "hint"',
subtitle:
"Calculating the number of thresholds from the input data will also be tricky with additional encodings like color and facets"
})
Insert cell
Plot.rectY(
fakeData,
Plot.binX(
{ y: "sum" },
{
x: "date",
y: "value",
thresholds: fakeData.map((d) => d.date),
// Even if I add another value the last date gets cut off
// thresholds: [
// ...fakeData.map((d) => d.date),
// d3.max(fakeData, (d) => d.Date)
// ]
}
)
).plot({
title:
"Passing in an array of thresholds yields different width bars and also cuts off the last one?",
subtitle:
"Calculating the number of thresholds from the input data will also be tricky with additional encodings like color and facets"
})
Insert cell
Insert cell
dates = d3.sort(Plot.valueof(fakeData, "date"))
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3.pairs(
d3.sort(Plot.valueof(fakeData, "date")),
(a, b) => Math.round((b - a) / 60000) // minutes
)
Insert cell
{
const m = d3.min(
d3.pairs(
d3.sort(Plot.valueof(fakeData, "date")),
(a, b) => Math.round((b - a) / 60000) // minutes
)
);
const interval =
m < 2
? d3.utcMinute
: m < 10
? d3.utcMinute.every(m)
: m < 60
? d3.utcMinute.every(m)
: m < 23 * 60
? d3.utcHour.every(Math.round(m / 60))
: m < 23 * 60 * 7
? d3.utcDay
: m < 24 * 60 * 27
? d3.utcWeek
: m < 24 * 60 * 364
? d3.utcMonth
: d3.utcYear;

return Plot.rectY(fakeData, {
x: "date",
y: "value",
interval
}).plot({
title: "Fil's solution",
subtitle: "I think it works"
});
}
Insert cell
Insert cell
// Generate some fake data
fakeData = d3
.range(range)
.map((d) => {
const date = d3.utcDay.offset(d3.utcDay(), d);
const value = Math.random();
return { date, value };
})
.filter((d) => d.value > 0.2)
Insert cell
fakeData
Type Table, then Shift-Enter. Ctrl-space for more options.

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