Package: jk-svg
jk_svgIntroductionThis python module implements a set of classes for easy programmatic create of SVG graphics.Information about this module can be found here:github.orgpypi.python.orgWhy this module?Sometimes it is easier to create SVG graphics (or parts of SVG graphics) programmatically than drawing them by hand. This module assists in this task of creating such SVG graphics as there is no comparable module offering these kind of features.Limitations of this moduleThis module currently only supports these kind of shapes:circleellipseglinepolygonpolylinerectAdditionally arbitrary elements of any kind can be provided, but those listed above will have a more beautiful API.How to use this moduleImport this modulePlease include this module into your application using the following code:importjk_svgCreate an SVG graphic main nodeTo be able to create geometry nodes we need to create a SVG graphic object first:svg=SVGGraphic()Now we will be able to add arbitrary graphical SVG objects.How to build SVG graphicsSVG elements form a hierarchical structure. In order to stack SVG elements you therefore require nodes and subnodes that represent graphical shapes. Have a look at this SVG file:<?xml version="1.0" encoding="UTF-8" standalone="no"?><svgxmlns:svg="http://www.w3.org/2000/svg"height="297mm"width="210mm"version="1.1"><g><linestyle="opacity:1;fill:none;fill-opacity:1;stroke:#008000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:5;stroke-dasharray:none;stroke-opacity:1"y1="100"x2="300"x1="100"y2="200"/><ellipsestyle="opacity:1;fill:none;fill-opacity:1;stroke:#0000c0;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:5;stroke-dasharray:none;stroke-opacity:1"cx="250"cy="140"ry="50"rx="75"/><polygonstyle="opacity:1;fill:none;fill-opacity:1;stroke:#c00000;stroke-width:5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:5;stroke-dasharray:none;stroke-opacity:1"points="120,100 200,120 180,200 100,180"/></g></svg>This file can be created using the following python code:withsvg.createGroup()asg:withg.createLine()asline:line.style=STYLE_GREENline.x1=100line.y1=100line.x2=300line.y2=200withg.createEllipse()asellipse:ellipse.style=STYLE_BLUEellipse.cx=250ellipse.cy=140ellipse.rx=75ellipse.ry=50withg.createPolygon()aspoly:poly.style=STYLE_REDpoly.points.append((20,0))poly.points.append((100,20))poly.points.append((80,100))poly.points.append((0,80))poly.move(100,100)Thewithstatements shown in this example are just a convenience to allow the source code to better reflect the hierarchical structure of the resulting SVG file. In this specific case there are no specific actions involved in entering or leaving this context. So the code shown above is equivalent to the following example:g=svg.createGroup()line=g.createLine()line.style=STYLE_GREENline.x1=100line.y1=100line.x2=300line.y2=200ellipse=g.createEllipse()ellipse.style=STYLE_BLUEellipse.cx=250ellipse.cy=140ellipse.rx=75ellipse.ry=50poly=g.createPolygon()poly.style=STYLE_REDpoly.points.append((20,0))poly.points.append((100,20))poly.points.append((80,100))poly.points.append((0,80))poly.move(100,100)The mechanism is always the same: Create a subcomponent that will be a child component to its parent. In this examplegis created which is then used to create aline, a anellipseand apolygonsubcomponent. While every component is basically the same ans contains anattributesandchildrenmember that holds the attributes and children, additional convenience members are provided. Here they are used to specify location, shape and style data. These convenience members depend on the specific shape: Therefore if you usecreateLine()you will get a slightly different SVG object compared to callingcreateEllipse()or any other create-method. This aspect assists in working with SVG data as it makes defining geometries very easy.Contact InformationThis work is Open Source. This enables you to use this work for free.Please have in mind this also enables you to contribute. We, the subspecies of software developers, can create great things. But the more collaborate, the more fantastic these things can become. Therefore Feel free to contact the author(s) listed below, either for giving feedback, providing comments, hints, indicate possible collaborations, ideas, improvements. Or maybe for "only" reporting some bugs:Jürgen Knauth:pubsrc@binary-overflow.deLicenseThis software is provided under the following license:Apache Software License 2.0