gerbilcharts 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/License.txt +21 -0
- data/Manifest.txt +75 -0
- data/PostInstall.txt +7 -0
- data/README.txt +174 -0
- data/Rakefile +4 -0
- data/lib/gerbilcharts.rb +18 -0
- data/lib/gerbilcharts/charts.rb +16 -0
- data/lib/gerbilcharts/charts/area_chart.rb +36 -0
- data/lib/gerbilcharts/charts/bar_chart.rb +33 -0
- data/lib/gerbilcharts/charts/bar_chart_compact.rb +26 -0
- data/lib/gerbilcharts/charts/chart_base.rb +123 -0
- data/lib/gerbilcharts/charts/impulse_chart.rb +30 -0
- data/lib/gerbilcharts/charts/line_chart.rb +35 -0
- data/lib/gerbilcharts/charts/stacked_area_chart.rb +31 -0
- data/lib/gerbilcharts/models.rb +19 -0
- data/lib/gerbilcharts/models/bucketized_timeseries_graph_model.rb +138 -0
- data/lib/gerbilcharts/models/discrete_time_range.rb +63 -0
- data/lib/gerbilcharts/models/graph_model.rb +89 -0
- data/lib/gerbilcharts/models/graph_model_group.rb +240 -0
- data/lib/gerbilcharts/models/monotonous_graph_model.rb +192 -0
- data/lib/gerbilcharts/models/presets.rb +94 -0
- data/lib/gerbilcharts/models/raw_range.rb +68 -0
- data/lib/gerbilcharts/models/round_range.rb +104 -0
- data/lib/gerbilcharts/models/round_time_range.rb +105 -0
- data/lib/gerbilcharts/models/sampled_timeseries_graph_model.rb +80 -0
- data/lib/gerbilcharts/models/simple_timeseries_model_group.rb +68 -0
- data/lib/gerbilcharts/models/time_series_graph_model.rb +34 -0
- data/lib/gerbilcharts/public/brushmetal.css +197 -0
- data/lib/gerbilcharts/public/gerbil.js +327 -0
- data/lib/gerbilcharts/surfaces.rb +32 -0
- data/lib/gerbilcharts/surfaces/area_surface.rb +46 -0
- data/lib/gerbilcharts/surfaces/axis.rb +31 -0
- data/lib/gerbilcharts/surfaces/bar_surface.rb +62 -0
- data/lib/gerbilcharts/surfaces/basic_grid.rb +17 -0
- data/lib/gerbilcharts/surfaces/chart.rb +132 -0
- data/lib/gerbilcharts/surfaces/graph_element.rb +170 -0
- data/lib/gerbilcharts/surfaces/grid.rb +38 -0
- data/lib/gerbilcharts/surfaces/horizontal_axis.rb +32 -0
- data/lib/gerbilcharts/surfaces/horizontal_name_axis.rb +28 -0
- data/lib/gerbilcharts/surfaces/horizontal_time_axis.rb +25 -0
- data/lib/gerbilcharts/surfaces/impulse_surface.rb +47 -0
- data/lib/gerbilcharts/surfaces/legend.rb +59 -0
- data/lib/gerbilcharts/surfaces/line_surface.rb +53 -0
- data/lib/gerbilcharts/surfaces/mark_band.rb +17 -0
- data/lib/gerbilcharts/surfaces/panel.rb +17 -0
- data/lib/gerbilcharts/surfaces/pie_surface.rb +16 -0
- data/lib/gerbilcharts/surfaces/rect.rb +86 -0
- data/lib/gerbilcharts/surfaces/stacked_area_surface.rb +66 -0
- data/lib/gerbilcharts/surfaces/stacked_grid.rb +15 -0
- data/lib/gerbilcharts/surfaces/surface.rb +20 -0
- data/lib/gerbilcharts/surfaces/surface_background.rb +13 -0
- data/lib/gerbilcharts/surfaces/title_panel.rb +44 -0
- data/lib/gerbilcharts/surfaces/tracker.rb +62 -0
- data/lib/gerbilcharts/surfaces/vertical_axis.rb +46 -0
- data/lib/gerbilcharts/svgdc.rb +22 -0
- data/lib/gerbilcharts/svgdc/filters.rb +40 -0
- data/lib/gerbilcharts/svgdc/presentation_attributes.rb +50 -0
- data/lib/gerbilcharts/svgdc/svg_circle.rb +22 -0
- data/lib/gerbilcharts/svgdc/svg_custom_win.rb +36 -0
- data/lib/gerbilcharts/svgdc/svg_element.rb +87 -0
- data/lib/gerbilcharts/svgdc/svg_line.rb +26 -0
- data/lib/gerbilcharts/svgdc/svg_polygon.rb +34 -0
- data/lib/gerbilcharts/svgdc/svg_polyline.rb +27 -0
- data/lib/gerbilcharts/svgdc/svg_rect.rb +29 -0
- data/lib/gerbilcharts/svgdc/svg_shape.rb +10 -0
- data/lib/gerbilcharts/svgdc/svg_text.rb +21 -0
- data/lib/gerbilcharts/svgdc/svg_win.rb +52 -0
- data/lib/gerbilcharts/svgdc/svgdc.rb +335 -0
- data/lib/gerbilcharts/svgdc/transformations.rb +66 -0
- data/lib/gerbilcharts/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/test_Scratch.rb +21 -0
- data/test/test_charts.rb +119 -0
- data/test/test_gerbilcharts.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/test/test_models.rb +118 -0
- data/test/test_noob.rb +81 -0
- data/test/test_ranges.rb +135 -0
- data/test/test_svgdc.rb +221 -0
- data/test/trafgen.rb +25 -0
- metadata +156 -0
data/History.txt
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
== 0.0.3 2008-11-8
|
2
|
+
|
3
|
+
* Initial package as a gem
|
4
|
+
* Thanks to newgem / hoe we now have GerbilCharts as a gem
|
5
|
+
* Cleaned and refactored svg,models,surfaces,charts
|
6
|
+
* Tests written for charts
|
7
|
+
|
8
|
+
== 0.0.1 2008-10-14
|
9
|
+
|
10
|
+
* 1 major enhancement:
|
11
|
+
* Initial release
|
data/License.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2008 Vivek Rajagopalan
|
2
|
+
Copyright (c) 2008 Unleash Networks Pvt Ltd
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
setup.rb
|
8
|
+
test/trafgen.rb
|
9
|
+
test/test_noob.rb
|
10
|
+
test/test_helper.rb
|
11
|
+
lib/gerbilcharts.rb
|
12
|
+
lib/gerbilcharts/version.rb
|
13
|
+
lib/gerbilcharts/models.rb
|
14
|
+
lib/gerbilcharts/svgdc.rb
|
15
|
+
lib/gerbilcharts/surfaces.rb
|
16
|
+
lib/gerbilcharts/charts.rb
|
17
|
+
lib/gerbilcharts/public/brushmetal.css
|
18
|
+
lib/gerbilcharts/public/gerbil.js
|
19
|
+
lib/gerbilcharts/models/bucketized_timeseries_graph_model.rb
|
20
|
+
lib/gerbilcharts/models/graph_model_group.rb
|
21
|
+
lib/gerbilcharts/models/graph_model.rb
|
22
|
+
lib/gerbilcharts/models/monotonous_graph_model.rb
|
23
|
+
lib/gerbilcharts/models/presets.rb
|
24
|
+
lib/gerbilcharts/models/raw_range.rb
|
25
|
+
lib/gerbilcharts/models/round_range.rb
|
26
|
+
lib/gerbilcharts/models/round_time_range.rb
|
27
|
+
lib/gerbilcharts/models/discrete_time_range.rb
|
28
|
+
lib/gerbilcharts/models/sampled_timeseries_graph_model.rb
|
29
|
+
lib/gerbilcharts/models/time_series_graph_model.rb
|
30
|
+
lib/gerbilcharts/models/simple_timeseries_model_group.rb
|
31
|
+
lib/gerbilcharts/surfaces/area_surface.rb
|
32
|
+
lib/gerbilcharts/surfaces/axis.rb
|
33
|
+
lib/gerbilcharts/surfaces/bar_surface.rb
|
34
|
+
lib/gerbilcharts/surfaces/basic_grid.rb
|
35
|
+
lib/gerbilcharts/surfaces/chart.rb
|
36
|
+
lib/gerbilcharts/surfaces/graph_element.rb
|
37
|
+
lib/gerbilcharts/surfaces/grid.rb
|
38
|
+
lib/gerbilcharts/surfaces/horizontal_axis.rb
|
39
|
+
lib/gerbilcharts/surfaces/horizontal_name_axis.rb
|
40
|
+
lib/gerbilcharts/surfaces/horizontal_time_axis.rb
|
41
|
+
lib/gerbilcharts/surfaces/impulse_surface.rb
|
42
|
+
lib/gerbilcharts/surfaces/legend.rb
|
43
|
+
lib/gerbilcharts/surfaces/line_surface.rb
|
44
|
+
lib/gerbilcharts/surfaces/mark_band.rb
|
45
|
+
lib/gerbilcharts/surfaces/panel.rb
|
46
|
+
lib/gerbilcharts/surfaces/pie_surface.rb
|
47
|
+
lib/gerbilcharts/surfaces/rect.rb
|
48
|
+
lib/gerbilcharts/surfaces/stacked_area_surface.rb
|
49
|
+
lib/gerbilcharts/surfaces/stacked_grid.rb
|
50
|
+
lib/gerbilcharts/surfaces/surface_background.rb
|
51
|
+
lib/gerbilcharts/surfaces/surface.rb
|
52
|
+
lib/gerbilcharts/surfaces/title_panel.rb
|
53
|
+
lib/gerbilcharts/surfaces/tracker.rb
|
54
|
+
lib/gerbilcharts/surfaces/vertical_axis.rb
|
55
|
+
lib/gerbilcharts/charts/area_chart.rb
|
56
|
+
lib/gerbilcharts/charts/bar_chart_compact.rb
|
57
|
+
lib/gerbilcharts/charts/bar_chart.rb
|
58
|
+
lib/gerbilcharts/charts/chart_base.rb
|
59
|
+
lib/gerbilcharts/charts/impulse_chart.rb
|
60
|
+
lib/gerbilcharts/charts/line_chart.rb
|
61
|
+
lib/gerbilcharts/charts/stacked_area_chart.rb
|
62
|
+
lib/gerbilcharts/svgdc/svgdc.rb
|
63
|
+
lib/gerbilcharts/svgdc/svg_element.rb
|
64
|
+
lib/gerbilcharts/svgdc/filters.rb
|
65
|
+
lib/gerbilcharts/svgdc/transformations.rb
|
66
|
+
lib/gerbilcharts/svgdc/presentation_attributes.rb
|
67
|
+
lib/gerbilcharts/svgdc/svg_win.rb
|
68
|
+
lib/gerbilcharts/svgdc/svg_custom_win.rb
|
69
|
+
lib/gerbilcharts/svgdc/svg_shape.rb
|
70
|
+
lib/gerbilcharts/svgdc/svg_circle.rb
|
71
|
+
lib/gerbilcharts/svgdc/svg_line.rb
|
72
|
+
lib/gerbilcharts/svgdc/svg_polygon.rb
|
73
|
+
lib/gerbilcharts/svgdc/svg_polyline.rb
|
74
|
+
lib/gerbilcharts/svgdc/svg_rect.rb
|
75
|
+
lib/gerbilcharts/svgdc/svg_text.rb
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
= gerbilcharts
|
2
|
+
|
3
|
+
* http://gerbilcharts.rubyforge.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
SVG based charting library especially suited for timeseries data.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Many predefined models
|
12
|
+
* Many chart types
|
13
|
+
* Customize via stylesheets instead of calls to setFont, setLineStyle, setColor etc
|
14
|
+
* Interactive show tooltips, handle clicks on chart objects
|
15
|
+
* Ajax enabled. gerbil.js allows each chart to autoupdate itself with new SVG elements.
|
16
|
+
|
17
|
+
Known issues :
|
18
|
+
* Requires a browser that can handle SVG such as Firefox/Opera.
|
19
|
+
* IE + Adobe SVG Viewer works but has some problems w/ Ajax
|
20
|
+
* Still needs some work on negative numbers
|
21
|
+
* Needs better min/max/avg plotting on bucketized data
|
22
|
+
|
23
|
+
===Note on stylesheets
|
24
|
+
GerbilCharts uses stylesheets to customize appearances of almost all visual
|
25
|
+
elements (colors, fonts, line strokes, fills). You can use the supplied
|
26
|
+
stylesheet (eg, brushmetal.css) or derive your own from it. GerbilCharts
|
27
|
+
searches for stylesheets in the working directory and the public directory of
|
28
|
+
the gerbilcharts gem.
|
29
|
+
|
30
|
+
== SYNOPSIS:
|
31
|
+
|
32
|
+
===Simple timeseries example
|
33
|
+
Assumes all models (data series) have values at discrete time points.
|
34
|
+
|
35
|
+
require 'rubygems'
|
36
|
+
gem 'gerbilcharts'
|
37
|
+
require 'gerbilcharts'
|
38
|
+
|
39
|
+
# test sales figures of 3 sales people
|
40
|
+
# use a simple timeseries model
|
41
|
+
mychart = GerbilCharts::Charts::LineChart.new( :width => 350, :height => 200, :style => 'brushmetal.css',
|
42
|
+
:circle_data_points => true )
|
43
|
+
|
44
|
+
modelgroup = GerbilCharts::Models::SimpleTimeSeriesModelGroup.new(
|
45
|
+
:title => "Sales figures",
|
46
|
+
:timeseries => (1..6).collect { |month| Time.local(2008,month) },
|
47
|
+
:models => [ ["Bruce", 1, 10, 18, 28, 80, 122],
|
48
|
+
["Rex" , 112,22, 45, 70, 218, 309],
|
49
|
+
["Buzo" , 0, 23, 25, 40, 18, 59]
|
50
|
+
]
|
51
|
+
)
|
52
|
+
mychart.modelgroup=modelgroup
|
53
|
+
mychart.render('/tmp/monthly_sales.svg')
|
54
|
+
|
55
|
+
To view the chart:
|
56
|
+
* firefox /tmp/monthly_sales.svg
|
57
|
+
|
58
|
+
|
59
|
+
===Bucketizer example
|
60
|
+
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.
|
61
|
+
|
62
|
+
require 'rubygems'
|
63
|
+
gem 'gerbilcharts'
|
64
|
+
require 'gerbilcharts'
|
65
|
+
|
66
|
+
# Helper class to generate time series data for test purposes
|
67
|
+
class TimeSeriesDataGenerator
|
68
|
+
|
69
|
+
attr_reader :tuples_array
|
70
|
+
|
71
|
+
# allows you to generate controlled random data
|
72
|
+
# tm_from, tm_to = start,end time (a Time object)
|
73
|
+
# avg_resolution_secs = generate a sample approx this many seconds. Varies randomly +/-25%
|
74
|
+
# max,min = max and min value
|
75
|
+
def initialize(tm_from, tm_to, avg_resolution_secs, min_val, max_val)
|
76
|
+
@tuples_array=[]
|
77
|
+
tm_tmp = tm_from
|
78
|
+
|
79
|
+
while tm_tmp < tm_to
|
80
|
+
@tuples_array << [ tm_tmp, min_val + (max_val - min_val)*rand ]
|
81
|
+
tm_tmp = tm_tmp + avg_resolution_secs *( 1 + (rand-0.5)/4)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# iterator
|
86
|
+
def each_tuple
|
87
|
+
@tuples_array.each do |t,v|
|
88
|
+
yield t,v
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# create an impulse chart 450x200 using the supplied brushmetal theme
|
95
|
+
mychart = GerbilCharts::Charts::ImpulseChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
96
|
+
|
97
|
+
# generate traffic sample 1 (eth0) at approx 5 min intervals and feed into a bucketizer model of 15 min
|
98
|
+
tend = Time.now
|
99
|
+
tbegin = tend - 3600*24
|
100
|
+
model1 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new( "eth0", 900 )
|
101
|
+
TimeSeriesDataGenerator.new(tbegin,tend,300,200000, 6000000).each_tuple do |t,v|
|
102
|
+
model1.add(t,v)
|
103
|
+
end
|
104
|
+
|
105
|
+
# generate traffic sample 2(wan1) at approx 5 min intervals and feed into a bucketizer model of 15 min
|
106
|
+
model2 = GerbilCharts::Models::BucketizedTimeSeriesGraphModel.new( "wan1", 900 )
|
107
|
+
TimeSeriesDataGenerator.new(tbegin,tend,300,500000, 2000000).each_tuple do |t,v|
|
108
|
+
model2.add(t,v)
|
109
|
+
end
|
110
|
+
|
111
|
+
# add these models to a modelgroup and render it
|
112
|
+
modelgroup = GerbilCharts::Models::GraphModelGroup.new( "External Traffic")
|
113
|
+
modelgroup.add model1
|
114
|
+
modelgroup.add model2
|
115
|
+
mychart.modelgroup=modelgroup
|
116
|
+
mychart.render('/tmp/daily_traffic.svg')
|
117
|
+
|
118
|
+
# attach the same model to a stacked area chart and show it
|
119
|
+
# this demonstrates how the views can be changed dynamically
|
120
|
+
|
121
|
+
mysachart = GerbilCharts::Charts::StackedAreaChart.new( :width => 450, :height => 200, :style => 'brushmetal.css')
|
122
|
+
mysachart.modelgroup=modelgroup
|
123
|
+
mysachart.render('/tmp/daily_traffic_stacked_area.svg')
|
124
|
+
|
125
|
+
To view the charts:
|
126
|
+
* firefox /tmp/daily_traffic.svg
|
127
|
+
* firefox /tmp/daily_traffic_stacked_area.svg
|
128
|
+
|
129
|
+
|
130
|
+
===Tooltips example
|
131
|
+
GerbilCharts can be interactive just like Flash charts. This is accomplished by a combination of SVG and
|
132
|
+
Javascript. The Javascript is packaged in the file gerbil.js (requires prototype.js)
|
133
|
+
|
134
|
+
Todo: A sample please (extract from Web Trisul)
|
135
|
+
|
136
|
+
===Time selector example
|
137
|
+
You can even select time intervals from the SVG using gerbil.js.
|
138
|
+
|
139
|
+
Todo: A sample please (extract from Web Trisul)
|
140
|
+
|
141
|
+
|
142
|
+
== REQUIREMENTS:
|
143
|
+
|
144
|
+
* builder gem
|
145
|
+
|
146
|
+
|
147
|
+
== INSTALL:
|
148
|
+
|
149
|
+
* sudo gem install gerbilcharts
|
150
|
+
|
151
|
+
== LICENSE:
|
152
|
+
|
153
|
+
(The MIT License)
|
154
|
+
|
155
|
+
Copyright (c) 2008 Vivek Rajagopalan (vivek at unleashnetworks )
|
156
|
+
|
157
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
158
|
+
a copy of this software and associated documentation files (the
|
159
|
+
'Software'), to deal in the Software without restriction, including
|
160
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
161
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
162
|
+
permit persons to whom the Software is furnished to do so, subject to
|
163
|
+
the following conditions:
|
164
|
+
|
165
|
+
The above copyright notice and this permission notice shall be
|
166
|
+
included in all copies or substantial portions of the Software.
|
167
|
+
|
168
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
169
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
170
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
171
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
172
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
173
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
174
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/gerbilcharts.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
# =GerbilCharts
|
5
|
+
#
|
6
|
+
# Time Series Ajax Enabled Charting
|
7
|
+
#
|
8
|
+
# Author:: Vivek Rajagopalan
|
9
|
+
# Date:: 28 Oct 2008
|
10
|
+
module GerbilCharts
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
|
15
|
+
require 'gerbilcharts/models'
|
16
|
+
require 'gerbilcharts/svgdc'
|
17
|
+
require 'gerbilcharts/surfaces'
|
18
|
+
require 'gerbilcharts/charts'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# = GerbilCharts charts
|
2
|
+
#
|
3
|
+
# Predefined charts. We have put together various components and
|
4
|
+
# created ready to use charts ! You can also create your own charts by
|
5
|
+
# combining elements like surfaces, axis, legends, titles, markers, etc
|
6
|
+
#
|
7
|
+
|
8
|
+
module GerbilCharts::Charts;end;
|
9
|
+
|
10
|
+
require 'gerbilcharts/charts/chart_base'
|
11
|
+
require 'gerbilcharts/charts/area_chart'
|
12
|
+
require 'gerbilcharts/charts/bar_chart_compact'
|
13
|
+
require 'gerbilcharts/charts/bar_chart'
|
14
|
+
require 'gerbilcharts/charts/impulse_chart'
|
15
|
+
require 'gerbilcharts/charts/line_chart'
|
16
|
+
require 'gerbilcharts/charts/stacked_area_chart'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module GerbilCharts::Charts
|
2
|
+
|
3
|
+
|
4
|
+
# =Area Chart
|
5
|
+
# Draws each model in a shaded area.
|
6
|
+
# We use a transparency to show hidden models. Not the best looking, but has its uses.
|
7
|
+
#
|
8
|
+
class AreaChart < ChartBase
|
9
|
+
|
10
|
+
def initialize(opt={})
|
11
|
+
super(opt)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_chart_elements
|
15
|
+
|
16
|
+
# anchor (line surface)
|
17
|
+
@thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(224,224,224)"))
|
18
|
+
|
19
|
+
# other elements
|
20
|
+
@thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
|
21
|
+
@thechart.add_child(GerbilCharts::Surfaces::BasicGrid.new(:orient => ORIENT_OVERLAY))
|
22
|
+
@thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30))
|
23
|
+
@thechart.add_child(GerbilCharts::Surfaces::AreaSurface.new(:orient => ORIENT_OVERLAY),:anchor => true)
|
24
|
+
@thechart.add_child(GerbilCharts::Surfaces::Legend.new(:orient=> ORIENT_OVERLAY, :dim => 100))
|
25
|
+
@thechart.add_child(GerbilCharts::Surfaces::VerticalAxis.new(:orient => ORIENT_WEST, :dim => 40 ))
|
26
|
+
@thechart.add_child(GerbilCharts::Surfaces::HorizontalTimeAxis.new(:orient => ORIENT_SOUTH, :dim => 25 ))
|
27
|
+
|
28
|
+
# optional features
|
29
|
+
if @feature_timetracker
|
30
|
+
@thechart.add_child(GerbilCharts::Surfaces::Tracker.new(:orient => ORIENT_SOUTH, :dim => 10 ))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module GerbilCharts::Charts
|
2
|
+
|
3
|
+
# =Bar Chart
|
4
|
+
# A standard bar chart.
|
5
|
+
# The latest values of each model is presented as a separate bar.
|
6
|
+
#
|
7
|
+
class BarChart < ChartBase
|
8
|
+
|
9
|
+
attr_reader :staggerlabels
|
10
|
+
|
11
|
+
def initialize(opt={})
|
12
|
+
super(opt)
|
13
|
+
|
14
|
+
@staggerlabels = 2
|
15
|
+
@staggerlabels = opt[:stagger] if opt[:stagger]
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_chart_elements
|
19
|
+
|
20
|
+
# anchor (line surface)
|
21
|
+
@thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(224,224,224)"))
|
22
|
+
|
23
|
+
# other elements
|
24
|
+
@thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
|
25
|
+
@thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30, :just => :right))
|
26
|
+
@thechart.add_child(GerbilCharts::Surfaces::BarSurface.new(:orient => ORIENT_OVERLAY), :anchor => true)
|
27
|
+
@thechart.add_child(GerbilCharts::Surfaces::VerticalAxis.new(:orient => ORIENT_WEST, :dim => 40 ))
|
28
|
+
@thechart.add_child(GerbilCharts::Surfaces::HorizontalNameAxis.new(:orient => ORIENT_SOUTH, :dim => (15 * @staggerlabels.to_i), :stagger => @staggerlabels))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GerbilCharts::Charts
|
2
|
+
|
3
|
+
# =Compact bar chart
|
4
|
+
# Tighter layout than a regular bar chart.
|
5
|
+
#
|
6
|
+
class BarChartCompact < ChartBase
|
7
|
+
|
8
|
+
def initialize(opt={})
|
9
|
+
super(opt)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_chart_elements
|
13
|
+
|
14
|
+
# anchor (line surface)
|
15
|
+
@thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(224,224,224)"))
|
16
|
+
|
17
|
+
# other elements
|
18
|
+
@thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
|
19
|
+
@thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30, :just => :right))
|
20
|
+
@thechart.add_child(GerbilCharts::Surfaces::BarSurface.new(:orient => ORIENT_OVERLAY),:anchor => true)
|
21
|
+
@thechart.add_child(GerbilCharts::Surfaces::HorizontalNameAxis.new(:orient => ORIENT_SOUTH, :dim => 30, :stagger => 2 ))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
module GerbilCharts::Charts
|
2
|
+
|
3
|
+
# =Chart base - sets up a container for surfaces
|
4
|
+
#
|
5
|
+
# You can put together various chart elements and create your own
|
6
|
+
# chart types. In fact, all the charts in this module are nothing
|
7
|
+
# but a composition of various surfaces
|
8
|
+
#
|
9
|
+
# The logic goes something like this :
|
10
|
+
# 1. A reddish gradient background
|
11
|
+
# 2. A stacked area surface to represent our data
|
12
|
+
# 3. Title overlay
|
13
|
+
# 4. Vertical labels on WEST
|
14
|
+
# 5. Horiz labels on SOUTH
|
15
|
+
# 6. Legend on EAST
|
16
|
+
#
|
17
|
+
# *A note on stylesheets*
|
18
|
+
#
|
19
|
+
# GerbilCharts uses a color scheme from a stylesheet.
|
20
|
+
# The stylesheets contain the coloring for each model.
|
21
|
+
class ChartBase
|
22
|
+
|
23
|
+
|
24
|
+
# orientations (same as Surfaces::)
|
25
|
+
ORIENT_NORTH=1
|
26
|
+
ORIENT_SOUTH=2
|
27
|
+
ORIENT_EAST=3
|
28
|
+
ORIENT_WEST=4
|
29
|
+
ORIENT_NORTHEAST=5
|
30
|
+
ORIENT_NORTHWEST=6
|
31
|
+
ORIENT_SOUTHEAST=7
|
32
|
+
ORIENT_SOUTHWEST=8
|
33
|
+
ORIENT_OVERLAY=9
|
34
|
+
|
35
|
+
|
36
|
+
attr_reader :thechart
|
37
|
+
attr_reader :renderopts
|
38
|
+
attr_reader :feature_timetracker
|
39
|
+
|
40
|
+
def initialize(opt={})
|
41
|
+
|
42
|
+
# suck out local options
|
43
|
+
@enabletimetracker=false
|
44
|
+
if opt[:enabletimetracker]
|
45
|
+
@feature_timetracker=opt[:enabletimetracker]
|
46
|
+
opt.delete :enabletimetracker
|
47
|
+
end
|
48
|
+
|
49
|
+
# pass on options to chart object
|
50
|
+
@thechart = GerbilCharts::Surfaces::Chart.new(opt)
|
51
|
+
@renderopts = {}
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_renderoptions=(opts)
|
55
|
+
@renderopts.merge!(opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def setmodelgroup(themodel)
|
59
|
+
@thechart.set_modelgroup(themodel)
|
60
|
+
|
61
|
+
# automatically set hrefs
|
62
|
+
if themodel.hasHref?
|
63
|
+
sethref(themodel.href)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def modelgroup=(themodelgroup)
|
68
|
+
setmodelgroup(themodelgroup)
|
69
|
+
end
|
70
|
+
|
71
|
+
# render options
|
72
|
+
# :file => filename
|
73
|
+
# :string => return a string
|
74
|
+
def render_base
|
75
|
+
create_chart_elements
|
76
|
+
@thechart.render(@renderopts)
|
77
|
+
end
|
78
|
+
|
79
|
+
def render(outfile)
|
80
|
+
@renderopts.merge!( :file => outfile )
|
81
|
+
render_base
|
82
|
+
end
|
83
|
+
|
84
|
+
def render_all(opts)
|
85
|
+
@renderopts.merge!(opts)
|
86
|
+
render_base
|
87
|
+
end
|
88
|
+
|
89
|
+
# render xfrag
|
90
|
+
def render_frag(xfrag)
|
91
|
+
@renderopts.merge!( :xfrag => xfrag )
|
92
|
+
render_base
|
93
|
+
end
|
94
|
+
|
95
|
+
# render string
|
96
|
+
def render_string(str)
|
97
|
+
@renderopts.merge!( :string => xfrag )
|
98
|
+
render_base
|
99
|
+
end
|
100
|
+
|
101
|
+
# click chart title to go somewhere else
|
102
|
+
def sethref(href)
|
103
|
+
@thechart.sethref(href)
|
104
|
+
end
|
105
|
+
|
106
|
+
# all sub charts override this to create custom layouts
|
107
|
+
def create_chart_elements
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# Ajax options (callback frequecy, URL, etc)
|
112
|
+
def setAjaxOptions(h)
|
113
|
+
@thechart.set_ajaxOptions(h)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Ajax context (custom parameters required by server)
|
117
|
+
def setAjaxContext(h)
|
118
|
+
@thechart.set_ajaxContext(h)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|