sparklines 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/README.txt +5 -0
  2. data/lib/sparklines.rb +59 -23
  3. data/samples/area-high.png +0 -0
  4. data/samples/area.png +0 -0
  5. data/samples/discrete.png +0 -0
  6. data/samples/pie-large.png +0 -0
  7. data/samples/pie.png +0 -0
  8. data/samples/pie0.png +0 -0
  9. data/samples/pie1.png +0 -0
  10. data/samples/pie100.png +0 -0
  11. data/samples/pie45.png +0 -0
  12. data/samples/pie95.png +0 -0
  13. data/samples/pie99.png +0 -0
  14. data/samples/smooth-colored.png +0 -0
  15. data/samples/smooth.png +0 -0
  16. data/test/output/area-high.png +0 -0
  17. data/test/output/area.png +0 -0
  18. data/test/output/bar-extreme-values.png +0 -0
  19. data/test/output/bar-string.png +0 -0
  20. data/test/output/bar-tall.png +0 -0
  21. data/test/output/bar-wide.png +0 -0
  22. data/test/output/bar.png +0 -0
  23. data/test/output/discrete-wide.png +0 -0
  24. data/test/output/discrete.png +0 -0
  25. data/test/output/pie-large.png +0 -0
  26. data/test/output/pie.png +0 -0
  27. data/test/output/pie0.png +0 -0
  28. data/test/output/pie1.png +0 -0
  29. data/test/output/pie100.png +0 -0
  30. data/test/output/pie45.png +0 -0
  31. data/test/output/pie95.png +0 -0
  32. data/test/output/pie99.png +0 -0
  33. data/test/output/smooth-colored.png +0 -0
  34. data/test/output/smooth.png +0 -0
  35. data/test/test.rb +77 -0
  36. metadata +39 -23
  37. data/docs/classes/Sparklines.html +0 -564
  38. data/docs/classes/Sparklines.src/M000001.html +0 -59
  39. data/docs/classes/Sparklines.src/M000002.html +0 -20
  40. data/docs/classes/Sparklines.src/M000003.html +0 -73
  41. data/docs/classes/Sparklines.src/M000004.html +0 -37
  42. data/docs/classes/Sparklines.src/M000005.html +0 -88
  43. data/docs/classes/Sparklines.src/M000006.html +0 -60
  44. data/docs/classes/Sparklines.src/M000007.html +0 -22
  45. data/docs/classes/Sparklines.src/M000008.html +0 -26
  46. data/docs/created.rid +0 -1
  47. data/docs/files/sparklines_rb.html +0 -109
  48. data/docs/fr_class_index.html +0 -27
  49. data/docs/fr_file_index.html +0 -27
  50. data/docs/fr_method_index.html +0 -34
  51. data/docs/index.html +0 -24
  52. data/docs/rdoc-style.css +0 -208
  53. data/samples/sparklinestest.rb +0 -33
data/README.txt CHANGED
@@ -39,6 +39,11 @@ Or specify details:
39
39
  CHANGES
40
40
  **********************************
41
41
 
42
+ 0.2.5
43
+
44
+ * Tests now use Test::Unit
45
+ * Bar type added
46
+
42
47
  0.2.1
43
48
 
44
49
  * Added line_color option for smooth graphs
data/lib/sparklines.rb CHANGED
@@ -22,6 +22,8 @@ Original port from Python Sparklines library.
22
22
 
23
23
  ===Tangent regarding RMagick
24
24
 
25
+ The easiest way to use RMagick on Mac OS X is to use darwinports. There are packages for libpng, freetype, and all the other libraries you need.
26
+
25
27
  I had a heck of a time getting RMagick to work on my system so in the interests of saving other people the trouble here's a little set of instructions on how to get RMagick working properly and with the right image formats.
26
28
 
