@@ -316,10 +316,13 @@ def __init__(self, data, object_path):
316
316
super (TopoJson , self ).__init__ ()
317
317
self ._name = 'TopoJson'
318
318
if 'read' in dir (data ):
319
+ self .embed = True
319
320
self .data = data .read ()
320
321
elif type (data ) is dict :
322
+ self .embed = True
321
323
self .data = json .dumps (data )
322
324
else :
325
+ self .embed = False
323
326
self .data = data
324
327
325
328
self .object_path = object_path
@@ -349,8 +352,33 @@ def _get_self_bounds(self):
349
352
"""Computes the bounds of the object itself (not including it's children)
350
353
in the form [[lat_min, lon_min], [lat_max, lon_max]]
351
354
"""
352
- raise NotImplementedError
353
- return [[self .location [0 ],self .location [1 ]],[self .location [0 ],self .location [1 ]]]
355
+ if not self .embed :
356
+ raise ValueError ('Cannot compute bounds of non-embedded TopoJSON.' )
357
+
358
+ data = json .loads (self .data )
359
+
360
+ xmin ,xmax ,ymin ,ymax = None , None , None , None
361
+
362
+ for arc in data ['arcs' ]:
363
+ x ,y = 0 ,0
364
+ for dx , dy in arc :
365
+ x += dx
366
+ y += dy
367
+ xmin = none_min (x , xmin )
368
+ xmax = none_max (x , xmax )
369
+ ymin = none_min (y , ymin )
370
+ ymax = none_max (y , ymax )
371
+ return [
372
+ [
373
+ data ['transform' ]['translate' ][0 ] + data ['transform' ]['scale' ][0 ] * xmin ,
374
+ data ['transform' ]['translate' ][1 ] + data ['transform' ]['scale' ][1 ] * ymin ,
375
+ ],
376
+ [
377
+ data ['transform' ]['translate' ][0 ] + data ['transform' ]['scale' ][0 ] * xmax ,
378
+ data ['transform' ]['translate' ][1 ] + data ['transform' ]['scale' ][1 ] * ymax ,
379
+ ]
380
+
381
+ ]
354
382
355
383
class ColorScale (MacroElement ):
356
384
def __init__ (self , color_domain , color_code , caption = "" ):
0 commit comments