bumpspark 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +13 -5
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bumpspark.gemspec +9 -6
- data/lib/bumpspark.rb +2 -0
- data/lib/bumpspark/formats/png.rb +2 -13
- data/lib/bumpspark/formats/string.rb +16 -0
- data/lib/bumpspark/graph.rb +5 -2
- data/lib/bumpspark/scale.rb +18 -0
- metadata +6 -4
data/README.markdown
CHANGED
@@ -19,16 +19,24 @@ Thanks to the various collaborators on _why's original post:
|
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
22
|
-
|
22
|
+
Since 1.1.0, bumpspark is only released on gemcutter. To install, you can setup gemcutter as your default gem source.
|
23
|
+
|
24
|
+
$ gem install gemcutter
|
25
|
+
$ gem tumble
|
26
|
+
|
27
|
+
Then you can install it:
|
28
|
+
|
29
|
+
$ gem install bumpspark
|
30
|
+
|
31
|
+
You can also just get it in one line:
|
32
|
+
|
33
|
+
$ gem install bumpspark -s http://gemcutter.org
|
23
34
|
|
24
35
|
## Usage
|
25
36
|
|
26
37
|
### From Rails
|
27
38
|
|
28
|
-
1. Include the gem as a dependency in `config/environment.rb`
|
29
|
-
|
30
|
-
config.gem 'bruce-bumpspark', :lib => 'bumpspark', :source => 'http://gems.github.com'
|
31
|
-
|
39
|
+
1. Include the gem as a gem dependency in `config/environment.rb`
|
32
40
|
2. Use `bumpspark_tag` from your views or helpers, passing it the data points
|
33
41
|
you'd like graphed.
|
34
42
|
|
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ begin
|
|
10
10
|
gem.email = "bruce@codefluency.com"
|
11
11
|
gem.homepage = "http://github.com/bruce/bumpspark"
|
12
12
|
gem.authors = ["Bruce Williams"]
|
13
|
+
gem.rubyforge_project = 'codefluency'
|
13
14
|
# TESTING ONLY
|
14
15
|
gem.add_development_dependency "thoughtbot-shoulda"
|
15
16
|
gem.add_development_dependency "activesupport"
|
@@ -17,6 +18,7 @@ begin
|
|
17
18
|
gem.add_development_dependency "rmagick"
|
18
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
20
|
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
20
22
|
rescue LoadError
|
21
23
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
24
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/bumpspark.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bumpspark}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bruce Williams"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-22}
|
13
13
|
s.description = %q{Generates transparent PNG "bumpspark"-style sparklines. Use from Ruby directly or as a Rails helper generating an image tag w/ built-in data, as conceived by whytheluckystiff.}
|
14
14
|
s.email = %q{bruce@codefluency.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,18 +27,20 @@ Gem::Specification.new do |s|
|
|
27
27
|
"bumpspark.gemspec",
|
28
28
|
"lib/bumpspark.rb",
|
29
29
|
"lib/bumpspark/formats/png.rb",
|
30
|
+
"lib/bumpspark/formats/string.rb",
|
30
31
|
"lib/bumpspark/graph.rb",
|
32
|
+
"lib/bumpspark/scale.rb",
|
31
33
|
"lib/bumpspark_helper.rb",
|
32
34
|
"rails/init.rb",
|
33
35
|
"test/bumpspark_helper_test.rb",
|
34
36
|
"test/bumpspark_test.rb",
|
35
37
|
"test/test_helper.rb"
|
36
38
|
]
|
37
|
-
s.has_rdoc = true
|
38
39
|
s.homepage = %q{http://github.com/bruce/bumpspark}
|
39
40
|
s.rdoc_options = ["--charset=UTF-8"]
|
40
41
|
s.require_paths = ["lib"]
|
41
|
-
s.
|
42
|
+
s.rubyforge_project = %q{codefluency}
|
43
|
+
s.rubygems_version = %q{1.3.5}
|
42
44
|
s.summary = %q{Generates "bumpspark"-style sparklines for Ruby & Rails}
|
43
45
|
s.test_files = [
|
44
46
|
"test/bumpspark_helper_test.rb",
|
@@ -68,3 +70,4 @@ Gem::Specification.new do |s|
|
|
68
70
|
s.add_dependency(%q<rmagick>, [">= 0"])
|
69
71
|
end
|
70
72
|
end
|
73
|
+
|
data/lib/bumpspark.rb
CHANGED
@@ -20,7 +20,7 @@ module Bumpspark
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def rows
|
23
|
-
|
23
|
+
scaled_numbers.inject([]) { |ary, r|
|
24
24
|
ary << [BLACK] * 15 << [BLACK] * 15
|
25
25
|
ary.last[r / 9,4] = [(r > 50 and RED or GREY)] * 4
|
26
26
|
ary
|
@@ -44,18 +44,7 @@ module Bumpspark
|
|
44
44
|
to_check = type + data
|
45
45
|
[data.length].pack("N") + to_check + [Zlib.crc32(to_check)].pack("N")
|
46
46
|
end
|
47
|
-
|
48
|
-
def normalized_numbers
|
49
|
-
nums = numbers.empty? ? [0] : numbers
|
50
|
-
min, max = nums.min, nums.max
|
51
|
-
width = max - min
|
52
|
-
return [1] * nums.size if width == 0
|
53
|
-
width += (300 * 1000)
|
54
|
-
nums.map do |result|
|
55
|
-
((result - min) * 100 / width.to_f).to_i
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
47
|
+
|
59
48
|
end
|
60
49
|
|
61
50
|
end
|
data/lib/bumpspark/graph.rb
CHANGED
@@ -2,11 +2,14 @@ module Bumpspark
|
|
2
2
|
|
3
3
|
class Graph
|
4
4
|
|
5
|
+
include Scale
|
5
6
|
include Formats::PNG
|
7
|
+
include Formats::String
|
6
8
|
|
7
|
-
attr_reader :numbers
|
8
|
-
def initialize(numbers)
|
9
|
+
attr_reader :numbers, :scale
|
10
|
+
def initialize(numbers, scale = 1)
|
9
11
|
@numbers = numbers
|
12
|
+
@scale = 1
|
10
13
|
end
|
11
14
|
|
12
15
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bumpspark
|
2
|
+
|
3
|
+
module Scale
|
4
|
+
|
5
|
+
def scaled_numbers
|
6
|
+
nums = numbers.empty? ? [0] : numbers
|
7
|
+
min, max = nums.min, nums.max
|
8
|
+
width = max - min
|
9
|
+
return [1] * nums.size if width == 0
|
10
|
+
width = width * @scale
|
11
|
+
nums.map do |result|
|
12
|
+
((result - min) * 100 / width.to_f).to_i
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumpspark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruce Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -72,7 +72,9 @@ files:
|
|
72
72
|
- bumpspark.gemspec
|
73
73
|
- lib/bumpspark.rb
|
74
74
|
- lib/bumpspark/formats/png.rb
|
75
|
+
- lib/bumpspark/formats/string.rb
|
75
76
|
- lib/bumpspark/graph.rb
|
77
|
+
- lib/bumpspark/scale.rb
|
76
78
|
- lib/bumpspark_helper.rb
|
77
79
|
- rails/init.rb
|
78
80
|
- test/bumpspark_helper_test.rb
|
@@ -101,8 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version:
|
102
104
|
requirements: []
|
103
105
|
|
104
|
-
rubyforge_project:
|
105
|
-
rubygems_version: 1.3.
|
106
|
+
rubyforge_project: codefluency
|
107
|
+
rubygems_version: 1.3.5
|
106
108
|
signing_key:
|
107
109
|
specification_version: 3
|
108
110
|
summary: Generates "bumpspark"-style sparklines for Ruby & Rails
|