Skip to content

The axis mark doesn’t support the filter option #1457

Closed
@mbostock

Description

@mbostock

It’d be nice if the filter option worked after the axis initializer so that you can easily filter ticks. For example here I want some ticks to use the left anchor, and others to use the right anchor:

Screenshot 2023-04-16 at 3 30 39 PM

Plot.plot({
  label: null,
  x: {
    axis: "top",
    grid: true,
    label: "← decrease · Change in population, 2010–2019 (%) · increase →",
    labelAnchor: "center",
    tickFormat: "+",
    percent: true
  },
  color: {
    scheme: "PiYg",
    type: "ordinal"
  },
  marks: [
    Plot.barX(statepop, {y: "State", x: (d) => (d[2019] - d[2010]) / d[2010], fill: (d) => Math.sign(d[2019] - d[2010]), sort: {y: "x"}}),
    Plot.axisY(statepop.filter((d) => d[2019] >= d[2010]).map((d) => d.State), {x: 0}),
    Plot.axisY(statepop.filter((d) => d[2019] < d[2010]).map((d) => d.State), {x: 0, anchor: "right"}),
    Plot.gridX({stroke: "var(--vp-c-bg)", strokeOpacity: 0.5}),
    Plot.ruleX([0])
  ]
})

I can do it by passing the tick values to the axis mark constructor, but I think using the filter option would be more intuitive. The reason that it crashes right now is that the default tick values aren’t known until the axis mark’s initializer runs (after all transforms). So, the axis mark would probably need to pull out the filter option and run it after the built-in initializer.

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