gerbilcharts 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/History.txt +11 -0
  2. data/License.txt +21 -0
  3. data/Manifest.txt +75 -0
  4. data/PostInstall.txt +7 -0
  5. data/README.txt +174 -0
  6. data/Rakefile +4 -0
  7. data/lib/gerbilcharts.rb +18 -0
  8. data/lib/gerbilcharts/charts.rb +16 -0
  9. data/lib/gerbilcharts/charts/area_chart.rb +36 -0
  10. data/lib/gerbilcharts/charts/bar_chart.rb +33 -0
  11. data/lib/gerbilcharts/charts/bar_chart_compact.rb +26 -0
  12. data/lib/gerbilcharts/charts/chart_base.rb +123 -0
  13. data/lib/gerbilcharts/charts/impulse_chart.rb +30 -0
  14. data/lib/gerbilcharts/charts/line_chart.rb +35 -0
  15. data/lib/gerbilcharts/charts/stacked_area_chart.rb +31 -0
  16. data/lib/gerbilcharts/models.rb +19 -0
  17. data/lib/gerbilcharts/models/bucketized_timeseries_graph_model.rb +138 -0
  18. data/lib/gerbilcharts/models/discrete_time_range.rb +63 -0
  19. data/lib/gerbilcharts/models/graph_model.rb +89 -0
  20. data/lib/gerbilcharts/models/graph_model_group.rb +240 -0
  21. data/lib/gerbilcharts/models/monotonous_graph_model.rb +192 -0
  22. data/lib/gerbilcharts/models/presets.rb +94 -0
  23. data/lib/gerbilcharts/models/raw_range.rb +68 -0
  24. data/lib/gerbilcharts/models/round_range.rb +104 -0
  25. data/lib/gerbilcharts/models/round_time_range.rb +105 -0
  26. data/lib/gerbilcharts/models/sampled_timeseries_graph_model.rb +80 -0
  27. data/lib/gerbilcharts/models/simple_timeseries_model_group.rb +68 -0
  28. data/lib/gerbilcharts/models/time_series_graph_model.rb +34 -0
  29. data/lib/gerbilcharts/public/brushmetal.css +197 -0
  30. data/lib/gerbilcharts/public/gerbil.js +327 -0
  31. data/lib/gerbilcharts/surfaces.rb +32 -0
  32. data/lib/gerbilcharts/surfaces/area_surface.rb +46 -0
  33. data/lib/gerbilcharts/surfaces/axis.rb +31 -0
  34. data/lib/gerbilcharts/surfaces/bar_surface.rb +62 -0
  35. data/lib/gerbilcharts/surfaces/basic_grid.rb +17 -0
  36. data/lib/gerbilcharts/surfaces/chart.rb +132 -0
  37. data/lib/gerbilcharts/surfaces/graph_element.rb +170 -0
  38. data/lib/gerbilcharts/surfaces/grid.rb +38 -0
  39. data/lib/gerbilcharts/surfaces/horizontal_axis.rb +32 -0
  40. data/lib/gerbilcharts/surfaces/horizontal_name_axis.rb +28 -0
  41. data/lib/gerbilcharts/surfaces/horizontal_time_axis.rb +25 -0
  42. data/lib/gerbilcharts/surfaces/impulse_surface.rb +47 -0
  43. data/lib/gerbilcharts/surfaces/legend.rb +59 -0
  44. data/lib/gerbilcharts/surfaces/line_surface.rb +53 -0
  45. data/lib/gerbilcharts/surfaces/mark_band.rb +17 -0
  46. data/lib/gerbilcharts/surfaces/panel.rb +17 -0
  47. data/lib/gerbilcharts/surfaces/pie_surface.rb +16 -0
  48. data/lib/gerbilcharts/surfaces/rect.rb +86 -0
  49. data/lib/gerbilcharts/surfaces/stacked_area_surface.rb +66 -0
  50. data/lib/gerbilcharts/surfaces/stacked_grid.rb +15 -0
  51. data/lib/gerbilcharts/surfaces/surface.rb +20 -0
  52. data/lib/gerbilcharts/surfaces/surface_background.rb +13 -0
  53. data/lib/gerbilcharts/surfaces/title_panel.rb +44 -0
  54. data/lib/gerbilcharts/surfaces/tracker.rb +62 -0
  55. data/lib/gerbilcharts/surfaces/vertical_axis.rb +46 -0
  56. data/lib/gerbilcharts/svgdc.rb +22 -0
  57. data/lib/gerbilcharts/svgdc/filters.rb +40 -0
  58. data/lib/gerbilcharts/svgdc/presentation_attributes.rb +50 -0
  59. data/lib/gerbilcharts/svgdc/svg_circle.rb +22 -0
  60. data/lib/gerbilcharts/svgdc/svg_custom_win.rb +36 -0
  61. data/lib/gerbilcharts/svgdc/svg_element.rb +87 -0
  62. data/lib/gerbilcharts/svgdc/svg_line.rb +26 -0
  63. data/lib/gerbilcharts/svgdc/svg_polygon.rb +34 -0
  64. data/lib/gerbilcharts/svgdc/svg_polyline.rb +27 -0
  65. data/lib/gerbilcharts/svgdc/svg_rect.rb +29 -0
  66. data/lib/gerbilcharts/svgdc/svg_shape.rb +10 -0
  67. data/lib/gerbilcharts/svgdc/svg_text.rb +21 -0
  68. data/lib/gerbilcharts/svgdc/svg_win.rb +52 -0
  69. data/lib/gerbilcharts/svgdc/svgdc.rb +335 -0
  70. data/lib/gerbilcharts/svgdc/transformations.rb +66 -0
  71. data/lib/gerbilcharts/version.rb +9 -0
  72. data/setup.rb +1585 -0
  73. data/test/test_Scratch.rb +21 -0
  74. data/test/test_charts.rb +119 -0
  75. data/test/test_gerbilcharts.rb +11 -0
  76. data/test/test_helper.rb +2 -0
  77. data/test/test_models.rb +118 -0
  78. data/test/test_noob.rb +81 -0
  79. data/test/test_ranges.rb +135 -0
  80. data/test/test_svgdc.rb +221 -0
  81. data/test/trafgen.rb +25 -0
  82. metadata +156 -0
