@@ -40,7 +40,6 @@ class Axes < Base
4040 attr_reader :plots
4141 # data variables for something
4242 attr_reader :raw_rows
43- attr_reader :backend
4443
4544 attr_reader :geometry , :font , :marker_font_size , :legend_font_size ,
4645 :title_font_size , :scale , :font_color , :marker_color , :axes ,
@@ -55,6 +54,8 @@ class Axes < Base
5554 attr_accessor :x_axis_margin
5655 # Margin between the Y axis and the left of the Axes artist.
5756 attr_accessor :y_axis_margin
57+ # Position of the legend box.
58+ attr_accessor :legend_box_position
5859
5960 # @param figure [Rubyplot::Figure] Figure object to which this Axes belongs.
6061 def initialize figure
@@ -76,8 +77,6 @@ def initialize figure
7677 @text_font = :default
7778 @grid = true
7879 @bounding_box = true
79- @x_axis_padding = :default
80- @y_axis_padding = :default
8180 @x_ticks = { }
8281 @plots = [ ]
8382
@@ -87,28 +86,46 @@ def initialize figure
8786 @geometry = Rubyplot ::MagickWrapper ::Plot ::Scatter ::Geometry . new
8887 vera_font_path = File . expand_path ( 'Vera.ttf' , ENV [ 'MAGICK_FONT_PATH' ] )
8988 @font = File . exist? ( vera_font_path ) ? vera_font_path : nil
89+ @font_color = "#000000"
9090 @marker_font_size = 15.0
9191 @legend_font_size = 20.0
9292 @legend_margin = LEGEND_MARGIN
93- @title_font_size = 36 .0
93+ @title_font_size = 25 .0
9494 @backend = @figure . backend
95- #@backend.scale(@scale)
9695 @plot_colors = [ ]
9796 @legends = [ ]
9897 @lines = [ ]
9998 @texts = [ ]
10099 @x_axis = nil
101100 @y_axis = nil
101+
102+ @legend_box_position = :top
103+ end
104+
105+ # X co-ordinate of the legend box depending on value of @legend_box_position.
106+ def legend_box_ix
107+ case @legend_box_position
108+ when :top
109+ abs_y + width / 2
110+ end
111+ end
112+
113+ # Y co-ordinate of the legend box depending on value of @legend_box_position.
114+ def legend_box_iy
115+ case @legend_box_position
116+ when :top
117+ abs_x + @x_axis_margin + @legend_margin
118+ end
102119 end
103120
104121 # Write an image to a file by communicating with the backend.
105122 def draw
106123 configure_title
107124 calculate_xy_axes_origin
108125 configure_xy_axes
109- # configure_legends
126+ configure_legends
110127 # configure_plotting_data
111- # actually_draw
128+ actually_draw
112129 # @plots.each(&:draw)
113130 end
114131
@@ -191,24 +208,6 @@ def with_backend plot_type, *args
191208 plot
192209 end
193210
194- def prepare_title
195- return if @geometry . hide_title || @title . nil?
196- t = Rubyplot ::Artist ::Text . new (
197- @title ,
198- self ,
199- x : 0 ,
200- y : @geometry . top_margin ,
201- height : 1.0 ,
202- width : @geometry . raw_columns ,
203- font : @font ,
204- color : @font_color ,
205- pointsize : @title_font_size ,
206- internal_label : "axes title."
207- )
208- @texts << t
209- @texts . each ( &:draw )
210- end
211-
212211 def prepare_legend
213212 @legends = @plots . map ( &:create_legend )
214213 @legends . each { |l | l . draw }
@@ -316,8 +315,8 @@ def configure_title
316315 @title = Rubyplot ::Artist ::Text . new (
317316 @title ,
318317 self ,
319- abs_x : abs_x ,
320- abs_y : abs_y ,
318+ abs_x : abs_x + width / 2 ,
319+ abs_y : abs_y + @title_margin ,
321320 font : @font ,
322321 color : @font_color ,
323322 pointsize : @title_font_size ,
@@ -328,22 +327,28 @@ def configure_title
328327 def calculate_xy_axes_origin
329328 @origin [ 0 ] = abs_x + @x_axis_margin
330329 @origin [ 1 ] = abs_y + height - @y_axis_margin
331- puts "origin: #{ @origin } "
332- puts "h: #{ height } "
333- puts "w: #{ width } "
334330 end
335331
336332 # Figure out co-ordinatees of the XAxis and YAxis
337333 def configure_xy_axes
338334 @x_axis = Rubyplot ::Artist ::XAxis . new (
339335 self , @x_title , @x_range [ 0 ] , @x_range [ 1 ] )
340- @x_axis . draw
341- # @y_axis = Rubyplot::Artist::YAxis.new(
342- # self, @y_title, @y_range[0], @y_range[1])
336+ @y_axis = Rubyplot ::Artist ::YAxis . new (
337+ self , @y_title , @y_range [ 0 ] , @y_range [ 1 ] )
343338 end
344339
345340 # Figure out co-ordinates of the legends
346341 def configure_legends
342+ @legend_box = Rubyplot ::Artist ::LegendBox . new (
343+ self , abs_x : legend_box_ix , abs_y : legend_box_iy )
344+ end
345+
346+ # Call the respective draw methods on each of the elements of this Axes.
347+ def actually_draw
348+ @x_axis . draw
349+ @y_axis . draw
350+ @title . draw
351+ @legend_box . draw
347352 end
348353
349354 # Return a formatted string representing a number value that should be
0 commit comments