Skip to content

Commit e1bd5dc

Browse files
authored
Tweak SVG parameters... (#1317)
Changes based on looking at WS SVG output * Make dots and line widths larger. * add miter style options Pass through some DiscretePlot options
1 parent 0c6c384 commit e1bd5dc

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

mathics/builtin/drawing/plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ class DiscretePlot(_Plot):
668668
)
669669

670670
rules = {
671-
# One argument-form of DiscretePlot
672-
"DiscretePlot[expr_, {var_Symbol, nmax_Integer}]": "DiscretePlot[expr, {var, 1, nmax, 1}]",
673-
# Two argument-form of DiscretePlot
674-
"DiscretePlot[expr_, {var_Symbol, nmin_Integer, nmax_Integer}]": "DiscretePlot[expr, {var, nmin, nmax, 1}]",
671+
# One-argument plot range form of DiscretePlot
672+
"DiscretePlot[expr_, {var_Symbol, nmax_Integer}, options___]": "DiscretePlot[expr, {var, 1, nmax, 1}, options]",
673+
# Two-argument plot range form of DiscretePlot
674+
"DiscretePlot[expr_, {var_Symbol, nmin_Integer, nmax_Integer}, options___]": "DiscretePlot[expr, {var, nmin, nmax, 1, options}]",
675675
}
676676

677677
summary_text = "discrete plot of a one-paremeter function"

mathics/builtin/graphics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
}
6969

7070
# fraction of point relative canvas width
71-
DEFAULT_POINT_FACTOR = 0.005
71+
DEFAULT_POINT_FACTOR = 0.007
7272

7373

7474
ERROR_BACKGROUND_COLOR = RGBColor(components=[1, 0.3, 0.3, 0.25])
@@ -276,9 +276,9 @@ class Graphics(Builtin):
276276
= #<--#
277277
. \begin{asy}
278278
. usepackage("amsmath");
279-
. size(5.8445cm, 5.8333cm);
280-
. draw(ellipse((175,175),175,175), rgb(0, 0, 0)+linewidth(0.33333));
281-
. clip(box((-0.16667,0.16667), (350.17,349.83)));
279+
. size(5.869cm, 5.8333cm);
280+
. draw(ellipse((175,175),175,175), rgb(0, 0, 0)+linewidth(1.0667));
281+
. clip(box((-0.53333,0.53333), (350.53,349.47)));
282282
. \end{asy}
283283
"""
284284

@@ -1016,7 +1016,7 @@ def get_style(
10161016
edge_style = self.get_default_edge_color()
10171017
elif style_class == _Thickness:
10181018
if not default_to_faces:
1019-
edge_style = AbsoluteThickness(self.graphics, value=0.5)
1019+
edge_style = AbsoluteThickness(self.graphics, value=1.6)
10201020
for item in self.styles:
10211021
if isinstance(item, style_class):
10221022
if default_to_faces:

mathics/format/svg.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ def path(closed):
116116
if closed:
117117
yield "Z"
118118

119-
l = self.style.get_line_width(face_element=self.face_element)
119+
line_width = self.style.get_line_width(face_element=self.face_element)
120120
style = create_css(
121121
self.edge_color,
122122
self.face_color,
123-
stroke_width=l,
123+
stroke_width=line_width,
124124
edge_opacity=self.edge_opacity,
125125
face_opacity=self.face_opacity,
126126
)
@@ -349,7 +349,7 @@ def graphics_elements(self, **options) -> str:
349349
for element in self.elements:
350350
try:
351351
format_fn = lookup_method(element, "svg")
352-
except:
352+
except Exception:
353353
# Note error and continue
354354
result.append(f"""unhandled {element}""")
355355
continue
@@ -427,6 +427,12 @@ def line_box(self, **options) -> str:
427427
stroke_width=line_width,
428428
edge_opacity=self.edge_opacity,
429429
)
430+
431+
# The following line options come from looking at SVG produced from WMA.
432+
# In the future we may incorporate these into create_css or
433+
# narrow this based on context.
434+
style += "; stroke-linecap:square; stroke-linejoin:miter; stroke-miterlimit:3.25"
435+
430436
svg = "<!--LineBox-->\n"
431437
for line in self.lines:
432438
svg += '<polyline points="%s" style="%s" />' % (
@@ -453,6 +459,11 @@ def pointbox(self, **options) -> str:
453459
edge_opacity=self.edge_opacity,
454460
face_opacity=self.face_opacity,
455461
)
462+
463+
# The following line options come from looking at SVG produced from WMA.
464+
# In the future we may incorporate these into create_css or
465+
style += "; fill-rule:even-odd"
466+
456467
svg = "<!--PointBox-->"
457468
for line in self.lines:
458469
for coords in line:

test/builtin/drawing/test_plot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
Unit tests from mathics.builtin.drawing.plot
44
"""
55

6-
import sys
7-
import time
8-
from test.helper import check_evaluation, evaluate
6+
from test.helper import check_evaluation
97

108
import pytest
119

0 commit comments

Comments
 (0)