facet wrap - #332
facet wrap#332Fil wants to merge 1 commit into
Conversation
|
After talking with @Fil it seems that the |
4b456a6 to
06d224e
Compare
|
This still needs some work:
|
|
|
|
maybe it makes sense to adopt a syntax where |
|
@Fil what do you think about adding an option to change the number of rows as well? Instead of having a generic |
|
I have added facet wrapping on The labels still have to be added by hand with a (clumsy) selectFirst; I'm not sure how to deal with that yet (ideas welcome). |
89c7d08 to
7140c58
Compare
|
Hi, Not sure if this is helpful, but the solution of the facet_wrap (just like in ggplot2) was actually something I was trying to implement the other day. I ended up having two different svgs and having them side by side. But it would be great if there was a way to do this directly from plot. Basically, the groupings are always on the same axis (either x or y) and then you select the number of columns (or rows). Otherwise, the small facets are too wide but not tall enough, or viceversa. |
7140c58 to
568c856
Compare
|
@irenedelatorre Thanks for the great example. Here's a remake of your chart https://observablehq.com/@fil/faceted-bar-chart-experimental, made with this pull-request. It's not perfect: for example, the facets’ names are still added "by hand". The build is published in the notebook https://observablehq.com/@fil/facet-wrap-332 |
|
That looks great @Fil ! |
|
it's just |
|
sorting facets by x is now addressed in #442 ! |
* empty facets (subset of #332) * test plots * filter facetKeys; pull domain up * where via range * update snapshots; remove unused import * call domain once * remove unused marksIndex Co-authored-by: Mike Bostock <mbostock@gmail.com>
04ad747 to
26a6f1c
Compare
|
rewritten now the facets are sorted (in natural order, unless the sort option is used); |
|
Really appreciate this PR! I am still having a bit of a hard time to understand how control the order of facets. For this example, I'd like to sort by the Average of the value within each facet. |
I'm not sure which value you want to take the average of, but I made a fork that shows how you can use |
ff239fb to
afcccf6
Compare
|
afcccf6 is a complete rewrite against Plot 0.4.3. |
|
here's an example from the community: https://observablehq.com/@osteele/shanghai-lockdown-spring-2022 |
mbostock
left a comment
There was a problem hiding this comment.
I like the way you’ve implemented wrapping here, where faceting on x means rows from top to bottom, and faceting on y means columns from left to right. 👍
The immediate challenge I see with this approach is that it seems to corrupt the meaning of the fx and fy scales (which can be seen by retrieving the computed scales). In the athletes-sport-facet example, without facet wrapping you get:
fx = ({
"type": "band",
"domain": [
"gymnastics",
"weightlifting",
"table tennis",
"wrestling",
"shooting",
"triathlon",
"hockey",
"judo",
"archery",
"golf",
"football",
"badminton",
"cycling",
"boxing",
"equestrian",
"athletics",
"rugby sevens",
"sailing",
"modern pentathlon",
"fencing",
"canoe",
"aquatics",
"taekwondo",
"tennis",
"handball",
"rowing",
"volleyball",
"basketball"
],
"range": [
40,
620
],
"label": "sport",
"align": 0.5,
"round": true,
"paddingInner": 0.1,
"paddingOuter": 0,
"bandwidth": 18,
"step": 20
})fy = nullWith facet wrapping you get
fx = ({
"type": "band",
"domain": [],
"range": [
40,
620
],
"align": 0.5,
"round": true,
"paddingInner": 0.1,
"paddingOuter": 0,
"bandwidth": 133,
"step": 148
})fy = ({
"type": "band",
"domain": [],
"range": [
40,
620
],
"align": 0.5,
"round": true,
"paddingInner": 0.1,
"paddingOuter": 0,
"bandwidth": 133,
"step": 148
})I guess I don’t know what fx and fy should mean in this scenario, because they’re no longer orthogonal when facet wrapping is applied. I suppose a simple thing we could do is to throw an error if you try to access either of these scales when facet wrapping is in use, and just treat that as undefined? Alternatively… I dunno, maybe fy is still null, but fx defines a range with [x, y] position instead of singular position? That kind of makes sense, though wouldn’t that imply that we’d allow you to set the range of the fx scale the same way when faceting is in use? Or maybe we should just leave the range as undefined and not allow you to set the range of facet scales when column wrapping? (I can’t imagine people will want to set the range explicitly anyway, and they don’t need to since you can achieve the same result by setting the dimensions and margins.)
|
superseded by #892 |


fixes #97
fixes #277
supersedes #293
supersedes #101
(I'm giving up on auto facet labels, since there's no good way of deciding where to place them, and they also require changes to the fy padding. This is easier to do with a function mark that places the facet's name where we want. It will be easier even if we pass the facet's name in #501.)
Build: https://observablehq.com/@fil/facet-wrap-332
Note: empty facets is now merged (#516).