1. Extract Vega Lite.ipynb
We have packaged extractTransform
from Vega Lite up as a mime renderer:
In [14]:
from IPython.display import display
from omnisci_renderer import VegaLite, extract_spec, EMPTY_SPEC
Let's use this example vega lite, which we put in a class so that it is rendered:
In [15]:
SPEC = VegaLite({
"data": {
"url": "https://vega.github.io/vega-lite/data/seattle-weather.csv"
},
"layer": [
{
"mark": "bar",
"encoding": {
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"y": {
"aggregate": "mean",
"field": "precipitation",
"type": "quantitative",
"axis": {
"grid": False
}
}
}
},
{
"mark": "line",
"encoding": {
"x": {
"timeUnit": "month",
"field": "date",
"type": "ordinal"
},
"y": {
"aggregate": "mean",
"field": "temp_max",
"type": "quantitative",
"axis": {
"grid": False
},
"scale": {
"zero": False
}
},
"color": {
"value": "firebrick"
}
}
}
],
"resolve": {
"scale": {
"y": "independent"
}
}
})
SPEC
Out[15]:
Now, let's transform this spec usingextractTransform
and render the result and save it:
In [18]:
from IPython.display import display
import IPython.display
display_id = display(VegaLite(EMPTY_SPEC), display_id=True)
UDPATED_SPEC = None
def on_transformed(updated):
global UDPATED_SPEC
UDPATED_SPEC = updated
display_id.update(VegaLite(updated))
extract_spec(SPEC.data, on_transformed)
Now let's look at the updated spec:
In [19]:
UDPATED_SPEC
Out[19]: