Skip to content

The interval option for line and area should round down#2386

Open
Fil wants to merge 4 commits intomainfrom
fil/fix-stack-interval
Open

The interval option for line and area should round down#2386
Fil wants to merge 4 commits intomainfrom
fil/fix-stack-interval

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Mar 18, 2026

Capture d’écran 2026-03-18 à 11 25 47

closes #1931

@Fil Fil requested a review from mbostock March 18, 2026 10:26
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the intersection with #2390 is interesting… Do we like this? My initial assumption is that the dense interval transform should produce zero instead of undefined… not sure what is happening here.

Image

Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`};
Copy link
Copy Markdown
Member

@mbostock mbostock Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change (outputting x: "x1") that matters. 👀

Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image

But in this branch, the dot and line don’t align because the line rounds down:

Image

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:

Image

@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 1, 2026

And if we change the dot and text marks to round down to the start of the interval, they don’t work as well to label rects (here representing the extent of a week along the x-axis) as in the seattlePrecipationSum test:

Screenshot 2026-04-01 at 2 05 28 PM

Hmmm! 🤔

@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 1, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The interval option for line and area perhaps should round down rather than center

2 participants