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

Additional Support for Chart DataSeriesValues #2906

Merged
merged 6 commits into from
Jun 30, 2022

Conversation

oleibman
Copy link
Collaborator

@oleibman oleibman commented Jun 23, 2022

Fix #2863. DataSeriesValues now extends Properties, allowing it to share code in common with Axis and Gridlines. This causes some minor breakages; in particular line width is now initialized to null instead of Excel's default value, and is specified in points, as the user would expect from Excel, rather than the value stored in Xml.

This change:

  • adds support for 1 or 2 marker colors.
  • adds support for smoothLine to DataSeriesValues.
  • will determine catAx or valAx for Axis based on what is read from the Xml when available, rather than guessing based on format. (Another minor break.)
  • reads formatCode and sourceLinked for Axis.
  • correct 2 uses of $plotSeriesRef to $plotSeriesIndex in Writer/Xlsx/Chart.
  • pushes coverage over 90% for Chart (88.70% overall).
  • Incorporates PR Allow setting fill colour for bar chart data points #2724 from @DanWin.

This is:

- [x] a bugfix
- [ ] a new feature
- [ ] refactoring
- [ ] additional unit tests

Checklist:

Why this change is needed?

Provide an explanation of why this change is needed, with links to any Issues (if appropriate).
If this is a bugfix or a new feature, and there are no existing Issues, then please also create an issue that will make it easier to track progress with this PR.

oleibman added 2 commits June 22, 2022 16:58
Fix PHPOffice#2863. DataSeriesValues now extends Properties, allowing it to share code in common with Axis and Gridlines. This causes some minor breakages; in particular line width is now initialized to null instead of Excel's default value, and is specified in points, as the user would expect from Excel, rather than the value stored in Xml.

This change:
- adds support for 1 or 2 marker colors.
- adds support for `smoothLine` to DataSeriesValues.
- will determine `catAx` or `valAx` for Axis based on what is read from the Xml when available, rather than guessing based on format. (Another minor break.)
- reads `formatCode` and `sourceLinked` for Axis.
- correct 2 uses of `$plotSeriesRef` to `$plotSeriesIndex` in Writer/Xlsx/Chart.
- pushes coverage over 90% for Chart (88.70% overall).
I had updated previously but forgot to stage the member.
@oleibman oleibman mentioned this pull request Jun 23, 2022
8 tasks
@bridgeplayr
Copy link

All your changes are very similar to my work to address these issues. I admit your implementation is better.

Adding Class ChartColor is good. That makes the various object's colors much easier to deal with.

I have some suggestions:

Property smoothLine (and its getter/setter methods) should be removed from DataSeries. They belong only in DataSeriesValues.

TYPOS:
I am embarrassed to point out "Properties::LINE_STYLE_DASH_SQUERE_DOT", but since I have used it in a chart, it should be renamed ---------------"LINE_STYLE_DASH_SQUARE_DOT".

You found and corrected almost all of the misnamed parameters "$AlphaType", but it escaped your correction in Axis. I renamed it "$ColorType", but it appears that you prefer "$colorType". Your call.

(Someday - I suggest adding another Class - ChartLine - as an extension of Properties, which can accommodate all of the classes Axis, Gridlines, Scatterlines (as well as the yet-to-be-added Trendline), all of which have very similar line properties (linewidth and color), as well as special effects: LineStyle, Shadow, Glow, and SoftEdges. The implications of implementing it in Writer/Xlsx are messy, of course.)

@bridgeplayr
Copy link

One more suggestion:
Inside an Excel chart, marker colors are listed as "Fill color" and "Border Color". Might it be better to rename markerColor1 as markerFillColor, and rename
markerColor2 as markerBorderColor?

And rename their respective getter/setter methods:
getMarkerFillColor(): ChartColor
return $this->markerFillColor;
getMarkerBorderColor(): ChartColor
return $this->markerBorderColor;

Further:
Now that markers have fill & border colors defined by class ChartColor, what is the purpose of the 7th parameter ($fillColor) in DataSeriesValues' constructor?

In Writer/Xlsx function writePlotGroup(), in the loop for $plotSeriesIdx => $plotSeriesRef, inside qualifiers "if ($plotSeriesValues) {
....
if ($plotSeriesMarker !== 'none') {
...
this superfluous statement appears: $fillColor = $plotSeriesValues->getFillColor();
The temporary variable $fillColor is not used. It is the 7th parameter passed to DataSeriesValues' constructor.
This leads to an important missing section of code between
// Labels
$plotSeriesLabel = ...
....
and
....
// Formatting for the points [markers]

Between those sections of xml generation must be the description of the line connecting the markers (or points). And, because it is a 'line', it can have color, linewidth, Styling, Shadow, Glow, SoftEdges - the whole barnyard of special effects. That is where all that stuff must be added. No fun, but I've taken a stab at it. More later.

@oleibman
Copy link
Collaborator Author

@bridgeplayr, thank you for the original suggestions, and for your thoughtful review of the change. There must be a way to insert replies in the correct place in the original message in Github, but I haven't figured it out yet. So I'll just put all my replies here.

  • removing smoothLine from DataSeries falls in the "breaking change" category, and I hope to get to those eventually (this isn't the first potential break that I've come across during these PRs), but, for now, it will stay.
  • I will spell Square correctly and add a deprecation notice for Squere. I will probably add a new commit to this PR over the weekend.
  • our properties are almost always camel case starting with lowercase, so colorType will remain.
  • $AlphaType should just be $type. Unfortunately, with Php8, changing parameter names is a breaking change, because you can now specify keyword parameters. So, see earlier comment about breaking changes.
  • I considered adding ChartLine as its own class, like ChartColor. I found that I didn't need it for this change; there may be a time when I change my mind. ChartColor was especially needed because it is used by non-Chart classes, in particular Font. Right now, everything that needs Line inherits it from Properties.
  • I will rename the properties to markerFillColor and markerBorderColor as you suggest. Part of this weekend's commit.
  • I agree that some constructor parameters no longer make sense. See earlier comment about breaking changes.
  • I have not yet had a chance to analyze your superfluous statement. If your comment makes sense, I will try to incorporate it over the weekend.
  • Work on labels is next on my list. It is too big to add to this change.
  • This change does deal with the lines between the markers. Otherwise, I would not have been able to handle your sample file.

@oleibman
Copy link
Collaborator Author

I think you are correct that the statement which initializes fillColor is superfluous. However, I don't think we miss any important executable code as a result. Writing of the line styles takes place with the call to writeLineStyles just at the end of the if statement immediately following "Formatting for the points". You are right that the effects aren't written there. In theory, they could be written, and quite simply, if the necessary support is added to Reader. Those changes are too big to add to this one; they are on my to-do list.

@bridgeplayr
Copy link

Success. Not the prettiest code you will see. Feel free to clean things up as you see fit.
(I also commented in a different thread - #2863)

33_Chart_create_Color_scatter.php.txt

Incorporate some changes suggested by @bridgeplayr.
oleibman added 3 commits June 27, 2022 21:30
DataSeriesValues Fill could be a scalar or an array, so I saved it till last.
No code changes.

Illustrate even more of the new features in existing sample files.

Deprecate *_ARGB in Properties/ChartColors in favor of *_RGB, because it uses only 6 hex digits. The alpha value is stored separately.
@oleibman oleibman merged commit 5d5e550 into PHPOffice:master Jun 30, 2022
MarkBaker added a commit that referenced this pull request Jul 9, 2022
Note that this will be the last 1.x branch release before the 2.x release. We will maintain both branches in parallel for a time; but users are requested to update to version 2.0 once that is fully available.

### Added

- Added `removeComment()` method for Worksheet [PR #2875](https://github.com/PHPOffice/PhpSpreadsheet/pull/2875/files)
- Add point size option for scatter charts [Issue #2298](#2298) [PR #2801](#2801)
- Basic support for Xlsx reading/writing Chart Sheets [PR #2830](#2830)

  Note that a ChartSheet is still only written as a normal Worksheet containing a single chart, not as an actual ChartSheet.

- Added Worksheet visibility in Ods Reader [PR #2851](#2851) and Gnumeric Reader [PR #2853](#2853)
- Added Worksheet visibility in Ods Writer [PR #2850](#2850)
- Allow Csv Reader to treat string as contents of file [Issue #1285](#1285) [PR #2792](#2792)
- Allow Csv Reader to store null string rather than leave cell empty [Issue #2840](#2840) [PR #2842](#2842)
- Provide new Worksheet methods to identify if a row or column is "empty", making allowance for different definitions of "empty":
  - Treat rows/columns containing no cell records as empty (default)
  - Treat cells containing a null value as empty
  - Treat cells containing an empty string as empty

### Changed

- Modify `rangeBoundaries()`, `rangeDimension()` and `getRangeBoundaries()` Coordinate methods to work with row/column ranges as well as with cell ranges and cells [PR #2926](#2926)
- Better enforcement of value modification to match specified datatype when using `setValueExplicit()`
- Relax validation of merge cells to allow merge for a single cell reference [Issue #2776](#2776)
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.

  See [the Discussion section on github](#2821) for details of performance across versions
- Improved performance for removing rows/columns from a worksheet

### Deprecated

- Nothing

### Removed

- Nothing

### Fixed

- Xls Reader resolving absolute named ranges to relative ranges [Issue #2826](#2826) [PR #2827](#2827)
- Null value handling in the Excel Math/Trig PRODUCT() function [Issue #2833](#2833) [PR #2834](#2834)
- Invalid Print Area defined in Xlsx corrupts internal storage of print area [Issue #2848](#2848) [PR #2849](#2849)
- Time interval formatting [Issue #2768](#2768) [PR #2772](#2772)
- Copy from Xls(x) to Html/Pdf loses drawings [PR #2788](#2788)
- Html Reader converting cell containing 0 to null string [Issue #2810](#2810) [PR #2813](#2813)
- Many fixes for Charts, especially, but not limited to, Scatter, Bubble, and Surface charts. [Issue #2762](#2762) [Issue #2299](#2299) [Issue #2700](#2700) [Issue #2817](#2817) [Issue #2763](#2763) [Issue #2219](#2219) [Issue #2863](#2863) [PR #2828](#2828) [PR #2841](#2841) [PR #2846](#2846) [PR #2852](#2852) [PR #2856](#2856) [PR #2865](#2865) [PR #2872](#2872) [PR #2879](#2879) [PR #2898](#2898) [PR #2906](#2906) [PR #2922](#2922) [PR #2923](#2923)
- Adjust both coordinates for two-cell anchors when rows/columns are added/deleted. [Issue #2908](#2908) [PR #2909](#2909)
- Keep calculated string results below 32K. [PR #2921](#2921)
- Filter out illegal Unicode char values FFFE/FFFF. [Issue #2897](#2897) [PR #2910](#2910)
- Better handling of REF errors and propagation of all errors in Calculation engine. [PR #2902](#2902)
- Calculating Engine regexp for Column/Row references when there are multiple quoted worksheet references in the formula [Issue #2874](#2874) [PR #2899](#2899)
@oleibman oleibman deleted the chartdsv3 branch July 23, 2022 23:20
@bridgeplayr
Copy link

bridgeplayr commented Oct 11, 2022 via email

@oleibman
Copy link
Collaborator Author

Thank you for the nice comments. I too have learned a lot from your suggestions (e.g. I had never actually created a chart in Excel before starting to work on them). Don't hesitate to let us know what's still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

Scheme colors in Charts
2 participants