Skip to content
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

Facet wrapping #277

Open
Fil opened this issue Mar 27, 2021 · 5 comments · May be fixed by #892
Open

Facet wrapping #277

Fil opened this issue Mar 27, 2021 · 5 comments · May be fixed by #892
Assignees
Labels
enhancement New feature or request

Comments

@Fil
Copy link
Contributor

Fil commented Mar 27, 2021

We can create a grid facet with:

    x: d => (f(d) % 5),
    y: d => Math.floor(f(d) / 5)

where f returns an integer, maybe d => groups.indexOf(d.group).

Can we make it easier to compute the gridded facet, and to draw its mark)? (In this case we can't use fx/fy for the facet ticks, and also need a way to draw the facet's tick inside or below the frame at a fixed point.)

Examples:

Capture d’écran 2021-03-27 à 18 44 33

https://observablehq.com/d/61ca1967e419b882

Capture d’écran 2021-01-14 à 18 19 45
https://observablehq.com/@data-workflows/geofacet & #101

@Fil Fil added the enhancement New feature or request label Mar 27, 2021
@Fil Fil self-assigned this Mar 27, 2021
Fil added a commit that referenced this issue Apr 2, 2021
We still have to struggle a bit to remove the automatic (and now meaningless) facet labels, and position our own facet labels in each frame.
@Fil Fil mentioned this issue Apr 2, 2021
1 task
Fil added a commit that referenced this issue Apr 13, 2021
We still have to struggle a bit to remove the automatic (and now meaningless) facet labels, and position our own facet labels in each frame.
@Fil Fil mentioned this issue Apr 19, 2021
3 tasks
@Fil
Copy link
Contributor Author

Fil commented May 20, 2021

@mbostock mbostock changed the title Grid faceting Facet wrapping Dec 1, 2022
@mbostock
Copy link
Member

mbostock commented Dec 2, 2022

I retitled this to “facet wrap” since that seems to be the more common term for this. We made an attempt in #332 and in #892 but haven’t yet landed anything. The main issue seems to be how we represent the fx and fy scales/axes.

@mbostock mbostock linked a pull request Apr 1, 2023 that will close this issue
@tophtucker
Copy link
Contributor

I almost wonder if this should be an fz channel, since it uses both x and y? Hm… but I guess it still has a directional bias because it either goes left-right before wrapping or top-down before wrapping.

@mbostock
Copy link
Member

Here is a new example. https://observablehq.com/@observablehq/plot-facet-wrap

untitled (64)

Plot.plot((() => {
  const n = 3; // number of facet columns
  const keys = Array.from(d3.union(industries.map((d) => d.industry)));
  const index = new Map(keys.map((key, i) => [key, i]));
  const fx = (key) => index.get(key) % n;
  const fy = (key) => Math.floor(index.get(key) / n);
  return {
    height: 300,
    axis: null,
    y: {insetTop: 10},
    fx: {padding: 0.03},
    marks: [
      Plot.areaY(industries, Plot.normalizeY("extent", {
        x: "date",
        y: "unemployed",
        fx: (d) => fx(d.industry),
        fy: (d) => fy(d.industry)
      })),
      Plot.text(keys, {fx, fy, frameAnchor: "top-left", dx: 6, dy: 6}),
      Plot.frame()
    ]
  };
})())

@fgregg
Copy link

fgregg commented Jul 10, 2023

i'd really appreciate if the wrap columns could adjust based on the width of the viewport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants