grosser-db_graph 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +2 -3
- data/VERSION.yml +1 -1
- data/lib/db_graph/line.rb +14 -5
- data/spec/db_graph/line_spec.rb +15 -6
- metadata +2 -2
data/README.markdown
CHANGED
@@ -3,9 +3,8 @@ Gem/Rails plugin to generate graphs from all your date fields, beautifully simpl
|
|
3
3
|
Examples
|
4
4
|
========
|
5
5
|
Weeks and months
|
6
|
-

|
7
|
+

|
9
8
|
|
10
9
|
Install
|
11
10
|
=======
|
data/VERSION.yml
CHANGED
data/lib/db_graph/line.rb
CHANGED
@@ -33,7 +33,7 @@ module DBGraph
|
|
33
33
|
size = @options[:size] || '600x500'
|
34
34
|
GoogleChart::LineChart.new(size, nil, false) do |line|
|
35
35
|
for name, hash in data
|
36
|
-
line.data(name,
|
36
|
+
line.data(name, klass.filled_and_sorted_values(hash, x_values), klass.color_for(name))
|
37
37
|
end
|
38
38
|
line.axis :x, :labels => x_labels
|
39
39
|
line.axis :y, :labels => y_labels
|
@@ -51,7 +51,7 @@ module DBGraph
|
|
51
51
|
|
52
52
|
def y_labels
|
53
53
|
values = []
|
54
|
-
data.each{|name,hash|values +=
|
54
|
+
data.each{|name,hash|values += klass.filled_and_sorted_values(hash, x_values)}
|
55
55
|
distribute_evently(values, NUM_Y_LABELS)
|
56
56
|
end
|
57
57
|
|
@@ -63,6 +63,10 @@ module DBGraph
|
|
63
63
|
|
64
64
|
private
|
65
65
|
|
66
|
+
def klass
|
67
|
+
self.class
|
68
|
+
end
|
69
|
+
|
66
70
|
def x_values
|
67
71
|
case @style
|
68
72
|
when :minutes then 0..59
|
@@ -74,15 +78,20 @@ module DBGraph
|
|
74
78
|
end.to_a
|
75
79
|
end
|
76
80
|
|
77
|
-
|
78
|
-
|
81
|
+
#determines a unique color based on a name
|
82
|
+
def self.color_for(name)
|
83
|
+
name = name.inspect + "some randomness for fun"
|
84
|
+
hash = (name.hash % 1_000_000_000).to_s #get a hash of a constant size
|
85
|
+
colors = [hash[0..1], hash[2..3], hash[4..5]].map{|c| c.to_f / 100.0 * 16} #use 3 parts of the hash to get numbers from 0 to 15.99
|
86
|
+
palette = ('0'..'9').to_a + ('a'..'f').to_a #hex values 0..f
|
87
|
+
colors.map{|c| palette[c.floor].to_s * 2} * '' #each color is duplicated and the joined
|
79
88
|
end
|
80
89
|
|
81
90
|
def interval_for(time)
|
82
91
|
interval_word = {:minutes=>:hour,:hours=>:day,:days=>:month,:weeks=>:year,:months=>:year}[@style]
|
83
92
|
raise "style #{@style} is not supported" unless interval_word
|
84
93
|
|
85
|
-
start =
|
94
|
+
start = klass.at_beginning_of_interval(time, interval_word)
|
86
95
|
ende = start + 1.send(interval_word) - 1.second
|
87
96
|
[start, ende]
|
88
97
|
end
|
data/spec/db_graph/line_spec.rb
CHANGED
@@ -205,14 +205,23 @@ describe DBGraph::Line do
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
describe :
|
209
|
-
|
210
|
-
|
208
|
+
describe :color_for do
|
209
|
+
it "returns the same color for the same names" do
|
210
|
+
c1 = DBGraph::Line.send(:color_for,'User found_at')
|
211
|
+
c2 = DBGraph::Line.send(:color_for,'User found_at')
|
212
|
+
c1.should == c2
|
213
|
+
end
|
214
|
+
|
215
|
+
it "returns different colors for different names" do
|
216
|
+
c1 = DBGraph::Line.send(:color_for,'User found_at')
|
217
|
+
c2 = DBGraph::Line.send(:color_for,'User created_at')
|
218
|
+
c1.should_not == c2
|
211
219
|
end
|
212
220
|
|
213
|
-
it "
|
214
|
-
|
215
|
-
|
221
|
+
it "returns a color for empty/nil/[] names" do
|
222
|
+
[nil,[],'',' '].each do |value|
|
223
|
+
DBGraph::Line.send(:color_for,value).length.should == 6
|
224
|
+
end
|
216
225
|
end
|
217
226
|
end
|
218
227
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grosser-db_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|