Class: Ruport::Formatter::Graph::Amline

Inherits:
Ruport::Formatter show all
Defined in:
lib/ruport/util/graph/amline.rb

Instance Method Summary collapse

Constructor Details

#initializeAmline

Returns a new instance of Amline.



6
7
8
# File 'lib/ruport/util/graph/amline.rb', line 6

def initialize
  Ruport.quiet { require "hpricot" }
end

Instance Method Details

#apply_templateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruport/util/graph/amline.rb', line 40

def apply_template       
  options.templated_settings_proc = lambda do |s|
    s.config do |c|
      c.values.y_left.max = template.y_max
      c.values.y_right.max = template.y_max 
      c.values.y_left.min = template.y_min
      c.values.y_right.min = template.y_min
      c.width = template.width
      c.height = template.height
      c.legend.enabled = template.show_legend
      if template.config
        template.config[c]
      end
    end      
    if template.graph_options
      default = template.graph_options[:_default] || lambda { }
      template.graph_options.each do |k,v|    
        next if k == :_default
        s.graph(k,&default)
        s.graph(k,&v)  
      end
    end
  end
end

#build_graphObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruport/util/graph/amline.rb', line 10

def build_graph
  generate_config_file
  data_out << "<chart>"
  data_out << "<xaxis>"
  data.x_labels.each_with_index do |e,i|
    data_out << %Q{<value xid="#{i}" show="true">#{e}</value>}
  end
  data_out << "</xaxis>"
  data_out << "<graphs>"
  data.each do |r|
    data_out << %Q{<graph gid="#{r.gid}">}
    r.each_with_index do |e,i|
      data_out << %Q{<value xid="#{i}">#{e}</value>}
    end
    data_out << "</graph>"
  end       
  data_out << "</graphs>"

  data_out << "</chart>"

  if options.data_file
    File.open(options.data_file,"w") { |f| f << data_out }
  end

  if options.settings_file
    File.open(options.settings_file,"w") { |f| f << settings_out }
  end

end

#data_outObject



88
89
90
# File 'lib/ruport/util/graph/amline.rb', line 88

def data_out
  @data_out ||= ""
end

#format_settingsObject



80
81
82
# File 'lib/ruport/util/graph/amline.rb', line 80

def format_settings
  options.format_settings || lambda {}
end

#generate_config_fileObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ruport/util/graph/amline.rb', line 66

def generate_config_file
  settings = ::Amline::Settings.new
  data.each do |r|
    settings.add_graph(r.gid)
    settings.graph(r.gid) { |g|
      g.title = r.gid
    }
  end

  options.templated_settings_proc[settings] if options.templated_settings_proc
  format_settings[settings]
  settings_out << settings.to_xml
end

#outputObject



84
85
86
# File 'lib/ruport/util/graph/amline.rb', line 84

def output
  { :data => data_out, :settings => settings_out }
end

#settings_outObject



92
93
94
# File 'lib/ruport/util/graph/amline.rb', line 92

def settings_out
  @settings_out ||= ""
end