--- frontends/php/include/classes/class.cchart.php.orig 2012-08-10 13:00:22.000000000 +0400 +++ frontends/php/include/classes/class.cchart.php 2012-08-31 22:32:09.000000000 +0400 @@ -1334,6 +1334,7 @@ $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_LEFT]; $units = null; + $valuemapid = null; $unitsLong = null; for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) { @@ -1343,6 +1344,17 @@ elseif ($this->items[$item]['units'] != $units) { $units = false; } + if (!empty($this->items[$item]['valuemapid']) && $this->items[$item]['valuemapid'] > 0) { + if (is_null($valuemapid)) { + $valuemapid = $this->items[$item]['valuemapid']; + } + elseif ($this->items[$item]['valuemapid'] != $valuemapid) { + $valuemapid = false; + } + } + else { + $valuemapid = false; + } } } @@ -1390,7 +1402,16 @@ if (bccomp(bcadd($val, bcdiv($step,2)), $maxY) == 1) { continue; } - $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS); + + if (zbx_empty($units) && !empty($valuemapid)) { + $str = convert_units($val, '', ITEM_CONVERT_WITH_UNITS); + $str = applyValueMap($str, $valuemapid, false); + if (zbx_empty($str)) + continue; + } + else { + $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS); + } $dims = imageTextSize(8, 0, $str); @@ -1411,7 +1432,15 @@ } } - $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS); + if (zbx_empty($units) && !empty($valuemapid)) { + $str = convert_units($maxY, '', ITEM_CONVERT_WITH_UNITS); + $str = applyValueMap($str, $valuemapid, false); + if (zbx_empty($str)) + return; + } + else { + $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS); + } $dims = imageTextSize(8, 0, $str); imageText( $this->im, @@ -1444,6 +1473,7 @@ $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT]; $units = null; + $valuemapid = null; $unitsLong = null; for ($item = 0; $item < $this->num; $item++) { if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) { @@ -1453,6 +1483,17 @@ elseif ($this->items[$item]['units'] != $units) { $units = false; } + if (!empty($this->items[$item]['valuemapid']) && $this->items[$item]['valuemapid'] > 0) { + if (is_null($valuemapid)) { + $valuemapid = $this->items[$item]['valuemapid']; + } + elseif ($this->items[$item]['valuemapid'] != $valuemapid) { + $valuemapid = false; + } + } + else { + $valuemapid = false; + } } } @@ -1501,7 +1542,15 @@ continue; } - $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS); + if (zbx_empty($units) && !empty($valuemapid)) { + $str = convert_units($val, '', ITEM_CONVERT_WITH_UNITS); + $str = applyValueMap($str, $valuemapid, false); + if (zbx_empty($str)) + continue; + } + else { + $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS); + } // marker Y coordinate $dims = imageTextSize(8, 0, $str); @@ -1521,7 +1570,15 @@ } } - $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS); + if (zbx_empty($units) && !empty($valuemapid)) { + $str = convert_units($maxY, '', ITEM_CONVERT_WITH_UNITS); + $str = applyValueMap($str, $valuemapid, false); + if (zbx_empty($str)) + return; + } + else { + $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS); + } imageText( $this->im, 8, @@ -1793,10 +1850,18 @@ $legend->addCell($colNum, array('text' => $item_caption)); $legend->addCell($colNum, array('text' => '['.$fnc_name.']')); + if (!empty($this->items[$i]['valuemapid']) && zbx_empty($this->items[$i]['units'])) { + $legend->addCell($colNum, array('text' => applyValueMap(convert_units($this->getLastValue($i), '', ITEM_CONVERT_WITH_UNITS), $this->items[$i]['valuemapid']), 'align' => 2)); + $legend->addCell($colNum, array('text' => applyValueMap(convert_units(min($data['min']), '', ITEM_CONVERT_WITH_UNITS), $this->items[$i]['valuemapid']), 'align' => 2)); + $legend->addCell($colNum, array('text' => applyValueMap(convert_units($data['avg_orig'], '', ITEM_CONVERT_WITH_UNITS), $this->items[$i]['valuemapid']), 'align' => 2)); + $legend->addCell($colNum, array('text' => applyValueMap(convert_units(max($data['max']), '', ITEM_CONVERT_WITH_UNITS), $this->items[$i]['valuemapid']), 'align' => 2)); + } + else { $legend->addCell($colNum, array('text' => convert_units($this->getLastValue($i), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units(min($data['min']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units($data['avg_orig'], $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); $legend->addCell($colNum, array('text' => convert_units(max($data['max']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2)); + } } else { $legend->addCell($colNum, array('text' => $item_caption)); --- frontends/php/include/valuemap.inc.php.orig 2012-08-10 13:00:23.000000000 +0400 +++ frontends/php/include/valuemap.inc.php 2012-08-31 22:31:58.000000000 +0400 @@ -247,27 +247,41 @@ * * @return string */ -function applyValueMap($value, $valueMapId) { +function applyValueMap($value, $valueMapId, $show_initial_value = true) { if ($valueMapId < 1) { return $value; } static $valueMaps = array(); - if (isset($valueMaps[$valueMapId][$value])) { - return $valueMaps[$valueMapId][$value]; - } - - $dbMappings = DBselect( - 'SELECT m.newvalue'. - ' FROM mappings m'. - ' WHERE m.valuemapid='.$valueMapId. + if (!isset($valueMaps[$valueMapId][$value])) { + $dbMappings = DBselect( + 'SELECT m.newvalue'. + ' FROM mappings m'. + ' WHERE m.valuemapid='.$valueMapId. ' AND m.value='.zbx_dbstr($value) - ); - if ($mapping = DBfetch($dbMappings)) { - $valueMaps[$valueMapId][$value] = $mapping['newvalue'].' '.'('.$value.')'; - return $valueMaps[$valueMapId][$value]; + ); + if ($mapping = DBfetch($dbMappings)) { + $valueMaps[$valueMapId][$value] = $mapping['newvalue']; + } + else { + $valueMaps[$valueMapId][$value] = ''; + } + } + if (zbx_empty($valueMaps[$valueMapId][$value])) { + if ($show_initial_value) { + return $value; + } + else { + return ''; + } + } + else { + if ($show_initial_value) { + return $valueMaps[$valueMapId][$value] . ' ' . '(' . $value . ')'; + } + else { + return $valueMaps[$valueMapId][$value]; + } } - - return $value; }