observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.46k stars 182 forks source link

Stack overlapping, non-aligned intervals? #1970

Open fgregg opened 10 months ago

fgregg commented 10 months ago

Currently, if two rects do not share an x1 and x2, they will not stack, it would be great if they did!

Here's an example of something i would like to stack but is not:

untitled(88)

https://observablehq.com/@fgregg/chicago-shelter-eviction-rates@129

I manually set offsets to look like this:

untitled(89)

https://observablehq.com/@fgregg/chicago-shelter-eviction-rates@171

mbostock commented 10 months ago

The GitHub Burndown chart does something like this by converting an interval into a regular pulse (e.g., daily value). It’s not technically possible to stack rects with overlapping but non-aligned intervals because the resulting stacked shape is no longer a rect. For example, say you have two intervals represented in ASCII art:

aaaaaaaaaa
    bbbb

If you were to stack a on top of b, the shape for a would no longer be a rectangle:

    aaaa
aaaabbbbaa

The stack transform doesn’t require that the independent dimension (normally x) is regular, so you wouldn’t have to take the pulse approach used in the linked notebook — you could instead cut every interval when it overlaps with another interval. And then the stack transform would work. Maybe the bin transform could do something fancy here to replicate data that spans multiple bins.

fgregg commented 10 months ago

this is the behavior i’d like to see:

    aaaa
aaaabbbbaa

and you are absolutely right that is not a rect anymore, so it probably shouldn’t be something you can do with rects.

however, stacking up bits of area of different widths would still be really useful! at least to me.