gerbilcharts 0.2.13 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +35 -0
  2. data/Manifest.txt +8 -0
  3. data/README.txt +8 -8
  4. data/lib/gerbilcharts/charts.rb +3 -0
  5. data/lib/gerbilcharts/charts/bubble_chart.rb +30 -0
  6. data/lib/gerbilcharts/charts/conversation_ring.rb +31 -0
  7. data/lib/gerbilcharts/charts/line_chart.rb +1 -0
  8. data/lib/gerbilcharts/charts/matrix_chart.rb +32 -0
  9. data/lib/gerbilcharts/charts/square_line_chart.rb +7 -0
  10. data/lib/gerbilcharts/models.rb +1 -0
  11. data/lib/gerbilcharts/models/bucketized_timeseries_graph_model.rb +1 -1
  12. data/lib/gerbilcharts/models/graph_model_group.rb +19 -2
  13. data/lib/gerbilcharts/models/matrix_model.rb +85 -0
  14. data/lib/gerbilcharts/models/monotonous_graph_model.rb +5 -1
  15. data/lib/gerbilcharts/models/presets.rb +18 -11
  16. data/lib/gerbilcharts/models/raw_range.rb +1 -1
  17. data/lib/gerbilcharts/models/round_range.rb +3 -1
  18. data/lib/gerbilcharts/models/round_time_range.rb +19 -29
  19. data/lib/gerbilcharts/models/sampled_timeseries_graph_model.rb +1 -1
  20. data/lib/gerbilcharts/public/brushmetal.css +123 -74
  21. data/lib/gerbilcharts/public/gerbil.js +104 -64
  22. data/lib/gerbilcharts/surfaces.rb +3 -0
  23. data/lib/gerbilcharts/surfaces/bubble_surface.rb +105 -0
  24. data/lib/gerbilcharts/surfaces/chart.rb +4 -2
  25. data/lib/gerbilcharts/surfaces/conversation_ring.rb +64 -0
  26. data/lib/gerbilcharts/surfaces/detailed_legend.rb +35 -13
  27. data/lib/gerbilcharts/surfaces/graph_element.rb +8 -1
  28. data/lib/gerbilcharts/surfaces/grid.rb +8 -2
  29. data/lib/gerbilcharts/surfaces/horizontal_axis.rb +12 -3
  30. data/lib/gerbilcharts/surfaces/horizontal_time_axis.rb +5 -4
  31. data/lib/gerbilcharts/surfaces/impulse_surface.rb +1 -1
  32. data/lib/gerbilcharts/surfaces/legend.rb +43 -6
  33. data/lib/gerbilcharts/surfaces/mark_band.rb +17 -1
  34. data/lib/gerbilcharts/surfaces/matrix_surface.rb +87 -0
  35. data/lib/gerbilcharts/surfaces/pie_surface.rb +109 -96
  36. data/lib/gerbilcharts/surfaces/rect.rb +18 -0
  37. data/lib/gerbilcharts/surfaces/stacked_area_surface.rb +42 -2
  38. data/lib/gerbilcharts/surfaces/stacked_grid.rb +1 -3
  39. data/lib/gerbilcharts/surfaces/title_panel.rb +7 -2
  40. data/lib/gerbilcharts/surfaces/tracker.rb +4 -1
  41. data/lib/gerbilcharts/surfaces/vertical_axis.rb +2 -2
  42. data/lib/gerbilcharts/svgdc.rb +1 -0
  43. data/lib/gerbilcharts/svgdc/css_inliner.rb +2 -2
  44. data/lib/gerbilcharts/svgdc/svg_ellipse.rb +21 -0
  45. data/lib/gerbilcharts/svgdc/svg_polygon.rb +19 -0
  46. data/lib/gerbilcharts/svgdc/svgdc.rb +4 -1
  47. data/lib/gerbilcharts/version.rb +2 -3
  48. data/test/test_bar.rb +1 -1
  49. data/test/test_bubble.rb +52 -0
  50. data/test/test_conversation.rb +34 -0
  51. data/test/test_lines.rb +3 -3
  52. data/test/test_matrix.rb +34 -0
  53. data/test/test_noob.rb +9 -6
  54. data/test/test_pie.rb +2 -2
  55. data/test/test_ranges.rb +15 -2
  56. data/test/test_sa.rb +88 -0
  57. metadata +14 -2
data/History.txt CHANGED
@@ -1,3 +1,38 @@
1
+ == 0.5.9 2011-01-15
2
+ * Changes
3
+ * New public release
4
+ * Across the board improvements & new features
5
+ * Used in production environments by Trisul Network Security Monitoring
6
+ * New bubble chart
7
+
8
+
9
+ == 0.3.7 2010-04-15
10
+ * Changes
11
+ * Lots of bug fixes rolled up
12
+ * Better scaling in 1G to 10G range
13
+ * Time zone support for gerbil.js
14
+
15
+ == 0.3.2 2010-01-05
16
+ * Changes
17
+ * New parameter :enable_detailed_legend :enable_legend
18
+ * Larger default fonts
19
+ * Better layout logic for detailed legend panel
20
+ * Block button to open/close legend panel
21
+
22
+
23
+ == 0.2.17 2009-12-16
24
+ * Changes
25
+ * Traffic Matrix and Conversation Error Rectified
26
+ * Angled labels for matrix
27
+
28
+ == 0.2.15 2009-12-11
29
+ * Changes
30
+ * More hardening of gerbilcharts against bad data
31
+
32
+ == 0.2.14 2009-12-10
33
+ * Changes
34
+ * Traffic matrix and conversation ring
35
+
1
36
  == 0.2.13 2009-12-01
2
37
  * Changes
3
38
  * inline javascript option now fixed
data/Manifest.txt CHANGED
@@ -30,6 +30,7 @@ lib/gerbilcharts/models/discrete_time_range.rb
30
30
  lib/gerbilcharts/models/sampled_timeseries_graph_model.rb
31
31
  lib/gerbilcharts/models/time_series_graph_model.rb
32
32
  lib/gerbilcharts/models/simple_timeseries_model_group.rb
33
+ lib/gerbilcharts/models/matrix_model.rb
33
34
  lib/gerbilcharts/surfaces/area_surface.rb
34
35
  lib/gerbilcharts/surfaces/axis.rb
35
36
  lib/gerbilcharts/surfaces/bar_surface.rb
@@ -53,10 +54,13 @@ lib/gerbilcharts/surfaces/stacked_grid.rb
53
54
  lib/gerbilcharts/surfaces/surface_background.rb
54
55
  lib/gerbilcharts/surfaces/surface.rb
55
56
  lib/gerbilcharts/surfaces/title_panel.rb
57
+ lib/gerbilcharts/surfaces/bubble_surface.rb
56
58
  lib/gerbilcharts/surfaces/tracker.rb
57
59
  lib/gerbilcharts/surfaces/vertical_axis.rb
58
60
  lib/gerbilcharts/surfaces/pie_surface.rb
59
61
  lib/gerbilcharts/surfaces/square_line_surface.rb
62
+ lib/gerbilcharts/surfaces/matrix_surface.rb
63
+ lib/gerbilcharts/surfaces/conversation_ring.rb
60
64
  lib/gerbilcharts/charts/area_chart.rb
61
65
  lib/gerbilcharts/charts/bar_chart_compact.rb
62
66
  lib/gerbilcharts/charts/bar_chart.rb
@@ -66,6 +70,9 @@ lib/gerbilcharts/charts/line_chart.rb
66
70
  lib/gerbilcharts/charts/stacked_area_chart.rb
67
71
  lib/gerbilcharts/charts/pie_chart.rb
68
72
  lib/gerbilcharts/charts/square_line_chart.rb
73
+ lib/gerbilcharts/charts/matrix_chart.rb
74
+ lib/gerbilcharts/charts/conversation_ring.rb
75
+ lib/gerbilcharts/charts/bubble_chart.rb
69
76
  lib/gerbilcharts/svgdc/svgdc.rb
