Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty bins fall back on the first element of their group #1837

Merged
merged 2 commits into from
Aug 26, 2023

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Aug 26, 2023

For z, stroke and fill. Previously b[0] was undefined, so a spurious undefined value was potentially added to GZ, GF or GS.

cc @yurivish

closes #1775

@Fil Fil requested a review from mbostock August 26, 2023 10:59
src/transforms/bin.js Outdated Show resolved Hide resolved
@mbostock mbostock enabled auto-merge (squash) August 26, 2023 16:23
@mbostock mbostock merged commit 26b5d14 into main Aug 26, 2023
@mbostock mbostock deleted the fil/spurious-series-1775 branch August 26, 2023 16:25
@Fil
Copy link
Contributor Author

Fil commented Aug 26, 2023

Thanks! Here's another test:

Capture d’écran 2023-08-26 à 18 56 09
export async function test2() {
  const fills = {red: d3.interpolateReds, green: d3.interpolateGreens, blue: d3.interpolateBlues};
  const data = []
    .concat(
      d3
        .range(100)
        .map((d) => ({x: d, y: 0.4 + 0.6 * Math.cos(d / 10), z: "red"}))
        .filter((d) => d.y > 0)
    )
    .concat(
      d3
        .range(100)
        .map((d) => ({x: d, y: 0.4 + 0.6 * Math.cos(d / 3), z: "green"}))
        .filter((d) => d.y > 0)
    )
    .concat(
      d3
        .range(100)
        .map((d) => ({x: d, y: 0.4 + 0.6 * Math.cos(d / 7), z: "blue"}))
        .filter((d) => d.y > 0)
    );
  return Plot.areaY(data, {
    x: "x",
    y: "y",
    z: "z",
    fill: (d) => fills[d.z](d.y),
    stroke: "z",
    interval: 1
  }).plot();
}

chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
…q#1837)

* Empty bins fall back on the first element of their group for z, stroke and fill

closes observablehq#1775

* test edge case

---------

Co-authored-by: Mike Bostock <mbostock@gmail.com>
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.

Area + interval creates a spurious series
2 participants