@@ -12,10 +12,6 @@ class Axes < Base
1212
1313 # FIXME: most of the below accessors should just be name= methods which
1414 # will access the required Artist and set the variable in there directly.
15- # Title of the X axis
16- attr_accessor :x_title
17- # Title of the Y axis.
18- attr_accessor :y_title
1915 # Range of X axis.
2016 attr_accessor :x_range
2117 # Range of Y axis.
@@ -60,8 +56,7 @@ def initialize figure
6056 @y_axis_margin = 40.0
6157 @x_range = [ nil , nil ]
6258 @y_range = [ nil , nil ]
63-
64- @origin = [ nil , nil ]
59+
6560 @title = ""
6661 @title_shift = 0
6762 @title_margin = TITLE_MARGIN
@@ -86,8 +81,10 @@ def initialize figure
8681 @legends = [ ]
8782 @lines = [ ]
8883 @texts = [ ]
89- @x_axis = nil
90- @y_axis = nil
84+ @origin = [ nil , nil ]
85+ calculate_xy_axes_origin
86+ @x_axis = Rubyplot ::Artist ::XAxis . new ( self )
87+ @y_axis = Rubyplot ::Artist ::YAxis . new ( self )
9188
9289 @legend_box_position = :top
9390 end
@@ -114,8 +111,6 @@ def draw
114111 consolidate_plots
115112 gather_plot_data
116113 configure_title
117- calculate_xy_axes_origin
118- configure_xy_axes
119114 configure_legends
120115 configure_plotting_data
121116 actually_draw
@@ -180,10 +175,18 @@ def height
180175 ( 1 - ( @figure . top_spacing + @figure . bottom_spacing ) ) * @figure . height
181176 end
182177
183- def x_ticks = ticks_hash
184- @x_ticks = ticks_hash
178+ def x_ticks = x_ticks
179+ @x_axis . x_ticks = x_ticks
185180 end
186181
182+ def x_title = x_title
183+ @x_axis . title = x_title
184+ end
185+
186+ def y_title = y_title
187+ @y_axis . title = y_title
188+ end
189+
187190 private
188191
189192 def assign_plot_defaults
@@ -236,14 +239,6 @@ def calculate_xy_axes_origin
236239 @origin [ 1 ] = abs_y + height - @y_axis_margin
237240 end
238241
239- # Figure out co-ordinatees of the XAxis and YAxis
240- def configure_xy_axes
241- @x_axis = Rubyplot ::Artist ::XAxis . new (
242- self , @x_title , @x_range [ 0 ] , @x_range [ 1 ] )
243- @y_axis = Rubyplot ::Artist ::YAxis . new (
244- self , @y_title , @y_range [ 0 ] , @y_range [ 1 ] )
245- end
246-
247242 # Figure out co-ordinates of the legends
248243 def configure_legends
249244 @legend_box = Rubyplot ::Artist ::LegendBox . new (
@@ -310,6 +305,7 @@ def consolidate_plots
310305 end
311306 end
312307
308+ # FIXME: replace x_range and y_range with XAxis::max/min_value and YAxis::max/min_value.
313309 def gather_plot_data
314310 set_xrange
315311 set_yrange
@@ -320,13 +316,17 @@ def set_xrange
320316 @x_range [ 0 ] = @plots . map { |p | p . x_min } . min
321317 @x_range [ 1 ] = @plots . map { |p | p . x_max } . max
322318 end
319+ @x_axis . min_val = @x_range [ 0 ]
320+ @x_axis . max_val = @x_range [ 1 ]
323321 end
324322
325323 def set_yrange
326324 if @y_range [ 0 ] . nil? && @y_range [ 1 ] . nil?
327325 @y_range [ 0 ] = @plots . map { |p | p . y_min } . min
328326 @y_range [ 1 ] = @plots . map { |p | p . y_max } . max
329327 end
328+ @y_axis . min_val = @y_range [ 0 ]
329+ @y_axis . max_val = @y_range [ 1 ]
330330 end
331331 end # class Axes
332332 end # moudle Artist
0 commit comments