sparklines 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/sparklines.rb +5 -3
- data/lib/sparklines_helper.rb +13 -3
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.4.5
|
2
|
+
|
3
|
+
* Several fixes by Rob Biedenharn
|
4
|
+
* lib/sparklines_helper.rb: Include example code for generating "data:" URLs (but leave it commented out due to lack of widespread testing)
|
5
|
+
* lib/sparklines_helper.rb: allow results to be passed in the options hash (i.e., sparkline_tag(nil, :results => [ ... ], ...))
|
6
|
+
* lib/sparklines.rb: Move calculation of whisker endpoints out of loop
|
7
|
+
* lib/sparklines.rb: Fix fencepost bug in whisker that caused plot to be 1 pixel short
|
8
|
+
|
1
9
|
== 0.4.4
|
2
10
|
|
3
11
|
* Fixed stddev rounding bug [Andrew Nutter-Upham]
|
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/output
|
14
|
+
p.clean_globs = ['test/output'] # 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.5'
|
78
78
|
|
79
79
|
@@label_margin = 5.0
|
80
80
|
@@pointsize = 10.0
|
@@ -463,11 +463,13 @@ class Sparklines
|
|
463
463
|
height = @options[:height].to_f
|
464
464
|
background_color = @options[:background_color]
|
465
465
|
|
466
|
-
create_canvas(
|
466
|
+
create_canvas(@data.size * 2 - 1, height, background_color)
|
467
467
|
|
468
468
|
whisker_color = @options[:whisker_color] || 'black'
|
469
469
|
exception_color = @options[:exception_color] || 'red'
|
470
470
|
|
471
|
+
on_row = (@canvas.rows/2.0 - 1).ceil
|
472
|
+
off_row = (@canvas.rows/2.0).floor
|
471
473
|
i = 0
|
472
474
|
@data.each do |r|
|
473
475
|
color = whisker_color
|
@@ -476,7 +478,7 @@ class Sparklines
|
|
476
478
|
color = exception_color
|
477
479
|
end
|
478
480
|
|
479
|
-
y_mid_point = (r >= 1) ?
|
481
|
+
y_mid_point = (r >= 1) ? on_row : off_row
|
480
482
|
|
481
483
|
y_end_point = y_mid_point
|
482
484
|
if ( r > 0)
|
data/lib/sparklines_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'base64'
|
1
2
|
# Provides a tag for embedding sparklines graphs into your Rails app.
|
2
3
|
#
|
3
4
|
module SparklinesHelper
|
@@ -8,11 +9,20 @@ module SparklinesHelper
|
|
8
9
|
#
|
9
10
|
# You can also pass :class => 'some_css_class' ('sparkline' by default).
|
10
11
|
def sparkline_tag(results=[], options={})
|
11
|
-
|
12
|
-
|
12
|
+
url = { :controller => 'sparklines' }
|
13
|
+
url[:results] = results.join(',') unless results.nil?
|
13
14
|
options = url.merge(options)
|
15
|
+
attributes = %(class="#{options[:class] || 'sparkline'}" alt="Sparkline Graph" )
|
16
|
+
attributes << %(title="#{options[:title]}" ) if options[:title]
|
17
|
+
|
18
|
+
# prefer to use a "data" URL scheme as described in {RFC 2397}[http://www.ietf.org/rfc/rfc2397.txt]
|
19
|
+
# data_url = "data:image/png;base64,#{Base64.encode64(Sparklines.plot(results,options))}"
|
20
|
+
# tag = %(<img src="#{data_url}" #{attributes}/>)
|
21
|
+
|
22
|
+
# # respect some limits noted in RFC 2397 since the data: url is supposed to be 'short'
|
23
|
+
# data_url.length <= 1024 && tag.length <= 2100 ? tag :
|
24
|
+
%(<img src="#{ url_for options }" #{attributes}/>)
|
14
25
|
|
15
|
-
%(<img src="#{ url_for options }" class="#{options[:class] || 'sparkline'}" alt="Sparkline Graph" />)
|
16
26
|
end
|
17
27
|
|
18
28
|
end
|
metadata
CHANGED