microsoft / datamations

https://microsoft.github.io/datamations/
Other
67 stars 14 forks source link

Hack faceted vega specs to build fake faceted view in a single plot #32

Closed giorgi-ghviniashvili closed 3 years ago

giorgi-ghviniashvili commented 3 years ago

@jhofman that's the new issue we talked about

jhofman commented 3 years ago

Ideally this could take as input a vegalite spec with a facet specification, then convert it on the javascript side to a vegalite spec with only one set of axes that fakes the facets. this could be done by reading off pixel locations from the original spec that never gets shown to the user, just gets used to read off pixel coordinates and create new x/y data for the gemini-compatible spec.

There's the issue of how to label the facets---either by making the axes continuous and the labels as annotations on top of them, or as a discrete scale with the facet labels as axis labels and the x/y points made to fit in the right way.

giorgi-ghviniashvili commented 3 years ago

@jhofman I think @sharlagelfand has done it on R side to fake the facets, can we ask her to either show the code or describe what exact was done?

jhofman commented 3 years ago

sure, although i think the way this is done in R is very R-specific, by reading off of a ggplot object.

i imagine this would be different in vegalite. my best guess would be this, unless there's a cleaner way: create an invisible div, use vegalite to render the faceted spec there. then select that div and pull out the x/y coordinates of all of the points that were rendered. make a new dataset out of that, and a new non-faceted spec containing that dataset. then render that using gemini.

make sense?

giorgi-ghviniashvili commented 3 years ago

Yes, that makes sense.

Couple of issues:

giorgi-ghviniashvili commented 3 years ago

vegaEmbed("#vis", spec, {renderer: "svg"}) - draws on svg.

giorgi-ghviniashvili commented 3 years ago

https://github.com/vega/vega-view#view_data - interesting method

giorgi-ghviniashvili commented 3 years ago

Accessing internal scale: image

giorgi-ghviniashvili commented 3 years ago

hey @jhofman , I managed to hack faceted view and create non faceted view.

Demo

Some notes:

giorgi-ghviniashvili commented 3 years ago

@jhofman then I applied same code to colored facet and got this. Pretty impressed. I am going to add annotations and then try to animation it with gemini!

giorgi-ghviniashvili commented 3 years ago

Perfect! added labels as well with some extra padding around groups:

image

Used same technique from @sharlagelfand 's comment in #25 .

giorgi-ghviniashvili commented 3 years ago

Hi @jhofman , here is the original work-degree animation with fake facets: https://rawcdn.githack.com/jhofman/datamations/gio/d3/sandbox/vega-gemini/work-degree/facets.html?version=0.2

giorgi-ghviniashvili commented 3 years ago

Even with gemini recommendations it has some weird errors... Or does not correctly show axis on animation while drawing with vega is ok with axis and stuff.

jhofman commented 3 years ago

Just linking to #33. Next up is to debug the axis annotations not showing up for the last two frames of the work-degree animation (distribution and mean).

jhofman commented 3 years ago

Also linking this to #23, see there for more.

jhofman commented 3 years ago

@giorgi-ghviniashvili: noticed that when we have a nominal or ordinal variable on the x axis with fake facets, the x axis isn't "centered".

so for instance, with the penguins data and sex on the x axis, the x axis goes from 0 to 3, and since the x data goes from 1 to 3, everything looks like it's shifted to the right a bit in the facet instead of centered in the facet.

can you adjust this so that things are centered horizontally within the facets? for instance in this case, maybe the x axis goes from 0.5 to 3.5?