Skip to content

Continuous color ranges with more than two elements are handled inconsistently #1632

Closed
@mbostock

Description

@mbostock

Below the domain implicitly has two elements [0, 39] while the specified range has three [red, green, blue]. The intended behavior is that the third element green in the range is ignored. However, the color legend incorrectly shows all three colors.

Screenshot 2023-05-24 at 12 42 39 PM
plot = Plot.plot({
  color: {
    legend: true,
    type: "linear",
    range: ["red", "blue", "green"]
  },
  marks: [
    Plot.cellX(d3.range(40), {fill: Plot.identity})
  ]
})

In addition, the exposed color scale incorrectly shows a three-element range:

plot.scale("color").range // ["red", "blue", "green"]

If the domain of the same length is specified, the piecewise color scale works fine. It’s only a problem when the two don’t match.

Screenshot 2023-05-24 at 12 44 24 PM
Plot.plot({
  color: {
    legend: true,
    type: "linear",
    domain: [0, 39 / 2, 39],
    range: ["red", "blue", "green"]
  },
  marks: [
    Plot.cellX(d3.range(40), {fill: Plot.identity})
  ]
})

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