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 .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls";
$sql .= " WHERE active=1";
$sql .= " Order by cls.rowid";
$sql .= " AND cls.code != 'LOST'";
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
@ -108,7 +110,6 @@ class box_funnel_of_prospection extends ModeleBoxes
$colorseriesstat[$objp->rowid] = $badgeStatus6;
break;
default:
$colorseriesstat[$objp->rowid] = $badgeStatus2;
break;
}
$i++;
@ -167,14 +168,16 @@ class box_funnel_of_prospection extends ModeleBoxes
$stringtoprint = '';
$stringtoprint .= '<div class="div-table-responsive-no-min ">';
$listofstatus = array_keys($listofoppstatus);
$liststatus = array();
$data = array('');
foreach ($listofstatus as $status) {
$labelStatus = '';
if ($status != 7) {
$code = dol_getIdFromCode($this->db, $status, 'c_lead_status', 'rowid', 'code');
if ($code) $labelStatus = $langs->transnoentitiesnoconv("OppStatus" . $code);
if (empty($labelStatus)) $labelStatus = $listofopplabel[$status];
$dataseries[] = array($labelStatus,(isset($valsamount[$status]) ? (float) $valsamount[$status] : 0));
$liststatus[] = $labelStatus;
$data[] = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
if (!$conf->use_javascript_ajax) {
$stringtoprint .= '<tr class="oddeven">';
$stringtoprint .= '<td>' . $labelStatus . '</td>';
@ -183,16 +186,21 @@ class box_funnel_of_prospection extends ModeleBoxes
}
}
}
$dataseries[] = $data;
if ($conf->use_javascript_ajax) {
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
$dolgraph = new DolGraph();
$dolgraph->SetMinValue(0);
$dolgraph->SetData($dataseries);
$dolgraph->SetLegend($liststatus);
$dolgraph->SetDataColor(array_values($colorseriesstat));
//$dolgraph->SetLegend(array('PROSP',$dataseries['PROSP']));
$dolgraph->setShowLegend(2);
$dolgraph->setShowPercent(1);
$dolgraph->SetType(array('pie'));
$dolgraph->setTitle('FunnelOfProspection');
$dolgraph->SetType(array('horizontalbars'));
$dolgraph->SetHeight('200');
$dolgraph->SetWidth('600');
$dolgraph->mode='depth';
$dolgraph->draw('idgraphstatus');
$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->bgcolor = array(235, 235, 224);
$color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
if (is_readable($color_file))
{
$color_file = DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
if (is_readable($color_file)) {
include_once $color_file;
if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor;
if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor;
@ -261,7 +260,7 @@ class DolGraph
* Set type
*
* @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
*/
public function SetType($type)
@ -466,10 +465,8 @@ class DolGraph
// phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_color))
{
if ($bg_color == 'onglet')
{
if (!is_array($bg_color)) {
if ($bg_color == 'onglet') {
//print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolor = $theme_bgcoloronglet;
} else {
@ -492,10 +489,8 @@ class DolGraph
// phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_colorgrid))
{
if ($bg_colorgrid == 'onglet')
{
if (!is_array($bg_colorgrid)) {
if ($bg_colorgrid == 'onglet') {
//print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolorgrid = $theme_bgcoloronglet;
} else {
@ -535,10 +530,8 @@ class DolGraph
$nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++)
{
for ($i = 0; $i < $nbvalues; $i++)
{
for ($j = 0; $j < $nblines; $j++) {
for ($i = 0; $i < $nbvalues; $i++) {
$vals[$k] = $this->data[$j][$i + 1];
$k++;
}
@ -564,10 +557,8 @@ class DolGraph
$nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++)
{
for ($i = 0; $i < $nbvalues; $i++)
{
for ($j = 0; $j < $nblines; $j++) {
for ($i = 0; $i < $nbvalues; $i++) {
$vals[$k] = $this->data[$j][$i + 1];
$k++;
}
@ -589,8 +580,7 @@ class DolGraph
if ($max != 0) $max++;
$size = dol_strlen(abs(ceil($max)));
$factor = 1;
for ($i = 0; $i < ($size - 1); $i++)
{
for ($i = 0; $i < ($size - 1); $i++) {
$factor *= 10;
}
@ -615,8 +605,7 @@ class DolGraph
if ($min != 0) $min--;
$size = dol_strlen(abs(floor($min)));
$factor = 1;
for ($i = 0; $i < ($size - 1); $i++)
{
for ($i = 0; $i < ($size - 1); $i++) {
$factor *= 10;
}
@ -635,24 +624,21 @@ class DolGraph
*/
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.";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR);
dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
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";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR);
dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
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";
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));
}
@ -678,10 +664,9 @@ class DolGraph
// phpcs:enable
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';
return;
}
@ -701,7 +686,7 @@ class DolGraph
while ($i < $nblot) // Loop on each serie
{
$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
$x = 0;
@ -712,14 +697,13 @@ class DolGraph
$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) {
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 {
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('-', '.'))));
$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->shownographyet))
{
$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 = '<!-- 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->shownographyet)) {
$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>';
return;
}
// Start the div that will contains all the graph
$dolxaxisvertical = '';
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 .= '$(function () {'."\n";
$this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$this->stringtoshow .= '$(function () {' . "\n";
$i = $firstlot;
if ($nblot < 0)
{
$this->stringtoshow .= '<!-- No series of data -->'."\n";
if ($nblot < 0) {
$this->stringtoshow .= '<!-- No series of data -->' . "\n";
} else {
while ($i < $nblot)
{
$this->stringtoshow .= '<!-- Serie '.$i.' -->'."\n";
$this->stringtoshow .= $serie[$i]."\n";
while ($i < $nblot) {
$this->stringtoshow .= '<!-- Serie ' . $i . ' -->' . "\n";
$this->stringtoshow .= $serie[$i] . "\n";
$i++;
}
}
$this->stringtoshow .= "\n";
// 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();
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'
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
@ -773,17 +753,17 @@ class DolGraph
$showpercent = $this->showpercent;
$this->stringtoshow .= '
function plotWithOptions_'.$tag.'() {
$.plot($("#placeholder_'.$tag.'"), d0,
function plotWithOptions_' . $tag . '() {
$.plot($("#placeholder_' . $tag . '"), d0,
{
series: {
pie: {
show: true,
radius: 0.8,
'.($this->combine ? '
' . ($this->combine ? '
combine: {
threshold: '.$this->combine.'
},' : '').'
threshold: ' . $this->combine . '
},' : '') . '
label: {
show: true,
radius: 0.9,
@ -791,15 +771,15 @@ class DolGraph
var percent=Math.round(series.percent);
var number=series.data[0][1];
return \'';
$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.'">';
$this->stringtoshow .= '\'+';
$this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend
$this->stringtoshow .= ($showpointvalue ? 'number+' : '');
$this->stringtoshow .= ($showpercent ? '\'<br/>\'+percent+\'%\'+' : '');
$this->stringtoshow .= '\'';
if ($urltemp) $this->stringtoshow .= '</a>';
$this->stringtoshow .= '</span>\';
$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 . '">';
$this->stringtoshow .= '\'+';
$this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend
$this->stringtoshow .= ($showpointvalue ? 'number+' : '');
$this->stringtoshow .= ($showpercent ? '\'<br/>\'+percent+\'%\'+' : '');
$this->stringtoshow .= '\'';
if ($urltemp) $this->stringtoshow .= '</a>';
$this->stringtoshow .= '</span>\';
},
background: {
opacity: 0.0,
@ -814,21 +794,20 @@ class DolGraph
pan: {
interactive: true
},';
if (count($datacolor))
{
$this->stringtoshow .= 'colors: '.(!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
if (count($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'
else {
// Add code to support tooltips
// TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes
$this->stringtoshow .= '
function showTooltip_'.$tag.'(x, y, contents) {
$(\'<div class="graph-tooltip-inner" id="tooltip_'.$tag.'">\' + contents + \'</div>\').css({
function showTooltip_' . $tag . '(x, y, contents) {
$(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag . '">\' + contents + \'</div>\').css({
position: \'absolute\',
display: \'none\',
top: y + 10,
@ -844,7 +823,7 @@ class DolGraph
}
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));
$("#y").text(pos.y.toFixed(2));
@ -858,27 +837,26 @@ class DolGraph
var y = item.datapoint[1].toFixed(2);
var z = item.series.xaxis.ticks[item.dataIndex].label;
';
if ($this->showpointvalue > 0) $this->stringtoshow .= '
showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
if ($this->showpointvalue > 0) $this->stringtoshow .= '
showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
';
$this->stringtoshow .= '
$this->stringtoshow .= '
}
}
else {
$("#tooltip_'.$tag.'").remove();
$("#tooltip_' . $tag . '").remove();
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 .= '$.plot($("#placeholder_'.$tag.'"), [ '."\n";
$this->stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n";
$this->stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n";
$i = $firstlot;
while ($i < $nblot)
{
if ($i > $firstlot) $this->stringtoshow .= ', '."\n";
while ($i < $nblot) {
if ($i > $firstlot) $this->stringtoshow .= ', ' . "\n";
$color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
$this->stringtoshow .= '{ ';
if (!isset($this->type[$i]) || $this->type[$i] == 'bars') {
@ -886,42 +864,41 @@ class DolGraph
if ($i == $firstlot) $align = 'right';
elseif ($i == $firstlot + 1) $align = 'center';
else $align = 'left';
$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 }, ';
$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 }, ';
}
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.' }';
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 . ' }';
$i++;
}
// 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
$this->stringtoshow .= ', xaxis: { ticks: ['."\n";
$this->stringtoshow .= ', xaxis: { ticks: [' . "\n";
$x = 0;
foreach ($this->data as $key => $valarray)
{
if ($x > 0) $this->stringtoshow .= ', '."\n";
$this->stringtoshow .= ' ['.$x.', "'.$valarray[0].'"]';
foreach ($this->data as $key => $valarray) {
if ($x > 0) $this->stringtoshow .= ', ' . "\n";
$this->stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]';
$x++;
}
$this->stringtoshow .= '] }'."\n";
$this->stringtoshow .= '] }' . "\n";
// Yaxis
$this->stringtoshow .= ', yaxis: { min: '.$this->MinValue.', max: '.($this->MaxValue).' }'."\n";
$this->stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . ($this->MaxValue) . ' }' . "\n";
// Background color
$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]);
$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 .= '});'."\n";
$this->stringtoshow .= '}'."\n";
$this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '}' . "\n";
}
$this->stringtoshow .= 'plotWithOptions_'.$tag.'();'."\n";
$this->stringtoshow .= '});'."\n";
$this->stringtoshow .= '</script>'."\n";
$this->stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n";
$this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '</script>' . "\n";
}
@ -947,10 +924,9 @@ class DolGraph
// phpcs:enable
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';
return;
}
@ -971,7 +947,8 @@ class DolGraph
// 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
$serie = array(); $arrayofgroupslegend = array();
$serie = array();
$arrayofgroupslegend = array();
//var_dump($this->data);
$i = $firstlot;
@ -989,15 +966,15 @@ class DolGraph
$alabelexists = 1;
$tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
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);
$arrayofgroupslegend[$i] = array(
'stacknum'=> $tmpykey[1],
'stacknum' => $tmpykey[1],
'legend' => $this->Legend[$tmpykey[1]],
'legendwithgroup' => $this->Legend[$tmpykey[1]].' - '.$tmpykey[2]
'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2]
);
} 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);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
}
@ -1007,9 +984,9 @@ class DolGraph
$j = 0;
foreach ($values as $x => $y) {
if (isset($y)) {
$serie[$i] .= ($j > 0 ? ", " : "").$y;
$serie[$i] .= ($j > 0 ? ", " : "") . $y;
} else {
$serie[$i] .= ($j > 0 ? ", " : "").'null';
$serie[$i] .= ($j > 0 ? ", " : "") . 'null';
}
$j++;
}
@ -1022,12 +999,11 @@ class DolGraph
$tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
$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->shownographyet))
{
$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 = '<!-- Build using chart -->' . "\n";
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)) {
$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>';
return;
}
@ -1036,17 +1012,15 @@ class DolGraph
if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical';
// No height for the pie grah
$cssfordiv = 'dolgraphchart';
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";
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 .= '<script id="'.$tag.'">'."\n";
$this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$i = $firstlot;
if ($nblot < 0)
{
if ($nblot < 0) {
$this->stringtoshow .= '<!-- No series of data -->';
} else {
while ($i < $nblot)
{
while ($i < $nblot) {
//$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n";
//$this->stringtoshow .= $serie[$i]."\n";
$i++;
@ -1055,69 +1029,69 @@ class DolGraph
$this->stringtoshow .= "\n";
// 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
$this->stringtoshow .= 'var options = {'."\n";
$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').'\'';
$this->stringtoshow .= 'legend: { position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\'';
if (!empty($legendMaxLines)) {
$this->stringtoshow .= ', maxLines: '.$legendMaxLines.'';
$this->stringtoshow .= ', maxLines: ' . $legendMaxLines . '';
}
$this->stringtoshow .= ' }, '."\n";
$this->stringtoshow .= ' }, ' . "\n";
}
if ($this->type[$firstlot] == 'piesemicircle') {
$this->stringtoshow .= 'circumference: Math.PI,'."\n";
$this->stringtoshow .= 'rotation: -Math.PI,'."\n";
$this->stringtoshow .= 'circumference: Math.PI,' . "\n";
$this->stringtoshow .= 'rotation: -Math.PI,' . "\n";
}
$this->stringtoshow .= 'elements: { arc: {'."\n";
$this->stringtoshow .= 'elements: { arc: {' . "\n";
// Color of earch arc
$this->stringtoshow .= 'backgroundColor: [';
$i = 0; $foundnegativecolor = 0;
$i = 0;
$foundnegativecolor = 0;
foreach ($legends as $val) // Loop on each serie
{
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 ($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)
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'
} else $color = "#" . $tmp; // If $val is '123' or '#123'
}
$this->stringtoshow .= "'".$color."'";
$this->stringtoshow .= "'" . $color . "'";
$i++;
}
$this->stringtoshow .= '], '."\n";
$this->stringtoshow .= '], ' . "\n";
// Border color
if ($foundnegativecolor) {
$this->stringtoshow .= 'borderColor: [';
$i = 0;
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)
else {
$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'
}
$this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'".$color."'");
$this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $color . "'");
$i++;
}
$this->stringtoshow .= ']';
}
$this->stringtoshow .= '} } };'."\n";
$this->stringtoshow .= '} } };' . "\n";
$this->stringtoshow .= '
var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d");
var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d");
var chart = new Chart(ctx, {
// 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
options: options,
data: {
@ -1127,7 +1101,7 @@ class DolGraph
foreach ($legends as $val) // Loop on each serie
{
if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
$this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
$i++;
}
@ -1137,26 +1111,28 @@ class DolGraph
$i = 0;
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));
if ($i > 0) $this->stringtoshow .= ', '."\n";
$this->stringtoshow .= '{'."\n";
if ($i > 0) $this->stringtoshow .= ', ' . "\n";
$this->stringtoshow .= '{' . "\n";
//$this->stringtoshow .= 'borderColor: \''.$color.'\', ';
//$this->stringtoshow .= 'backgroundColor: \''.$color.'\', ';
$this->stringtoshow .= ' data: ['.$serie[$i].']';
$this->stringtoshow .= '}'."\n";
$this->stringtoshow .= ' data: [' . $serie[$i] . ']';
$this->stringtoshow .= '}' . "\n";
$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'
else {
$type = 'bar';
$isfunnel = false;
if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar';
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';
$this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
@ -1164,6 +1140,10 @@ class DolGraph
$this->stringtoshow .= 'legend: { display: false }, ';
}
$this->stringtoshow .= 'scales: { xAxes: [{ ';
if ($isfunnel) {
$this->stringtoshow .= ' ticks: { beginAtZero: true}, display: false,';
}
//$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js
$this->stringtoshow .= 'distribution: \'linear\'';
if ($type == 'bar' && count($arrayofgroupslegend) > 0) {
@ -1175,23 +1155,24 @@ class DolGraph
}
$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, {
// The type of chart we want to create
type: \''.$type.'\',
type: \'' . $type . '\',
// Configuration options go here
options: options,
data: {
labels: [';
$i = 0;
foreach ($legends as $val) // Loop on each serie
{
if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
$i++;
if (!$isfunnel);{
foreach ($legends as $val) // Loop on each serie
{
if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
$i++;
}
}
//var_dump($arrayofgroupslegend);
@ -1205,6 +1186,7 @@ class DolGraph
$oldstacknum = -1;
while ($i < $nblot) // Loop on each serie
{
$foundnegativecolor = 0;
$usecolorvariantforgroupby = 0;
// 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.
@ -1233,7 +1215,7 @@ class DolGraph
$ratio = min(95, 10 + 10 * $iinstack); // step of 20
$brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
} 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
}
//var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio);
@ -1242,37 +1224,59 @@ class DolGraph
}
$oldstacknum = $arrayofgroupslegend[$i]['stacknum'];
$color = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].', 0.9)';
$bordercolor = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].')';
} else { // We do not use a 'group by'
$color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].', 0.9)';
$bordercolor = $color;
//$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor));
$color = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ', 0.9)';
$bordercolor = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ')';
} else { // We do not use a 'group by'
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'
$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 .= ', ';
$this->stringtoshow .= "\n";
$this->stringtoshow .= '{';
$this->stringtoshow .= 'dolibarrinfo: \'y_'.$i.'\', ';
$this->stringtoshow .= 'label: \''.dol_escape_js(dol_string_nohtmltag($textoflegend)).'\', ';
$this->stringtoshow .= 'pointStyle: \''.($this->type[$i] == 'linesnopoint' ? 'line' : 'circle').'\', ';
$this->stringtoshow .= 'fill: '.($type == 'bar' ? 'true' : 'false').', ';
if ($type == 'bar') { $this->stringtoshow .= 'borderWidth: \'1\', '; }
$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";
$this->stringtoshow .= 'dolibarrinfo: \'y_' . $i . '\', ';
$this->stringtoshow .= 'label: \'' . dol_escape_js(dol_string_nohtmltag($textoflegend)) . '\', ';
$this->stringtoshow .= 'pointStyle: \'' . ($this->type[$i] == 'linesnopoint' ? 'line' : 'circle') . '\', ';
$this->stringtoshow .= 'fill: ' . ($type == 'bar' ? 'true' : 'false') . ', ';
if ($isfunnel){
$this->stringtoshow .= 'borderWidth: \'2\', ';
}
else if ($type == 'bar' || $type == 'horizontalBar') {
$this->stringtoshow .= 'borderWidth: \'1\', ';
}
$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++;
$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;
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>';
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="nographyettext margintoponly">';
if (is_numeric($shownographyet)) {
$s .= $langs->trans("NotEnoughDataYet").'...';
$s .= $langs->trans("NotEnoughDataYet") . '...';
} else {
$s .= $shownographyet.'...';
$s .= $shownographyet . '...';
}
$s .= '</div>';
return $s;