diff options
author | Manuel CISSÉ | 2010-02-23 17:14:49 +0100 |
---|---|---|
committer | Pim van den Berg | 2010-03-01 20:55:15 +0100 |
commit | 78b253f756cb2aff93dc3291fd46d419e54861ab (patch) | |
tree | 1385b191181365b939f81d95296111e364ed6bd6 | |
parent | autofill DS names when not specified (diff) | |
download | apt-panopticon_cgp-78b253f756cb2aff93dc3291fd46d419e54861ab.zip apt-panopticon_cgp-78b253f756cb2aff93dc3291fd46d419e54861ab.tar.gz apt-panopticon_cgp-78b253f756cb2aff93dc3291fd46d419e54861ab.tar.bz2 apt-panopticon_cgp-78b253f756cb2aff93dc3291fd46d419e54861ab.tar.xz |
add the possibility to generate and use default colors for graphs
-rw-r--r-- | type/Default.class.php | 31 | ||||
-rw-r--r-- | type/GenericStacked.class.php | 8 |
2 files changed, 35 insertions, 4 deletions
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 { | |||
32 | $this->identifiers = $this->file2identifier($this->files); | 32 | $this->identifiers = $this->file2identifier($this->files); |
33 | } | 33 | } |
34 | 34 | ||
35 | function generate_colors() { | ||
36 | $base = array( array(255, 0, 0), | ||
37 | array( 0, 255, 0), | ||
38 | array( 0, 0, 255), | ||
39 | array(255, 120, 0), | ||
40 | array(255, 0, 120), | ||
41 | array( 0, 255, 120), | ||
42 | array(120, 255, 0), | ||
43 | array(120, 0, 255), | ||
44 | array( 0, 120, 255)); | ||
45 | |||
46 | $this->colors = array(); | ||
47 | $n = 0; | ||
48 | $p = 0; | ||
49 | foreach($base as $b) { | ||
50 | $n = $p; | ||
51 | for($i = 100; $i >= 20; $i -= 30) { | ||
52 | $this->colors[$n] = sprintf('%02x%02x%02x', $b[0] * $i / 100, $b[1] * $i / 100, $b[2] * $i / 100); | ||
53 | $n += count($base); | ||
54 | } | ||
55 | $p++; | ||
56 | } | ||
57 | } | ||
58 | |||
35 | # parse $_GET values | 59 | # parse $_GET values |
36 | function parse_get() { | 60 | function parse_get() { |
37 | $this->args = array( | 61 | $this->args = array( |
@@ -204,16 +228,19 @@ class Type_Default { | |||
204 | } | 228 | } |
205 | 229 | ||
206 | if(count($this->files)<=1) { | 230 | if(count($this->files)<=1) { |
231 | $c = 0; | ||
207 | foreach ($sources as $source) { | 232 | foreach ($sources as $source) { |
208 | $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($this->colors[$source])); | 233 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; |
234 | $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($color)); | ||
209 | $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), 'ffffff'); | 235 | $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), 'ffffff'); |
210 | break; # only 1 area to draw | 236 | break; # only 1 area to draw |
211 | } | 237 | } |
212 | } | 238 | } |
213 | 239 | ||
240 | $c = 0; | ||
214 | foreach ($sources as $source) { | 241 | foreach ($sources as $source) { |
215 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | 242 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
216 | $color = is_array($this->colors) ? $this->colors[$source]: $this->colors; | 243 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; |
217 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); | 244 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); |
218 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); | 245 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); |
219 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); | 246 | $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 { | |||
26 | $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i+1])); | 26 | $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i+1])); |
27 | } | 27 | } |
28 | 28 | ||
29 | $c = 0; | ||
29 | foreach ($sources as $source) { | 30 | foreach ($sources as $source) { |
30 | $color = $this->get_faded_color($this->colors[$source]); | 31 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; |
32 | $color = $this->get_faded_color($color); | ||
31 | $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color); | 33 | $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color); |
32 | } | 34 | } |
33 | 35 | ||
36 | $c = 0; | ||
34 | foreach ($sources as $source) { | 37 | foreach ($sources as $source) { |
35 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | 38 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
36 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($this->colors[$source]), $dsname); | 39 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; |
40 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); | ||
37 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); | 41 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); |
38 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); | 42 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); |
39 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); | 43 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); |