[READ-ONLY] Mirror of https://github.com/thoda-dev/svg-lua. svg lua library
0

Configure Feed

Select the types of activity you want to include in your feed.

v1.0.1 added method inndraw

Thomas (Mar 5, 2019, 5:44 PM +0100) 4ac0bb6a 76ff1b7f

+29 -2
+18
README.md
··· 71 71 <rect y="10" x="10" stroke-width="1" height="10" width="10" rx="0" ry="0" /> 72 72 ``` 73 73 74 + for several elements, you can use the normal usage and replace the `draw()` method by the `innerdraw()` 75 + 76 + ```lua 77 + mon_dessin = svg:create() 78 + mon_dessin:addRect() 79 + mon_dessin:addCircle() 80 + mon_dessin:innerdraw() 81 + ``` 82 + 83 + result for `print(mon_dessin:innerdraw())` : 84 + 85 + ```html 86 + <rect y="10" x="10" stroke-width="1" height="10" width="10" rx="0" ry="0" /> 87 + <circle stroke-width="1" r="25" cy="30" cx="30" transform="" fill="transparent" stroke="#000000" /> 88 + ``` 89 + 74 90 ### testing 75 91 76 92 can be tested [here](https://www.jdoodle.com/execute-lua-online) ··· 180 196 - element: svg.Element => see farther for element list 181 197 182 198 **svg:draw()** *return the svg formated string* 199 + 200 + **svg:draw()** *return the svg formated string for elements added to the drawing, without the outer `<svg>`* 183 201 184 202 ### Elements for svg:add(element) or elements rendering only 185 203
+1 -1
package.json
··· 1 1 { 2 2 "name": "svg-lua", 3 - "version": "1.0.0", 3 + "version": "1.0.1", 4 4 "description": "lua lib to create svg content", 5 5 "main": "svg-min.lua", 6 6 "repository": {
+1 -1
svg-min.lua
··· 1 - svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=height or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g,h)local i={}setmetatable(i,e.Element)i.name=f;i.strElement="<"..f.." "for j,k in pairs(g)do i[j]=k;i.strElement=i.strElement..j.."=\""..k.."\" "end;if h~=nil then i.strElement=i.strElement..">"..h.."</"..f..">"else i.strElement=i.strElement.."/>"end;return i end;return e end;function svg:add(l)table.insert(self.elements,l)end;function svg:draw()local m="<svg width=\""..self.width.."\" height=\""..self.height.."\" fill=\""..self.fill.."\" stroke=\""..self.stroke.."\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"for n,o in pairs(self.elements)do m=m..o.strElement end;m=m.."</svg>"return m end;function svg:Text(p,q,s,t,u)return self.Element:create("text",{x=q or 10,y=s or 50,style=t or"font-family: Verdana; font-size: 10; stroke: "..self.stroke.."; fill: "..self.fill..";",transform=u or""},p)end;function svg:addText(p,q,s,t,u)self:add(self:Text(p,q,s,t,u))end;function svg:Rect(q,s,a,height,c,v,d,w,x,u)return self.Element:create("rect",{x=q or 10,y=s or 10,width=a or 10,height=height or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=v or 1,rx=w or 0,ry=x or 0,transform=u or""})end;function svg:addRect(q,s,a,height,c,v,d,w,x,u)self:add(self:Rect(q,s,a,height,c,v,d,w,x,u))end;function svg:Circle(r,cx,cy,c,v,d,u)return self.Element:create("circle",{r=r or 25,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addCircle(r,cx,cy,c,v,d,u)self:add(self:Circle(r,cx,cy,c,v,d,u))end;function svg:Ellipse(cx,cy,w,x,c,v,d,u)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addEllipse(cx,cy,w,x,c,v,d,u)self:add(self:Ellipse(cx,cy,w,x,c,v,d,u))end;function svg:Line(y,z,A,B,c,v,d)return self.Element:create("line",{x1=r or 15,y1=r or 15,x2=cx or 50,y2=cy or 45,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill})end;function svg:addLine(y,z,A,B,c,v,d)self:add(self:Line(y,z,A,B,c,v,d))end;function svg:Polyline(C,c,v,d,u)return self.Element:create("polyline",{points=C or"10,10 50,50 50,25 75,25",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPolyline(C,c,v,d,u)self:add(self:Polyline(C,c,v,d,u))end;function svg:Path(D,c,v,d,u)return self.Element:create("path",{d=D or"M50 0 L75 100 L25 100 Z",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPath(D,c,v,d,u)self:add(self:Path(D,c,v,d,u))end 1 + svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=height or 100;e.stroke=c or"#000000"e.fill=d or"transparent"e.elements={}e.Element={}e.Element.__index=svg.Element;function e.Element:create(f,g,h)local i={}setmetatable(i,e.Element)i.name=f;i.strElement="<"..f.." "for j,k in pairs(g)do i[j]=k;i.strElement=i.strElement..j.."=\""..k.."\" "end;if h~=nil then i.strElement=i.strElement..">"..h.."</"..f..">"else i.strElement=i.strElement.."/>"end;return i end;return e end;function svg:add(l)table.insert(self.elements,l)end;function svg:draw()local m="<svg width=\""..self.width.."\" height=\""..self.height.."\" fill=\""..self.fill.."\" stroke=\""..self.stroke.."\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">"for n,o in pairs(self.elements)do m=m..o.strElement end;m=m.."</svg>"return m end;function svg:innerdraw()local m=""for n,o in pairs(self.elements)do m=m..o.strElement end;return m end;function svg:Text(p,q,s,t,u)return self.Element:create("text",{x=q or 10,y=s or 50,style=t or"font-family: Verdana; font-size: 10; stroke: "..self.stroke.."; fill: "..self.fill..";",transform=u or""},p)end;function svg:addText(p,q,s,t,u)self:add(self:Text(p,q,s,t,u))end;function svg:Rect(q,s,a,height,c,v,d,w,x,u)return self.Element:create("rect",{x=q or 10,y=s or 10,width=a or 10,height=height or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=v or 1,rx=w or 0,ry=x or 0,transform=u or""})end;function svg:addRect(q,s,a,height,c,v,d,w,x,u)self:add(self:Rect(q,s,a,height,c,v,d,w,x,u))end;function svg:Circle(r,cx,cy,c,v,d,u)return self.Element:create("circle",{r=r or 25,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addCircle(r,cx,cy,c,v,d,u)self:add(self:Circle(r,cx,cy,c,v,d,u))end;function svg:Ellipse(cx,cy,w,x,c,v,d,u)return self.Element:create("ellipse",{rx=r or 25,ry=r or 15,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addEllipse(cx,cy,w,x,c,v,d,u)self:add(self:Ellipse(cx,cy,w,x,c,v,d,u))end;function svg:Line(y,z,A,B,c,v,d)return self.Element:create("line",{x1=r or 15,y1=r or 15,x2=cx or 50,y2=cy or 45,stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill})end;function svg:addLine(y,z,A,B,c,v,d)self:add(self:Line(y,z,A,B,c,v,d))end;function svg:Polyline(C,c,v,d,u)return self.Element:create("polyline",{points=C or"10,10 50,50 50,25 75,25",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPolyline(C,c,v,d,u)self:add(self:Polyline(C,c,v,d,u))end;function svg:Path(D,c,v,d,u)return self.Element:create("path",{d=D or"M50 0 L75 100 L25 100 Z",stroke=c or self.stroke,["stroke-width"]=v or 1,fill=d or self.fill,transform=u or""})end;function svg:addPath(D,c,v,d,u)self:add(self:Path(D,c,v,d,u))end
+9
svg.lua
··· 60 60 return svgStr 61 61 end 62 62 63 + -- function to get the string formatted for the svg elements whithout the outer <svg> 64 + function svg:innerdraw() 65 + local svgStr = "" 66 + for k,v in pairs(self.elements) do 67 + svgStr = svgStr .. v.strElement 68 + end 69 + return svgStr 70 + end 71 + 63 72 -- function to add text 64 73 -- text: string => the text to write 65 74 -- x: number => Horizontal position