funnel horizontal bar

This commit is contained in:
lmarcouiller 2020-12-09 13:31:14 +01:00
parent 43b1be01d9
commit 83286d99be
2 changed files with 215 additions and 204 deletions

View File

@ -81,6 +81,8 @@ class box_funnel_of_prospection extends ModeleBoxes
$sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label"; $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls";
$sql .= " WHERE active=1"; $sql .= " WHERE active=1";
$sql .= " Order by cls.rowid";
$sql .= " AND cls.code != 'LOST'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -108,7 +110,6 @@ class box_funnel_of_prospection extends ModeleBoxes
$colorseriesstat[$objp->rowid] = $badgeStatus6; $colorseriesstat[$objp->rowid] = $badgeStatus6;
break; break;
default: default:
$colorseriesstat[$objp->rowid] = $badgeStatus2;
break; break;
} }
$i++; $i++;
@ -167,14 +168,16 @@ class box_funnel_of_prospection extends ModeleBoxes
$stringtoprint = ''; $stringtoprint = '';
$stringtoprint .= '<div class="div-table-responsive-no-min ">'; $stringtoprint .= '<div class="div-table-responsive-no-min ">';
$listofstatus = array_keys($listofoppstatus); $listofstatus = array_keys($listofoppstatus);
$liststatus = array();
$data = array('');
foreach ($listofstatus as $status) { foreach ($listofstatus as $status) {
$labelStatus = ''; $labelStatus = '';
if ($status != 7) { if ($status != 7) {
$code = dol_getIdFromCode($this->db, $status, 'c_lead_status', 'rowid', 'code'); $code = dol_getIdFromCode($this->db, $status, 'c_lead_status', 'rowid', 'code');
if ($code) $labelStatus = $langs->transnoentitiesnoconv("OppStatus" . $code); if ($code) $labelStatus = $langs->transnoentitiesnoconv("OppStatus" . $code);
if (empty($labelStatus)) $labelStatus = $listofopplabel[$status]; if (empty($labelStatus)) $labelStatus = $listofopplabel[$status];
$liststatus[] = $labelStatus;
$dataseries[] = array($labelStatus,(isset($valsamount[$status]) ? (float) $valsamount[$status] : 0)); $data[] = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
if (!$conf->use_javascript_ajax) { if (!$conf->use_javascript_ajax) {
$stringtoprint .= '<tr class="oddeven">'; $stringtoprint .= '<tr class="oddeven">';
$stringtoprint .= '<td>' . $labelStatus . '</td>'; $stringtoprint .= '<td>' . $labelStatus . '</td>';
@ -183,16 +186,21 @@ class box_funnel_of_prospection extends ModeleBoxes
} }
} }
} }
$dataseries[] = $data;
if ($conf->use_javascript_ajax) { if ($conf->use_javascript_ajax) {
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
$dolgraph = new DolGraph(); $dolgraph = new DolGraph();
$dolgraph->SetMinValue(0);
$dolgraph->SetData($dataseries); $dolgraph->SetData($dataseries);
$dolgraph->SetLegend($liststatus);
$dolgraph->SetDataColor(array_values($colorseriesstat)); $dolgraph->SetDataColor(array_values($colorseriesstat));
//$dolgraph->SetLegend(array('PROSP',$dataseries['PROSP']));
$dolgraph->setShowLegend(2); $dolgraph->setShowLegend(2);
$dolgraph->setShowPercent(1); $dolgraph->setShowPercent(1);
$dolgraph->SetType(array('pie')); $dolgraph->setTitle('FunnelOfProspection');
$dolgraph->SetType(array('horizontalbars'));
$dolgraph->SetHeight('200'); $dolgraph->SetHeight('200');
$dolgraph->SetWidth('600');
$dolgraph->mode='depth';
$dolgraph->draw('idgraphstatus'); $dolgraph->draw('idgraphstatus');
$stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
} }

View File

