2013-02-15 Sergio Martin <sergio.martin@artica.es>
* include/functions_graph.php include/graphs/functions_utils.php: Added a function to calculate the complementary color of a RGB hex code to assign automatically the overlapped graphs colors for bug 3604462 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7663 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
a208e250ad
commit
52de2e48bc
|
@ -1,3 +1,10 @@
|
|||
2013-02-15 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* include/functions_graph.php
|
||||
include/graphs/functions_utils.php: Added a function to calculate
|
||||
the complementary color of a RGB hex code to assign automatically
|
||||
the overlapped graphs colors for bug 3604462
|
||||
|
||||
2013-02-15 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/functions_treeview.php: fixed the cleaned source code.
|
||||
|
|
|
@ -700,6 +700,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
|||
|
||||
global $chart;
|
||||
global $color;
|
||||
global $color_prev;
|
||||
global $legend;
|
||||
global $long_index;
|
||||
global $series_type;
|
||||
|
@ -734,6 +735,10 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
|||
$chart_prev = array_values($chart);
|
||||
$legend_prev = $legend;
|
||||
$series_type_prev = $series_type;
|
||||
$color_prev = $color;
|
||||
foreach($color_prev as $k => $col) {
|
||||
$color_prev[$k]['color'] = '#'.get_complementary_rgb($color_prev[$k]['color']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -760,6 +765,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
|||
}
|
||||
|
||||
$legend = array_merge($legend, $legend_prev);
|
||||
$color = array_merge($color, $color_prev);
|
||||
}
|
||||
|
||||
if ($only_image) {
|
||||
|
@ -2683,6 +2689,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
|
|||
|
||||
global $chart;
|
||||
global $color;
|
||||
global $color_prev;
|
||||
global $legend;
|
||||
global $long_index;
|
||||
global $series_type;
|
||||
|
@ -2712,6 +2719,10 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
|
|||
$chart_prev = array_values($chart);
|
||||
$legend_prev = $legend;
|
||||
$series_type_prev = $series_type;
|
||||
$color_prev = $color;
|
||||
foreach($color_prev as $k => $col) {
|
||||
$color_prev[$k]['color'] = '#'.get_complementary_rgb($color_prev[$k]['color']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2726,6 +2737,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
|
|||
}
|
||||
|
||||
$legend = array_merge($legend, $legend_prev);
|
||||
$color = array_merge($color, $color_prev);
|
||||
}
|
||||
|
||||
if ($only_image) {
|
||||
|
|
|
@ -151,4 +151,154 @@ function setup_watermark($water_mark, &$water_mark_file, &$water_mark_url) {
|
|||
$water_mark_url = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Function to convert hue to RGB
|
||||
|
||||
function hue_2_rgb($v1,$v2,$vh) {
|
||||
if ($vh < 0) {
|
||||
$vh += 1;
|
||||
};
|
||||
|
||||
if ($vh > 1) {
|
||||
$vh -= 1;
|
||||
};
|
||||
|
||||
if ((6 * $vh) < 1) {
|
||||
return ($v1 + ($v2 - $v1) * 6 * $vh);
|
||||
};
|
||||
|
||||
if ((2 * $vh) < 1) {
|
||||
return ($v2);
|
||||
};
|
||||
|
||||
if ((3 * $vh) < 2) {
|
||||
return ($v1 + ($v2 - $v1) * ((2 / 3 - $vh) * 6));
|
||||
};
|
||||
|
||||
return ($v1);
|
||||
};
|
||||
|
||||
function get_complementary_rgb ($hexcode) {
|
||||
$hexcode = str_replace('#', '', $hexcode);
|
||||
|
||||
// $hexcode is the six digit hex colour code we want to convert
|
||||
|
||||
$redhex = substr($hexcode,0,2);
|
||||
$greenhex = substr($hexcode,2,2);
|
||||
$bluehex = substr($hexcode,4,2);
|
||||
|
||||
// $var_r, $var_g and $var_b are the three decimal fractions to be input to our RGB-to-HSL conversion routine
|
||||
|
||||
$var_r = (hexdec($redhex)) / 255;
|
||||
$var_g = (hexdec($greenhex)) / 255;
|
||||
$var_b = (hexdec($bluehex)) / 255;
|
||||
|
||||
//Now plug these values into the rgb2hsl routine. Below is my PHP version of EasyRGB.com's generic code for that conversion:
|
||||
|
||||
// Input is $var_r, $var_g and $var_b from above
|
||||
// Output is HSL equivalent as $h, $s and $l — these are again expressed as fractions of 1, like the input values
|
||||
|
||||
$var_min = min($var_r,$var_g,$var_b);
|
||||
$var_max = max($var_r,$var_g,$var_b);
|
||||
$del_max = $var_max - $var_min;
|
||||
|
||||
$l = ($var_max + $var_min) / 2;
|
||||
|
||||
if ($del_max == 0)
|
||||
{
|
||||
$h = 0;
|
||||
$s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($l < 0.5)
|
||||
{
|
||||
$s = $del_max / ($var_max + $var_min);
|
||||
}
|
||||
else
|
||||
{
|
||||
$s = $del_max / (2 - $var_max - $var_min);
|
||||
};
|
||||
|
||||
$del_r = ((($var_max - $var_r) / 6) + ($del_max / 2)) / $del_max;
|
||||
$del_g = ((($var_max - $var_g) / 6) + ($del_max / 2)) / $del_max;
|
||||
$del_b = ((($var_max - $var_b) / 6) + ($del_max / 2)) / $del_max;
|
||||
|
||||
if ($var_r == $var_max)
|
||||
{
|
||||
$h = $del_b - $del_g;
|
||||
}
|
||||
elseif ($var_g == $var_max)
|
||||
{
|
||||
$h = (1 / 3) + $del_r - $del_b;
|
||||
}
|
||||
elseif ($var_b == $var_max)
|
||||
{
|
||||
$h = (2 / 3) + $del_g - $del_r;
|
||||
};
|
||||
|
||||
if ($h < 0)
|
||||
{
|
||||
$h += 1;
|
||||
};
|
||||
|
||||
if ($h > 1)
|
||||
{
|
||||
$h -= 1;
|
||||
};
|
||||
};
|
||||
|
||||
//So now we have the colour as an HSL value, in the variables $h, $s and $l. These three output variables are again held as fractions of 1 at this stage, rather than as degrees and percentages. So e.g., cyan (180° 100% 50%) would come out as $h = 0.5, $s = 1, and $l = 0.5.
|
||||
|
||||
//Next find the value of the opposite Hue, i.e., the one that's 180°, or 0.5, away (I'm sure the mathematicians have a more elegant way of doing this, but):
|
||||
|
||||
// Calculate the opposite hue, $h2
|
||||
|
||||
$h2 = $h + 0.5;
|
||||
|
||||
if ($h2 > 1) {
|
||||
$h2 -= 1;
|
||||
};
|
||||
|
||||
//The HSL value of the complementary colour is now in $h2, $s, $l. So we're ready to convert this back to RGB (again, my PHP version of the EasyRGB.com formula). Note the input and output formats are different this time, see my comments at the top of the code:
|
||||
|
||||
// Input is HSL value of complementary colour, held in $h2, $s, $l as fractions of 1
|
||||
// Output is RGB in normal 255 255 255 format, held in $r, $g, $b
|
||||
// Hue is converted using function hue_2_rgb, shown at the end of this code
|
||||
|
||||
if ($s == 0)
|
||||
{
|
||||
$r = $l * 255;
|
||||
$g = $l * 255;
|
||||
$b = $l * 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($l < 0.5)
|
||||
{
|
||||
$var_2 = $l * (1 + $s);
|
||||
}
|
||||
else
|
||||
{
|
||||
$var_2 = ($l + $s) - ($s * $l);
|
||||
};
|
||||
$var_1 = 2 * $l - $var_2;
|
||||
|
||||
$r = 255 * hue_2_rgb($var_1,$var_2,$h2 + (1 / 3));
|
||||
$g = 255 * hue_2_rgb($var_1,$var_2,$h2);
|
||||
$b = 255 * hue_2_rgb($var_1,$var_2,$h2 - (1 / 3));
|
||||
};
|
||||
|
||||
|
||||
|
||||
//And after that routine, we finally have $r, $g and $b in 255 255 255 (RGB) format, which we can convert to six digits of hex:
|
||||
|
||||
$rhex = sprintf("%02X",round($r));
|
||||
$ghex = sprintf("%02X",round($g));
|
||||
$bhex = sprintf("%02X",round($b));
|
||||
|
||||
$rgbhex = $rhex.$ghex.$bhex;
|
||||
|
||||
return $rgbhex;
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue