Skip to content

The rect mark could work better with band scales #1899

Closed
@mbostock

Description

@mbostock

Currently the rect mark is a bit pedantic regarding band scales — it generally requires that you specify x1, x2, y1, y2 explicitly. So in a situation like this, you see nothing:

untitled (99)

Plot.plot({
  marks: [
    Plot.rectX(data, {x1: "start", x2: "end", y: "name"})
  ]
})

You have to switch to barX to see what you likely intend:

untitled (100)

Plot.plot({
  marks: [
    Plot.barX(data, {x1: "start", x2: "end", y: "name"})
  ]
})

A related question is whether we could automatically infer the band scale for y (rather than the default point). That would also be necessary for the rect to appear.

Another possibility, to at least show something that maybe guides someone to a better outcome, would be to apply default negative insets in the case whether the rect would otherwise have zero width or height.

untitled - 2023-10-20T111404 886

Plot.plot({
  marks: [
    Plot.rectX(data, {x1: "start", x2: "end", y: "name", inset: -0.5})
  ]
})

Notebook: https://observablehq.com/d/87107ffe90ae73be

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions