lib/seer/area_chart.rb in seer-0.4.0 vs lib/seer/area_chart.rb in seer-0.5.0
- old
+ new
@@ -9,11 +9,11 @@
#
# @series = @data.map{|w| w.widget_stats} # An array of arrays
#
# In your view:
#
- # <div id="chart" class="chart"></div>
+ # <div id="chart"></div>
#
# <%= Seer::visualize(
# @data,
# :as => :area_chart,
# :in_element => 'chart',
@@ -64,33 +64,39 @@
@data_table = []
end
def data_columns #:nodoc:
- _data_columns = " data.addRows(#{data_series.first.map{|d| d.send(data_label)}.uniq.size});\r"
+ _data_columns = " data.addRows(#{data_rows.size});\r"
_data_columns << " data.addColumn('string', 'Date');\r"
data.each do |datum|
_data_columns << " data.addColumn('number', '#{datum.send(series_label)}');\r"
end
_data_columns
end
def data_table #:nodoc:
- _rows = data_series.first.map{|d| d.send(data_label)}.uniq
+ _rows = data_rows
_rows.each_with_index do |r,i|
@data_table << " data.setCell(#{i}, 0,'#{r}');\r"
end
data_series.each_with_index do |column,i|
column.each_with_index do |c,j|
- @data_table << "data.setCell(#{j},#{i+1},#{c.send(data_method)});\r"
+ @data_table << " data.setCell(#{j},#{i+1},#{c.send(data_method)});\r"
end
end
@data_table
end
+
+ def data_rows
+ data_series.inject([]) do |rows, element|
+ rows |= element.map { |e| e.send(data_label) }
+ end
+ end
def nonstring_options #:nodoc:
- [ :axis_font_size, :colors, :enable_tooltip, :height, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width]
+ [ :axis_font_size, :colors, :enable_tooltip, :height, :is_stacked, :legend_font_size, :line_size, :log_scale, :max, :min, :point_size, :reverse_axis, :show_categories, :title_font_size, :tooltip_font_size, :tooltip_height, :tooltip_width, :width]
end
def string_options #:nodoc:
[ :axis_color, :axis_background_color, :background_color, :border_color, :focus_border_color, :legend, :legend_background_color, :legend_text_color, :title, :title_x, :title_y, :title_color ]
end
@@ -105,10 +111,10 @@
var data = new google.visualization.DataTable();
#{data_columns}
#{data_table.to_s}
var options = {};
#{options}
- var container = document.getElementById('chart');
+ var container = document.getElementById('#{self.chart_element}');
var chart = new google.visualization.AreaChart(container);
chart.draw(data, options);
}
</script>
}