Skip to content

The axis mark requires a range interval, but doesn’t check for it #1331

Closed
@mbostock

Description

@mbostock

For example, if you say

Plot.plot({
  x: {
    domain: [0, 10],
    interval: {
      floor: (x) => Math.floor(x),
      offset: (x, offset = 1) => x + offset
    }
  }
})

you get

TypeError: interval.range is not a function

here

data = interval.range(min, interval.offset(interval.floor(max))); // inclusive max

You can fix the problem like so

Screenshot 2023-03-13 at 5 51 20 PM

Plot.plot({
  x: {
    domain: [0, 10],
    interval: <Plot.RangeInterval>{
      floor: (x) => Math.floor(x),
      offset: (x, offset = 1) => x + offset,
      range: (x1, x2) => d3.range(x1, x2)
    }
  }
})

but you need the type declaration to avoid a lint error, since ScaleOptions["interval"] is also erroneously an Interval instead of a RangeInterval. Though, there are some cases like with ordinal scales where a plain Interval may be allowable?

We should decide whether a range interval is required for the ScaleOptions["interval"] option. If it’s not, then the axis mark should gracefully handle the interval not implementing interval.range. If it is, then the axis mark should throw a nicer “invalid interval” error message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn’t working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions