The interval option for line and area should round down#2386
The interval option for line and area should round down#2386
Conversation
mbostock
left a comment
There was a problem hiding this comment.
Can you explain what you’ve changed here? How does this change the behavior? I see some refactoring that seems to try to reduce code duplication but I can’t follow the logical change that is actually causing the interval transform to round down…
| if (options[k] != null) outputs[k] = reduce; | ||
| if (options[`${k}1`] != null) outputs[`${k}1`] = reduce; | ||
| if (options[`${k}2`] != null) outputs[`${k}2`] = reduce; | ||
| const outputs = {filter: null, [x]: `${x}1`}; |
There was a problem hiding this comment.
This is the change (outputting x: "x1") that matters. 👀
mbostock
left a comment
There was a problem hiding this comment.
Hmm, this seems wrong to me. Here is my test case:
test(async function aaplInterval() {
const aapl = (await d3.csv<any>("data/aapl.csv", d3.autoType)).slice(0, 81);
return Plot.plot({
x: {grid: true, ticks: "week"},
marks: [
Plot.dotY(aapl, {x: "Date", y: "High", interval: "week"}),
Plot.lineY(aapl, {x: "Date", y: "High", interval: "week", reduce: "max"}),
Plot.lineY(aapl, {x: "Date", y: "High", interval: "week", reduce: "min"})
]
});
});In main, the dot and line align because both round to the middle of the interval:
But in this branch, the dot and line don’t align because the line rounds down:
Maybe #1931 is just ill conceived? Or should we get rid of maybeIntervalMidX and maybeIntervalMidY, and have the dot and text marks round down, too? That would look like this:
|
I think probably #1931 is ill conceived and should be closed; if you want the dot to align with the line, the dot should have the interval option applied, too. |


closes #1931