Skip to content

Commit 33fc83a

Browse files
committed
Mark what's needed and tidy
1 parent ee8e6d3 commit 33fc83a

2 files changed

Lines changed: 69 additions & 59 deletions

File tree

mathics/builtin/graphics.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

mathics/formatter/svg.py

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -110,56 +110,61 @@ def components():
110110

111111
add_conversion_fn(FilledCurveBox)
112112

113+
# FIXME figure out how we can add this.
113114
# def graphicsbox(self, leaves=None, **options) -> str:
114-
# if not leaves:
115-
# leaves = self._leaves
116-
117-
# data = options.get("data", None)
118-
# if data:
119-
# elements, xmin, xmax, ymin, ymax, w, h, width, height = data
120-
# else:
121-
# elements, calc_dimensions = self._prepare_elements(
122-
# leaves, options, neg_y=True
115+
# if not leaves:
116+
# leaves = self._leaves
117+
#
118+
# data = options.get("data", None)
119+
# if data:
120+
# elements, xmin, xmax, ymin, ymax, w, h, width, height = data
121+
# else:
122+
# elements, calc_dimensions = self._prepare_elements(
123+
# leaves, options, neg_y=True
124+
# )
125+
# xmin, xmax, ymin, ymax, w, h, width, height = calc_dimensions()
126+
#
127+
# elements.view_width = w
128+
#
129+
# format_fn = lookup_method(elements, "svg")
130+
# if format_fn is not None:
131+
# svg_body = format_fn(elements, offset=options.get("offset", None))
132+
# else:
133+
# svg_body = elements.to_svg(offset=options.get("offset", None))
134+
#
135+
# if self.background_color is not None:
136+
# # Wrap svg_elements in a rectangle
137+
# svg_body = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % (
138+
# xmin,
139+
# ymin,
140+
# w,
141+
# h,
142+
# self.background_color.to_css()[0],
143+
# svg_body,
144+
# )
145+
#
146+
# xmin -= 1
147+
# ymin -= 1
148+
# w += 2
149+
# h += 2
150+
#
151+
# if options.get("noheader", False):
152+
# return svg_body
153+
# svg_main = """
154+
# <svg xmlns:svg="http://www.w3.org/2000/svg"
155+
# xmlns="http://www.w3.org/2000/svg"
156+
# version="1.1"
157+
# viewBox="%s">
158+
# %s
159+
# </svg>
160+
# """ % (
161+
# " ".join("%f" % t for t in (xmin, ymin, w, h)),
162+
# svg_body,
123163
# )
124-
# xmin, xmax, ymin, ymax, w, h, width, height = calc_dimensions()
125-
126-
# elements.view_width = w
127-
128-
# format_fn = lookup_method(elements, "svg")
129-
# if format_fn is not None:
130-
# svg = format_fn(elements)
131-
# else:
132-
# svg = elements.to_svg(offset=options.get("offset", None))
133-
134-
# if self.background_color is not None:
135-
# svg = '<rect x="%f" y="%f" width="%f" height="%f" style="fill:%s"/>%s' % (
136-
# xmin,
137-
# ymin,
138-
# w,
139-
# h,
140-
# self.background_color.to_css()[0],
141-
# svg,
142-
# )
143-
144-
# xmin -= 1
145-
# ymin -= 1
146-
# w += 2
147-
# h += 2
148-
149-
# if options.get("noheader", False):
150-
# return svg
151-
# svg = """
152-
# <svg xmlns:svg="http://www.w3.org/2000/svg"
153-
# xmlns="http://www.w3.org/2000/svg"
154-
# version="1.1"
155-
# viewBox="%s">
156-
# %s
157-
# </svg>
158-
# """ % (
159-
# " ".join("%f" % t for t in (xmin, ymin, w, h)),
160-
# svg,
161-
# )
162-
# return svg # , width, height
164+
# return svg_main # , width, height
165+
#
166+
#
167+
# add_conversion_fn(GraphicsBox)
163168

164169

165170
def graphicselements(self, offset=None):

0 commit comments

Comments
 (0)