observablehq / plot

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

A midX/midY transform? #1452

Open mbostock opened 1 year ago

mbostock commented 1 year ago

It might be nice to have a transform that takes x1 and x2 and derives an x channel, as the mid helper does internally (preserving dates as needed). And if you had an x channel and an interval option, it could derive an x that represents the midpoint of the associated intervals. And same for y.

Ref. https://talk.observablehq.com/t/mid-align-axisx-in-a-plot/7857/1

mbostock commented 1 year ago

I also had a thought where it’d be cool if you could somehow apply the bin transform to the axis mark, so that you could then bin the ticks and easily compute the extent and midpoint of each time interval. But that’s not readily doable with the axis mark because the axis mark uses an initializer to compute the ticks (running after scale construction). And I don’t think it’s currently possible to run an initializer after the axis mark’s built-in initializer, even if we were to adapt the bin transform to let it run as an initializer. I guess we could have a postinitialize option but that feels pretty specific and low-level!