@@ -316,10 +316,13 @@ def __init__(self, data, object_path):
316316 super (TopoJson , self ).__init__ ()
317317 self ._name = 'TopoJson'
318318 if 'read' in dir (data ):
319+ self .embed = True
319320 self .data = data .read ()
320321 elif type (data ) is dict :
322+ self .embed = True
321323 self .data = json .dumps (data )
322324 else :
325+ self .embed = False
323326 self .data = data
324327
325328 self .object_path = object_path
@@ -349,8 +352,33 @@ def _get_self_bounds(self):
349352 """Computes the bounds of the object itself (not including it's children)
350353 in the form [[lat_min, lon_min], [lat_max, lon_max]]
351354 """
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+ ]
354382
355383class ColorScale (MacroElement ):
356384 def __init__ (self , color_domain , color_code , caption = "" ):
0 commit comments