jagthedrummer-scruffy 0.2.12 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,74 @@
1
+ module Scruffy::Layers
2
+ # ==Scruffy::Layers::Multi
3
+ #
4
+ # Author:: Jeremy Green
5
+ # Date:: July 29th, 2009
6
+ #
7
+ # Based on:: Scruffy::Layers::Stacked by
8
+ # Author:: Brasten Sager
9
+ # Date:: August 12th, 2006
10
+ #
11
+ # Provides a generic way for displaying multiple bar graphs side by side.
12
+ class Multi < Base
13
+ include Scruffy::Helpers::LayerContainer
14
+
15
+ # Returns new Multi graph.
16
+ #
17
+ # You can provide a block for easily adding layers during (just after) initialization.
18
+ # Example:
19
+ # Multi.new do |multi|
20
+ # multi << Scruffy::Layers::Line.new( ... )
21
+ # multi.add(:multi_bar, 'My Bar', [...])
22
+ # end
23
+ #
24
+ # The initialize method passes itself to the block, and since multi is a LayerContainer,
25
+ # layers can be added just as if they were being added to Graph.
26
+ def initialize(options={}, &block)
27
+ super(options)
28
+
29
+ block.call(self) # Allow for population of data with a block during initialization.
30
+ end
31
+
32
+ # Overrides Base#render to fiddle with layers' points to achieve a multi effect.
33
+ def render(svg, options = {})
34
+ #TODO ensure this works with new points
35
+ #current_points = points
36
+ layers.each_with_index do |layer,i|
37
+
38
+ #real_points = layer.points
39
+ #layer.points = current_points
40
+ layer_options = options.dup
41
+
42
+ layer_options[:num_bars] = layers.size
43
+ layer_options[:position] = i
44
+ layer_options[:color] = layer.preferred_color || layer.color || options[:theme].next_color
45
+ layer.render(svg, layer_options)
46
+
47
+ options.merge(layer_options)
48
+
49
+ #layer.points = real_points
50
+ #layer.points.each_with_index { |val, idx| current_points[idx] -= val }
51
+ end
52
+ end
53
+
54
+ # A multi graph has many data sets. Return legend information for all of them.
55
+ def legend_data
56
+ if relevant_data?
57
+ retval = []
58
+ layers.each do |layer|
59
+ retval << layer.legend_data
60
+ end
61
+ retval
62
+ else
63
+ nil
64
+ end
65
+ end
66
+
67
+ # TODO, special points accessor
68
+
69
+
70
+ def points=(val)
71
+ throw ArgumentsError, "Multi layers cannot accept points, only other layers."
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ module Scruffy::Layers
2
+ # ==Scruffy::Layers::MultiBar
3
+ #
4
+ # Author:: Jeremy Green
5
+ # Date:: July 29th, 2009
6
+ #
7
+ # Based on:: Scruffy::Layers::Bar by
8
+ # Author:: Brasten Sager
9
+ # Date:: August 6th, 2006
10
+ #
11
+ # Standard multi_bar graph.
12
+ class MultiBar < Bar
13
+
14
+
15
+
16
+ protected
17
+
18
+ # Due to the size of the bar graph, X-axis coords must
19
+ # be squeezed so that the bars do not hang off the ends
20
+ # of the graph.
21
+ #
22
+ # Unfortunately this just mean that bar-graphs and most other graphs
23
+ # end up on different points. Maybe adding a padding to the coordinates
24
+ # should be a graph-wide thing?
25
+ #
26
+ # Update : x-axis coords for lines and area charts should now line
27
+ # up with the center of bar charts.
28
+
29
+ def generate_coordinates(options = {})
30
+ @point_width = (width / points.size)
31
+ @point_space = @point_width * 0.1
32
+ @point_width = @point_width - @point_space
33
+ @bar_width = @point_width/options[:num_bars]
34
+ @bar_space = @bar_width * 0.1
35
+ @bar_width = @bar_width * 0.9
36
+
37
+ #options[:point_distance] = (width - (width / points.size)) / (points.size - 1).to_f
38
+
39
+ #TODO more array work with index, try to rework to be accepting of hashes
40
+ coords = (0...points.size).map do |idx|
41
+
42
+ x_coord = (@point_width * idx) + @point_space/2 + @point_space*idx + @bar_width * options[:position] + @bar_space*(options[:position].to_f - 0.5)
43
+
44
+ relative_percent = ((points[idx] == min_value) ? 0 : ((points[idx] - min_value) / (max_value - min_value).to_f))
45
+ y_coord = (height - (height * relative_percent))
46
+ [x_coord, y_coord]
47
+ end
48
+ coords
49
+ end
50
+ end
51
+ end
@@ -2,7 +2,7 @@ module Scruffy
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 9
5
+ TINY = 14
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jagthedrummer-scruffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brasten Sager
@@ -51,6 +51,8 @@ files:
51
51
  - lib/scruffy/layers/average.rb
52
52
  - lib/scruffy/layers/line.rb
53
53
  - lib/scruffy/layers/box.rb
54
+ - lib/scruffy/layers/multi.rb
55
+ - lib/scruffy/layers/multi_bar.rb
54
56
  - lib/scruffy/rasterizers.rb
55
57
  - lib/scruffy/renderers.rb
56
58
  - lib/scruffy/themes.rb