Renders the HTML representation of the element.
(self, **kwargs)
| 189 | self.position = position |
| 190 | |
| 191 | def render(self, **kwargs): |
| 192 | """Renders the HTML representation of the element.""" |
| 193 | super().render(**kwargs) |
| 194 | |
| 195 | self.json = json.dumps(self.data) |
| 196 | |
| 197 | self._parent.html.add_child( |
| 198 | Element( |
| 199 | Template( |
| 200 | """ |
| 201 | <div id="{{this.get_name()}}"></div> |
| 202 | """ |
| 203 | ).render(this=self, kwargs=kwargs) |
| 204 | ), |
| 205 | name=self.get_name(), |
| 206 | ) |
| 207 | |
| 208 | self._parent.script.add_child( |
| 209 | Element( |
| 210 | Template( |
| 211 | """ |
| 212 | vega_parse({{this.json}},{{this.get_name()}}); |
| 213 | """ |
| 214 | ).render(this=self) |
| 215 | ), |
| 216 | name=self.get_name(), |
| 217 | ) |
| 218 | |
| 219 | figure = self.get_root() |
| 220 | assert isinstance( |
| 221 | figure, Figure |
| 222 | ), "You cannot render this Element if it is not in a Figure." |
| 223 | |
| 224 | figure.header.add_child( |
| 225 | Element( |
| 226 | Template( |
| 227 | """ |
| 228 | <style> #{{this.get_name()}} { |
| 229 | position : {{this.position}}; |
| 230 | width : {{this.width[0]}}{{this.width[1]}}; |
| 231 | height: {{this.height[0]}}{{this.height[1]}}; |
| 232 | left: {{this.left[0]}}{{this.left[1]}}; |
| 233 | top: {{this.top[0]}}{{this.top[1]}}; |
| 234 | </style> |
| 235 | """ |
| 236 | ).render(this=self, **kwargs) |
| 237 | ), |
| 238 | name=self.get_name(), |
| 239 | ) |
| 240 | |
| 241 | figure.script.add_child( |
| 242 | Template( |
| 243 | """function vega_parse(spec, div) { |
| 244 | vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}""" |
| 245 | ), # noqa |
| 246 | name="vega_parse", |
| 247 | ) |
| 248 |
no test coverage detected