Skip to content

Commit

Permalink
%r -> %s to handle new numpy repr behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
harmsm committed Jul 12, 2024
1 parent 25f1fed commit cce091b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion toyplot/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, family, size):
self._descent = toyplot.units.convert(descent, target="px", default="pt")

def __repr__(self): # pragma: no cover
return "<toyplot.font.ReportlabFont family=%r size=%r ascent=%r descent=%r>" % (self._family, self._size, self.ascent, self.descent)
return "<toyplot.font.ReportlabFont family=%s size=%s ascent=%s descent=%s>" % (self._family, self._size, self.ascent, self.descent)

@property
def ascent(self):
Expand Down
50 changes: 25 additions & 25 deletions toyplot/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ def _draw_text(

transform = ""
if x or y:
transform += "translate(%r,%r)" % (x, y)
transform += "translate(%s,%s)" % (x, y)
if angle:
transform += "rotate(%r)" % (-angle) # pylint: disable=invalid-unary-operand-type
transform += "rotate(%s)" % (-angle) # pylint: disable=invalid-unary-operand-type

group = xml.SubElement(
root,
Expand Down Expand Up @@ -618,7 +618,7 @@ def _draw_bar(parent_xml, size, angle=0):
y2=str(size / 2),
)
if angle:
markup.set("transform", "rotate(%r)" % (-angle,))
markup.set("transform", "rotate(%s)" % (-angle,))


def _draw_rect(parent_xml, size, width=1, height=1, angle=0):
Expand All @@ -631,21 +631,21 @@ def _draw_rect(parent_xml, size, width=1, height=1, angle=0):
height=str(size * height),
)
if angle:
markup.set("transform", "rotate(%r)" % (-angle,))
markup.set("transform", "rotate(%s)" % (-angle,))


def _draw_triangle(parent_xml, size, angle=0):
markup = xml.SubElement(
parent_xml,
"polygon",
points=" ".join(["%r,%r" % (xp, yp) for xp, yp in [
points=" ".join(["%s,%s" % (xp, yp) for xp, yp in [
(-size / 2, size / 2),
(0, -size / 2),
(size / 2, size / 2),
]]),
)
if angle:
markup.set("transform", "rotate(%r)" % (-angle,))
markup.set("transform", "rotate(%s)" % (-angle,))


def _draw_circle(parent_xml, size):
Expand Down Expand Up @@ -673,9 +673,9 @@ def _draw_marker(
xml.SubElement(marker_xml, "title").text = str(title)

if transform is None:
transform = "translate(%r, %r)" % (cx, cy)
transform = "translate(%s, %s)" % (cx, cy)
if marker.angle:
transform += " rotate(%r)" % (-marker.angle,)
transform += " rotate(%s)" % (-marker.angle,)
marker_xml.set("transform", transform)

if marker.shape == "|":
Expand Down Expand Up @@ -750,7 +750,7 @@ def _draw_marker(
{
"-toyplot-vertical-align": "middle",
"fill": toyplot.color.black,
"font-size": "%rpx" % (marker.size * 0.75),
"font-size": "%spx" % (marker.size * 0.75),
"stroke": "none",
"text-anchor": "middle",
},
Expand Down Expand Up @@ -794,9 +794,9 @@ def _render(canvas, context):
"xmlns:toyplot": "http://www.sandia.gov/toyplot",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
},
width="%rpx" % canvas.width,
height="%rpx" % canvas.height,
viewBox="0 0 %r %r" % (canvas.width, canvas.height),
width="%spx" % canvas.width,
height="%spx" % canvas.height,
viewBox="0 0 %s %s" % (canvas.width, canvas.height),
preserveAspectRatio="xMidYMid meet",
style=_css_style(canvas._style),
id=context.get_id(canvas))
Expand Down Expand Up @@ -2176,7 +2176,7 @@ def _render(axes, mark, context):
numpy.concatenate((boundary1[segment], boundary2[segment][::-1])),
numpy.concatenate((position[segment], position[segment][::-1])))
series_xml = xml.SubElement(mark_xml, "polygon", points=" ".join(
["%r,%r" % (xi, yi) for xi, yi in coordinates]), style=_css_style(series_style))
["%s,%s" % (xi, yi) for xi, yi in coordinates]), style=_css_style(series_style))
if title is not None:
xml.SubElement(series_xml, "title").text = str(title)

