Skip to content

Implicitly stack bars #348

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 5 commits into from
May 1, 2021
Merged

Implicitly stack bars #348

merged 5 commits into from
May 1, 2021

Conversation

mbostock
Copy link
Member

If a barY is specified without y1 or y2, implicitly apply the stackY transform. Same with barX, x1, and x2.

This is stacked:

Plot.barY(crimea, {x: "date", y: "deaths", fill: "cause"})

This overlaps:

Plot.barY(crimea, {x: "date", y2: "deaths", fill: "cause"})

The idea is that this reduces the possibility of unintentionally overlapping opaque bars, but you can still opt-out of stacking easily if that’s what you intend.

@mbostock mbostock requested a review from Fil April 30, 2021 23:20
@mbostock
Copy link
Member Author

I’d love help getting the unit tests working again…

@mbostock mbostock force-pushed the mbostock/implicit-stack branch from a1ab72e to 6aea825 Compare May 1, 2021 16:07
@mbostock
Copy link
Member Author

mbostock commented May 1, 2021

I get the impression that this should also apply to the area mark.

@Fil
Copy link
Contributor

Fil commented May 1, 2021

Overlapping areas are more common than overlapping bars, but yes it would be consistent if bars and areas worked similarly.
But then there is this pesky issue of #325 and you might want to also include the "seriesX" transform (probably a poor choice of a name) explored in https://observablehq.com/d/f6a7975f2ad4519a

@mbostock
Copy link
Member Author

mbostock commented May 1, 2021

Added areas. I don’t know how to address your other comment.

@mbostock mbostock force-pushed the mbostock/implicit-stack branch from f6ca3db to 3aa9c56 Compare May 1, 2021 16:29
@mbostock
Copy link
Member Author

mbostock commented May 1, 2021

Oops, need to stack rect too. Works well though! It’s fun that you can turn on or off stacking by switching between y and y2.

@Fil
Copy link
Contributor

Fil commented May 1, 2021

A foolproof solution for stacked areas should include the seriesX transform (and similarly seriesY transform for areaX).

So I suppose 7594f0e#diff-8f62f80a02a317ce3253c0795d19093acea8456b90e720732b62455ef9d96203R94 might become something like maybeStackYSeriesX(…)

I thought it would be a plugin, but I can research it now as a PR to this PR or to main.

The risk with seriesX is that it might create a combinatory explosion if you make a mistake in your choice of x, transforming n data points into n^2.

@mbostock
Copy link
Member Author

mbostock commented May 1, 2021

Do you think this is a blocker? It doesn’t feel like one for me.

@Fil
Copy link
Contributor

Fil commented May 1, 2021

No, not a blocker; it's just a case where the default doesn't work out of the box; let's say that, if the series are incomplete on x and you want to represent them with a stacked areaY, you need the plugin; in the meantime we recommend using stacked rects (or bars, or rules).

@mbostock
Copy link
Member Author

mbostock commented May 1, 2021

Yep. I feel like the seriesX transform should probably instead be an option to the stack transform that fills any missing values across stacks with zero.

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