Creates a Vega chart element. Parameters ---------- data: JSON-like str or object The Vega description of the chart. It can also be any object that has a method `to_json`, so that you can (for instance) provide a `vincent` chart. width: int or str, defau
| 125 | |
| 126 | |
| 127 | class Vega(JSCSSMixin): |
| 128 | """ |
| 129 | Creates a Vega chart element. |
| 130 | |
| 131 | Parameters |
| 132 | ---------- |
| 133 | data: JSON-like str or object |
| 134 | The Vega description of the chart. |
| 135 | It can also be any object that has a method `to_json`, |
| 136 | so that you can (for instance) provide a `vincent` chart. |
| 137 | width: int or str, default None |
| 138 | The width of the output element. |
| 139 | If None, either data['width'] (if available) or '100%' will be used. |
| 140 | Ex: 120, '120px', '80%' |
| 141 | height: int or str, default None |
| 142 | The height of the output element. |
| 143 | If None, either data['width'] (if available) or '100%' will be used. |
| 144 | Ex: 120, '120px', '80%' |
| 145 | left: int or str, default '0%' |
| 146 | The horizontal distance of the output with respect to the parent |
| 147 | HTML object. Ex: 120, '120px', '80%' |
| 148 | top: int or str, default '0%' |
| 149 | The vertical distance of the output with respect to the parent |
| 150 | HTML object. Ex: 120, '120px', '80%' |
| 151 | position: str, default 'relative' |
| 152 | The `position` argument that the CSS shall contain. |
| 153 | Ex: 'relative', 'absolute' |
| 154 | |
| 155 | """ |
| 156 | |
| 157 | _template = Template("") |
| 158 | |
| 159 | default_js = [ |
| 160 | ("d3", "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"), |
| 161 | ("vega", "https://cdnjs.cloudflare.com/ajax/libs/vega/1.4.3/vega.min.js"), |
| 162 | ("jquery", "https://code.jquery.com/jquery-3.7.1.min.js"), |
| 163 | ] |
| 164 | |
| 165 | def __init__( |
| 166 | self, |
| 167 | data: Any, |
| 168 | width: Union[int, str, None] = None, |
| 169 | height: Union[int, str, None] = None, |
| 170 | left: Union[int, str] = "0%", |
| 171 | top: Union[int, str] = "0%", |
| 172 | position: str = "relative", |
| 173 | ): |
| 174 | super().__init__() |
| 175 | self._name = "Vega" |
| 176 | self.data = data.to_json() if hasattr(data, "to_json") else data |
| 177 | if isinstance(self.data, str): |
| 178 | self.data = json.loads(self.data) |
| 179 | |
| 180 | # Size Parameters. |
| 181 | self.width = _parse_size( |
| 182 | self.data.get("width", "100%") if width is None else width |
| 183 | ) |
| 184 | self.height = _parse_size( |