Skip to content

Commit

Permalink
Merge pull request #3894 from martinpovolny/report_charts3
Browse files Browse the repository at this point in the history
Initial implementation of numeric report charts.
  • Loading branch information
Dan Clarizio committed Sep 8, 2015
2 parents 495fc20 + 97ceb99 commit bb89929
Show file tree
Hide file tree
Showing 16 changed files with 809 additions and 193 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -44,6 +44,8 @@
//= require jqplot-plugins/jqplot.highlighter
//= require jqplot-plugins/jqplot.cursor
//= require jqplot-plugins/jqplot.enhancedLegendRenderer
//= require jqplot-plugins/jqplot.canvasAxisTickRenderer
//= require jqplot-plugins/jqplot.canvasTextRenderer
//= require miq_jqplot
//= require jquery/jquery-ui-1.9.2.custom.min
//= require bootstrap
Expand Down
24 changes: 24 additions & 0 deletions app/assets/javascripts/miq_jqplot.js
Expand Up @@ -17,6 +17,9 @@ function _jqplot_eval_option(data, option) {
function jqplot_process_options(data) {
$.each([ 'seriesDefaults.renderer',
'axes.xaxis.renderer',
'axes.yaxis.tickRenderer',
'axes.yaxis.renderer',
'axes.xaxis.tickRenderer',
'legend.renderer',
'highlighter.tooltipContentEditor' ], function (index, key) {
_jqplot_eval_option(data, key);
Expand Down Expand Up @@ -68,6 +71,27 @@ function jqplot_redraw_charts() {
}
}

function jqplot_pie_highligh_values(str, seriesIndex, pointIndex, plot) {
return plot.series[seriesIndex].data[pointIndex][0] + ': ' +
plot.series[seriesIndex].data[pointIndex][1];
}

function jqplot_pie_highligh(str, seriesIndex, pointIndex, plot) {
return plot.series[seriesIndex].data[pointIndex][0];
}

function jqplot_xaxis_tick_highlight(str, seriesIndex, pointIndex, plot) {
return plot.options.axes.xaxis.ticks[pointIndex] + ' / ' +
plot.options.series[seriesIndex].label + ': ' +
str;
}

function jqplot_yaxis_tick_highlight(str, seriesIndex, pointIndex, plot) {
return plot.options.axes.yaxis.ticks[pointIndex] + ' / ' +
plot.options.series[seriesIndex].label + ': ' +
str;
}

$(document).ready(function(){
$(window).resize(function() {
setTimeout(jqplot_redraw_charts, 500);
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/report_controller.rb
Expand Up @@ -9,6 +9,8 @@ class ReportController < ApplicationController
include_concern 'Usage'
include_concern 'Widgets'

include ReportHelper

before_filter :check_privileges
before_filter :get_session_data
after_filter :cleanup_action
Expand Down
257 changes: 144 additions & 113 deletions app/controllers/report_controller/reports/editor.rb

Large diffs are not rendered by default.

54 changes: 40 additions & 14 deletions app/helpers/report_helper.rb
@@ -1,19 +1,19 @@
module ReportHelper
STYLE_CLASSES = {
:miq_rpt_red_text => "Red Text",
:miq_rpt_red_bg => "Red Background",
:miq_rpt_yellow_text => "Yellow Text",
:miq_rpt_yellow_bg => "Yellow Background",
:miq_rpt_green_text => "Green Text",
:miq_rpt_green_bg => "Green Background",
:miq_rpt_blue_text => "Blue Text",
:miq_rpt_blue_bg => "Blue Background",
:miq_rpt_maroon_text => "Light Blue Text",
:miq_rpt_maroon_bg => "Light Blue Background",
:miq_rpt_purple_text => "Purple Text",
:miq_rpt_purple_bg => "Purple Background",
:miq_rpt_gray_text => "Gray Text",
:miq_rpt_gray_bg => "Gray Background"
:miq_rpt_red_text => "Red Text",
:miq_rpt_red_bg => "Red Background",
:miq_rpt_yellow_text => "Yellow Text",
:miq_rpt_yellow_bg => "Yellow Background",
:miq_rpt_green_text => "Green Text",
:miq_rpt_green_bg => "Green Background",
:miq_rpt_blue_text => "Blue Text",
:miq_rpt_blue_bg => "Blue Background",
:miq_rpt_maroon_text => "Light Blue Text",
:miq_rpt_maroon_bg => "Light Blue Background",
:miq_rpt_purple_text => "Purple Text",
:miq_rpt_purple_bg => "Purple Background",
:miq_rpt_gray_text => "Gray Text",
:miq_rpt_gray_bg => "Gray Background"
}

def visibility_options(widget)
Expand All @@ -25,4 +25,30 @@ def visibility_options(widget)
_("By %{typ}: %{values}") % {:typ => typ.to_s.titleize, :values => values.join(',')}
end
end

def chart_fields_options
if @edit[:new][:group] != 'No'
groupings = @edit[:new][:col_options].find_all do |_field, col_options|
col_options[:grouping].present? && !col_options[:grouping].empty?
end
groupings.each_with_object([]) do |(field, col_options), options|
model = @edit[:new][:model]
col_options[:grouping].each do |fun|
field_label = @edit[:new][:headers]["#{model}-#{field}"]
options << ["#{field_label} (#{fun.to_s.titleize})", "#{model}-#{field}:#{fun}"]
end
end
else
@edit[:new][:field_order].find_all do |f|
ci = MiqReport.get_col_info(f.last.split("__").first)
ci[:numeric]
end
end
end

# We allow value-based charts when we have aggregations or
# simple charts w/o summary.
def chart_mode_values_allowed?
@edit[:new][:group] != 'Counts'
end
end
5 changes: 3 additions & 2 deletions app/models/miq_report/generator/aggregation.rb
@@ -1,9 +1,10 @@
module MiqReport::Generator::Aggregation
def build_subtotals
def build_subtotals(all_dims = false)
return unless self.group == "c" || (!self.col_options.blank? && !col_options.find {|c,h| h.has_key?(:grouping)}.blank?)
return if self.sortby.blank?

self.extras[:grouping] = self.generate_subtotals(self.table, self.sortby.first, self.col_options)
grouping_keys = all_dims ? self.sortby : self.sortby.first
self.extras[:grouping] = self.generate_subtotals(self.table, grouping_keys, self.col_options)
end

def generate_subtotals(table, group_keys, options)
Expand Down
29 changes: 28 additions & 1 deletion app/views/report/_form_chart.html.haml
Expand Up @@ -8,13 +8,40 @@
= _('Choose a chart type')
%td
= select_tag('chosen_graph',
options_for_select(["<No chart>"] + Charting.chart_names_for_select, @edit[:new][:graph_type]),
options_for_select([_("<No chart>")] + Charting.chart_names_for_select, @edit[:new][:graph_type]),
:multiple => false,
:class => "widthed",
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
- unless @edit[:new][:graph_type].blank?
%tr
%td.key
= _('Chart mode')
%td
- if chart_mode_values_allowed?
= select_tag('chart_mode',
options_for_select([[_('Counts'), 'counts'], [_('Values'), 'values']], @edit[:new][:chart_mode]),
:multiple => false,
:class => "widthed",
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
- else
= _('Counts')
= hidden_field_tag('chart_mode', 'counts')
%tr
- if @edit[:new][:chart_mode] == 'values'
%td.key
= _('Data column')
%td
= select_tag('chart_column',
options_for_select(chart_fields_options, @edit[:new][:chart_column]),
:multiple => false,
:class => "widthed",
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
"data-miq_observe" => {:url => url}.to_json)
%tr
%td.key
= _('Top values to show')
Expand Down
8 changes: 4 additions & 4 deletions lib/charting/jqplot.rb
Expand Up @@ -40,7 +40,7 @@ def basic_chart(chart_type)
:options => {
:seriesDefaults => {
:renderer => 'jQuery.jqplot.BarRenderer',
:rendererOptions => {:barDirection => 'horizontal'},
:rendererOptions => {:barDirection => 'horizontal', :barWidth => 5},
},
:series => []
},
Expand All @@ -52,7 +52,7 @@ def basic_chart(chart_type)
:stackSeries => true,
:seriesDefaults => {
:renderer => 'jQuery.jqplot.BarRenderer',
:rendererOptions => {:barDirection => 'horizontal'},
:rendererOptions => {:barDirection => 'horizontal', :barWidth => 5},
},
:series => []
},
Expand All @@ -63,7 +63,7 @@ def basic_chart(chart_type)
:options => {
:seriesDefaults => {
:renderer => 'jQuery.jqplot.BarRenderer',
:rendererOptions => {:barDirection => 'vertical'},
:rendererOptions => {:barDirection => 'vertical', :barWidth => 5},
},
:series => []
},
Expand All @@ -75,7 +75,7 @@ def basic_chart(chart_type)
:stackSeries => true,
:seriesDefaults => {
:renderer => 'jQuery.jqplot.BarRenderer',
:rendererOptions => {:barDirection => 'vertical'},
:rendererOptions => {:barDirection => 'vertical', :barWidth => 5},
},
:series => []
},
Expand Down
12 changes: 6 additions & 6 deletions lib/charting/jqplot_charting.rb
Expand Up @@ -40,12 +40,12 @@ def chart_names_for_select
end

CHART_NAMES = [
["Bars (2D)", "Bar"],
["Bars, Stacked (2D)", "StackedBar"],
["Columns (2D)", "Column"],
["Columns, Stacked (2D)", "StackedColumn"],
["Donut (2D)", "Donut"],
["Pie (2D)", "Pie"],
["Bars", "Bar"],
["Bars, Stacked", "StackedBar"],
["Columns", "Column"],
["Columns, Stacked", "StackedColumn"],
["Donut", "Donut"],
["Pie", "Pie"],
]

def chart_themes_for_select
Expand Down

0 comments on commit bb89929

Please sign in to comment.