Observium_CE/html/includes/graphs/legend.inc.php

79 lines
2.0 KiB
PHP

<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage graphs
* @copyright (C) Adam Armstrong
*
*/
// Here we scale the number of numerical columns shown to make sure we keep the text.
if ($width > 600) {
$data_show = ['lst', 'avg', 'min', 'max', 'tot'];
} elseif ($width > 400) {
$data_show = ['lst', 'avg', 'max', 'tot'];
} elseif ($width > 300) {
$data_show = ['lst', 'avg', 'max', 'tot'];
} else {
$data_show = ['lst', 'avg', 'max'];
}
// Drop total from view if requested not to show
if ($args['nototal'] || $nototal) {
if (($key = array_search('tot', $data_show)) !== FALSE) {
unset($data_show[$key]);
}
}
// Here we scale the length of the description to make sure we keep the numbers
$data_len = safe_count($data_show) * 8;
if ($width > 600) {
$descr_len = 40;
} elseif ($width > 300) {
$descr_len = floor(($width + 42) / 8) - $data_len;
} else {
$descr_len = floor(($width + 42) / 7) - $data_len;
}
// Build the legend headers using the length values previously calculated
if (!isset($unit_text)) {
if ($format == "octets" || $format == "bytes") {
$units = "Bps";
$format = "bytes";
$unit_text = "Bytes/s";
} else {
$units = "bps";
$format = "bits";
$unit_text = "Bits/s";
}
}
if ($legend != 'no') {
$rrd_options .= " COMMENT:'" . rrdtool_escape($unit_text, $descr_len) . "'";
if (in_array("lst", $data_show)) {
$rrd_options .= " COMMENT:' Now'";
}
if (in_array("avg", $data_show)) {
$rrd_options .= " COMMENT:' Avg'";
}
if (in_array("min", $data_show)) {
$rrd_options .= " COMMENT:' Min'";
}
if (in_array("max", $data_show)) {
$rrd_options .= " COMMENT:' Max'";
}
if (in_array("tot", $data_show)) {
$rrd_options .= " COMMENT:' Total'";
}
$rrd_options .= " COMMENT:'\\l'";
$graph_return['legend_lines']++;
}
// EOF