plot icon indicating copy to clipboard operation
plot copied to clipboard

The rect mark should be aware of the interval scale option

Open mbostock opened this issue 2 years ago • 1 comments

Related #1511, the rect mark isn’t aware of the interval scale option, so this produces an empty chart:

untitled (87)

Plot.plot({
  x: { interval: 1, tickFormat: "d" },
  y: { interval: 5 },
  color: { type: "log" },
  marks: [
    Plot.rect(causes, {
      x: "year",
      y: "age",
      fill: "mx",
      tip: true
    })
  ]
})

You need to pass the interval option to the rect mark explicitly to get the desired result:

untitled (86)

Plot.plot({
  x: { tickFormat: "d" },
  color: { type: "log" },
  marks: [
    Plot.rect(causes, {
      x: { value: "year", interval: 1 },
      y: { value: "age", interval: 5 },
      fill: "mx",
      tip: true
    })
  ]
})

But, since the plot options are passed to the rect mark during initialization, it should be possible to do this automatically. 🤔

I think this affects maybeIntervalK and maybeIntervalMidK: rather than exclusively creating channel transforms based on the passed-in interval option, we need a mark transform to compute the interval’d channels so that we can look at the plot options.

mbostock avatar Sep 17 '23 16:09 mbostock

The cell mark also works well as-is:

untitled (88)

Plot.plot({
  padding: 0,
  x: { interval: 1, tickFormat: "d" },
  y: { interval: 5, reverse: true },
  color: { type: "log" },
  marks: [
    Plot.cell(causes, {
      x: "year",
      y: "age",
      fill: "mx",
      tip: true
    })
  ]
})

mbostock avatar Sep 17 '23 16:09 mbostock