File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,7 +132,9 @@ def scatter! *args, &block
132132 end
133133
134134 def bar! *args , &block
135- add_plot "Bar" , *args , &block
135+ plot = Rubyplot ::Artist ::Plot ::Bar . new self
136+ yield ( plot ) if block_given?
137+ @plots << plot
136138 end
137139
138140 def line! *args , &block
Original file line number Diff line number Diff line change 11require_relative 'plot/base'
22require_relative 'plot/scatter'
33require_relative 'plot/line'
4+ require_relative 'plot/bar'
Original file line number Diff line number Diff line change 1+ module Rubyplot
2+ module Artist
3+ module Plot
4+ class Bar < Artist ::Plot ::Base
5+ # Space between the columns.
6+ attr_accessor :bar_spacing
7+ # Number between 0 and 1.0 denoting spacing between the bars.
8+ # 0.0 means no spacing at all 1.0 means that each bars' width
9+ # is nearly 0 (so each bar is a simple line with no X dimension).
10+ attr_reader :spacing_factor
11+ def initialize ( *)
12+ super
13+ @spacing_factor = 0.9
14+ end
15+
16+ # Set the spacing factor for this bar plot.
17+ def spacing_factor = sf
18+ raise ValueError , '@spacing_factor must be between 0.00 and 1.00' unless
19+ ( sf >= 0 ) && ( sf <= 1 )
20+ @spacing_factor = sf
21+ end
22+
23+ def draw
24+ super
25+ return unless @axes . geometry . has_data
26+ end
27+ end # class Bar
28+ end # module Plot
29+ end # module Artist
30+ end # module Rubyplot
31+
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ def initialize
2222 @backend = Rubyplot ::Backend ::MagickWrapper . new
2323 @width = DEFAULT_TARGET_WIDTH
2424 @height = @width * 0.75
25+ @x = 0
26+ @y = 0
2527 add_subplots @nrows , @ncols
2628 end
2729
Original file line number Diff line number Diff line change 449449 # FileUtils.rm_rf SPEC_ROOT + "temp/bar"
450450 end
451451
452- it "adds a simple bar plot" do
452+ it "adds a simple bar plot" , focus : true do
453453 fig = Rubyplot ::Figure . new
454454 axes = fig . add_subplot 0 , 0
455455 axes . bar! ( 600 ) do |p |
524524 end
525525
526526 skip "adds multiple bar plots for wide graph" do
527-
528527 fig = Rubyplot ::Figure . new
529528 axes = fig . add_subplot 0 , 0
530529 data . each do |name , nums |
You can’t perform that action at this time.
0 commit comments