@@ -8,16 +8,7 @@ class Axes < Base
88 LABEL_MARGIN = 10.0
99 DEFAULT_MARGIN = 20.0
1010 THOUSAND_SEPARATOR = ',' . freeze
11- # FIXME: most of the below accessors should just be name= methods which
12- # will access the required Artist and set the variable in there directly.
13- # Range of X axis.
14- attr_accessor :x_range
15- # Range of Y axis.
16-
17- attr_accessor :y_range , :text_font , :grid , :bounding_box , :origin , :title_shift , :title_margin
18-
19- # Main title for this Axes.
20- attr_accessor :title
11+
2112 # Rubyplot::Figure object to which this Axes belongs.
2213 attr_reader :figure
2314 # Array of plots contained in this Axes.
@@ -26,24 +17,30 @@ class Axes < Base
2617 :title_font_size , :scale , :font_color , :marker_color , :axes ,
2718 :legend_margin , :backend , :marker_caps_height
2819 attr_reader :label_stagger_height
29- # FIXME: possibly disposable attrs
30- attr_reader :title_caps_height
31- # Set true if title is to be hidden.
32- attr_accessor :hide_title
33- # Margin between the X axis and the bottom of the Axes artist.
34- attr_accessor :x_axis_margin
35- # Margin between the Y axis and the left of the Axes artist.
36- attr_accessor :y_axis_margin
37- # Position of the legend box.
38- attr_accessor :legend_box_position
3920 # Rubyplot::Artist::XAxis object.
4021 attr_reader :x_axis
4122 # Rubyplot::Artist::YAxis object.
4223 attr_reader :y_axis
4324 # Array of X ticks.
4425 attr_reader :x_ticks
26+ # Array denoting co-ordinates in pixels of the origin of X and Y axes.
27+ attr_reader :origin
4528 # Number of X ticks.
4629 attr_accessor :num_x_ticks
30+ # Position of the legend box.
31+ attr_accessor :legend_box_position
32+ # Set true if title is to be hidden.
33+ attr_accessor :hide_title
34+ # Margin between the X axis and the bottom of the Axes artist.
35+ attr_accessor :x_axis_margin
36+ # Margin between the Y axis and the left of the Axes artist.
37+ attr_accessor :y_axis_margin
38+ # Range of X axis.
39+ attr_accessor :x_range
40+ # Range of Y axis.
41+ attr_accessor :y_range , :grid , :bounding_box , :title_shift
42+ # Main title for this Axes.
43+ attr_accessor :title
4744
4845 # @param figure [Rubyplot::Figure] Figure object to which this Axes belongs.
4946 def initialize ( figure )
@@ -208,16 +205,15 @@ def assign_default_label_colors
208205 end
209206
210207 def assign_x_ticks
208+ @inter_x_ticks_distance = @x_axis . length / ( @num_x_ticks . to_f -1 )
211209 unless @x_ticks
212- val_distance = ( @x_range [ 1 ] - @x_range [ 0 ] ) . abs / @num_x_ticks . to_f
213- @x_ticks = ( @x_range [ 0 ] ..@x_range [ 1 ] ) . step ( val_distance ) . map { |i | i }
210+ @x_ticks = ( @x_range [ 0 ] ..@x_range [ 1 ] ) . step ( @inter_x_ticks_distance ) . map { |i | i }
214211 end
215212 unless @x_ticks . all? { |t | t . is_a? ( Rubyplot ::Artist ::XTick ) }
216- inter_ticks_distance = @x_axis . length / ( @num_x_ticks - 1 )
217213 @x_ticks . map! . with_index do |tick_label , i |
218214 Rubyplot ::Artist ::XTick . new (
219215 self ,
220- abs_x : i * inter_ticks_distance + @x_axis . abs_x1 ,
216+ abs_x : i * @inter_x_ticks_distance + @x_axis . abs_x1 ,
221217 abs_y : @origin [ 1 ] ,
222218 label : Rubyplot ::Utils . format_label ( tick_label ) ,
223219 length : 6 ,
@@ -305,8 +301,8 @@ def set_axes_ranges
305301
306302 def set_xrange
307303 if @x_range [ 0 ] . nil? && @x_range [ 1 ] . nil?
308- @x_range [ 0 ] = @plots . map { | p | p . x_min } . min
309- @x_range [ 1 ] = @plots . map { | p | p . x_max } . max
304+ @x_range [ 0 ] = @plots . map ( & : x_min) . min
305+ @x_range [ 1 ] = @plots . map ( & : x_max) . max
310306 end
311307 @x_axis . min_val = @x_range [ 0 ]
312308 @x_axis . max_val = @x_range [ 1 ]
0 commit comments