Fix graph of product distribution when too much record
This commit is contained in:
parent
8e9d4e408f
commit
ad9d0a3472
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@ -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: [';
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user