Index: include/locales/en_gb.inc.php =================================================================== --- include/locales/en_gb.inc.php (revision 14696) +++ include/locales/en_gb.inc.php (working copy) @@ -2486,6 +2486,8 @@ // class.cookie.js 'S_MAX_COOKIE_SIZE_REACHED' => 'We are sorry, the maximum possible number of elements to remember has been reached.', +// popup_gitem.php + 'S_GITEM_SMOOTHNESS' => 'Smoothness', ); ?> Index: include/schema.inc.php =================================================================== --- include/schema.inc.php (revision 14696) +++ include/schema.inc.php (working copy) @@ -475,6 +475,7 @@ 'calc_fnc' => DB::FIELD_TYPE_INT, 'type' => DB::FIELD_TYPE_INT, 'periods_cnt' => DB::FIELD_TYPE_INT, + 'smoothness' => DB::FIELD_TYPE_INT, ), ), 'graph_theme' => array( Index: include/defines.inc.php =================================================================== --- include/defines.inc.php (revision 14696) +++ include/defines.inc.php (working copy) @@ -318,6 +318,10 @@ define('GRAPH_ITEM_DRAWTYPE_GRADIENT_LINE', 5); define('GRAPH_ITEM_DRAWTYPE_BOLD_DOT', 6); + define('GRAPH_ITEM_SMOOTHNESS', 0); + define('GRAPH_ITEM_SMOOTHNESS_MAX', 9); + define('GRAPH_ITEM_SMOOTHNESS_DEFAULT', 3); + define('MAP_LINK_DRAWTYPE_LINE', 0); define('MAP_LINK_DRAWTYPE_BOLD_LINE', 2); define('MAP_LINK_DRAWTYPE_DOT', 3); Index: include/export.inc.php =================================================================== --- include/export.inc.php (revision 14696) +++ include/export.inc.php (working copy) @@ -218,7 +218,8 @@ 'yaxisside' => '', 'calc_fnc' => '', 'type' => '', - 'periods_cnt' => '' + 'periods_cnt' => '', + 'smoothness' => '' ) ) ); Index: include/graphs.inc.php =================================================================== --- include/graphs.inc.php (revision 14696) +++ include/graphs.inc.php (working copy) @@ -460,7 +460,8 @@ $gitem['yaxisside'], $gitem['calc_fnc'], $gitem['type'], - $gitem['periods_cnt'])) + $gitem['periods_cnt'], + $gitem['smoothness'])) { break; } @@ -611,7 +612,8 @@ $gitem['yaxisside'], $gitem['calc_fnc'], $gitem['type'], - $gitem['periods_cnt'])) + $gitem['periods_cnt'], + $gitem['smoothness'])) { return $result; } @@ -727,13 +729,13 @@ * Comments: !!! Don't forget sync code with C !!! * */ - function add_item_to_graph($graphid,$itemid,$color,$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt){ + function add_item_to_graph($graphid,$itemid,$color,$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt,$smoothness){ $gitemid = get_dbid('graphs_items','gitemid'); $result = DBexecute('insert into graphs_items'. - ' (gitemid,graphid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt)'. + ' (gitemid,graphid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt,smoothness)'. ' values ('.$gitemid.','.$graphid.','.$itemid.','.zbx_dbstr($color).','.$drawtype.','. - $sortorder.','.$yaxisside.','.$calc_fnc.','.$type.','.$periods_cnt.')'); + $sortorder.','.$yaxisside.','.$calc_fnc.','.$type.','.$periods_cnt.','.$smoothness.')'); return ( $result ? $gitemid : $result ); } @@ -862,7 +864,8 @@ 'yaxisside' => $db_gitem['yaxisside'], 'calc_fnc' => $db_gitem['calc_fnc'], 'type' => $db_gitem['type'], - 'periods_cnt' => $db_gitem['periods_cnt'] + 'periods_cnt' => $db_gitem['periods_cnt'], + 'smoothness' => $db_gitem['smoothness'] ); } Index: include/classes/class.cchart.php =================================================================== --- include/classes/class.cchart.php (revision 14696) +++ include/classes/class.cchart.php (working copy) @@ -113,7 +113,7 @@ $this->m_showTriggers = ($value==1)?1:0; } - public function addItem($itemid, $axis=GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc=CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null){ + public function addItem($itemid, $axis=GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc=CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null, $smoothness=GRAPH_ITEM_SMOOTHNESS_DEFAULT){ if($this->type == GRAPH_TYPE_STACKED /* stacked graph */) $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; @@ -137,6 +137,7 @@ $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt; + $this->items[$this->num]['smoothness'] = (is_null($smoothness) or $smoothness == 0) ? GRAPH_ITEM_SMOOTHNESS_DEFAULT : $smoothness; if($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) $this->yaxisleft=1; @@ -190,6 +191,30 @@ $this->percentile['right']['percent'] = $percentile; } + private function medianFilter() { + + $args = func_get_args(); + $args = array_pop($args); + + if(!is_array($args)) { + trigger_error('median() requires a list of numbers to operate on or an array of numbers',E_USER_NOTICE); + return false; + } + + sort($args); + + $n = count($args); + $h = intval($n / 2); + + if($n % 2 == 0) { + $median = ($args[$h] + $args[$h-1]) / 2; + } else { + $median = $args[$h]; + } + + return $median; + } + protected function selectData(){ $this->data = array(); @@ -367,6 +392,7 @@ if($first_idx < 0) $first_idx = $ci; // if no data FROM start of graph get current data as first data + for(;$cj > 0; $cj--){ if(($dx < ($this->sizeX/20)) && ($this->type == GRAPH_TYPE_STACKED)){ $curr_data['count'][$ci - ($dx - $cj)] = 1; @@ -402,10 +428,31 @@ } } } + +/* Smoothing graph item */ + + $smoothness = $this->items[$i]['smoothness']; + + if (isset($smoothness) && $smoothness != 0) { + foreach(array('min','max','avg') as $var_name){ + for($k=0; $k < $this->sizeX - $smoothness + 1; $k+=1){ + $var = &$curr_data[$var_name]; + $vars = array(); + for($l = 0; $l <= $smoothness; $l ++){ + array_push($vars, $var[$k + $l]); + } + $var[$k] = $this->medianFilter($vars); + } + } + } + + //*/ // end of missed points calculation } + + // calculte shift for stacked graphs if($this->type == GRAPH_TYPE_STACKED){ for($i=1; $i<$this->num; $i++){ Index: include/js.inc.php =================================================================== --- include/js.inc.php (revision 14696) +++ include/js.inc.php (working copy) @@ -350,7 +350,7 @@ }'); break; case 'add_graph_item': - insert_js('function add_graph_item(formname,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt){ + insert_js('function add_graph_item(formname,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt,smoothness){ var form = window.opener.document.forms[formname]; if(!form){ @@ -366,6 +366,7 @@ window.opener.create_var(form,"new_graph_item[calc_fnc]",calc_fnc); window.opener.create_var(form,"new_graph_item[type]",type); window.opener.create_var(form,"new_graph_item[periods_cnt]",periods_cnt); + window.opener.create_var(form,"new_graph_item[smoothness]",smoothness); form.submit(); close_window(); @@ -373,7 +374,7 @@ }'); break; case 'update_graph_item': - insert_js('function update_graph_item(formname,list_name,gid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt){ + insert_js('function update_graph_item(formname,list_name,gid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt,smoothness){ var form = window.opener.document.forms[formname]; if(!form){ @@ -389,6 +390,7 @@ window.opener.create_var(form,list_name + "[" + gid + "][calc_fnc]",calc_fnc); window.opener.create_var(form,list_name + "[" + gid + "][type]",type); window.opener.create_var(form,list_name + "[" + gid + "][periods_cnt]",periods_cnt); + window.opener.create_var(form,list_name + "[" + gid + "][smoothness]",smoothness); form.submit(); close_window(); Index: chart2.php =================================================================== --- chart2.php (revision 14696) +++ chart2.php (working copy) @@ -122,7 +122,8 @@ $db_data['color'], $db_data['drawtype'], $db_data['type'], - $db_data['periods_cnt'] + $db_data['periods_cnt'], + $db_data['smoothness'] ); } Index: api/classes/class.cgraph.php =================================================================== --- api/classes/class.cgraph.php (revision 14696) +++ api/classes/class.cgraph.php (working copy) @@ -751,6 +751,7 @@ if(isset($gitem['calc_fnc'])) $values['calc_fnc'] = $gitem['calc_fnc']; if(isset($gitem['type'])) $values['type'] = $gitem['type']; if(isset($gitem['periods_cnt'])) $values['periods_cnt'] = $gitem['periods_cnt']; + if(isset($gitem['smoothness'])) $values['smoothness'] = $gitem['smoothness']; $sql = 'INSERT INTO graphs_items ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')'; DBexecute($sql) or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror'); @@ -805,6 +806,7 @@ if(isset($gitem['calc_fnc'])) $values['calc_fnc'] = $gitem['calc_fnc']; if(isset($gitem['type'])) $values['type'] = $gitem['type']; if(isset($gitem['periods_cnt'])) $values['periods_cnt'] = $gitem['periods_cnt']; + if(isset($gitem['smoothness'])) $values['smoothness'] = $gitem['smoothness']; $sql = 'INSERT INTO graphs_items ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')'; DBexecute($sql) or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror'); Index: api/classes/class.cgraphitem.php =================================================================== --- api/classes/class.cgraphitem.php (revision 14696) +++ api/classes/class.cgraphitem.php (working copy) @@ -58,6 +58,7 @@ 'graphids' => null, 'itemids' => null, 'type' => null, + 'smoothness' => null, 'editable' => null, 'nopermissions' => null, // output Index: graphs.php =================================================================== --- graphs.php (revision 14696) +++ graphs.php (working copy) @@ -250,7 +250,8 @@ $new_gitem['yaxisside'] == $data['yaxisside'] && $new_gitem['calc_fnc'] == $data['calc_fnc'] && $new_gitem['type'] == $data['type'] && - $new_gitem['periods_cnt'] == $data['periods_cnt']) + $new_gitem['periods_cnt'] == $data['periods_cnt'] && + $new_gitem['smoothness'] == $data['smoothness']) { $already_exist = true; break; Index: popup_gitem.php =================================================================== --- popup_gitem.php (revision 14696) +++ popup_gitem.php (working copy) @@ -51,9 +51,10 @@ 'calc_fnc'=> array(T_ZBX_INT, O_OPT, null, IN('1,2,4,7,9'), 'isset({save})'), 'type'=> array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), 'isset({save})'), 'periods_cnt'=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,360), 'isset({save})'), - + 'smoothness'=>array(T_ZBX_INT, O_OPT, null, BETWEEN(0,GRAPH_ITEM_SMOOTHNESS_MAX), null), 'only_hostid'=> array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'monitored_hosts'=>array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), + /* actions */ 'add'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), 'save'=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), @@ -70,6 +71,7 @@ $_REQUEST['drawtype'] = get_request('drawtype',0); $_REQUEST['yaxisside'] = get_request('yaxisside',GRAPH_YAXIS_SIDE_DEFAULT); $_REQUEST['sortorder'] = get_request('sortorder',0); + $_REQUEST['smoothness'] = get_request('smoothness',GRAPH_ITEM_SMOOTHNESS_DEFAULT); $graphid = get_request('graphid',false); @@ -99,7 +101,8 @@ $_REQUEST['yaxisside'].",". $_REQUEST['calc_fnc'].",". $_REQUEST['type'].",". - $_REQUEST['periods_cnt'].");\n"; + $_REQUEST['periods_cnt'].",". + $_REQUEST['smoothness'].");\n"; insert_js($script); } @@ -115,7 +118,8 @@ $_REQUEST['yaxisside'].",". $_REQUEST['calc_fnc'].",". $_REQUEST['type'].",". - $_REQUEST['periods_cnt'].");\n"; + $_REQUEST['periods_cnt'].",". + $_REQUEST['smoothness'].");\n"; insert_js($script); } else{ @@ -133,6 +137,7 @@ $calc_fnc = get_request('calc_fnc', 2); $type = get_request('type', 0); $periods_cnt = get_request('periods_cnt', 5); + $smoothness = get_request('smoothness', GRAPH_ITEM_SMOOTHNESS_DEFAULT); $only_hostid = get_request('only_hostid', null); $monitored_hosts = get_request('monitored_hosts', null); @@ -239,6 +244,13 @@ } $frmGItem->addRow(S_COLOR, new CColor('color',$color)); + +/* Added smoothness option */ + $cmbSmooth = new CComboBox('smoothness',$smoothness); + foreach(range(0, GRAPH_ITEM_SMOOTHNESS_MAX) as $cs){ + $cmbSmooth->addItem($cs, $cs); + } + $frmGItem->addRow(S_GITEM_SMOOTHNESS, $cmbSmooth); } if(($graphtype == GRAPH_TYPE_NORMAL) || ($graphtype == GRAPH_TYPE_STACKED)){