27
29
  1. Install the zlib[http://www.libpng.org/pub/png/libpng.html] library
@@ -70,6 +72,7 @@ Graph types:
70
72
  discrete
71
73
  pie
72
74
  smooth
75
+ bar (results will be normalized, i.e. scaled to take up the full height of the graph)
73
76
 
74
77
  General Defaults:
75
78
 
@@ -88,7 +91,7 @@ Licensed under the MIT license.
88
91
  =end
89
92
 
90
93
  module Sparklines
91
- $VERSION = '0.2.3'
94
+ $VERSION = '0.2.5'
92
95
 
93
96
  # Does the actually plotting of the graph. Calls the appropriate function based on the :type value passed. Defaults to 'smooth.'
94
97
  def Sparklines.plot(results=[], options={})
@@ -115,25 +118,16 @@ module Sparklines
115
118
 
116
119
  # This symbol->string->symbol is kind of awkward. Is there a more elegant way?
117
120
 
118
- # Convert all symbol keys to strings
119
- defaults.keys.reverse.each do |key|
120
- defaults[key.to_s] = defaults[key]
121
- end
122
- options.keys.reverse.each do |key|
123
- options[key.to_s] = options[key]
124
- end
125
-
126
- options = defaults.merge(options)
127
-
128
- # Convert options string keys back to symbols
129
121
  options.keys.reverse.each do |key|
130
122
  options[key.to_sym] = options[key]
131
123
  end
132
-
124
+ options = defaults.merge(options)
125
+
126
+ # Minimal normalization
127
+ maximum_value = self.get_max_value(results).to_f
133
128
 
134
129
  # Call the appropriate function for actual plotting
135
- #self.send('smooth', results, options)
136
- self.send(options[:type], results, options)
130
+ self.send(options[:type], results, options, maximum_value)
137
131
  end
138
132
 
139
133
  # Writes a graph to disk with the specified filename, or "Sparklines.png"
@@ -154,7 +148,7 @@ module Sparklines
154
148
  # :share_color - A string or color code representing the color to draw the share of the pie represented by percent. Defaults to blue.
155
149
  #
156
150
  # :remain_color - A string or color code representing the color to draw the pie not taken by the share color. Defaults to lightgrey.
157
- def self.pie(results=[],options={})
151
+ def self.pie(results=[],options={}, maximum_value=100.0)
158
152
 
159
153
  diameter = options[:diameter].to_i
160
154
  share_color = options[:share_color]
@@ -226,7 +220,7 @@ module Sparklines
226
220
  # :above_color - A string or color code representing the color to draw values above or equal the upper value. Defaults to red.
227
221
  #
228
222
  # :below_color - A string or color code representing the color to draw values below the upper value. Defaults to gray.
229
- def self.discrete(results=[], options = {})
223
+ def self.discrete(results=[], options = {}, maximum_value=100.0)
230
224
 
231
225
  height = options[:height].to_i
232
226
  upper = options[:upper].to_i
@@ -237,12 +231,14 @@ module Sparklines
237
231
  img.format = "PNG"
238
232
  draw = Magick::Draw.new
239
233
 
240
- i=0
234
+ i = 0
241
235
  results.each do |r|
242
- color = (r >= upper) && above_color || below_color
236
+ color = (r >= upper) ? above_color : below_color
243
237
  draw.stroke(color)
244
- draw.line(i, (img.rows - r/(101.0/(height-4))-4).to_i,i,(img.rows - r/(101.0/(height-4))).to_i)
245
- i+=2
238
+ draw.line(i, (img.rows - r/(101.0/(height-4))-4).to_i,
239
+ i, (img.rows - r/(101.0/(height-4))).to_i)
240
+
241
+ i += 2
246
242
  end
247
243
 
248
244
  draw.draw(img)
@@ -276,7 +272,7 @@ module Sparklines
276
272
  # :above_color - A string or color code representing the color to draw values above or equal the upper value. Defaults to red.
277
273
  #
278
274
  # :below_color - A string or color code representing the color to draw values below the upper value. Defaults to gray.
279
- def self.area(results=[], options={})
275
+ def self.area(results=[], options={}, maximum_value=100.0)
280
276
 
281
277
  step = options[:step].to_i
282
278
  height = options[:height].to_i
@@ -371,7 +367,7 @@ module Sparklines
371
367
  # :max_color - A string or color code representing the color that the dot drawn at the largest value will be displayed as. Defaults to green.
372
368
  #
373
369
  # :last_color - A string or color code representing the color that the dot drawn at the last value will be displayed as. Defaults to red.
374
- def self.smooth(results, options)
370
+ def self.smooth(results, options, maximum_value=100.0)
375
371
 
376
372
  step = options[:step].to_i
377
373
  height = options[:height].to_i
@@ -444,4 +440,44 @@ module Sparklines
444
440
  img.to_blob
445
441
  end
446
442
 
443
+
444
+ # Draws a bar graph, normalized.
445
+ #
446
+ # BUG: Last column never goes all the way to the bottom.
447
+ def self.bar(results=[], options = {}, maximum_value=100.0)
448
+ step = options[:step].to_i
449
+ height = options[:height].to_f
450
+ upper = options[:upper].to_i
451
+ below_color = options[:below_color]
452
+ above_color = options[:above_color]
453
+
454
+ img = Magick::Image.new((results.size) * step + 1, height) {
455
+ self.background_color = options[:background_color]
456
+ }
457
+ img.format = "PNG"
458
+ draw = Magick::Draw.new
459
+
460
+ i = 1
461
+ results.each_with_index do |r, index|
462
+ color = (r >= upper) ? above_color : below_color
463
+ draw.stroke('transparent')
464
+ draw.fill(color)
465
+ draw.rectangle( i, img.rows,
466
+ i + step - 2, img.rows - ((r / maximum_value) * img.rows) )
467
+ i += step
468
+ end
469
+
470
+ draw.draw(img)
471
+ img.to_blob
472
+ end
473
+
474
+
475
+ def self.get_max_value(values=[])
476
+ max_value = 0
477
+ values.each do |value|
478
+ max_value = (value > max_value) ? value : max_value
479
+ end
480
+ return max_value
481
+ end
482
+
447
483
  end
Binary file
data/samples/area.png ADDED
Binary file
Binary file
Binary file
data/samples/pie.png ADDED
Binary file
data/samples/pie0.png ADDED
Binary file
data/samples/pie1.png ADDED
Binary file
Binary file
data/samples/pie45.png ADDED
Binary file
data/samples/pie95.png ADDED
Binary file
data/samples/pie99.png ADDED
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.rb ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'test/unit'
4
+ require 'lib/sparklines'
5
+
6
+ class SparklinesTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @data = (1..30).map { rand 100 }
10
+ end
11
+
12
+ def test_each_graph
13
+ %w{pie area discrete smooth bar}.each do |type|
14
+ Sparklines.plot_to_file("test/output/#{type}.png", @data, :type => type)
15
+ end
16
+ end
17
+
18
+ def test_pie_graph
19
+ # Test extremes which previously did not work right
20
+ [0, 1, 45, 95, 99, 100].each do |value|
21
+ Sparklines.plot_to_file("test/output/pie#{value}.png", [value], :type => 'pie', :diameter => 128)
22
+ end
23
+ end
24
+
25
+ def test_special
26
+ # Run special tests
27
+ tests = { 'smooth-colored' => { :type => 'smooth', :line_color => 'purple'},
28
+ 'pie-large' => { :type => 'pie', :diameter => 200 },
29
+ 'area-high' => { :type => 'area',
30
+ :upper => 80,
31
+ :step => 4,
32
+ :height => 20},
33
+ 'discrete-wide' => { :type => 'discrete',
34
+ :step => 8 },
35
+ 'bar-wide' => { :type => 'bar',
36
+ :step => 8 }
37
+ }
38
+ tests.keys.each do |key|
39
+ Sparklines.plot_to_file("test/output/#{key}.png", @data, tests[key])
40
+ end
41
+ end
42
+
43
+ def test_smooth_graph
44
+
45
+ end
46
+
47
+ def test_bar_tall
48
+ Sparklines.plot_to_file('test/output/bar-tall.png', @data,
49
+ :type => 'bar',
50
+ :below_color => 'blue',
51
+ :above_color => 'red',
52
+ :upper => 90,
53
+ :height => 50,
54
+ :step => 8 )
55
+ end
56
+
57
+ def test_bar_extreme_values
58
+ Sparklines.plot_to_file('test/output/bar-extreme-values.png', [0,1,100,2,99,3,98,4,97,5,96,6,95,7,94,8,93,9,92,10,91],
59
+ :type => 'bar',
60
+ :below_color => 'blue',
61
+ :above_color => 'red',
62
+ :upper => 90,
63
+ :step => 4 )
64
+ end
65
+
66
+ def test_string_args
67
+ Sparklines.plot_to_file('test/output/bar-string.png', @data,
68
+ 'type' => 'bar',
69
+ 'below_color' => 'blue',
70
+ 'above_color' => 'red',
71
+ 'upper' => 50,
72
+ 'height' => 50,
73
+ 'step' => 8 )
74
+ end
75
+
76
+
77
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: sparklines
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.4
7
- date: 2005-08-09
6
+ version: 0.2.5
7
+ date: 2005-10-24 00:00:00 -07:00
8
8
  summary: Sparklines generates tiny little graphs for use alongside tables or inline with text. Rails helpers are also available for easy use in web pages.
9
9
  require_paths:
10
10
  - lib
@@ -24,31 +24,47 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
24
24
  version: 0.0.0
25
25
  version:
26
26
  platform: ruby
27
+ signing_key:
28
+ cert_chain:
27
29
  authors:
28
30
  - Geoffrey Grosenbach
29
31
  - Dan Nugent
30
32
  files:
31
33
  - lib/sparklines.rb
32
- - samples/sparklinestest.rb
33
- - docs/classes
34
- - docs/created.rid
35
- - docs/files
36
- - docs/fr_class_index.html
37
- - docs/fr_file_index.html
38
- - docs/fr_method_index.html
39
- - docs/index.html
40
- - docs/rdoc-style.css
41
- - docs/classes/Sparklines.html
42
- - docs/classes/Sparklines.src
43
- - docs/classes/Sparklines.src/M000001.html
44
- - docs/classes/Sparklines.src/M000002.html
45
- - docs/classes/Sparklines.src/M000003.html
46
- - docs/classes/Sparklines.src/M000004.html
47
- - docs/classes/Sparklines.src/M000005.html
48
- - docs/classes/Sparklines.src/M000006.html
49
- - docs/classes/Sparklines.src/M000007.html
50
- - docs/classes/Sparklines.src/M000008.html
51
- - docs/files/sparklines_rb.html
34
+ - samples/area-high.png
35
+ - samples/area.png
36
+ - samples/discrete.png
37
+ - samples/pie-large.png
38
+ - samples/pie.png
39
+ - samples/pie0.png
40
+ - samples/pie1.png
41
+ - samples/pie100.png
42
+ - samples/pie45.png
43
+ - samples/pie95.png
44
+ - samples/pie99.png
45
+ - samples/smooth-colored.png
46
+ - samples/smooth.png
47
+ - test/output
48
+ - test/test.rb
49
+ - test/output/area-high.png
50
+ - test/output/area.png
51
+ - test/output/bar-extreme-values.png
52
+ - test/output/bar-string.png
53
+ - test/output/bar-tall.png
54
+ - test/output/bar-wide.png
55
+ - test/output/bar.png
56
+ - test/output/discrete-wide.png
57
+ - test/output/discrete.png
58
+ - test/output/pie-large.png
59
+ - test/output/pie.png
60
+ - test/output/pie0.png
61
+ - test/output/pie1.png
62
+ - test/output/pie100.png
63
+ - test/output/pie45.png
64
+ - test/output/pie95.png
65
+ - test/output/pie99.png
66
+ - test/output/smooth-colored.png
67
+ - test/output/smooth.png
52
68
  - README.txt
53
69
  test_files: []
54
70
  rdoc_options: []
@@ -1,564 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: Sparklines</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Module</strong></td>
53
- <td class="class-name-in-header">Sparklines</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/sparklines_rb.html">
59
- sparklines.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- </table>
66
- </div>
67
- <!-- banner header -->
68
-
69
- <div id="bodyContent">
70
-
71
-
72
-
73
- <div id="contextContent">
74
-
75
- <div id="description">
76
- <p>
77
- A library (in Ruby!) for generating sparklines.
78
- </p>
79
- <p>
80
- Can be used to write to a file or make a web service with Rails or other
81
- Ruby CGI apps.
82
- </p>
83
- <p>
84
- Idea and much of the outline for the source lifted directly from <a
85
- href="http://bitworking.org/projects/sparklines">Joe Gregorio's Python
86
- Sparklines web service script</a>.
87
- </p>
88
- <p>
89
- Requires the RMagick image library.
90
- </p>
91
- <h2>Authors</h2>
92
- <p>
93
- <a href="mailto:nugend@gmail.com">Dan Nugent</a> Original port from Python
94
- <a href="Sparklines.html">Sparklines</a> library.
95
- </p>
96
- <p>
97
- <a href="mailto:boss@topfunky.com">Geoffrey Grosenbach</a> &#8212; <a
98
- href="http://nubyonrails.topfunky.com">nubyonrails.topfunky.com</a> &#8212;
99
- Conversion to module and addition of functions for using with Rails. Also
100
- changed functions to use Rails-style option hashes for parameters.
101
- </p>
102
- <h3>Tangent regarding RMagick</h3>
103
- <p>
104
- I had a heck of a time getting RMagick to work on my system so in the
105
- interests of saving other people the trouble here&#8217;s a little set of
106
- instructions on how to get RMagick working properly and with the right
107
- image formats.
108
- </p>
109
- <ol>
110
- <li>Install the <a href="http://www.libpng.org/pub/png/libpng.html">zlib</a>
111
- library
112
-
113
- </li>
114
- <li>With zlib in the same directory as the <a
115
- href="http://www.libpng.org/pub/png/libpng.html">libpng</a> library,
116
- install libpng
117
-
118
- </li>
119
- <li>Option step: Install the <a
120
- href="ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz">jpeg library</a>
121
- (You need it to use jpegs and you might want to have it)
122
-
123
- </li>
124
- <li>Install ImageMagick from <b><a
125
- href="http://www.imagemagick.org/script/install-source.php">source</a></b>.
126
- RMagick requires the ImageMagick headers, so this is important.
127
-
128
- </li>
129
- <li>Install RMagick from <a
130
- href="http://rubyforge.org/projects/rmagick/">source</a>. The gem is not
131
- reliable.
132
-
133
- </li>
134
- <li>Edit Magick-conf if necessary. I had to remove -lcms and -ltiff since I
135
- didn&#8217;t want those to be built and the libraries weren&#8217;t on my
136
- system.
137
-
138
- </li>
139
- </ol>
140
- <p>
141
- Please keep in mind that these were only the steps that made RMagick work
142
- on my machine. This is a tricky library to get working. Consider using Joe
143
- Gregorio&#8217;s version for Python if the installation proves to be too
144
- cumbersome.
145
- </p>
146
- <h2>General Usage and Defaults</h2>
147
- <p>
148
- To use in a script:
149
- </p>
150
- <pre>
151
- require 'rubygems'
152
- require 'sparklines'
153
- Sparklines.plot([1,25,33,46,89,90,85,77,42], :type =&gt; 'discrete', :height =&gt; 20)
154
- </pre>
155
- <p>
156
- An image blob will be returned which you can print, write to STDOUT, etc.
157
- </p>
158
- <p>
159
- In Rails,
160
- </p>
161
- <ul>
162
- <li>Install the &#8216;sparklines_generator&#8217; gem (&#8216;gem install
163
- sparklines_generator&#8217;)
164
-
165
- </li>
166
- <li>Call &#8216;ruby script/generate sparklines&#8217;. This will copy the <a
167
- href="Sparklines.html">Sparklines</a> controller and helper to your rails
168
- directories
169
-
170
- </li>
171
- <li>Add &quot;require &#8216;sparklines&#8217;&quot; to the bottom of your
172
- config/environment.rb
173
-
174
- </li>
175
- <li>Restart your fcgi&#8217;s or your WEBrick if necessary
176
-
177
- </li>
178
- </ul>
179
- <p>
180
- And finally, add this to the controller whose view will be using
181
- sparklines:
182
- </p>
183
- <pre>
184
- helper :sparklines
185
- </pre>
186
- <p>
187
- In your view, call it like this:
188
- </p>
189
- <p>
190
- &lt;%= sparkline_tag [1,2,3,4,5,6] %&gt; &lt;!&#8212; Gives you a smooth
191
- graph &#8212;&gt;
192
- </p>
193
- <p>
194
- Or specify details:
195
- </p>
196
- <p>
197
- &lt;%= sparkline_tag [1,2,3,4,5,6], :type =&gt; &#8216;discrete&#8217;,
198
- :height =&gt; 10, :upper =&gt; 80, :above_color =&gt; &#8216;green&#8217;,
199
- :below_color =&gt; &#8216;blue&#8217; %&gt;
200
- </p>
201
- <p>
202
- Graph types:
203
- </p>
204
- <pre>
205
- area
206
- discrete
207
- pie
208
- smooth
209
- </pre>
210
- <p>
211
- General Defaults:
212
- </p>
213
- <pre>
214
- :type =&gt; 'smooth'
215
- :height =&gt; 14px
216
- :upper =&gt; 50
217
- :above_color =&gt; 'red'
218
- :below_color =&gt; 'grey'
219
- :background_color =&gt; 'white'
220
- :line_color =&gt; 'lightgrey'
221
- </pre>
222
- <h2>License</h2>
223
- <p>
224
- Licensed under the MIT license.
225
- </p>
226
-
227
- </div>
228
-
229
-
230
- </div>
231
-
232
- <div id="method-list">
233
- <h3 class="section-bar">Methods</h3>
234
-
235
- <div class="name-list">
236
- <a href="#M000005">area</a>&nbsp;&nbsp;
237
- <a href="#M000004">discrete</a>&nbsp;&nbsp;
238
- <a href="#M000007">my_polyline</a>&nbsp;&nbsp;
239
- <a href="#M000003">pie</a>&nbsp;&nbsp;
240
- <a href="#M000001">plot</a>&nbsp;&nbsp;
241
- <a href="#M000008">plot_error</a>&nbsp;&nbsp;
242
- <a href="#M000002">plot_to_file</a>&nbsp;&nbsp;
243
- <a href="#M000006">smooth</a>&nbsp;&nbsp;
244
- </div>
245
- </div>
246
-
247
- </div>
248
-
249
-
250
- <!-- if includes -->
251
-
252
- <div id="section">
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
- <!-- if method_list -->
262
- <div id="methods">
263
- <h3 class="section-bar">Public Class methods</h3>
264
-
265
- <div id="method-M000005" class="method-detail">
266
- <a name="M000005"></a>
267
-
268
- <div class="method-heading">
269
- <a href="Sparklines.src/M000005.html" target="Code" class="method-signature"
270
- onclick="popupCode('Sparklines.src/M000005.html');return false;">
271
- <span class="method-name">area</span><span class="method-args">(results=[], options={})</span>
272
- </a>
273
- </div>
274
-
275
- <div class="method-description">
276
- <p>
277
- Creates a continuous area sparkline
278
- </p>
279
- <ul>
280
- <li>results is an array of integer values between 0 and 100 inclusive
281
-
282
- </li>
283
- <li>options is a hash that takes 4 parameters:
284
-
285
- </li>
286
- </ul>
287
- <p>
288
- :step - An integer that determines the distance between each point on the
289
- sparkline. Defaults to 2.
290
- </p>
291
- <p>
292
- :height - An integer that determines what the height of the sparkline will
293
- be. Defaults to 14
294
- </p>
295
- <p>
296
- :upper - An ineger that determines the threshold for colorization purposes.
297
- Any value less than upper will be colored using below_color, anything above
298
- and equal to upper will use above_color. Defaults to 50.
299
- </p>
300
- <p>
301
- :has_min - Determines whether a dot will be drawn at the lowest value or
302
- not. Defaulst to false.
303
- </p>
304
- <p>
305
- :has_max - Determines whether a dot will be drawn at the highest value or
306
- not. Defaulst to false.
307
- </p>
308
- <p>
309
- :has_last - Determines whether a dot will be drawn at the last value or
310
- not. Defaulst to false.
311
- </p>
312
- <p>
313
- :min_color - A string or color code representing the color that the dot
314
- drawn at the smallest value will be displayed as. Defaults to blue.
315
- </p>
316
- <p>
317
- :max_color - A string or color code representing the color that the dot
318
- drawn at the largest value will be displayed as. Defaults to green.
319
- </p>
320
- <p>
321
- :last_color - A string or color code representing the color that the dot
322
- drawn at the last value will be displayed as. Defaults to red.
323
- </p>
324
- <p>
325
- :above_color - A string or color code representing the color to draw values
326
- above or equal the upper value. Defaults to red.
327
- </p>
328
- <p>
329
- :below_color - A string or color code representing the color to draw values
330
- below the upper value. Defaults to gray.
331
- </p>
332
- </div>
333
- </div>
334
-
335
- <div id="method-M000004" class="method-detail">
336
- <a name="M000004"></a>
337
-
338
- <div class="method-heading">
339
- <a href="Sparklines.src/M000004.html" target="Code" class="method-signature"
340
- onclick="popupCode('Sparklines.src/M000004.html');return false;">
341
- <span class="method-name">discrete</span><span class="method-args">(results=[], options = {})</span>
342
- </a>
343
- </div>
344
-
345
- <div class="method-description">
346
- <p>
347
- Creates a discretized sparkline
348
- </p>
349
- <ul>
350
- <li>results is an array of integer values between 0 and 100 inclusive
351
-
352
- </li>
353
- <li>options is a hash that takes 4 parameters:
354
-
355
- </li>
356
- </ul>
357
- <p>
358
- :height - An integer that determines what the height of the sparkline will
359
- be. Defaults to 14
360
- </p>
361
- <p>
362
- :upper - An integer that determines the threshold for colorization
363
- purposes. Any value less than upper will be colored using below_color,
364
- anything above and equal to upper will use above_color. Defaults to 50.
365
- </p>
366
- <p>
367
- :above_color - A string or color code representing the color to draw values
368
- above or equal the upper value. Defaults to red.
369
- </p>
370
- <p>
371
- :below_color - A string or color code representing the color to draw values
372
- below the upper value. Defaults to gray.
373
- </p>
374
- </div>
375
- </div>
376
-
377
- <div id="method-M000007" class="method-detail">
378
- <a name="M000007"></a>
379
-
380
- <div class="method-heading">
381
- <a href="Sparklines.src/M000007.html" target="Code" class="method-signature"
382
- onclick="popupCode('Sparklines.src/M000007.html');return false;">
383
- <span class="method-name">my_polyline</span><span class="method-args">(draw, arr)</span>
384
- </a>
385
- </div>
386
-
387
- <div class="method-description">
388
- <p>
389
- This is a function to replace the RMagick polyline function because it
390
- doesn&#8217;t seem to work properly.
391
- </p>
392
- <ul>
393
- <li>draw - a RMagick::Draw object.
394
-
395
- </li>
396
- <li>arr - an array of points (represented as two element arrays)
397
-
398
- </li>
399
- </ul>
400
- </div>
401
- </div>
402
-
403
- <div id="method-M000003" class="method-detail">
404
- <a name="M000003"></a>
405
-
406
- <div class="method-heading">
407
- <a href="Sparklines.src/M000003.html" target="Code" class="method-signature"
408
- onclick="popupCode('Sparklines.src/M000003.html');return false;">
409
- <span class="method-name">pie</span><span class="method-args">(results=[],options={})</span>
410
- </a>
411
- </div>
412
-
413
- <div class="method-description">
414
- <p>
415
- Creates a pie-chart sparkline
416
- </p>
417
- <ul>
418
- <li>results - an array of integer values between 0 and 100 inclusive. Only the
419
- first integer will be accepted. It will be used to determine the percentage
420
- of the pie that is filled by the share_color
421
-
422
- </li>
423
- <li>options - a hash that takes parameters:
424
-
425
- </li>
426
- </ul>
427
- <p>
428
- :diameter - An integer that determines what the size of the sparkline will
429
- be. Defaults to 20
430
- </p>
431
- <p>
432
- :share_color - A string or color code representing the color to draw the
433
- share of the pie represented by percent. Defaults to blue.
434
- </p>
435
- <p>
436
- :remain_color - A string or color code representing the color to draw the
437
- pie not taken by the share color. Defaults to lightgrey.
438
- </p>
439
- </div>
440
- </div>
441
-
442
- <div id="method-M000001" class="method-detail">
443
- <a name="M000001"></a>
444
-
445
- <div class="method-heading">
446
- <a href="Sparklines.src/M000001.html" target="Code" class="method-signature"
447
- onclick="popupCode('Sparklines.src/M000001.html');return false;">
448
- <span class="method-name">plot</span><span class="method-args">(results=[], options={})</span>
449
- </a>
450
- </div>
451
-
452
- <div class="method-description">
453
- <p>
454
- Does the actually plotting of the graph. Calls the appropriate function
455
- based on the :type value passed. Defaults to &#8216;smooth.&#8217;
456
- </p>
457
- </div>
458
- </div>
459
-
460
- <div id="method-M000008" class="method-detail">
461
- <a name="M000008"></a>
462
-
463
- <div class="method-heading">
464
- <a href="Sparklines.src/M000008.html" target="Code" class="method-signature"
465
- onclick="popupCode('Sparklines.src/M000008.html');return false;">
466
- <span class="method-name">plot_error</span><span class="method-args">(options={})</span>
467
- </a>
468
- </div>
469
-
470
- <div class="method-description">
471
- <p>
472
- Draw the error Sparkline. Not implemented yet.
473
- </p>
474
- </div>
475
- </div>
476
-
477
- <div id="method-M000002" class="method-detail">
478
- <a name="M000002"></a>
479
-
480
- <div class="method-heading">
481
- <a href="Sparklines.src/M000002.html" target="Code" class="method-signature"
482
- onclick="popupCode('Sparklines.src/M000002.html');return false;">
483
- <span class="method-name">plot_to_file</span><span class="method-args">(filename=&quot;sparklines.png&quot;, results=[], options={})</span>
484
- </a>
485
- </div>
486
-
487
- <div class="method-description">
488
- <p>
489
- Writes a graph to disk with the specified filename, or
490
- &quot;Sparklines.png&quot;
491
- </p>
492
- </div>
493
- </div>
494
-
495
- <div id="method-M000006" class="method-detail">
496
- <a name="M000006"></a>
497
-
498
- <div class="method-heading">
499
- <a href="Sparklines.src/M000006.html" target="Code" class="method-signature"
500
- onclick="popupCode('Sparklines.src/M000006.html');return false;">
501
- <span class="method-name">smooth</span><span class="method-args">(results, options)</span>
502
- </a>
503
- </div>
504
-
505
- <div class="method-description">
506
- <p>
507
- Creates a smooth sparkline
508
- </p>
509
- <ul>
510
- <li>results - an array of integer values between 0 and 100 inclusive
511
-
512
- </li>
513
- <li>options - a hash that takes these optional parameters:
514
-
515
- </li>
516
- </ul>
517
- <p>
518
- :step - An integer that determines the distance between each point on the
519
- sparkline. Defaults to 2.
520
- </p>
521
- <p>
522
- :height - An integer that determines what the height of the sparkline will
523
- be. Defaults to 14
524
- </p>
525
- <p>
526
- :has_min - Determines whether a dot will be drawn at the lowest value or
527
- not. Defaulst to false.
528
- </p>
529
- <p>
530
- :has_max - Determines whether a dot will be drawn at the highest value or
531
- not. Defaulst to false.
532
- </p>
533
- <p>
534
- :has_last - Determines whether a dot will be drawn at the last value or
535
- not. Defaulst to false.
536
- </p>
537
- <p>
538
- :min_color - A string or color code representing the color that the dot
539
- drawn at the smallest value will be displayed as. Defaults to blue.
540
- </p>
541
- <p>
542
- :max_color - A string or color code representing the color that the dot
543
- drawn at the largest value will be displayed as. Defaults to green.
544
- </p>
545
- <p>
546
- :last_color - A string or color code representing the color that the dot
547
- drawn at the last value will be displayed as. Defaults to red.
548
- </p>
549
- </div>
550
- </div>
551
-
552
-
553
- </div>
554
-
555
-
556
- </div>
557
-
558
-
559
- <div id="validator-badges">
560
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
561
- </div>
562
-
563
- </body>
564
- </html>