From 6424e50ba4fbf9b67b1257f216012e667ae0938f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 7 Mar 2020 16:45:28 +0100 Subject: [PATCH] Enhance of colors in graph --- htdocs/core/class/dolgraph.class.php | 46 ++++++++++++++++------ htdocs/core/class/html.formother.class.php | 5 ++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index d540f04b8de..0e87475ee70 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -535,6 +535,8 @@ class DolGraph public function GetMaxValueInData() { // phpcs:enable + if (! is_array($this->data)) return 0; + $k = 0; $vals = array(); @@ -562,6 +564,8 @@ class DolGraph public function GetMinValueInData() { // phpcs:enable + if (! is_array($this->data)) return 0; + $k = 0; $vals = array(); @@ -1197,35 +1201,55 @@ class DolGraph $this->stringtoshow .= '], datasets: ['; + global $theme_datacolor; + //var_dump($arrayofgroupslegend); $i = 0; $iinstack = 0; $oldstacknum = -1; while ($i < $nblot) // Loop on each serie { - if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // We used a 'group by' - // If we change the stack + // We used a 'group by' and we have too many colors so we generated color variants per + if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by. + $nbofcolorneeds = count($arrayofgroupslegend); + $nbofcolorsavailable = count($theme_datacolor); + if ($nbofcolorneeds > $nbofcolorsavailable) { + $usecolorvariantforgroypby = 1; + } + + $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup']; + } else { + $textoflegend = $this->Legend[$i]; + } + if ($usecolorvariantforgroypby) { $newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum']]; + // If we change the stack if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum'] != $oldstacknum) { $iinstack = 0; - //var_dump('iinstack='.$iinstack.' - '.colorArrayToHex($newcolor)); - } else { + } + + //var_dump($iinstack); + if ($iinstack) { // Change color with offset of $$iinstack //var_dump($newcolor); - $ratio = max(-90, -10 * $iinstack); - $brightnessratio = min(90, 20 * $iinstack); + if ($iinstack % 2) { // We increase agressiveness of reference color for color 2, 4, 6, ... + $ratio = min(95, 10 + 10 * $iinstack); // step of 20 + $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10 + } else { // We decrease agressiveness of reference color for color 3, 5, 7, .. + $ratio = max(-100, - 15 * $iinstack + 10); // step of -20 + $brightnessratio = min(90, 10 * $iinstack); // step of 20 + } + //var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio); + $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true)); - //var_dump($ratio.' '.$brightnessratio); - //var_dump($newcolor); } $oldstacknum = $arrayofgroupslegend[$i]['stacknum']; $color = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].', 0.9)'; $bordercolor = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].')'; - $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup']; - } else { + + } else { // We do not use a 'group by' $color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].', 0.9)'; $bordercolor = $color; //$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); - $textoflegend = $this->Legend[$i]; } if ($i > 0) $this->stringtoshow .= ', '; diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 68af8236fc3..f38e5f461ec 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1434,12 +1434,13 @@ class FormOther } } } + // Add extrafields to X-Axis if ($object->isextrafieldmanaged) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue; if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue; - $arrayofxaxis['te.'.$key] = array('label' => $extrafields->attributes[$object->table_element]['label'][$key], 'position' => (int) $extrafields->attributes[$object->table_element]['pos'][$key]); + $arrayofxaxis['te.'.$key] = array('label' => $langs->trans($extrafields->attributes[$object->table_element]['label'][$key]), 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key]); } } @@ -1448,7 +1449,7 @@ class FormOther foreach ($arrayofxaxis as $key => $val) { $arrayofxaxislabel[$key] = $val['label']; } - $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, 0, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1); + $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, 1, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1); return $result; }