Skip to content

handle collapsed domains #470

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

Merged
merged 3 commits into from
Aug 10, 2021
Merged

handle collapsed domains #470

merged 3 commits into from
Aug 10, 2021

Conversation

mbostock
Copy link
Member

Supersedes #438.
Ref. #417 (comment).

This adds special logic to marks with continuous position dimensions such that when the associated scale’s domain is collapsed (i.e., all values in the input domain map to the same value in the output range), the mark spans the full extent of the chart. For example, here is a plot with the collapsed y-domain [0, 0]; note that the bar and rule span the full y-extent of the chart. Previously this chart would be empty because the bar and rule would have zero height.

Screen Shot 2021-07-31 at 9 35 21 AM

Plot.plot({
  marks: [
    Plot.barY({length: 1}, {x: ["foo"], y1: [0], y2: [0]}),
    Plot.ruleX(["foo"], {stroke: "red", y1: [0], y2: [0]})
  ]
})

In practice, this seems most likely to occur when binning values that all happen to be equal, but unlike #438 this does not change the semantics of the chart and thus is more robust and general.

The isCollapsed check could be memoized if performance is a concern in the future, given how rare it is for a scale to be collapsed. And also it’s slightly unfortunate that this logic must be applied by mark implementations rather than somehow generalizing to the scales. I think it might be possible to do this more generically, and faster, but this seems fine for now?

@mbostock mbostock requested a review from Fil July 31, 2021 16:40
@mbostock mbostock mentioned this pull request Aug 1, 2021
@Fil
Copy link
Contributor

Fil commented Aug 2, 2021

Works perfectly. But following your hint of doing this “more generically”, I offer an alternative in #474.

Notice that the singleValueBar example is identical if we omit y1 and y2:

Plot.plot({
    marks: [
      Plot.barY({length: 2}, {x: ["foo", "bar"]}),
      Plot.ruleX(["foo"], {stroke: "red"})
    ]
  });

@Fil
Copy link
Contributor

Fil commented Aug 2, 2021

A serious issue I'm seeing only now is what happens when if we have only 1 bar with a 0-height (barY({y:0}))… it would probably be very surprising to see it shown at all? OTOH one can argue that it's "continuous" with barY({y: 𝜺}) with 𝜺 => 0? Wanted to flag it anyway.

@mbostock mbostock force-pushed the mbostock/collapsed-domains branch from 2ef9aa4 to 54afea0 Compare August 9, 2021 20:47
@mbostock
Copy link
Member Author

mbostock commented Aug 9, 2021

I’ve rebased this and I’m still in favor of this over #474. Do you have any objection, @Fil?

@Fil
Copy link
Contributor

Fil commented Aug 9, 2021

Not a strong objection—it's one of these cases where we need an arbitrary resolution anyway.

@mbostock mbostock force-pushed the mbostock/collapsed-domains branch from 5e87fb4 to 5b3fc8f Compare August 10, 2021 19:35
@mbostock mbostock merged commit b6e4c64 into main Aug 10, 2021
@mbostock mbostock deleted the mbostock/collapsed-domains branch August 10, 2021 19:46
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.

2 participants