diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 0859bdb7974..ee42ca26471 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -210,10 +210,11 @@ class PropaleStats extends Stats /** * Return nb, amount of predefined product for year * - * @param int $year Year to scan - * @return array Array of values + * @param int $year Year to scan + * @param int $limit Limit + * @return array Array of values */ - public function getAllByProduct($year) + public function getAllByProduct($year, $limit = 10) { global $user; @@ -227,6 +228,6 @@ class PropaleStats extends Stats $sql.= $this->db->order('nb', 'DESC'); //$sql.= $this->db->plimit(20); - return $this->_getAllByProduct($sql); + return $this->_getAllByProduct($sql, $limit); } } diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 0311f4c49ed..522bd7b2e31 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -203,10 +203,11 @@ class CommandeStats extends Stats /** * Return nb, amount of predefined product for year * - * @param int $year Year to scan - * @return array Array of values + * @param int $year Year to scan + * @param int $limit Limit + * @return array Array of values */ - public function getAllByProduct($year) + public function getAllByProduct($year, $limit = 10) { global $user; @@ -220,6 +221,6 @@ class CommandeStats extends Stats $sql.= $this->db->order('nb', 'DESC'); //$sql.= $this->db->plimit(20); - return $this->_getAllByProduct($sql); + return $this->_getAllByProduct($sql, $limit); } } diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index f24f31bbc9a..730df6ee6e4 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -205,10 +205,11 @@ class FactureStats extends Stats /** * Return nb, amount of predefined product for year * - * @param int $year Year to scan - * @return array Array of values + * @param int $year Year to scan + * @param int $limit Limit + * @return array Array of values */ - public function getAllByProduct($year) + public function getAllByProduct($year, $limit = 10) { global $user; @@ -222,6 +223,6 @@ class FactureStats extends Stats $sql.= $this->db->order('nb', 'DESC'); //$sql.= $this->db->plimit(20); - return $this->_getAllByProduct($sql); + return $this->_getAllByProduct($sql, $limit); } } diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index 0bea87ccdf3..ea8e98b6cbc 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -145,7 +145,7 @@ class box_graph_product_distribution extends ModeleBoxes $showpointvalue = 1; $nocolor = 0; $mode = 'customer'; $stats_invoice = new FactureStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0)); - $data1 = $stats_invoice->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24))); + $data1 = $stats_invoice->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5); if (empty($data1)) { @@ -160,12 +160,12 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px1->isGraphKo(); if (!$mesg) { - $i = 0; $tot = count($data1); $legend = array(); - while ($i < $tot) + $i = 0; $legend = array(); + + foreach($data1 as $key => $val) { - //$data1[$i][0] = dol_trunc($data1[$i][0], 5); // Required to avoid error "Could not draw pie with labels contained inside canvas" - $data1[$i][0] = dol_trunc($data1[$i][0], 32); - $legend[] = $data1[$i][0]; + $data1[$key][0] = dol_trunc($data1[$key][0], 32); + $legend[] = $data1[$key][0]; $i++; } @@ -204,7 +204,7 @@ class box_graph_product_distribution extends ModeleBoxes $showpointvalue = 1; $nocolor = 0; $stats_proposal = new PropaleStats($this->db, $socid, ($userid > 0 ? $userid : 0)); - $data2 = $stats_proposal->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24))); + $data2 = $stats_proposal->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5); if (empty($data2)) { $showpointvalue = 0; @@ -219,11 +219,12 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px2->isGraphKo(); if (!$mesg) { - $i = 0; $tot = count($data2); $legend = array(); - while ($i < $tot) + $i = 0; $legend = array(); + + foreach($data2 as $key => $val) { - $data2[$i][0] = dol_trunc($data2[$i][0], 5); // Required to avoid error "Could not draw pie with labels contained inside canvas" - $legend[] = $data2[$i][0]; + $data2[$key][0] = dol_trunc($data2[$key][0], 32); + $legend[] = $data2[$key][0]; $i++; } @@ -263,7 +264,7 @@ class box_graph_product_distribution extends ModeleBoxes $showpointvalue = 1; $nocolor = 0; $mode = 'customer'; $stats_order = new CommandeStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0)); - $data3 = $stats_order->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24))); + $data3 = $stats_order->getAllByProductEntry($year, (GETPOST('action', 'aZ09') == $refreshaction ?-1 : (3600 * 24)), 5); if (empty($data3)) { $showpointvalue = 0; @@ -278,11 +279,12 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px3->isGraphKo(); if (!$mesg) { - $i = 0; $tot = count($data3); $legend = array(); - while ($i < $tot) + $i = 0; $legend = array(); + + foreach($data3 as $key => $val) { - $data3[$i][0] = dol_trunc($data3[$i][0], 5); // Required to avoid error "Could not draw pie with labels contained inside canvas" - $legend[] = $data3[$i][0]; + $data3[$key][0] = dol_trunc($data3[$key][0], 32); + $legend[] = $data3[$key][0]; $i++; } diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 745e5e7af5c..dc0ad04fc97 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -1051,16 +1051,22 @@ class DolGraph if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle')))) { $type = $this->type[$firstlot]; // pie or polar - $this->stringtoshow .= 'var options = {'."\n"; + $legendMaxLines= 0; // Does not work if (empty($showlegend)) { $this->stringtoshow .= 'legend: { display: false }, '; + } else { + $this->stringtoshow .= 'legend: { position: \''.($showlegend == 2 ? 'right' : 'top').'\''; + if (! empty($legendMaxLines)) { + $this->stringtoshow .= ', maxLines: '.$legendMaxLines.''; + } + $this->stringtoshow .= ' }, '."\n"; } + if ($this->type[$firstlot] == 'piesemicircle') { $this->stringtoshow .= 'circumference: Math.PI,'."\n"; $this->stringtoshow .= 'rotation: -Math.PI,'."\n"; } - if ($showlegend) $this->stringtoshow .= 'legend: { position: \''.($showlegend == 2 ? 'right' : 'top').'\' },'."\n"; $this->stringtoshow .= 'elements: { arc: {'."\n"; // Color of earch arc $this->stringtoshow .= 'backgroundColor: ['; diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index c4f10c69469..e0c19e300a3 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -269,13 +269,14 @@ abstract class Stats * * @param int $year Year * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) + * @param int $limit Limit * @return array Array of values */ - public function getAllByProductEntry($year, $cachedelay = 0) + public function getAllByProductEntry($year, $cachedelay = 0, $limit = 10) { global $conf,$user,$langs; - $datay=array(); + $data=array(); // Search into cache if (! empty($cachedelay)) @@ -313,7 +314,7 @@ abstract class Stats } else { - $data=$this->getAllByProduct($year); + $data = $this->getAllByProduct($year, $limit); // $data[$i][]=$datay[$year][$i][1]; // set yval for x=i } @@ -604,7 +605,6 @@ abstract class Stats global $langs; $result=array(); - $res=array(); dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/fichinter/class/fichinterstats.class.php b/htdocs/fichinter/class/fichinterstats.class.php index 98eb218e9ef..0a4daa03955 100644 --- a/htdocs/fichinter/class/fichinterstats.class.php +++ b/htdocs/fichinter/class/fichinterstats.class.php @@ -191,10 +191,11 @@ class FichinterStats extends Stats /** * Return nb, amount of predefined product for year * - * @param int $year Year to scan - * @return array Array of values + * @param int $year Year to scan + * @param int $limit Limit + * @return array Array of values */ - public function getAllByProduct($year) + public function getAllByProduct($year, $limit = 0) { global $user; @@ -208,6 +209,6 @@ class FichinterStats extends Stats $sql.= $this->db->order('nb', 'DESC'); //$sql.= $this->db->plimit(20); - return $this->_getAllByProduct($sql); + return $this->_getAllByProduct($sql, $limit); } }