@@ -20,26 +20,15 @@ class Axes < Base
2020 attr_accessor :x_range
2121 # Range of Y axis.
2222 attr_accessor :y_range ,
23- :x_tick_count , :y_tick_count , : text_font, :grid ,
24- :bounding_box , :x_axis_padding , :y_axis_padding , : origin,
23+ :text_font , :grid ,
24+ :bounding_box , :origin ,
2525 :title_shift , :title_margin
26-
27- # A hash of names for the individual columns, where the key is the array
28- # index for the column this label represents.
29- #
30- # Not all columns need to be named.
31- #
32- # Example: 0 => 2005, 3 => 2006, 5 => 2007, 7 => 2008
33- attr_accessor :x_ticks
34- attr_accessor :y_ticks
3526 # Main title for this Axes.
3627 attr_accessor :title
3728 # Rubyplot::Figure object to which this Axes belongs.
3829 attr_reader :figure
3930 # Array of plots contained in this Axes.
4031 attr_reader :plots
41- # data variables for something
42- attr_reader :raw_rows
4332
4433 attr_reader :geometry , :font , :marker_font_size , :legend_font_size ,
4534 :title_font_size , :scale , :font_color , :marker_color , :axes ,
@@ -71,8 +60,6 @@ def initialize figure
7160 @y_axis_margin = 40.0
7261 @x_range = [ nil , nil ]
7362 @y_range = [ nil , nil ]
74- @x_tick_count = :default
75- @y_tick_count = :default
7663
7764 @origin = [ nil , nil ]
7865 @title = ""
@@ -81,7 +68,6 @@ def initialize figure
8168 @text_font = :default
8269 @grid = true
8370 @bounding_box = true
84- @x_ticks = { }
8571 @plots = [ ]
8672
8773 @raw_rows = width * ( height /width )
@@ -124,6 +110,9 @@ def legend_box_iy
124110
125111 # Write an image to a file by communicating with the backend.
126112 def draw
113+ assign_plot_defaults
114+ consolidate_plots
115+ gather_plot_data
127116 configure_title
128117 calculate_xy_axes_origin
129118 configure_xy_axes
@@ -191,8 +180,25 @@ def height
191180 ( 1 - ( @figure . top_spacing + @figure . bottom_spacing ) ) * @figure . height
192181 end
193182
183+ def x_ticks = ticks_hash
184+ @x_ticks = ticks_hash
185+ end
186+
194187 private
195188
189+ def assign_plot_defaults
190+ assign_label_colors
191+ end
192+
193+ def assign_label_colors
194+ @plots . each_with_index do |p , i |
195+ if p . color == :default
196+ p . color = @figure . theme_options [ :label_colors ] [
197+ i % @figure . theme_options [ :label_colors ] . size ]
198+ end
199+ end
200+ end
201+
196202 def add_plot plot_type , *args , &block
197203 plot = with_backend plot_type , *args
198204 yield ( plot ) if block_given?
@@ -211,11 +217,6 @@ def with_backend plot_type, *args
211217 plot
212218 end
213219
214- def prepare_legend
215- @legends = @plots . map ( &:create_legend )
216- @legends . each { |l | l . draw }
217- end
218-
219220 # Figure out the co-ordinates of the title text w.r.t Axes.
220221 def configure_title
221222 @title = Rubyplot ::Artist ::Text . new (
@@ -300,6 +301,33 @@ def label_string(value, increment)
300301 parts [ 0 ] . gsub! ( /(\d )(?=(\d \d \d )+(?!\d ))/ , "\\ 1#{ THOUSAND_SEPARATOR } " )
301302 parts . join ( '.' )
302303 end
304+
305+ def consolidate_plots
306+ bars = @plots . grep ( Rubyplot ::Artist ::Plot ::Bar )
307+ if !bars . empty?
308+ @plots . delete_if { |p | p . is_a? ( Rubyplot ::Artist ::Plot ::Bar ) }
309+ @plots << Rubyplot ::Artist ::Plot ::MultiBars . new ( self , bar_plots : bars )
310+ end
311+ end
312+
313+ def gather_plot_data
314+ set_xrange
315+ set_yrange
316+ end
317+
318+ def set_xrange
319+ if @x_range [ 0 ] . nil? && @x_range [ 1 ] . nil?
320+ @x_range [ 0 ] = @plots . map { |p | p . x_min } . min
321+ @x_range [ 1 ] = @plots . map { |p | p . x_max } . max
322+ end
323+ end
324+
325+ def set_yrange
326+ if @y_range [ 0 ] . nil? && @y_range [ 1 ] . nil?
327+ @y_range [ 0 ] = @plots . map { |p | p . y_min } . min
328+ @y_range [ 1 ] = @plots . map { |p | p . y_max } . max
329+ end
330+ end
303331 end # class Axes
304332 end # moudle Artist
305333end # module Rubyplot
0 commit comments