lilygraph 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +0 -0
- data/README +0 -0
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/doc/classes/Lilygraph.html +298 -0
- data/doc/classes/Lilygraph.src/M000001.html +20 -0
- data/doc/classes/Lilygraph.src/M000002.html +18 -0
- data/doc/classes/Lilygraph.src/M000003.html +120 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/lilygraph_rb.html +119 -0
- data/doc/fr_class_index.html +27 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +29 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/lilygraph.rb +208 -0
- data/lilygraph.gemspec +57 -0
- metadata +82 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "lilygraph"
|
5
|
+
s.summary = "Lilygraph is a Ruby library for creating svg charts and graphs based on XmlBuilder."
|
6
|
+
s.description = "Lilygraph is a Ruby library for creating svg charts and graphs based on XmlBuilder."
|
7
|
+
s.email = "kelsin@valefor.com"
|
8
|
+
s.homepage = "http://github.com/Kelsin/lilygraph"
|
9
|
+
s.authors = ["Christopher Giroir"]
|
10
|
+
|
11
|
+
s.add_dependency("color-tools", ">= 1.3.0")
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.5
|
@@ -0,0 +1,298 @@
|
|
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 graph to use if you want to create a graph!
|
84
|
+
</p>
|
85
|
+
<pre>
|
86
|
+
graph = Lilygraph.new(:title => "My Awesome Graph")
|
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>
|
106
|
+
<a href="#M000003">render</a>
|
107
|
+
<a href="#M000002">update_options</a>
|
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 => '100%', :width => '100%', :indent => 2, :padding => 14, :bar_text => true, :viewbox => { :width => 800, :height => 600</td>
|
128
|
+
<td width="3em"> </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">data</td>
|
147
|
+
<td class="context-item-value"> [RW] </td>
|
148
|
+
<td class="context-item-desc">
|
149
|
+
This is the data for the graph. It should be an array where every item is
|
150
|
+
either a number or an array of numbers.
|
151
|
+
|
152
|
+
<p>
|
153
|
+
For a simple bar graph:
|
154
|
+
</p>
|
155
|
+
<pre>
|
156
|
+
graph.data=[1,2,3]
|
157
|
+
</pre>
|
158
|
+
<p>
|
159
|
+
For a grouped bar graph:
|
160
|
+
</p>
|
161
|
+
<pre>
|
162
|
+
graph.data=[[1,10],[2,20],[3,30]]
|
163
|
+
</pre>
|
164
|
+
</td>
|
165
|
+
</tr>
|
166
|
+
<tr class="top-aligned-row context-row">
|
167
|
+
<td class="context-item-name">labels</td>
|
168
|
+
<td class="context-item-value"> [RW] </td>
|
169
|
+
<td class="context-item-desc">
|
170
|
+
An array of labels to use on the y axis. Make sure you have the right
|
171
|
+
number of labels. The size of this array should = the size of the data
|
172
|
+
array.
|
173
|
+
|
174
|
+
</td>
|
175
|
+
</tr>
|
176
|
+
</table>
|
177
|
+
</div>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
<!-- if method_list -->
|
183
|
+
<div id="methods">
|
184
|
+
<h3 class="section-bar">Public Class methods</h3>
|
185
|
+
|
186
|
+
<div id="method-M000001" class="method-detail">
|
187
|
+
<a name="M000001"></a>
|
188
|
+
|
189
|
+
<div class="method-heading">
|
190
|
+
<a href="Lilygraph.src/M000001.html" target="Code" class="method-signature"
|
191
|
+
onclick="popupCode('Lilygraph.src/M000001.html');return false;">
|
192
|
+
<span class="method-name">new</span><span class="method-args">(options = {})</span>
|
193
|
+
</a>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div class="method-description">
|
197
|
+
<p>
|
198
|
+
Returns a <a href="Lilygraph.html#M000001">new</a> graph creator with some
|
199
|
+
default options specified via a hash:
|
200
|
+
</p>
|
201
|
+
<table>
|
202
|
+
<tr><td valign="top">height:</td><td>String to use as height parameter on the svg tag. Default is
|
203
|
+
<tt>‘100%’</tt>.
|
204
|
+
|
205
|
+
</td></tr>
|
206
|
+
<tr><td valign="top">width:</td><td>String to use as width parameter on the svg tag. Default is
|
207
|
+
<tt>‘100%’</tt>.
|
208
|
+
|
209
|
+
</td></tr>
|
210
|
+
<tr><td valign="top">indent:</td><td>Indent option to the XmlMarkup object. Defaults to <tt>2</tt>.
|
211
|
+
|
212
|
+
</td></tr>
|
213
|
+
<tr><td valign="top">padding:</td><td>Number of svg units in between two bars. Defaults to <tt>14</tt>.
|
214
|
+
|
215
|
+
</td></tr>
|
216
|
+
<tr><td valign="top">bar_text:</td><td>(Boolean) Whether or not to include the text labels above every bar.
|
217
|
+
Defaults to <tt>true</tt>.
|
218
|
+
|
219
|
+
</td></tr>
|
220
|
+
<tr><td valign="top">viewbox:</td><td>Hash of <tt>:height</tt> and <tt>:width</tt> keys to use for the viewbox
|
221
|
+
parameter of the svg tag. Defaults to <tt>{:height => 600, :width =>
|
222
|
+
800}</tt>.
|
223
|
+
|
224
|
+
</td></tr>
|
225
|
+
<tr><td valign="top">margin:</td><td>Hash of margins to use for graph (in svg units). Defaults to <tt>{:top
|
226
|
+
=> 50, :left => 50, :right => 50, :bottom => 100}</tt>.
|
227
|
+
|
228
|
+
</td></tr>
|
229
|
+
</table>
|
230
|
+
<p>
|
231
|
+
For example, this creates a graph with a title and different indent
|
232
|
+
setting:
|
233
|
+
</p>
|
234
|
+
<pre>
|
235
|
+
graph = Lilygraph.new(:title => 'Testing a title', :indent => 4)
|
236
|
+
</pre>
|
237
|
+
</div>
|
238
|
+
</div>
|
239
|
+
|
240
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
241
|
+
|
242
|
+
<div id="method-M000003" class="method-detail">
|
243
|
+
<a name="M000003"></a>
|
244
|
+
|
245
|
+
<div class="method-heading">
|
246
|
+
<a href="Lilygraph.src/M000003.html" target="Code" class="method-signature"
|
247
|
+
onclick="popupCode('Lilygraph.src/M000003.html');return false;">
|
248
|
+
<span class="method-name">render</span><span class="method-args">() {|xml, @options| ...}</span>
|
249
|
+
</a>
|
250
|
+
</div>
|
251
|
+
|
252
|
+
<div class="method-description">
|
253
|
+
<p>
|
254
|
+
This returns a string of the graph as an svg. You can pass in a block in
|
255
|
+
order to add your own items to the graph. Your block is passed the
|
256
|
+
XmlMarkup object to use as well as the options hash in case you need to use
|
257
|
+
some of that data.
|
258
|
+
</p>
|
259
|
+
<pre>
|
260
|
+
graph.render do |xml|
|
261
|
+
xml.text "Hello", :x => 5, :y => 25
|
262
|
+
end
|
263
|
+
</pre>
|
264
|
+
</div>
|
265
|
+
</div>
|
266
|
+
|
267
|
+
<div id="method-M000002" class="method-detail">
|
268
|
+
<a name="M000002"></a>
|
269
|
+
|
270
|
+
<div class="method-heading">
|
271
|
+
<a href="Lilygraph.src/M000002.html" target="Code" class="method-signature"
|
272
|
+
onclick="popupCode('Lilygraph.src/M000002.html');return false;">
|
273
|
+
<span class="method-name">update_options</span><span class="method-args">(options = {})</span>
|
274
|
+
</a>
|
275
|
+
</div>
|
276
|
+
|
277
|
+
<div class="method-description">
|
278
|
+
<p>
|
279
|
+
Updates the graph options with items from the passed in hash. Please refer
|
280
|
+
to <a href="Lilygraph.html#M000001">new</a> for a description of available
|
281
|
+
options.
|
282
|
+
</p>
|
283
|
+
</div>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
|
287
|
+
</div>
|
288
|
+
|
289
|
+
|
290
|
+
</div>
|
291
|
+
|
292
|
+
|
293
|
+
<div id="validator-badges">
|
294
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
295
|
+
</div>
|
296
|
+
|
297
|
+
</body>
|
298
|
+
</html>
|
@@ -0,0 +1,20 @@
|
|
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 55</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
|
+
<span class="ruby-keyword kw">end</span></pre>
|
19
|
+
</body>
|
20
|
+
</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 63</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,120 @@
|
|
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 75</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">""</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">></span> <span class="ruby-identifier">output</span>, <span class="ruby-identifier">:indent</span> =<span class="ruby-operator">></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">"-//W3C//DTD SVG 1.1//EN"</span>, <span class="ruby-value str">"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"</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">></span> <span class="ruby-node">"0 0 #{@options[:viewbox][:width]} #{@options[:viewbox][:height]}"</span>,
|
23
|
+
<span class="ruby-identifier">:width</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:width</span>], <span class="ruby-identifier">:height</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:height</span>],
|
24
|
+
<span class="ruby-identifier">:xmlns</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'http://www.w3.org/2000/svg'</span>, <span class="ruby-identifier">:version</span> =<span class="ruby-operator">></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">></span> <span class="ruby-value str">'black'</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'black'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'2'</span>,
|
27
|
+
<span class="ruby-value str">'font-family'</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'Helvetica, Arial, sans-serif'</span>, <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'10px'</span>, <span class="ruby-value str">'font-weight'</span> =<span class="ruby-operator">></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">></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">></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">></span> <span class="ruby-identifier">graph_width</span>,
|
32
|
+
<span class="ruby-identifier">:height</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">graph_height</span>,
|
33
|
+
<span class="ruby-identifier">:fill</span> =<span class="ruby-operator">></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">></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">></span> <span class="ruby-value str">'24px'</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">></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">></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">></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">></span> <span class="ruby-value str">'18px'</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">></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">></span> <span class="ruby-value">34</span>, <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">></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">></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">></span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></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">></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">></span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:x2</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">></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">></span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></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">></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">></span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">></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">></span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">></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">></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"><</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">></span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></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">></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">></span> <span class="ruby-identifier">line_x1</span>, <span class="ruby-identifier">:y1</span> =<span class="ruby-operator">></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">></span> <span class="ruby-identifier">line_x2</span>, <span class="ruby-identifier">:y2</span> =<span class="ruby-operator">></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">></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"><</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">></span> <span class="ruby-value str">'end'</span>, <span class="ruby-value str">'font-size'</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'12px'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">></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">></span> <span class="ruby-identifier">x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">:transform</span> =<span class="ruby-operator">></span> <span class="ruby-node">"rotate(-45 #{x} #{y})"</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">></span> <span class="ruby-value str">'8px'</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">></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-constant">Color</span><span class="ruby-operator">::</span><span class="ruby-constant">HSL</span>.<span class="ruby-identifier">from_fraction</span>(<span class="ruby-identifier">data_index</span> <span class="ruby-operator">*</span> (<span class="ruby-value">1.0</span> <span class="ruby-operator">/</span> <span class="ruby-ivar">@data</span>.<span class="ruby-identifier">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-identifier">number_index</span> <span class="ruby-operator">*</span> <span class="ruby-value">0</span><span class="ruby-value">.2</span>)).<span class="ruby-identifier">to_rgb</span>
|
85
|
+
<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>
|
86
|
+
|
87
|
+
<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>
|
88
|
+
<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>
|
89
|
+
|
90
|
+
<span class="ruby-identifier">xml</span>.<span class="ruby-identifier">rect</span> <span class="ruby-identifier">:fill</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">html</span>, <span class="ruby-identifier">:stroke</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">html</span>, <span class="ruby-value str">'stroke-width'</span> =<span class="ruby-operator">></span> <span class="ruby-value">0</span>, <span class="ruby-identifier">:x</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">bar_x</span>, <span class="ruby-identifier">:width</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">bar_width</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">bar_y</span>, <span class="ruby-identifier">:height</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">height</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
91
|
+
<span class="ruby-keyword kw">end</span>
|
92
|
+
|
93
|
+
<span class="ruby-comment cmt"># Text</span>
|
94
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:bar_text</span>]
|
95
|
+
<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>
|
96
|
+
<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>
|
97
|
+
|
98
|
+
<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>
|
99
|
+
<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>
|
100
|
+
|
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
|
+
<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>
|
103
|
+
|
104
|
+
<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">></span> <span class="ruby-identifier">text_x</span>, <span class="ruby-identifier">:y</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">text_y</span>, <span class="ruby-value str">'text-anchor'</span> =<span class="ruby-operator">></span> <span class="ruby-value str">'middle'</span>
|
105
|
+
<span class="ruby-keyword kw">end</span>
|
106
|
+
<span class="ruby-keyword kw">end</span>
|
107
|
+
<span class="ruby-keyword kw">end</span>
|
108
|
+
<span class="ruby-keyword kw">end</span>
|
109
|
+
|
110
|
+
<span class="ruby-comment cmt"># Yield in case they want to do some custom drawing and have a block ready</span>
|
111
|
+
<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>
|
112
|
+
|
113
|
+
<span class="ruby-keyword kw">end</span>
|
114
|
+
<span class="ruby-keyword kw">end</span>
|
115
|
+
<span class="ruby-keyword kw">end</span>
|
116
|
+
|
117
|
+
<span class="ruby-identifier">output</span>
|
118
|
+
<span class="ruby-keyword kw">end</span></pre>
|
119
|
+
</body>
|
120
|
+
</html>
|
data/doc/created.rid
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Wed, 19 Aug 2009 16:54:01 -0400
|