70
77
  lib/gerbilcharts/svgdc/svg_element.rb
71
78
  lib/gerbilcharts/svgdc/filters.rb
@@ -75,6 +82,7 @@ lib/gerbilcharts/svgdc/svg_win.rb
75
82
  lib/gerbilcharts/svgdc/svg_custom_win.rb
76
83
  lib/gerbilcharts/svgdc/svg_shape.rb
77
84
  lib/gerbilcharts/svgdc/svg_circle.rb
85
+ lib/gerbilcharts/svgdc/svg_ellipse.rb
78
86
  lib/gerbilcharts/svgdc/svg_line.rb
79
87
  lib/gerbilcharts/svgdc/svg_polygon.rb
80
88
  lib/gerbilcharts/svgdc/svg_polyline.rb
data/README.txt CHANGED
@@ -4,23 +4,23 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- SVG based charting library especially suited for timeseries data.
7
+ SVG based Ruby charting library.
8
8
 
9
9
  == FEATURES/PROBLEMS:
10
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
11
+ * All common chart types supported (Line, Stacked Area, Pie, Bar, Area)
12
+ * If used in a Rails app, SVG is fully generated server side
13
+ * Javascript is used within the SVG document for interactivity only
14
+ * Completely change look and feel via a SVG CSS
15
+ * Show tooltips, handle clicks on chart objects
15
16
  * Ajax enabled. gerbil.js allows each chart to autoupdate itself with new SVG elements.
16
17
 
17
18
  Known issues :
18
19
  * Requires a browser that can handle SVG such as Firefox/Opera.
19
20
  * 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
21
 
23
22
  ===Note on stylesheets
23
+
24
24
  GerbilCharts uses stylesheets to customize appearances of almost all visual
25
25
  elements (colors, fonts, line strokes, fills). You can use the supplied
26
26
  stylesheet (eg, brushmetal.css) or derive your own from it. GerbilCharts
@@ -245,7 +245,7 @@ Todo: A sample please (extract from Web Trisul)
245
245
 
246
246
  (The MIT License)
247
247
 
248
- Copyright (c) 2008 Vivek Rajagopalan (vivek at unleashnetworks )
248
+ Copyright (c) 2008-10 Vivek Rajagopalan (vivek at unleashnetworks )
249
249
 
250
250
  Permission is hereby granted, free of charge, to any person obtaining
251
251
  a copy of this software and associated documentation files (the
@@ -16,3 +16,6 @@ require 'gerbilcharts/charts/line_chart'
16
16
  require 'gerbilcharts/charts/stacked_area_chart'
17
17
  require 'gerbilcharts/charts/pie_chart'
18
18
  require 'gerbilcharts/charts/square_line_chart'
19
+ require 'gerbilcharts/charts/matrix_chart'
20
+ require 'gerbilcharts/charts/conversation_ring'
21
+ require 'gerbilcharts/charts/bubble_chart'
@@ -0,0 +1,30 @@
1
+ module GerbilCharts::Charts
2
+
3
+ # = Bubble chart
4
+ # Size of SVG bubbles (can be shapes) determined by occurances
5
+ #
6
+ class BubbleChart < ChartBase
7
+
8
+ def initialize(opt={})
9
+ super(opt)
10
+ end
11
+
12
+ def create_chart_elements
13
+
14
+ # other elements
15
+ @thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
16
+ @thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30))
17
+ @thechart.add_child(GerbilCharts::Surfaces::BubbleSurface.new(:orient => ORIENT_OVERLAY),:anchor => true)
18
+ @thechart.add_child(GerbilCharts::Surfaces::Legend.new(:orient=> ORIENT_OVERLAY, :dim => 2*@legend_width))
19
+ @thechart.add_child(GerbilCharts::Surfaces::DetailedLegend.new(:orient=> ORIENT_OVERLAY, :dim => 4*@legend_width))
20
+ @thechart.add_child(GerbilCharts::Surfaces::HorizontalTimeAxis.new(:orient => ORIENT_SOUTH, :dim => 25 ))
21
+
22
+ # optional features
23
+ if @feature_timetracker
24
+ @thechart.add_child(GerbilCharts::Surfaces::Tracker.new(:orient => ORIENT_SOUTH, :dim => 10 ))
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,31 @@
1
+ module GerbilCharts::Charts
2
+
3
+ # Matrix Chart
4
+ class ConversationRing < ChartBase
5
+
6
+ def initialize(opt={})
7
+ super(opt)
8
+ end
9
+
10
+
11
+ def create_chart_elements
12
+ # filters if required
13
+ @thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(224,224,224)"))
14
+
15
+ # additional filter by name
16
+ @thechart.create_filter(GerbilCharts::SVGDC::LikeButton.new('LikeButton')) if @gerbilfilter == 'LikeButton'
17
+
18
+
19
+ # other elements
20
+ @thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
21
+ @thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30))
22
+ @thechart.add_child(GerbilCharts::Surfaces::ConversationRing.new(:orient => ORIENT_OVERLAY), :anchor => true)
23
+ end
24
+
25
+
26
+
27
+ end
28
+
29
+
30
+
31
+ end
@@ -29,6 +29,7 @@ class LineChart < ChartBase
29
29
  @thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30))
30
30
  @thechart.add_child(GerbilCharts::Surfaces::LineSurface.new(:orient => ORIENT_OVERLAY),:anchor => true)
31
31
  @thechart.add_child(GerbilCharts::Surfaces::Legend.new(:orient=> ORIENT_OVERLAY, :dim => @legend_width))
32
+ @thechart.add_child(GerbilCharts::Surfaces::DetailedLegend.new(:orient=> ORIENT_OVERLAY, :dim => 3*@legend_width))
32
33
  @thechart.add_child(GerbilCharts::Surfaces::VerticalAxis.new(:orient => ORIENT_WEST, :dim => 40 ))
33
34
  @thechart.add_child(GerbilCharts::Surfaces::HorizontalTimeAxis.new(:orient => ORIENT_SOUTH, :dim => 25 ))
34
35
  end
@@ -0,0 +1,32 @@
1
+ module GerbilCharts::Charts
2
+
3
+ # Matrix Chart
4
+ class MatrixChart < ChartBase
5
+
6
+
7
+ def initialize(opt={})
8
+ super(opt)
9
+ end
10
+
11
+
12
+ def create_chart_elements
13
+
14
+ # filters if required
15
+ @thechart.create_filter(GerbilCharts::SVGDC::LinearGradientVertical.new("vertgrad","rgb(255,255,255)","rgb(224,224,224)"))
16
+
17
+ # additional filter by name
18
+ @thechart.create_filter(GerbilCharts::SVGDC::LikeButton.new('LikeButton')) if @gerbilfilter == 'LikeButton'
19
+
20
+ # other elements
21
+ @thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
22
+ @thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_NORTH, :dim => 30))
23
+ @thechart.add_child(GerbilCharts::Surfaces::MatrixSurface.new(:orient => ORIENT_OVERLAY), :anchor => true)
24
+ end
25
+
26
+
27
+
28
+ end
29
+
30
+
31
+
32
+ end
@@ -26,12 +26,19 @@ class SquareLineChart < ChartBase
26
26
 
27
27
  # other elements
28
28
  @thechart.add_child(GerbilCharts::Surfaces::SurfaceBackground.new(:orient => ORIENT_OVERLAY))
29
+ @thechart.add_child(GerbilCharts::Surfaces::MarkBand.new(:orient => ORIENT_OVERLAY))
29
30
  @thechart.add_child(GerbilCharts::Surfaces::BasicGrid.new(:orient => ORIENT_OVERLAY))
30
31
  @thechart.add_child(GerbilCharts::Surfaces::TitlePanel.new(:orient => ORIENT_OVERLAY, :dim => 30))
31
32
  @thechart.add_child(GerbilCharts::Surfaces::SquareLineSurface.new(:orient => ORIENT_OVERLAY),:anchor => true)
32
33
  @thechart.add_child(GerbilCharts::Surfaces::Legend.new(:orient=> ORIENT_OVERLAY, :dim => @legend_width))
34
+ @thechart.add_child(GerbilCharts::Surfaces::DetailedLegend.new(:orient=> ORIENT_OVERLAY, :dim => 3*@legend_width))
33
35
  @thechart.add_child(GerbilCharts::Surfaces::VerticalAxis.new(:orient => ORIENT_WEST, :dim => 40 ))
34
36
  @thechart.add_child(GerbilCharts::Surfaces::HorizontalTimeAxis.new(:orient => ORIENT_SOUTH, :dim => 25 ))
37
+
38
+ # optional features
39
+ if @feature_timetracker
40
+ @thechart.add_child(GerbilCharts::Surfaces::Tracker.new(:orient => ORIENT_OVERLAY ))
41
+ end
35
42
  end
36
43
  end
37
44
 
@@ -17,3 +17,4 @@ require 'gerbilcharts/models/time_series_graph_model'
17
17
  require 'gerbilcharts/models/bucketized_timeseries_graph_model'
18
18
  require 'gerbilcharts/models/sampled_timeseries_graph_model'
19
19
  require 'gerbilcharts/models/simple_timeseries_model_group'
20
+ require 'gerbilcharts/models/matrix_model.rb'
@@ -35,6 +35,7 @@ class BucketizedTimeSeriesGraphModel < TimeSeriesGraphModel
35
35
  def add(x_tm,y_val)
36
36
  buckettm_in = to_buckettime(x_tm)
37
37
 
38
+
38
39
  # first time
39
40
  if @xarr.length==0
40
41
  super(buckettm_in,y_val)
@@ -42,7 +43,6 @@ class BucketizedTimeSeriesGraphModel < TimeSeriesGraphModel
42
43
  return
43
44
  end
44
45
 
45
-
46
46
  # subsequent times
47
47
  if buckettm_in== latest_x
48
48
  ynew = bucketize(y_val)
@@ -10,6 +10,8 @@ class GraphModelGroup
10
10
  attr_accessor :href
11
11
  attr_accessor :emptycaption
12
12
  attr_accessor :units
13
+ attr_accessor :x_markers
14
+ attr_accessor :ref_model
13
15
 
14
16
  def initialize(n="Untitled-Group")
15
17
  @models=[]
@@ -187,14 +189,17 @@ class GraphModelGroup
187
189
  # sum of model ranges with min y being 0
188
190
  def cumulative_round_range_y0
189
191
 
190
- return 0,100 if models.empty?
192
+ return 0,100 if models.empty?
191
193
 
192
194
  reffy = RawRange.new
193
195
  reffy.update(0)
194
196
  @models.each do |m|
195
- reffy.update(m.yrange.rmax+reffy.rmax)
197
+ reffy.update(m.yrange.rmax+reffy.rmax) if m.yrange.rmax
196
198
  end
199
+
200
+ reffy.update(ref_model.yrange.rmax) if has_ref_model?
197
201
  return models[0].round_given_y(reffy)
202
+
198
203
  end
199
204
 
200
205
  # sum of model ranges
@@ -203,6 +208,7 @@ class GraphModelGroup
203
208
  @models.each do |m|
204
209
  reffy.update(m.yrange.rmax+reffy.rmax)
205
210
  end
211
+ reffy.update(ref_model.yrange.rmax) if has_ref_model?
206
212
  return models[0].round_given_y(reffy)
207
213
  end
208
214
 
@@ -292,6 +298,15 @@ class GraphModelGroup
292
298
  return @emptycaption
293
299
  end
294
300
 
301
+ def has_x_markers?
302
+ not x_markers.nil?
303
+ end
304
+
305
+ def has_ref_model?
306
+ not @ref_model.nil?
307
+ end
308
+
309
+
295
310
 
