216 $this->bordercolor = array(235, 235, 224);
217 $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
218 $this->bgcolor = array(235, 235, 224);
221 if (!empty($conf->dol_optimize_smallscreen)) {
226 $color_file = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/theme_vars.inc.php';
227 if (is_readable($color_file)) {
229 if (isset($theme_bordercolor)) {
230 $this->bordercolor = $theme_bordercolor;
235 if (isset($theme_bgcolor)) {
236 $this->bgcolor = $theme_bgcolor;
241 $this->_library = $library;
242 if ($this->_library ==
'auto') {
243 $this->_library = (!
getDolGlobalString(
'MAIN_JS_GRAPH') ?
'chart' : $conf->global->MAIN_JS_GRAPH);
904 dol_syslog(get_class($this) .
"::draw_jflot this->type=" . implode(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
906 if (empty($this->width) && empty($this->height)) {
907 print
'Error width or height not set';
913 if (is_array($this->data) && is_array($this->data[0])) {
914 $nblot = count($this->data[0]) - 1;
917 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
925 while ($i < $nblot) {
927 $series[$i] =
"var d" . $i .
" = [];\n";
931 foreach ($this->data as $valarray) {
932 $legends[$x] = $valarray[0];
933 $values[$x] = (is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] :
null);
937 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
938 foreach ($values as $x => $y) {
940 $series[$i] .=
'd' . $i .
'.push({"label":"' .
dol_escape_js($legends[$x]) .
'", "data":' . $y .
'});' .
"\n";
944 foreach ($values as $x => $y) {
946 $series[$i] .=
'd' . $i .
'.push([' . $x .
', ' . $y .
']);' .
"\n";
956 $this->stringtoshow =
'<!-- Build using jflot -->' .
"\n";
957 if (!empty($this->title)) {
958 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
960 if (!empty($this->shownographyet)) {
961 $this->stringtoshow .=
'<div style="width:' . $this->width .
'px;height:' . $this->height .
'px;" class="nographyet"></div>';
962 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
967 $dolxaxisvertical =
'';
968 if (count($this->data) > 20) {
969 $dolxaxisvertical =
'dol-xaxis-vertical';
971 $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";
973 $this->stringtoshow .=
'<script nonce="'.getNonce().
'" id="' . $tag .
'">' .
"\n";
974 $this->stringtoshow .=
'$(function () {' .
"\n";
977 $this->stringtoshow .=
'<!-- No series of data -->' .
"\n";
979 while ($i < $nblot) {
980 $this->stringtoshow .=
'<!-- Series ' . $i .
' -->' .
"\n";
981 $this->stringtoshow .= $series[$i] .
"\n";
985 $this->stringtoshow .=
"\n";
988 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
989 $datacolor = array();
990 foreach ($this->datacolor as $val) {
991 if (is_array($val)) {
992 $datacolor[] =
"#" . sprintf(
"%02x%02x%02x", $val[0], $val[1], $val[2]);
994 $datacolor[] =
"#" . str_replace(array(
'#',
'-'),
'', $val);
999 $showlegend = $this->showlegend;
1000 $showpointvalue = $this->showpointvalue;
1001 $showpercent = $this->showpercent;
1003 $this->stringtoshow .=
'
1004 function plotWithOptions_' . $tag .
'() {
1005 $.plot($("#placeholder_' . $tag .
'"), d0,
1011 ' . ($this->combine ?
'
1013 threshold: ' . $this->combine .
'
1018 formatter: function(label, series) {
1019 var percent=Math.round(series.percent);
1020 var number=series.data[0][1];
1022 $this->stringtoshow .=
'<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
1024 $this->stringtoshow .=
'<a style="color: #FFFFFF;" border="0" href="' . $urltemp .
'">';
1026 $this->stringtoshow .=
'\'+
';
1027 $this->stringtoshow .= ($showlegend ? '' : 'label+\
' \'+');
1028 $this->stringtoshow .= ($showpointvalue ?
'number+' :
'');
1029 $this->stringtoshow .= ($showpercent ?
'\'<br>\
'+percent+\'%\'+' :
'');
1030 $this->stringtoshow .=
'\'';
1032 $this->stringtoshow .=
'</a>';
1034 $this->stringtoshow .=
'</span>\';
1049 if (count($datacolor)) {
1050 $this->stringtoshow .=
'colors: ' . json_encode($datacolor) .
',';
1052 $this->stringtoshow .=
'legend: {show: ' . ($showlegend ?
'true' :
'false') .
', position: \'ne\' }
1059 $this->stringtoshow .=
'
1060 function showTooltip_' . $tag .
'(x, y, contents) {
1061 $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag .
'">\' + contents + \'</div>\').css({
1062 position: \'absolute\',
1066 border: \'1px solid #000\',
1068 \'background-color\': \'#000\',
1069 \'color\': \'#fff\',
1070 \'font-weight\': \'bold\',
1073 }).appendTo("body").fadeIn(100);
1076 var previousPoint = null;
1077 $("#placeholder_' . $tag .
'").bind("plothover", function (event, pos, item) {
1078 $("#x").text(pos.x.toFixed(2));
1079 $("#y").text(pos.y.toFixed(2));
1082 if (previousPoint != item.dataIndex) {
1083 previousPoint = item.dataIndex;
1085 $("#tooltip").remove();
1086 /* console.log(item); */
1087 var x = item.datapoint[0].toFixed(2);
1088 var y = item.datapoint[1].toFixed(2);
1089 var z = item.series.xaxis.ticks[item.dataIndex].label;
1091 if ($this->showpointvalue > 0) {
1092 $this->stringtoshow .=
'
1093 showTooltip_' . $tag .
'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
1096 $this->stringtoshow .=
'
1100 $("#tooltip_' . $tag .
'").remove();
1101 previousPoint = null;
1106 $this->stringtoshow .=
'var stack = null, steps = false;' .
"\n";
1108 $this->stringtoshow .=
'function plotWithOptions_' . $tag .
'() {' .
"\n";
1109 $this->stringtoshow .=
'$.plot($("#placeholder_' . $tag .
'"), [ ' .
"\n";
1111 while ($i < $nblot) {
1112 if ($i > $firstlot) {
1113 $this->stringtoshow .=
', ' .
"\n";
1115 $color = sprintf(
"%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
1116 $this->stringtoshow .=
'{ ';
1117 if (!isset($this->
type[$i]) || $this->
type[$i] ==
'bars') {
1119 if ($i == $firstlot) {
1121 } elseif ($i == $firstlot + 1) {
1126 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . $align .
'", barWidth: 0.45 }, ';
1128 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ?
'center' :
'left') .
'", barWidth: 0.5 }, ';
1131 if (isset($this->
type[$i]) && ($this->
type[$i] ==
'lines' || $this->
type[$i] ==
'linesnopoint')) {
1132 $this->stringtoshow .=
'lines: { show: true, fill: false }, points: { show: ' . ($this->
type[$i] ==
'linesnopoint' ?
'false' :
'true') .
' }, ';
1134 $this->stringtoshow .=
'color: "#' . $color .
'", label: "' . (isset($this->Legend[$i]) ?
dol_escape_js($this->Legend[$i]) :
'') .
'", data: d' . $i .
' }';
1138 $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";
1141 $this->stringtoshow .=
', xaxis: { ticks: [' .
"\n";
1143 foreach ($this->data as $key => $valarray) {
1145 $this->stringtoshow .=
', ' .
"\n";
1147 $this->stringtoshow .=
' [' . $x .
', "' . $valarray[0] .
'"]';
1150 $this->stringtoshow .=
'] }' .
"\n";
1153 $this->stringtoshow .=
', yaxis: { min: ' . $this->MinValue .
', max: ' . ($this->MaxValue) .
' }' .
"\n";
1156 $color1 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
1157 $color2 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
1158 $this->stringtoshow .=
', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 .
'", "#' . $color2 .
'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' .
"\n";
1159 $this->stringtoshow .=
'});' .
"\n";
1160 $this->stringtoshow .=
'}' .
"\n";
1163 $this->stringtoshow .=
'plotWithOptions_' . $tag .
'();' .
"\n";
1164 $this->stringtoshow .=
'});' .
"\n";
1165 $this->stringtoshow .=
'</script>' .
"\n";
1191 dol_syslog(get_class($this) .
"::draw_chart this->type=" . implode(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
1193 if (empty($this->width) && empty($this->height)) {
1194 print
'Error width or height not set';
1198 $showlegend = $this->showlegend;
1203 if (is_array($this->data)) {
1204 foreach ($this->data as $valarray) {
1205 $nblot = max($nblot, count($valarray) - 1);
1210 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
1217 '@phan-var-force array<int,array{stacknum:int,legend:string,legendwithgroup:string}> $arrayofgroupslegend';
1218 $arrayofgroupslegend = array();
1222 while ($i < $nblot) {
1228 foreach ($this->data as $valarray) {
1229 $legends[$x] = (array_key_exists(
'label', $valarray) ? $valarray[
'label'] : $valarray[0]);
1230 $array_of_ykeys = array_keys($valarray);
1232 $ykeyindex = $i + ($alabelexists ? 1 : 0);
1233 $tmpykey = isset($array_of_ykeys[$ykeyindex]) ? explode(
'_', (
string) $array_of_ykeys[$ykeyindex], 3) : array();
1234 if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] ==
'0')) {
1235 $tmpvalue = (array_key_exists(
'y_' . $tmpykey[1] .
'_' . $tmpykey[2], $valarray) ? $valarray[
'y_' . $tmpykey[1] .
'_' . $tmpykey[2]] : ($valarray[$i + 1] ??
null));
1236 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1237 $arrayofgroupslegend[$i] = array(
1238 'stacknum' => (
int) $tmpykey[1],
1239 'legend' => $this->Legend[$tmpykey[1]] ??
'',
1240 'legendwithgroup' => ($this->Legend[$tmpykey[1]] ??
'') .
' - ' . $tmpykey[2]
1243 $tmpvalue = (array_key_exists(
'y_' . $i, $valarray) ? $valarray[
'y_' . $i] : ($valarray[$i + 1] ??
null));
1245 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1251 foreach ($values as $x => $y) {
1253 $series[$i] .= ($j > 0 ?
", " :
"") . $y;
1255 $series[$i] .= ($j > 0 ?
", " :
"") .
'null';
1268 $this->stringtoshow =
'<!-- Build using chart -->' .
"\n";
1269 if (!empty($this->title)) {
1270 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
1272 if (!empty($this->shownographyet)) {
1273 $this->stringtoshow .=
'<div style="width:' . $this->width . (strpos($this->width,
'%') > 0 ?
'' :
'px') .
'; height:' . $this->height .
'px;" class="nographyet"></div>';
1274 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
1279 $dolxaxisvertical =
'';
1280 if (count($this->data) > 20) {
1281 $dolxaxisvertical =
'dol-xaxis-vertical';
1284 $cssfordiv =
'dolgraphchart';
1285 if (isset($this->
type[$firstlot])) {
1286 $cssfordiv .=
' dolgraphchar' . $this->
type[$firstlot];
1288 $this->stringtoshow .=
'<div id="placeholder_'.$tag.
'" style="min-height: '.$this->height.(strpos((
string) $this->height,
'%') > 0 ?
'' :
'px').
'; max-height: '.(strpos((
string) $this->height,
'%') > 0 ? $this->height : ((int) $this->height + 100) .
'px').
'; width:'.$this->width.(strpos((
string) $this->width,
'%') > 0 ?
'' :
'px').
';" class="'.$cssfordiv.
' dolgraph'.(empty($dolxaxisvertical) ?
'' :
' '.$dolxaxisvertical).(empty($this->cssprefix) ?
'' :
' dolgraph'.$this->cssprefix).
' center">'.
"\n";
1289 $this->stringtoshow .=
'<canvas id="canvas_'.$tag.
'"></canvas></div>'.
"\n";
1291 $this->stringtoshow .=
'<script nonce="'.getNonce().
'" id="' . $tag .
'">' .
"\n";
1294 $this->stringtoshow .=
'<!-- No series of data -->';
1296 while ($i < $nblot) {
1302 $this->stringtoshow .=
"\n";
1305 if (isset($this->
type[$firstlot]) && (in_array($this->
type[$firstlot], array(
'pie',
'polar',
'piesemicircle')))) {
1306 $type = $this->
type[$firstlot];
1308 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1311 $legendMaxLines = 0;
1314 if (empty($showlegend)) {
1315 $this->stringtoshow .=
'legend: { display: false }, ';
1317 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1318 if (!empty($legendMaxLines)) {
1319 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1321 $this->stringtoshow .=
' }, ' .
"\n";
1325 $this->stringtoshow .=
'plugins: { ';
1326 if (empty($showlegend)) {
1327 $this->stringtoshow .=
'legend: { display: false }, ';
1329 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1330 if (!empty($legendMaxLines)) {
1331 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1333 $this->stringtoshow .=
' }, ' .
"\n";
1335 $this->stringtoshow .=
' }, ' .
"\n";
1338 if ($this->
type[$firstlot] ==
'piesemicircle') {
1339 $this->stringtoshow .=
'circumference: Math.PI,' .
"\n";
1340 $this->stringtoshow .=
'rotation: -Math.PI,' .
"\n";
1342 $this->stringtoshow .=
'elements: { arc: {' .
"\n";
1344 $this->stringtoshow .=
'backgroundColor: [';
1346 $foundnegativecolor = 0;
1347 foreach ($legends as $val) {
1349 $this->stringtoshow .=
', ' .
"\n";
1351 if (is_array($this->datacolor[$i])) {
1352 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1354 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1355 if (strpos($tmp,
'-') !==
false) {
1356 $foundnegativecolor++;
1357 $color =
'rgba(0,0,0,.0)';
1359 $color =
"#" . $tmp;
1362 $this->stringtoshow .=
"'" . $color .
"'";
1365 $this->stringtoshow .=
'], ' .
"\n";
1367 if ($foundnegativecolor) {
1368 $this->stringtoshow .=
'borderColor: [';
1370 foreach ($legends as $val) {
1372 $this->stringtoshow .=
', ' .
"\n";
1374 if ($this->datacolor !==
null) {
1375 $datacolor_item = $this->datacolor[$i];
1377 $datacolor_item =
null;
1380 if (is_array($datacolor_item) || $datacolor_item ===
null) {
1383 $tmpcolor = str_replace(
'#',
'', $datacolor_item);
1384 if (strpos($tmpcolor,
'-') !==
false) {
1385 $color =
'#' . str_replace(
'-',
'', $tmpcolor);
1390 $this->stringtoshow .= ($color ==
'null' ?
"'rgba(0,0,0,0.2)'" :
"'" . $color .
"'");
1393 $this->stringtoshow .=
']';
1395 $this->stringtoshow .=
'} } };' .
"\n";
1397 $this->stringtoshow .=
'
1398 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1399 var chart = new Chart(ctx, {
1400 // The type of chart we want to create
1401 type: \'' . (in_array($type, array(
'pie',
'piesemicircle')) ?
'doughnut' :
'polarArea') .
'\',
1408 foreach ($legends as $val) { // Loop on each series
1410 $this->stringtoshow .= ',
';
1412 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 25)) . "'"; // Lower than 25 make some important label (that we can't shorten) to be truncated
1416 $this->stringtoshow .=
'],
1419 while ($i < $nblot) {
1420 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1423 $this->stringtoshow .=
', ' .
"\n";
1425 $this->stringtoshow .=
'{' .
"\n";
1428 $this->stringtoshow .=
' data: [' . $series[$i] .
']';
1429 $this->stringtoshow .=
'}' .
"\n";
1432 $this->stringtoshow .=
']' .
"\n";
1433 $this->stringtoshow .=
'}' .
"\n";
1434 $this->stringtoshow .=
'});' .
"\n";
1440 if (isset($this->
type[$firstlot]) && $this->
type[$firstlot] ==
'horizontalbars') {
1441 $xaxis =
"indexAxis: 'y', ";
1443 if (isset($this->
type[$firstlot]) && ($this->
type[$firstlot] ==
'lines' || $this->
type[$firstlot] ==
'linesnopoint')) {
1448 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1449 $this->stringtoshow .= $xaxis;
1450 if ($this->showpointvalue == 2) {
1451 $this->stringtoshow .=
'interaction: { intersect: true, mode: \'index\'}, ';
1464 $this->stringtoshow .=
'plugins: { '.
"\n";
1465 if (empty($showlegend)) {
1466 $this->stringtoshow .=
'legend: { display: false }, '.
"\n";
1468 $this->stringtoshow .=
'legend: { maxWidth: '.round(intval($this->width) / 2).
', labels: { boxWidth: 15 }, position: \'' . (($showlegend && $showlegend == 2) ?
'right' :
'top') .
'\' },
'."\n";
1470 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1471 $this->stringtoshow .= 'tooltip: { mode: \
'nearest\',
1473 if (is_array($this->tooltipsTitles)) {
1474 $this->stringtoshow .=
'
1475 title: function(tooltipItem, data) {
1476 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1477 return tooltipsTitle[tooltipItem[0].datasetIndex];
1480 if (is_array($this->tooltipsLabels)) {
1481 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1482 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1483 return tooltipslabels[tooltipItem.datasetIndex]
1486 $this->stringtoshow .=
'}},';
1488 $this->stringtoshow .=
"}, \n";
1491 if ($this->hideYValues || $this->hideXValues) {
1492 $this->stringtoshow .=
'scales: { ';
1493 if ($this->hideXValues) {
1494 $this->stringtoshow .=
'x: { display: false }';
1496 if ($this->hideYValues && $this->hideXValues) {
1497 $this->stringtoshow .=
', ';
1499 if ($this->hideYValues) {
1500 $this->stringtoshow .=
'y: { display: false }';
1502 $this->stringtoshow .=
'}, ';
1506 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1507 $this->stringtoshow .=
'tooltips: { mode: \'nearest\',
1509 if (is_array($this->tooltipsTitles)) {
1510 $this->stringtoshow .=
'
1511 title: function(tooltipItem, data) {
1512 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1513 return tooltipsTitle[tooltipItem[0].datasetIndex];
1516 if (is_array($this->tooltipsLabels)) {
1517 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1518 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1519 return tooltipslabels[tooltipItem.datasetIndex]
1522 $this->stringtoshow .=
'}},';
1524 $this->stringtoshow .=
'};';
1525 $this->stringtoshow .=
'
1526 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1527 var chart = new Chart(ctx, {
1528 // The type of chart we want to create
1529 type: \'' . $type .
'\',
1536 foreach ($legends as $val) { // Loop on each series
1538 $this->stringtoshow .= ',
';
1540 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
1544 //var_dump($arrayofgroupslegend);
1546 $this->stringtoshow .= '],
1549 global $theme_datacolor;
1550 '@phan-var-force array{0:array{0:int,1:int,2:
int},1:array{0:int,1:int,2:
int},2:array{0:int,1:int,2:
int},3:array{0:int,1:int,2:
int}}
$theme_datacolor';
1551 //var_dump($arrayofgroupslegend);
1556 while ($i < $nblot) { // Loop on each series
1557 $foundnegativecolor = 0;
1558 $usecolorvariantforgroupby = 0;
1559 // We used a 'group by
' and we have too many colors so we generated color variants per
1560 if (!empty($arrayofgroupslegend) && is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
1561 $nbofcolorneeds = count($arrayofgroupslegend);
1562 $nbofcolorsavailable = count($theme_datacolor);
1563 if ($nbofcolorneeds > $nbofcolorsavailable) {
1564 $usecolorvariantforgroupby = 1;
1567 $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup
'];
1569 $textoflegend = !empty($this->Legend[$i]) ? $this->Legend[$i] : '';
1572 if ($usecolorvariantforgroupby) {
1573 $idx = $arrayofgroupslegend[$i]['stacknum
'];
1575 $newcolor = $this->datacolor[$idx];
1576 // If we change the stack
1577 if ($oldstacknum == -1 || $idx != $oldstacknum) {
1581 //var_dump($iinstack);
1583 // Change color with offset of $iinstack
1584 //var_dump($newcolor);
1585 if ($iinstack % 2) { // We increase aggressiveness of reference color for color 2, 4, 6, ...
1586 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
1587 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
1588 } else { // We decrease aggressiveness of reference color for color 3, 5, 7, ..
1589 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
1590 $brightnessratio = min(90, 10 * $iinstack); // step of 20
1592 //var_dump('Color
'.($iinstack+1).' :
'.$ratio.' '.$brightnessratio);
1594 $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true));
1596 $oldstacknum = $arrayofgroupslegend[$i]['stacknum
'];
1598 $color = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ', 0.9)
';
1599 $bordercolor = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ')
';
1600 } else { // We do not use a 'group by
'
1601 if (!empty($this->datacolor[$i])) {
1602 if (is_array($this->datacolor[$i])) {
1603 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ', 0.9)
';
1605 $color = $this->datacolor[$i];
1608 // else: $color will be undefined
1609 if (!empty($this->bordercolor[$i]) && is_array($this->bordercolor[$i])) {
1610 $bordercolor = 'rgb(
' . $this->bordercolor[$i][0] . ',
' . $this->bordercolor[$i][1] . ',
' . $this->bordercolor[$i][2] . ', 0.9)
';
1612 if ($type != 'horizontalBar
') {
1613 $bordercolor = $color;
1615 $bordercolor = $this->bordercolor[$i];
1619 // For negative colors, we invert border and background
1620 $tmp = str_replace('#
', '', $color);
1621 if (strpos($tmp, '-
') !== false) {
1622 $foundnegativecolor++;
1623 $bordercolor = str_replace('-
', '', $color);
1624 $color = '#FFFFFF
'; // If $val is '-123
'
1628 $this->stringtoshow .= ',
';
1630 $this->stringtoshow .= "\n";
1631 $this->stringtoshow .= '{
';
1632 $this->stringtoshow .= 'dolibarrinfo: \
'y_' . $i .
'\',
';
1634 $this->stringtoshow .= 'pointStyle: \
'' . ((!empty($this->
type[$i]) && $this->
type[$i] ==
'linesnopoint') ?
'line' :
'circle') .
'\',
';
1635 $this->stringtoshow .= 'fill:
' . ($type == 'bar
' ? 'true' : 'false') . ',
';
1636 if ($type == 'bar
' || $type == 'horizontalBar
') {
1637 $this->stringtoshow .= 'borderWidth: \
''.$this->borderwidth.
'\',
';
1639 $this->stringtoshow .= 'borderColor: \
'' . $bordercolor .
'\',
';
1640 $this->stringtoshow .= 'borderSkipped: \
'' . $this->borderskip .
'\',
';
1641 $this->stringtoshow .= 'backgroundColor: \
'' . $color .
'\',
';
1642 if (!empty($arrayofgroupslegend) && !empty($arrayofgroupslegend[$i])) {
1643 $this->stringtoshow .= 'stack: \
'' . $arrayofgroupslegend[$i][
'stacknum'] .
'\',
';
1645 $this->stringtoshow .= 'data: [
';
1647 $this->stringtoshow .= $this->mirrorGraphValues ? '[-
' . $series[$i] . ',
' . $series[$i] . ']
' : $series[$i];
1648 $this->stringtoshow .= ']
';
1649 $this->stringtoshow .= '}
' . "\n";
1654 $this->stringtoshow .= ']
' . "\n";
1655 $this->stringtoshow .= '}
' . "\n";
1656 $this->stringtoshow .= '});
' . "\n";
1659 $this->stringtoshow .= '</script>
' . "\n";