diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-05 12:15:43 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-12-05 12:15:43 +0000 |
| commit | 3265938a7cd0ef277bfc550ff47b60ed71b417de (patch) | |
| tree | 308a9561fd97e3a2b449d5a36ad33f9db3552fbd /frontends/php/include/classes | |
| parent | f65cf979409619d9de7174926e51c995f145017a (diff) | |
| download | zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.tar.gz zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.tar.xz zabbix-3265938a7cd0ef277bfc550ff47b60ed71b417de.zip | |
- improved editing of graphs (Eugene)
- developed 'Color picker' (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3567 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/classes')
| -rw-r--r-- | frontends/php/include/classes/ccolor.inc.php | 219 | ||||
| -rw-r--r-- | frontends/php/include/classes/ctag.inc.php | 86 | ||||
| -rw-r--r-- | frontends/php/include/classes/graph.inc.php | 89 |
3 files changed, 329 insertions, 65 deletions
diff --git a/frontends/php/include/classes/ccolor.inc.php b/frontends/php/include/classes/ccolor.inc.php new file mode 100644 index 00000000..49d9d2af --- /dev/null +++ b/frontends/php/include/classes/ccolor.inc.php @@ -0,0 +1,219 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + require_once "include/classes/clink.inc.php"; + +?> +<?php + + function insert_show_color_picker_javascript() + { + global $SHOW_COLOR_PICKER_SCRIPT_ISERTTED; + + if($SHOW_COLOR_PICKER_SCRIPT_ISERTTED) return; + $SHOW_COLOR_PICKER_SCRIPT_ISERTTED = true; +?> +<script language="JavaScript" type="text/javascript"> +<!-- + +var color_table = <?php + $table = ''; + + $table .= '<table cellspacing="0" cellpadding="1">'; + $table .= '<tr>'; + /* gray colors */ + foreach(array('0','3','6','8','9','A','C','E','F') as $c) + { + $color = $c.$c.$c.$c.$c.$c; + $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\''.$color.'\')')).'</td>'; + } + $table .= '</tr>'; + + /* other colors */ + $colors = array( + array('r' => 0, 'g' => 0, 'b' => 1), + array('r' => 0, 'g' => 1, 'b' => 0), + array('r' => 1, 'g' => 0, 'b' => 0), + array('r' => 0, 'g' => 1, 'b' => 1), + array('r' => 1, 'g' => 0, 'b' => 1), + array('r' => 1, 'g' => 1, 'b' => 0) + ); + + $brigs = array( + array(0 => '0', 1 => '3'), + array(0 => '0', 1 => '6'), + array(0 => '0', 1 => '9'), + array(0 => '0', 1 => 'C'), + array(0 => '0', 1 => 'F'), + array(0 => '3', 1 => 'F'), + array(0 => '6', 1 => 'F'), + array(0 => '9', 1 => 'F'), + array(0 => 'C', 1 => 'F') + ); + + foreach($colors as $c) + { + $table .= '<tr>'; + foreach($brigs as $br) + { + $r = $br[$c['r']]; + $g = $br[$c['g']]; + $b = $br[$c['b']]; + + $color = $r.$r.$g.$g.$b.$b; + + $table .= '<td>'.unpack_object(new CColorCell(null, $color, 'set_color(\''.$color.'\')')).'</td>'; + } + $table .= '</tr>'; + } + $table .= '</table>'; + $cancel = '<a href="javascript:hide_color_picker()">'.S_CANCEL.'</a>'; + echo '\''.addslashes($table).$cancel.'\''; + unset($table); +?> + +function GetPos(obj) +{ + var left = obj.offsetLeft; + var top = obj.offsetTop;; + while (obj = obj.offsetParent) + { + left += obj.offsetLeft + top += obj.offsetTop + } + return [left,top]; +} + +var color_picker = null; +var curr_lbl = null; +var curr_txt = null; + +function hide_color_picker() +{ + if(!color_picker) return; + + color_picker.style.visibility="hidden" + color_picker.style.left = "-" + ((color_picker.style.width) ? color_picker.style.width : 100) + "px"; + + curr_lbl = null; + curr_txt = null; +} + +function show_color_picker(name) +{ + if(!color_picker) return; + + curr_lbl = document.getElementById('lbl_' + name); + curr_txt = document.getElementById(name); + + var pos = GetPos(curr_lbl); + + color_picker.x = pos[0]; + color_picker.y = pos[1]; + + color_picker.style.left = color_picker.x + "px"; + color_picker.style.top = color_picker.y + "px"; + + color_picker.style.visibility = "visible"; +} + +function create_color_picker() +{ + if(color_picker) return; + + color_picker = document.createElement("div"); + color_picker.setAttribute("id", "color_picker"); + color_picker.innerHTML = color_table; + document.body.appendChild(color_picker); + + hide_color_picker(); +} + +function set_color(color) +{ + if(curr_lbl) curr_lbl.style.background = curr_lbl.style.color = '#' + color; + if(curr_txt) curr_txt.value = color; + + hide_color_picker(); +} + +function set_color_by_name(name, color) +{ + curr_lbl = document.getElementById('lbl_' + name); + curr_txt = document.getElementById(name); + + set_color(color); +} + +if (window.addEventListener) +{ + window.addEventListener("load", create_color_picker, false); +} +else if (window.attachEvent) +{ + window.attachEvent("onload", create_color_picker); +} +else if (document.getElementById) +{ + window.onload = create_color_picker; +} + +//--> +</script> +<?php + } + + class CColorCell extends CLink + { + function CColorCell($name, $value, $action=null) + { + parent::CLink(SPACE.SPACE.SPACE, null); + $this->SetName($name); + $this->AddOption('id', $name); + $this->AddOption('title', '#'.$value); + $this->AddOption('style', 'text-decoration: none; outline: 1px solid black; background-color: #'.$value); + $this->SetAction($action); + } + function SetAction($action=null) + { + if(!isset($action)) return false; + + return $this->SetUrl('javascript:'.$action); + } + } + + class CColor extends CObject + { +/* public */ + function CColor($name,$value) + { + parent::CObject(); + + $lbl = new CColorCell('lbl_'.$name, $value, 'show_color_picker(\''.$name.'\')'); + + $txt = new CTextBox($name,$value,7); + $txt->AddOption('id', $name); + $txt->AddOption('onChange', 'set_color_by_name(\''.$name.'\',this.value)'); + $txt->AddOption('style', 'margin: 0px'); + $this->AddItem(array($txt, $lbl)); + + insert_show_color_picker_javascript(); + } + } +?> diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php index 33c00221..0be0f5f2 100644 --- a/frontends/php/include/classes/ctag.inc.php +++ b/frontends/php/include/classes/ctag.inc.php @@ -51,7 +51,52 @@ return $res; } - class CTag + class CObject + { + function CObject($items=null) + { + $this->items = array(); + if(isset($items)) + { + $this->AddItems($items); + } + } + + function ToString($destroy=true) + { + $res = implode('',$this->items); + if($destroy) $this->Destroy(); + return $res; + } + + function Show($destroy=true) { echo $this->ToString($destroy); } + + function Destroy() + { +### TODO Problem under PHP 5.0 "Fatal error: Cannot re-assign $this in ..." +# $this = null; + $this->CleanItems(); + } + + function CleanItems() { $this->items = array(); } + function ItemsCount() { return count($this->items); } + function AddItem($value) + { + if(is_array($value)) + { + foreach($value as $item) + { + array_push($this->items,unpack_object($item)); + } + } + elseif(!is_null($value)) + { + array_push($this->items,unpack_object($value)); + } + } + } + + class CTag extends CObject { /* private *//* var $tagname; @@ -68,8 +113,9 @@ /* public */ function CTag($tagname=NULL, $paired='no', $body=NULL, $class=null) { + parent::CObject(); + $this->options = array(); - $this->items = array(); if(!is_string($tagname)) { @@ -95,12 +141,6 @@ function ShowStart() { echo $this->StartToString(); } function ShowBody() { echo $this->BodyToString(); } function ShowEnd() { echo $this->EndToString(); } - function Show($destroy=true) { echo $this->ToString($destroy); } - - function Destroy() { -### TODO Problem under PHP 5.0 "Fatal error: Cannot re-assign $this in ..." -# $this = null; - } function StartToString() { @@ -115,9 +155,11 @@ function BodyToString() { $res = $this->tag_body_start; - foreach($this->items as $item) + return $res.parent::ToString(false); + + /*foreach($this->items as $item) $res .= $item; - return $res; + return $res;*/ } function EndToString() { @@ -137,6 +179,8 @@ } function SetName($value) { + if(is_null($value)) return $value; + if(!is_string($value)) { return $this->error("Incorrect value for SetName [$value]"); @@ -195,28 +239,6 @@ { $this->options[$name] = htmlspecialchars(strval($value)); } - function CleanItems() - { - $this->items = array(); - } - function ItemsCount() - { - return count($this->items); - } - function AddItem($value) - { - if(is_array($value)) - { - foreach($value as $item) - { - array_push($this->items,unpack_object($item)); - } - } - elseif(!is_null($value)) - { - array_push($this->items,unpack_object($value)); - } - } function SetEnabled($value='yes') { if((is_string($value) && ($value == 'yes' || $value == 'enabled' || $value=='on') || $value=='1') diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php index 1493a929..83ecbb8e 100644 --- a/frontends/php/include/classes/graph.inc.php +++ b/frontends/php/include/classes/graph.inc.php @@ -220,7 +220,7 @@ if(isset($RGBA[3]) && function_exists("ImageColorExactAlpha") && function_exists("ImageCreateTrueColor") && - @imagecreatetruecolor(1,1) + @ImageCreateTrueColor(1,1) ) { $this->colors[$name] = ImageColorExactAlpha($this->im,$RGBA[0],$RGBA[1],$RGBA[2],$RGBA[3]); @@ -242,7 +242,7 @@ $this->m_showTriggers = $value == 1 ? 1 : 0;; } - function addItem($itemid, $axis, $calc_fnc = CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null) + function AddItem($itemid, $axis, $calc_fnc = CALC_FNC_AVG, $color=null, $drawtype=null, $type=null, $periods_cnt=null) { $this->items[$this->num] = get_item_by_itemid($itemid); $this->items[$this->num]["description"]=item_description($this->items[$this->num]["description"],$this->items[$this->num]["key_"]); @@ -283,7 +283,7 @@ $this->yaxistype=$yaxistype; } - function setSTime($stime) + function SetSTime($stime) { if($stime>200000000000 && $stime<220000000000) { @@ -345,7 +345,7 @@ $this->shiftY-1, $this->sizeX+$this->shiftXleft-1, $this->sizeY+$this->shiftY+1, - $this->colors["Black No Alpha"] + $this->GetColor("Black No Alpha") ); } @@ -353,12 +353,12 @@ { ImageFilledRectangle($this->im,0,0, $this->fullSizeX,$this->fullSizeY, - $this->colors["White"]); + $this->GetColor("White")); if($this->border==1) { - ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->colors["Black No Alpha"]); + ImageRectangle($this->im,0,0,$this->fullSizeX-1,$this->fullSizeY-1,$this->GetColor("Black No Alpha")); } } @@ -407,7 +407,7 @@ $fontnum = 4; } $x=$this->fullSizeX/2-ImageFontWidth($fontnum)*strlen($str)/2; - ImageString($this->im, $fontnum,$x,1, $str , $this->colors["Dark Red No Alpha"]); + ImageString($this->im, $fontnum,$x,1, $str , $this->GetColor("Dark Red No Alpha")); } function setHeader($header) @@ -420,24 +420,24 @@ $this->drawSmallRectangle(); for($i=1;$i<=5;$i++) { - DashedLine($this->im,$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->colors["Gray"]); + DashedLine($this->im,$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->sizeX+$this->shiftXleft,$i*$this->sizeY/6+$this->shiftY,$this->GetColor("Gray")); } for($i=1;$i<=23;$i++) { - DashedLine($this->im,$i*$this->sizeX/24+$this->shiftXleft,$this->shiftY,$i*$this->sizeX/24+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->colors["Gray"]); + DashedLine($this->im,$i*$this->sizeX/24+$this->shiftXleft,$this->shiftY,$i*$this->sizeX/24+$this->shiftXleft,$this->sizeY+$this->shiftY,$this->GetColor("Gray")); } $old_day=-1; for($i=0;$i<=24;$i++) { - ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*$this->period/24) , $this->colors["Black No Alpha"]); + ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date(" H:i",$this->from_time+$i*$this->period/24) , $this->GetColor("Black No Alpha")); $new_day=date("d",$this->from_time+$i*$this->period/24); if( ($old_day != $new_day) ||($i==24)) { $old_day=$new_day; - ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*$this->period/24) , $this->colors["Dark Red No Alpha"]); + ImageStringUp($this->im, 1,$i*$this->sizeX/24+$this->shiftXleft-3, $this->sizeY+$this->shiftY+57, date("m.d H:i",$this->from_time+$i*$this->period/24) , $this->GetColor("Dark Red No Alpha")); } } @@ -462,7 +462,7 @@ $this->shiftY, $this->sizeX+$this->shiftXleft, $this->sizeY+$this->shiftY, - $this->colors["Not Work Period"]); + $this->GetColor("Not Work Period")); $now = time(); if(isset($this->stime)) @@ -494,7 +494,7 @@ $this->shiftY, $x2, $this->sizeY+$this->shiftY, - $this->colors["White"]); + $this->GetColor("White")); $start = find_period_start($periods,$end); } @@ -559,16 +559,39 @@ $trigger['y'], $this->sizeX+$this->shiftXleft, $trigger['y'], - $this->colors[$trigger['color']]); + $this->GetColor($trigger['color'])); } } function drawLogo() { - ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->colors["Gray"]); + ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->GetColor("Gray")); } + function GetColor($color,$alfa=50) + { + if(isset($this->colors[$color])) + return $this->colors[$color]; + + $RGB = array( + hexdec('0x'.substr($color, 0,2)), + hexdec('0x'.substr($color, 2,2)), + hexdec('0x'.substr($color, 4,2)) + ); + + if(isset($alfa) && + function_exists("ImageColorExactAlpha") && + function_exists("ImageCreateTrueColor") && + @ImageCreateTrueColor(1,1) + ) + { + return ImageColorExactAlpha($this->im,$RGB[0],$RGB[1],$RGB[2],$alfa); + } + + return ImageColorAllocate($this->im,$RGB[0],$RGB[1],$RGB[2]); + } + function drawLegend() { $max_host_len=0; @@ -584,11 +607,11 @@ if($this->items[$i]["calc_type"] == GRAPH_ITEM_AGGREGATED) { $fnc_name = "agr(".$this->items[$i]["periods_cnt"].")"; - $color = $this->colors["HistoryMinMax"]; + $color = $this->GetColor("HistoryMinMax"); } else { - $color = $this->colors[$this->items[$i]["color"]]; + $color = $this->GetColor($this->items[$i]["color"]); switch($this->items[$i]["calc_fnc"]) { case CALC_FNC_MIN: $fnc_name = "min"; break; @@ -618,13 +641,13 @@ } ImageFilledRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$color); - ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->colors["Black No Alpha"]); + ImageRectangle($this->im,$this->shiftXleft,$this->sizeY+$this->shiftY+62+12*$i,$this->shiftXleft+5,$this->sizeY+$this->shiftY+5+62+12*$i,$this->GetColor("Black No Alpha")); ImageString($this->im, 2, $this->shiftXleft+9, $this->sizeY+$this->shiftY+(62-5)+12*$i, $str, - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); } if($this->sizeY < 120) return; @@ -636,14 +659,14 @@ $this->sizeY+$this->shiftY+2+62+12*$i, 6, 6, - $this->colors[$trigger["color"]]); + $this->GetColor($trigger["color"])); ImageEllipse($this->im, $this->shiftXleft + 2, $this->sizeY+$this->shiftY+2+62+12*$i, 6, 6, - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); ImageString( $this->im, @@ -651,7 +674,7 @@ $this->shiftXleft+9, $this->sizeY+$this->shiftY+(62-5)+12*$i, $trigger['description'], - $this->colors["Black No Alpha"]); + $this->GetColor("Black No Alpha")); ++$i; } } @@ -1127,7 +1150,7 @@ for($i=0;$i<=6;$i++) { $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," ", STR_PAD_LEFT); - ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->colors["Dark Red No Alpha"]); + ImageString($this->im, 1, 5, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); } } } @@ -1150,7 +1173,7 @@ for($i=0;$i<=6;$i++) { $str = str_pad(convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$units),10," "); - ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->colors["Dark Red No Alpha"]); + ImageString($this->im, 1, $this->sizeX+$this->shiftXleft+2, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, $str, $this->GetColor("Dark Red No Alpha")); } } } @@ -1212,10 +1235,10 @@ { $drawtype = GRAPH_DRAW_TYPE_LINE; - $max_color = $this->colors["HistoryMax"]; - $avg_color = $this->colors["HistoryAvg"]; - $min_color = $this->colors["HistoryMin"]; - $minmax_color = $this->colors["HistoryMinMax"]; + $max_color = $this->GetColor("HistoryMax"); + $avg_color = $this->GetColor("HistoryAvg"); + $min_color = $this->GetColor("HistoryMin"); + $minmax_color = $this->GetColor("HistoryMinMax"); $calc_fnc = CALC_FNC_ALL; } @@ -1223,10 +1246,10 @@ { $drawtype = $this->items[$item]["drawtype"]; - $max_color = $this->colors["ValueMax"]; - $avg_color = $this->colors[$this->items[$item]["color"]]; - $min_color = $this->colors["ValueMin"]; - $minmax_color = $this->colors["ValueMinMax"]; + $max_color = $this->GetColor("ValueMax"); + $avg_color = $this->GetColor($this->items[$item]["color"]); + $min_color = $this->GetColor("ValueMin"); + $minmax_color = $this->GetColor("ValueMinMax"); $calc_fnc = $this->items[$item]["calc_fnc"]; } @@ -1282,7 +1305,7 @@ $end_time=getmicrotime(); $str=sprintf("%0.2f",($end_time-$start_time)); - ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->colors["Gray"]); + ImageString($this->im, 0,$this->fullSizeX-120,$this->fullSizeY-12,"Generated in $str sec", $this->GetColor("Gray")); ImageOut($this->im); ImageDestroy($this->im); |
