Creates a Vega-Lite chart element. Parameters ---------- data: JSON-like str or object The Vega-Lite description of the chart. It can also be any object that has a method `to_json`, so that you can (for instance) provide an `Altair` chart. width: int or
| 248 | |
| 249 | |
| 250 | class VegaLite(MacroElement): |
| 251 | """ |
| 252 | Creates a Vega-Lite chart element. |
| 253 | |
| 254 | Parameters |
| 255 | ---------- |
| 256 | data: JSON-like str or object |
| 257 | The Vega-Lite description of the chart. |
| 258 | It can also be any object that has a method `to_json`, |
| 259 | so that you can (for instance) provide an `Altair` chart. |
| 260 | width: int or str, default None |
| 261 | The width of the output element. |
| 262 | If None, either data['width'] (if available) or '100%' will be used. |
| 263 | Ex: 120, '120px', '80%' |
| 264 | height: int or str, default None |
| 265 | The height of the output element. |
| 266 | If None, either data['width'] (if available) or '100%' will be used. |
| 267 | Ex: 120, '120px', '80%' |
| 268 | left: int or str, default '0%' |
| 269 | The horizontal distance of the output with respect to the parent |
| 270 | HTML object. Ex: 120, '120px', '80%' |
| 271 | top: int or str, default '0%' |
| 272 | The vertical distance of the output with respect to the parent |
| 273 | HTML object. Ex: 120, '120px', '80%' |
| 274 | position: str, default 'relative' |
| 275 | The `position` argument that the CSS shall contain. |
| 276 | Ex: 'relative', 'absolute' |
| 277 | |
| 278 | """ |
| 279 | |
| 280 | _template = Template("") |
| 281 | |
| 282 | def __init__( |
| 283 | self, |
| 284 | data: Any, |
| 285 | width: Union[int, str, None] = None, |
| 286 | height: Union[int, str, None] = None, |
| 287 | left: Union[int, str] = "0%", |
| 288 | top: Union[int, str] = "0%", |
| 289 | position: str = "relative", |
| 290 | ): |
| 291 | super(self.__class__, self).__init__() |
| 292 | self._name = "VegaLite" |
| 293 | self.data = data.to_json() if hasattr(data, "to_json") else data |
| 294 | if isinstance(self.data, str): |
| 295 | self.data = json.loads(self.data) |
| 296 | |
| 297 | self.json = json.dumps(self.data) |
| 298 | |
| 299 | # Size Parameters. |
| 300 | self.width = _parse_size( |
| 301 | self.data.get("width", "100%") if width is None else width |
| 302 | ) |
| 303 | self.height = _parse_size( |
| 304 | self.data.get("height", "100%") if height is None else height |
| 305 | ) |
| 306 | self.left = _parse_size(left) |
| 307 | self.top = _parse_size(top) |