| Conditions | 103 |
| Paths | > 20000 |
| Total Lines | 467 |
| Code Lines | 273 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 1071 | private function draw_chart($file, $fileurl) // @phpstan-ignore-line |
||
| 1072 | { |
||
| 1073 | // phpcs:enable |
||
| 1074 | global $langs; |
||
| 1075 | |||
| 1076 | dol_syslog(get_class($this) . "::draw_chart this->type=" . implode(',', $this->type) . " this->MaxValue=" . $this->MaxValue); |
||
| 1077 | |||
| 1078 | if (empty($this->width) && empty($this->height)) { |
||
| 1079 | print 'Error width or height not set'; |
||
| 1080 | return; |
||
| 1081 | } |
||
| 1082 | |||
| 1083 | $showlegend = $this->showlegend; |
||
| 1084 | $bordercolor = ""; |
||
| 1085 | |||
| 1086 | $legends = array(); |
||
| 1087 | $nblot = 0; |
||
| 1088 | if (is_array($this->data)) { |
||
| 1089 | foreach ($this->data as $valarray) { // Loop on each x |
||
| 1090 | $nblot = max($nblot, count($valarray) - 1); // -1 to remove legend |
||
| 1091 | } |
||
| 1092 | } |
||
| 1093 | //var_dump($nblot); |
||
| 1094 | if ($nblot < 0) { |
||
| 1095 | dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING); |
||
| 1096 | } |
||
| 1097 | $firstlot = 0; |
||
| 1098 | // Works with line but not with bars |
||
| 1099 | //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x |
||
| 1100 | |||
| 1101 | $series = array(); |
||
| 1102 | $arrayofgroupslegend = array(); |
||
| 1103 | //var_dump($this->data); |
||
| 1104 | |||
| 1105 | $i = $firstlot; |
||
| 1106 | while ($i < $nblot) { // Loop on each series |
||
| 1107 | $values = array(); // Array with horizontal y values (specific values of a series) for each abscisse x (with x=0,1,2,...) |
||
| 1108 | $series[$i] = ""; |
||
| 1109 | |||
| 1110 | // Fill array $series from $this->data |
||
| 1111 | $x = 0; |
||
| 1112 | foreach ($this->data as $valarray) { // Loop on each x |
||
| 1113 | $legends[$x] = (array_key_exists('label', $valarray) ? $valarray['label'] : $valarray[0]); |
||
| 1114 | $array_of_ykeys = array_keys($valarray); |
||
| 1115 | $alabelexists = 1; |
||
| 1116 | $tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3); |
||
| 1117 | if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] == '0')) { // This is a 'Group by' array |
||
| 1118 | $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]); |
||
| 1119 | $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); |
||
| 1120 | $arrayofgroupslegend[$i] = array( |
||
| 1121 | 'stacknum' => $tmpykey[1], |
||
| 1122 | 'legend' => $this->Legend[$tmpykey[1]], |
||
| 1123 | 'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2] |
||
| 1124 | ); |
||
| 1125 | } else { |
||
| 1126 | $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : $valarray[$i + 1]); |
||
| 1127 | //var_dump($i.'_'.$x.'_'.$tmpvalue); |
||
| 1128 | $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); |
||
| 1129 | } |
||
| 1130 | $x++; |
||
| 1131 | } |
||
| 1132 | //var_dump($values); |
||
| 1133 | $j = 0; |
||
| 1134 | foreach ($values as $x => $y) { |
||
| 1135 | if (isset($y)) { |
||
| 1136 | $series[$i] .= ($j > 0 ? ", " : "") . $y; |
||
| 1137 | } else { |
||
| 1138 | $series[$i] .= ($j > 0 ? ", " : "") . 'null'; |
||
| 1139 | } |
||
| 1140 | $j++; |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | $values = null; // Free mem |
||
| 1144 | $i++; |
||
| 1145 | } |
||
| 1146 | //var_dump($series); |
||
| 1147 | //var_dump($arrayofgroupslegend); |
||
| 1148 | |||
| 1149 | $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); |
||
| 1150 | |||
| 1151 | $this->stringtoshow = '<!-- Build using chart -->' . "\n"; |
||
| 1152 | if (!empty($this->title)) { |
||
| 1153 | $this->stringtoshow .= '<div class="center dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>'; |
||
| 1154 | } |
||
| 1155 | if (!empty($this->shownographyet)) { |
||
| 1156 | $this->stringtoshow .= '<div style="width:' . $this->width . (strpos($this->width, '%') > 0 ? '' : 'px') . '; height:' . $this->height . 'px;" class="nographyet"></div>'; |
||
| 1157 | $this->stringtoshow .= '<div class="nographyettext margintoponly">' . $langs->trans("NotEnoughDataYet") . '...</div>'; |
||
| 1158 | return; |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | // Start the div that will contains all the graph |
||
| 1162 | $dolxaxisvertical = ''; |
||
| 1163 | if (count($this->data) > 20) { |
||
| 1164 | $dolxaxisvertical = 'dol-xaxis-vertical'; |
||
| 1165 | } |
||
| 1166 | // No height for the pie graph |
||
| 1167 | $cssfordiv = 'dolgraphchart'; |
||
| 1168 | if (isset($this->type[$firstlot])) { |
||
| 1169 | $cssfordiv .= ' dolgraphchar' . $this->type[$firstlot]; |
||
| 1170 | } |
||
| 1171 | $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"; |
||
| 1172 | $this->stringtoshow .= '<canvas id="canvas_' . $tag . '"></canvas></div>' . "\n"; |
||
| 1173 | |||
| 1174 | $this->stringtoshow .= '<script nonce="' . getNonce() . '" id="' . $tag . '">' . "\n"; |
||
| 1175 | $i = $firstlot; |
||
| 1176 | if ($nblot < 0) { |
||
| 1177 | $this->stringtoshow .= '<!-- No series of data -->'; |
||
| 1178 | } else { |
||
| 1179 | while ($i < $nblot) { |
||
| 1180 | //$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n"; |
||
| 1181 | //$this->stringtoshow .= $series[$i]."\n"; |
||
| 1182 | $i++; |
||
| 1183 | } |
||
| 1184 | } |
||
| 1185 | $this->stringtoshow .= "\n"; |
||
| 1186 | |||
| 1187 | // Special case for Graph of type 'pie', 'piesemicircle', or 'polar' |
||
| 1188 | if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle')))) { |
||
| 1189 | $type = $this->type[$firstlot]; // pie or polar |
||
| 1190 | //$this->stringtoshow .= 'var options = {' . "\n"; |
||
| 1191 | $this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, '; |
||
| 1192 | |||
| 1193 | |||
| 1194 | $legendMaxLines = 0; // Does not work |
||
| 1195 | |||
| 1196 | /* For Chartjs v2.9 */ |
||
| 1197 | if (empty($showlegend)) { |
||
| 1198 | $this->stringtoshow .= 'legend: { display: false }, '; |
||
| 1199 | } else { |
||
| 1200 | $this->stringtoshow .= 'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\''; |
||
| 1201 | if (!empty($legendMaxLines)) { |
||
| 1202 | $this->stringtoshow .= ', maxLines: ' . $legendMaxLines; |
||
| 1203 | } |
||
| 1204 | $this->stringtoshow .= ' }, ' . "\n"; |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | /* For Chartjs v3.5 */ |
||
| 1208 | $this->stringtoshow .= 'plugins: { '; |
||
| 1209 | if (empty($showlegend)) { |
||
| 1210 | $this->stringtoshow .= 'legend: { display: false }, '; |
||
| 1211 | } else { |
||
| 1212 | $this->stringtoshow .= 'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\''; |
||
| 1213 | if (!empty($legendMaxLines)) { |
||
| 1214 | $this->stringtoshow .= ', maxLines: ' . $legendMaxLines; |
||
| 1215 | } |
||
| 1216 | $this->stringtoshow .= ' }, ' . "\n"; |
||
| 1217 | } |
||
| 1218 | $this->stringtoshow .= ' }, ' . "\n"; |
||
| 1219 | |||
| 1220 | |||
| 1221 | if ($this->type[$firstlot] == 'piesemicircle') { |
||
| 1222 | $this->stringtoshow .= 'circumference: Math.PI,' . "\n"; |
||
| 1223 | $this->stringtoshow .= 'rotation: -Math.PI,' . "\n"; |
||
| 1224 | } |
||
| 1225 | $this->stringtoshow .= 'elements: { arc: {' . "\n"; |
||
| 1226 | // Color of each arc |
||
| 1227 | $this->stringtoshow .= 'backgroundColor: ['; |
||
| 1228 | $i = 0; |
||
| 1229 | $foundnegativecolor = 0; |
||
| 1230 | foreach ($legends as $val) { // Loop on each series |
||
| 1231 | if ($i > 0) { |
||
| 1232 | $this->stringtoshow .= ', ' . "\n"; |
||
| 1233 | } |
||
| 1234 | if (is_array($this->datacolor[$i])) { |
||
| 1235 | $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')'; // If datacolor is array(R, G, B) |
||
| 1236 | } else { |
||
| 1237 | $tmp = str_replace('#', '', $this->datacolor[$i]); |
||
| 1238 | if (strpos($tmp, '-') !== false) { |
||
| 1239 | $foundnegativecolor++; |
||
| 1240 | $color = 'rgba(0,0,0,.0)'; // If $val is '-123' |
||
| 1241 | } else { |
||
| 1242 | $color = "#" . $tmp; // If $val is '123' or '#123' |
||
| 1243 | } |
||
| 1244 | } |
||
| 1245 | $this->stringtoshow .= "'" . $color . "'"; |
||
| 1246 | $i++; |
||
| 1247 | } |
||
| 1248 | $this->stringtoshow .= '], ' . "\n"; |
||
| 1249 | // Border color |
||
| 1250 | if ($foundnegativecolor) { |
||
| 1251 | $this->stringtoshow .= 'borderColor: ['; |
||
| 1252 | $i = 0; |
||
| 1253 | foreach ($legends as $val) { // Loop on each series |
||
| 1254 | if ($i > 0) { |
||
| 1255 | $this->stringtoshow .= ', ' . "\n"; |
||
| 1256 | } |
||
| 1257 | if (is_array($this->datacolor[$i])) { |
||
| 1258 | $color = 'null'; // If datacolor is array(R, G, B) |
||
| 1259 | } else { |
||
| 1260 | $tmp = str_replace('#', '', $this->datacolor[$i]); |
||
| 1261 | if (strpos($tmp, '-') !== false) { |
||
| 1262 | $color = '#' . str_replace('-', '', $tmp); // If $val is '-123' |
||
| 1263 | } else { |
||
| 1264 | $color = 'null'; // If $val is '123' or '#123' |
||
| 1265 | } |
||
| 1266 | } |
||
| 1267 | $this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $color . "'"); |
||
| 1268 | $i++; |
||
| 1269 | } |
||
| 1270 | $this->stringtoshow .= ']'; |
||
| 1271 | } |
||
| 1272 | $this->stringtoshow .= '} } };' . "\n"; |
||
| 1273 | |||
| 1274 | $this->stringtoshow .= ' |
||
| 1275 | var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d"); |
||
| 1276 | var chart = new Chart(ctx, { |
||
| 1277 | // The type of chart we want to create |
||
| 1278 | type: \'' . (in_array($type, array('pie', 'piesemicircle')) ? 'doughnut' : 'polarArea') . '\', |
||
| 1279 | // Configuration options go here |
||
| 1280 | options: options, |
||
| 1281 | data: { |
||
| 1282 | labels: ['; |
||
| 1283 | |||
| 1284 | $i = 0; |
||
| 1285 | foreach ($legends as $val) { // Loop on each series |
||
| 1286 | if ($i > 0) { |
||
| 1287 | $this->stringtoshow .= ', '; |
||
| 1288 | } |
||
| 1289 | $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 25)) . "'"; // Lower than 25 make some important label (that we can't shorten) to be truncated |
||
| 1290 | $i++; |
||
| 1291 | } |
||
| 1292 | |||
| 1293 | $this->stringtoshow .= '], |
||
| 1294 | datasets: ['; |
||
| 1295 | $i = 0; |
||
| 1296 | while ($i < $nblot) { // Loop on each series |
||
| 1297 | $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')'; |
||
| 1298 | |||
| 1299 | if ($i > 0) { |
||
| 1300 | $this->stringtoshow .= ', ' . "\n"; |
||
| 1301 | } |
||
| 1302 | $this->stringtoshow .= '{' . "\n"; |
||
| 1303 | //$this->stringtoshow .= 'borderColor: \''.$color.'\', '; |
||
| 1304 | //$this->stringtoshow .= 'backgroundColor: \''.$color.'\', '; |
||
| 1305 | $this->stringtoshow .= ' data: [' . $series[$i] . ']'; |
||
| 1306 | $this->stringtoshow .= '}' . "\n"; |
||
| 1307 | $i++; |
||
| 1308 | } |
||
| 1309 | $this->stringtoshow .= ']' . "\n"; |
||
| 1310 | $this->stringtoshow .= '}' . "\n"; |
||
| 1311 | $this->stringtoshow .= '});' . "\n"; |
||
| 1312 | } else { |
||
| 1313 | // Other cases, graph of type 'bars', 'lines', 'linesnopoint' |
||
| 1314 | $type = 'bar'; |
||
| 1315 | $xaxis = ''; |
||
| 1316 | |||
| 1317 | if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') { |
||
| 1318 | $xaxis = "indexAxis: 'y', "; |
||
| 1319 | } |
||
| 1320 | if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) { |
||
| 1321 | $type = 'line'; |
||
| 1322 | } |
||
| 1323 | |||
| 1324 | // Set options |
||
| 1325 | $this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, '; |
||
| 1326 | $this->stringtoshow .= $xaxis; |
||
| 1327 | if ($this->showpointvalue == 2) { |
||
| 1328 | $this->stringtoshow .= 'interaction: { intersect: true, mode: \'index\'}, '; |
||
| 1329 | } |
||
| 1330 | |||
| 1331 | /* For Chartjs v2.9 */ |
||
| 1332 | /* |
||
| 1333 | if (empty($showlegend)) { |
||
| 1334 | $this->stringtoshow .= 'legend: { display: false }, '."\n"; |
||
| 1335 | } else { |
||
| 1336 | $this->stringtoshow .= 'legend: { maxWidth: '.round($this->width / 2).', labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\' }, '."\n"; |
||
| 1337 | } |
||
| 1338 | */ |
||
| 1339 | |||
| 1340 | /* For Chartjs v3.5 */ |
||
| 1341 | $this->stringtoshow .= 'plugins: { ' . "\n"; |
||
| 1342 | if (empty($showlegend)) { |
||
| 1343 | $this->stringtoshow .= 'legend: { display: false }, ' . "\n"; |
||
| 1344 | } else { |
||
| 1345 | $this->stringtoshow .= 'legend: { maxWidth: ' . round(intval($this->width) / 2) . ', labels: { boxWidth: 15 }, position: \'' . (($showlegend && $showlegend == 2) ? 'right' : 'top') . '\' },' . "\n"; |
||
| 1346 | } |
||
| 1347 | if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) { |
||
| 1348 | $this->stringtoshow .= 'tooltip: { mode: \'nearest\', |
||
| 1349 | callbacks: {'; |
||
| 1350 | if (is_array($this->tooltipsTitles)) { |
||
| 1351 | $this->stringtoshow .= ' |
||
| 1352 | title: function(tooltipItem, data) { |
||
| 1353 | var tooltipsTitle =' . json_encode($this->tooltipsTitles) . ' |
||
| 1354 | return tooltipsTitle[tooltipItem[0].datasetIndex]; |
||
| 1355 | },'; |
||
| 1356 | } |
||
| 1357 | if (is_array($this->tooltipsLabels)) { |
||
| 1358 | $this->stringtoshow .= 'label: function(tooltipItem, data) { |
||
| 1359 | var tooltipslabels =' . json_encode($this->tooltipsLabels) . ' |
||
| 1360 | return tooltipslabels[tooltipItem.datasetIndex] |
||
| 1361 | }'; |
||
| 1362 | } |
||
| 1363 | $this->stringtoshow .= '}},'; |
||
| 1364 | } |
||
| 1365 | $this->stringtoshow .= "}, \n"; |
||
| 1366 | |||
| 1367 | /* For Chartjs v2.9 */ |
||
| 1368 | /* |
||
| 1369 | $this->stringtoshow .= 'scales: { xAxis: [{ '; |
||
| 1370 | if ($this->hideXValues) { |
||
| 1371 | $this->stringtoshow .= ' ticks: { display: false }, display: true,'; |
||
| 1372 | } |
||
| 1373 | //$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js |
||
| 1374 | $this->stringtoshow .= 'distribution: \'linear\''; |
||
| 1375 | if ($type == 'bar' && count($arrayofgroupslegend) > 0) { |
||
| 1376 | $this->stringtoshow .= ', stacked: true'; |
||
| 1377 | } |
||
| 1378 | $this->stringtoshow .= ' }]'; |
||
| 1379 | $this->stringtoshow .= ', yAxis: [{ ticks: { beginAtZero: true }'; |
||
| 1380 | if ($type == 'bar' && count($arrayofgroupslegend) > 0) { |
||
| 1381 | $this->stringtoshow .= ', stacked: true'; |
||
| 1382 | } |
||
| 1383 | $this->stringtoshow .= ' }] }'; |
||
| 1384 | */ |
||
| 1385 | |||
| 1386 | // Add a callback to change label to show only positive value |
||
| 1387 | if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) { |
||
| 1388 | $this->stringtoshow .= 'tooltips: { mode: \'nearest\', |
||
| 1389 | callbacks: {'; |
||
| 1390 | if (is_array($this->tooltipsTitles)) { |
||
| 1391 | $this->stringtoshow .= ' |
||
| 1392 | title: function(tooltipItem, data) { |
||
| 1393 | var tooltipsTitle =' . json_encode($this->tooltipsTitles) . ' |
||
| 1394 | return tooltipsTitle[tooltipItem[0].datasetIndex]; |
||
| 1395 | },'; |
||
| 1396 | } |
||
| 1397 | if (is_array($this->tooltipsLabels)) { |
||
| 1398 | $this->stringtoshow .= 'label: function(tooltipItem, data) { |
||
| 1399 | var tooltipslabels =' . json_encode($this->tooltipsLabels) . ' |
||
| 1400 | return tooltipslabels[tooltipItem.datasetIndex] |
||
| 1401 | }'; |
||
| 1402 | } |
||
| 1403 | $this->stringtoshow .= '}},'; |
||
| 1404 | } |
||
| 1405 | $this->stringtoshow .= '};'; |
||
| 1406 | $this->stringtoshow .= ' |
||
| 1407 | var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d"); |
||
| 1408 | var chart = new Chart(ctx, { |
||
| 1409 | // The type of chart we want to create |
||
| 1410 | type: \'' . $type . '\', |
||
| 1411 | // Configuration options go here |
||
| 1412 | options: options, |
||
| 1413 | data: { |
||
| 1414 | labels: ['; |
||
| 1415 | |||
| 1416 | $i = 0; |
||
| 1417 | foreach ($legends as $val) { // Loop on each series |
||
| 1418 | if ($i > 0) { |
||
| 1419 | $this->stringtoshow .= ', '; |
||
| 1420 | } |
||
| 1421 | $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'"; |
||
| 1422 | $i++; |
||
| 1423 | } |
||
| 1424 | |||
| 1425 | //var_dump($arrayofgroupslegend); |
||
| 1426 | |||
| 1427 | $this->stringtoshow .= '], |
||
| 1428 | datasets: ['; |
||
| 1429 | |||
| 1430 | global $theme_datacolor; |
||
| 1431 | '@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'; |
||
| 1432 | //var_dump($arrayofgroupslegend); |
||
| 1433 | $i = 0; |
||
| 1434 | $iinstack = 0; |
||
| 1435 | $oldstacknum = -1; |
||
| 1436 | while ($i < $nblot) { // Loop on each series |
||
| 1437 | $foundnegativecolor = 0; |
||
| 1438 | $usecolorvariantforgroupby = 0; |
||
| 1439 | // We used a 'group by' and we have too many colors so we generated color variants per |
||
| 1440 | if (!empty($arrayofgroupslegend) && is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by. |
||
| 1441 | $nbofcolorneeds = count($arrayofgroupslegend); |
||
| 1442 | $nbofcolorsavailable = count($theme_datacolor); |
||
| 1443 | if ($nbofcolorneeds > $nbofcolorsavailable) { |
||
| 1444 | $usecolorvariantforgroupby = 1; |
||
| 1445 | } |
||
| 1446 | |||
| 1447 | $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup']; |
||
| 1448 | } else { |
||
| 1449 | $textoflegend = !empty($this->Legend[$i]) ? $this->Legend[$i] : ''; |
||
| 1450 | } |
||
| 1451 | |||
| 1452 | if ($usecolorvariantforgroupby) { |
||
| 1453 | $newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum']]; |
||
| 1454 | // If we change the stack |
||
| 1455 | if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum'] != $oldstacknum) { |
||
| 1456 | $iinstack = 0; |
||
| 1457 | } |
||
| 1458 | |||
| 1459 | //var_dump($iinstack); |
||
| 1460 | if ($iinstack) { |
||
| 1461 | // Change color with offset of $iinstack |
||
| 1462 | //var_dump($newcolor); |
||
| 1463 | if ($iinstack % 2) { // We increase aggressiveness of reference color for color 2, 4, 6, ... |
||
| 1464 | $ratio = min(95, 10 + 10 * $iinstack); // step of 20 |
||
| 1465 | $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10 |
||
| 1466 | } else { // We decrease aggressiveness of reference color for color 3, 5, 7, .. |
||
| 1467 | $ratio = max(-100, -15 * $iinstack + 10); // step of -20 |
||
| 1468 | $brightnessratio = min(90, 10 * $iinstack); // step of 20 |
||
| 1469 | } |
||
| 1470 | //var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio); |
||
| 1471 | |||
| 1472 | $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true)); |
||
| 1473 | } |
||
| 1474 | $oldstacknum = $arrayofgroupslegend[$i]['stacknum']; |
||
| 1475 | |||
| 1476 | $color = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ', 0.9)'; |
||
| 1477 | $bordercolor = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ')'; |
||
| 1478 | } else { // We do not use a 'group by' |
||
| 1479 | if (!empty($this->datacolor[$i])) { |
||
| 1480 | if (is_array($this->datacolor[$i])) { |
||
| 1481 | $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ', 0.9)'; |
||
| 1482 | } else { |
||
| 1483 | $color = $this->datacolor[$i]; |
||
| 1484 | } |
||
| 1485 | } |
||
| 1486 | // else: $color will be undefined |
||
| 1487 | if (!empty($this->bordercolor[$i]) && is_array($this->bordercolor[$i])) { |
||
| 1488 | $bordercolor = 'rgb(' . $this->bordercolor[$i][0] . ', ' . $this->bordercolor[$i][1] . ', ' . $this->bordercolor[$i][2] . ', 0.9)'; |
||
| 1489 | } else { |
||
| 1490 | if ($type != 'horizontalBar') { |
||
| 1491 | $bordercolor = $color; |
||
| 1492 | } else { |
||
| 1493 | $bordercolor = $this->bordercolor[$i]; |
||
| 1494 | } |
||
| 1495 | } |
||
| 1496 | |||
| 1497 | // For negative colors, we invert border and background |
||
| 1498 | $tmp = str_replace('#', '', $color); |
||
| 1499 | if (strpos($tmp, '-') !== false) { |
||
| 1500 | $foundnegativecolor++; |
||
| 1501 | $bordercolor = str_replace('-', '', $color); |
||
| 1502 | $color = '#FFFFFF'; // If $val is '-123' |
||
| 1503 | } |
||
| 1504 | } |
||
| 1505 | if ($i > 0) { |
||
| 1506 | $this->stringtoshow .= ', '; |
||
| 1507 | } |
||
| 1508 | $this->stringtoshow .= "\n"; |
||
| 1509 | $this->stringtoshow .= '{'; |
||
| 1510 | $this->stringtoshow .= 'dolibarrinfo: \'y_' . $i . '\', '; |
||
| 1511 | $this->stringtoshow .= 'label: \'' . dol_escape_js(dol_string_nohtmltag($textoflegend)) . '\', '; |
||
| 1512 | $this->stringtoshow .= 'pointStyle: \'' . ((!empty($this->type[$i]) && $this->type[$i] == 'linesnopoint') ? 'line' : 'circle') . '\', '; |
||
| 1513 | $this->stringtoshow .= 'fill: ' . ($type == 'bar' ? 'true' : 'false') . ', '; |
||
| 1514 | if ($type == 'bar' || $type == 'horizontalBar') { |
||
| 1515 | $this->stringtoshow .= 'borderWidth: \'' . $this->borderwidth . '\', '; |
||
| 1516 | } |
||
| 1517 | $this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', '; |
||
| 1518 | $this->stringtoshow .= 'borderSkipped: \'' . $this->borderskip . '\', '; |
||
| 1519 | $this->stringtoshow .= 'backgroundColor: \'' . $color . '\', '; |
||
| 1520 | if (!empty($arrayofgroupslegend) && !empty($arrayofgroupslegend[$i])) { |
||
| 1521 | $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', '; |
||
| 1522 | } |
||
| 1523 | $this->stringtoshow .= 'data: ['; |
||
| 1524 | |||
| 1525 | $this->stringtoshow .= $this->mirrorGraphValues ? '[-' . $series[$i] . ',' . $series[$i] . ']' : $series[$i]; |
||
| 1526 | $this->stringtoshow .= ']'; |
||
| 1527 | $this->stringtoshow .= '}' . "\n"; |
||
| 1528 | |||
| 1529 | $i++; |
||
| 1530 | $iinstack++; |
||
| 1531 | } |
||
| 1532 | $this->stringtoshow .= ']' . "\n"; |
||
| 1533 | $this->stringtoshow .= '}' . "\n"; |
||
| 1534 | $this->stringtoshow .= '});' . "\n"; |
||
| 1535 | } |
||
| 1536 | |||
| 1537 | $this->stringtoshow .= '</script>' . "\n"; |
||
| 1538 | } |
||
| 1605 |