class SVG
Attributes
height[R]
width[R]
Public Class Methods
new(io,width,height)
click to toggle source
# File lib/svg-lib.rb, line 6 def initialize(io,width,height) @io = io @width = width @height = height end
new(x:,y:,width:,height:,io: STDOUT,**args) { |svg| ... }
click to toggle source
Calls superclass method
# File lib/svg-lib.rb, line 17 def self.new(x:,y:,width:,height:,io: STDOUT,**args) svg = super(io,width,height) svg.print %(<svg viewBox="#{x} #{y} #{width} #{height}" version="1.1" xmlns="http://www.w3.org/2000/svg" ) svg.print_args(**args) svg.print(" >") yield svg svg.puts "</svg>" end
transform() { |transform| ... }
click to toggle source
# File lib/transform.rb, line 38 def self.transform io = StringIO.new yield Transform.new(io) return io.string end
Public Instance Methods
circle(cx:,cy:,r:,title: "",**args)
click to toggle source
# File lib/shapes.rb, line 18 def circle(cx:,cy:,r:,title: "",**args) @io.print %(<circle cx="#{cx}" cy="#{cy}" r="#{r}" ) print_args(**args) @io.print " >" print_title(title) @io.puts("</circle>") end
defs() { |self| ... }
click to toggle source
# File lib/containers.rb, line 2 def defs @io.puts "<defs>" yield self @io.puts "</defs>" end
g(**args) { |self| ... }
click to toggle source
# File lib/containers.rb, line 17 def g(**args) @io.print %(<g ) print_args(**args) @io.puts %( >) yield self @io.puts %(</g>) end
line(x1:,y1:,x2:,y2:,title: "",**args)
click to toggle source
# File lib/shapes.rb, line 10 def line(x1:,y1:,x2:,y2:,title: "",**args) @io.print %(<line x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}" ) print_args(**args) @io.print " >" print_title(title) @io.puts("</line>") end
marker(id:,viewBox:,refX:,refY:,title: "",**args) { |self| ... }
click to toggle source
# File lib/containers.rb, line 8 def marker(id:,viewBox:,refX:,refY:,title: "",**args) @io.print %(<marker id="#{id}" viewBox="#{viewBox.join(" ")}" refX="#{refX}" refY="#{refY}" ) print_args(**args) @io.puts " >" print_title(title) yield self @io.puts "</marker>" end
path(title: "",**args) { |path| ... }
click to toggle source
# File lib/shapes.rb, line 40 def path(title: "",**args) @io.print %(<path d=") yield Path.new(self) @io.print %(" ) print_args(**args) @io.puts %( >) print_title(title) @io.puts %(</path>) end
plot()
click to toggle source
# File lib/plot2d.rb, line 3 def plot return Plot.new end
polygon(points:,title: "",**args)
click to toggle source
# File lib/shapes.rb, line 26 def polygon(points:,title: "",**args) @io.print "<polygon " @io.print "points=\"" points.each do |p| @io.print p[0],",",p[1]," " end @io.print "\" " print_args(**args) @io.print " >" print_title(title) @io.puts "</polygon>" end
print(*args)
click to toggle source
# File lib/svg-lib.rb, line 14 def print(*args) @io.print(*args) end
print_args(**args)
click to toggle source
# File lib/svg-lib.rb, line 25 def print_args(**args) args.each do |k,v| @io.print k.to_s.gsub("_","-"),"=","\"",v,"\""," " end end
print_title(title)
click to toggle source
# File lib/svg-lib.rb, line 30 def print_title(title) @io.puts %(<title>#{title}</title>) if title != "" end
puts(*args)
click to toggle source
# File lib/svg-lib.rb, line 11 def puts(*args) @io.puts(*args) end
rect(x:,y:,width:,height:,title: "",**args)
click to toggle source
# File lib/shapes.rb, line 2 def rect(x:,y:,width:,height:,title: "",**args) @io.print %(<rect x="#{x}" y="#{y}" width="#{width}" height="#{height}" ) print_args(**args) @io.print " >" print_title(title) @io.puts("</rect>") end
text(x:,y:,text:,title: "",**args)
click to toggle source
# File lib/text.rb, line 2 def text(x:,y:,text:,title: "",**args) @io.print %(<text x="#{x}" y="#{y}" ) print_args(**args) @io.print " >" print_title(title) @io.print text @io.puts "</text>" end