gerbilcharts 0.0.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +1 -0
- data/PostInstall.txt +1 -6
- data/README.txt +93 -0
- data/lib/gerbilcharts/charts/chart_base.rb +3 -2
- data/lib/gerbilcharts/charts/line_chart.rb +3 -0
- data/lib/gerbilcharts/surfaces/axis.rb +1 -1
- data/lib/gerbilcharts/surfaces/bar_surface.rb +1 -1
- data/lib/gerbilcharts/surfaces/chart.rb +5 -0
- data/lib/gerbilcharts/svgdc/svgdc.rb +2 -1
- data/lib/gerbilcharts/version.rb +2 -2
- data/test/test_render_string.rb +38 -0
- metadata +14 -15
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 0.0.5 2009-06-05
|
2
|
+
* Changes
|
3
|
+
* Support render_to_string to inline render in browser
|
4
|
+
* New test case for testing string rendering
|
5
|
+
* New sample demonstrates integration with a Ruby on Rails app
|
6
|
+
|
7
|
+
== 0.0.4 2008-11-10
|
8
|
+
* Changes
|
9
|
+
* Demonstrate tooltips
|
10
|
+
* Gradient style for line chart (need to make this an option)
|
11
|
+
|
1
12
|
== 0.0.3 2008-11-8
|
2
13
|
|
3
14
|
* Initial package as a gem
|
data/Manifest.txt
CHANGED
data/PostInstall.txt
CHANGED
data/README.txt
CHANGED
@@ -55,6 +55,57 @@ Assumes all models (data series) have values at discrete time points.
|
|
55
55
|
To view the chart:
|
56
56
|
* firefox /tmp/monthly_sales.svg
|
57
57
|
|
58
|
+
===Rails example
|
59
|
+
The most common use of gerbilcharts will be in a Rails application. Here is a guide to quickly get you on board. You can skip the first three steps if you already have a rails app up and running.
|
60
|
+
|
61
|
+
First install gerbilcharts
|
62
|
+
sudo gem install gerbilcharts
|
63
|
+
|
64
|
+
Generate a test app called gtest
|
65
|
+
rails generate gtest
|
66
|
+
|
67
|
+
Create a controller
|
68
|
+
cd gtest
|
69
|
+
ruby script/generate controller tgerbil
|
70
|
+
|
71
|
+
Copy the following code into app/controllers/tgerbil_controller.rb
|
72
|
+
|
73
|
+
|
74
|
+
require 'gerbilcharts'
|
75
|
+
|
76
|
+
class GerbtController < ApplicationController
|
77
|
+
|
78
|
+
# render inline to browser without using a temp file
|
79
|
+
def tgerb
|
80
|
+
|
81
|
+
# test sales figures of 3 sales people
|
82
|
+
# use a simple timeseries model
|
83
|
+
# output to string finally
|
84
|
+
mychart = GerbilCharts::Charts::LineChart.new( :width => 350, :height => 200, :style => 'brushmetal.css',
|
85
|
+
:circle_data_points => true )
|
86
|
+
|
87
|
+
mychart.modelgroup = GerbilCharts::Models::SimpleTimeSeriesModelGroup.new(
|
88
|
+
:title => "Sales figures",
|
89
|
+
:timeseries => (1..6).collect { |month| Time.local(2008,month) },
|
90
|
+
:models => [ ["Bruce", 1, 10, 18, 28, 80, 122],
|
91
|
+
["Rex" , 112,22, 45, 70, 218, 309],
|
92
|
+
["Buzo" , 0, 23, 25, 40, 18, 59]
|
93
|
+
]
|
94
|
+
)
|
95
|
+
|
96
|
+
send_data mychart.render_string, :disposition => 'inline', :type => 'image/svg+xml'
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
Start the web server
|
104
|
+
ruby script/server
|
105
|
+
|
106
|
+
|
107
|
+
Point to website and test out the chart at http://localhost:3000/tgerbil/tgerb
|
108
|
+
|
58
109
|
|
59
110
|
===Bucketizer example
|
60
111
|
This is a typical use of gerbilcharts. A number of timeseries data sources of various resolutions are bucketized uniformly and shown on a variety of charts. In this example, data points at varying intervals of approx 5 mins are collated into 15 min buckets using the BucketizedTimeSeriesGraphModel. This sample also shows the seperation of the data from the view. In the sample below, we switch the view from an ImpulseChart to a StackedAreaChart without touching the model.
|
@@ -126,6 +177,48 @@ To view the charts:
|
|
126
177
|
* firefox /tmp/daily_traffic.svg
|
127
178
|
* firefox /tmp/daily_traffic_stacked_area.svg
|
128
179
|
|
180
|
+
== Bucketizer rails example
|
181
|
+
Use the bucketizer if you want to present timeseries data at a lower resolution that that of the incoming stream. The sample code is shown below. Copy paste this code into a controller to test the bucketizer
|
182
|
+
|
183
|
+
|
184
|
+
require 'gerbilcharts'
|
185
|
+
|
186
|
+
class GerbtController < ApplicationController
|
187
|
+
|
188
|
+
# use the bucketized model only if we want the output to have a lower resolution
|
189
|
+
# than the incoming data
|
190
|
+
def tbucket
|
191
|
+
|
192
|
+
# create a model group, this houses the individual models
|
193
|
+
modelgroup = GerbilCharts::Models::GraphModelGroup.new("Price trends")
|
194
|
+
|
195
|
+
# bucketized models, we create one and add it to the group
|
196
|
+
bucket1 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new("Selling Price",60)
|
197
|
+
tbeg = Time.local( 1978, "jun", 5, 9, 10, 0, 0)
|
198
|
+
|
199
|
+
# generate some random values at random resolution between 5 and 30 seconds
|
200
|
+
# the timestamps of incoming data start from jun 5 9:10 AM :w
|
201
|
+
100.times do |c|
|
202
|
+
tbeg = tbeg + 5 + rand*30
|
203
|
+
bucket1.add tbeg, rand*1000
|
204
|
+
end
|
205
|
+
|
206
|
+
# add all models to the group , we will chart the group
|
207
|
+
modelgroup.add(bucket1)
|
208
|
+
|
209
|
+
# create a area chart
|
210
|
+
mychart = GerbilCharts::Charts::AreaChart.new( :width => 350, :height => 200,
|
211
|
+
:style => 'brushmetal.css')
|
212
|
+
|
213
|
+
# connect the model group to the chart
|
214
|
+
mychart.setmodelgroup(modelgroup)
|
215
|
+
|
216
|
+
send_data mychart.render_string, :disposition => 'inline', :type => 'image/svg+xml'
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
end
|
129
222
|
|
130
223
|
===Tooltips example
|
131
224
|
GerbilCharts can be interactive just like Flash charts. This is accomplished by a combination of SVG and
|
@@ -93,9 +93,10 @@ class ChartBase
|
|
93
93
|
end
|
94
94
|
|
95
95
|
# render string
|
96
|
-
def render_string
|
97
|
-
@renderopts.merge!( :string =>
|
96
|
+
def render_string
|
97
|
+
@renderopts.merge!( :string => "" )
|
98
98
|
render_base
|
99
|
+
@renderopts[:string]
|
99
100
|
end
|
100
101
|
|
101
102
|
# click chart title to go somewhere else
|
@@ -20,6 +20,9 @@ class LineChart < ChartBase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_chart_elements
|
23
|
+
|
24
|
+
# anchor (line surface)
|
25
|
+
@thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(192,192,192)"))
|
23
26
|
|
24
27
|
# other elements
|
25
28
|
@thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
|
@@ -26,7 +26,7 @@ class BarSurface < Surface
|
|
26
26
|
# see if the element spacing or width need to be adjusted to fit
|
27
27
|
nmodels = parent.modelgroup.count
|
28
28
|
delta = @bounds.width - (nmodels * (@element_width + @element_spacing) + @element_spacing)
|
29
|
-
p "delta = #{delta} width = #{@bounds.width}"
|
29
|
+
#p "delta = #{delta} width = #{@bounds.width}"
|
30
30
|
if delta < 0
|
31
31
|
delta_per_item = delta/(nmodels+1)
|
32
32
|
@element_width += delta_per_item
|
@@ -25,6 +25,11 @@ class Chart < GraphElement
|
|
25
25
|
@needslayout=false
|
26
26
|
end
|
27
27
|
|
28
|
+
# We search for the javascript code in the javascripts directory
|
29
|
+
# This works with Ruby on Rails applications, if you want to change it
|
30
|
+
# pass a :javascripts => { "file:///gerbil.js" => false }
|
31
|
+
# The second parameter says if you want the js inlined in the HTML.
|
32
|
+
#
|
28
33
|
def set_defaults
|
29
34
|
@javascripts = { "/javascripts/gerbil.js" => false, "/javascripts/prototype.js" => false }
|
30
35
|
end
|
@@ -209,6 +209,7 @@ class SVGDC
|
|
209
209
|
doc.instruct!
|
210
210
|
doc.declare! :DOCTYPE, :svg, :PUBLIC,"-//W3C//DTD SVG 1.1//EN","http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
|
211
211
|
|
212
|
+
|
212
213
|
render_to_frag(doc,opts)
|
213
214
|
|
214
215
|
# return the svg_string
|
@@ -225,7 +226,7 @@ class SVGDC
|
|
225
226
|
|
226
227
|
# synonym for render_to_file with no options
|
227
228
|
def render(opts={})
|
228
|
-
|
229
|
+
opts[:string]=render_to_string(opts) if opts[:string]
|
229
230
|
render_to_file(opts[:file],opts) if opts[:file]
|
230
231
|
render_to_frag(opts[:xfrag],opts) if opts[:xfrag]
|
231
232
|
end
|
data/lib/gerbilcharts/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
require 'trafgen'
|
4
|
+
|
5
|
+
# test if render to string works correctly
|
6
|
+
class TestRenderString < Test::Unit::TestCase
|
7
|
+
|
8
|
+
|
9
|
+
# test sales figures of 3 sales people
|
10
|
+
# use a simple timeseries model
|
11
|
+
# output to string finally
|
12
|
+
def test_string_render
|
13
|
+
|
14
|
+
mychart = GerbilCharts::Charts::LineChart.new( :width => 350, :height => 200, :style => 'brushmetal.css',
|
15
|
+
:circle_data_points => true )
|
16
|
+
|
17
|
+
modelgroup = GerbilCharts::Models::SimpleTimeSeriesModelGroup.new(
|
18
|
+
:title => "Sales figures",
|
19
|
+
:timeseries => (1..6).collect { |month| Time.local(2008,month) },
|
20
|
+
:models => [ ["Bruce", 1, 10, 18, 28, 80, 122],
|
21
|
+
["Rex" , 112,22, 45, 70, 218, 309],
|
22
|
+
["Buzo" , 0, 23, 25, 40, 18, 59]
|
23
|
+
]
|
24
|
+
)
|
25
|
+
|
26
|
+
mychart.modelgroup=modelgroup
|
27
|
+
|
28
|
+
strout = mychart.render_string
|
29
|
+
|
30
|
+
# a large enough string (basic test a large enough string generated)
|
31
|
+
assert strout.size > 1000
|
32
|
+
|
33
|
+
# the string SVG is present in the out (very basic test)
|
34
|
+
assert strout.match("SVG")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gerbilcharts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vivek Rajagopalan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-06-06 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.8.0
|
24
24
|
version:
|
25
25
|
description: SVG based charting library for timeseries data
|
26
26
|
email:
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- setup.rb
|
46
46
|
- test/trafgen.rb
|
47
47
|
- test/test_noob.rb
|
48
|
+
- test/test_render_string.rb
|
48
49
|
- test/test_helper.rb
|
49
50
|
- lib/gerbilcharts.rb
|
50
51
|
- lib/gerbilcharts/version.rb
|
@@ -113,13 +114,10 @@ files:
|
|
113
114
|
- lib/gerbilcharts/svgdc/svg_text.rb
|
114
115
|
has_rdoc: true
|
115
116
|
homepage: http://gerbilcharts.rubyforge.org
|
117
|
+
licenses: []
|
118
|
+
|
116
119
|
post_install_message: |+
|
117
|
-
|
118
|
-
For more information on gerbilcharts, see http://gerbilcharts.rubyforge.org
|
119
|
-
|
120
|
-
NOTE: Change this information in PostInstall.txt
|
121
|
-
You can also delete it if you don't want it.
|
122
|
-
|
120
|
+
Thanks for installing GerbilCharts SVG
|
123
121
|
|
124
122
|
rdoc_options:
|
125
123
|
- --main
|
@@ -141,16 +139,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
139
|
requirements: []
|
142
140
|
|
143
141
|
rubyforge_project: gerbilcharts
|
144
|
-
rubygems_version: 1.3.
|
142
|
+
rubygems_version: 1.3.4
|
145
143
|
signing_key:
|
146
|
-
specification_version:
|
144
|
+
specification_version: 3
|
147
145
|
summary: SVG based charting library for timeseries data
|
148
146
|
test_files:
|
149
|
-
- test/test_charts.rb
|
150
|
-
- test/test_ranges.rb
|
151
147
|
- test/test_gerbilcharts.rb
|
152
|
-
- test/
|
148
|
+
- test/test_ranges.rb
|
149
|
+
- test/test_helper.rb
|
153
150
|
- test/test_svgdc.rb
|
151
|
+
- test/test_noob.rb
|
152
|
+
- test/test_render_string.rb
|
154
153
|
- test/test_models.rb
|
155
|
-
- test/
|
154
|
+
- test/test_charts.rb
|
156
155
|
- test/test_Scratch.rb
|