207 global $theme_bordercolor, $theme_datacolor, $theme_bgcolor;
210 $this->bordercolor = array(235, 235, 224);
211 $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
212 $this->bgcolor = array(235, 235, 224);
215 if (!empty($conf->dol_optimize_smallscreen)) {
220 $color_file = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/theme_vars.inc.php';
221 if (is_readable($color_file)) {
223 if (isset($theme_bordercolor)) {
224 $this->bordercolor = $theme_bordercolor;
226 if (isset($theme_datacolor)) {
227 $this->datacolor = $theme_datacolor;
229 if (isset($theme_bgcolor)) {
230 $this->bgcolor = $theme_bgcolor;
235 $this->_library = $library;
236 if ($this->_library ==
'auto') {
237 $this->_library = (!
getDolGlobalString(
'MAIN_JS_GRAPH') ?
'chart' : $conf->global->MAIN_JS_GRAPH);
881 dol_syslog(get_class($this) .
"::draw_jflot this->type=" . implode(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
883 if (empty($this->width) && empty($this->height)) {
884 print
'Error width or height not set';
890 if (is_array($this->data) && is_array($this->data[0])) {
891 $nblot = count($this->data[0]) - 1;
894 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
902 while ($i < $nblot) {
904 $series[$i] =
"var d" . $i .
" = [];\n";
908 foreach ($this->data as $valarray) {
909 $legends[$x] = $valarray[0];
910 $values[$x] = (is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] :
null);
914 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
915 foreach ($values as $x => $y) {
917 $series[$i] .=
'd' . $i .
'.push({"label":"' .
dol_escape_js($legends[$x]) .
'", "data":' . $y .
'});' .
"\n";
921 foreach ($values as $x => $y) {
923 $series[$i] .=
'd' . $i .
'.push([' . $x .
', ' . $y .
']);' .
"\n";
933 $this->stringtoshow =
'<!-- Build using jflot -->' .
"\n";
934 if (!empty($this->title)) {
935 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
937 if (!empty($this->shownographyet)) {
938 $this->stringtoshow .=
'<div style="width:' . $this->width .
'px;height:' . $this->height .
'px;" class="nographyet"></div>';
939 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
944 $dolxaxisvertical =
'';
945 if (count($this->data) > 20) {
946 $dolxaxisvertical =
'dol-xaxis-vertical';
948 $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";
950 $this->stringtoshow .=
'<script nonce="'.getNonce().
'" id="' . $tag .
'">' .
"\n";
951 $this->stringtoshow .=
'$(function () {' .
"\n";
954 $this->stringtoshow .=
'<!-- No series of data -->' .
"\n";
956 while ($i < $nblot) {
957 $this->stringtoshow .=
'<!-- Series ' . $i .
' -->' .
"\n";
958 $this->stringtoshow .= $series[$i] .
"\n";
962 $this->stringtoshow .=
"\n";
965 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
966 $datacolor = array();
967 foreach ($this->datacolor as $val) {
968 if (is_array($val)) {
969 $datacolor[] =
"#" . sprintf(
"%02x%02x%02x", $val[0], $val[1], $val[2]);
971 $datacolor[] =
"#" . str_replace(array(
'#',
'-'),
'', $val);
976 $showlegend = $this->showlegend;
977 $showpointvalue = $this->showpointvalue;
978 $showpercent = $this->showpercent;
980 $this->stringtoshow .=
'
981 function plotWithOptions_' . $tag .
'() {
982 $.plot($("#placeholder_' . $tag .
'"), d0,
988 ' . ($this->combine ?
'
990 threshold: ' . $this->combine .
'
995 formatter: function(label, series) {
996 var percent=Math.round(series.percent);
997 var number=series.data[0][1];
999 $this->stringtoshow .=
'<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
1001 $this->stringtoshow .=
'<a style="color: #FFFFFF;" border="0" href="' . $urltemp .
'">';
1003 $this->stringtoshow .=
'\'+
';
1004 $this->stringtoshow .= ($showlegend ? '' : 'label+\
' \'+');
1005 $this->stringtoshow .= ($showpointvalue ?
'number+' :
'');
1006 $this->stringtoshow .= ($showpercent ?
'\'<br>\
'+percent+\'%\'+' :
'');
1007 $this->stringtoshow .=
'\'';
1009 $this->stringtoshow .=
'</a>';
1011 $this->stringtoshow .=
'</span>\';
1026 if (count($datacolor)) {
1027 $this->stringtoshow .=
'colors: ' . json_encode($datacolor) .
',';
1029 $this->stringtoshow .=
'legend: {show: ' . ($showlegend ?
'true' :
'false') .
', position: \'ne\' }
1036 $this->stringtoshow .=
'
1037 function showTooltip_' . $tag .
'(x, y, contents) {
1038 $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag .
'">\' + contents + \'</div>\').css({
1039 position: \'absolute\',
1043 border: \'1px solid #000\',
1045 \'background-color\': \'#000\',
1046 \'color\': \'#fff\',
1047 \'font-weight\': \'bold\',
1050 }).appendTo("body").fadeIn(100);
1053 var previousPoint = null;
1054 $("#placeholder_' . $tag .
'").bind("plothover", function (event, pos, item) {
1055 $("#x").text(pos.x.toFixed(2));
1056 $("#y").text(pos.y.toFixed(2));
1059 if (previousPoint != item.dataIndex) {
1060 previousPoint = item.dataIndex;
1062 $("#tooltip").remove();
1063 /* console.log(item); */
1064 var x = item.datapoint[0].toFixed(2);
1065 var y = item.datapoint[1].toFixed(2);
1066 var z = item.series.xaxis.ticks[item.dataIndex].label;
1068 if ($this->showpointvalue > 0) {
1069 $this->stringtoshow .=
'
1070 showTooltip_' . $tag .
'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
1073 $this->stringtoshow .=
'
1077 $("#tooltip_' . $tag .
'").remove();
1078 previousPoint = null;
1083 $this->stringtoshow .=
'var stack = null, steps = false;' .
"\n";
1085 $this->stringtoshow .=
'function plotWithOptions_' . $tag .
'() {' .
"\n";
1086 $this->stringtoshow .=
'$.plot($("#placeholder_' . $tag .
'"), [ ' .
"\n";
1088 while ($i < $nblot) {
1089 if ($i > $firstlot) {
1090 $this->stringtoshow .=
', ' .
"\n";
1092 $color = sprintf(
"%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
1093 $this->stringtoshow .=
'{ ';
1094 if (!isset($this->
type[$i]) || $this->
type[$i] ==
'bars') {
1096 if ($i == $firstlot) {
1098 } elseif ($i == $firstlot + 1) {
1103 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . $align .
'", barWidth: 0.45 }, ';
1105 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ?
'center' :
'left') .
'", barWidth: 0.5 }, ';
1108 if (isset($this->
type[$i]) && ($this->
type[$i] ==
'lines' || $this->
type[$i] ==
'linesnopoint')) {
1109 $this->stringtoshow .=
'lines: { show: true, fill: false }, points: { show: ' . ($this->
type[$i] ==
'linesnopoint' ?
'false' :
'true') .
' }, ';
1111 $this->stringtoshow .=
'color: "#' . $color .
'", label: "' . (isset($this->Legend[$i]) ?
dol_escape_js($this->Legend[$i]) :
'') .
'", data: d' . $i .
' }';
1115 $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";
1118 $this->stringtoshow .=
', xaxis: { ticks: [' .
"\n";
1120 foreach ($this->data as $key => $valarray) {
1122 $this->stringtoshow .=
', ' .
"\n";
1124 $this->stringtoshow .=
' [' . $x .
', "' . $valarray[0] .
'"]';
1127 $this->stringtoshow .=
'] }' .
"\n";
1130 $this->stringtoshow .=
', yaxis: { min: ' . $this->MinValue .
', max: ' . ($this->MaxValue) .
' }' .
"\n";
1133 $color1 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
1134 $color2 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
1135 $this->stringtoshow .=
', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 .
'", "#' . $color2 .
'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' .
"\n";
1136 $this->stringtoshow .=
'});' .
"\n";
1137 $this->stringtoshow .=
'}' .
"\n";
1140 $this->stringtoshow .=
'plotWithOptions_' . $tag .
'();' .
"\n";
1141 $this->stringtoshow .=
'});' .
"\n";
1142 $this->stringtoshow .=
'</script>' .
"\n";
1168 dol_syslog(get_class($this) .
"::draw_chart this->type=" . implode(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
1170 if (empty($this->width) && empty($this->height)) {
1171 print
'Error width or height not set';
1175 $showlegend = $this->showlegend;
1180 if (is_array($this->data)) {
1181 foreach ($this->data as $valarray) {
1182 $nblot = max($nblot, count($valarray) - 1);
1187 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
1194 '@phan-var-force array<int,array{stacknum:int,legend:string,legendwithgroup:string}> $arrayofgroupslegend';
1195 $arrayofgroupslegend = array();
1199 while ($i < $nblot) {
1205 foreach ($this->data as $valarray) {
1206 $legends[$x] = (array_key_exists(
'label', $valarray) ? $valarray[
'label'] : $valarray[0]);
1207 $array_of_ykeys = array_keys($valarray);
1209 $tmpykey = explode(
'_', (
string) ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
1210 if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] ==
'0')) {
1211 $tmpvalue = (array_key_exists(
'y_' . $tmpykey[1] .
'_' . $tmpykey[2], $valarray) ? $valarray[
'y_' . $tmpykey[1] .
'_' . $tmpykey[2]] : $valarray[$i + 1]);
1212 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1213 $arrayofgroupslegend[$i] = array(
1214 'stacknum' => (
int) $tmpykey[1],
1215 'legend' => $this->Legend[$tmpykey[1]],
1216 'legendwithgroup' => $this->Legend[$tmpykey[1]] .
' - ' . $tmpykey[2]
1219 $tmpvalue = (array_key_exists(
'y_' . $i, $valarray) ? $valarray[
'y_' . $i] : $valarray[$i + 1]);
1221 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1227 foreach ($values as $x => $y) {
1229 $series[$i] .= ($j > 0 ?
", " :
"") . $y;
1231 $series[$i] .= ($j > 0 ?
", " :
"") .
'null';
1244 $this->stringtoshow =
'<!-- Build using chart -->' .
"\n";
1245 if (!empty($this->title)) {
1246 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
1248 if (!empty($this->shownographyet)) {
1249 $this->stringtoshow .=
'<div style="width:' . $this->width . (strpos($this->width,
'%') > 0 ?
'' :
'px') .
'; height:' . $this->height .
'px;" class="nographyet"></div>';
1250 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
1255 $dolxaxisvertical =
'';
1256 if (count($this->data) > 20) {
1257 $dolxaxisvertical =
'dol-xaxis-vertical';
1260 $cssfordiv =
'dolgraphchart';
1261 if (isset($this->
type[$firstlot])) {
1262 $cssfordiv .=
' dolgraphchar' . $this->
type[$firstlot];
1264 $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";
1265 $this->stringtoshow .=
'<canvas id="canvas_'.$tag.
'"></canvas></div>'.
"\n";
1267 $this->stringtoshow .=
'<script nonce="'.getNonce().
'" id="' . $tag .
'">' .
"\n";
1270 $this->stringtoshow .=
'<!-- No series of data -->';
1272 while ($i < $nblot) {
1278 $this->stringtoshow .=
"\n";
1281 if (isset($this->
type[$firstlot]) && (in_array($this->
type[$firstlot], array(
'pie',
'polar',
'piesemicircle')))) {
1282 $type = $this->
type[$firstlot];
1284 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1287 $legendMaxLines = 0;
1290 if (empty($showlegend)) {
1291 $this->stringtoshow .=
'legend: { display: false }, ';
1293 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1294 if (!empty($legendMaxLines)) {
1295 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1297 $this->stringtoshow .=
' }, ' .
"\n";
1301 $this->stringtoshow .=
'plugins: { ';
1302 if (empty($showlegend)) {
1303 $this->stringtoshow .=
'legend: { display: false }, ';
1305 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1306 if (!empty($legendMaxLines)) {
1307 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1309 $this->stringtoshow .=
' }, ' .
"\n";
1311 $this->stringtoshow .=
' }, ' .
"\n";
1314 if ($this->
type[$firstlot] ==
'piesemicircle') {
1315 $this->stringtoshow .=
'circumference: Math.PI,' .
"\n";
1316 $this->stringtoshow .=
'rotation: -Math.PI,' .
"\n";
1318 $this->stringtoshow .=
'elements: { arc: {' .
"\n";
1320 $this->stringtoshow .=
'backgroundColor: [';
1322 $foundnegativecolor = 0;
1323 foreach ($legends as $val) {
1325 $this->stringtoshow .=
', ' .
"\n";
1327 if (is_array($this->datacolor[$i])) {
1328 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1330 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1331 if (strpos($tmp,
'-') !==
false) {
1332 $foundnegativecolor++;
1333 $color =
'rgba(0,0,0,.0)';
1335 $color =
"#" . $tmp;
1338 $this->stringtoshow .=
"'" . $color .
"'";
1341 $this->stringtoshow .=
'], ' .
"\n";
1343 if ($foundnegativecolor) {
1344 $this->stringtoshow .=
'borderColor: [';
1346 foreach ($legends as $val) {
1348 $this->stringtoshow .=
', ' .
"\n";
1350 if ($this->datacolor !==
null) {
1351 $datacolor_item = $this->datacolor[$i];
1353 $datacolor_item =
null;
1356 if (is_array($datacolor_item) || $datacolor_item ===
null) {
1359 $tmpcolor = str_replace(
'#',
'', $datacolor_item);
1360 if (strpos($tmpcolor,
'-') !==
false) {
1361 $color =
'#' . str_replace(
'-',
'', $tmpcolor);
1366 $this->stringtoshow .= ($color ==
'null' ?
"'rgba(0,0,0,0.2)'" :
"'" . $color .
"'");
1369 $this->stringtoshow .=
']';
1371 $this->stringtoshow .=
'} } };' .
"\n";
1373 $this->stringtoshow .=
'
1374 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1375 var chart = new Chart(ctx, {
1376 // The type of chart we want to create
1377 type: \'' . (in_array($type, array(
'pie',
'piesemicircle')) ?
'doughnut' :
'polarArea') .
'\',
1384 foreach ($legends as $val) { // Loop on each series
1386 $this->stringtoshow .= ',
';
1388 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 25)) . "'"; // Lower than 25 make some important label (that we can't shorten) to be truncated
1392 $this->stringtoshow .=
'],
1395 while ($i < $nblot) {
1396 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1399 $this->stringtoshow .=
', ' .
"\n";
1401 $this->stringtoshow .=
'{' .
"\n";
1404 $this->stringtoshow .=
' data: [' . $series[$i] .
']';
1405 $this->stringtoshow .=
'}' .
"\n";
1408 $this->stringtoshow .=
']' .
"\n";
1409 $this->stringtoshow .=
'}' .
"\n";
1410 $this->stringtoshow .=
'});' .
"\n";
1416 if (isset($this->
type[$firstlot]) && $this->
type[$firstlot] ==
'horizontalbars') {
1417 $xaxis =
"indexAxis: 'y', ";
1419 if (isset($this->
type[$firstlot]) && ($this->
type[$firstlot] ==
'lines' || $this->
type[$firstlot] ==
'linesnopoint')) {
1424 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1425 $this->stringtoshow .= $xaxis;
1426 if ($this->showpointvalue == 2) {
1427 $this->stringtoshow .=
'interaction: { intersect: true, mode: \'index\'}, ';
1440 $this->stringtoshow .=
'plugins: { '.
"\n";
1441 if (empty($showlegend)) {
1442 $this->stringtoshow .=
'legend: { display: false }, '.
"\n";
1444 $this->stringtoshow .=
'legend: { maxWidth: '.round(intval($this->width) / 2).
', labels: { boxWidth: 15 }, position: \'' . (($showlegend && $showlegend == 2) ?
'right' :
'top') .
'\' },
'."\n";
1446 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1447 $this->stringtoshow .= 'tooltip: { mode: \
'nearest\',
1449 if (is_array($this->tooltipsTitles)) {
1450 $this->stringtoshow .=
'
1451 title: function(tooltipItem, data) {
1452 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1453 return tooltipsTitle[tooltipItem[0].datasetIndex];
1456 if (is_array($this->tooltipsLabels)) {
1457 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1458 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1459 return tooltipslabels[tooltipItem.datasetIndex]
1462 $this->stringtoshow .=
'}},';
1464 $this->stringtoshow .=
"}, \n";
1486 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1487 $this->stringtoshow .=
'tooltips: { mode: \'nearest\',
1489 if (is_array($this->tooltipsTitles)) {
1490 $this->stringtoshow .=
'
1491 title: function(tooltipItem, data) {
1492 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1493 return tooltipsTitle[tooltipItem[0].datasetIndex];
1496 if (is_array($this->tooltipsLabels)) {
1497 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1498 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1499 return tooltipslabels[tooltipItem.datasetIndex]
1502 $this->stringtoshow .=
'}},';
1504 $this->stringtoshow .=
'};';
1505 $this->stringtoshow .=
'
1506 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1507 var chart = new Chart(ctx, {
1508 // The type of chart we want to create
1509 type: \'' . $type .
'\',
1516 foreach ($legends as $val) { // Loop on each series
1518 $this->stringtoshow .= ',
';
1520 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
1524 //var_dump($arrayofgroupslegend);
1526 $this->stringtoshow .= '],
1529 global $theme_datacolor;
1530 '@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
';
1531 //var_dump($arrayofgroupslegend);
1536 while ($i < $nblot) { // Loop on each series
1537 $foundnegativecolor = 0;
1538 $usecolorvariantforgroupby = 0;
1539 // We used a 'group by
' and we have too many colors so we generated color variants per
1540 if (!empty($arrayofgroupslegend) && is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
1541 $nbofcolorneeds = count($arrayofgroupslegend);
1542 $nbofcolorsavailable = count($theme_datacolor);
1543 if ($nbofcolorneeds > $nbofcolorsavailable) {
1544 $usecolorvariantforgroupby = 1;
1547 $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup
'];
1549 $textoflegend = !empty($this->Legend[$i]) ? $this->Legend[$i] : '';
1552 if ($usecolorvariantforgroupby) {
1553 $idx = $arrayofgroupslegend[$i]['stacknum
'];
1555 $newcolor = $this->datacolor[$idx];
1556 // If we change the stack
1557 if ($oldstacknum == -1 || $idx != $oldstacknum) {
1561 //var_dump($iinstack);
1563 // Change color with offset of $iinstack
1564 //var_dump($newcolor);
1565 if ($iinstack % 2) { // We increase aggressiveness of reference color for color 2, 4, 6, ...
1566 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
1567 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
1568 } else { // We decrease aggressiveness of reference color for color 3, 5, 7, ..
1569 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
1570 $brightnessratio = min(90, 10 * $iinstack); // step of 20
1572 //var_dump('Color
'.($iinstack+1).' :
'.$ratio.' '.$brightnessratio);
1574 $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true));
1576 $oldstacknum = $arrayofgroupslegend[$i]['stacknum
'];
1578 $color = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ', 0.9)
';
1579 $bordercolor = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ')
';
1580 } else { // We do not use a 'group by
'
1581 if (!empty($this->datacolor[$i])) {
1582 if (is_array($this->datacolor[$i])) {
1583 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ', 0.9)
';
1585 $color = $this->datacolor[$i];
1588 // else: $color will be undefined
1589 if (!empty($this->bordercolor[$i]) && is_array($this->bordercolor[$i])) {
1590 $bordercolor = 'rgb(
' . $this->bordercolor[$i][0] . ',
' . $this->bordercolor[$i][1] . ',
' . $this->bordercolor[$i][2] . ', 0.9)
';
1592 if ($type != 'horizontalBar
') {
1593 $bordercolor = $color;
1595 $bordercolor = $this->bordercolor[$i];
1599 // For negative colors, we invert border and background
1600 $tmp = str_replace('#
', '', $color);
1601 if (strpos($tmp, '-
') !== false) {
1602 $foundnegativecolor++;
1603 $bordercolor = str_replace('-
', '', $color);
1604 $color = '#FFFFFF
'; // If $val is '-123
'
1608 $this->stringtoshow .= ',
';
1610 $this->stringtoshow .= "\n";
1611 $this->stringtoshow .= '{
';
1612 $this->stringtoshow .= 'dolibarrinfo: \
'y_' . $i .
'\',
';
1614 $this->stringtoshow .= 'pointStyle: \
'' . ((!empty($this->
type[$i]) && $this->
type[$i] ==
'linesnopoint') ?
'line' :
'circle') .
'\',
';
1615 $this->stringtoshow .= 'fill:
' . ($type == 'bar
' ? 'true' : 'false') . ',
';
1616 if ($type == 'bar
' || $type == 'horizontalBar
') {
1617 $this->stringtoshow .= 'borderWidth: \
''.$this->borderwidth.
'\',
';
1619 $this->stringtoshow .= 'borderColor: \
'' . $bordercolor .
'\',
';
1620 $this->stringtoshow .= 'borderSkipped: \
'' . $this->borderskip .
'\',
';
1621 $this->stringtoshow .= 'backgroundColor: \
'' . $color .
'\',
';
1622 if (!empty($arrayofgroupslegend) && !empty($arrayofgroupslegend[$i])) {
1623 $this->stringtoshow .= 'stack: \
'' . $arrayofgroupslegend[$i][
'stacknum'] .
'\',
';
1625 $this->stringtoshow .= 'data: [
';
1627 $this->stringtoshow .= $this->mirrorGraphValues ? '[-
' . $series[$i] . ',
' . $series[$i] . ']
' : $series[$i];
1628 $this->stringtoshow .= ']
';
1629 $this->stringtoshow .= '}
' . "\n";
1634 $this->stringtoshow .= ']
' . "\n";
1635 $this->stringtoshow .= '}
' . "\n";
1636 $this->stringtoshow .= '});
' . "\n";
1639 $this->stringtoshow .= '</script>
' . "\n";