@@ -0,0 +1,47 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Impulse Bar Surface w/ transparency
4
+ # impulse duration = width of bar
5
+ class ImpulseSurface < Surface
6
+ def initialize(opts={})
7
+ super(opts)
8
+ end
9
+
10
+ def int_render(g)
11
+
12
+ rx = parent.modelgroup.effective_round_range_x
13
+ ry = parent.modelgroup.effective_round_range_y0
14
+
15
+ impulse_width = 2
16
+ x2 = scale_x Time.at(0),rx
17
+ x1 = scale_x Time.at(parent.modelgroup.models[0].bucket_size_secs),rx
18
+ impulse_width = (x2-x1).abs if x2 != x1
19
+
20
+ # ajax if used
21
+ if parent.usesAjax?
22
+ set_ajaxSurfaceContext(rx.rmax,ry.rmax,"IMPULSE")
23
+ end
24
+
25
+
26
+
27
+ w=g.newwin("impulse", "stroke-width" => impulse_width)
28
+ g.setactivewindow(w)
29
+
30
+ parent.modelgroup.each_model_with_index do | mod, i|
31
+ opts = {:id => "item#{i}"}
32
+ firstpoint=true
33
+ xpos=0
34
+ ypos=0
35
+ mod.each_tuple do |x,y|
36
+ xpos = scale_x x,rx
37
+ ypos = scale_y y,ry
38
+ g.line(xpos,@bounds.bottom,xpos,ypos,opts)
39
+ end
40
+ end
41
+
42
+ g.setactivewindow
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,59 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Legend
4
+ # legend panel shows names/colors of items in a separate box (transparent)
5
+ class Legend < GraphElement
6
+
7
+ attr_reader :width
8
+ attr_reader :showvalues
9
+
10
+ def initialize(opts={})
11
+ @class = "legendpanel"
12
+ super(opts)
13
+ @width = opts[:dim] if defined? opts[:dim]
14
+ end
15
+
16
+ def int_render(g)
17
+
18
+ # count determines the bounds
19
+ @bounds.bottom = @bounds.top + 15 * parent.modelgroup.count
20
+ g.rectangle_r(@bounds, {:class => @class})
21
+
22
+ rbox = Rect.new
23
+ rbox.initfrom(@bounds)
24
+ rbox.left += 2
25
+ rbox.right = rbox.left + 10
26
+ rbox.top += 2
27
+ rbox.bottom = rbox.top+10
28
+
29
+ parent.modelgroup.each_model_with_index do | mod, i|
30
+
31
+
32
+ g.rectangle_r(rbox, :id => "item#{i}")
33
+ g.textout(rbox.right+5, rbox.bottom-2, mod.name, {:class => "legendtext"})
34
+
35
+ rbox.top += 10 + 5
36
+ rbox.bottom = rbox.top+10
37
+
38
+ end
39
+
40
+ end
41
+
42
+
43
+ def align_to_anchor(anc)
44
+ super
45
+
46
+ @bounds.deflate_v(10,10)
47
+ @bounds.deflate_h(2,4)
48
+
49
+ if @width
50
+ @bounds.left = @bounds.right - @width
51
+ end
52
+
53
+ end
54
+
55
+
56
+ end
57
+
58
+ end
59
+
@@ -0,0 +1,53 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Line Surface
4
+ # Simple line drawing
5
+ # Control the color,thickness of the line via the stylesheet item lineitem1, lineitem2 etc
6
+ #
7
+ # Supported global options
8
+ #
9
+ # [+circle_data_points+] Draw a solid circle around datapoints
10
+ #
11
+ class LineSurface < Surface
12
+ def initialize(opts={})
13
+ super(opts)
14
+ end
15
+
16
+ def int_render(g)
17
+
18
+ rx = parent.modelgroup.effective_round_range_x
19
+ ry = parent.modelgroup.effective_round_range_y0
20
+
21
+ # ajax if used
22
+ if parent.usesAjax?
23
+ set_ajaxSurfaceContext(rx.rmax,ry.rmax,"LINE")
24
+ end
25
+
26
+ parent.modelgroup.each_model_with_index do | mod, i|
27
+
28
+ mod.each_tuple do |x,y|
29
+
30
+ # the basic line
31
+ xpos = scale_x x,rx
32
+ ypos = scale_y y,ry
33
+ g.lineto xpos,ypos
34
+
35
+
36
+ # datapoint and a tooltip
37
+ opts = {:id => "item#{i}"}
38
+ if parent.get_global_option(:auto_tooltips,false)
39
+ opts.merge!(:onmouseover => "OpacityDown(evt)", :onmouseout => "OpacityUp(evt)")
40
+ opts.store(:gerbiltooltip1, mod.name)
41
+ opts.store(:gerbiltooltip2, "Val = #{y}")
42
+ end
43
+ g.circle(xpos,ypos,4,opts) if parent.get_global_option(:circle_data_points,false)
44
+ end
45
+ g.endline(:id => "lineitem#{i}")
46
+ end
47
+
48
+ #draw each model in the group
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,17 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = MarkBand
4
+ # Mark out a rectangular area on the surface (eg, critical zone)
5
+ class MarkBand < GraphElement
6
+ def initialize(opts={})
7
+ @class = "markband"
8
+ super(opts)
9
+ end
10
+
11
+ def int_render(g)
12
+ g.rectangle_r(@bounds, {:class => @class})
13
+ end
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Panel
4
+ # General purpose rectangular panel
5
+ class Panel < GraphElement
6
+ def initialize(opts={})
7
+ @class = "panel"
8
+ super(opts)
9
+ end
10
+
11
+ def int_render(g)
12
+ g.rectangle_r(@bounds, {:class => @class})
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Pie Surface
4
+ # Not yet implemented
5
+ class PieSurface < Surface
6
+ def initialize(opts={})
7
+ super(opts)
8
+ end
9
+
10
+ def int_render(g)
11
+ g.rectangle_r(@bounds, {:class => @class})
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,86 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Rect
4
+ # Utility class for manipulations on a rectangle
5
+ #
6
+ class Rect
7
+
8
+ attr_accessor :left, :top, :right, :bottom
9
+
10
+ def initialize()
11
+ @left,@top,@right,@bottom=0,0,0,0
12
+ end
13
+
14
+ def from_wh(w,h)
15
+ @left=0
16
+ @right=w
17
+ @top=0
18
+ @bottom=h
19
+ end
20
+
21
+ def deflate_h(l,r)
22
+ @left += l
23
+ @right -= r
24
+ end
25
+
26
+ def deflate_v(t,b)
27
+ @top += t
28
+ @bottom -= b
29
+ end
30
+
31
+ def initfrom(r)
32
+ @left=r.left
33
+ @right=r.right
34
+ @top=r.top
35
+ @bottom=r.bottom
36
+ end
37
+
38
+ def clip_b(dim)
39
+ @top=@bottom-dim
40
+ end
41
+
42
+ def clip_t(dim)
43
+ @bottom=@top+dim
44
+ end
45
+
46
+ def clip_l(dim)
47
+ @right=@left+dim
48
+ end
49
+
50
+ def clip_r(dim)
51
+ @left=@right-dim
52
+ end
53
+
54
+ def crop_b(dim)
55
+ @bottom=@bottom-dim
56
+ end
57
+
58
+ def crop_t(dim)
59
+ @top=@top+dim
60
+ end
61
+
62
+ def crop_l(dim)
63
+ @left=@left+dim
64
+ end
65
+
66
+ def crop_r(dim)
67
+ @right=@right-dim
68
+ end
69
+
70
+ def width
71
+ @right-@left
72
+ end
73
+
74
+ def height
75
+ @bottom-@top
76
+ end
77
+
78
+
79
+ def to_s
80
+ "#{@left},#{@top} [w=#{width} h=#{height}]"
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
@@ -0,0 +1,66 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # == Stacked Area Surface w/ transparency
4
+ # models are expected to be 'sweepable' (use a bucketized time series model)
5
+ #
6
+ class StackedAreaSurface < Surface
7
+ def initialize(opts={})
8
+ super(opts)
9
+ end
10
+
11
+ def int_render(g)
12
+
13
+
14
+ rx = parent.modelgroup.effective_round_range_x
15
+ ry = parent.modelgroup.cumulative_sweep_round_range_y0
16
+
17
+ # ajax if used
18
+ if parent.usesAjax?
19
+ set_ajaxSurfaceContext(rx.rmax,ry.rmax,"SA")
20
+ end
21
+
22
+ # prepare models for sweeping
23
+ sweep_pos= rx.rmin
24
+ sweep_to = rx.rmax
25
+ polygons = []
26
+ parent.modelgroup.each_model do | mod|
27
+ mod.begin_sweep
28
+ polygons << GerbilCharts::SVGDC::SVGPolygon.new
29
+ end
30
+
31
+ # sweep interval
32
+ sweep_interval = parent.modelgroup.sweep_interval
33
+
34
+ # perform the sweep
35
+ while (sweep_pos<=sweep_to)
36
+
37
+ acc_y = 0
38
+
39
+ parent.modelgroup.each_model_with_index do | mod, i|
40
+
41
+ acc_y += mod.sweep(sweep_pos)
42
+ xpos = scale_x sweep_pos,rx
43
+ ypos = scale_y acc_y,ry
44
+
45
+ if polygons[i].isempty?
46
+ polygons[i].addpoint(xpos,@bounds.bottom)
47
+ end
48
+
49
+ polygons[i].addpoint(xpos,ypos)
50
+ end
51
+
52
+ sweep_pos += sweep_interval
53
+ end
54
+
55
+ # layout all polygons in reverse
56
+ i=polygons.length-1
57
+ polygons.reverse_each do |p|
58
+ g.addshape(p, {:id => "item#{i}"})
59
+ i -= 1
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,15 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # Stacked Grid - grid overlay
4
+ # Used for stacked area surface. Maps the sum of the model values
5
+ class StackedGrid < Grid
6
+
7
+ protected
8
+
9
+ def grid_range_y
10
+ return parent.modelgroup.cumulative_round_range_y0
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,20 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = Surface - graph surface
4
+ # Base class for all surfaces (line,bar,pie,area,...)
5
+ #
6
+ class Surface < GraphElement
7
+ def initialize(opts={})
8
+ @class = "surfacepanel"
9
+ super(opts)
10
+ end
11
+
12
+ def int_render(g)
13
+ end
14
+
15
+ def set_ajaxSurfaceContext(mxx, mxy, type)
16
+ parent.set_ajaxContext(:axmxx => mxx, :axmxy => mxy, :axsurface => type)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,13 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # = SurfaceBackground
4
+ # See the stylesheet surfaceback for customization
5
+ #
6
+ class SurfaceBackground < Panel
7
+ def initialize(opts={})
8
+ super(opts)
9
+ @class = "surfaceback"
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,44 @@
1
+ module GerbilCharts::Surfaces
2
+
3
+ # == TitlePanel
4
+ # just - left or right justify the title
5
+ class TitlePanel < Panel
6
+
7
+ attr_accessor :just
8
+
9
+ def initialize(opts={})
10
+ @class = "titlepanel"
11
+ @just = :left
12
+ @just = opts[:just] if opts[:just]
13
+
14
+ super(opts)
15
+ end
16
+
17
+ def int_render(g)
18
+ opts = {:class => "titletext"}
19
+ opts.store(:href, @parent.href) if @parent.href
20
+
21
+ if @just == :left
22
+ g.textout(@bounds.left, @bounds.top+16, parent.modelgroup.name, opts)
23
+ else
24
+ opts.store( "text-anchor", "end" )
25
+ g.textout(@bounds.right, @bounds.top+16, parent.modelgroup.name, opts)
26
+ end
27
+
28
+ end
29
+
30
+ def align_to_anchor(anc)
31
+ super
32
+ @bounds.deflate_v(4,4)
33
+ @bounds.deflate_h(2,2)
34
+
35
+ if @width
36
+ @bounds.bottom= @bounds.top + @lay_dimension
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+
44
+ end