lib/lilygraph.rb in lilygraph-0.5.1 vs lib/lilygraph.rb in lilygraph-0.5.2
- old
+ new
@@ -33,11 +33,11 @@
# of labels. The size of this array should = the size of the data array.
attr_accessor :labels
# This is the data for the graph. It should be an array where every item is
# either a number or an array of numbers.
- #
+ #
# For a simple bar graph:
# graph.data=[1,2,3]
# For a grouped bar graph:
# graph.data=[[1,10],[2,20],[3,30]]
attr_accessor :data
@@ -55,11 +55,11 @@
# Last but not least you can set the color value to any object that responds to call (like a Proc). The proc takes four arguments.
# data_index: The index of the current bar (or group)
# number_index: The index of the current bar INSIDE of the current bar group (always 0 if you don't have grouped bars)
# data_size: total number of bar or groups.
# number_size: total number of bars in the current group (always 1 if you don't have bar groups)
- #
+ #
# The default proc looks like:
# graph.colors=Proc.new do |data_index, number_index, data_size, number_size|
# Color::HSL.from_fraction(Float(data_index) / Float(data_size), 1.0, 0.4 + (Float(number_index) / Float(number_size) * 0.4)).to_rgb.html
# end
attr_accessor :colors
@@ -183,11 +183,11 @@
data.each_with_index do |number, number_index|
color = if @colors.respond_to? :call
@colors.call(data_index, number_index, @data.size, data.size)
elsif @colors.class == Array
first = @colors[data_index % (@colors.size)]
-
+
if first.class == Array
first[number_index % (first.size)]
else
first
end
@@ -209,11 +209,11 @@
xml.line(:x1 => last_spot[number_index][:x], :y1 => last_spot[number_index][:y], :x2 => bar_x, :y2 => bar_y,
:fill => color, :stroke => color, 'stroke-width' => 2.0)
end
xml.circle :cx => bar_x, :cy => bar_y, :fill => color, :stroke => color, :r => bar_width * 1.5
end
-
+
last_spot[number_index] = { :x => bar_x, :y => bar_y }
end
end
@data.each_with_index do |data, data_index|
@@ -293,10 +293,10 @@
num.respond_to?(:max) ? num.max : num
end.max || 0
end
def division
- (10 ** Math.log10(data_max).floor) / 10
+ [(10 ** Math.log10(data_max).floor) / 10, 1].max
end
def max
(((data_max + (division / 10)) / Float(division)).ceil * Float(division)).round
end