bumpspark 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -4
- data/.gitignore +16 -3
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/{LICENSE → LICENSE.txt} +3 -1
- data/README.md +91 -0
- data/Rakefile +5 -59
- data/bumpspark.gemspec +21 -68
- data/exe/bumpspark +7 -0
- data/lib/bumpspark.rb +2 -8
- data/lib/bumpspark/formats/data_uri.rb +24 -0
- data/lib/bumpspark/graph.rb +7 -1
- data/lib/bumpspark/helper.rb +17 -0
- data/lib/bumpspark/railtie.rb +10 -0
- data/lib/bumpspark/version.rb +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/pages_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/pages_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/pages/home.html.erb +6 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +70 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/application_helper_spec.rb +12 -0
- data/spec/lib/bumpspark/graph_spec.rb +30 -0
- data/spec/lib/bumpspark/helper_spec.rb +21 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/matchers/valid_png.rb +9 -0
- metadata +190 -87
- data/README.markdown +0 -74
- data/VERSION +0 -1
- data/lib/bumpspark_helper.rb +0 -19
- data/rails/init.rb +0 -1
- data/test/bumpspark_helper_test.rb +0 -23
- data/test/bumpspark_test.rb +0 -32
- data/test/test_helper.rb +0 -10
data/.document
CHANGED
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p362
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3-p362
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2013 Bruce Williams and collaborators
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
Bumpspark
|
2
|
+
=========
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/bruce/bumpspark.png)](https://travis-ci.org/bruce/bumpspark)
|
5
|
+
|
6
|
+
Generate "bumpspark"-style sparklines from Ruby & Rails. Bumpsparks
|
7
|
+
are sparklines which show discrete data points and highlight extremes.
|
8
|
+
|
9
|
+
Note: This library is based on _why's `bumpspark' code,
|
10
|
+
originally discussed and collaborated on at
|
11
|
+
[RedHanded](http://redhanded.hobix.com/inspect/sparklinesForMinimalists.html).
|
12
|
+
|
13
|
+
It has been refactored and built out as a gem suitable for inclusion
|
14
|
+
in Rails projects (and standalone Ruby code).
|
15
|
+
|
16
|
+
Credits
|
17
|
+
-------
|
18
|
+
|
19
|
+
Thanks to the original collaborators:
|
20
|
+
|
21
|
+
* _why (concept, BMP implementation)
|
22
|
+
* jzp (png)
|
23
|
+
* MenTaLguY (transparency)
|
24
|
+
|
25
|
+
Installation
|
26
|
+
------------
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install bumpspark
|
30
|
+
```
|
31
|
+
|
32
|
+
Usage
|
33
|
+
-----
|
34
|
+
|
35
|
+
### From Rails
|
36
|
+
|
37
|
+
Add `bumpspark` as a dependency:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem 'bumpspark'
|
41
|
+
```
|
42
|
+
|
43
|
+
Use `bumpspark_tag` from your views or helpers, passing it the data
|
44
|
+
points you'd like graphed.
|
45
|
+
|
46
|
+
```erb
|
47
|
+
<%= bumpspark_tag [12, 34, 12, 42, 12, 23] %>
|
48
|
+
```
|
49
|
+
|
50
|
+
### From Ruby
|
51
|
+
|
52
|
+
Simply create a `Bumpspark::Graph` instance and call `to_png` on it.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'bumpspark'
|
56
|
+
|
57
|
+
graph = Bumpspark::Graph.new [12, 34, 12, 42, 12, 23]
|
58
|
+
|
59
|
+
File.open('bumpspark.png', 'wb') do |file|
|
60
|
+
file.write graph.to_png
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
### From the commandline
|
65
|
+
|
66
|
+
Generate a bumpspark directly from the commandline.
|
67
|
+
|
68
|
+
```
|
69
|
+
% cat temperature.txt
|
70
|
+
23 25 33 22 25 33 22
|
71
|
+
|
72
|
+
% cat temperature.txt | bumpspark > temperature.png
|
73
|
+
```
|
74
|
+
|
75
|
+
### Note on Patches/Pull Requests
|
76
|
+
|
77
|
+
Please check the TODO file for information on things that need doing.
|
78
|
+
|
79
|
+
* Fork the project.
|
80
|
+
* Make your feature addition or bug fix.
|
81
|
+
* Add tests for it. This is important so I don't break it in a
|
82
|
+
future version unintentionally.
|
83
|
+
* Commit, do not mess with rakefile, version, or history.
|
84
|
+
(if you want to have your own version, that is fine but
|
85
|
+
bump version in a commit by itself I can ignore when I pull)
|
86
|
+
* Send me a pull request. Bonus points for topic branches.
|
87
|
+
|
88
|
+
### Copyright
|
89
|
+
|
90
|
+
Copyright (c) 2009-2012 Bruce Williams, et al. See LICENSE for
|
91
|
+
details.
|
data/Rakefile
CHANGED
@@ -1,62 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
1
|
+
require "bundler/gem_tasks"
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
gem.name = "bumpspark"
|
8
|
-
gem.summary = %Q{Generates "bumpspark"-style sparklines for Ruby & Rails}
|
9
|
-
gem.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.}
|
10
|
-
gem.email = "bruce@codefluency.com"
|
11
|
-
gem.homepage = "http://github.com/bruce/bumpspark"
|
12
|
-
gem.authors = ["Bruce Williams"]
|
13
|
-
gem.rubyforge_project = 'codefluency'
|
14
|
-
# TESTING ONLY
|
15
|
-
gem.add_development_dependency "thoughtbot-shoulda"
|
16
|
-
gem.add_development_dependency "activesupport"
|
17
|
-
gem.add_development_dependency "actionpack"
|
18
|
-
gem.add_development_dependency "rmagick"
|
19
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
-
end
|
21
|
-
Jeweler::GemcutterTasks.new
|
22
|
-
rescue LoadError
|
23
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
RSpec::Core::RakeTask.new do |t|
|
5
|
+
t.pattern = 'spec/{helpers,lib}/**/*_spec.rb'
|
24
6
|
end
|
25
7
|
|
26
|
-
|
27
|
-
Rake::TestTask.new(:test) do |test|
|
28
|
-
test.libs << 'lib' << 'test'
|
29
|
-
test.pattern = 'test/**/*_test.rb'
|
30
|
-
test.verbose = true
|
31
|
-
end
|
32
|
-
|
33
|
-
begin
|
34
|
-
require 'rcov/rcovtask'
|
35
|
-
Rcov::RcovTask.new do |test|
|
36
|
-
test.libs << 'test'
|
37
|
-
test.pattern = 'test/**/*_test.rb'
|
38
|
-
test.verbose = true
|
39
|
-
end
|
40
|
-
rescue LoadError
|
41
|
-
task :rcov do
|
42
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
task :test => :check_dependencies
|
47
|
-
|
48
|
-
task :default => :test
|
49
|
-
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
if File.exist?('VERSION')
|
53
|
-
version = File.read('VERSION')
|
54
|
-
else
|
55
|
-
version = ""
|
56
|
-
end
|
57
|
-
|
58
|
-
rdoc.rdoc_dir = 'rdoc'
|
59
|
-
rdoc.title = "bumpspark #{version}"
|
60
|
-
rdoc.rdoc_files.include('README*')
|
61
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
-
end
|
8
|
+
task :default => :spec
|
data/bumpspark.gemspec
CHANGED
@@ -1,73 +1,26 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bumpspark/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "bumpspark"
|
8
|
+
gem.version = Bumpspark::VERSION
|
9
|
+
gem.authors = ["Bruce Williams"]
|
10
|
+
gem.email = ["brwcodes@gmail.com"]
|
11
|
+
gem.description = %q{Generates transparent PNG and Data URI bumpspark-style sparklines. Use from Ruby directly or as a Rails helper.}
|
12
|
+
gem.summary = %q{Generates bumpspark-style sparklines for Ruby & Rails}
|
13
|
+
gem.homepage = "http://github.com/bruce/bumpspark"
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.markdown"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.markdown",
|
24
|
-
"Rakefile",
|
25
|
-
"TODO.markdown",
|
26
|
-
"VERSION",
|
27
|
-
"bumpspark.gemspec",
|
28
|
-
"lib/bumpspark.rb",
|
29
|
-
"lib/bumpspark/formats/png.rb",
|
30
|
-
"lib/bumpspark/formats/string.rb",
|
31
|
-
"lib/bumpspark/graph.rb",
|
32
|
-
"lib/bumpspark/scale.rb",
|
33
|
-
"lib/bumpspark_helper.rb",
|
34
|
-
"rails/init.rb",
|
35
|
-
"test/bumpspark_helper_test.rb",
|
36
|
-
"test/bumpspark_test.rb",
|
37
|
-
"test/test_helper.rb"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/bruce/bumpspark}
|
40
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
-
s.require_paths = ["lib"]
|
42
|
-
s.rubyforge_project = %q{codefluency}
|
43
|
-
s.rubygems_version = %q{1.3.5}
|
44
|
-
s.summary = %q{Generates "bumpspark"-style sparklines for Ruby & Rails}
|
45
|
-
s.test_files = [
|
46
|
-
"test/bumpspark_helper_test.rb",
|
47
|
-
"test/bumpspark_test.rb",
|
48
|
-
"test/test_helper.rb"
|
49
|
-
]
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.bindir = 'exe'
|
17
|
+
gem.executables = gem.files.grep(%r{^exe/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
50
20
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
-
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
58
|
-
s.add_development_dependency(%q<actionpack>, [">= 0"])
|
59
|
-
s.add_development_dependency(%q<rmagick>, [">= 0"])
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
62
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
63
|
-
s.add_dependency(%q<actionpack>, [">= 0"])
|
64
|
-
s.add_dependency(%q<rmagick>, [">= 0"])
|
65
|
-
end
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
68
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
69
|
-
s.add_dependency(%q<actionpack>, [">= 0"])
|
70
|
-
s.add_dependency(%q<rmagick>, [">= 0"])
|
71
|
-
end
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'rspec-rails'
|
23
|
+
gem.add_development_dependency 'chunky_png'
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
gem.add_development_dependency 'rails', '3.2.11'
|
72
26
|
end
|
73
|
-
|
data/exe/bumpspark
ADDED
data/lib/bumpspark.rb
CHANGED
@@ -1,8 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require File.dirname(__FILE__) << "/bumpspark/scale"
|
4
|
-
require File.dirname(__FILE__) << "/bumpspark/graph"
|
5
|
-
|
6
|
-
module Bumpspark
|
7
|
-
VERSION = File.read(File.dirname(__FILE__) << "/../VERSION").strip
|
8
|
-
end
|
1
|
+
require "bumpspark/graph"
|
2
|
+
require "bumpspark/railtie" if defined?(Rails)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "cgi"
|
3
|
+
|
4
|
+
module Bumpspark
|
5
|
+
|
6
|
+
module Formats
|
7
|
+
|
8
|
+
module DataURI
|
9
|
+
|
10
|
+
# Generate a Data URI
|
11
|
+
# @see http://en.wikipedia.org/wiki/Data_URI_scheme
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
#
|
15
|
+
def to_data_uri
|
16
|
+
data = Base64.encode64(to_png).delete("\n")
|
17
|
+
"data:image/png;base64,#{CGI.escape(data)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/bumpspark/graph.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require "bumpspark/scale"
|
2
|
+
require "bumpspark/formats/png"
|
3
|
+
require "bumpspark/formats/string"
|
4
|
+
require "bumpspark/formats/data_uri"
|
5
|
+
|
1
6
|
module Bumpspark
|
2
7
|
|
3
8
|
class Graph
|
@@ -5,6 +10,7 @@ module Bumpspark
|
|
5
10
|
include Scale
|
6
11
|
include Formats::PNG
|
7
12
|
include Formats::String
|
13
|
+
include Formats::DataURI
|
8
14
|
|
9
15
|
attr_reader :numbers, :scale
|
10
16
|
def initialize(numbers, scale = 1)
|
@@ -14,4 +20,4 @@ module Bumpspark
|
|
14
20
|
|
15
21
|
end
|
16
22
|
|
17
|
-
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Bumpspark
|
5
|
+
module Helper
|
6
|
+
|
7
|
+
# Generate a bumpspark-style sparkline image tag
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
def bumpspark_tag(numbers, html_opts={})
|
12
|
+
graph = Bumpspark::Graph.new(numbers)
|
13
|
+
tag(:img, html_opts.merge(src: graph.to_data_uri))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|