Skip to content

Commit 381ff06

Browse files
committed
to_svg doesn't seem needed for _ArcBox
1 parent 495a84b commit 381ff06

File tree

2 files changed

+69
-57
lines changed

2 files changed

+69
-57
lines changed

mathics/builtin/graphics.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,20 +1176,26 @@ class Disk(Builtin):
11761176
class Circle(Builtin):
11771177
"""
11781178
<dl>
1179-
<dt>'Circle[{$cx$, $cy$}, $r$]'
1180-
<dd>draws a circle with center '($cx$, $cy$)' and radius $r$.
1181-
<dt>'Circle[{$cx$, $cy$}, {$rx$, $ry$}]'
1182-
<dd>draws an ellipse.
1183-
<dt>'Circle[{$cx$, $cy$}]'
1184-
<dd>chooses radius 1.
1185-
<dt>'Circle[]'
1186-
<dd>chooses center '(0, 0)' and radius 1.
1179+
<dt>'Circle[{$cx$, $cy$}, $r$]'
1180+
<dd>draws a circle with center '($cx$, $cy$)' and radius $r$.
1181+
1182+
<dt>'Circle[{$cx$, $cy$}, {$rx$, $ry$}]'
1183+
<dd>draws an ellipse.
1184+
1185+
<dt>'Circle[{$cx$, $cy$}]'
1186+
<dd>chooses radius 1.
1187+
1188+
<dt>'Circle[]'
1189+
<dd>chooses center '(0, 0)' and radius 1.
11871190
</dl>
11881191
11891192
>> Graphics[{Red, Circle[{0, 0}, {2, 1}]}]
11901193
= -Graphics-
11911194
>> Graphics[{Circle[], Disk[{0, 0}, {1, 1}, {0, 2.1}]}]
11921195
= -Graphics-
1196+
1197+
Target practice:
1198+
>> Graphics[Circle[], Axes-> True]
11931199
"""
11941200

11951201
rules = {"Circle[]": "Circle[{0, 0}]"}
@@ -1359,31 +1365,33 @@ def _arc_params(self):
13591365

13601366
return x, y, abs(rx), abs(ry), sx, sy, ex, ey, large_arc
13611367

1362-
def to_svg(self, offset=None):
1363-
# FIXME: figure out how to put in svg.py
1364-
if self.arc is None:
1365-
return super(_ArcBox, self).to_svg(offset)
1368+
# FIXME: Why do we need this? If so,
1369+
# figure out how to put in svg.py
1370+
# --------------------------------
1371+
# def to_svg(self, offset=None):
1372+
# if self.arc is None:
1373+
# return super(_ArcBox, self).to_svg(offset)
13661374

1367-
x, y, rx, ry, sx, sy, ex, ey, large_arc = self._arc_params()
1375+
# x, y, rx, ry, sx, sy, ex, ey, large_arc = self._arc_params()
13681376

1369-
format_fn = lookup_method(self, "svg")
1370-
if format_fn is not None:
1371-
return format_fn(self, offset)
1372-
def path(closed):
1373-
if closed:
1374-
yield "M %f,%f" % (x, y)
1375-
yield "L %f,%f" % (sx, sy)
1376-
else:
1377-
yield "M %f,%f" % (sx, sy)
1377+
# format_fn = lookup_method(self, "svg")
1378+
# if format_fn is not None:
1379+
# return format_fn(self, offset)
1380+
# def path(closed):
1381+
# if closed:
1382+
# yield "M %f,%f" % (x, y)
1383+
# yield "L %f,%f" % (sx, sy)
1384+
# else:
1385+
# yield "M %f,%f" % (sx, sy)
13781386

1379-
yield "A %f,%f,0,%d,0,%f,%f" % (rx, ry, large_arc, ex, ey)
1387+
# yield "A %f,%f,0,%d,0,%f,%f" % (rx, ry, large_arc, ex, ey)
13801388

1381-
if closed:
1382-
yield "Z"
1389+
# if closed:
1390+
# yield "Z"
13831391

1384-
l = self.style.get_line_width(face_element=self.face_element)
1385-
style = create_css(self.edge_color, self.face_color, stroke_width=l)
1386-
return '<path d="%s" style="%s" />' % (" ".join(path(self.face_element)), style)
1392+
# l = self.style.get_line_width(face_element=self.face_element)
1393+
# style = create_css(self.edge_color, self.face_color, stroke_width=l)
1394+
# return '<path d="%s" style="%s" />' % (" ".join(path(self.face_element)), style)
13871395

13881396
def to_asy(self):
13891397
if self.arc is None:
@@ -2491,7 +2499,6 @@ def extent(self):
24912499
y = p[1] - h / 2.0 + opos[1] * h / 2.0
24922500
return [(x, y), (x + w, y + h)]
24932501

2494-
24952502
def to_asy(self):
24962503
x, y = self.pos.pos()
24972504
content = self.content.boxes_to_tex(evaluation=self.graphics.evaluation)

