From 78b253f756cb2aff93dc3291fd46d419e54861ab Mon Sep 17 00:00:00 2001 From: Manuel CISSÉ Date: Tue, 23 Feb 2010 17:14:49 +0100 Subject: add the possibility to generate and use default colors for graphs --- type/Default.class.php | 31 +++++++++++++++++++++++++++++-- type/GenericStacked.class.php | 8 ++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'type') diff --git a/type/Default.class.php b/type/Default.class.php index 0eab459..48460f3 100644 --- a/type/Default.class.php +++ b/type/Default.class.php @@ -32,6 +32,30 @@ 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); + } + $p++; + } + } + # parse $_GET values function parse_get() { $this->args = array( @@ -204,16 +228,19 @@ class Type_Default { } if(count($this->files)<=1) { + $c = 0; foreach ($sources as $source) { - $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($this->colors[$source])); + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; + $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($color)); $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), 'ffffff'); break; # only 1 area to draw } } + $c = 0; foreach ($sources as $source) { $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; - $color = is_array($this->colors) ? $this->colors[$source]: $this->colors; + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); diff --git a/type/GenericStacked.class.php b/type/GenericStacked.class.php index 89e9f65..e9213de 100644 --- a/type/GenericStacked.class.php +++ b/type/GenericStacked.class.php @@ -26,14 +26,18 @@ class Type_GenericStacked extends Type_Default { $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i+1])); } + $c = 0; foreach ($sources as $source) { - $color = $this->get_faded_color($this->colors[$source]); + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; + $color = $this->get_faded_color($color); $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color); } + $c = 0; foreach ($sources as $source) { $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; - $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($this->colors[$source]), $dsname); + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; + $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); -- cgit v1.1