Merge branch '2096-shorten_labels_in_hbars' into 'develop'

Fixed label shortener in hbar

See merge request artica/pandorafms!1385
This commit is contained in:
vgilc 2018-03-23 11:18:54 +01:00
commit 4371551a1b
4 changed files with 31 additions and 29 deletions

View File

@ -653,13 +653,13 @@ function hbar_graph($flash_chart, $chart_data, $width, $height,
else { else {
foreach ($chart_data as $key => $value) { foreach ($chart_data as $key => $value) {
if(strlen($key) > 40){ $str_key = io_safe_output($key);
if(strpos($key, ' - ') != -1){ if(strlen($str_key) > 40){
$key_temp = explode(" - ",$key); if(strpos($str_key, ' - ') != -1){
$key_temp[0] = $key_temp[0]." \n"; $key_temp = explode(" - ",$str_key);
$key_temp[0] = $key_temp[0]." <br>";
$key_temp[1]= '...'.substr($key_temp[1],-20); $key_temp[1]= '...'.substr($key_temp[1],-20);
$key2 = $key_temp[0].$key_temp[1]; $key2 = $key_temp[0].$key_temp[1];
io_safe_output($key2);
} }
$chart_data[$key2]['g'] = $chart_data[$key]['g']; $chart_data[$key2]['g'] = $chart_data[$key]['g'];
unset($chart_data[$key]); unset($chart_data[$key]);

View File

@ -419,28 +419,22 @@ function pandoraFlotHBars(graph_id, values, labels, water_mark,
for (i = 0; i < labels_total.length; i++) { for (i = 0; i < labels_total.length; i++) {
var label = labels_total[i][1]; var label = labels_total[i][1];
// var shortLabel = reduceText(label, 25); // var shortLabel = reduceText(label, 25);
var title = ''; var title = label;
// if (label !== shortLabel) { var margin_top = 0;
title = label; if(label.length > 33){
// label = shortLabel; label = reduceText(label, 33);
// }
if(label.length > 30){
if(label.indexOf(" - ")){
var label_temp = label.split(" - ");
}
else if(label.indexOf(" ")){
var label_temp = label.split(" ");
}
else{
var label_temp = '';
label_temp[0] = label.substring(0, (label.length/2));
label_temp[1] = label.substring((label.length/2));
}
label = reduceText(label_temp[0], 20)+"<br>"+reduceText(label_temp[1], 20);
} }
var div_attributes = 'style="font-size:'+font_size+'pt !important;'
format.push([i,'<div style="font-size:'+font_size+'pt !important; word-break:keep-all; max-width: 150px;margin-right:20px;" title="'+title+'" class="'+font+'">' + ' margin: 0; max-width: 150px;'
+ 'margin-right:5px;';
if (label.indexOf("<br>") != -1) {
div_attributes += "min-height: 2.5em;";
}
div_attributes += '" title="'+title+'" class="'+font+'"';
format.push([i,'<div ' + div_attributes + '>'
+ label + label
+ '</div>']); + '</div>']);
} }
@ -2325,8 +2319,9 @@ function add_threshold (data_base, threshold_data, y_min, y_max,
} }
function reduceText (text, maxLength) { function reduceText (text, maxLength) {
if(!text) return text;
if (text.length <= maxLength) return text if (text.length <= maxLength) return text
var firstSlideEnd = parseInt((maxLength - 3) / 2); var firstSlideEnd = parseInt((maxLength - 3)/1.6);
var str_cut = text.substr(0, firstSlideEnd); var str_cut = text.substr(0, firstSlideEnd);
return str_cut + '...' + text.substr(-firstSlideEnd - 3); return str_cut + '...<br>' + text.substr(-firstSlideEnd - 3);
} }

View File

@ -712,7 +712,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font =
$data = array(); $data = array();
foreach ($graph_data as $label => $values) { foreach ($graph_data as $label => $values) {
$labels[] = $label; $labels[] = io_safe_output($label);
$i--; $i--;
foreach ($values as $key => $value) { foreach ($values as $key => $value) {

View File

@ -4627,3 +4627,10 @@ form ul.form_flex li ul li{
#snmp_data .databox { #snmp_data .databox {
border: 0px; border: 0px;
} }
.tickLabel {
white-space: nowrap;
overflow-x: hidden;
line-height: 1.05em!important;
}