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

add support for additional properties for class Trendline #3011

Closed
2 of 8 tasks
bridgeplayr opened this issue Aug 17, 2022 · 2 comments · Fixed by #3028
Closed
2 of 8 tasks

add support for additional properties for class Trendline #3011

bridgeplayr opened this issue Aug 17, 2022 · 2 comments · Fixed by #3028
Labels

Comments

@bridgeplayr
Copy link

This is:

- [ ] 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)

What is the expected behavior?

What is the current behavior?

Missing properties

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...

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 Calculations
  • Charts
  • AutoFilter
  • Form Elements

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

Xlsx

Which versions of PhpSpreadsheet and PHP are affected?

1.24 7.3

@bridgeplayr
Copy link
Author

bridgeplayr commented Aug 18, 2022

The following properties were missing from my original Trendline request. My apologies for that. These additional properties need simple setter/getter methods: "name", "forward", "intercept", (and possibly "backward") added to the Chart/Trendline.php class. They must also be comprehended as well in Writer/Xlsx/Chart.php class.

In my experiments with Excel, when I assigned a value to the 'backward' property, it promptly reset itself - regardless of the Trend type. Therefore I am not requesting its inclusion. I mention it only for completeness. Although it seems logical that "forward" and "backward" might be appropriate for Trendtype 'moving_avg', those two properties are unavailable - "grayed out" - for that trendline type.

modify Chart/Trendline.php


    /** @var string */
    private $trendLineName = '';

    /** @var float */
    private $forward = 0;

    /** @var float */
    private $intercept = 0;

// I propose leaving the constructor as it is. Add the extra properties' setter/getter methods,
// and tack on the 3 additional properties at the end of the argument list in 'setTrendlneProperties' method.

. . .
    public function getTrendLineName(): string
    {
        return $this->trendLineName;
    }

    public function setTrendLineName(string $trendLineName): self
    {
        $this->trendLineName = $trendLineName;

        return $this;
    }

    public function getForward(): float
    {
        return $this->forward;
    }

    public function setForward(float $forward): self
    {
        $this->forward = $forward;

        return $this;
    }

    public function getIntercept(): float
    {
        return $this->intercept;
    }

    public function setIntercept(float $intercept): self
    {
        $this->intercept = $intercept;

        return $this;
    }

    public function setTrendLineProperties(?string $trendLineType = null, ?int $order = 0, ?int $period = 0, ?bool $dispRSqr = false, ?bool $dispEq = false, ?string $trendLineName = null, ?float $forward = 0, ?float $intercept = 0): self
    {
        if (!empty($trendLineType)) {
            $this->setTrendLineType($trendLineType);
        }
        if ($order !== null) {
            $this->setOrder($order);
        }
        if ($period !== null) {
            $this->setPeriod($period);
        }
        if ($dispRSqr !== null) {
            $this->setDispRSqr($dispRSqr);
        }
        if ($dispEq !== null) {
            $this->setDispEq($dispEq);
        }
        if (!empty($trendLineName)) {
            $this->setTrendLineName($trendLineName);
        }
        if ($forward !== null) {
            $this->setForward($forward);
        }
        if ($intercept !== null) {
            $this->setIntercept($intercept);
        }

        return $this;
    }

modify Writer/Xlsx/Chart.php

            // Trendlines
            if ($plotSeriesValues !== false) {
                foreach ($plotSeriesValues->getTrendLines() as $trendLine) {
                    $trendLineType = $trendLine->getTrendLineType();
                    $trendLineName = $trendLine->getTrendLineName();
                    $order = $trendLine->getOrder();
                    $period = $trendLine->getPeriod();
                    $forward= $trendLine->getForward();
                    $intercept = $trendLine->getIntercept();
                    $dispRSqr = $trendLine->getDispRSqr();
                    $dispEq = $trendLine->getDispEq();
                    $trendLineColor = $trendLine->getLineColor(); // ChartColor
                    $trendLineWidth = $trendLine->getLineStyleProperty('width');

                    $objWriter->startElement('c:trendline'); // N.B. lowercase 'ell'
                    if ($trendLineName) {
                        $objWriter->startElement('c:name');
                        $objWriter->writeRawData($trendLineName);
                        $objWriter->endElement(); // name
                    }

                    $objWriter->startElement('c:spPr');

. . .
                    $objWriter->endElement(); // trendlineType
                    if ($forward <> 0) {
                        $objWriter->startElement('c:forward');
                        $objWriter->writeAttribute('val', $forward);
                        $objWriter->endElement(); // forward
                    }
                    if ($intercept <> 0) {
                        $objWriter->startElement('c:intercept');
                        $objWriter->writeAttribute('val', $intercept);
                        $objWriter->endElement(); // intercept
                    }

Attachments:

  1. sample code to produce two charts. One chart with 3 dataseries but without trendlines; the second chart displays one dataseries but adds 3 trendlines with names and intercepts. "33_Chart_create_scatter_trendlines_wNameIntercept.php"
    33_Chart_create_scatter_trendlines_wNameIntercept.php.txt

  2. resultant spreadsheet

@bridgeplayr
Copy link
Author

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 25, 2022
Fix PHPOffice#3011. Some properties for Trendlines were omitted in the original request for this feature. Also, the trendlines sample spreadsheet included two charts. The rendering script 35_Chart_render handles this, but overlays the first output file with the second. It is changed to produce files with different names.
oleibman added a commit that referenced this issue Aug 28, 2022
Fix #3011. Some properties for Trendlines were omitted in the original request for this feature. Also, the trendlines sample spreadsheet included two charts. The rendering script 35_Chart_render handles this, but overlays the first output file with the second. It is changed to produce files with different names.
MarkBaker added a commit that referenced this issue Dec 21, 2022
### Added

- Extended flag options for the Reader `load()` and Writer `save()` methods
- Apply Row/Column limits (1048576 and XFD) in ReferenceHelper [PR #3213](#3213)
- Allow the creation of In-Memory Drawings from a string of binary image data, or from a stream. [PR #3157](#3157)
- Xlsx Reader support for Pivot Tables [PR #2829](#2829)
- Permit Date/Time Entered on Spreadsheet to be calculated as Float [Issue #1416](#1416) [PR #3121](#3121)

### Changed

- Nothing

### Deprecated

- Direct update of Calculation::suppressFormulaErrors is replaced with setter.
- Font public static variable defaultColumnWidths replaced with constant DEFAULT_COLUMN_WIDTHS.
- ExcelError public static variable errorCodes replaced with constant ERROR_CODES.
- NumberFormat constant FORMAT_DATE_YYYYMMDD2 replaced with existing identical FORMAT_DATE_YYYYMMDD.

### Removed

- Nothing

### Fixed

- Fixed handling for `_xlws` prefixed functions from Office365 [Issue #3245](#3245) [PR #3247](#3247)
- Conditionals formatting rules applied to rows/columns are removed [Issue #3184](#3184) [PR #3213](#3213)
- Treat strings containing currency or accounting values as floats in Calculation Engine operations [Issue #3165](#3165) [PR #3189](#3189)
- Treat strings containing percentage values as floats in Calculation Engine operations [Issue #3155](#3155) [PR #3156](#3156) and [PR #3164](#3164)
- Xlsx Reader Accept Palette of Fewer than 64 Colors [Issue #3093](#3093) [PR #3096](#3096)
- Use Locale-Independent Float Conversion for Xlsx Writer Custom Property [Issue #3095](#3095) [PR #3099](#3099)
- Allow setting AutoFilter range on a single cell or row [Issue #3102](#3102) [PR #3111](#3111)
- Xlsx Reader External Data Validations Flag Missing [Issue #2677](#2677) [PR #3078](#3078)
- Reduces extra memory usage on `__destruct()` calls [PR #3092](#3092)
- Additional properties for Trendlines [Issue #3011](#3011) [PR #3028](#3028)
- Calculation suppressFormulaErrors fix [Issue #1531](#1531) [PR #3092](#3092)
- Permit Date/Time Entered on Spreadsheet to be Calculated as Float [Issue #1416](#1416) [PR #3121](#3121)
- Incorrect Handling of Data Validation Formula Containing Ampersand [Issue #3145](#3145) [PR #3146](#3146)
- Xlsx Namespace Handling of Drawings, RowAndColumnAttributes, MergeCells [Issue #3138](#3138) [PR #3136](#3137)
- Generation3 Copy With Image in Footer [Issue #3126](#3126) [PR #3140](#3140)
- MATCH Function Problems with Int/Float Compare and Wildcards [Issue #3141](#3141) [PR #3142](#3142)
- Fix ODS Read Filter on number-columns-repeated cell [Issue #3148](#3148) [PR #3149](#3149)
- Problems Formatting Very Small and Very Large Numbers [Issue #3128](#3128) [PR #3152](#3152)
- XlsxWrite preserve line styles for y-axis, not just x-axis [PR #3163](#3163)
- Xlsx Namespace Handling of Drawings, RowAndColumnAttributes, MergeCells [Issue #3138](#3138) [PR #3137](#3137)
- More Detail for Cyclic Error Messages [Issue #3169](#3169) [PR #3170](#3170)
- Improved Documentation for Deprecations - many PRs [Issue #3162](#3162)
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