mathics/formatter/svg.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from mathics.builtin.drawing.graphics3d import Graphics3DElements
99
from mathics.builtin.graphics import (
10-
# _ArcBox,
1110
ArrowBox,
1211
BezierCurveBox,
1312
FilledCurveBox,
@@ -29,7 +28,10 @@
2928

3029
def create_css(
3130
edge_color=None, face_color=None, stroke_width=None, font_color=None, opacity=1.0
32-
):
31+
) -> str:
32+
"""
33+
Return a string suitable for CSS inclusion setting the various parameters passed.
34+
"""
3335
css = []
3436
if edge_color is not None:
3537
color, stroke_opacity = edge_color.to_css()
@@ -52,29 +54,6 @@ def create_css(
5254
return "; ".join(css)
5355

5456

55-
# def arcbox(self, offset=None):
56-
# if self.arc is None:
57-
# raise RuntimeError(f"{self}.arc should not be none")
58-
59-
# x, y, rx, ry, sx, sy, ex, ey, large_arc = self._arc_params()
60-
61-
# def path(closed):
62-
# if closed:
63-
# yield "M %f,%f" % (x, y)
64-
# yield "L %f,%f" % (sx, sy)
65-
# else:
66-
# yield "M %f,%f" % (sx, sy)
67-
68-
# yield "A %f,%f,0,%d,0,%f,%f" % (rx, ry, large_arc, ex, ey)
69-
70-
# if closed:
71-
# yield "Z"
72-
73-
# l = self.style.get_line_width(face_element=self.face_element)
74-
# style = create_css(self.edge_color, self.face_color, stroke_width=l)
75-
# return '<path d="%s" style="%s" />' % (" ".join(path(self.face_element)), style)
76-
77-
7857
def arrowbox(self, offset=None):
7958
width = self.style.get_line_width(face_element=False)
8059
style = create_css(edge_color=self.edge_color, stroke_width=width)
@@ -91,8 +70,11 @@ def polygon(points):
9170
default_arrow = self._default_arrow(polygon)
9271
custom_arrow = self._custom_arrow("svg", _SVGTransform)
9372
return "".join(self._draw(polyline, default_arrow, custom_arrow, extent))
73+
74+
9475
add_conversion_fn(ArrowBox)
9576

77+
9678
def beziercurvebox(self, offset=None):
9779
l = self.style.get_line_width(face_element=False)
9880
style = create_css(edge_color=self.edge_color, stroke_width=l)
@@ -103,8 +85,11 @@ def beziercurvebox(self, offset=None):
10385
svg += '<path d="%s" style="%s"/>' % (s, style)
10486
# print("XXX bezier", svg)
10587
return svg
88+
89+
10690
add_conversion_fn(BezierCurveBox)
10791

92+
10893
def filledcurvebox(self, offset=None):
10994
l = self.style.get_line_width(face_element=False)
11095
style = create_css(
@@ -121,6 +106,8 @@ def components():
121106
" ".join(components()),
122107
style,
123108
)
109+
110+
124111
add_conversion_fn(FilledCurveBox)
125112

126113
# def graphicsbox(self, leaves=None, **options) -> str:
@@ -174,21 +161,25 @@ def components():
174161
# )
175162
# return svg # , width, height
176163

164+
177165
def graphicselements(self, offset=None):
178166
result = []
179167
for element in self.elements:
180168
format_fn = lookup_method(element, "svg")
181-
if format_fn is not None:
182-
result.append(format_fn(element, offset))
183-
else:
169+
if format_fn is None:
184170
result.append(element.to_svg(offset))
171+
else:
172+
result.append(format_fn(element, offset))
185173

186174
return "\n".join(result)
175+
176+
187177
add_conversion_fn(GraphicsElements)
188178
graphics3delements = graphicselements
189179

190180
add_conversion_fn(Graphics3DElements)
191181

182+
192183
def insetbox(self, offset=None):
193184
x, y = self.pos.pos()
194185
if offset:
@@ -218,8 +209,11 @@ def insetbox(self, offset=None):
218209
# "<math>%s</math></foreignObject>")
219210

220211
return svg
212+
213+
221214
add_conversion_fn(InsetBox)
222215

216+
223217
def linebox(self, offset=None):
224218
l = self.style.get_line_width(face_element=False)
225219
style = create_css(edge_color=self.edge_color, stroke_width=l)
@@ -231,6 +225,8 @@ def linebox(self, offset=None):
231225
)
232226
# print("XXX linebox", svg)
233227
return svg
228+
229+
234230
add_conversion_fn(LineBox)
235231

236232

@@ -254,8 +250,11 @@ def pointbox(self, offset=None):
254250
)
255251
# print("XXX PointBox", svg)
256252
return svg
253+
254+
257255
add_conversion_fn(PointBox)
258256

257+
259258
def polygonbox(self, offset=None):
260259
l = self.style.get_line_width(face_element=True)
261260
if self.vertex_colors is None:
@@ -282,6 +281,8 @@ def polygonbox(self, offset=None):
282281
)
283282
# print("XXX PolygonBox", svg)
284283
return svg
284+
285+
285286
add_conversion_fn(PolygonBox)
286287

287288

@@ -305,6 +306,8 @@ def rectanglebox(self, offset=None):
305306
style,
306307
)
307308
"\n".join(element.to_svg() for element in self.elements)
309+
310+
308311
add_conversion_fn(RectangleBox)
309312

310313

@@ -322,4 +325,6 @@ def _roundbox(self, offset=None):
322325
ry,
323326
style,
324327
)
328+
329+
325330
add_conversion_fn(_RoundBox)

0 commit comments

Comments
 (0)