Expand Down Expand Up @@ -2222,7 +2222,7 @@ def _render(axes, mark, context):
numpy.concatenate((boundary1[segment], boundary2[segment][::-1])),
numpy.concatenate((position[segment], position[segment][::-1])))
series_xml = xml.SubElement(mark_xml, "polygon", points=" ".join(
["%r,%r" % (xi, yi) for xi, yi in coordinates]), style=_css_style(series_style))
["%s,%s" % (xi, yi) for xi, yi in coordinates]), style=_css_style(series_style))
if title is not None:
xml.SubElement(series_xml, "title").text = str(title)

Expand Down Expand Up @@ -2319,7 +2319,7 @@ def _render(axes, mark, context):
x = axes.project("x", dx + p[:,0])
y = axes.project("y", dy + p[:,1])

points = ["%r,%r" % point for point in zip(x, y)]
points = ["%s,%s" % point for point in zip(x, y)]

datum_xml = xml.SubElement(
series_xml,
Expand Down Expand Up @@ -2500,16 +2500,16 @@ def _render(axes, mark, context): # pragma: no cover
edge_coordinates[estart+1][0] - edge_coordinates[estart][0],
))

transform = "translate(%r, %r)" % (edge_coordinates[estart][0], edge_coordinates[estart][1])
transform = "translate(%s, %s)" % (edge_coordinates[estart][0], edge_coordinates[estart][1])
if edge_angle:
transform += " rotate(%r)" % (-edge_angle,)
transform += " translate(%r, 0)" % (marker.size / 2,)
transform += " rotate(%s)" % (-edge_angle,)
transform += " translate(%s, 0)" % (marker.size / 2,)
if marker.angle is not None:
if isinstance(marker.angle, str) and marker.angle[0:1] == "r":
angle = as_float(marker.angle[1:])
else:
angle = -edge_angle + as_float(marker.angle)
transform += " rotate(%r)" % (-angle,)
transform += " rotate(%s)" % (-angle,)


_draw_marker(
Expand Down Expand Up @@ -2572,16 +2572,16 @@ def _render(axes, mark, context): # pragma: no cover
edge_coordinates[end-1][0] - edge_coordinates[end-2][0],
))

transform = "translate(%r, %r)" % (edge_coordinates[end-1][0], edge_coordinates[end-1][1])
transform = "translate(%s, %s)" % (edge_coordinates[end-1][0], edge_coordinates[end-1][1])
if edge_angle:
transform += " rotate(%r)" % (-edge_angle,)
transform += " translate(%r, 0)" % (-marker.size / 2,)
transform += " rotate(%s)" % (-edge_angle,)
transform += " translate(%s, 0)" % (-marker.size / 2,)
if marker.angle is not None:
if isinstance(marker.angle, str) and marker.angle[0:1] == "r":
angle = as_float(marker.angle[1:])
else:
angle = -edge_angle + as_float(marker.angle)
transform += " rotate(%r)" % (-angle,)
transform += " rotate(%s)" % (-angle,)


_draw_marker(
Expand Down Expand Up @@ -2682,9 +2682,9 @@ def _render(axes, mark, context):
for segment in segments:
start, stop, step = segment.indices(len(not_null))
for i in range(start, start + 1):
d.append("M %r %r" % (x[i], y[i]))
d.append("M %s %s" % (x[i], y[i]))
for i in range(start + 1, stop):
d.append("L %r %r" % (x[i], y[i]))
d.append("L %s %s" % (x[i], y[i]))
xml.SubElement(
series_xml,
"path",
Expand Down
4 changes: 2 additions & 2 deletions toyplot/require.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def hyperlink(value):
return optional_string(value)

def as_int(value,precision=None):
"""Raise an exception of a value cannot be converted to an int, or value
"""Raise an exception if a value cannot be converted to an int, or value
coerced to a python int. precision is optional but can be 8, 16, etc."""

# Try simple conversion; if this fails, move on
Expand All @@ -130,7 +130,7 @@ def as_int(value,precision=None):


def as_float(value):
"""Raise an exception of a value cannot be converted to a float, or value
"""Raise an exception if a value cannot be converted to a float, or value
coerced to a python float."""

# Try simple conversion; if this fails, move on
Expand Down

0 comments on commit cce091b

Please sign in to comment.