Skip to content
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

Exception is raised when intervalXY is used on cells #204

Open
RyanChapman2x opened this issue Oct 18, 2023 · 1 comment
Open

Exception is raised when intervalXY is used on cells #204

RyanChapman2x opened this issue Oct 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@RyanChapman2x
Copy link

The underlying issue is that the invert.js code expects a scale.invert function. But cell marks use d3.scaleBand, which doesn't have a invert function. Here's a quick monkeypatch/proof-of-concept fix (I don't make any adjustments for pixelSize; also note that this won't work if the domain isn't sorted low to high):

invert.js

export function invert(value, scale, pixelSize = 1) {
  if (scale.type == 'band') {
    return Math.round(( (value - scale.range[0]) / (scale.range[1] - scale.range[0]) ) * (scale.domain.slice(-1) - scale.domain[0]));
  } else {
    return scale.invert(pixelSize * Math.floor(value / pixelSize));
  }
}
@jheer jheer added the enhancement New feature or request label Oct 18, 2023
@jheer
Copy link
Member

jheer commented Oct 18, 2023

Thanks! And, yes, this is a known limitation. Interval interactors are currently only valid over a continuous domain.

Long ago in Vega I implemented inversion methods for ordinal band and point scales, but they were not accepted into D3 and so unfortunately not available by default here, either. We could consider bringing custom logic into the interval implementation, assuming we can properly accept the scale type. Or, at minimum, we should check the scale type and proactively raise helpful error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants