/
vega.py
53 lines (42 loc) · 1.57 KB
/
vega.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Defines custom VegaPlot bokeh model to render Vega json plots.
"""
from bokeh.core.properties import (
Any, Bool, Dict, Enum, Instance, Nullable, String
)
from bokeh.models import LayoutDOM, ColumnDataSource
from ..io.resources import bundled_files
from ..util import classproperty
class VegaPlot(LayoutDOM):
"""
A Bokeh model that wraps around a Vega plot and renders it inside
a Bokeh plot.
"""
__javascript_raw__ = [
"https://cdn.jsdelivr.net/npm/vega@5",
'https://cdn.jsdelivr.net/npm/vega-lite@4',
'https://cdn.jsdelivr.net/npm/vega-embed@6'
]
@classproperty
def __javascript__(cls):
return bundled_files(cls)
@classproperty
def __js_skip__(cls):
return {
'vega': cls.__javascript__[:1],
'vegaLite': cls.__javascript__[1:2],
'vegaEmbed': cls.__javascript__[2:]
}
__js_require__ = {
'paths': {
"vega-embed": "https://cdn.jsdelivr.net/npm/vega-embed@6/build/vega-embed.min",
"vega-lite": "https://cdn.jsdelivr.net/npm/vega-lite@4/build/vega-lite.min",
"vega": "https://cdn.jsdelivr.net/npm/vega@5/build/vega.min"
},
'exports': {'vega-embed': 'vegaEmbed', 'vega': 'vega', 'vega-lite': 'vl'}
}
data = Nullable(Dict(String, Any))
data_sources = Dict(String, Instance(ColumnDataSource))
show_actions = Bool(False)
theme = Nullable(Enum('excel', 'ggplot2', 'quartz', 'vox', 'fivethirtyeight', 'dark',
'latimes', 'urbaninstitute', 'googlecharts', default=None))