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

Domain nicing may break when zero: true #2634

Open
domoritz opened this issue May 20, 2020 · 4 comments
Open

Domain nicing may break when zero: true #2634

domoritz opened this issue May 20, 2020 · 4 comments
Assignees
Labels
bug For bugs or other software errors

Comments

@domoritz
Copy link
Member

Notice how in the example below, the domain is not nice when zero: true.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 200,
  "height": 20,
  "padding": 5,
  "scales": [
    {
      "name": "scale1",
      "domain": [90, 210],
      "nice": 2,
      "range": "width"
    },
    {
      "name": "scale2",
      "domain": [90, 210],
      "nice": 2,
      "range": "width",
      "zero": false
    }
  ],
  "axes": [
    { "orient": "top", "scale": "scale1", "tickCount": 2},
    { "orient": "bottom", "scale": "scale2", "tickCount": 2}
  ]
}

image

Open the Chart in the Vega Editor

@domoritz domoritz added the bug For bugs or other software errors label May 20, 2020
@domoritz
Copy link
Member Author

The issue seems to be that linear scales nice domains differently when the first value is small or not.

$ d3.scaleLinear().domain([60,210]).nice(2).domain()
[0,400]

$ d3.scaleLinear().domain([70,210]).nice(2).domain()
[0,300]

I would expect that both domains produce the same niced domain as they are both contained within the niced domain of the other.

Try at https://observablehq.com/d/ff5a76630225a0bb

Screen Shot 2020-05-19 at 19 58 22

@domoritz
Copy link
Member Author

domoritz commented May 20, 2020

The issue with the code above is that ticks generated from the niced domain do not surround the domain anymore.

$ d3
  .scaleLinear()
  .domain([70, 210])
  .nice(2)
  .ticks(2)
[0,200]

Should I expect this to work or am I misunderstanding what nicing is supposed to do?

The d3 docs say about nice "An optional tick count argument allows greater control over the step size used to extend the bounds, guaranteeing that the returned ticks will exactly cover the domain."

I filed this as d3/d3-scale#209.

@jheer
Copy link
Member

jheer commented May 20, 2020

The Scale transform in vega-encode is the primary contact point, where we invoke d3’s nice function. This looks like a potential d3-scale issue, so that’s the right place to file. What we do in Vega is pre-process the domain (ensuring zero as needed, any domain padding, etc) then invoke nice if the scale definition specifies it.

I wonder if the specific tick count argument (2) drives the behavior here.

@domoritz domoritz self-assigned this May 20, 2020
@domoritz
Copy link
Member Author

Confirmed bug and we have a fix in d3/d3-scale#210. I'll leave this issue open so we make sure to update Vega once the fix is out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For bugs or other software errors
Projects
None yet
Development

No branches or pull requests

2 participants