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

Graph custom colors #768

Conversation

krzysztofruszczynski
Copy link
Contributor

@krzysztofruszczynski krzysztofruszczynski commented Nov 9, 2018

This is:

- [ ] a bugfix
- [x] a new feature

Checklist:

Why this change is needed?

To customize colors on pie and donut charts.

Copy link
Member

@PowerKiKi PowerKiKi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like an interesting new feature, but there are a few things that need to be improved before merging.

Also make sure to review the PR checklist (missing changelog).

try {
$testInstance->setFillColor('WRONG COLOR');
} catch (Exception $e) {
self::assertEquals($e->getMessage(), 'Invalid hex color for chart series');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use PHPunit's $this->expectExceptionMessage($expectMessage); in a separate test case.

try {
$testInstance->setFillColor(['b8292f', 'WRONG COLOR']);
} catch (Exception $e) {
self::assertEquals($e->getMessage(), 'Invalid hex color for chart series (color: "WRONG COLOR")');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

*
* @var string
* @var array|string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be and all similar type hinting too:

Suggested change
* @var array|string
* @var string[]|string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it, however phpcs suggest string|string[] instead of string[]|string

}
}
} else {
if (!preg_match('/^[a-f0-9]{6}$/i', $color)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid duplicating validation code by creating a private method like "validateColor(string $color): void" that throw exception if need be.

$fillColorValues = $plotSeriesValues->getFillColor();
if ($fillColorValues !== null && is_array($fillColorValues)) {
foreach ($plotSeriesValues->getDataValues() as $dataKey => $dataValue) {
$objWriter->startElement('c:dPt');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be extract into private method to avoid duplicating code

@@ -1127,9 +1151,6 @@ private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMulti
$objWriter->endElement();
}

// Values
$plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was moved to line 1100 ($plotSeriesValues is needed earlier).

@krzysztofruszczynski
Copy link
Contributor Author

@PowerKiKi I hope I have made all what is needed.
Regarding Scrutinizer remarks about sample - I have copied this part of code from 33_Chart_create_pie.php . Both samples are created properly.

@PowerKiKi PowerKiKi closed this in 12bf085 Dec 10, 2018
@PowerKiKi
Copy link
Member

Thanks, I rebased and merged your work.

guillaume-ro-fr pushed a commit to guillaume-ro-fr/PhpSpreadsheet that referenced this pull request Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants