Kelsin-lilygraph 0.2.5 → 0.3.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/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
 
11
11
  s.add_dependency("color-tools", ">= 1.3.0")
12
12
  end
13
+ Jeweler::GemcutterTasks.new
13
14
  rescue LoadError
14
15
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
15
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.0
@@ -0,0 +1,347 @@
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>Class: Lilygraph</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>Class</strong></td>
53
+ <td class="class-name-in-header">Lilygraph</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/lilygraph_rb.html">
59
+ lib/lilygraph.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ This is the main class to use if you want to create a graph!
84
+ </p>
85
+ <pre>
86
+ graph = Lilygraph.new(:title =&gt; &quot;My Awesome Graph&quot;)
87
+ graph.data = [1,2,3]
88
+ graph.labels = ['One','Two','Three']
89
+ graph.render
90
+ </pre>
91
+ <p>
92
+ This class outputs svg as a string once you call <a
93
+ href="Lilygraph.html#M000003">render</a>.
94
+ </p>
95
+
96
+ </div>
97
+
98
+
99
+ </div>
100
+
101
+ <div id="method-list">
102
+ <h3 class="section-bar">Methods</h3>
103
+
104
+ <div class="name-list">
105
+ <a href="#M000001">new</a>&nbsp;&nbsp;
106
+ <a href="#M000003">render</a>&nbsp;&nbsp;
107
+ <a href="#M000002">update_options</a>&nbsp;&nbsp;
108
+ </div>
109
+ </div>
110
+
111
+ </div>
112
+
113
+
114
+ <!-- if includes -->
115
+
116
+ <div id="section">
117
+
118
+
119
+ <div id="constants-list">
120
+ <h3 class="section-bar">Constants</h3>
121
+
122
+ <div class="name-list">
123
+ <table summary="Constants">
124
+ <tr class="top-aligned-row context-row">
125
+ <td class="context-item-name">DEFAULT_OPTIONS</td>
126
+ <td>=</td>
127
+ <td class="context-item-value">{ :height =&gt; '100%', :width =&gt; '100%', :indent =&gt; 2, :padding =&gt; 14, :bar_text =&gt; true, :viewbox =&gt; { :width =&gt; 800, :height =&gt; 600</td>
128
+ <td width="3em">&nbsp;</td>
129
+ <td class="context-item-desc">
130
+ Default options for the initializer
131
+
132
+ </td>
133
+ </tr>
134
+ </table>
135
+ </div>
136
+ </div>
137
+
138
+
139
+
140
+ <div id="attribute-list">
141
+ <h3 class="section-bar">Attributes</h3>
142
+
143
+ <div class="name-list">
144
+ <table>
145
+ <tr class="top-aligned-row context-row">
146
+ <td class="context-item-name">colors</td>
147
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
148
+ <td class="context-item-desc">
149
+ This allows you to set colors for the bars.
150
+
151
+ <p>
152
+ If you just want a single color:
153
+ </p>
154
+ <pre>
155
+ graph.colors='#0000aa'
156
+ </pre>
157
+ <p>
158
+ If you want to make each bar (or bar group) different colors:
159
+ </p>
160
+ <pre>
161
+ graph.colors=['#aa0000','#00aa00','#0000aa']
162
+ </pre>
163
+ <p>
164
+ If you want every bar group to be the same, but each bar in the groups to
165
+ have a different color
166
+ </p>
167
+ <pre>
168
+ graph.colors=[['#aa0000','#00aa00','#0000aa']]
169
+ </pre>
170
+ <p>
171
+ If you want to set every bar group color:
172
+ </p>
173
+ <pre>
174
+ graph.colors=[['#aa0000','#00aa00','#0000aa'],['#bb0000','#00bb00','#0000bb']]
175
+ </pre>
176
+ <p>
177
+ Last but not least you can set the color value to any object that responds
178
+ to call (like a Proc). The proc takes four arguments. data_index: The index
179
+ of the current bar (or group) number_index: The index of the current bar
180
+ INSIDE of the current bar group (always 0 if you don&#8216;t have grouped
181
+ bars) data_size: total number of bar or groups. number_size: total number
182
+ of bars in the current group (always 1 if you don&#8216;t have bar groups)
183
+ </p>
184
+ <p>
185
+ The default proc looks like:
186
+ </p>
187
+ <pre>
188
+ graph.colors=Proc.new do |data_index, number_index, data_size, number_size|
189
+ Color::HSL.from_fraction(Float(data_index) / Float(data_size), 1.0, 0.4 + (Float(number_index) / Float(number_size) * 0.4)).to_rgb.html
190
+ end
191
+ </pre>
192
+ </td>
193
+ </tr>
194
+ <tr class="top-aligned-row context-row">
195
+ <td class="context-item-name">data</td>
196
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
197
+ <td class="context-item-desc">
198
+ This is the data for the graph. It should be an array where every item is
199
+ either a number or an array of numbers.
200
+
201
+ <p>
202
+ For a simple bar graph:
203
+ </p>
204
+ <pre>
205
+ graph.data=[1,2,3]
206
+ </pre>
207
+ <p>
208
+ For a grouped bar graph:
209
+ </p>
210
+ <pre>
211
+ graph.data=[[1,10],[2,20],[3,30]]
212
+ </pre>
213
+ </td>
214
+ </tr>
215
+ <tr class="top-aligned-row context-row">
216
+ <td class="context-item-name">labels</td>
217
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
218
+ <td class="context-item-desc">
219
+ An array of labels to use on the y axis. Make sure you have the right
220
+ number of labels. The size of this array should = the size of the data
221
+ array.
222
+
223
+ </td>
224
+ </tr>
225
+ </table>
226
+ </div>
227
+ </div>
228
+
229
+
230
+
231
+ <!-- if method_list -->
232
+ <div id="methods">
233
+ <h3 class="section-bar">Public Class methods</h3>
234
+
235
+ <div id="method-M000001" class="method-detail">
236
+ <a name="M000001"></a>
237
+
238
+ <div class="method-heading">
239
+ <a href="Lilygraph.src/M000001.html" target="Code" class="method-signature"
240
+ onclick="popupCode('Lilygraph.src/M000001.html');return false;">
241
+ <span class="method-name">new</span><span class="method-args">(options = {})</span>
242
+ </a>
243
+ </div>
244
+
245
+ <div class="method-description">
246
+ <p>
247
+ Returns a <a href="Lilygraph.html#M000001">new</a> graph creator with some
248
+ default options specified via a hash:
249
+ </p>
250
+ <table>
251
+ <tr><td valign="top">height:</td><td>String to use as height parameter on the svg tag. Default is
252
+ <tt>&#8216;100%&#8217;</tt>.
253
+
254
+ </td></tr>
255
+ <tr><td valign="top">width:</td><td>String to use as width parameter on the svg tag. Default is
256
+ <tt>&#8216;100%&#8217;</tt>.
257
+
258
+ </td></tr>
259
+ <tr><td valign="top">indent:</td><td>Indent option to the XmlMarkup object. Defaults to <tt>2</tt>.
260
+
261
+ </td></tr>
262
+ <tr><td valign="top">padding:</td><td>Number of svg units in between two bars. Defaults to <tt>14</tt>.
263
+
264
+ </td></tr>
265
+ <tr><td valign="top">bar_text:</td><td>(Boolean) Whether or not to include the text labels above every bar.
266
+ Defaults to <tt>true</tt>.
267
+
268
+ </td></tr>
269
+ <tr><td valign="top">viewbox:</td><td>Hash of <tt>:height</tt> and <tt>:width</tt> keys to use for the viewbox
270
+ parameter of the svg tag. Defaults to <tt>{:height =&gt; 600, :width =&gt;
271
+ 800}</tt>.
272
+
273
+ </td></tr>
274
+ <tr><td valign="top">margin:</td><td>Hash of margins to use for graph (in svg units). Defaults to <tt>{:top
275
+ =&gt; 50, :left =&gt; 50, :right =&gt; 50, :bottom =&gt; 100}</tt>.
276
+
277
+ </td></tr>
278
+ </table>
279
+ <p>
280
+ For example, this creates a graph with a title and different indent
281
+ setting:
282
+ </p>
283
+ <pre>
284
+ graph = Lilygraph.new(:title =&gt; 'Testing a title', :indent =&gt; 4)
285
+ </pre>
286
+ </div>
287
+ </div>
288
+
289
+ <h3 class="section-bar">Public Instance methods</h3>
290
+
291
+ <div id="method-M000003" class="method-detail">
292
+ <a name="M000003"></a>
293
+
294
+ <div class="method-heading">
295
+ <a href="Lilygraph.src/M000003.html" target="Code" class="method-signature"
296
+ onclick="popupCode('Lilygraph.src/M000003.html');return false;">
297
+ <span class="method-name">render</span><span class="method-args">() {|xml, @options| ...}</span>
298
+ </a>
299
+ </div>
300
+
301
+ <div class="method-description">
302
+ <p>
303
+ This returns a string of the graph as an svg. You can pass in a block in
304
+ order to add your own items to the graph. Your block is passed the
305
+ XmlMarkup object to use as well as the options hash in case you need to use
306
+ some of that data.
307
+ </p>
308
+ <pre>
309
+ graph.render do |xml|
310
+ xml.text &quot;Hello&quot;, :x =&gt; 5, :y =&gt; 25
311
+ end
312
+ </pre>
313
+ </div>
314
+ </div>
315
+
316
+ <div id="method-M000002" class="method-detail">
317
+ <a name="M000002"></a>
318
+
319
+ <div class="method-heading">
320
+ <a href="Lilygraph.src/M000002.html" target="Code" class="method-signature"
321
+ onclick="popupCode('Lilygraph.src/M000002.html');return false;">
322
+ <span class="method-name">update_options</span><span class="method-args">(options = {})</span>
323
+ </a>
324
+ </div>
325
+
326
+ <div class="method-description">
327
+ <p>
328
+ Updates the graph options with items from the passed in hash. Please refer
329
+ to <a href="Lilygraph.html#M000001">new</a> for a description of available
330
+ options.
331
+ </p>
332
+ </div>
333
+ </div>
334
+
335
+
336
+ </div>
337
+
338
+
339
+ </div>
340
+
341
+
342
+ <div id="validator-badges">
343
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
344
+ </div>
345
+
346
+ </body>
347
+ </html>
@@ -0,0 +1,24 @@
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>
7
+ <head>
8
+ <title>new (Lilygraph)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lilygraph.rb, line 77</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
15
+ <span class="ruby-ivar">@options</span> = <span class="ruby-constant">DEFAULT_OPTIONS</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
16
+ <span class="ruby-ivar">@data</span> = []
17
+ <span class="ruby-ivar">@labels</span> = []
18
+
19
+ <span class="ruby-ivar">@colors</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">data_index</span>, <span class="ruby-identifier">number_index</span>, <span class="ruby-identifier">data_size</span>, <span class="ruby-identifier">number_size</span><span class="ruby-operator">|</span>
20
+ <span class="ruby-constant">Color</span><span class="ruby-operator">::</span><span class="ruby-constant">HSL</span>.<span class="ruby-identifier">from_fraction</span>(<span class="ruby-constant">Float</span>(<span class="ruby-identifier">data_index</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Float</span>(<span class="ruby-identifier">data_size</span>), <span class="ruby-value">1.0</span>, <span class="ruby-value">0</span><span class="ruby-value">.4</span> <span class="ruby-operator">+</span> (<span class="ruby-constant">Float</span>(<span class="ruby-identifier">number_index</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Float</span>(<span class="ruby-identifier">number_size</span>) <span class="ruby-operator">*</span> <span class="ruby-value">0</span><span class="ruby-value">.4</span>)).<span class="ruby-identifier">to_rgb</span>.<span class="ruby-identifier">html</span>
21
+ <span class="ruby-keyword kw">end</span>
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>
@@ -0,0 +1,18 @@
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>
7
+ <head>
8
+ <title>update_options (Lilygraph)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lilygraph.rb, line 89</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_options</span>(<span class="ruby-identifier">options</span> = {})
15
+ <span class="ruby-ivar">@options</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,133 @@
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>
7
+ <head>
8
+ <title>render (Lilygraph)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lilygraph.rb, line 101</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>
15
+ <span class="ruby-identifier">output</span> = <span class="ruby-value str">&quot;&quot;</span>
16
+ <span class="ruby-identifier">xml</span> = <span class="ruby-constant">Builder</span><span class="ruby-operator">::</span><span class="ruby-constant">XmlMarkup</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:target</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">output</span>, <span class="ruby-identifier">:indent</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:indent</span>])
17
+
18
+ <span class="ruby-comment cmt"># Output headers unless we specified otherwise</span>
19
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">instruct!</span>
20
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">declare!</span> <span class="ruby-identifier">:DOCTYPE</span>, <span class="ruby-identifier">:svg</span>, <span class="ruby-identifier">:PUBLIC</span>, <span class="ruby-value str">&quot;-//W3C//DTD SVG 1.1//EN&quot;</span>, <span class="ruby-value str">&quot;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&quot;</span>
21
+
22
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">svg</span>(<span class="ruby-identifier">:viewBox</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;0 0 #{@options[:viewbox][:width]} #{@options[:viewbox][:height]}&quot;</span>,
23
+ <span class="ruby-identifier">:width</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:width</span>], <span class="ruby-identifier">:height</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:height</span>],
24
+ <span class="ruby-identifier">:xmlns</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'http://www.w3.org/2000/svg'</span>, <span class="ruby-identifier">:version</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'1.1'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
25
+
26
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">g</span>(<span class="ruby-identifier">:fill</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'black'</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'black'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'2'</span>,
27
+ <span class="ruby-value str">'font-family'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'Helvetica, Arial, sans-serif'</span>, <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'10px'</span>, <span class="ruby-value str">'font-weight'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'medium'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
28
+
29
+ <span class="ruby-comment cmt"># Outline</span>
30
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">rect</span>(<span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:left</span>], <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:top</span>],
31
+ <span class="ruby-identifier">:width</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">graph_width</span>,
32
+ <span class="ruby-identifier">:height</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">graph_height</span>,
33
+ <span class="ruby-identifier">:fill</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'lightgray'</span>)
34
+
35
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">g</span> <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'1'</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
36
+
37
+ <span class="ruby-comment cmt"># Title</span>
38
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span>(<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:title</span>], <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'24px'</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:width</span>] <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>).<span class="ruby-identifier">round</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:subtitle</span>] <span class="ruby-operator">?</span> <span class="ruby-value">24</span> <span class="ruby-operator">:</span> <span class="ruby-value">32</span>), <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'middle'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:title</span>]
39
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span>(<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:subtitle</span>], <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'18px'</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:width</span>] <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>).<span class="ruby-identifier">round</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">34</span>, <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'middle'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:subtitle</span>]
40
+
41
+ <span class="ruby-comment cmt"># Lines</span>
42
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">g</span> <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'10px'</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
43
+ <span class="ruby-identifier">line_x1</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:left</span>] <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
44
+ <span class="ruby-identifier">line_x2</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:width</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:right</span>] <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
45
+
46
+ <span class="ruby-identifier">text_x</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:left</span>] <span class="ruby-operator">-</span> <span class="ruby-value">25</span>
47
+
48
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:height</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:bottom</span>] <span class="ruby-operator">+</span> <span class="ruby-value">4</span>), <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.5</span>
49
+
50
+ <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>((<span class="ruby-identifier">max</span> <span class="ruby-operator">/</span> <span class="ruby-value">10</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line_number</span><span class="ruby-operator">|</span>
51
+ <span class="ruby-identifier">y</span> = (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:top</span>] <span class="ruby-operator">+</span> (<span class="ruby-identifier">line_number</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dy</span>)).<span class="ruby-identifier">round</span>
52
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">line</span> <span class="ruby-identifier">:x1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:x2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'#666666'</span>
53
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">line_number</span> <span class="ruby-operator">*</span> <span class="ruby-value">10</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span> <span class="ruby-operator">+</span> <span class="ruby-value">4</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.5</span>
54
+
55
+ <span class="ruby-comment cmt"># Smaller Line</span>
56
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">line</span>(<span class="ruby-identifier">:x1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span> <span class="ruby-operator">+</span> (<span class="ruby-value">0</span><span class="ruby-value">.5</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dy</span>), <span class="ruby-identifier">:x2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span> <span class="ruby-operator">+</span> (<span class="ruby-value">0</span><span class="ruby-value">.5</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dy</span>), <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'#999999'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">55</span>
57
+ <span class="ruby-keyword kw">end</span>
58
+
59
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">max</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:top</span>] <span class="ruby-operator">+</span> <span class="ruby-value">4</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.5</span>
60
+ <span class="ruby-comment cmt"># Smaller Line</span>
61
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">line</span>(<span class="ruby-identifier">:x1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:top</span>] <span class="ruby-operator">+</span> (<span class="ruby-value">0</span><span class="ruby-value">.5</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dy</span>), <span class="ruby-identifier">:x2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:top</span>] <span class="ruby-operator">+</span> (<span class="ruby-value">0</span><span class="ruby-value">.5</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">dy</span>), <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'#999999'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">55</span>
62
+ <span class="ruby-keyword kw">end</span>
63
+
64
+ <span class="ruby-comment cmt"># Labels</span>
65
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">g</span> <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'end'</span>, <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'12px'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.3</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
66
+ <span class="ruby-ivar">@labels</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">label</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
67
+ <span class="ruby-identifier">x</span> = (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:left</span>] <span class="ruby-operator">+</span> (<span class="ruby-identifier">dx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">index</span>) <span class="ruby-operator">+</span> (<span class="ruby-identifier">dx</span> <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>)).<span class="ruby-identifier">round</span>
68
+ <span class="ruby-identifier">y</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:height</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:bottom</span>] <span class="ruby-operator">+</span> <span class="ruby-value">15</span>
69
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">label</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:transform</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;rotate(-45 #{x} #{y})&quot;</span>
70
+ <span class="ruby-keyword kw">end</span>
71
+ <span class="ruby-keyword kw">end</span>
72
+
73
+ <span class="ruby-comment cmt"># Bars</span>
74
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">g</span> <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'8px'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.3</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xml</span><span class="ruby-operator">|</span>
75
+ <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">data</span>, <span class="ruby-identifier">data_index</span><span class="ruby-operator">|</span>
76
+ <span class="ruby-identifier">data</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">data</span>)
77
+ <span class="ruby-identifier">width</span> = <span class="ruby-identifier">dx</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:padding</span>]
78
+ <span class="ruby-identifier">bar_width</span> = (<span class="ruby-identifier">width</span> <span class="ruby-operator">/</span> <span class="ruby-constant">Float</span>(<span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span>)).<span class="ruby-identifier">round</span>
79
+
80
+ <span class="ruby-identifier">x</span> = (<span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:left</span>] <span class="ruby-operator">+</span> (<span class="ruby-identifier">dx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">data_index</span>)).<span class="ruby-identifier">round</span>
81
+
82
+ <span class="ruby-comment cmt"># Rectangles</span>
83
+ <span class="ruby-identifier">data</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">number</span>, <span class="ruby-identifier">number_index</span><span class="ruby-operator">|</span>
84
+ <span class="ruby-identifier">color</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@colors</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:call</span>
85
+ <span class="ruby-ivar">@colors</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">data_index</span>, <span class="ruby-identifier">number_index</span>, <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span>)
86
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@colors</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
87
+ <span class="ruby-identifier">first</span> = <span class="ruby-ivar">@colors</span>[<span class="ruby-identifier">data_index</span> <span class="ruby-operator">%</span> (<span class="ruby-ivar">@colors</span>.<span class="ruby-identifier">size</span>)]
88
+
89
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">first</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Array</span>
90
+ <span class="ruby-identifier">first</span>[<span class="ruby-identifier">number_index</span> <span class="ruby-operator">%</span> (<span class="ruby-identifier">first</span>.<span class="ruby-identifier">size</span>)]
91
+ <span class="ruby-keyword kw">else</span>
92
+ <span class="ruby-identifier">first</span>
93
+ <span class="ruby-keyword kw">end</span>
94
+ <span class="ruby-keyword kw">else</span>
95
+ <span class="ruby-ivar">@colors</span>
96
+ <span class="ruby-keyword kw">end</span>
97
+
98
+ <span class="ruby-identifier">height</span> = ((<span class="ruby-identifier">dy</span> <span class="ruby-operator">/</span> <span class="ruby-value">10.0</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">number</span>).<span class="ruby-identifier">round</span>
99
+
100
+ <span class="ruby-identifier">bar_x</span> = (<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> ((<span class="ruby-identifier">dx</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">width</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>) <span class="ruby-operator">+</span> (<span class="ruby-identifier">number_index</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bar_width</span>)).<span class="ruby-identifier">round</span>
101
+ <span class="ruby-identifier">bar_y</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:height</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:bottom</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">height</span>
102
+
103
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">rect</span> <span class="ruby-identifier">:fill</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">color</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">color</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">bar_x</span>, <span class="ruby-identifier">:width</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">bar_width</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">bar_y</span>, <span class="ruby-identifier">:height</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">height</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
104
+ <span class="ruby-keyword kw">end</span>
105
+
106
+ <span class="ruby-comment cmt"># Text</span>
107
+ <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:bar_text</span>]
108
+ <span class="ruby-identifier">data</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">number</span>, <span class="ruby-identifier">number_index</span><span class="ruby-operator">|</span>
109
+ <span class="ruby-identifier">height</span> = ((<span class="ruby-identifier">dy</span> <span class="ruby-operator">/</span> <span class="ruby-value">10.0</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">number</span>).<span class="ruby-identifier">round</span>
110
+
111
+ <span class="ruby-identifier">bar_x</span> = (<span class="ruby-identifier">x</span> <span class="ruby-operator">+</span> ((<span class="ruby-identifier">dx</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">width</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>) <span class="ruby-operator">+</span> (<span class="ruby-identifier">number_index</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bar_width</span>)).<span class="ruby-identifier">round</span>
112
+ <span class="ruby-identifier">text_x</span> = (<span class="ruby-identifier">bar_x</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">bar_width</span> <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>)).<span class="ruby-identifier">round</span>
113
+
114
+ <span class="ruby-identifier">bar_y</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:viewbox</span>][<span class="ruby-identifier">:height</span>] <span class="ruby-operator">-</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:margin</span>][<span class="ruby-identifier">:bottom</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">height</span>
115
+ <span class="ruby-identifier">text_y</span> = <span class="ruby-identifier">bar_y</span> <span class="ruby-operator">-</span> <span class="ruby-value">3</span>
116
+
117
+ <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">number</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text_y</span>, <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'middle'</span>
118
+ <span class="ruby-keyword kw">end</span>
119
+ <span class="ruby-keyword kw">end</span>
120
+ <span class="ruby-keyword kw">end</span>
121
+ <span class="ruby-keyword kw">end</span>
122
+
123
+ <span class="ruby-comment cmt"># Yield in case they want to do some custom drawing and have a block ready</span>
124
+ <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-ivar">@options</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
125
+
126
+ <span class="ruby-keyword kw">end</span>
127
+ <span class="ruby-keyword kw">end</span>
128
+ <span class="ruby-keyword kw">end</span>
129
+
130
+ <span class="ruby-identifier">output</span>
131
+ <span class="ruby-keyword kw">end</span></pre>
132
+ </body>
133
+ </html>
@@ -0,0 +1 @@
1
+ Thu, 20 Aug 2009 16:27:09 -0400
@@ -0,0 +1,119 @@
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>File: lilygraph.rb</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="fileHeader">
50
+ <h1>lilygraph.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/lilygraph.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Thu Aug 20 16:27:03 -0400 2009</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <p>
73
+ This is the main graphing class used for generating svg graphs.
74
+ </p>
75
+ <table>
76
+ <tr><td valign="top">Author:</td><td>Christopher Giroir &lt;kelsin@valefor.com&gt;
77
+
78
+ </td></tr>
79
+ </table>
80
+
81
+ </div>
82
+
83
+ <div id="requires-list">
84
+ <h3 class="section-bar">Required files</h3>
85
+
86
+ <div class="name-list">
87
+ color&nbsp;&nbsp;
88
+ </div>
89
+ </div>
90
+
91
+ </div>
92
+
93
+
94
+ </div>
95
+
96
+
97
+ <!-- if includes -->
98
+
99
+ <div id="section">
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ <!-- if method_list -->
109
+
110
+
111
+ </div>
112
+
113
+
114
+ <div id="validator-badges">
115
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
116
+ </div>
117
+
118
+ </body>
119
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/Lilygraph.html">Lilygraph</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/lib/lilygraph_rb.html">lib/lilygraph.rb</a><br />
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,29 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/Lilygraph.html#M000001">new (Lilygraph)</a><br />
24
+ <a href="classes/Lilygraph.html#M000003">render (Lilygraph)</a><br />
25
+ <a href="classes/Lilygraph.html#M000002">update_options (Lilygraph)</a><br />
26
+ </div>
27
+ </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/lib/lilygraph_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -1,9 +1,17 @@
1
1
  # This is the main graphing class used for generating svg graphs.
2
2
  #
3
- # :author: Christopher Giroir <kelsin@valefor.com>
3
+ # Author:: Christopher Giroir <kelsin@valefor.com>
4
4
 
5
5
  require 'color'
6
6
 
7
+ # This is the main class to use if you want to create a graph!
8
+ #
9
+ # graph = Lilygraph.new(:title => "My Awesome Graph")
10
+ # graph.data = [1,2,3]
11
+ # graph.labels = ['One','Two','Three']
12
+ # graph.render
13
+ #
14
+ # This class outputs svg as a string once you call render.
7
15
  class Lilygraph
8
16
  # Default options for the initializer
9
17
  DEFAULT_OPTIONS = {
@@ -26,27 +34,58 @@ class Lilygraph
26
34
  # This is the data for the graph. It should be an array where every item is
27
35
  # either a number or an array of numbers.
28
36
  #
29
- # Examples:
30
- # For a simple bar graph: data=[1,2,3]
31
- # For a grouped bar graph: data=[[1,10],[2,20],[3,30]]
37
+ # For a simple bar graph:
38
+ # graph.data=[1,2,3]
39
+ # For a grouped bar graph:
40
+ # graph.data=[[1,10],[2,20],[3,30]]
32
41
  attr_accessor :data
42
+
43
+ # This allows you to set colors for the bars.
44
+ #
45
+ # If you just want a single color:
46
+ # graph.colors='#0000aa'
47
+ # If you want to make each bar (or bar group) different colors:
48
+ # graph.colors=['#aa0000','#00aa00','#0000aa']
49
+ # If you want every bar group to be the same, but each bar in the groups to have a different color
50
+ # graph.colors=[['#aa0000','#00aa00','#0000aa']]
51
+ # If you want to set every bar group color:
52
+ # graph.colors=[['#aa0000','#00aa00','#0000aa'],['#bb0000','#00bb00','#0000bb']]
53
+ # Last but not least you can set the color value to any object that responds to call (like a Proc). The proc takes four arguments.
54
+ # data_index: The index of the current bar (or group)
55
+ # number_index: The index of the current bar INSIDE of the current bar group (always 0 if you don't have grouped bars)
56
+ # data_size: total number of bar or groups.
57
+ # number_size: total number of bars in the current group (always 1 if you don't have bar groups)
58
+ #
59
+ # The default proc looks like:
60
+ # graph.colors=Proc.new do |data_index, number_index, data_size, number_size|
61
+ # Color::HSL.from_fraction(Float(data_index) / Float(data_size), 1.0, 0.4 + (Float(number_index) / Float(number_size) * 0.4)).to_rgb.html
62
+ # end
63
+ attr_accessor :colors
33
64
 
34
- # Returns a new graph creator with some default options and other options that you pass.
65
+ # Returns a new graph creator with some default options specified via a hash:
66
+ # height:: String to use as height parameter on the svg tag. Default is <tt>'100%'</tt>.
67
+ # width:: String to use as width parameter on the svg tag. Default is <tt>'100%'</tt>.
68
+ # indent:: Indent option to the XmlMarkup object. Defaults to <tt>2</tt>.
69
+ # padding:: Number of svg units in between two bars. Defaults to <tt>14</tt>.
70
+ # bar_text:: (Boolean) Whether or not to include the text labels above every bar. Defaults to +true+.
71
+ # viewbox:: Hash of <tt>:height</tt> and <tt>:width</tt> keys to use for the viewbox parameter of the svg tag. Defaults to <tt>{:height => 600, :width => 800}</tt>.
72
+ # margin:: Hash of margins to use for graph (in svg units). Defaults to <tt>{:top => 50, :left => 50, :right => 50, :bottom => 100}</tt>.
35
73
  #
36
- # The options has includes:
37
- # :height - String to use as height parameter on the svg tag. Default is '100%'.
38
- # :width - String to use as width parameter on the svg tag. Default is '100%'.
39
- # :indent - Indent option to the XmlMarkup object. Defaults to 2.
40
- # :padding - Number of svg units in between two bars.
41
- # :viewbox - Hash of :height and :width keys to use for the viewbox parameter of the svg tag. Defaults to { :height => 600, :width => 800 }.
42
- # :margin - Hash of margins to use for graph (in svg units). Defaults to { :top => 50, :left => 50, :right => 50, :bottom => 100 }.
74
+ # For example, this creates a graph with a title and different indent setting:
75
+ #
76
+ # graph = Lilygraph.new(:title => 'Testing a title', :indent => 4)
43
77
  def initialize(options = {})
44
78
  @options = DEFAULT_OPTIONS.merge(options)
45
79
  @data = []
46
80
  @labels = []
81
+
82
+ @colors = Proc.new do |data_index, number_index, data_size, number_size|
83
+ Color::HSL.from_fraction(Float(data_index) / Float(data_size), 1.0, 0.4 + (Float(number_index) / Float(number_size) * 0.4)).to_rgb.html
84
+ end
47
85
  end
48
86
 
49
- # Updates the graph options with items from the passed in hash
87
+ # Updates the graph options with items from the passed in hash. Please refer
88
+ # to new for a description of available options.
50
89
  def update_options(options = {})
51
90
  @options = @options.merge(options)
52
91
  end
@@ -55,6 +94,10 @@ class Lilygraph
55
94
  # order to add your own items to the graph. Your block is passed the XmlMarkup
56
95
  # object to use as well as the options hash in case you need to use some of
57
96
  # that data.
97
+ #
98
+ # graph.render do |xml|
99
+ # xml.text "Hello", :x => 5, :y => 25
100
+ # end
58
101
  def render
59
102
  output = ""
60
103
  xml = Builder::XmlMarkup.new(:target => output, :indent => @options[:indent])
@@ -125,13 +168,26 @@ class Lilygraph
125
168
 
126
169
  # Rectangles
127
170
  data.each_with_index do |number, number_index|
128
- color = Color::HSL.from_fraction(data_index * (1.0 / @data.size),1.0, 0.4 + (number_index * 0.2)).to_rgb
171
+ color = if @colors.respond_to? :call
172
+ @colors.call(data_index, number_index, @data.size, data.size)
173
+ elsif @colors.class == Array
174
+ first = @colors[data_index % (@colors.size)]
175
+
176
+ if first.class == Array
177
+ first[number_index % (first.size)]
178
+ else
179
+ first
180
+ end
181
+ else
182
+ @colors
183
+ end
184
+
129
185
  height = ((dy / 10.0) * number).round
130
186
 
131
187
  bar_x = (x + ((dx - width) / 2.0) + (number_index * bar_width)).round
132
188
  bar_y = @options[:viewbox][:height] - @options[:margin][:bottom] - height
133
189
 
134
- xml.rect :fill => color.html, :stroke => color.html, 'stroke-width' => 0, :x => bar_x, :width => bar_width, :y => bar_y, :height => height - 1
190
+ xml.rect :fill => color, :stroke => color, 'stroke-width' => 0, :x => bar_x, :width => bar_width, :y => bar_y, :height => height - 1
135
191
  end
136
192
 
137
193
  # Text
@@ -152,7 +208,7 @@ class Lilygraph
152
208
  end
153
209
 
154
210
  # Yield in case they want to do some custom drawing and have a block ready
155
- yield xml, @options if block_given?
211
+ yield(xml, @options) if block_given?
156
212
 
157
213
  end
158
214
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lilygraph}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christopher Giroir"]
12
- s.date = %q{2009-08-19}
12
+ s.date = %q{2009-08-20}
13
13
  s.description = %q{Lilygraph is a Ruby library for creating svg charts and graphs based on XmlBuilder.}
14
14
  s.email = %q{kelsin@valefor.com}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,17 @@ Gem::Specification.new do |s|
22
22
  "README",
23
23
  "Rakefile",
24
24
  "VERSION",
25
+ "doc/classes/Lilygraph.html",
26
+ "doc/classes/Lilygraph.src/M000001.html",
27
+ "doc/classes/Lilygraph.src/M000002.html",
28
+ "doc/classes/Lilygraph.src/M000003.html",
29
+ "doc/created.rid",
30
+ "doc/files/lib/lilygraph_rb.html",
31
+ "doc/fr_class_index.html",
32
+ "doc/fr_file_index.html",
33
+ "doc/fr_method_index.html",
34
+ "doc/index.html",
35
+ "doc/rdoc-style.css",
25
36
  "lib/lilygraph.rb",
26
37
  "lilygraph.gemspec"
27
38
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Kelsin-lilygraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Giroir
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-19 00:00:00 -07:00
12
+ date: 2009-08-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,6 +37,17 @@ files:
37
37
  - README
38
38
  - Rakefile
39
39
  - VERSION
40
+ - doc/classes/Lilygraph.html
41
+ - doc/classes/Lilygraph.src/M000001.html
42
+ - doc/classes/Lilygraph.src/M000002.html
43
+ - doc/classes/Lilygraph.src/M000003.html
44
+ - doc/created.rid
45
+ - doc/files/lib/lilygraph_rb.html
46
+ - doc/fr_class_index.html
47
+ - doc/fr_file_index.html
48
+ - doc/fr_method_index.html
49
+ - doc/index.html
50
+ - doc/rdoc-style.css
40
51
  - lib/lilygraph.rb
41
52
  - lilygraph.gemspec
42
53
  has_rdoc: false