Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mbostock opened this issue Apr 16, 2023 · 0 comments · Fixed by #1665
Closed

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

mbostock opened this issue Apr 16, 2023 · 0 comments · Fixed by #1665
Labels
bug Something isn’t working

Comments

@mbostock
Copy link
Member

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.

@mbostock mbostock added the bug Something isn’t working label Apr 16, 2023
Fil added a commit that referenced this issue Jun 1, 2023
Add an explicit error message if using the sort and reverse option

closes #1457
closes #1655
Fil added a commit that referenced this issue Jun 27, 2023
Add an explicit error message if using the sort and reverse option

closes #1457
closes #1655
@Fil Fil closed this as completed in #1665 Jun 28, 2023
Fil added a commit that referenced this issue Jun 28, 2023
* Axes and grids now support {filter, sort, reverse}

closes #1457
closes #1655
Fil added a commit that referenced this issue Aug 21, 2023
* Axes and grids now support {filter, sort, reverse}

closes #1457
closes #1655
chaichontat pushed a commit to chaichontat/plot that referenced this issue Jan 14, 2024
* Axes and grids now support {filter, sort, reverse}

closes observablehq#1457
closes observablehq#1655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant