-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Graph custom colors #768
Conversation
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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")'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
* @var array|string | |
* @var string[]|string |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed ?
There was a problem hiding this comment.
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).
…uszczynski/PhpSpreadsheet into graph_multiple_colors
@PowerKiKi I hope I have made all what is needed. |
Thanks, I rebased and merged your work. |
This is an follow-up for PHPOffice#158 Fixes PHPOffice#768
This is:
Checklist:
Why this change is needed?
To customize colors on pie and donut charts.