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

Scheme colors in Charts #2863

Closed
2 of 8 tasks
bridgeplayr opened this issue Jun 1, 2022 · 19 comments · Fixed by #2906
Closed
2 of 8 tasks

Scheme colors in Charts #2863

bridgeplayr opened this issue Jun 1, 2022 · 19 comments · Fixed by #2906
Labels

Comments

@bridgeplayr
Copy link

bridgeplayr commented Jun 1, 2022

This is:

- [x] a bug report
- [x] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

See also issue #2299 and fix #2828

What is the expected behavior?

PhpSpreadsheet/Chart/DataSeriesValues.php and PhpSpreadsheet/Writer/Xlsx/Chart.php should support "Scheme colors" as well as RGB colors (both string and hex value), for lines, markers, and fill properties. Scheme colors are available in 4 "colorful" palettes and 11 "monochrome" palettes. These built-in palette colors are labeled as 'schemeClr', [string] in xml attributes.
E.g. xml snippet: <a:schemeClr val="accent6">

What is the current behavior?

Phpspreadsheet Chart does not currently support these colors, which are the default (automatic) colors when none is chosen by the user.

What are the steps to reproduce?

33_Chart_create_scatterManual.xlsx
Attached is a manually modified version of the chart produced by '33_Chart_create_scatter2.php' which demonstrates several unsupported properties related to SchemeClr, as well as unsupported line properties demonstrated below:
<c:spPr>
<a:ln w="31750" cap="sq" cmpd="tri"> width, cap type, compound type
<a:solidFill>
<a:schemeClr val="accent1"> palette color
<a:alpha val="60000"/> transparency ?
</a:schemeClr>
</a:solidFill>
<a:prstDash val="sysDash"/> dash type
<a:miter lim="800000"/> miter
<a:headEnd type="arrow" w="med" len="sm"/> arrow-head type, width, size
<a:tailEnd type="triangle" w="med" len="lg"/> arrow-tail type, with, size
</a:ln>
</c:spPr>

Note: Bezier (smooth) line property is the very last attribute of a data series:
...
</c:v>
</c:pt>
</c:numCache>
</c:numRef>
</c:yVal>
<c:smooth val="1"/> Bezier line designation

Marker properties

Markers types and sizes are now supported properties.

Marker fill colors and marker border colors are not supported quite right yet. (even in the cloned version from a week ago).

  • Markers can have no fill color, and no border color. (Excel supplies an automatic schemeClr for the marker border in this case: like

<a:schemeClr val="accent1"> for the first dataseries,
<a:schemeClr val="accent2"> for the second, and so on.)

  • A marker can have a border color, but no fill color.

e.g.
<a:ln>
<a:solidFill>
<a:srgbClr val="002060"/>
</a:solidFill>
</a:ln>

  • A marker can have both a fill color and a border color. (In this case, the marker color must be an array.)

<c:marker>
<c:symbol val="square"/>
<c:size val="7"/>
<c:spPr>
<a:solidFill>
<a:schemeClr val="accent6">
<a:alpha val="97000"/>
</a:schemeClr>
</a:solidFill>
<a:ln>
<a:solidFill>
<a:srgbClr val="0FF000"/>
</a:solidFill>
</a:ln>
</c:spPr>
</c:marker>

I have not been successful in creating php code to implement these new properties with setter/getter methods, but they can probably be implemented in ./Chart/DataSeriesValues.php (& maybe ./Chart/Properties.php) and ./Writer/Xlsx/Chart.php

None of the above properties are propagated to any other files (like ./xl/drawings/drawingsN.xml) as I feared they might. Good news.

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calulations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

I have not experimented with any format other than xlsx.

Which versions of PhpSpreadsheet and PHP are affected?

1.23 & 7.3

I didn't forget. I'm just slow (& old).

@oleibman
Copy link
Collaborator

oleibman commented Jun 2, 2022

As you've noted, we've recently added Scheme colors for Chart fonts. The additional opportunities you've described are on my to-do list, but it may take a while. Thank you for providing a sample spreadsheet to use for testing when the time comes.

@oleibman oleibman added the charts label Jun 2, 2022
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jun 10, 2022
Fix PHPOffice#2219. Address some, but not all, issues mentioned in PHPOffice#2863.

For Pie Charts, fill color is stored in XML as part of dPt node, which had been ignored by Reader/Xlsx/Chart. Add support for it, including when specified as schemeClr or prstClr rather than srgbClr. Add support for prstClr in other cases where schemeClr is supported.
oleibman added a commit that referenced this issue Jun 14, 2022
* Expand Chart Support for schemeClr and prstClr

Fix #2219. Address some, but not all, issues mentioned in #2863.

For Pie Charts, fill color is stored in XML as part of dPt node, which had been ignored by Reader/Xlsx/Chart. Add support for it, including when specified as schemeClr or prstClr rather than srgbClr. Add support for prstClr in other cases where schemeClr is supported.

* Update Change Log

Add this PR.
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jun 22, 2022
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).
@oleibman
Copy link
Collaborator

Please test with PR #2906 if you are able. I'm not sure how easy that is since there are prerequisite changes since the last release. At the very least, I am able to copy your sample file accurately.

@bridgeplayr
Copy link
Author

bridgeplayr commented Jun 23, 2022 via email

@bridgeplayr
Copy link
Author

It took me some time to recall that the "connect-the-dots" property is named "scatterLines", with its getter/setter methods. That's ok, but it confuses me. In my attempted implementation, I added keys 'smooth' and 'connected' with boolean values in the property $lineStyleProperties. I then defined $scatterLine as an object described by the many getter/setter methods dealing with LineStyle/Color/Shadow/Glow/SoftEdge special effects. I'm still figuring out how to describe all of the properties of each DataSeriesValues objects in my proposed chart.

