LoginSignup
0
0

More than 5 years have passed since last update.

Zabbixのグラデーションラインは値域が負の時のことを考えていない

Last updated at Posted at 2015-04-02

Zabbixのグラフでグラデーションラインを使うと、データに負の値があると、なにも考えずに下端からY=0のところまで塗りつぶす。おそらく値域が負域に入るの時のことを考えていないのだろう。

正の時と負の時を考慮して Y=0 の線を中心にグラデーションで描くように修正した。ネストが深くなりすぎるため、インデントはいじっていないのでコードが見づらいけど。

/usr/share/zabbix/include/classes/graphdraw/CLineGraphDraw.php
--- CLineGraphDraw.php  2014-12-16 15:38:26.000000000 +0900
+++ CLineGraphDraw.php  2015-04-03 22:04:19.736847627 +0900
@@ -2245,6 +2245,10 @@
                }
                break;
            case GRAPH_ITEM_DRAWTYPE_GRADIENT_LINE:
+               if ($y1 == $y2 && $y1 == $zero)
+               {
+                   break;
+               }
                imageLine($this->im, $x1, $y1, $x2, $y2, $avg_color); // draw the initial line
                imageLine($this->im, $x1, $y1 - 1, $x2, $y2 - 1, $avg_color);

@@ -2271,9 +2275,15 @@
                    $Yincr = ($diffX > 0) ? (abs($y2 - $y1) / $diffX) : 0;

                    $gy = ($y1 > $y2) ? ($y2 + $Yincr * $i) : ($y2 - $Yincr * $i);
+                   if ($gy <= $zero)
+                   {
                    $steps = $this->sizeY + $this->shiftY - $gy + 1;

                    for ($j = 0; $j < $steps; $j++) {
+                       if (($gy + $j) > $zero)
+                       {
+                           break;
+                       }
                        if (($gy + $j) < ($this->shiftY + $startAlpha)) {
                            $alpha = 0;
                        }
@@ -2284,6 +2294,24 @@
                        $color = imagecolorexactalpha($this->im, $red, $green, $blue, $alpha);
                        imagesetpixel($this->im, $x2 + $i, $gy + $j, $color);
                    }
+                   } else {
+                   $steps = $gy - $zero + 1;
+
+                   for ($j = 0; $j < $steps; $j++) {
+                       if ($gy - $zero - $j > $this->shiftY + $startAlpha) {
+                           $alpha = 0;
+                       }
+                       else {
+                           $alpha = 127 - abs(127 - ($alphaRatio * (2*$zero - $gy + $j - $this->shiftY - $startAlpha)));
+                       }
+                       $color = imagecolorexactalpha($this->im, $red, $green, $blue, $alpha);
+                       imagesetpixel($this->im, $x2 + $i, $gy - $j, $color);
+                       if (($gy - $j) < $zero)
+                       {
+                           break;
+                       }
+                   }
+                   }
                }
            break;
        }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0