From b1e34bd1868be418ef5ec26683a8d07f22cebd51 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 5 Feb 2011 20:01:26 +0100 Subject: replace function generate_colors by rainbow_colors When no colors are defined they will be generated by function rainbow_colors. --- type/Default.class.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'type') diff --git a/type/Default.class.php b/type/Default.class.php index 57d0bf3..0930fe3 100644 --- a/type/Default.class.php +++ b/type/Default.class.php @@ -34,27 +34,25 @@ class Type_Default { $this->identifiers = $this->file2identifier($this->files); } - function generate_colors() { - $base = array( array(255, 0, 0), - array( 0, 255, 0), - array( 0, 0, 255), - array(255, 120, 0), - array(255, 0, 120), - array( 0, 255, 120), - array(120, 255, 0), - array(120, 0, 255), - array( 0, 120, 255)); - - $this->colors = array(); - $n = 0; - $p = 0; - foreach($base as $b) { - $n = $p; - for($i = 100; $i >= 20; $i -= 30) { - $this->colors[$n] = sprintf('%02x%02x%02x', $b[0] * $i / 100, $b[1] * $i / 100, $b[2] * $i / 100); - $n += count($base); + function rainbow_colors() { + $sources = count($this->rrd_get_sources()); + foreach ($this->rrd_get_sources() as $ds) { + # hue (saturnation=1, value=1) + $h = 360 - ($c * (330/($sources-1))); + + $h = ($h %= 360) / 60; + $f = $h - floor($h); + $q[0] = $q[1] = 0; + $q[2] = 1*(1-1*(1-$f)); + $q[3] = $q[4] = 1; + $q[5] = 1*(1-1*$f); + + $hex = ''; + foreach(array(4,2,0) as $j) { + $hex .= sprintf('%02x', $q[(floor($h)+$j)%6] * 255); } - $p++; + $this->colors[$ds] = $hex; + $c++; } } @@ -141,6 +139,9 @@ class Type_Default { } function rrd_graph($debug=false) { + if (!$this->colors) + $this->rainbow_colors(); + $graphdata = $this->rrd_gen_graph(); if(!$debug) { -- cgit v1.1