I must modify the methods which I was close to implementing. No worries. I am working hard to do it.

@bridgeplayr
Copy link
Author

33_Chart_create_Color_scatter.php.txt

Success. Not the prettiest code you will see. Feel free to clean things up as you see fit.

@oleibman
Copy link
Collaborator

Please do not double-post in this thread and the PR. I have adopted several of your suggestions in my latest commit; your code sample is incorporated into the existing 33_chart_create_scatter2. There was a slight mismatch between your code and my changes; previously, you needed to set a marker shape in order to support marker colors, and your code didn't do that. I have changed so that this is no longer necessary; I explicitly set the marker shape for 2 of the 3 series in the updated sample, and leave it unset for the other.

Is "scatterlines" applicable to other types of chart? I can certainly consider making it part of line styles if so. I think I added it after the latest release, so that wouldn't be a breaking change at this point.

@bridgeplayr
Copy link
Author

bridgeplayr commented Jun 26, 2022 via email

@bridgeplayr
Copy link
Author

FYI, there is a typo in Chart/Properties.php
const LINE_STYLE_JOIN_ROUND = 'bevel'; -->'round'
const LINE_STYLE_JOIN_MITER = 'miter';
const LINE_STYLE_JOIN_BEVEL = 'bevel';

@oleibman
Copy link
Collaborator

I might be wrong, but it's deliberate, not a typo. When I tried setting the property to 'round' in Excel, I thought the XML nevertheless specified 'bevel'. If you think otherwise, I will try that experiment again.

@bridgeplayr
Copy link
Author

I changed a chart line join property to 'round' in Excel, and the xml also showed 'round'.

@oleibman
Copy link
Collaborator

Okay, I will take another look.

@oleibman
Copy link
Collaborator

My latest push is probably the one where I'm done tinkering. Have a look. I did change 'round', but I haven't been successful in creating an Excel spreadsheet that uses it. Please upload yours and I'll incorporate some tests for it in my next PR.

@bridgeplayr
Copy link
Author

Glad to do it.

@bridgeplayr
Copy link
Author

Small changes to samples/Chart/33_Chart_create_scatter2.php:

  • LINE_STYLE_DASH_SQUARE_DOT --> ...ROUND_DOT
  • added linestyles to $yAxis to prove Writer can correctly handle it.

33_Chart_create_scatter2.1.php.txt
33_Chart_create_Color_scatter2.1.xlsx

@oleibman
Copy link
Collaborator

Why is ROUND_DOT a better test than SQUARE_DOT?
You did not include yAxis in the Chart. Even had you done so, it seems close or identical to the result from not including it. If I increase the width to, say, 1.75, there is at least a visual difference.
My comments about width were wrong - size is in points, not pixels.

@bridgeplayr
Copy link
Author

Oops. WRONG round. Retrying with JOIN instead of DASH.

In my own version, I included the yAxis, but in the edited version of the released sample, I neglected to add it to the chart. If added, it will work. Yes, its impact is hard to see. But it is in the xml, which is all that counts.

@bridgeplayr
Copy link
Author

Results of experiments with 33_Chart_create_scatter2.1.xlsx

  • DSV 1: set join= 'bevel' got 'bevel'
  • DSV 1: set join= 'round', got 'bevel', [confirming your observation]
  • DSV 2: set join= 'miter', got 'miter'
  • DSV 2: set join= 'round', got 'miter' ??
  • I conclude that Excel ignores join settings of DSVs because other DSV settings override it.
  • My guess: In the case of DSV 1, since it is a Bezier (smooth) line, JOIN==='bevel'.
  • My guess: in the case of DSV 2, since it is straight line, JOIN==='miter'.

To try something else with LineStyle properties, I added a border around the Title, with these settings which I kept constant:

  • width: w=1.5 pts
  • dash: 'dashDot'
  • color: val='accent2'
  • color; alpha=0
  • color: type='schemeClr'

Here are the results of changing the JOIN setting of the Title border:

  • set join = 'round', got 'round' [So here is a case where 'round' -> 'round']
  • set join = 'bevel', got 'bevel'
  • set join = 'miter', got 'bevel' ??
  • I conclude Excel changes the JOIN setting 'miter' to 'bevel' for a text box. Just because.
  • Further, I conclude Excel applies some set of consistency rules for chart and drawing objects which we mere mortals can only guess at.

Bottom line:

  • For at least one case, setting join property to 'round' actually produced a join property 'round'. So keep LINE_STYLE_JOIN_ROUND = 'round'.

@oleibman
Copy link
Collaborator

I will make one more push tonight. The results of using schemeClr for Axis lines wasn't entirely satisfactory - it's in the Xml, but you can't see it in Excel. This might be another case where Excel is acting on its own - perhaps accent2 used a certain way means one color, but used in another way means a different color. I will use srgbClr for this demonstration.

oleibman added a commit that referenced this issue Jun 30, 2022
* Additional Support for Chart DataSeriesValues

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).

* Update Change Log

I had updated previously but forgot to stage the member.

* Adopt Some Suggestions

Incorporate some changes suggested by @bridgeplayr.

* Use ChartColor for DSV Fill And Font Text

DataSeriesValues Fill could be a scalar or an array, so I saved it till last.

* Some Final Cleanup

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.
@bridgeplayr
Copy link
Author

Well done. These are big improvements.
Many thanks for enabling me to move forward with my project. (But I have more requests...)

MarkBaker added a commit that referenced this issue 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants