Skip to content

Commit 5c13b17

Browse files
authored
Replace Dev jpgraph/jpgraph with mitoteam/jpgraph (#2997)
* Replace Dev jpgraph/jpgraph with mitoteam/jpgraph PR #2979 added support for mitoteam/jpgraph as an alternative to jpgraph/jpgraph. The package jpgraph/jpgraph is abandoned in composer, and the version loaded with composer has been unusable for some time. This PR removes the dev requirement for jpgraph/jpgraph, and adds a dev requirement for mitoteam/jpgraph in its place. With a usable graph library, a number of tests and samples that had been disabled are now re-enabled. A lot of new functionality has been added to Charts recently. Some of that new code has exposed bugs in JpgraphRendererBase. I have fixed those where I could. A handful of exceptions remain; I will investigate, and hopefully fix, those over time, but I don't feel it is necessary to fix them all before installing this PR - we are already way ahead of the game with the graphs that are working. Three members had been ignoring code coverage in whole or in part because of the unavailability of a usable graph libray. Code coverage is restored in them. I am relieved to report that, although they aren't completely covered, adding them did not reduce code coverage by much - it is still over 90.4%. I took a look at JpgraphRendererBase and Phpstan. Phpstan reports 128 problems. When I added some docblocks to correct some of those, the number increased to 284. Sigh. I will investigate over time, but, for now, we will still suppress Phpstan for JpgraphRendererBase. I do not find a License file for mitoteam. However, there also wasn't one for jpgraph in the first place. Based on that and the discussion in #2996 (mitoteam will be used in exactly the same manner as mpdf), I don't think this is a problem. IANAL. * PHP 8.2 Problems Tons of "cannot create dynamic property" deprecations in jpgraph. Disable the test with most of those for now; leave the two with only a handful of messages enabled. * Correct Failures in 2 Stock Charts Down to 6 templates on which Render fails.
1 parent f34e0ea commit 5c13b17

File tree

12 files changed

+110
-82
lines changed

12 files changed

+110
-82
lines changed

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
8282
"dompdf/dompdf": "^1.0 || ^2.0",
8383
"friendsofphp/php-cs-fixer": "^3.2",
84-
"jpgraph/jpgraph": "^4.0",
84+
"mitoteam/jpgraph": "^10.1",
8585
"mpdf/mpdf": "8.1.1",
8686
"phpcompatibility/php-compatibility": "^9.3",
8787
"phpstan/phpstan": "^1.1",
@@ -91,10 +91,11 @@
9191
"tecnickcom/tcpdf": "^6.4"
9292
},
9393
"suggest": {
94+
"ext-intl": "PHP Internationalization Functions",
9495
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
95-
"dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
96-
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
97-
"jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers"
96+
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
97+
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet fully support PHP8)",
98+
"mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers"
9899
},
99100
"autoload": {
100101
"psr-4": {

composer.lock

Lines changed: 45 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ parameters:
1212
excludePaths:
1313
- src/PhpSpreadsheet/Chart/Renderer/JpGraph.php
1414
- src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
15-
- src/PhpSpreadsheet/Chart/Renderer/MtJpGraphRenderer.php
1615
parallel:
1716
processTimeout: 300.0
1817
checkMissingIterableValueType: false

samples/Chart/32_Chart_read_write_HTML.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
require __DIR__ . '/../Header.php';
77

88
// Change these values to select the Rendering library that you wish to use
9-
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
9+
//Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
10+
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class);
1011

1112
$inputFileType = 'Xlsx';
1213
$inputFileNames = __DIR__ . '/../templates/36write*.xlsx';

samples/Chart/32_Chart_read_write_PDF.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf::class);
99

1010
// Change these values to select the Rendering library that you wish to use
11-
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
11+
//Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
12+
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class);
1213

1314
$inputFileType = 'Xlsx';
1415
$inputFileNames = __DIR__ . '/../templates/36write*.xlsx';

samples/Chart/35_Chart_render.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
require __DIR__ . '/../Header.php';
77

8-
if (PHP_VERSION_ID >= 80000) {
9-
$helper->log('Jpgraph no longer runs against PHP8');
10-
exit;
11-
}
12-
138
// Change these values to select the Rendering library that you wish to use
14-
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
9+
//Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
10+
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class);
1511

1612
$inputFileType = 'Xlsx';
1713
$inputFileNames = __DIR__ . '/../templates/32readwrite*[0-9].xlsx';
14+
//$inputFileNames = __DIR__ . '/../templates/32readwriteStockChart5.xlsx';
1815

1916
if ((isset($argc)) && ($argc > 1)) {
2017
$inputFileNames = [];
@@ -24,6 +21,18 @@
2421
} else {
2522
$inputFileNames = glob($inputFileNames);
2623
}
24+
if (count($inputFileNames) === 1) {
25+
$unresolvedErrors = [];
26+
} else {
27+
$unresolvedErrors = [
28+
'32readwriteBubbleChart2.xlsx',
29+
'32readwritePieChart3.xlsx',
30+
'32readwritePieChart4.xlsx',
31+
'32readwritePieChart3D1.xlsx',
32+
'32readwritePieChartExploded1.xlsx',
33+
'32readwritePieChartExploded3D1.xlsx',
34+
];
35+
}
2736
foreach ($inputFileNames as $inputFileName) {
2837
$inputFileNameShort = basename($inputFileName);
2938

@@ -32,6 +41,11 @@
3241

3342
continue;
3443
}
44+
if (in_array($inputFileNameShort, $unresolvedErrors, true)) {
45+
$helper->log('File ' . $inputFileNameShort . ' does not yet work with this script');
46+
47+
continue;
48+
}
3549

3650
$helper->log("Load Test from $inputFileType file " . $inputFileNameShort);
3751

src/PhpSpreadsheet/Chart/Chart.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,10 @@ public function refresh(): void
661661

662662
/**
663663
* Render the chart to given file (or stream).
664-
* Unable to cover code until a usable current version of JpGraph
665-
* is made available through Composer.
666664
*
667665
* @param string $outputDestination Name of the file render to
668666
*
669667
* @return bool true on success
670-
*
671-
* @codeCoverageIgnore
672668
*/
673669
public function render($outputDestination = null)
674670
{

src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ private function renderPlotLine($groupID, $filled = false, $combination = false,
277277
{
278278
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
279279

280-
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
280+
$index = array_keys($this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder())[0];
281+
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
281282
if ($labelCount > 0) {
282283
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
283284
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount);
@@ -294,8 +295,9 @@ private function renderPlotLine($groupID, $filled = false, $combination = false,
294295

295296
// Loop through each data series in turn
296297
for ($i = 0; $i < $seriesCount; ++$i) {
297-
$dataValues = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
298-
$marker = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
298+
$index = array_keys($this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder())[$i];
299+
$dataValues = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getDataValues();
300+
$marker = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointMarker();
299301

300302
if ($grouping == 'percentStacked') {
301303
$dataValues = $this->percentageAdjustValues($dataValues, $sumValues);
@@ -324,7 +326,7 @@ private function renderPlotLine($groupID, $filled = false, $combination = false,
324326
// Set the appropriate plot marker
325327
$this->formatPointMarker($seriesPlot, $marker);
326328
}
327-
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
329+
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)->getDataValue();
328330
$seriesPlot->SetLegend($dataLabel);
329331

330332
$seriesPlots[] = $seriesPlot;
@@ -347,7 +349,8 @@ private function renderPlotBar($groupID, $dimensions = '2d'): void
347349
}
348350
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
349351

350-
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
352+
$index = array_keys($this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder())[0];
353+
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
351354
if ($labelCount > 0) {
352355
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
353356
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
@@ -371,7 +374,8 @@ private function renderPlotBar($groupID, $dimensions = '2d'): void
371374

372375
// Loop through each data series in turn
373376
for ($j = 0; $j < $seriesCount; ++$j) {
374-
$dataValues = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
377+
$index = array_keys($this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder())[$j];
378+
$dataValues = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getDataValues();
375379
if ($grouping == 'percentStacked') {
376380
$dataValues = $this->percentageAdjustValues($dataValues, $sumValues);
377381
}
@@ -535,6 +539,10 @@ private function renderPlotStock($groupID): void
535539
$dataValues = [];
536540
// Loop through each data series in turn and build the plot arrays
537541
foreach ($plotOrder as $i => $v) {
542+
$dataValuesX = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($v);
543+
if ($dataValuesX === false) {
544+
continue;
545+
}
538546
$dataValuesX = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($v)->getDataValues();
539547
foreach ($dataValuesX as $j => $dataValueX) {
540548
$dataValues[$plotOrder[$i]][$j] = $dataValueX;
@@ -549,7 +557,7 @@ private function renderPlotStock($groupID): void
549557
$jMax = count($dataValues[0]);
550558
for ($j = 0; $j < $jMax; ++$j) {
551559
for ($i = 0; $i < $seriesCount; ++$i) {
552-
$dataValuesPlot[] = $dataValues[$i][$j];
560+
$dataValuesPlot[] = $dataValues[$i][$j] ?? null;
553561
}
554562
}
555563

src/PhpSpreadsheet/Chart/Renderer/MtJpGraphRenderer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* https://packagist.org/packages/mitoteam/jpgraph
1010
*
1111
* This package is up to date for August 2022 and has PHP 8.1 support.
12-
*
13-
* @codeCoverageIgnore
1412
*/
1513
class MtJpGraphRenderer extends JpGraphRendererBase
1614
{

src/PhpSpreadsheet/Writer/Html.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,10 @@ public function generateNavigation()
551551
* Extend Row if chart is placed after nominal end of row.
552552
* This code should be exercised by sample:
553553
* Chart/32_Chart_read_write_PDF.php.
554-
* However, that test is suppressed due to out-of-date
555-
* Jpgraph code issuing warnings. So, don't measure
556-
* code coverage for this function till that is fixed.
557554
*
558555
* @param int $row Row to check for charts
559556
*
560557
* @return array
561-
*
562-
* @codeCoverageIgnore
563558
*/
564559
private function extendRowsForCharts(Worksheet $worksheet, int $row)
565560
{
@@ -725,11 +720,6 @@ private function writeImageInCell(Worksheet $worksheet, $coordinates)
725720
* Generate chart tag in cell.
726721
* This code should be exercised by sample:
727722
* Chart/32_Chart_read_write_PDF.php.
728-
* However, that test is suppressed due to out-of-date
729-
* Jpgraph code issuing warnings. So, don't measure
730-
* code coverage for this function till that is fixed.
731-
*
732-
* @codeCoverageIgnore
733723
*/
734724
private function writeChartInCell(Worksheet $worksheet, string $coordinates): string
735725
{

0 commit comments

Comments
 (0)