You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it's kinda weird to set a static 300*300 dimension to the sketches, can we change the show() method and SVG class to have a width, height property (with default values 300 of course!) ?
Here is an example:
classSVG:
"""SVG renders any svg element into an svg image. """def__init__(self, nodes, width=300, height=300):
self.nodes=nodesself.width=widthself.height=heightdefrender(self):
attrs= {
"tag": "svg",
"width": self.width,
"height": self.height,
"viewBox": f"-{self.width//2} -{self.height//2}{self.width}{self.height}",
"fill": "none",
"stroke": "black",
"xmlns": "http://www.w3.org/2000/svg",
"xmlns:xlink": "http://www.w3.org/1999/xlink"
}
svg_header=render_tag(**attrs)+"\n"svg_footer="</svg>\n"# flip the y axis so that y grows upwardsnode=Group(self.nodes) |Scale(sx=1, sy=-1)
returnsvg_header+node._svg() +svg_footerdef_repr_svg_(self):
returnself.render()
def__str__(self):
returnself.render()
def__repr__(self):
return"SVG:{self.nodes}"defshow(*shapes, width=300, height=300):
"""Shows the given shapes. It also adds a border to the canvas and axis at the origin with a light color as a reference. Parameters: shapes: The shapes to show. Examples: Show a circle: >>> show(circle()) Show a circle and square. >>> c = circle() >>> s = rect() >>> show(c, s) """markers= [
Rectangle(width=width, height=height, stroke="#ddd"),
Line(start=Point(x=-(width//2), y=0), end=Point(x=(width//2), y=0), stroke="#ddd"),
Line(start=Point(x=0, y=-(height//2)), end=Point(x=0, y=(height//2)), stroke="#ddd")
]
shapes=markers+list(shapes)
img=SVG(shapes, width=width, height=height)
fromIPython.displayimportdisplaydisplay(img)
The text was updated successfully, but these errors were encountered:
rijfas
changed the title
Re-sizeable show function
re-sizeable show function
Aug 10, 2021
it's kinda weird to set a static 300*300 dimension to the sketches, can we change the show() method and SVG class to have a width, height property (with default values 300 of course!) ?
Here is an example:
The text was updated successfully, but these errors were encountered: