|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpOffice\PhpSpreadsheetTests\Chart; |
| 4 | + |
| 5 | +use PhpOffice\PhpSpreadsheet\Chart\Chart; |
| 6 | +use PhpOffice\PhpSpreadsheet\Chart\DataSeries; |
| 7 | +use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; |
| 8 | +use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; |
| 9 | +use PhpOffice\PhpSpreadsheet\Chart\PlotArea; |
| 10 | +use PhpOffice\PhpSpreadsheet\Chart\Title; |
| 11 | +use PhpOffice\PhpSpreadsheet\Spreadsheet; |
| 12 | +use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class Issue2931Test extends TestCase |
| 16 | +{ |
| 17 | + public function testSurface(): void |
| 18 | + { |
| 19 | + $spreadsheet = new Spreadsheet(); |
| 20 | + $sheet = $spreadsheet->getActiveSheet(); |
| 21 | + |
| 22 | + $dataSeriesLabels = [ |
| 23 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['5-6']), |
| 24 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['6-7']), |
| 25 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['7-8']), |
| 26 | + ]; |
| 27 | + |
| 28 | + $xAxisTickValues = [ |
| 29 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]), |
| 30 | + ]; |
| 31 | + |
| 32 | + $dataSeriesValues = [ |
| 33 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6, 6, 6, 5.9, 6, 6]), |
| 34 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6.5, 7, 7, 7, 7, 7]), |
| 35 | + new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 7, 8, 8, 8, 8, 7.9]), |
| 36 | + ]; |
| 37 | + |
| 38 | + $series = new DataSeries( |
| 39 | + DataSeries::TYPE_SURFACECHART, |
| 40 | + DataSeries::GROUPING_STANDARD, // grouping should not be written for surface chart |
| 41 | + range(0, count($dataSeriesValues) - 1), |
| 42 | + $dataSeriesLabels, |
| 43 | + $xAxisTickValues, |
| 44 | + $dataSeriesValues, |
| 45 | + null, // plotDirection |
| 46 | + false, // smooth line |
| 47 | + DataSeries::STYLE_LINEMARKER // plotStyle |
| 48 | + ); |
| 49 | + |
| 50 | + $plotArea = new PlotArea(null, [$series]); |
| 51 | + $legend = new ChartLegend(ChartLegend::POSITION_BOTTOM, null, false); |
| 52 | + |
| 53 | + $title = new Title('График распредления температур в пределах кр'); |
| 54 | + |
| 55 | + $chart = new Chart( |
| 56 | + 'chart2', |
| 57 | + $title, |
| 58 | + $legend, |
| 59 | + $plotArea, |
| 60 | + true, |
| 61 | + DataSeries::EMPTY_AS_GAP, |
| 62 | + ); |
| 63 | + |
| 64 | + $chart->setTopLeftPosition('$A$1'); |
| 65 | + $chart->setBottomRightPosition('$P$20'); |
| 66 | + |
| 67 | + $sheet->addChart($chart); |
| 68 | + |
| 69 | + $writer = new XlsxWriter($spreadsheet); |
| 70 | + $writer->setIncludeCharts(true); |
| 71 | + $writer = new XlsxWriter($spreadsheet); |
| 72 | + $writer->setIncludeCharts(true); |
| 73 | + $writerChart = new XlsxWriter\Chart($writer); |
| 74 | + $data = $writerChart->writeChart($chart); |
| 75 | + |
| 76 | + // rotX etc. should be generated for surfaceChart 2D |
| 77 | + // even when unspecified. |
| 78 | + $expectedXml2D = [ |
| 79 | + '<c:view3D><c:rotX val="90"/><c:rotY val="0"/><c:rAngAx val="0"/><c:perspective val="0"/></c:view3D>', |
| 80 | + ]; |
| 81 | + $expectedXml3D = [ |
| 82 | + '<c:view3D/>', |
| 83 | + ]; |
| 84 | + $expectedXmlNoX = [ |
| 85 | + 'c:grouping', |
| 86 | + ]; |
| 87 | + |
| 88 | + // confirm that file contains expected tags |
| 89 | + foreach ($expectedXml2D as $expected) { |
| 90 | + self::assertSame(1, substr_count($data, $expected), $expected); |
| 91 | + } |
| 92 | + foreach ($expectedXmlNoX as $expected) { |
| 93 | + self::assertSame(0, substr_count($data, $expected), $expected); |
| 94 | + } |
| 95 | + |
| 96 | + $series->setPlotType(DataSeries::TYPE_SURFACECHART_3D); |
| 97 | + $plotArea = new PlotArea(null, [$series]); |
| 98 | + $chart->setPlotArea($plotArea); |
| 99 | + $writerChart = new XlsxWriter\Chart($writer); |
| 100 | + $data = $writerChart->writeChart($chart); |
| 101 | + // confirm that file contains expected tags |
| 102 | + foreach ($expectedXml3D as $expected) { |
| 103 | + self::assertSame(1, substr_count($data, $expected), $expected); |
| 104 | + } |
| 105 | + foreach ($expectedXmlNoX as $expected) { |
| 106 | + self::assertSame(0, substr_count($data, $expected), $expected); |
| 107 | + } |
| 108 | + |
| 109 | + $spreadsheet->disconnectWorksheets(); |
| 110 | + } |
| 111 | +} |
0 commit comments