@ -103,9 +103,8 @@ class DolGraph
$this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220)); $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
$this->bgcolor = array(235, 235, 224); $this->bgcolor = array(235, 235, 224);
$color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; $color_file = DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
if (is_readable($color_file)) if (is_readable($color_file)) {
{
include_once $color_file; include_once $color_file;
if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor;
if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor;
@ -261,7 +260,7 @@ class DolGraph
* Set type * Set type
* *
* @param array $type Array with type for each serie. Example: array('type1', 'type2', ...) where type can be: * @param array $type Array with type for each serie. Example: array('type1', 'type2', ...) where type can be:
* 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horirontalbars'... * 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horizontalbars'...
* @return void * @return void
*/ */
public function SetType($type) public function SetType($type)
@ -466,10 +465,8 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet; global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_color)) if (!is_array($bg_color)) {
{ if ($bg_color == 'onglet') {
if ($bg_color == 'onglet')
{
//print 'ee'.join(',',$theme_bgcoloronglet); //print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolor = $theme_bgcoloronglet; $this->bgcolor = $theme_bgcoloronglet;
} else { } else {
@ -492,10 +489,8 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet; global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_colorgrid)) if (!is_array($bg_colorgrid)) {
{ if ($bg_colorgrid == 'onglet') {
if ($bg_colorgrid == 'onglet')
{
//print 'ee'.join(',',$theme_bgcoloronglet); //print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolorgrid = $theme_bgcoloronglet; $this->bgcolorgrid = $theme_bgcoloronglet;
} else { } else {
@ -535,10 +530,8 @@ class DolGraph
$nblines = count($this->data); $nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++) for ($j = 0; $j < $nblines; $j++) {
{ for ($i = 0; $i < $nbvalues; $i++) {
for ($i = 0; $i < $nbvalues; $i++)
{
$vals[$k] = $this->data[$j][$i + 1]; $vals[$k] = $this->data[$j][$i + 1];
$k++; $k++;
} }
@ -564,10 +557,8 @@ class DolGraph
$nblines = count($this->data); $nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++) for ($j = 0; $j < $nblines; $j++) {
{ for ($i = 0; $i < $nbvalues; $i++) {
for ($i = 0; $i < $nbvalues; $i++)
{
$vals[$k] = $this->data[$j][$i + 1]; $vals[$k] = $this->data[$j][$i + 1];
$k++; $k++;
} }
@ -589,8 +580,7 @@ class DolGraph
if ($max != 0) $max++; if ($max != 0) $max++;
$size = dol_strlen(abs(ceil($max))); $size = dol_strlen(abs(ceil($max)));
$factor = 1; $factor = 1;
for ($i = 0; $i < ($size - 1); $i++) for ($i = 0; $i < ($size - 1); $i++) {
{
$factor *= 10; $factor *= 10;
} }
@ -615,8 +605,7 @@ class DolGraph
if ($min != 0) $min--; if ($min != 0) $min--;
$size = dol_strlen(abs(floor($min))); $size = dol_strlen(abs(floor($min)));
$factor = 1; $factor = 1;
for ($i = 0; $i < ($size - 1); $i++) for ($i = 0; $i < ($size - 1); $i++) {
{
$factor *= 10; $factor *= 10;
} }
@ -635,24 +624,21 @@ class DolGraph
*/ */
public function draw($file, $fileurl = '') public function draw($file, $fileurl = '')
{ {
if (empty($file)) if (empty($file)) {
{
$this->error = "Call to draw method was made with empty value for parameter file."; $this->error = "Call to draw method was made with empty value for parameter file.";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
return -2; return -2;
} }
if (!is_array($this->data)) if (!is_array($this->data)) {
{
$this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; $this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
return -1; return -1;
} }
if (count($this->data) < 1) if (count($this->data) < 1) {
{
$this->error = "Call to draw method was made but SetData was is an empty dataset"; $this->error = "Call to draw method was made but SetData was is an empty dataset";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_WARNING); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_WARNING);
} }
$call = "draw_".$this->_library; $call = "draw_" . $this->_library;
call_user_func_array(array($this, $call), array($file, $fileurl)); call_user_func_array(array($this, $call), array($file, $fileurl));
} }
@ -678,10 +664,9 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
dol_syslog(get_class($this)."::draw_jflot this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue);
if (empty($this->width) && empty($this->height)) if (empty($this->width) && empty($this->height)) {
{
print 'Error width or height not set'; print 'Error width or height not set';
return; return;
} }
@ -701,7 +686,7 @@ class DolGraph
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x $values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x
$serie[$i] = "var d".$i." = [];\n"; $serie[$i] = "var d" . $i . " = [];\n";
// Fill array $values // Fill array $values
$x = 0; $x = 0;
@ -712,14 +697,13 @@ class DolGraph
$x++; $x++;
} }
if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) {
{
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) $serie[$i] .= 'd'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; if (isset($y)) $serie[$i] .= 'd' . $i . '.push({"label":"' . dol_escape_js($legends[$x]) . '", "data":' . $y . '});' . "\n";
} }
} else { } else {
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) $serie[$i] .= 'd'.$i.'.push(['.$x.', '.$y.']);'."\n"; if (isset($y)) $serie[$i] .= 'd' . $i . '.push([' . $x . ', ' . $y . ']);' . "\n";
} }
} }
@ -728,43 +712,39 @@ class DolGraph
} }
$tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
$this->stringtoshow = '<!-- Build using jflot -->'."\n"; $this->stringtoshow = '<!-- Build using jflot -->' . "\n";
if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle'.(empty($this->cssprefix) ? '' : ' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>';
if (!empty($this->shownographyet)) if (!empty($this->shownographyet)) {
{ $this->stringtoshow .= '<div style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="nographyet"></div>';
$this->stringtoshow .= '<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>'; $this->stringtoshow .= '<div class="nographyettext margintoponly">' . $langs->trans("NotEnoughDataYet") . '...</div>';
$this->stringtoshow .= '<div class="nographyettext margintoponly">'.$langs->trans("NotEnoughDataYet").'...</div>';
return; return;
} }
// Start the div that will contains all the graph // Start the div that will contains all the graph
$dolxaxisvertical = ''; $dolxaxisvertical = '';
if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical';
$this->stringtoshow .= '<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph'.(empty($dolxaxisvertical) ? '' : ' '.$dolxaxisvertical).(empty($this->cssprefix) ? '' : ' dolgraph'.$this->cssprefix).' center"></div>'."\n"; $this->stringtoshow .= '<div id="placeholder_' . $tag . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="dolgraph' . (empty($dolxaxisvertical) ? '' : ' ' . $dolxaxisvertical) . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . ' center"></div>' . "\n";
$this->stringtoshow .= '<script id="'.$tag.'">'."\n"; $this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$this->stringtoshow .= '$(function () {'."\n"; $this->stringtoshow .= '$(function () {' . "\n";
$i = $firstlot; $i = $firstlot;
if ($nblot < 0) if ($nblot < 0) {
{ $this->stringtoshow .= '<!-- No series of data -->' . "\n";
$this->stringtoshow .= '<!-- No series of data -->'."\n";
} else { } else {
while ($i < $nblot) while ($i < $nblot) {
{ $this->stringtoshow .= '<!-- Serie ' . $i . ' -->' . "\n";
$this->stringtoshow .= '<!-- Serie '.$i.' -->'."\n"; $this->stringtoshow .= $serie[$i] . "\n";
$this->stringtoshow .= $serie[$i]."\n";
$i++; $i++;
} }
} }
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
// Special case for Graph of type 'pie' // Special case for Graph of type 'pie'
if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) {
{
$datacolor = array(); $datacolor = array();
foreach ($this->datacolor as $val) { 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) 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' else $datacolor[] = "#" . str_replace(array('#', '-'), '', $val); // If $val is '124' or '#124'
} }
$urltemp = ''; // TODO Add support for url link into labels $urltemp = ''; // TODO Add support for url link into labels
@ -773,17 +753,17 @@ class DolGraph
$showpercent = $this->showpercent; $showpercent = $this->showpercent;
$this->stringtoshow .= ' $this->stringtoshow .= '
function plotWithOptions_'.$tag.'() { function plotWithOptions_' . $tag . '() {
$.plot($("#placeholder_'.$tag.'"), d0, $.plot($("#placeholder_' . $tag . '"), d0,
{ {
series: { series: {
pie: { pie: {
show: true, show: true,
radius: 0.8, radius: 0.8,
'.($this->combine ? ' ' . ($this->combine ? '
combine: { combine: {
threshold: '.$this->combine.' threshold: ' . $this->combine . '
},' : '').' },' : '') . '
label: { label: {
show: true, show: true,
radius: 0.9, radius: 0.9,
@ -791,15 +771,15 @@ class DolGraph
var percent=Math.round(series.percent); var percent=Math.round(series.percent);
var number=series.data[0][1]; var number=series.data[0][1];
return \''; return \'';
$this->stringtoshow .= '<span style="font-size:8pt;text-align:center;padding:2px;color:black;">'; $this->stringtoshow .= '<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
if ($urltemp) $this->stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; if ($urltemp) $this->stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="' . $urltemp . '">';
$this->stringtoshow .= '\'+'; $this->stringtoshow .= '\'+';
$this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend $this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend
$this->stringtoshow .= ($showpointvalue ? 'number+' : ''); $this->stringtoshow .= ($showpointvalue ? 'number+' : '');
$this->stringtoshow .= ($showpercent ? '\'<br/>\'+percent+\'%\'+' : ''); $this->stringtoshow .= ($showpercent ? '\'<br/>\'+percent+\'%\'+' : '');
$this->stringtoshow .= '\''; $this->stringtoshow .= '\'';
if ($urltemp) $this->stringtoshow .= '</a>'; if ($urltemp) $this->stringtoshow .= '</a>';
$this->stringtoshow .= '</span>\'; $this->stringtoshow .= '</span>\';
}, },
background: { background: {
opacity: 0.0, opacity: 0.0,
@ -814,21 +794,20 @@ class DolGraph
pan: { pan: {
interactive: true interactive: true
},'; },';
if (count($datacolor)) if (count($datacolor)) {
{ $this->stringtoshow .= 'colors: ' . (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)) . ',';
$this->stringtoshow .= 'colors: '.(!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
} }
$this->stringtoshow .= 'legend: {show: '.($showlegend ? 'true' : 'false').', position: \'ne\' } $this->stringtoshow .= 'legend: {show: ' . ($showlegend ? 'true' : 'false') . ', position: \'ne\' }
}); });
}'."\n"; }' . "\n";
} }
// Other cases, graph of type 'bars', 'lines' // Other cases, graph of type 'bars', 'lines'
else { else {
// Add code to support tooltips // Add code to support tooltips
// TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes // TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes
$this->stringtoshow .= ' $this->stringtoshow .= '
function showTooltip_'.$tag.'(x, y, contents) { function showTooltip_' . $tag . '(x, y, contents) {
$(\'<div class="graph-tooltip-inner" id="tooltip_'.$tag.'">\' + contents + \'</div>\').css({ $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag . '">\' + contents + \'</div>\').css({
position: \'absolute\', position: \'absolute\',
display: \'none\', display: \'none\',
top: y + 10, top: y + 10,
@ -844,7 +823,7 @@ class DolGraph
} }
var previousPoint = null; var previousPoint = null;
$("#placeholder_'.$tag.'").bind("plothover", function (event, pos, item) { $("#placeholder_' . $tag . '").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2)); $("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2)); $("#y").text(pos.y.toFixed(2));
@ -858,27 +837,26 @@ class DolGraph
var y = item.datapoint[1].toFixed(2); var y = item.datapoint[1].toFixed(2);
var z = item.series.xaxis.ticks[item.dataIndex].label; var z = item.series.xaxis.ticks[item.dataIndex].label;
'; ';
if ($this->showpointvalue > 0) $this->stringtoshow .= ' if ($this->showpointvalue > 0) $this->stringtoshow .= '
showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
'; ';
$this->stringtoshow .= ' $this->stringtoshow .= '
} }
} }
else { else {
$("#tooltip_'.$tag.'").remove(); $("#tooltip_' . $tag . '").remove();
previousPoint = null; previousPoint = null;
} }
}); });
'; ';
$this->stringtoshow .= 'var stack = null, steps = false;'."\n"; $this->stringtoshow .= 'var stack = null, steps = false;' . "\n";
$this->stringtoshow .= 'function plotWithOptions_'.$tag.'() {'."\n"; $this->stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n";
$this->stringtoshow .= '$.plot($("#placeholder_'.$tag.'"), [ '."\n"; $this->stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n";
$i = $firstlot; $i = $firstlot;
while ($i < $nblot) while ($i < $nblot) {
{ if ($i > $firstlot) $this->stringtoshow .= ', ' . "\n";
if ($i > $firstlot) $this->stringtoshow .= ', '."\n";
$color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
$this->stringtoshow .= '{ '; $this->stringtoshow .= '{ ';
if (!isset($this->type[$i]) || $this->type[$i] == 'bars') { if (!isset($this->type[$i]) || $this->type[$i] == 'bars') {
@ -886,42 +864,41 @@ class DolGraph
if ($i == $firstlot) $align = 'right'; if ($i == $firstlot) $align = 'right';
elseif ($i == $firstlot + 1) $align = 'center'; elseif ($i == $firstlot + 1) $align = 'center';
else $align = 'left'; else $align = 'left';
$this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "'.$align.'", barWidth: 0.45 }, '; $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "' . $align . '", barWidth: 0.45 }, ';
} else $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "'.($i == $firstlot ? 'center' : 'left').'", barWidth: 0.5 }, '; } else $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ? 'center' : 'left') . '", barWidth: 0.5 }, ';
} }
if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow .= 'lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow .= 'lines: { show: true, fill: false }, points: { show: ' . ($this->type[$i] == 'linesnopoint' ? 'false' : 'true') . ' }, ';
$this->stringtoshow .= 'color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }'; $this->stringtoshow .= 'color: "#' . $color . '", label: "' . (isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '') . '", data: d' . $i . ' }';
$i++; $i++;
} }
// shadowSize: 0 -> Drawing is faster without shadows // shadowSize: 0 -> Drawing is faster without shadows
$this->stringtoshow .= "\n".' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6, fillColor: { colors: [{opacity: 0.9 }, {opacity: 0.85}] }} }'."\n"; $this->stringtoshow .= "\n" . ' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6, fillColor: { colors: [{opacity: 0.9 }, {opacity: 0.85}] }} }' . "\n";
// Xaxis // Xaxis
$this->stringtoshow .= ', xaxis: { ticks: ['."\n"; $this->stringtoshow .= ', xaxis: { ticks: [' . "\n";
$x = 0; $x = 0;
foreach ($this->data as $key => $valarray) foreach ($this->data as $key => $valarray) {
{ if ($x > 0) $this->stringtoshow .= ', ' . "\n";
if ($x > 0) $this->stringtoshow .= ', '."\n"; $this->stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]';
$this->stringtoshow .= ' ['.$x.', "'.$valarray[0].'"]';
$x++; $x++;
} }
$this->stringtoshow .= '] }'."\n"; $this->stringtoshow .= '] }' . "\n";
// Yaxis // Yaxis
$this->stringtoshow .= ', yaxis: { min: '.$this->MinValue.', max: '.($this->MaxValue).' }'."\n"; $this->stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . ($this->MaxValue) . ' }' . "\n";
// Background color // Background color
$color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]); $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
$color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
$this->stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#'.$color1.'", "#'.$color2.'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }'."\n"; $this->stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 . '", "#' . $color2 . '"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' . "\n";
//$this->stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this //$this->stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
} }
$this->stringtoshow .= 'plotWithOptions_'.$tag.'();'."\n"; $this->stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '</script>'."\n"; $this->stringtoshow .= '</script>' . "\n";
} }
@ -947,10 +924,9 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
dol_syslog(get_class($this)."::draw_chart this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); dol_syslog(get_class($this) . "::draw_chart this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue);
if (empty($this->width) && empty($this->height)) if (empty($this->width) && empty($this->height)) {
{
print 'Error width or height not set'; print 'Error width or height not set';
return; return;
} }
@ -971,7 +947,8 @@ class DolGraph
// Works with line but not with bars // Works with line but not with bars
//if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x
$serie = array(); $arrayofgroupslegend = array(); $serie = array();
$arrayofgroupslegend = array();
//var_dump($this->data); //var_dump($this->data);
$i = $firstlot; $i = $firstlot;
@ -989,15 +966,15 @@ class DolGraph
$alabelexists = 1; $alabelexists = 1;
$tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3); $tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
if (!empty($tmpykey[2]) || $tmpykey[2] == '0') { // This is a 'Group by' array if (!empty($tmpykey[2]) || $tmpykey[2] == '0') { // This is a 'Group by' array
$tmpvalue = (array_key_exists('y_'.$tmpykey[1].'_'.$tmpykey[2], $valarray) ? $valarray['y_'.$tmpykey[1].'_'.$tmpykey[2]] : $valarray[$i + 1]); $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
$arrayofgroupslegend[$i] = array( $arrayofgroupslegend[$i] = array(
'stacknum'=> $tmpykey[1], 'stacknum' => $tmpykey[1],
'legend' => $this->Legend[$tmpykey[1]], 'legend' => $this->Legend[$tmpykey[1]],
'legendwithgroup' => $this->Legend[$tmpykey[1]].' - '.$tmpykey[2] 'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2]
); );
} else { } else {
$tmpvalue = (array_key_exists('y_'.$i, $valarray) ? $valarray['y_'.$i] : $valarray[$i + 1]); $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : $valarray[$i + 1]);
//var_dump($i.'_'.$x.'_'.$tmpvalue); //var_dump($i.'_'.$x.'_'.$tmpvalue);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
} }
@ -1007,9 +984,9 @@ class DolGraph
$j = 0; $j = 0;
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) { if (isset($y)) {
$serie[$i] .= ($j > 0 ? ", " : "").$y; $serie[$i] .= ($j > 0 ? ", " : "") . $y;
} else { } else {
$serie[$i] .= ($j > 0 ? ", " : "").'null'; $serie[$i] .= ($j > 0 ? ", " : "") . 'null';
} }
$j++; $j++;
} }
@ -1022,12 +999,11 @@ class DolGraph
$tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
$this->stringtoshow = '<!-- Build using chart -->'."\n"; $this->stringtoshow = '<!-- Build using chart -->' . "\n";
if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle'.(empty($this->cssprefix) ? '' : ' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; if (!empty($this->title)&&$this->title!='FunnelOfProspection') $this->stringtoshow .= '<div class="center dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>';
if (!empty($this->shownographyet)) if (!empty($this->shownographyet)) {
{ $this->stringtoshow .= '<div style="width:' . $this->width . (strpos($this->width, '%') > 0 ? '' : 'px') . '; height:' . $this->height . 'px;" class="nographyet"></div>';
$this->stringtoshow .= '<div style="width:'.$this->width.(strpos($this->width, '%') > 0 ? '' : 'px').'; height:'.$this->height.'px;" class="nographyet"></div>'; $this->stringtoshow .= '<div class="nographyettext margintoponly">' . $langs->trans("NotEnoughDataYet") . '...</div>';
$this->stringtoshow .= '<div class="nographyettext margintoponly">'.$langs->trans("NotEnoughDataYet").'...</div>';
return; return;
} }
@ -1036,17 +1012,15 @@ class DolGraph
if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical';
// No height for the pie grah // No height for the pie grah
$cssfordiv = 'dolgraphchart'; $cssfordiv = 'dolgraphchart';
if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar'.$this->type[$firstlot]; if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar' . $this->type[$firstlot];
$this->stringtoshow .= '<div id="placeholder_'.$tag.'" style="min-height: '.$this->height.(strpos($this->height, '%') > 0 ? '' : 'px').'; width:'.$this->width.(strpos($this->width, '%') > 0 ? '' : 'px').';" class="'.$cssfordiv.' dolgraph'.(empty($dolxaxisvertical) ? '' : ' '.$dolxaxisvertical).(empty($this->cssprefix) ? '' : ' dolgraph'.$this->cssprefix).' center"><canvas id="canvas_'.$tag.'"></canvas></div>'."\n"; $this->stringtoshow .= '<div id="placeholder_' . $tag . '" style="min-height: ' . $this->height . (strpos($this->height, '%') > 0 ? '' : 'px') . '; width:' . $this->width . (strpos($this->width, '%') > 0 ? '' : 'px') . ';" class="' . $cssfordiv . ' dolgraph' . (empty($dolxaxisvertical) ? '' : ' ' . $dolxaxisvertical) . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . ' center"><canvas id="canvas_' . $tag . '"></canvas></div>' . "\n";
$this->stringtoshow .= '<script id="'.$tag.'">'."\n"; $this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$i = $firstlot; $i = $firstlot;
if ($nblot < 0) if ($nblot < 0) {
{
$this->stringtoshow .= '<!-- No series of data -->'; $this->stringtoshow .= '<!-- No series of data -->';
} else { } else {
while ($i < $nblot) while ($i < $nblot) {
{
//$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n"; //$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n";
//$this->stringtoshow .= $serie[$i]."\n"; //$this->stringtoshow .= $serie[$i]."\n";
$i++; $i++;
@ -1055,69 +1029,69 @@ class DolGraph
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
// Special case for Graph of type 'pie', 'piesemicircle', or 'polar' // Special case for Graph of type 'pie', 'piesemicircle', or 'polar'
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 $legendMaxLines = 0; // Does not work
if (empty($showlegend)) { if (empty($showlegend)) {
$this->stringtoshow .= 'legend: { display: false }, '; $this->stringtoshow .= 'legend: { display: false }, ';
} else { } else {
$this->stringtoshow .= 'legend: { position: \''.($showlegend == 2 ? 'right' : 'top').'\''; $this->stringtoshow .= 'legend: { position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\'';
if (!empty($legendMaxLines)) { if (!empty($legendMaxLines)) {
$this->stringtoshow .= ', maxLines: '.$legendMaxLines.''; $this->stringtoshow .= ', maxLines: ' . $legendMaxLines . '';
} }
$this->stringtoshow .= ' }, '."\n"; $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";
} }
$this->stringtoshow .= 'elements: { arc: {'."\n"; $this->stringtoshow .= 'elements: { arc: {' . "\n";
// Color of earch arc // Color of earch arc
$this->stringtoshow .= 'backgroundColor: ['; $this->stringtoshow .= 'backgroundColor: [';
$i = 0; $foundnegativecolor = 0; $i = 0;
$foundnegativecolor = 0;
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
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) 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 { else {
$tmp = str_replace('#', '', $this->datacolor[$i]); $tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) { if (strpos($tmp, '-') !== false) {
$foundnegativecolor++; $foundnegativecolor++;
$color = '#FFFFFF'; // If $val is '-123' $color = '#FFFFFF'; // If $val is '-123'
} else $color = "#".$tmp; // If $val is '123' or '#123' } else $color = "#" . $tmp; // If $val is '123' or '#123'
} }
$this->stringtoshow .= "'".$color."'"; $this->stringtoshow .= "'" . $color . "'";
$i++; $i++;
} }
$this->stringtoshow .= '], '."\n"; $this->stringtoshow .= '], ' . "\n";
// Border color // Border color
if ($foundnegativecolor) { if ($foundnegativecolor) {
$this->stringtoshow .= 'borderColor: ['; $this->stringtoshow .= 'borderColor: [';
$i = 0; $i = 0;
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B) if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B)
else { else {
$tmp = str_replace('#', '', $this->datacolor[$i]); $tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) $color = '#'.str_replace('-', '', $tmp); // If $val is '-123' if (strpos($tmp, '-') !== false) $color = '#' . str_replace('-', '', $tmp); // If $val is '-123'
else $color = 'null'; // If $val is '123' or '#123' else $color = 'null'; // If $val is '123' or '#123'
} }
$this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'".$color."'"); $this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $color . "'");
$i++; $i++;
} }
$this->stringtoshow .= ']'; $this->stringtoshow .= ']';
} }
$this->stringtoshow .= '} } };'."\n"; $this->stringtoshow .= '} } };' . "\n";
$this->stringtoshow .= ' $this->stringtoshow .= '
var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d"); var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d");
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
// The type of chart we want to create // The type of chart we want to create
type: \''.(in_array($type, array('pie', 'piesemicircle')) ? 'doughnut' : 'polarArea').'\', type: \'' . (in_array($type, array('pie', 'piesemicircle')) ? 'doughnut' : 'polarArea') . '\',
// Configuration options go here // Configuration options go here
options: options, options: options,
data: { data: {
@ -1127,7 +1101,7 @@ class DolGraph
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '; if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
$i++; $i++;
} }
@ -1137,26 +1111,28 @@ class DolGraph
$i = 0; $i = 0;
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].')'; $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')';
//$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); //$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor));
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
$this->stringtoshow .= '{'."\n"; $this->stringtoshow .= '{' . "\n";
//$this->stringtoshow .= 'borderColor: \''.$color.'\', '; //$this->stringtoshow .= 'borderColor: \''.$color.'\', ';
//$this->stringtoshow .= 'backgroundColor: \''.$color.'\', '; //$this->stringtoshow .= 'backgroundColor: \''.$color.'\', ';
$this->stringtoshow .= ' data: ['.$serie[$i].']'; $this->stringtoshow .= ' data: [' . $serie[$i] . ']';
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$i++; $i++;
} }
$this->stringtoshow .= ']'."\n"; $this->stringtoshow .= ']' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
} }
// Other cases, graph of type 'bars', 'lines', 'linesnopoint' // Other cases, graph of type 'bars', 'lines', 'linesnopoint'
else { else {
$type = 'bar'; $type = 'bar';
$isfunnel = false;
if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar'; if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar';
if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') $type = 'horizontalBar'; if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') $type = 'horizontalBar';
if ($this->title == 'FunnelOfProspection') $isfunnel = true;
if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) $type = 'line'; if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) $type = 'line';
$this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, '; $this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
@ -1164,6 +1140,10 @@ class DolGraph
$this->stringtoshow .= 'legend: { display: false }, '; $this->stringtoshow .= 'legend: { display: false }, ';
} }
$this->stringtoshow .= 'scales: { xAxes: [{ '; $this->stringtoshow .= 'scales: { xAxes: [{ ';
if ($isfunnel) {
$this->stringtoshow .= ' ticks: { beginAtZero: true}, display: false,';
}
//$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js //$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js
$this->stringtoshow .= 'distribution: \'linear\''; $this->stringtoshow .= 'distribution: \'linear\'';
if ($type == 'bar' && count($arrayofgroupslegend) > 0) { if ($type == 'bar' && count($arrayofgroupslegend) > 0) {
@ -1175,23 +1155,24 @@ class DolGraph
} }
$this->stringtoshow .= ' }'; $this->stringtoshow .= ' }';
$this->stringtoshow .= '};'; $this->stringtoshow .= '};';
$this->stringtoshow .= ' $this->stringtoshow .= '
var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d"); var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d");
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
// The type of chart we want to create // The type of chart we want to create
type: \''.$type.'\', type: \'' . $type . '\',
// Configuration options go here // Configuration options go here
options: options, options: options,
data: { data: {
labels: ['; labels: [';
$i = 0; $i = 0;
foreach ($legends as $val) // Loop on each serie if (!$isfunnel);{
{ foreach ($legends as $val) // Loop on each serie
if ($i > 0) $this->stringtoshow .= ', '; {
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; if ($i > 0) $this->stringtoshow .= ', ';
$i++; $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
$i++;
}
} }
//var_dump($arrayofgroupslegend); //var_dump($arrayofgroupslegend);
@ -1205,6 +1186,7 @@ class DolGraph
$oldstacknum = -1; $oldstacknum = -1;
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$foundnegativecolor = 0;
$usecolorvariantforgroupby = 0; $usecolorvariantforgroupby = 0;
// We used a 'group by' and we have too many colors so we generated color variants per // 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. if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
@ -1233,7 +1215,7 @@ class DolGraph
$ratio = min(95, 10 + 10 * $iinstack); // step of 20 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
$brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
} else { // We decrease agressiveness of reference color for color 3, 5, 7, .. } else { // We decrease agressiveness of reference color for color 3, 5, 7, ..
$ratio = max(-100, - 15 * $iinstack + 10); // step of -20 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
$brightnessratio = min(90, 10 * $iinstack); // step of 20 $brightnessratio = min(90, 10 * $iinstack); // step of 20
} }
//var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio); //var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio);
@ -1242,37 +1224,59 @@ class DolGraph
} }
$oldstacknum = $arrayofgroupslegend[$i]['stacknum']; $oldstacknum = $arrayofgroupslegend[$i]['stacknum'];
$color = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].', 0.9)'; $color = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ', 0.9)';
$bordercolor = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].')'; $bordercolor = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ')';
} else { // We do not use a 'group by' } else { // We do not use a 'group by'
$color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].', 0.9)'; 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)
$bordercolor = $color; else {
//$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); $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'
$bordercolor = $color;
}
if ($foundnegativecolor) {
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) $bordercolor = '#' . str_replace('-', '', $tmp); // If $val is '-123'
else $bordercolor = 'null'; // If $val is '123' or '#123'
}
$bordercolor == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $bordercolor . "'";
}
}
} }
if ($i > 0) $this->stringtoshow .= ', '; if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
$this->stringtoshow .= '{'; $this->stringtoshow .= '{';
$this->stringtoshow .= 'dolibarrinfo: \'y_'.$i.'\', '; $this->stringtoshow .= 'dolibarrinfo: \'y_' . $i . '\', ';
$this->stringtoshow .= 'label: \''.dol_escape_js(dol_string_nohtmltag($textoflegend)).'\', '; $this->stringtoshow .= 'label: \'' . dol_escape_js(dol_string_nohtmltag($textoflegend)) . '\', ';
$this->stringtoshow .= 'pointStyle: \''.($this->type[$i] == 'linesnopoint' ? 'line' : 'circle').'\', '; $this->stringtoshow .= 'pointStyle: \'' . ($this->type[$i] == 'linesnopoint' ? 'line' : 'circle') . '\', ';
$this->stringtoshow .= 'fill: '.($type == 'bar' ? 'true' : 'false').', '; $this->stringtoshow .= 'fill: ' . ($type == 'bar' ? 'true' : 'false') . ', ';
if ($type == 'bar') { $this->stringtoshow .= 'borderWidth: \'1\', '; } if ($isfunnel){
$this->stringtoshow .= 'borderColor: \''.$bordercolor.'\', '; $this->stringtoshow .= 'borderWidth: \'2\', ';
$this->stringtoshow .= 'backgroundColor: \''.$color.'\', '; }
if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \''.$arrayofgroupslegend[$i]['stacknum'].'\', '; else if ($type == 'bar' || $type == 'horizontalBar') {
$this->stringtoshow .= 'data: ['.$serie[$i].']'; $this->stringtoshow .= 'borderWidth: \'1\', ';
$this->stringtoshow .= '}'."\n"; }
$this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', ';
$this->stringtoshow .= 'backgroundColor: \'' . $color . '\', ';
if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', ';
$this->stringtoshow .= 'data: [' . $serie[$i] . ']';
$this->stringtoshow .= '}' . "\n";
$i++; $i++;
$iinstack++; $iinstack++;
} }
$this->stringtoshow .= ']'."\n"; $this->stringtoshow .= ']' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
} }
$this->stringtoshow .= '</script>'."\n"; $this->stringtoshow .= '</script>' . "\n";
} }
@ -1301,14 +1305,13 @@ class DolGraph
{ {
global $langs; global $langs;
if ($shownographyet) if ($shownographyet) {
{ $s = '<div class="nographyet" style="width:' . (preg_match('/%/', $this->width) ? $this->width : $this->width . 'px') . '; height:' . (preg_match('/%/', $this->height) ? $this->height : $this->height . 'px') . ';"></div>';
$s = '<div class="nographyet" style="width:'.(preg_match('/%/', $this->width) ? $this->width : $this->width.'px').'; height:'.(preg_match('/%/', $this->height) ? $this->height : $this->height.'px').';"></div>';
$s .= '<div class="nographyettext margintoponly">'; $s .= '<div class="nographyettext margintoponly">';
if (is_numeric($shownographyet)) { if (is_numeric($shownographyet)) {
$s .= $langs->trans("NotEnoughDataYet").'...'; $s .= $langs->trans("NotEnoughDataYet") . '...';
} else { } else {
$s .= $shownographyet.'...'; $s .= $shownographyet . '...';
} }
$s .= '</div>'; $s .= '</div>';
return $s; return $s;