Module: MetaPost::Stacks
- Includes:
- Standard
- Defined in:
- lib/metapost-erb.rb
Instance Attribute Summary collapse
-
#default_stack_colours ⇒ Object
Returns the value of attribute default_stack_colours.
-
#stack_sw_x ⇒ Object
Returns the value of attribute stack_sw_x.
-
#stacks ⇒ Object
Returns the value of attribute stacks.
Instance Method Summary collapse
- #box_definition(string) ⇒ Object
- #box_draw(string) ⇒ Object
- #box_label(string) ⇒ Object
- #box_position(string) ⇒ Object
- #chart(default_stack_colours, &block) ⇒ Object
- #label_box(box_name, text, corner = :n, colour = "black", rotation = nil, offset = nil, label_position = nil) ⇒ Object
- #stack(stack_name, width, heights, pen_color = self.default_stack_colours, fill_color = nil) ⇒ Object
Methods included from Standard
#draw_labels, #draw_on_layer, #labels, #layers, #v, #write!, #x, #y
Instance Attribute Details
#default_stack_colours ⇒ Object
Returns the value of attribute default_stack_colours.
94 95 96 |
# File 'lib/metapost-erb.rb', line 94 def default_stack_colours @default_stack_colours end |
#stack_sw_x ⇒ Object
Returns the value of attribute stack_sw_x.
96 97 98 |
# File 'lib/metapost-erb.rb', line 96 def stack_sw_x @stack_sw_x end |
#stacks ⇒ Object
Returns the value of attribute stacks.
95 96 97 |
# File 'lib/metapost-erb.rb', line 95 def stacks @stacks end |
Instance Method Details
#box_definition(string) ⇒ Object
139 140 141 |
# File 'lib/metapost-erb.rb', line 139 def box_definition(string) draw_on_layer 0, string end |
#box_draw(string) ⇒ Object
147 148 149 |
# File 'lib/metapost-erb.rb', line 147 def box_draw(string) draw_on_layer 2, string end |
#box_label(string) ⇒ Object
151 152 153 |
# File 'lib/metapost-erb.rb', line 151 def box_label(string) draw_on_layer 3, string end |
#box_position(string) ⇒ Object
143 144 145 |
# File 'lib/metapost-erb.rb', line 143 def box_position(string) draw_on_layer 1, string end |
#chart(default_stack_colours, &block) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/metapost-erb.rb', line 120 def chart(default_stack_colours, &block) self.stacks = nil self.stack_sw_x = nil self.default_stack_colours = default_stack_colours block.call write! end |
#label_box(box_name, text, corner = :n, colour = "black", rotation = nil, offset = nil, label_position = nil) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/metapost-erb.rb', line 128 def label_box(box_name,text,corner = :n, colour = "black", rotation = nil, offset = nil, label_position = nil) rotation ||= {'ne' => '45', 'n' => '45'}[corner.to_s] offset ||= {'ne' => "(0.5 cm, 0.5 cm)", 'n' => "(0.5 cm,0.5 cm)", 'e' => "(0.5 cm, 0 cm)"}[corner.to_s] label_position ||= {'ne' => 'urt', 'e' => 'rt', 'n' => 'urt' }[corner.to_s] anchor = "#{box_name}.#{corner}" box_label arrow = "draw (#{anchor} shifted #{offset})..(#{anchor} shifted (#{offset}/10)) withcolor #{colour}" box_label text = "label.#{label_position}( btex #{text} etex #{rotation && "rotated #{rotation}"}, (#{anchor} shifted #{offset}) ) withcolor #{colour}" arrow + ";\n" + text + ";\n" end |
#stack(stack_name, width, heights, pen_color = self.default_stack_colours, fill_color = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/metapost-erb.rb', line 98 def stack(stack_name, width, heights, pen_color = self.default_stack_colours, fill_color = nil) self.stacks ||= {} self.stacks[stack_name] = [] self.stack_sw_x ||= 0 heights = [heights] unless heights.is_a?(Array) pen_color = Array.new(heights.size,pen_color) unless pen_color.is_a?(Array) fill_color = pen_color.map { |pen| "0.75*white+0.25*(#{pen})" } unless fill_color fill_color = Array.new(heights.size,fill_color) unless fill_color.is_a?(Array) result = [] height = 0 heights.each.with_index do |box_height,i| self.stacks[stack_name] << box_name = "#{v(stack_name)}[#{i}]" box_definition "boxit.#{box_name}()" box_position "#{box_name}.sw = (#{x @stack_sw_x}, #{y height})" box_position "#{box_name}.ne = (#{x(@stack_sw_x + width)}, #{y height + box_height})" height = height + box_height box_draw "fill bpath(#{box_name}) withcolor #{fill_color[i]}" box_draw "draw bpath(#{box_name}) withcolor #{pen_color[i]}" end self.stack_sw_x = self.stack_sw_x + width end |