autograph 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,50 +0,0 @@
1
- class FlotRenderer < BaseRenderer
2
- def to_html
3
- data = []
4
- graph_type = ''
5
- if series[0].type.to_sym == :bar
6
- graph_type = "bars"
7
- series.each_with_index do |s, i|
8
- data << "[#{i}, #{s.y_values[0]}]"
9
- end
10
- else
11
- graph_type = "lines"
12
- 1.upto(series[0].x_values.size.to_i - 1) do |index|
13
- data << "[#{series[0].x_values[index]}, #{series[0].y_values[index]}]"
14
- end
15
- end
16
-
17
- html = <<GRAPH_HTML
18
- <div style="with:600px;height:350px;" id="#{graph_name}"></div>
19
- <script language="javascript" type="text/javascript">
20
- //#{series.inspect}
21
- $('.report').show();
22
- $.plot($("##{graph_name}"), [
23
- {
24
- data: [#{data.join(",")}],
25
- #{graph_type}: { show: true, fill: true }
26
- }
27
- ]);
28
- $('.report').hide();
29
- show_report('overview');
30
- </script>
31
- GRAPH_HTML
32
- html
33
- end
34
-
35
- def self.header_html
36
- html = <<HEADER_HTML
37
- <script type="text/javascript" src="http://127.0.0.1:1234/jquery.js"></script>
38
- <script type="text/javascript" src="http://127.0.0.1:1234/jquery.flot.js"></script>
39
- HEADER_HTML
40
- end
41
-
42
- private
43
- def format_file_name(desired_name)
44
- desired_name.to_s.gsub("/","_").gsub("=","_").gsub("?","_")
45
- end
46
-
47
- def graph_name
48
- @graph_name ||= "graph_#{format_file_name(path || 'overview')}_#{(rand * 100).to_i}"
49
- end
50
- end
@@ -1,82 +0,0 @@
1
- require 'gchart'
2
-
3
- class GChartRenderer < BaseRenderer
4
-
5
- def to_html
6
- render_graph
7
- "<img src='#{render_graph.to_url}'/>"
8
- end
9
-
10
- private
11
- def available_colors
12
- [:red, :yellow, :green, :blue, :black]
13
- end
14
-
15
- def render_graph
16
- chart_type = series[0].type.to_s
17
- chart_type = 'line' if chart_type == 'area'
18
-
19
- chart = GChart.send(chart_type) do |g|
20
-
21
- x_values = series[0].x_values
22
- y_values = series[0].y_values
23
-
24
- x_values = series.map{|s| s.x_values} if chart_type.to_sym == :bar
25
-
26
- series_data = series.map{|s| s.y_values}
27
-
28
- g.data = series_data
29
-
30
- # chg, grid lines
31
- # chm data point makers
32
- # chma, margins
33
- # chm, flags :chm => "fMax,FF0000,0,#{y_values.index(y_values.max)},15"
34
- # cht, bvg (bar vertical grouped)
35
- # chbh, bar spacing
36
- # chdlp, legend on bottom, vertical
37
-
38
- # TODO: Should case off of chart types
39
-
40
- extras = {:chg => "#{100/(y_values.size)},20,1,5",
41
- :chm => "o,0066FF,0,-1.0,6",
42
- :chma => "20,20,20,30|80,20",
43
- :chdlp => "bv"}
44
-
45
- if chart_type.to_sym == :bar
46
- extras = extras.merge({:chm => '', :chbh => 'a,20,20'})
47
- # chm=N*f0*,000000,1,-1,11|N*f0*,000000,2,-1,11|N*f1*,000000,3,-1,11|N*f2*,FF0000,0,0,18
48
- g.grouped = true
49
- end
50
-
51
- g.extras = extras
52
-
53
- g.axis(:bottom) do |a|
54
- a.labels = [0] << x_values
55
- a.text_color = :black
56
- end
57
-
58
- g.axis(:left) do |a|
59
- interval = (y_values.max/10).to_i
60
- interval = 1 if interval == 0
61
- a.labels = (0..(y_values.max.to_i)).to_a.select{|y| y % interval == 0}
62
- a.text_color = :black
63
- end
64
-
65
- if chart_type.to_sym == :bar
66
- g.orientation = :vertical
67
- end
68
-
69
- colors = available_colors
70
- g.colors = series.map{|s| colors.pop}
71
-
72
- g.legend = series.map{|s| s.label.gsub("'", "")}
73
-
74
- g.title = title
75
-
76
- g.width = width
77
- g.height = height
78
-
79
- g.entire_background = "f4f4f4"
80
- end
81
- end
82
- end
@@ -1,20 +0,0 @@
1
- def rasterize_graphs
2
- batik_location = @conf['batik-rasterizer-jar']
3
- if File.exist?(batik_location)
4
- `java -jar #{batik_location} *.svg > /dev/null 2>&1`
5
-
6
- Dir.glob('*.png').each do |png|
7
- if File.size(png) > 0
8
- File.delete(png.sub('.png', '.svg'))
9
- else
10
- puts "Error rasterizing #{png}, leaving SVG intact."
11
- end
12
- end
13
-
14
- @graphs.each do |uri, graph|
15
- @graphs[uri].each do |file_name|
16
- @graphs[uri] = @graphs[uri].map{|x| File.exist?(x.sub('.svg', '.png')) ? x.sub('.svg', '.png') : x}
17
- end
18
- end
19
- end
20
- end
@@ -1,35 +0,0 @@
1
- require 'scruffy'
2
-
3
- class ScruffyRenderer < BaseRenderer
4
- SCRUFFY_HEIGHT=360
5
- SCRUFFY_WIDTH=600
6
-
7
- def to_html
8
- render_graph
9
- "<iframe width=\"#{SCRUFFY_WIDTH}\" height=\"#{SCRUFFY_HEIGHT}\" src=\"./#{graph_file_name}\"></iframe>"
10
- end
11
-
12
- private
13
- def format_file_name(desired_name)
14
- desired_name.to_s.gsub("/","_").gsub("=","_").gsub("?","_")
15
- end
16
-
17
- def graph_file_name
18
- @graph_name ||= "graph_#{format_file_name(path || 'overview')}_#{(rand * 100).to_i}.svg"
19
- end
20
-
21
- def render_graph
22
- graph = Scruffy::Graph.new
23
- graph.title = title
24
- graph.renderer = Scruffy::Renderers::Standard.new(:values => series[0].x_values.size + 1)
25
- graph.point_markers = series[0].x_values
26
-
27
- series.each do |s|
28
- graph.add s.type.to_sym, s.label, s.y_values
29
- end
30
-
31
- graph.render :to => graph_file_name, :min_value => 0, :max_value => find_max_y_value, :width => SCRUFFY_WIDTH, :height => SCRUFFY_HEIGHT
32
-
33
- graph
34
- end
35
- end