@@ -3100,6 +3100,7 @@ def boxes_to_tex(self, leaves=None, **options):
31003100
31013101 return tex
31023102
3103+ # FIXME: figure out how to move this to the SVG formatter
31033104 def to_svg (self , leaves = None , ** options ):
31043105 if not leaves :
31053106 leaves = self ._leaves
@@ -3117,18 +3118,19 @@ def to_svg(self, leaves=None, **options):
31173118
31183119 format_fn = lookup_method (elements , "svg" )
31193120 if format_fn is not None :
3120- svg = format_fn (elements , offset = options .get ("offset" , None ))
3121+ svg_body = format_fn (elements , offset = options .get ("offset" , None ))
31213122 else :
3122- svg = elements .to_svg (offset = options .get ("offset" , None ))
3123+ svg_body = elements .to_svg (offset = options .get ("offset" , None ))
31233124
31243125 if self .background_color is not None :
3125- svg = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % (
3126+ # Wrap svg_elements in a rectangle
3127+ svg_body = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % (
31263128 xmin ,
31273129 ymin ,
31283130 w ,
31293131 h ,
31303132 self .background_color .to_css ()[0 ],
3131- svg ,
3133+ svg_body ,
31323134 )
31333135
31343136 xmin -= 1
@@ -3137,8 +3139,8 @@ def to_svg(self, leaves=None, **options):
31373139 h += 2
31383140
31393141 if options .get ("noheader" , False ):
3140- return svg
3141- svg_xml = """
3142+ return svg_body
3143+ svg_main = """
31423144 <svg xmlns:svg="http://www.w3.org/2000/svg"
31433145 xmlns="http://www.w3.org/2000/svg"
31443146 version="1.1"
@@ -3147,19 +3149,21 @@ def to_svg(self, leaves=None, **options):
31473149 </svg>
31483150 """ % (
31493151 " " .join ("%f" % t for t in (xmin , ymin , w , h )),
3150- svg ,
3152+ svg_body ,
31513153 )
3152- return svg_xml # , width, height
3154+ return svg_main # , width, height
31533155
3154- def boxes_to_mathml (self , leaves = None , ** options ):
3156+ # fixme: figure out how to move the svg-specific portions to the SVG formatter.
3157+ def boxes_to_mathml (self , leaves = None , ** options ) -> str :
31553158 if not leaves :
31563159 leaves = self ._leaves
31573160
31583161 elements , calc_dimensions = self ._prepare_elements (leaves , options , neg_y = True )
31593162 xmin , xmax , ymin , ymax , w , h , width , height = calc_dimensions ()
31603163 data = (elements , xmin , xmax , ymin , ymax , w , h , width , height )
31613164
3162- svg_xml = self .to_svg (leaves , data = data , ** options )
3165+ svg_main = self .to_svg (leaves , data = data , ** options )
3166+
31633167 # mglyph, which is what we have been using, is bad because MathML standard changed.
31643168 # metext does not work because the way in which we produce the svg images is also based on this outdated mglyph behaviour.
31653169 # template = '<mtext width="%dpx" height="%dpx"><img width="%dpx" height="%dpx" src="data:image/svg+xml;base64,%s"/></mtext>'
@@ -3172,9 +3176,10 @@ def boxes_to_mathml(self, leaves=None, **options):
31723176 # int(height),
31733177 int (width ),
31743178 int (height ),
3175- base64 .b64encode (svg_xml .encode ("utf8" )).decode ("utf8" ),
3179+ base64 .b64encode (svg_main .encode ("utf8" )).decode ("utf8" ),
31763180 )
31773181
3182+ # FIXME: this isn't always properly align with overlaid SVG plots
31783183 def axis_ticks (self , xmin , xmax ):
31793184 def round_to_zero (value ):
31803185 if value == 0 :
0 commit comments