Class: SVG
- Inherits:
-
Object
show all
- Defined in:
- lib/text.rb,
lib/plot2d.rb,
lib/shapes.rb,
lib/svg-lib.rb,
lib/transform.rb,
lib/containers.rb,
lib/plot2d/boxplot.rb,
lib/plot2d/markers.rb,
lib/plot2d/scatter.rb,
lib/plot2d/lineplot.rb
Defined Under Namespace
Classes: Path, Plot, Transform
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#circle(cx:, cy:, r:, title: "", **args) ⇒ Object
-
#defs {|_self| ... } ⇒ Object
-
#g(**args) {|_self| ... } ⇒ Object
-
#initialize(io, width, height) ⇒ SVG
constructor
-
#line(x1:, y1:, x2:, y2:, title: "", **args) ⇒ Object
-
#marker(id:, viewBox:, refX:, refY:, title: "", **args) {|_self| ... } ⇒ Object
-
#path(title: "", **args) {|Path.new(self)| ... } ⇒ Object
-
#plot ⇒ Object
-
#polygon(points:, title: "", **args) ⇒ Object
-
#print(*args) ⇒ Object
-
#print_args(**args) ⇒ Object
-
#print_title(title) ⇒ Object
-
#puts(*args) ⇒ Object
-
#rect(x:, y:, width:, height:, title: "", **args) ⇒ Object
-
#text(x:, y:, text:, title: "", **args) ⇒ Object
Constructor Details
#initialize(io, width, height) ⇒ SVG
Returns a new instance of SVG.
6
7
8
9
10
|
# File 'lib/svg-lib.rb', line 6
def initialize(io,width,height)
@io = io
@width = width
@height = height
end
|
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
5
6
7
|
# File 'lib/svg-lib.rb', line 5
def height
@height
end
|
#width ⇒ Object
Returns the value of attribute width.
4
5
6
|
# File 'lib/svg-lib.rb', line 4
def width
@width
end
|
Class Method Details
.new(x:, y:, width:, height:, io: STDOUT, **args) {|svg| ... } ⇒ Object
17
18
19
20
21
22
23
24
|
# 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
|
38
39
40
41
42
|
# File 'lib/transform.rb', line 38
def self.transform
io = StringIO.new
yield Transform.new(io)
return io.string
end
|
Instance Method Details
#circle(cx:, cy:, r:, title: "", **args) ⇒ Object
18
19
20
21
22
23
24
|
# 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| ... } ⇒ Object
2
3
4
5
6
|
# File 'lib/containers.rb', line 2
def defs
@io.puts "<defs>"
yield self
@io.puts "</defs>"
end
|
#g(**args) {|_self| ... } ⇒ Object
17
18
19
20
21
22
23
|
# 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) ⇒ Object
10
11
12
13
14
15
16
|
# 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| ... } ⇒ Object
8
9
10
11
12
13
14
15
|
# 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.new(self)| ... } ⇒ Object
40
41
42
43
44
45
46
47
48
|
# 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 ⇒ Object
3
4
5
|
# File 'lib/plot2d.rb', line 3
def plot
return Plot.new
end
|
#polygon(points:, title: "", **args) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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) ⇒ Object
14
15
16
|
# File 'lib/svg-lib.rb', line 14
def print(*args)
@io.print(*args)
end
|
#print_args(**args) ⇒ Object
25
26
27
28
29
|
# 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) ⇒ Object
30
31
32
|
# File 'lib/svg-lib.rb', line 30
def print_title(title)
@io.puts %(<title>#{title}</title>) if title != ""
end
|
#puts(*args) ⇒ Object
11
12
13
|
# File 'lib/svg-lib.rb', line 11
def puts(*args)
@io.puts(*args)
end
|
#rect(x:, y:, width:, height:, title: "", **args) ⇒ Object
2
3
4
5
6
7
8
|
# 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) ⇒ Object
2
3
4
5
6
7
8
9
|
# 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
|