@@ -21,16 +21,14 @@ class Axes < Base
2121 # Range of Y axis.
2222 attr_accessor :y_range ,
2323 :text_font , :grid ,
24- :bounding_box , :x_axis_padding , :y_axis_padding , : origin,
24+ :bounding_box , :origin ,
2525 :title_shift , :title_margin
2626 # Main title for this Axes.
2727 attr_accessor :title
2828 # Rubyplot::Figure object to which this Axes belongs.
2929 attr_reader :figure
3030 # Array of plots contained in this Axes.
3131 attr_reader :plots
32- # data variables for something
33- attr_reader :raw_rows
3432
3533 attr_reader :geometry , :font , :marker_font_size , :legend_font_size ,
3634 :title_font_size , :scale , :font_color , :marker_color , :axes ,
@@ -112,7 +110,9 @@ def legend_box_iy
112110
113111 # Write an image to a file by communicating with the backend.
114112 def draw
113+ assign_plot_defaults
115114 consolidate_plots
115+ gather_plot_data
116116 configure_title
117117 calculate_xy_axes_origin
118118 configure_xy_axes
@@ -186,6 +186,19 @@ def x_ticks= ticks_hash
186186
187187 private
188188
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+
189202 def add_plot plot_type , *args , &block
190203 plot = with_backend plot_type , *args
191204 yield ( plot ) if block_given?
@@ -204,11 +217,6 @@ def with_backend plot_type, *args
204217 plot
205218 end
206219
207- def prepare_legend
208- @legends = @plots . map ( &:create_legend )
209- @legends . each { |l | l . draw }
210- end
211-
212220 # Figure out the co-ordinates of the title text w.r.t Axes.
213221 def configure_title
214222 @title = Rubyplot ::Artist ::Text . new (
@@ -296,8 +304,29 @@ def label_string(value, increment)
296304
297305 def consolidate_plots
298306 bars = @plots . grep ( Rubyplot ::Artist ::Plot ::Bar )
299- @plots . delete_if { |p | p . is_a? ( Rubyplot ::Artist ::Plot ::Bar ) }
300- @plots << Rubyplot ::Artist ::Plot ::MultiBars . new ( self , bar_plots : bars )
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
301330 end
302331 end # class Axes
303332 end # moudle Artist
0 commit comments