diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 51f58ec89c3..cab3e002028 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -198,9 +198,12 @@ if ($conf->use_javascript_ajax) $dataseries[] = array($langs->trans("MembersStatusResiliated"), round($SommeD)); $dataseries[] = array($langs->trans("MembersStatusToValid"), round($SommeA)); + include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $dolgraph = new DolGraph(); $dolgraph->SetData($dataseries); + $dolgraph->SetDataColor(array($badgeStatus1, $badgeStatus4, $badgeStatus6, '-'.$badgeStatus0)); $dolgraph->setShowLegend(1); $dolgraph->setShowPercent(1); $dolgraph->SetType(array('pie')); diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 0616a2e82e6..0035b4c813e 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -120,20 +120,6 @@ class DolGraph } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set Y precision - * - * @param float $which_prec Precision - * @return boolean - * @deprecated - */ - public function SetPrecisionY($which_prec) - { - // phpcs:enable - return true; - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2 @@ -729,7 +715,6 @@ class DolGraph $x++; } - // TODO Avoid push by adding generated long array... if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') { foreach ($values as $x => $y) { @@ -784,7 +769,10 @@ class DolGraph if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'pie' || $this->type[$firstlot] == 'polar')) { $datacolor = array(); - foreach ($this->datacolor as $val) $datacolor[] = "#".sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); + foreach ($this->datacolor as $val) { + if (is_array($val)) $datacolor[] = "#".sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); // If datacolor is array(R, G, B) + else $datacolor[] = "#".str_replace(array('#', '-'), '', $val); // If $val is '124' or '#124' + } $urltemp = ''; // TODO Add support for url link into labels $showlegend = $this->showlegend; @@ -994,7 +982,6 @@ class DolGraph $x++; } - // TODO Avoid push by adding generated long array... if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') { $j = 0; @@ -1062,22 +1049,44 @@ class DolGraph { $type = $this->type[$firstlot]; // pie or polar - $this->stringtoshow .= 'var options = { - elements: { - arc: { - backgroundColor: ['; - $i = 0; + $this->stringtoshow .= 'var options = { elements: { arc: {'."\n"; + $this->stringtoshow .= 'backgroundColor: ['; + $i = 0; $foundnegativecolor = 0; foreach($legends as $val) // Loop on each serie { if ($i > 0) $this->stringtoshow .= ', '."\n"; - $color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].')'; + if (is_array($this->datacolor[$i])) $color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].')'; // If datacolor is array(R, G, B) + else { + $tmp = str_replace('#', '', $this->datacolor[$i]); + if (strpos($tmp, '-') !== false) { + $foundnegativecolor++; + $color = '#FFFFFF'; // If $val is '-123' + } + else $color = "#".$tmp; // If $val is '123' or '#123' + } $this->stringtoshow .= "'".$color."'"; $i++; } - $this->stringtoshow .= '] + $this->stringtoshow .= '], '."\n"; + + if ($foundnegativecolor) { + $this->stringtoshow .= 'borderColor: ['; + $i = 0; + foreach($legends as $val) // Loop on each serie + { + if ($i > 0) $this->stringtoshow .= ', '."\n"; + if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B) + else { + $tmp = str_replace('#', '', $this->datacolor[$i]); + if (strpos($tmp, '-') !== false) $color = '#'.str_replace('-', '', $tmp); // If $val is '-123' + else $color = 'null'; // If $val is '123' or '#123' } + $this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'".$color."'"); + $i++; } - };'."\n"; + $this->stringtoshow .= ']'; + } + $this->stringtoshow .= '} } };'."\n"; $this->stringtoshow .= ' var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d");