ramhoj-scruffy 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scruffy/layers/stacked.rb +10 -9
- data/lib/scruffy/version.rb +1 -1
- metadata +3 -3
@@ -10,7 +10,7 @@ module Scruffy::Layers
|
|
10
10
|
# graphs work fine).
|
11
11
|
class Stacked < Base
|
12
12
|
include Scruffy::Helpers::LayerContainer
|
13
|
-
|
13
|
+
|
14
14
|
# Returns new Stacked graph.
|
15
15
|
#
|
16
16
|
# You can provide a block for easily adding layers during (just after) initialization.
|
@@ -27,21 +27,21 @@ module Scruffy::Layers
|
|
27
27
|
|
28
28
|
block.call(self) # Allow for population of data with a block during initialization.
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# Overrides Base#render to fiddle with layers' points to achieve a stacked effect.
|
32
32
|
def render(svg, options = {})
|
33
33
|
#TODO ensure this works with new points
|
34
34
|
current_points = points.dup
|
35
|
-
|
35
|
+
|
36
36
|
layers.each do |layer|
|
37
37
|
real_points = layer.points
|
38
38
|
layer.points = current_points
|
39
39
|
layer_options = options.dup
|
40
|
-
layer_options[:color] = layer.preferred_color || layer.color || options[:theme].next_color
|
40
|
+
layer_options[:color] = layer.preferred_color || layer.color || options[:theme].next_color
|
41
41
|
layer.render(svg, layer_options)
|
42
42
|
options.merge(layer_options)
|
43
43
|
layer.points = real_points
|
44
|
-
|
44
|
+
|
45
45
|
layer.points.each_with_index { |val, idx| current_points[idx] -= val }
|
46
46
|
end
|
47
47
|
end
|
@@ -59,12 +59,13 @@ module Scruffy::Layers
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
# TODO, special points accessor
|
62
|
+
# TODO, special points accessor
|
63
63
|
def points
|
64
64
|
longest_arr = layers.inject(nil) do |longest, layer|
|
65
65
|
longest = layer.points if (longest.nil? || longest.size < layer.points.size)
|
66
|
+
longest
|
66
67
|
end
|
67
|
-
|
68
|
+
|
68
69
|
summed_points = (0...longest_arr.size).map do |idx|
|
69
70
|
layers.inject(nil) do |sum, layer|
|
70
71
|
if sum.nil? && !layer.points[idx].nil?
|
@@ -72,7 +73,7 @@ module Scruffy::Layers
|
|
72
73
|
elsif !layer.points[idx].nil?
|
73
74
|
sum += layer.points[idx]
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
sum
|
77
78
|
end
|
78
79
|
end
|
@@ -84,4 +85,4 @@ module Scruffy::Layers
|
|
84
85
|
throw ArgumentsError, "Stacked layers cannot accept points, only other layers."
|
85
86
|
end
|
86
87
|
end
|
87
|
-
end
|
88
|
+
end
|
data/lib/scruffy/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 8
|
9
|
+
version: 0.2.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonas Nicklas
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-14 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|