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
|
* Return nb, amount of predefined product for year
|
||||||
*
|
*
|
||||||
* @param int $year Year to scan
|
* @param int $year Year to scan
|
||||||
* @return array Array of values
|
* @param int $limit Limit
|
||||||
|
* @return array Array of values
|
||||||
*/
|
*/
|
||||||
public function getAllByProduct($year)
|
public function getAllByProduct($year, $limit = 10)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
@ -227,6 +228,6 @@ class PropaleStats extends Stats
|
|||||||
$sql.= $this->db->order('nb', 'DESC');
|
$sql.= $this->db->order('nb', 'DESC');
|
||||||
//$sql.= $this->db->plimit(20);
|
//$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
|
* Return nb, amount of predefined product for year
|
||||||
*
|
*
|
||||||
* @param int $year Year to scan
|
* @param int $year Year to scan
|
||||||
* @return array Array of values
|
* @param int $limit Limit
|
||||||
|
* @return array Array of values
|
||||||
*/
|
*/
|
||||||
public function getAllByProduct($year)
|
public function getAllByProduct($year, $limit = 10)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
@ -220,6 +221,6 @@ class CommandeStats extends Stats
|
|||||||
$sql.= $this->db->order('nb', 'DESC');
|
$sql.= $this->db->order('nb', 'DESC');
|
||||||
//$sql.= $this->db->plimit(20);
|
//$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
|
* Return nb, amount of predefined product for year
|
||||||
*
|
*
|
||||||
* @param int $year Year to scan
|
* @param int $year Year to scan
|
||||||
* @return array Array of values
|
* @param int $limit Limit
|
||||||
|
* @return array Array of values
|
||||||
*/
|
*/
|
||||||
public function getAllByProduct($year)
|
public function getAllByProduct($year, $limit = 10)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
@ -222,6 +223,6 @@ class FactureStats extends Stats
|
|||||||
$sql.= $this->db->order('nb', 'DESC');
|
$sql.= $this->db->order('nb', 'DESC');
|
||||||
//$sql.= $this->db->plimit(20);
|
//$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;
|
$showpointvalue = 1; $nocolor = 0;
|
||||||
$mode = 'customer';
|
$mode = 'customer';
|
||||||
$stats_invoice = new FactureStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
|
$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))
|
if (empty($data1))
|
||||||
{
|
{
|
||||||
@ -160,12 +160,12 @@ class box_graph_product_distribution extends ModeleBoxes
|
|||||||
$mesg = $px1->isGraphKo();
|
$mesg = $px1->isGraphKo();
|
||||||
if (!$mesg)
|
if (!$mesg)
|
||||||
{
|
{
|
||||||
$i = 0; $tot = count($data1); $legend = array();
|
$i = 0; $legend = array();
|
||||||
while ($i < $tot)
|
|
||||||
|
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[$key][0] = dol_trunc($data1[$key][0], 32);
|
||||||
$data1[$i][0] = dol_trunc($data1[$i][0], 32);
|
$legend[] = $data1[$key][0];
|
||||||
$legend[] = $data1[$i][0];
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ class box_graph_product_distribution extends ModeleBoxes
|
|||||||
|
|
||||||
$showpointvalue = 1; $nocolor = 0;
|
$showpointvalue = 1; $nocolor = 0;
|
||||||
$stats_proposal = new PropaleStats($this->db, $socid, ($userid > 0 ? $userid : 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))
|
if (empty($data2))
|
||||||
{
|
{
|
||||||
$showpointvalue = 0;
|
$showpointvalue = 0;
|
||||||
@ -219,11 +219,12 @@ class box_graph_product_distribution extends ModeleBoxes
|
|||||||
$mesg = $px2->isGraphKo();
|
$mesg = $px2->isGraphKo();
|
||||||
if (!$mesg)
|
if (!$mesg)
|
||||||
{
|
{
|
||||||
$i = 0; $tot = count($data2); $legend = array();
|
$i = 0; $legend = array();
|
||||||
while ($i < $tot)
|
|
||||||
|
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"
|
$data2[$key][0] = dol_trunc($data2[$key][0], 32);
|
||||||
$legend[] = $data2[$i][0];
|
$legend[] = $data2[$key][0];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +264,7 @@ class box_graph_product_distribution extends ModeleBoxes
|
|||||||
$showpointvalue = 1; $nocolor = 0;
|
$showpointvalue = 1; $nocolor = 0;
|
||||||
$mode = 'customer';
|
$mode = 'customer';
|
||||||
$stats_order = new CommandeStats($this->db, $socid, $mode, ($userid > 0 ? $userid : 0));
|
$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))
|
if (empty($data3))
|
||||||
{
|
{
|
||||||
$showpointvalue = 0;
|
$showpointvalue = 0;
|
||||||
@ -278,11 +279,12 @@ class box_graph_product_distribution extends ModeleBoxes
|
|||||||
$mesg = $px3->isGraphKo();
|
$mesg = $px3->isGraphKo();
|
||||||
if (!$mesg)
|
if (!$mesg)
|
||||||
{
|
{
|
||||||
$i = 0; $tot = count($data3); $legend = array();
|
$i = 0; $legend = array();
|
||||||
while ($i < $tot)
|
|
||||||
|
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"
|
$data3[$key][0] = dol_trunc($data3[$key][0], 32);
|
||||||
$legend[] = $data3[$i][0];
|
$legend[] = $data3[$key][0];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1051,16 +1051,22 @@ class DolGraph
|
|||||||
if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle'))))
|
if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle'))))
|
||||||
{
|
{
|
||||||
$type = $this->type[$firstlot]; // pie or polar
|
$type = $this->type[$firstlot]; // pie or polar
|
||||||
|
|
||||||
$this->stringtoshow .= 'var options = {'."\n";
|
$this->stringtoshow .= 'var options = {'."\n";
|
||||||
|
$legendMaxLines= 0; // Does not work
|
||||||
if (empty($showlegend)) {
|
if (empty($showlegend)) {
|
||||||
$this->stringtoshow .= 'legend: { display: false }, ';
|
$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') {
|
if ($this->type[$firstlot] == 'piesemicircle') {
|
||||||
$this->stringtoshow .= 'circumference: Math.PI,'."\n";
|
$this->stringtoshow .= 'circumference: Math.PI,'."\n";
|
||||||
$this->stringtoshow .= 'rotation: -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";
|
$this->stringtoshow .= 'elements: { arc: {'."\n";
|
||||||
// Color of earch arc
|
// Color of earch arc
|
||||||
$this->stringtoshow .= 'backgroundColor: [';
|
$this->stringtoshow .= 'backgroundColor: [';
|
||||||
|
|||||||
@ -269,13 +269,14 @@ abstract class Stats
|
|||||||
*
|
*
|
||||||
* @param int $year Year
|
* @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 $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
|
* @return array Array of values
|
||||||
*/
|
*/
|
||||||
public function getAllByProductEntry($year, $cachedelay = 0)
|
public function getAllByProductEntry($year, $cachedelay = 0, $limit = 10)
|
||||||
{
|
{
|
||||||
global $conf,$user,$langs;
|
global $conf,$user,$langs;
|
||||||
|
|
||||||
$datay=array();
|
$data=array();
|
||||||
|
|
||||||
// Search into cache
|
// Search into cache
|
||||||
if (! empty($cachedelay))
|
if (! empty($cachedelay))
|
||||||
@ -313,7 +314,7 @@ abstract class Stats
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$data=$this->getAllByProduct($year);
|
$data = $this->getAllByProduct($year, $limit);
|
||||||
// $data[$i][]=$datay[$year][$i][1]; // set yval for x=i
|
// $data[$i][]=$datay[$year][$i][1]; // set yval for x=i
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,7 +605,6 @@ abstract class Stats
|
|||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
$result=array();
|
$result=array();
|
||||||
$res=array();
|
|
||||||
|
|
||||||
dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG);
|
dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
|||||||
@ -191,10 +191,11 @@ class FichinterStats extends Stats
|
|||||||
/**
|
/**
|
||||||
* Return nb, amount of predefined product for year
|
* Return nb, amount of predefined product for year
|
||||||
*
|
*
|
||||||
* @param int $year Year to scan
|
* @param int $year Year to scan
|
||||||
* @return array Array of values
|
* @param int $limit Limit
|
||||||
|
* @return array Array of values
|
||||||
*/
|
*/
|
||||||
public function getAllByProduct($year)
|
public function getAllByProduct($year, $limit = 0)
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
||||||
@ -208,6 +209,6 @@ class FichinterStats extends Stats
|
|||||||
$sql.= $this->db->order('nb', 'DESC');
|
$sql.= $this->db->order('nb', 'DESC');
|
||||||
//$sql.= $this->db->plimit(20);
|
//$sql.= $this->db->plimit(20);
|
||||||
|
|
||||||
return $this->_getAllByProduct($sql);
|
return $this->_getAllByProduct($sql, $limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user