sparklines 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,18 @@
27
27
  <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">fill</span>(<span class="ruby-identifier">remain_color</span>)
28
28
  <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">ellipse</span>(<span class="ruby-identifier">r</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>, <span class="ruby-identifier">r</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>, <span class="ruby-identifier">r</span> , <span class="ruby-identifier">r</span> , <span class="ruby-value">0</span>, <span class="ruby-value">360</span>)
29
29
  <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">fill</span>(<span class="ruby-identifier">share_color</span>)
30
+
31
+ <span class="ruby-comment cmt"># Special exceptions</span>
32
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">percent</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
33
+ <span class="ruby-comment cmt"># For 0% return blank</span>
34
+ <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">draw</span>(<span class="ruby-identifier">img</span>)
35
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">img</span>.<span class="ruby-identifier">to_blob</span>
36
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">percent</span> <span class="ruby-operator">==</span> <span class="ruby-value">100</span>
37
+ <span class="ruby-comment cmt"># For 100% just draw a full circle</span>
38
+ <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">ellipse</span>(<span class="ruby-identifier">r</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>, <span class="ruby-identifier">r</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>, <span class="ruby-identifier">r</span> , <span class="ruby-identifier">r</span> , <span class="ruby-value">0</span>, <span class="ruby-value">360</span>)
39
+ <span class="ruby-identifier">draw</span>.<span class="ruby-identifier">draw</span>(<span class="ruby-identifier">img</span>)
40
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">img</span>.<span class="ruby-identifier">to_blob</span>
41
+ <span class="ruby-keyword kw">end</span>
30
42
 
31
43
  <span class="ruby-comment cmt">#Okay, this part is as confusing as hell, so pay attention:
32
44
  <span class="ruby-comment cmt">#This line determines the horizontal portion of the point on the circle where the X-Axis
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File sparklines.rb, line 217</span>
13
+ <pre><span class="ruby-comment cmt"># File sparklines.rb, line 229</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">discrete</span>(<span class="ruby-identifier">results</span>=[], <span class="ruby-identifier">options</span> = {})
15
15
 
16
16
  <span class="ruby-identifier">height</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:height</span>].<span class="ruby-identifier">to_i</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File sparklines.rb, line 267</span>
13
+ <pre><span class="ruby-comment cmt"># File sparklines.rb, line 279</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">area</span>(<span class="ruby-identifier">results</span>=[], <span class="ruby-identifier">options</span>={})
15
15
 
16
16
  <span class="ruby-identifier">step</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:step</span>].<span class="ruby-identifier">to_i</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File sparklines.rb, line 362</span>
13
+ <pre><span class="ruby-comment cmt"># File sparklines.rb, line 374</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">smooth</span>(<span class="ruby-identifier">results</span>, <span class="ruby-identifier">options</span>)
15
15
 
16
16
  <span class="ruby-identifier">step</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:step</span>].<span class="ruby-identifier">to_i</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File sparklines.rb, line 414</span>
13
+ <pre><span class="ruby-comment cmt"># File sparklines.rb, line 426</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">my_polyline</span> (<span class="ruby-identifier">draw</span>, <span class="ruby-identifier">arr</span>)
15
15
  <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
16
16
  <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File sparklines.rb, line 423</span>
13
+ <pre><span class="ruby-comment cmt"># File sparklines.rb, line 435</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">plot_error</span>(<span class="ruby-identifier">options</span>={})
15
15
  <span class="ruby-identifier">img</span> = <span class="ruby-constant">Magick</span><span class="ruby-operator">::</span><span class="ruby-constant">Image</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">40</span>,<span class="ruby-value">15</span>) {<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">background_color</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:background_color</span>]}
16
16
  <span class="ruby-identifier">img</span>.<span class="ruby-identifier">format</span> = <span class="ruby-value str">&quot;PNG&quot;</span>
data/docs/created.rid CHANGED
@@ -1 +1 @@
1
- Mon Aug 01 20:19:02 PDT 2005
1
+ Thu Aug 04 17:20:52 PDT 2005
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Mon Aug 01 20:18:57 PDT 2005</td>
59
+ <td>Tue Aug 02 11:24:32 PDT 2005</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
data/lib/sparklines.rb CHANGED
@@ -88,7 +88,7 @@ Licensed under the MIT license.
88
88
  =end
89
89
 
90
90
  module Sparklines
91
- $VERSION = '0.2.2'
91
+ $VERSION = '0.2.3'
92
92
 
93
93
  # Does the actually plotting of the graph. Calls the appropriate function based on the :type value passed. Defaults to 'smooth.'
94
94
  def Sparklines.plot(results=[], options={})
@@ -170,6 +170,18 @@ module Sparklines
170
170
  draw.fill(remain_color)
171
171
  draw.ellipse(r + 2, r + 2, r , r , 0, 360)
172
172
  draw.fill(share_color)
173
+
174
+ # Special exceptions
175
+ if percent == 0
176
+ # For 0% return blank
177
+ draw.draw(img)
178
+ return img.to_blob
179
+ elsif percent == 100
180
+ # For 100% just draw a full circle
181
+ draw.ellipse(r + 2, r + 2, r , r , 0, 360)
182
+ draw.draw(img)
183
+ return img.to_blob
184
+ end
173
185
 
174
186
  #Okay, this part is as confusing as hell, so pay attention:
175
187
  #This line determines the horizontal portion of the point on the circle where the X-Axis
@@ -3,6 +3,12 @@
3
3
  require 'rubygems'
4
4
  require 'sparklines'
5
5
 
6
+
7
+ [0, 1, 45, 95, 99, 100].each do |value|
8
+ Sparklines.plot_to_file("pie#{value}.png", [value], :type => 'pie', :diameter => 128)
9
+ end
10
+
11
+
6
12
  ary = (1..20).map { rand 100 }
7
13
 
8
14
  # Run each with defaults
@@ -23,4 +29,5 @@ tests = { 'smooth-colored' => { :type => 'smooth',
23
29
 
24
30
  tests.keys.each do |key|
25
31
  Sparklines.plot_to_file("#{key}.png", ary, tests[key])
26
- end
32
+ end
33
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: sparklines
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.2
7
- date: 2005-08-01
6
+ version: 0.2.3
7
+ date: 2005-08-04
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