vega / vegafusion

Serverside scaling for Vega and Altair visualizations
https://vegafusion.io
BSD 3-Clause "New" or "Revised" License
303 stars 15 forks source link

Support aggregate transforms in facet group marks #411

Closed jonmmease closed 8 months ago

jonmmease commented 8 months ago

Overview

This PR adds support for extracting aggregate transforms from facet charts so that they can be evaluated using the regular VegaFusion machinery.

Closes https://github.com/hex-inc/vegafusion/issues/370

Approach

After thinking through the approaches I discussed in #370, I developed an alternative approach that doesn't require giving the planner access to the input data to manually expand the facet into a list of group marks. The approach this PR takes is to handle the special (common) case of facet marks that define a transform pipeline where the first transform is aggregate. This single transform can be lifted out of the facet with the modification that the groupby fields are augmented with the facet's groupby fields. Any remaining transforms after aggregate are left inside the facet to be evaluated in the client with Vega.js.

Additionally, this PR handles the case where the facet defines custom aggregate fields. This is most commonly used when sorting facets by aggregate values in Vega-Lite. In this case a joinaggregate transform is inserted prior to the lifted aggregate transform.

In the uncommon case of a facet dataset being used by multiple child datasets, aggregate lifting is not performed.