Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of numeric report charts. #3894

Merged
merged 19 commits into from Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1900db9
Reporting charts: allow creating concrete number charts.
martinpovolny Apr 28, 2015
bc54120
Fix chart type for jqplot report charts.
martinpovolny Aug 18, 2015
cbd21bf
Charts: fix regression in pie charts.
martinpovolny Aug 18, 2015
d622fc0
Charts: add a spec for count bases 2dim chart.
martinpovolny Aug 18, 2015
3542661
Report editor: handle "null" value for aggreg fun in summary.
martinpovolny Aug 20, 2015
d3713ce
Report editor: Summary set to counts does not allow value-based charts.
martinpovolny Aug 20, 2015
c0ca936
Report charts: styling and lighlighing for pie charts.
martinpovolny Aug 20, 2015
6955aa8
Report charts: Rubocop styling fixes.
martinpovolny Aug 21, 2015
571509e
Report charts: implement 2dim numeric charts.
martinpovolny Aug 27, 2015
09e526c
Report charts: fix pie highlighter.
martinpovolny Aug 27, 2015
11520d3
Charts: use truncute to shorten texts.
martinpovolny Aug 27, 2015
a75d08f
Charts: address Rubocop complaints.
martinpovolny Aug 27, 2015
f979296
Report editor: address Rubocop complaints.
martinpovolny Aug 28, 2015
200c378
Report editor: disallow value charts when summary changed.
martinpovolny Aug 31, 2015
74f62ec
Report charts: fix styling for count-based 2dim charts.
martinpovolny Aug 31, 2015
ee7f292
Report editor: show nice field names for chart data column.
martinpovolny Sep 3, 2015
473c296
Charting: remove "2D" from chart names.
martinpovolny Sep 4, 2015
93ee3c4
Report charts: add more styling for count based 1dim charts.
martinpovolny Sep 4, 2015
97ceb99
Report charts: handle empty keys in 2dim numeric chart.
martinpovolny Sep 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should highligh be spelled highlight?

return plot.series[seriesIndex].data[pointIndex][0] + ': ' +
plot.series[seriesIndex].data[pointIndex][1];
}

function jqplot_pie_highligh(str, seriesIndex, pointIndex, plot) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should highligh be spelled highlight?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll look into it.

Also In master we are scoping all the javascript functions under ManageIQ.whatever context. So I will have to touch this area soon. But we do not have the scoping in production so I have to backport this first.

Also I still have to use @himdel #4003 and axis ticks formating.

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