-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add mimetype renderer #195
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rename vf.jupyter.enable to vf.jupyter.enable_widget()
Add top-level vf.enable_mime()/enable_widget() methods
…e transforms on a Chart
3 tasks
This reverts commit 9b0bb4d.
Sharing a reqwest Client across tokio runtimes can result in "dispatch dropped without returning error" error. This removes the lazy_static client and reconstructs the client on demand
Looks great! Question, will the following also work?: with vf.enable_mime(mimetype="html"): # or similar
chart |
No, but that's a good idea! #200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a new Altair data transformer and renderer for displaying pre-transformed Vega specifications using standard Jupyter renderers (
vega
,html
,svg
, andpng
).This renderer provides most of the benefits of VegaFusion without requiring the custom
VegaFusionWidget
renderer.Usage
The new data transformer and renderer are activated using the
vegafusion.enable_mime()
function.Other supported
mimetype
values arevega
,svg
, andpng
How it works
The mimetype renderer uses an approach that is very different than the existing Jupyter Widget-based renderer.
Here is an outline of the process
1.
vegafusion-inline
data transformerInline DataFrames are extracted into a global
dict
by the newvegafusion-inline
data transformer. The DataFrames are replaced by VegaFusion inline dataset URLs (e.g.vegafusion+dataset://table-{uuid}
). This prevents DataFrames from being serialized directly to JSON.2. compile Vega-Lite to Vega
The
vegafusion-mime
renderer inputs a Vega-Lite spec that has already gone through step 1. In compiles the Vega-Lite to a Vega spec using the active plugin in the newvf.vegalite_compilers
plugin registry. The default plugin usesvl-convert
to perform the conversion, but it's possible to register custom compilation functions as well.3. Pre-transform Vega spec
The Vega spec that results from step 2 is processed using the
vegafusion.runtime.pre_transform_spec
function. This function inputs a Vega spec, and DataFrames extracted in step 1, extracts and evaluates as many transforms as possible, and then produces a new Vega spec with the transformed data inlined.Unlike the
VegaFusionWidget
renderer, the resulting Vega spec does not require communication with the server to maintain interactivity. All of the data required for interactivity is inlined in the pre-transformed Vega spec. The benefit is that this pre-transformed spec can be renderered just like a normal Vega spec.4. Produce mime bundle
The renderer uses this pre-transformed Vega spec to generate mimetype bundles for the various mime types. The default mime type is
"text/html"
, which works in the classic Jupyter Notebook and JupyterLab. The"application/vnd.vega.v5+json"
mime type works in JupyterLab and other environments that provide a Vega mimetype renderer. The"image/svg+xml"
mimetype uses vl-convert to convert the pre-transformed Vega spec to an SVG image and similarly the"image/png"
mimetype uses vl-convert to create a PNG image.What's the benefit?
Here are three examples that demonstrate the benefit of using the VegaFusion mime renderer compared to the default Altair renderer. The specs themselves are below, but I thought it would be easier to walk through the benefits in a screencast.
https://www.loom.com/share/094b3958ffad49bdaa3a7af19f26370b
Example 1: Aggregated chart
Example 2: Non-aggregated scatter chart
Example 3: Interactive Chart
Comparison to the widget renderer.
The existing VegaFusion renderer can be enabled using
vegfusion.jupyter.enable()
or (now in this PR)vegafusion.enable_widget()
. Here are some details on how the two renderers compar._vegafusion_data
directory while the mime renderer handles everything in memory without temporary files