Skip to content

Instantly share code, notes, and snippets.

@komeda-shinji
Last active August 29, 2015 14:18
Show Gist options
  • Save komeda-shinji/38e051e03705f24a4ee0 to your computer and use it in GitHub Desktop.
Save komeda-shinji/38e051e03705f24a4ee0 to your computer and use it in GitHub Desktop.
Zabbixのグラデーションラインは値域が負の時のことを考えていない ref: http://qiita.com/komeda-shinji/items/0591f495cda8ff1c9c09
--- 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment