Class: Ruport::Formatter::Graph::OFC
- Inherits:
-
Ruport::Formatter
- Object
- Ruport::Formatter
- Ruport::Formatter::Graph::OFC
- Defined in:
- lib/ruport/util/graph/o_f_c.rb
Overview
This class implements the open flash chart engine for Ruport.
Depend of the OpenFlashChart plugin
Options
-
title #=> Title of the Graph
-
title_style #=> Style of the title
-
bg_color #=> ‘#DFFFDF’
-
y_label_steps #=>
-
x_tick_size #=>
-
tool_tips #=>
-
x_axis_3d #=>
-
y_right_min #=>
-
y_right_max #=>
-
attach_to_y_right_axis #=>
-
x_labels #=>
-
y_max #=>
-
y_min #=>
-
x_axis_steps #=> 3
X Label Style :
-
label_style #=>
-
x_label_color #=> ”
-
x_orientation #=> 0
-
x_label_step #=> -1
-
x_label_grid_color #=> ”
X Legend Text :
-
x_legend_text #=>
-
x_legend_size #=> -1
-
x_legend_color #=> ”
X Legend Text :
-
y_legend_text #=>
-
y_legend_size #=> -1
-
y_legend_color #=> ”
Y Label Style :
-
y_label_size #=>
-
y_label_color #=> ”
X Label Style :
-
x_label_size #=>
-
x_label_color #=> ”
-
x_label_orientation #=> 0
-
x_label_step #=> -1
-
x_label_grid_color #=> ”
Y Right Label Style :
-
y_right_label_size #=>
-
y_right_label_color #=> ”
Y Right Legend Text :
-
y_right_legend_text #=>
-
y_right_legend_size #=> -1
-
y_right_legend_color #=> ”
Background Image :
-
bg_image #=>
-
bg_image_x #=> ‘center’
-
bg_image_y #=> ‘center’
Inner background Color
-
inner_bg_color #=>
-
inner_bg_color2 #=> ”
-
inner_bg_angle #=> -1
Chart Type :
-
chart_type : Table of table, with the first cell, the type of the chart, and the other cells parameters
-
line => (width, color=”, text=”, size=-1, circles=-1)
-
line_dot => (width, dot_size, color, text=”, font_size=-1)
-
line hollow => (width, dot_size, color, text=”, font_size=-1)
-
bar => (alpha, color, text=”, font_size=-1)
-
bar_3d => (alpha, color, text=”, font_size=-1)
-
bar_fade => (alpha, color, text=”, font_size=-1)
-
bar_glass => (alpha, color, color_outline, text=”, font_size=-1)
-
bar_filled => (alpha, color, color_outline, text=”, font_size=-1)
-
area_hollow => (width, dot_size, color, alpha, text=”, font_size=-1)
-
pie => (alpha, line_color, label_color)
Plugin hooks called (in order)
-
prepare_graph
-
build_graph
-
finalize_graph
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Attribute of the OpenFlashChart object.
Instance Method Summary collapse
-
#build_graph ⇒ Object
Build the Graph.
-
#initialize ⇒ OFC
constructor
Initialize the OpenFlashChart.
-
#prepare_graph ⇒ Object
Prepare the Graph.
Constructor Details
#initialize ⇒ OFC
Initialize the OpenFlashChart
93 94 95 96 97 |
# File 'lib/ruport/util/graph/o_f_c.rb', line 93 def initialize Ruport.quiet { require 'open_flash_chart' } @graph = OpenFlashChart.new @graph_pie = false end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Attribute of the OpenFlashChart object
90 91 92 |
# File 'lib/ruport/util/graph/o_f_c.rb', line 90 def graph @graph end |
Instance Method Details
#build_graph ⇒ Object
Build the Graph
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ruport/util/graph/o_f_c.rb', line 177 def build_graph if (@graph_pie) @graph.pie_values(data.data.first.to_a, (.x_labels || data.column_names).map{|l| l.nil? ? '' : l}) else data.each_with_index do |r,i| @graph.set_data(r.to_a) end end output << @graph.render end |
#prepare_graph ⇒ Object
Prepare the Graph
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ruport/util/graph/o_f_c.rb', line 100 def prepare_graph @graph.title(.title || "#{.style} Report", .title_style || 'font-weight:bold; font-size: 25px;') @graph.set_bg_color(.bg_color || '#DFFFDF') @graph.set_y_label_steps(.y_label_steps) if .y_label_steps @graph.set_x_tick_size(.x_tick_size) if .x_tick_size @graph.set_tool_tips(.tool_tips) if .tool_tips @graph.set_x_axis_3d(.x_axis_3d) if .x_axis_3d @graph.set_y_right_min(.y_right_min) if .y_right_min @graph.set_y_right_max(.y_right_max) if .y_right_max @graph.attach_to_y_right_axis(.attach_to_y_right_axis) if .attach_to_y_right_axis if .x_label_size @graph.set_x_label_style(.x_label_size, .x_label_color || '', .x_orientation || 0, .x_label_step || -1, .x_label_grid_color || '') end if .x_legend_text @graph.set_x_legend(.x_legend_text, .x_legend_size || -1, .x_legend_color || '') end if .y_legend_text @graph.set_y_legend(.y_legend_text, .y_legend_size || -1, .y_legend_color || '') end if .y_label_size @graph.set_y_label_style( .y_label_size, .y_label_color || '') end if .x_label_size @graph.set_x_label_style( .x_label_size, .x_label_color || '', .x_label_orientation || 0, .x_label_step || -1, .x_label_grid_color || '') end if .y_right_label_size @graph.set_y_right_label_style( .y_right_label_size, .y_right_label_color || '') end if .y_right_legend_text @graph.set_y_right_legend(.y_right_legend_text, .y_right_legend_size || -1, .y_right_legend_color || '') end if .bg_image @graph.set_bg_image(.bg_image, .bg_image_x || 'center', .bg_image_y || 'center') end if .inner_bg_color @graph.set_inner_background(.inner_bg_color, .inner_bg_color2 || '', .inner_bg_angle || -1) end (.chart_types || []).each{ |ct| if [:line, :line_dot, :line_hollow, :bar, :bar_3d, :bar_fade, :bar_glass, :bar_filled, :area_hollow].include?(ct[0]) @graph.send(*ct) end if ct[0] == :pie @graph_pie = true @graph.pie_slice_colors(.pie_slice_colors) if .pie_slice_colors @graph.pie(ct[1] || 50, ct[2] || '#DFFFDF', ct[3] || '#DFFFDF') end } @graph.set_x_labels((.x_labels || data.column_names).map{|l| l.nil? ? '' : l}) all_val = data.inject([]) {|ac, t| ac += t.to_a }.flatten @graph.set_y_max(.y_max || all_val.max) @graph.set_y_min(.y_min || all_val.min) @graph.set_x_axis_steps(.x_axis_step || 3) end |