···119119 - stroke: string => lines color, default to "#000000"
120120 - fill: string => fill color, default to "transparent"
121121122122-**svg:addText(text, x, y, style, transform)** *add text*
122122+**svg:addText(text, x, y, anchor, style, transform)** *add text*
123123124124 - text: string => the text to write
125125 - x: number => Horizontal position, default to 10
126126 - y: number => Vertical position, default to 50
127127+ - anchor: string => the text-anchor attribute (start, middle or end)
127128 - style: string => style of the text (css with svg params), default to:
128129 * `font-family: Verdana`
129130 * `font-size: 10`
···201202202203### Elements for svg:add(element) or elements rendering only
203204204204-**svg:Text(text, x, y, style, transform)** *add text*
205205+**svg:Text(text, x, y, anchor, style, transform)** *add text*
205206206207 - text: string => the text to write
207208 - x: number => Horizontal position, default to 10
208209 - y: number => Vertical position, default to 50
210210+ - anchor: string => the text-anchor attribute (start, middle or end)
209211 - style: string => style of the text (css with svg params), default to:
210212 * `font-family: Verdana`
211213 * `font-size: 10`
···11-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
11+svg={}svg.__index=svg;function svg:create(a,b,c,d)local e={}setmetatable(e,svg)e.width=a or 100;e.height=b 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,v)return self.Element:create("text",{x=q or 10,y=s or 50,["text-anchor"]=t or"start",style=u or"font-family: Verdana; font-size: 10; stroke: "..self.stroke.."; fill: "..self.fill..";",transform=v or""},p)end;function svg:addText(p,q,s,u,v)self:add(self:Text(p,q,s,u,v))end;function svg:Rect(q,s,a,b,c,w,d,x,y,v)return self.Element:create("rect",{x=q or 10,y=s or 10,width=a or 10,height=b or 10,stroke=c or self.stroke,fill=d or self.fill,["stroke-width"]=w or 1,rx=x or 0,ry=y or 0,transform=v or""})end;function svg:addRect(q,s,a,b,c,w,d,x,y,v)self:add(self:Rect(q,s,a,b,c,w,d,x,y,v))end;function svg:Circle(r,cx,cy,c,w,d,v)return self.Element:create("circle",{r=r or 25,cx=cx or 30,cy=cy or 30,stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addCircle(r,cx,cy,c,w,d,v)self:add(self:Circle(r,cx,cy,c,w,d,v))end;function svg:Ellipse(cx,cy,x,y,c,w,d,v)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"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addEllipse(cx,cy,x,y,c,w,d,v)self:add(self:Ellipse(cx,cy,x,y,c,w,d,v))end;function svg:Line(z,A,B,C,c,w,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"]=w or 1,fill=d or self.fill})end;function svg:addLine(z,A,B,C,c,w,d)self:add(self:Line(z,A,B,C,c,w,d))end;function svg:Polyline(D,c,w,d,v)return self.Element:create("polyline",{points=D or"10,10 50,50 50,25 75,25",stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addPolyline(D,c,w,d,v)self:add(self:Polyline(D,c,w,d,v))end;function svg:Path(E,c,w,d,v)return self.Element:create("path",{d=E or"M50 0 L75 100 L25 100 Z",stroke=c or self.stroke,["stroke-width"]=w or 1,fill=d or self.fill,transform=v or""})end;function svg:addPath(E,c,w,d,v)self:add(self:Path(E,c,w,d,v))end
+4-2
svg.lua
···77-- height: number => height of the drawing
88-- stroke: string => lines color
99-- fill: string => fill color
1010-function svg:create(width, heigth, stroke, fill)
1010+function svg:create(width, height, stroke, fill)
1111 local s = {}
1212 setmetatable(s,svg)
1313 s.width = width or 100
···7373-- text: string => the text to write
7474-- x: number => Horizontal position
7575-- y: number => Vertical position
7676+-- anchor: string => the text-anchor attribute (start, middle or end)
7677-- style: string => style of the text (css with svg params)
7778-- tranform: string => transformation options (eg: rotation)
7878-function svg:Text(text, x, y, style, transform)
7979+function svg:Text(text, x, y, anchor, style, transform)
7980 return self.Element:create("text", {
8081 x = x or 10,
8182 y = y or 50,
8383+ ["text-anchor"] = anchor or "start",
8284 style = style or ("font-family: Verdana; font-size: 10; stroke: " .. self.stroke .. "; fill: " .. self.fill .. ";"),
8385 transform = transform or ""
8486 }, text)