Class: AlGraph::GraphBase
Overview
各グラフのベースクラス
Direct Known Subclasses
Constant Summary collapse
- COLOR_LIST =
[ '#004586', '#ff420e', '#ffd320', '#579d1c', '#7e0021', '#83caff', '#314004', '#aecf00', '#4b1f6f', '#ff950e', '#c5000b', '#0084d1' ]
Constants inherited from GraphView
AlGraph::GraphView::ATTR_NAMES
Instance Attribute Summary collapse
-
#at_graph_area ⇒ Hash
グラフエリアアトリビュート.
-
#at_legend ⇒ Hash
凡例アトリビュート.
-
#at_main_title ⇒ Hash
メインタイトルアトリビュート.
-
#at_plot_area ⇒ Hash
プロットエリアアトリビュート.
-
#color_list ⇒ Array<String>
色リスト.
-
#output ⇒ Kernel, StringIO
出力制御オブジェクト.
Attributes inherited from GraphView
Instance Method Summary collapse
-
#add_aux_tag(text) ⇒ Object
(GraphBase) 任意タグを追加.
-
#add_legend ⇒ Object
(GraphBase) 凡例表示追加.
-
#add_main_title(title_string) ⇒ Object
(GraphBase) メインタイトルの追加.
-
#add_text(x, y, text) ⇒ Object
(GraphBase) テキスト追加.
-
#draw_buffer ⇒ Object
(GraphBase) バッファーへ描画.
-
#initialize(width, height) ⇒ GraphBase
constructor
(GraphBase) constructor.
-
#set_margin(top, right, bottom, left) ⇒ Object
(GraphBase) プロットエリアのマージン設定.
-
#set_mode(mode) ⇒ Object
(GraphBase) 動作モード指定.
Constructor Details
#initialize(width, height) ⇒ GraphBase
(GraphBase) constructor
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/al_graph_base.rb', line 164 def initialize(width, height) super( width, height ) @at_graph_area = { :width=>@width, :height=>@height, :stroke_width=>1, :stroke=>"black", :fill=>"white" } @at_plot_area = { :x=>0, :y=>0, :width=>0, :height=>0 } @at_main_title = nil @at_legend = nil @color_list = COLOR_LIST # 追加任意タグ @aux_tags = [] # 動作モード (see set_mode() function.) @work_mode = {:SVGTAG_START=>true, :SVGTAG_END=>true} @output = Kernel end |
Instance Attribute Details
#at_graph_area ⇒ Hash
Returns グラフエリアアトリビュート.
139 140 141 |
# File 'lib/al_graph_base.rb', line 139 def at_graph_area @at_graph_area end |
#at_legend ⇒ Hash
Returns 凡例アトリビュート.
148 149 150 |
# File 'lib/al_graph_base.rb', line 148 def at_legend @at_legend end |
#at_main_title ⇒ Hash
Returns メインタイトルアトリビュート.
145 146 147 |
# File 'lib/al_graph_base.rb', line 145 def at_main_title @at_main_title end |
#at_plot_area ⇒ Hash
Returns プロットエリアアトリビュート.
142 143 144 |
# File 'lib/al_graph_base.rb', line 142 def at_plot_area @at_plot_area end |
#color_list ⇒ Array<String>
Returns 色リスト.
151 152 153 |
# File 'lib/al_graph_base.rb', line 151 def color_list @color_list end |
#output ⇒ Kernel, StringIO
Returns 出力制御オブジェクト.
154 155 156 |
# File 'lib/al_graph_base.rb', line 154 def output @output end |
Instance Method Details
#add_aux_tag(text) ⇒ Object
(GraphBase) 任意タグを追加
284 285 286 |
# File 'lib/al_graph_base.rb', line 284 def add_aux_tag(text) @aux_tags << text end |
#add_legend ⇒ Object
(GraphBase) 凡例表示追加
自動追加されるので、たいていの場合、ユーザがこのメソッドを使うことはないかもしれない。
270 271 272 273 274 275 276 |
# File 'lib/al_graph_base.rb', line 270 def add_legend() return if @at_legend right = @width - @at_plot_area[:width] - @at_plot_area[:x] + 70 set_margin(nil, right, nil, nil) @at_legend = {:x=>@width - 60, :font_size=>10, :line_spacing=>4} end |
#add_main_title(title_string) ⇒ Object
(GraphBase) メインタイトルの追加
259 260 261 262 |
# File 'lib/al_graph_base.rb', line 259 def add_main_title(title_string) set_margin(25, nil, nil, nil) @at_main_title = {:node_value=>title_string, :y=>20, :font_size=>16, :text_anchor=>'middle'} end |
#add_text(x, y, text) ⇒ Object
(GraphBase) テキスト追加
299 300 301 |
# File 'lib/al_graph_base.rb', line 299 def add_text(x, y, text) @aux_tags << %!<text x="#{x}" y="#{y}">#{text}</text>\n! end |
#draw_buffer ⇒ Object
(GraphBase) バッファーへ描画
240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/al_graph_base.rb', line 240 def draw_buffer() @work_mode[:CONTENT_TYPE] = false if !@work_mode.key?(:CONTENT_TYPE) @work_mode[:XML_DECLARATION] = false if !@work_mode.key?(:XML_DECLARATION) output_bak = @output s = "" @output = StringIO.new(s) draw() @output = output_bak return s end |
#set_margin(top, right, bottom, left) ⇒ Object
(GraphBase) プロットエリアのマージン設定
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/al_graph_base.rb', line 216 def set_margin(top, right, bottom, left) # calculate insufficiency parameters. top ||= @at_plot_area[:y] right ||= @width - @at_plot_area[:width] - @at_plot_area[:x] bottom ||= @height - @at_plot_area[:height] - @at_plot_area[:y] left ||= @at_plot_area[:x] # set plot area parameters @at_plot_area[:x] = left @at_plot_area[:y] = top @at_plot_area[:width] = @width - left - right @at_plot_area[:height] = @height - top - bottom @at_plot_area[:width] = 0 if @at_plot_area[:width] < 0 @at_plot_area[:height] = 0 if @at_plot_area[:height] < 0 end |
#set_mode(mode) ⇒ Object
(GraphBase) 動作モード指定
194 195 196 197 198 199 200 201 202 |
# File 'lib/al_graph_base.rb', line 194 def set_mode(mode) mode = mode.to_s if mode.start_with?("NO_") mode.slice!(0, 3) @work_mode[mode.to_sym] = false else @work_mode[mode.to_sym] = true end end |