Class: Treemap::ImageOutput
Instance Attribute Summary
Attributes inherited from OutputBase
#color, #height, #layout, #margin_left, #margin_top, #width
Instance Method Summary
collapse
Constructor Details
#initialize {|_self| ... } ⇒ ImageOutput
Returns a new instance of ImageOutput.
17
18
19
20
21
22
23
|
# File 'lib/treemap/image_output.rb', line 17
def initialize
super
yield self if block_given?
end
|
Instance Method Details
#draw_map(node, draw, image) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/treemap/image_output.rb', line 65
def draw_map(node, draw, image)
return "" if node.nil?
if(node.color.nil?)
draw.fill("#CCCCCC")
else
draw.fill("#" + @color.get_hex_color(node.color))
end
draw.rectangle(node.bounds.x1, node.bounds.y1, node.bounds.x2, node.bounds.y2)
node.children.each do |c|
draw_map(c, draw, image)
end
end
|
#new_image ⇒ Object
38
39
40
|
# File 'lib/treemap/image_output.rb', line 38
def new_image
Magick::Image.new(@width, @height) {self.background_color = "white"}
end
|
#setup_draw ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/treemap/image_output.rb', line 25
def setup_draw
draw = Magick::Draw.new
draw.stroke_width(1)
draw.stroke("#000000")
draw.stroke_opacity(1)
draw.fill_opacity(1)
draw.font_family = "Verdana"
draw.pointsize = 12
draw.gravity = Magick::WestGravity
return draw
end
|
#to_png(node, filename = "treemap.png") ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/treemap/image_output.rb', line 42
def to_png(node, filename="treemap.png")
image = self.new_image
draw = self.setup_draw
@bounds = self.bounds
@bounds.x2 -= 1
@bounds.y2 -= 1
@layout.process(node, @bounds)
draw_map(node, draw, image)
draw.draw(image)
image.write(filename)
end
|