d3-scale icon indicating copy to clipboard operation
d3-scale copied to clipboard

Add band/point invertExtent.

Open jheer opened this issue 9 years ago • 7 comments

Adds invertExtent method for band and point scales, which can be useful for brushing and linking over ordinal domains. Separated from earlier PR #60.

jheer avatar Jun 08 '16 15:06 jheer

I’d like the documentation to be clearer. Given this representation of bands:

Some questions: Is a band included if [r0, r1] has a non-empty intersection with the band, or does [r0, r1] have to completely cover the band? And are r0 and r1 both treated as inclusive bounds? Is a point scale treated as zero-width bands? If [r0, r1] falls within the padding between bands, does it return an empty array? It’d be helpful to have tests which explicitly state the expected outcome for these cases.

mbostock avatar Jun 08 '16 16:06 mbostock

  1. Non-empty intersection with a band is sufficient for inclusion; r0 and r1 are treated as inclusive bounds. Related cases are included in the submitted tests (e.g., band-test.js#L309).
  2. A point scale is treated as having zero-width bands. Zero bandwidth scales are not explicitly included in the tests, but band boundary tests are.
  3. If the queried range falls entirely within padding, invertExtent returns undefined. This case is included in the submitted tests (e.g., band-test.js#L340, though more detailed comments might be helpful).

jheer avatar Jun 08 '16 18:06 jheer

was there any update on merging this or whether there would be .invert() support for band/point scales? would ❤️ this functionality.

williaster avatar Aug 01 '17 18:08 williaster

@williaster If it is useful to you, we have an updated version of band/point scales included in the vega-scale repo. It includes an invert function in addition to modifications to improve layout consistency. We'd be happy to have those merged here if there is interest.

jheer avatar Aug 01 '17 22:08 jheer

I’ve implemented a demo of ordinal brushing here:

https://observablehq.com/@d3/ordinal-brushing

I used bisectRight as in this PR. One point of awkwardness is x.domain().map(x) to access the underlying ordinal scale’s range. My preference for this type of interaction would be to only select ordinal values based on the middle of the band (in effect, treating band and point scales the same way). I wonder whether the proposed band.invertExtent here could be flexible enough to support different intersection logic, or if some other API is desired?

mbostock avatar Aug 02 '19 22:08 mbostock

After a little more thought, I switched my demo to use a point scale. I think it makes sense for the point scale to consider something selected only if the point is inside the interval, while the band scale would consider something selected if the band intersects the interval, as implemented here. So, I’m down with this approach—I just need to think through the API a little more.

mbostock avatar Aug 02 '19 22:08 mbostock

Any update on this? It'll be really useful to have an invert function for band scales.

AbreezaSaleem avatar Oct 17 '22 18:10 AbreezaSaleem