Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3783 taking graph size from chart's PlotArea instead of using hard-coded values #3785

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: braces

namespace PhpOffice\PhpSpreadsheet\Chart\Renderer;

Expand Down Expand Up @@ -26,9 +26,8 @@
*/
abstract class JpGraphRendererBase implements IRenderer
{
private static $width = 640;

private static $height = 480;
private const DEFAULT_WIDTH = 640;
private const DEFAULT_HEIGHT = 480;

private static $colourSet = [
'mediumpurple1', 'palegreen3', 'gold1', 'cadetblue1',
Expand Down Expand Up @@ -75,6 +74,16 @@
*/
abstract protected static function init(): void;

private function getGraphWidth(): ?float
{
return $this->chart->getPlotArea()?->getLayout()?->getWidth() ?: self::DEFAULT_WIDTH;

Check failure on line 79 in src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 6
}

private function getGraphHeight(): ?float
{
return $this->chart->getPlotArea()?->getLayout()?->getHeight() ?: self::DEFAULT_HEIGHT;

Check failure on line 84 in src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 6
}

private function formatPointMarker($seriesPlot, $markerID)
{
$plotMarkKeys = array_keys(self::$markSet);
Expand Down Expand Up @@ -221,7 +230,7 @@

private function renderCartesianPlotArea(string $type = 'textlin'): void
{
$this->graph = new Graph(self::$width, self::$height);
$this->graph = new Graph($this->getGraphWidth(), $this->getGraphHeight());
$this->graph->SetScale($type);

$this->renderTitle();
Expand Down Expand Up @@ -258,14 +267,14 @@

private function renderPiePlotArea(): void
{
$this->graph = new PieGraph(self::$width, self::$height);
$this->graph = new PieGraph($this->getGraphWidth(), $this->getGraphHeight());

$this->renderTitle();
}

private function renderRadarPlotArea(): void
{
$this->graph = new RadarGraph(self::$width, self::$height);
$this->graph = new RadarGraph($this->getGraphWidth(), $this->getGraphHeight());
$this->graph->SetScale('lin');

$this->renderTitle();
Expand Down Expand Up @@ -468,7 +477,7 @@
$seriesPlot->link->SetColor(self::$colourSet[self::$plotColour]);
} elseif ($scatterStyle == 'smoothMarker') {
$spline = new Spline($dataValuesY, $dataValuesX);
[$splineDataY, $splineDataX] = $spline->Get(count($dataValuesX) * self::$width / 20);
[$splineDataY, $splineDataX] = $spline->Get(count($dataValuesX) * $this->getGraphWidth() / 20);
$lplot = new LinePlot($splineDataX, $splineDataY);
$lplot->SetColor(self::$colourSet[self::$plotColour]);

Expand Down
Loading