Some visual improvements and an option to hide the labels of the pie graphs

(cherry picked from commit 14127df1dc)
This commit is contained in:
Alejandro Gallardo Escobar 2016-05-26 13:47:45 +02:00
parent 5df150bc1b
commit 0490a00506
3 changed files with 28 additions and 37 deletions

View File

@ -688,26 +688,28 @@ function hbar_graph($flash_chart, $chart_data, $width, $height,
function pie3d_graph($flash_chart, $chart_data, $width, $height, function pie3d_graph($flash_chart, $chart_data, $width, $height,
$others_str = "other", $homedir = "", $water_mark = "", $font = '', $others_str = "other", $homedir = "", $water_mark = "", $font = '',
$font_size = '', $ttl = 1, $legend_position = false, $colors = '') { $font_size = '', $ttl = 1, $legend_position = false, $colors = '',
$hide_labels = false) {
return pie_graph('3d', $flash_chart, $chart_data, $width, $height, return pie_graph('3d', $flash_chart, $chart_data, $width, $height,
$others_str, $homedir, $water_mark, $font, $font_size, $ttl, $others_str, $homedir, $water_mark, $font, $font_size, $ttl,
$legend_position, $colors); $legend_position, $colors, $hide_labels);
} }
function pie2d_graph($flash_chart, $chart_data, $width, $height, function pie2d_graph($flash_chart, $chart_data, $width, $height,
$others_str = "other", $homedir="", $water_mark = "", $font = '', $others_str = "other", $homedir="", $water_mark = "", $font = '',
$font_size = '', $ttl = 1, $legend_position = false, $colors = '') { $font_size = '', $ttl = 1, $legend_position = false, $colors = '',
$hide_labels = false) {
return pie_graph('2d', $flash_chart, $chart_data, $width, $height, return pie_graph('2d', $flash_chart, $chart_data, $width, $height,
$others_str, $homedir, $water_mark, $font, $font_size, $ttl, $others_str, $homedir, $water_mark, $font, $font_size, $ttl,
$legend_position, $colors); $legend_position, $colors, $hide_labels);
} }
function pie_graph($graph_type, $flash_chart, $chart_data, $width, function pie_graph($graph_type, $flash_chart, $chart_data, $width,
$height, $others_str = "other", $homedir="", $water_mark = "", $height, $others_str = "other", $homedir="", $water_mark = "",
$font = '', $font_size = '', $ttl = 1, $legend_position = false, $font = '', $font_size = '', $ttl = 1, $legend_position = false,
$colors = '') { $colors = '', $hide_labels = false) {
if (empty($chart_data)) { if (empty($chart_data)) {
return graph_nodata_image($width, $height, 'pie'); return graph_nodata_image($width, $height, 'pie');
@ -746,7 +748,7 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width,
if ($flash_chart) { if ($flash_chart) {
return flot_pie_chart(array_values($chart_data), return flot_pie_chart(array_values($chart_data),
array_keys($chart_data), $width, $height, $water_mark_url, array_keys($chart_data), $width, $height, $water_mark_url,
$font, $font_size, $legend_position, $colors); $font, $font_size, $legend_position, $colors, $hide_labels);
} }
else { else {
//TODO SET THE LEGEND POSITION //TODO SET THE LEGEND POSITION

View File

@ -3,7 +3,7 @@
*/ */
function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height, colors) { function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height, colors, hide_labels) {
var labels = labels.split(separator); var labels = labels.split(separator);
var data = values.split(separator); var data = values.split(separator);
if (colors != '') { if (colors != '') {
@ -21,7 +21,7 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
var label_conf; var label_conf;
if (width < 400) { if (width < 400 || hide_labels) {
label_conf = { label_conf = {
show: false show: false
}; };
@ -93,10 +93,7 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
var plot = $.plot($('#'+graph_id), data, conf_pie); var plot = $.plot($('#'+graph_id), data, conf_pie);
var legends = $('#'+graph_id+' .legendLabel'); var legends = $('#'+graph_id+' .legendLabel');
legends.each(function () { legends.css('font-size', font_size+'pt');
$(this).css('width', $(this).width());
$(this).css('font-size', font_size+'pt');
});
// Events // Events
$('#' + graph_id).bind('plothover', pieHover); $('#' + graph_id).bind('plothover', pieHover);
@ -105,22 +102,17 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
$('#' + graph_id).css('margin-left', 'auto'); $('#' + graph_id).css('margin-left', 'auto');
$('#' + graph_id).css('margin-right', 'auto'); $('#' + graph_id).css('margin-right', 'auto');
function pieHover(event, pos, obj) function pieHover(event, pos, obj) {
{ if (!obj) return;
if (!obj)
return;
index = obj.seriesIndex; index = obj.seriesIndex;
legends.css('font-weight', ''); legends.css('color', '#3F3F3D');
legends.eq(index).css('font-weight', 'bold'); legends.eq(index).css('color', '#000000');
} }
// Reset styles // Reset styles
function resetInteractivity() { function resetInteractivity() {
legends.each(function () { legends.css('color', '#3F3F3D');
// fix the widths so they don't jump around
$(this).css('font-weight', '');
});
} }
if (water_mark) { if (water_mark) {
@ -160,7 +152,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width,
formatter: function(label, series) { formatter: function(label, series) {
return '<div style="font-size:' + font_size + 'pt;' + return '<div style="font-size:' + font_size + 'pt;' +
'text-align:center;padding:2px;color:white;">' + 'text-align:center;padding:2px;color:white;">' +
label + ':' + series.percent.toFixed(2) + '%</div>'; series.percent.toFixed(2) + '%</div>';
}, },
background: { background: {
opacity: 0.5, opacity: 0.5,
@ -229,20 +221,16 @@ function pandoraFlotPieCustom(graph_id, values, labels, width,
$('#' + graph_id).css('margin-left', 'auto'); $('#' + graph_id).css('margin-left', 'auto');
$('#' + graph_id).css('margin-right', 'auto'); $('#' + graph_id).css('margin-right', 'auto');
function pieHover(event, pos, obj) function pieHover(event, pos, obj) {
{ if (!obj) return;
if (!obj)
return;
index = obj.seriesIndex; index = obj.seriesIndex;
legends.css('font-weight', ''); legends.css('color', '#3F3F3D');
legends.eq(index).css('font-weight', 'bold'); legends.eq(index).css('color', '#000000');
} }
function Clickpie(event, pos, obj) function Clickpie(event, pos, obj) {
{ if (!obj) return;
if (!obj)
return;
percent = parseFloat(obj.series.percent).toFixed(2); percent = parseFloat(obj.series.percent).toFixed(2);
valor = parseFloat(obj.series.data[0][1]); valor = parseFloat(obj.series.data[0][1]);
@ -264,7 +252,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width,
function resetInteractivity() { function resetInteractivity() {
legends.each(function () { legends.each(function () {
// fix the widths so they don't jump around // fix the widths so they don't jump around
$(this).css('font-weight', ''); $(this).css('color', '#3F3F3D');
}); });
} }

View File

@ -463,7 +463,8 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
// Prints a FLOT pie chart // Prints a FLOT pie chart
function flot_pie_chart ($values, $labels, $width, $height, $water_mark, function flot_pie_chart ($values, $labels, $width, $height, $water_mark,
$font = '', $font_size = 8, $legend_position = '', $colors = '') { $font = '', $font_size = 8, $legend_position = '', $colors = '',
$hide_labels = false) {
include_javascript_dependencies_flot_graph(); include_javascript_dependencies_flot_graph();
@ -505,8 +506,8 @@ function flot_pie_chart ($values, $labels, $width, $height, $water_mark,
$return .= "<script type='text/javascript'>"; $return .= "<script type='text/javascript'>";
$return .= "pandoraFlotPie('$graph_id', '$values', '$labels', $return .= "pandoraFlotPie('$graph_id', '$values', '$labels',
'$series', '$width', $font_size, $water_mark, '$series', '$width', $font_size, $water_mark, '$separator',
'$separator', '$legend_position', '$height', '$colors')"; '$legend_position', '$height', '$colors', " . json_encode($hide_labels) . ")";
$return .= "</script>"; $return .= "</script>";