@@ -33,19 +33,19 @@ def matrix(self, a, b, c, d, e, f):
3333 # a c e
3434 # b d f
3535 # 0 0 1
36- self .transforms .append ("matrix(%f, %f, %f, %f, %f, %f)" % ( a , b , c , d , e , f ) )
36+ self .transforms .append (f "matrix({ a :f } , { b :f } , { c :f } , { d :f } , { e :f } , { e :f } )" )
3737
3838 def translate (self , x , y ):
39- self .transforms .append ("translate(%f, %f)" % ( x , y ) )
39+ self .transforms .append (f "translate({ x :f } , { y :f } )" )
4040
4141 def scale (self , x , y ):
42- self .transforms .append ("scale(%f, %f)" % ( x , y ) )
42+ self .transforms .append (f "scale({ x :f } , { y :f } )" )
4343
4444 def rotate (self , x ):
45- self .transforms .append ("rotate(%f)" % x )
45+ self .transforms .append (f "rotate({ x :f } )" )
4646
4747 def apply (self , svg ):
48- return ' <g transform="%s">%s</g>' % ( " " .join (self .transforms ), svg )
48+ return f""" <g transform="{ ' ' .join (self .transforms )} "> { svg } </g>"""
4949
5050
5151def create_css (
@@ -57,22 +57,22 @@ def create_css(
5757 css = []
5858 if edge_color is not None :
5959 color , stroke_opacity = edge_color .to_css ()
60- css .append ("stroke: %s" % color )
61- css .append ("stroke-opacity: %s" % stroke_opacity )
60+ css .append (f "stroke: { color } " )
61+ css .append (f "stroke-opacity: { stroke_opacity } " )
6262 else :
6363 css .append ("stroke: none" )
6464 if stroke_width is not None :
65- css .append ("stroke-width: %fpx" % stroke_width )
65+ css .append (f "stroke-width: { stroke_width :f } px" )
6666 if face_color is not None :
6767 color , fill_opacity = face_color .to_css ()
68- css .append ("fill: %s" % color )
69- css .append ("fill-opacity: %s" % fill_opacity )
68+ css .append (f "fill: { color } " )
69+ css .append (f "fill-opacity: { fill_opacity } " )
7070 else :
7171 css .append ("fill: none" )
7272 if font_color is not None :
7373 color , _ = font_color .to_css ()
74- css .append ("color: %s" % color )
75- css .append ("opacity: %s" % opacity )
74+ css .append (f "color: { color } " )
75+ css .append (f "opacity: { opacity } " )
7676 return "; " .join (css )
7777
7878
@@ -86,7 +86,7 @@ def arrow_box(self, **options):
8686 def polygon (points ):
8787 yield '<polygon points="'
8888 yield " " .join ("%f,%f" % xy for xy in points )
89- yield '" style="%s " />' % arrow_style
89+ yield f '" style="{ arrow_style } " />'
9090
9191 extent = self .graphics .view_width or 0
9292 default_arrow = self ._default_arrow (polygon )
@@ -104,7 +104,7 @@ def beziercurvebox(self, **options):
104104 svg = ""
105105 for line in self .lines :
106106 s = " " .join (_svg_bezier ((self .spline_degree , [xy .pos () for xy in line ])))
107- svg += '<path d="%s " style="%s "/>' % ( s , style )
107+ svg += f '<path d="{ s } " style="{ style } "/>'
108108 # print("XXX bezier", svg)
109109 return svg
110110
@@ -133,6 +133,7 @@ def components():
133133add_conversion_fn (FilledCurveBox , filled_curve_box )
134134
135135def graphics_box (self , leaves = None , ** options ) -> str :
136+
136137 if not leaves :
137138 leaves = self ._leaves
138139
@@ -164,24 +165,20 @@ def graphics_box(self, leaves=None, **options) -> str:
164165 svg_body ,
165166 )
166167
167- xmin -= 1
168- ymin -= 1
169- w += 2
170- h += 2
171-
172168 if options .get ("noheader" , False ):
173169 return svg_body
174170 svg_main = """
175- <svg xmlns:svg="http://www.w3.org/2000/svg"
171+ <svg xmlns:svg="http://www.w3.org/2000/svg"
176172 xmlns="http://www.w3.org/2000/svg"
177173 version="1.1"
178174 viewBox="%s">
179175 %s
180- </svg>
181- """ % (
176+ </svg>
177+ """ % (
182178 " " .join ("%f" % t for t in (xmin , ymin , w , h )),
183179 svg_body ,
184180 )
181+ # print("svg_main", svg_main)
185182 return svg_main # , width, height
186183
187184
@@ -200,7 +197,9 @@ def graphics_elements(self, **options)->str:
200197 else :
201198 result .append (format_fn (element , ** options ))
202199
203- return "\n " .join (result )
200+ svg = "\n " .join (result )
201+ # print("graphics_elements", svg)
202+ return svg
204203
205204
206205add_conversion_fn (GraphicsElements , graphics_elements )
@@ -256,7 +255,7 @@ def line_box(self, **options)->str:
256255 " " .join (["%f,%f" % coords .pos () for coords in line ]),
257256 style ,
258257 )
259- # print("XXX linebox ", svg)
258+ # print("LineBox ", svg)
260259 return svg
261260
262261
@@ -275,13 +274,10 @@ def pointbox(self, **options)->str:
275274 svg = ""
276275 for line in self .lines :
277276 for coords in line :
278- svg += '<circle cx="%f" cy="%f" r="%f" style="%s" />' % (
279- coords .pos ()[0 ],
280- coords .pos ()[1 ],
281- size ,
282- style ,
283- )
284- # print("XXX PointBox", svg)
277+ svg += f"""
278+ <circle cx="{ coords .pos ()[0 ]:f} " cy="{ coords .pos ()[1 ]:f} "
279+ r="{ size :f} " style="{ style } "/>"""
280+ # print("PointBox", svg)
285281 return svg
286282
287283
@@ -312,7 +308,7 @@ def polygonbox(self, **options):
312308 " " .join ("%f,%f" % coords .pos () for coords in line ),
313309 style ,
314310 )
315- # print("XXX PolygonBox", svg)
311+ print ("XXX PolygonBox" , svg )
316312 return svg
317313
318314
@@ -331,14 +327,15 @@ def rectanglebox(self, **options):
331327 x1 , x2 = x1 + offset [0 ], x2 + offset [0 ]
332328 y1 , y2 = y1 + offset [1 ], y2 + offset [1 ]
333329 style = create_css (self .edge_color , self .face_color , line_width )
334- return '<rect x="%f" y="%f" width="%f" height="%f" style="%s" />' % (
330+ svg = '<rect x="%f" y="%f" width="%f" height="%f" style="%s" />' % (
335331 xmin ,
336332 ymin ,
337333 w ,
338334 h ,
339335 style ,
340336 )
341- "\n " .join (element .to_svg () for element in self .elements )
337+ # print("RectangleBox", svg)
338+ return svg
342339
343340
344341add_conversion_fn (RectangleBox )
@@ -351,13 +348,15 @@ def _roundbox(self, **options):
351348 ry = y - ry
352349 line_width = self .style .get_line_width (face_element = self .face_element )
353350 style = create_css (self .edge_color , self .face_color , stroke_width = line_width )
354- return '<ellipse cx="%f" cy="%f" rx="%f" ry="%f" style="%s" />' % (
351+ svg = '<ellipse cx="%f" cy="%f" rx="%f" ry="%f" style="%s" />' % (
355352 x ,
356353 y ,
357354 rx ,
358355 ry ,
359356 style ,
360357 )
358+ # print("_RoundBox", svg)
359+ return svg
361360
362361
363362add_conversion_fn (_RoundBox )
0 commit comments