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

Add ChartState for managing interactive chart state in Python #426

Closed jonmmease closed 7 months ago

jonmmease commented 7 months ago

This PR adds a new vf.runtime.new_chart_state Python method which returns an instance of a ChartState Python class. The ChartState stores a copy of the TaskGraph that corresponds to the chart and provides an update method that can be used to update the task graph and return updates that should be made to the displayed visualization.

This is a step toward replacing VegaFusionWidget with Altair's own JupyterChart. My goal is that eventually the built-in Altair JuptyerChart will be able to optionally support VegaFusionWidget's current functionality. To accomplish this, JupyterChart will construct a ChartState and use it to determine what callbacks to install in the displayed Vega visualization, and will determine what properties to update in response to interactions.

A big advantage of this approach is that the chart state maintains references to any inline datasets, so it's not necessary to write inline datasets to arrow files on disk. Everything can stay in memory. This also means that non-pandas Datasets (Like SqlDataset) will be compatible with the widget configuration.

Another advantage over VegaFusionWidget is that it will be possible to use JupyterChart's support for accessing selections and params while enjoying VegaFusion's serverside scaling.