sparklines 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Manifest.txt +40 -0
- data/Rakefile +1 -1
- data/lib/sparklines.rb +43 -4
- data/test/expected/area.png +0 -0
- data/test/expected/area_high.png +0 -0
- data/test/expected/area_min_max.png +0 -0
- data/test/expected/bar.png +0 -0
- data/test/expected/bar_extreme_values.png +0 -0
- data/test/expected/bar_string.png.png +0 -0
- data/test/expected/bar_tall.png +0 -0
- data/test/expected/bar_wide.png +0 -0
- data/test/expected/bullet_basic.png +0 -0
- data/test/expected/bullet_full_featured.png +0 -0
- data/test/expected/bullet_tall.png +0 -0
- data/test/expected/bullet_wide.png +0 -0
- data/test/expected/discrete.png +0 -0
- data/test/expected/discrete_wide.png +0 -0
- data/test/expected/error.png +0 -0
- data/test/expected/labeled_area.png +0 -0
- data/test/expected/labeled_bar.png +0 -0
- data/test/expected/labeled_discrete.png +0 -0
- data/test/expected/labeled_pie.png +0 -0
- data/test/expected/labeled_smooth.png +0 -0
- data/test/expected/labeled_whisker_decimals.png +0 -0
- data/test/expected/pie.png +0 -0
- data/test/expected/pie0.png +0 -0
- data/test/expected/pie1.png +0 -0
- data/test/expected/pie100.png +0 -0
- data/test/expected/pie45.png +0 -0
- data/test/expected/pie95.png +0 -0
- data/test/expected/pie99.png +0 -0
- data/test/expected/pie_flat.png +0 -0
- data/test/expected/pie_large.png +0 -0
- data/test/expected/smooth.png +0 -0
- data/test/expected/smooth_colored.png +0 -0
- data/test/expected/smooth_similar_nonzero_values.png +0 -0
- data/test/expected/smooth_underneath_color.png +0 -0
- data/test/expected/standard_deviation.png +0 -0
- data/test/expected/standard_deviation_short.png +0 -0
- data/test/expected/standard_deviation_tall.png +0 -0
- data/test/expected/whisker.png +0 -0
- data/test/expected/whisker_junk.png +0 -0
- data/test/expected/whisker_non_exceptional.png +0 -0
- data/test/test_all.rb +73 -2
- metadata +90 -43
data/CHANGELOG
CHANGED
data/Manifest.txt
CHANGED
@@ -18,4 +18,44 @@ samples/pie95.png
|
|
18
18
|
samples/pie99.png
|
19
19
|
samples/smooth-colored.png
|
20
20
|
samples/smooth.png
|
21
|
+
test/expected/area.png
|
22
|
+
test/expected/area_high.png
|
23
|
+
test/expected/area_min_max.png
|
24
|
+
test/expected/bar.png
|
25
|
+
test/expected/bar_extreme_values.png
|
26
|
+
test/expected/bar_string.png.png
|
27
|
+
test/expected/bar_tall.png
|
28
|
+
test/expected/bar_wide.png
|
29
|
+
test/expected/bullet_basic.png
|
30
|
+
test/expected/bullet_full_featured.png
|
31
|
+
test/expected/bullet_tall.png
|
32
|
+
test/expected/bullet_wide.png
|
33
|
+
test/expected/discrete.png
|
34
|
+
test/expected/discrete_wide.png
|
35
|
+
test/expected/error.png
|
36
|
+
test/expected/labeled_area.png
|
37
|
+
test/expected/labeled_bar.png
|
38
|
+
test/expected/labeled_discrete.png
|
39
|
+
test/expected/labeled_pie.png
|
40
|
+
test/expected/labeled_smooth.png
|
41
|
+
test/expected/labeled_whisker_decimals.png
|
42
|
+
test/expected/pie.png
|
43
|
+
test/expected/pie0.png
|
44
|
+
test/expected/pie1.png
|
45
|
+
test/expected/pie100.png
|
46
|
+
test/expected/pie45.png
|
47
|
+
test/expected/pie95.png
|
48
|
+
test/expected/pie99.png
|
49
|
+
test/expected/pie_flat.png
|
50
|
+
test/expected/pie_large.png
|
51
|
+
test/expected/smooth.png
|
52
|
+
test/expected/smooth_colored.png
|
53
|
+
test/expected/smooth_similar_nonzero_values.png
|
54
|
+
test/expected/smooth_underneath_color.png
|
55
|
+
test/expected/standard_deviation.png
|
56
|
+
test/expected/standard_deviation_short.png
|
57
|
+
test/expected/standard_deviation_tall.png
|
58
|
+
test/expected/whisker.png
|
59
|
+
test/expected/whisker_junk.png
|
60
|
+
test/expected/whisker_non_exceptional.png
|
21
61
|
test/test_all.rb
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ Hoe.new('Sparklines', Sparklines::VERSION) do |p|
|
|
11
11
|
p.email = 'boss@topfunky.com'
|
12
12
|
p.summary = "Tiny graphs."
|
13
13
|
p.url = "http://nubyonrails.com/pages/sparklines"
|
14
|
-
p.clean_globs = ['test/
|
14
|
+
p.clean_globs = ['test/actual'] # Remove this directory on "rake clean"
|
15
15
|
p.remote_rdoc_dir = '' # Release to root
|
16
16
|
p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
|
17
17
|
# * extra_deps - An array of rubygem dependencies.
|
data/lib/sparklines.rb
CHANGED
@@ -74,7 +74,7 @@ Licensed under the MIT license.
|
|
74
74
|
=end
|
75
75
|
class Sparklines
|
76
76
|
|
77
|
-
VERSION = '0.4.
|
77
|
+
VERSION = '0.4.8'
|
78
78
|
|
79
79
|
@@label_margin = 5.0
|
80
80
|
@@pointsize = 10.0
|
@@ -121,7 +121,7 @@ class Sparklines
|
|
121
121
|
|
122
122
|
# Call the appropriate method for actual plotting.
|
123
123
|
sparkline = self.new(data, options_sym)
|
124
|
-
if %w(area bar pie smooth discrete whisker).include? options_sym[:type]
|
124
|
+
if %w(area bar bullet pie smooth discrete whisker).include? options_sym[:type]
|
125
125
|
sparkline.send options_sym[:type]
|
126
126
|
else
|
127
127
|
sparkline.plot_error options_sym
|
@@ -498,6 +498,43 @@ class Sparklines
|
|
498
498
|
@canvas.to_blob
|
499
499
|
end
|
500
500
|
|
501
|
+
def bullet
|
502
|
+
height = @options[:height].to_f
|
503
|
+
@graph_width = @options.has_key?(:width) ? @options[:width].to_f : 100.0
|
504
|
+
background_color = '#eeeeee' # @options[:background_color]
|
505
|
+
@thickness = height/3.0
|
506
|
+
|
507
|
+
create_canvas(@graph_width, height, background_color)
|
508
|
+
|
509
|
+
@value = @norm_data
|
510
|
+
@good_value = @options[:good].to_f
|
511
|
+
|
512
|
+
@graph_height = @options[:height]
|
513
|
+
|
514
|
+
qualitative_range_colors = ['#bbbbbb', '#999999']
|
515
|
+
[:satisfactory, :bad].each_with_index do |indicator, index|
|
516
|
+
next unless @options.has_key?(indicator)
|
517
|
+
@draw = @draw.fill(qualitative_range_colors[index])
|
518
|
+
indicator_width_x = @graph_width * (@options[indicator].to_f / @good_value)
|
519
|
+
@draw = @draw.rectangle(0, 0, indicator_width_x.to_i, @graph_height)
|
520
|
+
end
|
521
|
+
|
522
|
+
if @options.has_key?(:target)
|
523
|
+
@draw = @draw.fill 'black'
|
524
|
+
target_x = @graph_width * (@options[:target].to_f / @good_value)
|
525
|
+
half_thickness = (@thickness / 2.0).to_i
|
526
|
+
bar_width = 1.0
|
527
|
+
@draw = @draw.rectangle(target_x.to_i, half_thickness, (target_x + bar_width).to_i, @thickness * 2 + half_thickness)
|
528
|
+
end
|
529
|
+
|
530
|
+
# Value
|
531
|
+
@draw = @draw.fill 'black'
|
532
|
+
@draw = @draw.rectangle(0, @thickness.to_i, @graph_width * (@data.first.to_f / @good_value), (@thickness * 2.0).to_i)
|
533
|
+
|
534
|
+
@draw.draw(@canvas)
|
535
|
+
@canvas.to_blob
|
536
|
+
end
|
537
|
+
|
501
538
|
##
|
502
539
|
# Draw the error Sparkline.
|
503
540
|
|
@@ -517,7 +554,10 @@ class Sparklines
|
|
517
554
|
def normalize_data
|
518
555
|
@minimum_value = @data.min
|
519
556
|
@maximum_value = @data.max
|
520
|
-
|
557
|
+
case @options[:type].to_s
|
558
|
+
when 'pie'
|
559
|
+
@norm_data = @data
|
560
|
+
when 'bullet'
|
521
561
|
@norm_data = @data
|
522
562
|
else
|
523
563
|
@norm_data = @data.map do |value|
|
@@ -661,5 +701,4 @@ class Sparklines
|
|
661
701
|
Math.sqrt(variance(population))
|
662
702
|
end
|
663
703
|
|
664
|
-
|
665
704
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test_all.rb
CHANGED
@@ -3,11 +3,13 @@
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'lib/sparklines'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'tidy_table'
|
7
|
+
require 'dust'
|
6
8
|
|
7
9
|
class SparklinesTest < Test::Unit::TestCase
|
8
10
|
|
9
11
|
def setup
|
10
|
-
@output_dir = "test/
|
12
|
+
@output_dir = "test/actual"
|
11
13
|
FileUtils.mkdir_p(@output_dir)
|
12
14
|
|
13
15
|
@data = %w( 1 5 15 20 30 50 57 58 55 48
|
@@ -16,6 +18,49 @@ class SparklinesTest < Test::Unit::TestCase
|
|
16
18
|
115 120 130 140 150 160 170 100 100 10).map {|i| i.to_f}
|
17
19
|
end
|
18
20
|
|
21
|
+
test "basic bullet" do
|
22
|
+
Sparklines.plot_to_file("#{@output_dir}/bullet_basic.png", 85, {
|
23
|
+
:type => "bullet",
|
24
|
+
:target => 80,
|
25
|
+
:good => 100,
|
26
|
+
:height => 15
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
test "full-featured bullet" do
|
31
|
+
Sparklines.plot_to_file("#{@output_dir}/bullet_full_featured.png", 85, {
|
32
|
+
:type => "bullet",
|
33
|
+
:target => 90,
|
34
|
+
:bad => 60,
|
35
|
+
:satisfactory => 80,
|
36
|
+
:good => 100,
|
37
|
+
:height => 15
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
test "tall bullet" do
|
42
|
+
Sparklines.plot_to_file("#{@output_dir}/bullet_tall.png", 85, {
|
43
|
+
:type => "bullet",
|
44
|
+
:target => 90,
|
45
|
+
:bad => 60,
|
46
|
+
:satisfactory => 80,
|
47
|
+
:good => 100,
|
48
|
+
:height => 30
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
test "wide bullet" do
|
53
|
+
Sparklines.plot_to_file("#{@output_dir}/bullet_wide.png", 85, {
|
54
|
+
:type => "bullet",
|
55
|
+
:target => 90,
|
56
|
+
:bad => 60,
|
57
|
+
:satisfactory => 80,
|
58
|
+
:good => 100,
|
59
|
+
:height => 15,
|
60
|
+
:width => 200
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
19
64
|
def test_each_graph
|
20
65
|
%w{pie area discrete smooth bar}.each do |type|
|
21
66
|
quick_graph("#{type}", :type => type)
|
@@ -150,7 +195,7 @@ class SparklinesTest < Test::Unit::TestCase
|
|
150
195
|
end
|
151
196
|
|
152
197
|
def test_close_values
|
153
|
-
Sparklines.plot_to_file("#{@output_dir}/
|
198
|
+
Sparklines.plot_to_file("#{@output_dir}/smooth_similar_nonzero_values.png", [100, 90, 95, 99, 80, 90], {
|
154
199
|
:type => 'smooth',
|
155
200
|
:line_color => "#6699cc",
|
156
201
|
:underneath_color => "#ebf3f6"
|
@@ -198,3 +243,29 @@ class SparklinesTest < Test::Unit::TestCase
|
|
198
243
|
end
|
199
244
|
|
200
245
|
end
|
246
|
+
|
247
|
+
# HACK Make reference HTML file for viewing output
|
248
|
+
END {
|
249
|
+
def image_tag(image_path)
|
250
|
+
%(<img src="#{image_path}" />)
|
251
|
+
end
|
252
|
+
|
253
|
+
reference_files = Dir['test/expected/*']
|
254
|
+
output = TidyTable.new(reference_files).to_html(%w(Expected Actual)) do |record|
|
255
|
+
[image_tag("../../" + record), image_tag("../../" + record.gsub('expected', 'actual'))]
|
256
|
+
end
|
257
|
+
FileUtils.mkdir_p("test/actual")
|
258
|
+
File.open("test/actual/result.html", "w") do |f|
|
259
|
+
f.write <<-EOL
|
260
|
+
<style>
|
261
|
+
.first_column {
|
262
|
+
text-align: right;
|
263
|
+
}
|
264
|
+
.last_column {
|
265
|
+
text-align: left;
|
266
|
+
}
|
267
|
+
</style>
|
268
|
+
EOL
|
269
|
+
f.write output
|
270
|
+
end
|
271
|
+
}
|
metadata
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: sparklines
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
|
8
|
-
summary: Tiny graphs.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: boss@topfunky.com
|
12
|
-
homepage: http://nubyonrails.com/pages/sparklines
|
13
|
-
rubyforge_project: sparklines
|
14
|
-
description: Tiny graphs.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
25
|
-
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
4
|
+
version: 0.4.8
|
5
|
+
platform: ""
|
29
6
|
authors:
|
30
7
|
- Geoffrey Grosenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: Tiny graphs.
|
25
|
+
email: boss@topfunky.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- Manifest.txt
|
31
32
|
files:
|
32
33
|
- CHANGELOG
|
33
34
|
- MIT-LICENSE
|
@@ -49,27 +50,73 @@ files:
|
|
49
50
|
- samples/pie99.png
|
50
51
|
- samples/smooth-colored.png
|
51
52
|
- samples/smooth.png
|
53
|
+
- test/expected/area.png
|
54
|
+
- test/expected/area_high.png
|
55
|
+
- test/expected/area_min_max.png
|
56
|
+
- test/expected/bar.png
|
57
|
+
- test/expected/bar_extreme_values.png
|
58
|
+
- test/expected/bar_string.png.png
|
59
|
+
- test/expected/bar_tall.png
|
60
|
+
- test/expected/bar_wide.png
|
61
|
+
- test/expected/bullet_basic.png
|
62
|
+
- test/expected/bullet_full_featured.png
|
63
|
+
- test/expected/bullet_tall.png
|
64
|
+
- test/expected/bullet_wide.png
|
65
|
+
- test/expected/discrete.png
|
66
|
+
- test/expected/discrete_wide.png
|
67
|
+
- test/expected/error.png
|
68
|
+
- test/expected/labeled_area.png
|
69
|
+
- test/expected/labeled_bar.png
|
70
|
+
- test/expected/labeled_discrete.png
|
71
|
+
- test/expected/labeled_pie.png
|
72
|
+
- test/expected/labeled_smooth.png
|
73
|
+
- test/expected/labeled_whisker_decimals.png
|
74
|
+
- test/expected/pie.png
|
75
|
+
- test/expected/pie0.png
|
76
|
+
- test/expected/pie1.png
|
77
|
+
- test/expected/pie100.png
|
78
|
+
- test/expected/pie45.png
|
79
|
+
- test/expected/pie95.png
|
80
|
+
- test/expected/pie99.png
|
81
|
+
- test/expected/pie_flat.png
|
82
|
+
- test/expected/pie_large.png
|
83
|
+
- test/expected/smooth.png
|
84
|
+
- test/expected/smooth_colored.png
|
85
|
+
- test/expected/smooth_similar_nonzero_values.png
|
86
|
+
- test/expected/smooth_underneath_color.png
|
87
|
+
- test/expected/standard_deviation.png
|
88
|
+
- test/expected/standard_deviation_short.png
|
89
|
+
- test/expected/standard_deviation_tall.png
|
90
|
+
- test/expected/whisker.png
|
91
|
+
- test/expected/whisker_junk.png
|
92
|
+
- test/expected/whisker_non_exceptional.png
|
52
93
|
- test/test_all.rb
|
53
|
-
|
54
|
-
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://nubyonrails.com/pages/sparklines
|
96
|
+
post_install_message:
|
55
97
|
rdoc_options:
|
56
98
|
- --main
|
57
99
|
- README.txt
|
58
|
-
|
59
|
-
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
64
114
|
requirements: []
|
65
115
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 1.3.0
|
75
|
-
version:
|
116
|
+
rubyforge_project: sparklines
|
117
|
+
rubygems_version: 0.9.5
|
118
|
+
signing_key:
|
119
|
+
specification_version: 2
|
120
|
+
summary: Tiny graphs.
|
121
|
+
test_files:
|
122
|
+
- test/test_all.rb
|