Skip to content

Commit

Permalink
Tweak SVG parameters...
Browse files Browse the repository at this point in the history
Changes based on looking at WS SVG output

* Make dots and line widths larger.
* add miter style options

Pass through some DiscretePlot options
  • Loading branch information
rocky committed Jan 25, 2025
1 parent 9048440 commit e482f9e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 4 additions & 4 deletions mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ class DiscretePlot(_Plot):
)

rules = {
# One argument-form of DiscretePlot
"DiscretePlot[expr_, {var_Symbol, nmax_Integer}]": "DiscretePlot[expr, {var, 1, nmax, 1}]",
# Two argument-form of DiscretePlot
"DiscretePlot[expr_, {var_Symbol, nmin_Integer, nmax_Integer}]": "DiscretePlot[expr, {var, nmin, nmax, 1}]",
# One-argument plot range form of DiscretePlot
"DiscretePlot[expr_, {var_Symbol, nmax_Integer}, options___]": "DiscretePlot[expr, {var, 1, nmax, 1}, options]",
# Two-argument plot range form of DiscretePlot
"DiscretePlot[expr_, {var_Symbol, nmin_Integer, nmax_Integer}, options___]": "DiscretePlot[expr, {var, nmin, nmax, 1, options}]",
}

summary_text = "discrete plot of a one-paremeter function"
Expand Down
10 changes: 5 additions & 5 deletions mathics/builtin/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}

# fraction of point relative canvas width
DEFAULT_POINT_FACTOR = 0.005
DEFAULT_POINT_FACTOR = 0.007


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

Expand Down Expand Up @@ -1016,7 +1016,7 @@ def get_style(
edge_style = self.get_default_edge_color()
elif style_class == _Thickness:
if not default_to_faces:
edge_style = AbsoluteThickness(self.graphics, value=0.5)
edge_style = AbsoluteThickness(self.graphics, value=1.6)
for item in self.styles:
if isinstance(item, style_class):
if default_to_faces:
Expand Down
17 changes: 14 additions & 3 deletions mathics/format/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ def path(closed):
if closed:
yield "Z"

l = self.style.get_line_width(face_element=self.face_element)
line_width = self.style.get_line_width(face_element=self.face_element)
style = create_css(
self.edge_color,
self.face_color,
stroke_width=l,
stroke_width=line_width,
edge_opacity=self.edge_opacity,
face_opacity=self.face_opacity,
)
Expand Down Expand Up @@ -349,7 +349,7 @@ def graphics_elements(self, **options) -> str:
for element in self.elements:
try:
format_fn = lookup_method(element, "svg")
except:
except Exception:
# Note error and continue
result.append(f"""unhandled {element}""")
continue
Expand Down Expand Up @@ -427,6 +427,12 @@ def line_box(self, **options) -> str:
stroke_width=line_width,
edge_opacity=self.edge_opacity,
)

# The following line options come from looking at SVG produced from WMA.
# In the future we may incorporate these into create_css or
# narrow this based on context.
style += "; stroke-linecap:square; stroke-linejoin:miter; stroke-miterlimit:3.25"

svg = "<!--LineBox-->\n"
for line in self.lines:
svg += '<polyline points="%s" style="%s" />' % (
Expand All @@ -453,6 +459,11 @@ def pointbox(self, **options) -> str:
edge_opacity=self.edge_opacity,
face_opacity=self.face_opacity,
)

# The following line options come from looking at SVG produced from WMA.
# In the future we may incorporate these into create_css or
style += "; fill-rule:even-odd"

svg = "<!--PointBox-->"
for line in self.lines:
for coords in line:
Expand Down
4 changes: 1 addition & 3 deletions test/builtin/drawing/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Unit tests from mathics.builtin.drawing.plot
"""

import sys
import time
from test.helper import check_evaluation, evaluate
from test.helper import check_evaluation

import pytest

Expand Down

0 comments on commit e482f9e

Please sign in to comment.