296
311
  private
297
312
 
@@ -318,6 +333,8 @@ private
318
333
  reffy.update(acc_y)
319
334
  end
320
335
 
336
+ reffy.update(ref_model.yrange.rmax) if has_ref_model?
337
+
321
338
  return models[0].round_given_y(reffy)
322
339
 
323
340
  end
@@ -0,0 +1,85 @@
1
+ module GerbilCharts::Models
2
+
3
+ class MatrixModel
4
+
5
+ attr_reader :aend, :zend, :aenduniq, :zenduniq
6
+ attr_accessor :name
7
+ attr_reader :aendlen , :zendlen
8
+ attr_reader :hash , :sort,:multiply_factor,:name
9
+
10
+ # Create the model group for matrix chart
11
+ # Input = {"a","b",1000}
12
+ # {"a","c",1030}
13
+ # {"b","v",2345}
14
+ #
15
+ # Output = {"a"=>[1000,1030,0],"b"=>[0,0,2345]}
16
+
17
+ def initialize(opts)
18
+ @name=opts
19
+ @aend = []
20
+ @zend = []
21
+ @input_values = []
22
+ @arr = []
23
+ @hash = {}
24
+ @sort = []
25
+ @unsort_value = []
26
+ @multiply_factor = 1.0
27
+ @flag = 1
28
+ end
29
+
30
+ # Construct the input values
31
+ # Eg : @input_values = [["a","b",3000],["a","c",4000],["d","r",4500]]
32
+ def add(item1,item2,item3)
33
+ @aend << item1
34
+ @zend << item2
35
+ for i in 0...@input_values.count
36
+ if ((@input_values[i][0] == item1) and (@input_values[i][1] == item2))
37
+ @input_values[i][2] = @input_values[i][2] + item3
38
+ @flag = 0
39
+ end
40
+ end
41
+ if(@flag==1)
42
+ @input_values << [item1,item2,item3]
43
+ end
44
+ @flag=1
45
+ end
46
+
47
+ # calculates the conversation matrix based on the raw arrays a/zend
48
+ def calc_matrix
49
+ @aenduniq = @aend.uniq
50
+ @zenduniq = @zend.uniq
51
+ @aendlen = @aenduniq.length
52
+ @zendlen = @zenduniq.length
53
+
54
+ @input_values.each do |item|
55
+ @unsort_value << item[2]
56
+ end
57
+ @sort = @unsort_value.sort.reverse
58
+
59
+ @aenduniq.each do |aitem|
60
+ @zenduniq.each_with_index do |zitem,i|
61
+ @input_values.each do |vitem|
62
+ if ((vitem[0] == aitem) and (vitem[1] == zitem))
63
+ @arr << vitem[2]
64
+ end
65
+ end
66
+ if @arr[i].nil?
67
+ @arr << 0
68
+ end
69
+ end
70
+ @hash.store(aitem,@arr)
71
+ @arr = []
72
+ end
73
+ end
74
+
75
+ def hasHref?
76
+ return false
77
+ end
78
+
79
+ def empty?
80
+ return false
81
+ end
82
+
83
+ end
84
+ end
85
+
@@ -27,7 +27,9 @@ class MonotonousGraphModel < GraphModel
27
27
  def add(x_val,y_val)
28
28
 
29
29
  if @xarr.length > 0 and @xarr.last > x_val
30
- raise "Expecting monotonous series data"
30
+ # ignoring out of order data
31
+ # raise "Expecting monotonous series data"
32
+ return
31
33
  end
32
34
 
33
35
  # x updates
@@ -158,6 +160,8 @@ class MonotonousGraphModel < GraphModel
158
160
  # todo : support :ninety_fifth
159
161
  #
160
162
  def get_statistical_analysis(mode = :normal)
163
+ return [0,0,0,0,0] if @yarr.size==0
164
+
161
165
  a = []
162
166
  a[0]= @yrange.rmin
163
167
  a[1]= @yrange.rmax