Renders the HTML representation of the element.
(self, **kwargs)
| 1209 | ) |
| 1210 | |
| 1211 | def render(self, **kwargs): |
| 1212 | """Renders the HTML representation of the element.""" |
| 1213 | figure = self.get_root() |
| 1214 | if isinstance(self._parent, GeoJson): |
| 1215 | keys = tuple( |
| 1216 | self._parent.data["features"][0]["properties"].keys() |
| 1217 | if self._parent.data["features"] |
| 1218 | else [] |
| 1219 | ) |
| 1220 | self.warn_for_geometry_collections() |
| 1221 | elif isinstance(self._parent, TopoJson): |
| 1222 | obj_name = self._parent.object_path.split(".")[-1] |
| 1223 | keys = tuple( |
| 1224 | self._parent.data["objects"][obj_name]["geometries"][0][ |
| 1225 | "properties" |
| 1226 | ].keys() |
| 1227 | ) |
| 1228 | else: |
| 1229 | raise TypeError( |
| 1230 | f"You cannot add a {self._name} to anything other than a " |
| 1231 | "GeoJson or TopoJson object." |
| 1232 | ) |
| 1233 | keys = tuple(x for x in keys if x not in ("style", "highlight")) |
| 1234 | for value in self.fields: |
| 1235 | assert ( |
| 1236 | value in keys |
| 1237 | ), f"The field {value} is not available in the data. Choose from: {keys}." |
| 1238 | figure.header.add_child( |
| 1239 | Element( |
| 1240 | Template( |
| 1241 | """ |
| 1242 | <style> |
| 1243 | .{{ this.class_name }} { |
| 1244 | {{ this.style }} |
| 1245 | } |
| 1246 | .{{ this.class_name }} table{ |
| 1247 | margin: auto; |
| 1248 | } |
| 1249 | .{{ this.class_name }} tr{ |
| 1250 | text-align: left; |
| 1251 | } |
| 1252 | .{{ this.class_name }} th{ |
| 1253 | padding: 2px; padding-right: 8px; |
| 1254 | } |
| 1255 | </style> |
| 1256 | """ |
| 1257 | ).render(this=self) |
| 1258 | ), |
| 1259 | name=self.get_name() + "tablestyle", |
| 1260 | ) |
| 1261 | |
| 1262 | super().render() |
| 1263 | |
| 1264 | |
| 1265 | class GeoJsonTooltip(GeoJsonDetail): |
nothing calls this directly
no test coverage detected