reportable 1.0.3 → 1.1.0
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/HISTORY.md +10 -0
- data/README.md +49 -10
- data/Rakefile +0 -1
- data/generators/reportable_jquery_flot_assets/reportable_jquery_flot_assets_generator.rb +37 -0
- data/generators/reportable_jquery_flot_assets/templates/NOTES +7 -0
- data/generators/reportable_jquery_flot_assets/templates/excanvas.min.js +1 -0
- data/generators/reportable_jquery_flot_assets/templates/jquery.flot.min.js +1 -0
- data/generators/reportable_migration/reportable_migration_generator.rb +35 -4
- data/generators/reportable_migration/templates/{migration.erb → migration.rb} +7 -7
- data/generators/reportable_raphael_assets/reportable_raphael_assets_generator.rb +42 -0
- data/generators/reportable_raphael_assets/templates/NOTES +6 -0
- data/generators/reportable_raphael_assets/templates/g.line.min.js +7 -0
- data/generators/reportable_raphael_assets/templates/g.raphael.min.js +7 -0
- data/generators/reportable_raphael_assets/templates/raphael.min.js +113 -0
- data/lib/saulabs/reportable.rb +7 -0
- data/lib/saulabs/reportable/config.rb +55 -0
- data/lib/saulabs/reportable/cumulated_report.rb +2 -0
- data/lib/saulabs/reportable/grouping.rb +2 -2
- data/lib/saulabs/reportable/railtie.rb +26 -0
- data/lib/saulabs/reportable/report.rb +3 -0
- data/lib/saulabs/reportable/report_cache.rb +13 -1
- data/lib/saulabs/reportable/report_tag_helper.rb +162 -0
- data/lib/saulabs/reportable/reporting_period.rb +2 -3
- data/lib/saulabs/reportable/result_set.rb +40 -0
- data/rails/init.rb +3 -1
- data/spec/boot.rb +4 -7
- data/spec/classes/grouping_spec.rb +1 -1
- data/spec/classes/report_cache_spec.rb +85 -0
- data/spec/db/schema.rb +6 -6
- data/spec/other/report_method_spec.rb +27 -3
- data/spec/other/report_tag_helper_spec.rb +118 -0
- data/spec/spec_helper.rb +3 -7
- metadata +54 -18
- data/lib/saulabs/reportable/sparkline_tag_helper.rb +0 -62
- data/spec/other/sparkline_tag_helper_spec.rb +0 -64
data/spec/db/schema.rb
CHANGED
|
@@ -9,12 +9,12 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
create_table :reportable_cache, :force => true do |t|
|
|
12
|
-
t.string :model_name, :null => false
|
|
13
|
-
t.string :report_name, :null => false
|
|
14
|
-
t.string :grouping, :null => false
|
|
15
|
-
t.string :aggregation, :null => false
|
|
16
|
-
t.string :conditions, :null => false
|
|
17
|
-
t.float :value, :null => false,
|
|
12
|
+
t.string :model_name, :null => false, :limit => 100
|
|
13
|
+
t.string :report_name, :null => false, :limit => 100
|
|
14
|
+
t.string :grouping, :null => false, :limit => 10
|
|
15
|
+
t.string :aggregation, :null => false, :limit => 10
|
|
16
|
+
t.string :conditions, :null => false, :limit => 100
|
|
17
|
+
t.float :value, :null => false, :default => 0
|
|
18
18
|
t.datetime :reporting_period, :null => false
|
|
19
19
|
|
|
20
20
|
t.timestamps
|
|
@@ -2,14 +2,33 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
|
2
2
|
|
|
3
3
|
describe Saulabs::Reportable do
|
|
4
4
|
|
|
5
|
+
before(:all) do
|
|
6
|
+
User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :profile_visits => 1)
|
|
7
|
+
User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :profile_visits => 2)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'should return a Saulabs::Reportable::ResultSet' do
|
|
11
|
+
User.registrations_report.should be_instance_of(Saulabs::Reportable::ResultSet)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should return a result set that stores the name of the model the report was invoked on' do
|
|
15
|
+
User.registrations_report.model_name.should == User.name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should return a result set that stores the name of the report that was invoked' do
|
|
19
|
+
User.registrations_report.report_name.should == 'registrations'
|
|
20
|
+
end
|
|
21
|
+
|
|
5
22
|
describe 'for inherited models' do
|
|
6
23
|
|
|
7
24
|
before(:all) do
|
|
8
|
-
User.create!(:login => 'test 1', :created_at => Time.now - 1.days, :profile_visits => 1)
|
|
9
|
-
User.create!(:login => 'test 2', :created_at => Time.now - 2.days, :profile_visits => 2)
|
|
10
25
|
SpecialUser.create!(:login => 'test 3', :created_at => Time.now - 2.days, :profile_visits => 3)
|
|
11
26
|
end
|
|
12
27
|
|
|
28
|
+
it 'should return a result set that stores the model the report was invoked on' do
|
|
29
|
+
SpecialUser.registrations_report.model_name.should == SpecialUser.name
|
|
30
|
+
end
|
|
31
|
+
|
|
13
32
|
it 'should include all data when invoked on the base model class' do
|
|
14
33
|
result = User.registrations_report.to_a
|
|
15
34
|
|
|
@@ -25,7 +44,6 @@ describe Saulabs::Reportable do
|
|
|
25
44
|
end
|
|
26
45
|
|
|
27
46
|
after(:all) do
|
|
28
|
-
User.destroy_all
|
|
29
47
|
SpecialUser.destroy_all
|
|
30
48
|
end
|
|
31
49
|
|
|
@@ -35,10 +53,16 @@ describe Saulabs::Reportable do
|
|
|
35
53
|
Saulabs::Reportable::ReportCache.destroy_all
|
|
36
54
|
end
|
|
37
55
|
|
|
56
|
+
after(:all) do
|
|
57
|
+
User.destroy_all
|
|
58
|
+
end
|
|
59
|
+
|
|
38
60
|
end
|
|
39
61
|
|
|
40
62
|
class User < ActiveRecord::Base
|
|
63
|
+
|
|
41
64
|
reportable :registrations, :limit => 10
|
|
65
|
+
|
|
42
66
|
end
|
|
43
67
|
|
|
44
68
|
class SpecialUser < User; end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
|
+
|
|
3
|
+
describe Saulabs::Reportable::ReportTagHelper do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@helper = TestHelper.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '#raphael_report_tag' do
|
|
10
|
+
|
|
11
|
+
data_set = Saulabs::Reportable::ResultSet.new([[DateTime.now, 1.0], [DateTime.now - 1.day, 3.0]], "User", "registrations")
|
|
12
|
+
|
|
13
|
+
it 'should return a string' do
|
|
14
|
+
@helper.raphael_report_tag(data_set).class.should == String
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should contain a div tag' do
|
|
18
|
+
@helper.raphael_report_tag(data_set).should =~ /^<div id=".*">.*<\/div>/
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should contain a script tag' do
|
|
22
|
+
@helper.raphael_report_tag(data_set).should =~ /<script type="text\/javascript" charset="utf-8">.*<\/script>/m
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should assign a default dom id to the the div tag if none is specified' do
|
|
26
|
+
@helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}".*<\/div>/
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'should assign correct default dom ids to the the div tag if none is specified and there are more than one report tags on the page' do
|
|
30
|
+
@helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}".*<\/div>/
|
|
31
|
+
@helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}1".*<\/div>/
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#flot_report_tag' do
|
|
37
|
+
|
|
38
|
+
data_set = Saulabs::Reportable::ResultSet.new([[DateTime.now, 1.0], [DateTime.now - 1.day, 3.0]], "User", "registrations")
|
|
39
|
+
|
|
40
|
+
it 'should return a string' do
|
|
41
|
+
@helper.flot_report_tag(data_set).class.should == String
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'should contain a div tag' do
|
|
45
|
+
@helper.flot_report_tag(data_set).should =~ /^<div id=".*">.*<\/div>/
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'should contain a script tag' do
|
|
49
|
+
@helper.flot_report_tag(data_set).should =~ /<script type="text\/javascript" charset="utf-8">.*<\/script>/m
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'should assign a default dom id to the the div tag if none is specified' do
|
|
53
|
+
@helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}".*<\/div>/
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should assign correct default dom ids to the the div tag if none is specified and there are more than one report tags on the page' do
|
|
57
|
+
@helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}".*<\/div>/
|
|
58
|
+
@helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_name.downcase}_#{data_set.report_name}1".*<\/div>/
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe '#google_report_tag' do
|
|
64
|
+
|
|
65
|
+
it 'should render an image with the correct source' do
|
|
66
|
+
@helper.should_receive(:image_tag).once.with(
|
|
67
|
+
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
68
|
+
{ :title => nil, :alt => nil }
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
@helper.google_report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should add parameters for labels to the source of the image if rendering of lables is specified' do
|
|
75
|
+
@helper.should_receive(:image_tag).once.with(
|
|
76
|
+
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0&chxt=x,y,r,t&chxr=0,0,3|1,0,3.0|2,0,3.0|3,0,3',
|
|
77
|
+
{ :title => nil, :alt => nil }
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@helper.google_report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :labels => [:x, :y, :r, :t])
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should set the parameters for custom colors if custom colors are specified' do
|
|
84
|
+
@helper.should_receive(:image_tag).once.with(
|
|
85
|
+
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=000000&chm=B,ffffff,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
86
|
+
{ :title => nil, :alt => nil }
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
@helper.google_report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :line_color => '000000', :fill_color => 'ffffff')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'should set the parameters for a custom title if a title specified' do
|
|
93
|
+
@helper.should_receive(:image_tag).once.with(
|
|
94
|
+
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0&chtt=title',
|
|
95
|
+
{ :title => 'title', :alt => nil }
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@helper.google_report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :title => 'title')
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should use a specified alt text as alt text for the image' do
|
|
102
|
+
@helper.should_receive(:image_tag).once.with(
|
|
103
|
+
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
104
|
+
{ :title => nil, :alt => 'alt' }
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
@helper.google_report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :alt => 'alt')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class TestHelper
|
|
115
|
+
|
|
116
|
+
include Saulabs::Reportable::ReportTagHelper
|
|
117
|
+
|
|
118
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
$:.reject! { |e| e.include? 'TextMate' }
|
|
2
|
-
|
|
3
1
|
ENV['RAILS_ENV'] = 'test'
|
|
4
2
|
|
|
5
3
|
require 'rubygems'
|
|
6
|
-
require '
|
|
7
|
-
|
|
8
|
-
require 'active_support'
|
|
9
|
-
require 'initializer'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
Bundler.setup
|
|
10
6
|
|
|
11
|
-
require File.join(File.dirname(__FILE__), 'boot')
|
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
|
12
8
|
|
|
13
9
|
class User < ActiveRecord::Base; end
|
|
14
10
|
|
metadata
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reportable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 19
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 1
|
|
8
|
+
- 1
|
|
9
|
+
- 0
|
|
10
|
+
version: 1.1.0
|
|
5
11
|
platform: ruby
|
|
6
12
|
authors:
|
|
7
13
|
- Marco Otte-Witte
|
|
@@ -10,30 +16,42 @@ autorequire:
|
|
|
10
16
|
bindir: bin
|
|
11
17
|
cert_chain: []
|
|
12
18
|
|
|
13
|
-
date: 2010-
|
|
19
|
+
date: 2010-05-26 00:00:00 +02:00
|
|
14
20
|
default_executable:
|
|
15
21
|
dependencies:
|
|
16
22
|
- !ruby/object:Gem::Dependency
|
|
17
23
|
name: activerecord
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
prerelease: false
|
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
21
27
|
requirements:
|
|
22
28
|
- - ">="
|
|
23
29
|
- !ruby/object:Gem::Version
|
|
30
|
+
hash: 15
|
|
31
|
+
segments:
|
|
32
|
+
- 2
|
|
33
|
+
- 0
|
|
34
|
+
- 0
|
|
24
35
|
version: 2.0.0
|
|
25
|
-
|
|
36
|
+
type: :runtime
|
|
37
|
+
version_requirements: *id001
|
|
26
38
|
- !ruby/object:Gem::Dependency
|
|
27
39
|
name: activesupport
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
prerelease: false
|
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
31
43
|
requirements:
|
|
32
44
|
- - ">="
|
|
33
45
|
- !ruby/object:Gem::Version
|
|
46
|
+
hash: 15
|
|
47
|
+
segments:
|
|
48
|
+
- 2
|
|
49
|
+
- 0
|
|
50
|
+
- 0
|
|
34
51
|
version: 2.0.0
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
type: :runtime
|
|
53
|
+
version_requirements: *id002
|
|
54
|
+
description: Reportable allows for easy report generation from ActiveRecord models by the addition of the reportable method.
|
|
37
55
|
email: reportable@saulabs.com
|
|
38
56
|
executables: []
|
|
39
57
|
|
|
@@ -46,14 +64,26 @@ files:
|
|
|
46
64
|
- HISTORY.md
|
|
47
65
|
- Rakefile
|
|
48
66
|
- MIT-LICENSE
|
|
67
|
+
- generators/reportable_jquery_flot_assets/reportable_jquery_flot_assets_generator.rb
|
|
68
|
+
- generators/reportable_jquery_flot_assets/templates/NOTES
|
|
69
|
+
- generators/reportable_jquery_flot_assets/templates/excanvas.min.js
|
|
70
|
+
- generators/reportable_jquery_flot_assets/templates/jquery.flot.min.js
|
|
49
71
|
- generators/reportable_migration/reportable_migration_generator.rb
|
|
50
|
-
- generators/reportable_migration/templates/migration.
|
|
72
|
+
- generators/reportable_migration/templates/migration.rb
|
|
73
|
+
- generators/reportable_raphael_assets/reportable_raphael_assets_generator.rb
|
|
74
|
+
- generators/reportable_raphael_assets/templates/NOTES
|
|
75
|
+
- generators/reportable_raphael_assets/templates/g.line.min.js
|
|
76
|
+
- generators/reportable_raphael_assets/templates/g.raphael.min.js
|
|
77
|
+
- generators/reportable_raphael_assets/templates/raphael.min.js
|
|
78
|
+
- lib/saulabs/reportable/config.rb
|
|
51
79
|
- lib/saulabs/reportable/cumulated_report.rb
|
|
52
80
|
- lib/saulabs/reportable/grouping.rb
|
|
81
|
+
- lib/saulabs/reportable/railtie.rb
|
|
53
82
|
- lib/saulabs/reportable/report.rb
|
|
54
83
|
- lib/saulabs/reportable/report_cache.rb
|
|
84
|
+
- lib/saulabs/reportable/report_tag_helper.rb
|
|
55
85
|
- lib/saulabs/reportable/reporting_period.rb
|
|
56
|
-
- lib/saulabs/reportable/
|
|
86
|
+
- lib/saulabs/reportable/result_set.rb
|
|
57
87
|
- lib/saulabs/reportable.rb
|
|
58
88
|
- rails/init.rb
|
|
59
89
|
- spec/boot.rb
|
|
@@ -64,11 +94,11 @@ files:
|
|
|
64
94
|
- spec/classes/reporting_period_spec.rb
|
|
65
95
|
- spec/db/schema.rb
|
|
66
96
|
- spec/other/report_method_spec.rb
|
|
67
|
-
- spec/other/
|
|
97
|
+
- spec/other/report_tag_helper_spec.rb
|
|
68
98
|
- spec/spec_helper.rb
|
|
69
99
|
- spec/db/database.yml
|
|
70
100
|
- spec/spec.opts
|
|
71
|
-
has_rdoc:
|
|
101
|
+
has_rdoc: true
|
|
72
102
|
homepage: http://github.com/saulabs/reportable
|
|
73
103
|
licenses: []
|
|
74
104
|
|
|
@@ -78,21 +108,27 @@ rdoc_options: []
|
|
|
78
108
|
require_paths:
|
|
79
109
|
- lib
|
|
80
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
|
+
none: false
|
|
81
112
|
requirements:
|
|
82
113
|
- - ">="
|
|
83
114
|
- !ruby/object:Gem::Version
|
|
115
|
+
hash: 3
|
|
116
|
+
segments:
|
|
117
|
+
- 0
|
|
84
118
|
version: "0"
|
|
85
|
-
version:
|
|
86
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
|
+
none: false
|
|
87
121
|
requirements:
|
|
88
122
|
- - ">="
|
|
89
123
|
- !ruby/object:Gem::Version
|
|
124
|
+
hash: 3
|
|
125
|
+
segments:
|
|
126
|
+
- 0
|
|
90
127
|
version: "0"
|
|
91
|
-
version:
|
|
92
128
|
requirements: []
|
|
93
129
|
|
|
94
130
|
rubyforge_project:
|
|
95
|
-
rubygems_version: 1.3.
|
|
131
|
+
rubygems_version: 1.3.7
|
|
96
132
|
signing_key:
|
|
97
133
|
specification_version: 2
|
|
98
134
|
summary: Easy report generation for Ruby on Rails
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Saulabs
|
|
2
|
-
|
|
3
|
-
module Reportable
|
|
4
|
-
|
|
5
|
-
module SparklineTagHelper
|
|
6
|
-
|
|
7
|
-
# Renders a sparkline with the given data.
|
|
8
|
-
#
|
|
9
|
-
# @param [Array<Array<DateTime, Float>>] data
|
|
10
|
-
# an array of report data as returned by {Saulabs::Reportable::Report#run}
|
|
11
|
-
# @param [Hash] options
|
|
12
|
-
# options for the sparkline
|
|
13
|
-
#
|
|
14
|
-
# @option options [Fixnum] :width (300)
|
|
15
|
-
# the width of the generated image
|
|
16
|
-
# @option options [Fixnum] :height (34)
|
|
17
|
-
# the height of the generated image
|
|
18
|
-
# @option options [String] :line_color ('0077cc')
|
|
19
|
-
# the line color of the generated image
|
|
20
|
-
# @option options [String] :fill_color ('e6f2fa')
|
|
21
|
-
# the fill color of the generated image
|
|
22
|
-
# @option options [Array<Symbol>] :labels ([])
|
|
23
|
-
# the axes to render lables for (Array of +:x+, +:y+, +:r+, +:t+; this is x axis, y axis, right, top)
|
|
24
|
-
# @option options [String] :alt ('')
|
|
25
|
-
# the alt attribute for the generated image
|
|
26
|
-
# @option options [String] :title ('')
|
|
27
|
-
# the title attribute for the generated image
|
|
28
|
-
#
|
|
29
|
-
# @return [String]
|
|
30
|
-
# an image tag showing a sparkline for the passed +data+
|
|
31
|
-
#
|
|
32
|
-
# @example Rendering a sparkline tag for report data
|
|
33
|
-
#
|
|
34
|
-
# <%= sparkline_tag(User.registrations_report, :width => 200, :height => 100, :color => '000') %>
|
|
35
|
-
#
|
|
36
|
-
def sparkline_tag(data, options = {})
|
|
37
|
-
options.reverse_merge!({ :width => 300, :height => 34, :line_color => '0077cc', :fill_color => 'e6f2fa', :labels => [], :alt => '', :title => '' })
|
|
38
|
-
data = data.collect { |d| d[1] }
|
|
39
|
-
labels = ''
|
|
40
|
-
unless options[:labels].empty?
|
|
41
|
-
chxr = {}
|
|
42
|
-
options[:labels].each_with_index do |l, i|
|
|
43
|
-
chxr[l] = "#{i}," + ([:x, :t].include?(l) ? "0,#{data.length}" : "#{[data.min, 0].min},#{data.max}")
|
|
44
|
-
end
|
|
45
|
-
labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=#{options[:labels].collect{|l| chxr[l]}.join('|')}"
|
|
46
|
-
end
|
|
47
|
-
title = ''
|
|
48
|
-
unless options[:title].empty?
|
|
49
|
-
title = "&chtt=#{options[:title]}"
|
|
50
|
-
end
|
|
51
|
-
image_tag(
|
|
52
|
-
"http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{options[:height]}&chd=t:#{data.join(',')}&chco=#{options[:line_color]}&chm=B,#{options[:fill_color]},0,0,0&chls=1,0,0&chds=#{data.min},#{data.max}#{labels}#{title}",
|
|
53
|
-
:alt => options[:alt],
|
|
54
|
-
:title => options[:title]
|
|
55
|
-
)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
|
-
|
|
3
|
-
describe Saulabs::Reportable::SparklineTagHelper do
|
|
4
|
-
|
|
5
|
-
before do
|
|
6
|
-
@helper = TestHelper.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe '#sparkline_tag' do
|
|
10
|
-
|
|
11
|
-
it 'should render an image with the correct source' do
|
|
12
|
-
@helper.should_receive(:image_tag).once.with(
|
|
13
|
-
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
14
|
-
{ :title => '', :alt => '' }
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
@helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]])
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'should add parameters for labels to the source of the image if rendering of lables is specified' do
|
|
21
|
-
@helper.should_receive(:image_tag).once.with(
|
|
22
|
-
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0&chxt=x,y,r,t&chxr=0,0,3|1,0,3.0|2,0,3.0|3,0,3',
|
|
23
|
-
{ :title => '', :alt => '' }
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
@helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :labels => [:x, :y, :r, :t])
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'should set the parameters for custom colors if custom colors are specified' do
|
|
30
|
-
@helper.should_receive(:image_tag).once.with(
|
|
31
|
-
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=000000&chm=B,ffffff,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
32
|
-
{ :title => '', :alt => '' }
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
@helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :line_color => '000000', :fill_color => 'ffffff')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should set the parameters for a custom title if a title specified' do
|
|
39
|
-
@helper.should_receive(:image_tag).once.with(
|
|
40
|
-
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0&chtt=title',
|
|
41
|
-
{ :title => 'title', :alt => '' }
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
@helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :title => 'title')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'should use a specified alt text as alt text for the image' do
|
|
48
|
-
@helper.should_receive(:image_tag).once.with(
|
|
49
|
-
'http://chart.apis.google.com/chart?cht=ls&chs=300x34&chd=t:1.0,2.0,3.0&chco=0077cc&chm=B,e6f2fa,0,0,0&chls=1,0,0&chds=1.0,3.0',
|
|
50
|
-
{ :title => '', :alt => 'alt' }
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
@helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :alt => 'alt')
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
class TestHelper
|
|
61
|
-
|
|
62
|
-
include Saulabs::Reportable::SparklineTagHelper
|
|
63
|
-
|
|
64
|
-
end
|