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

[Feature] Can set min and max values for axes. #2751

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/changes/1.x/1.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
- Add basic ruby text (phonetic guide) support for Word2007 and HTML Reader/Writer, RTF Writer, basic support for ODT writing by [@Deadpikle](https://github.com/Deadpikle) in [#2727](https://github.com/PHPOffice/PHPWord/pull/2727)
- Reader HTML: Support font styles for h1/h6 by [@Progi1984](https://github.com/Progi1984) fixing [#2619](https://github.com/PHPOffice/PHPWord/issues/2619) in [#2737](https://github.com/PHPOffice/PHPWord/pull/2737)
- Writer EPub3: Basic support by [@Sambit003](https://github.com/Sambit003) fixing [#55](https://github.com/PHPOffice/PHPWord/issues/55) in [#2724](https://github.com/PHPOffice/PHPWord/pull/2724)
- Writer2007: Added support for background and border color transparency in Text Box element [@chudy20007](https://github.com/Chudy20007) in [#2555](https://github.com/PHPOffice/PHPWord/pull/2555)
- Writer Word2007: Added support for background and border color transparency in Text Box element by [@chudy20007](https://github.com/Chudy20007) in [#2555](https://github.com/PHPOffice/PHPWord/pull/2555)
- Writer/Reader Word2007: Added support for the firstLineChars for Indentation by [@liuzhilinux](https://github.com/liuzhilinux) & [@Progi1984](https://github.com/Progi1984) in [#2753](https://github.com/PHPOffice/PHPWord/pull/2753)

### Bug fixes

Expand All @@ -29,6 +30,7 @@
- Reader HTML: Support for inherit value for property line-height by [@Progi1984](https://github.com/Progi1984) fixing [#2683](https://github.com/PHPOffice/PHPWord/issues/2683) in [#2733](https://github.com/PHPOffice/PHPWord/pull/2733)
- Writer HTML: Fixed null string for Text Elements by [@armagedon007](https://github.com/armagedon007) and [@Progi1984](https://github.com/Progi1984) in [#2738](https://github.com/PHPOffice/PHPWord/pull/2738)
- Template Processor: Fix 0 considered as empty string by [@cavasinf](https://github.com/cavasinf), [@SnipsMine](https://github.com/SnipsMine) and [@Progi1984](https://github.com/Progi1984) fixing [#2572](https://github.com/PHPOffice/PHPWord/issues/2572), [#2703](https://github.com/PHPOffice/PHPWord/issues/2703) in [#2748](https://github.com/PHPOffice/PHPWord/pull/2748)
- Word2007 Writer : Corrected generating TOC to fix page number missing issues [@jgiacomello](https://github.com/jgiacomello) in [#2556](https://github.com/PHPOffice/PHPWord/pull/2556)

### Miscellaneous

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/styles/paragraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Available Paragraph style options:
- ``basedOn``. Parent style.
- ``hanging``. Hanging indentation in *half inches*.
- ``indent``. Indent (left indentation) in *half inches*.
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation.
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine*, *firstLineChars* and *hanging* indentation.
See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types.
- ``keepLines``. Keep all lines on one page, *true* or *false*.
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ protected function readParagraphStyle(XMLReader $xmlReader, DOMElement $domNode)
'indentRight' => [self::READ_VALUE, 'w:ind', 'w:right'],
'indentHanging' => [self::READ_VALUE, 'w:ind', 'w:hanging'],
'indentFirstLine' => [self::READ_VALUE, 'w:ind', 'w:firstLine'],
'indentFirstLineChars' => [self::READ_VALUE, 'w:ind', 'w:firstLineChars'],
'spaceAfter' => [self::READ_VALUE, 'w:spacing', 'w:after'],
'spaceBefore' => [self::READ_VALUE, 'w:spacing', 'w:before'],
'widowControl' => [self::READ_FALSE, 'w:widowControl'],
Expand Down
92 changes: 92 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ class Chart extends AbstractStyle
*/
private $gridX = false;

/**
* Min value for Y-Axis.
*
* @var null|float|int
*/
private $minY;

/**
* Max value for X-Axis.
*
* @var null|float|int
*/
private $minX;

/**
* Max value for Y-Axis.
*
* @var null|float|int
*/
private $maxY;

/**
* Max value for X-Axis.
*
* @var null|float|int
*/
private $maxX;

/**
* Create a new instance.
*
Expand Down Expand Up @@ -551,4 +579,68 @@ public function setShowGridX($value = true)

return $this;
}

/**
* @return null|float|int
*/
public function minY()
{
return $this->minY;
}

/**
* @param null|float|int $minY
*/
public function setMinY($minY): void
{
$this->minY = $minY;
}

/**
* @return null|float|int
*/
public function minX()
{
return $this->minX;
}

/**
* @param null|float|int $minX
*/
public function setMinX($minX): void
{
$this->minX = $minX;
}

/**
* @return null|float|int
*/
public function maxY()
{
return $this->maxY;
}

/**
* @param null|float|int $maxY
*/
public function setMaxY($maxY): void
{
$this->maxY = $maxY;
}

/**
* @return null|float|int
*/
public function maxX()
{
return $this->maxX;
}

/**
* @param null|float|int $maxX
*/
public function setMaxX($maxX): void
{
$this->maxX = $maxX;
}
}
25 changes: 25 additions & 0 deletions src/PhpWord/Style/Indentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Indentation extends AbstractStyle
*/
private $firstLine = 0;

/**
* Additional first line chars indentation (twip).
*
* @var int
*/
private $firstLineChars = 0;

/**
* Indentation removed from first line (twip).
*
Expand Down Expand Up @@ -118,6 +125,24 @@ public function setFirstLine(?float $value): self
return $this;
}

/**
* Get first line chars.
*/
public function getFirstLineChars(): int
{
return $this->firstLineChars;
}

/**
* Set first line chars.
*/
public function setFirstLineChars(int $value): self
{
$this->firstLineChars = $this->setIntVal($value, $this->firstLineChars);

return $this;
}

/**
* Get hanging.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/PhpWord/Style/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ public function setIndentFirstLine(?float $value = null): self
return $this->setIndentation(['firstLine' => $value]);
}

/**
* Set firstlineChars indentation.
*/
public function setIndentFirstLineChars(int $value = 0): self
{
return $this->setIndentation(['firstLineChars' => $value]);
}

/**
* Set left indentation.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Element/TOC.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, Title $ti
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:instrText');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->text("PAGEREF _Toc{$rId} \\h");
$xmlWriter->text("PAGEREF $rId \\h");
$xmlWriter->endElement();
$xmlWriter->endElement();

Expand Down
20 changes: 20 additions & 0 deletions src/PhpWord/Writer/Word2007/Part/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,26 @@ private function writeAxis(XMLWriter $xmlWriter, $type): void

$xmlWriter->startElement('c:scaling');
$xmlWriter->writeElementBlock('c:orientation', 'val', 'minMax');
if ($type == 'cat' && $style->minX()) {
$xmlWriter->startElement('c:min');
$xmlWriter->writeAttribute('val', $style->minX());
$xmlWriter->endElement();
}
if ($type == 'cat' && $style->maxX()) {
$xmlWriter->startElement('c:max');
$xmlWriter->writeAttribute('val', $style->maxX());
$xmlWriter->endElement();
}
if ($type == 'val' && $style->minY()) {
$xmlWriter->startElement('c:min');
$xmlWriter->writeAttribute('val', $style->minY());
$xmlWriter->endElement();
}
if ($type == 'val' && $style->maxY()) {
$xmlWriter->startElement('c:max');
$xmlWriter->writeAttribute('val', $style->maxY());
$xmlWriter->endElement();
}
$xmlWriter->endElement(); // c:scaling

$this->writeShape($xmlWriter, true);
Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Writer/Word2007/Style/Indentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function write(): void
$firstLine = $style->getFirstLine();
$xmlWriter->writeAttributeIf(null !== $firstLine, 'w:firstLine', $this->convertTwip($firstLine));

$firstLineChars = $style->getFirstLineChars();
$xmlWriter->writeAttributeIf(0 !== $firstLineChars, 'w:firstLineChars', $this->convertTwip($firstLineChars));

$hanging = $style->getHanging();
$xmlWriter->writeAttributeIf(null !== $hanging, 'w:hanging', $this->convertTwip($hanging));

Expand Down
16 changes: 14 additions & 2 deletions tests/PhpWordTests/Element/AbstractElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class AbstractElementTest extends \PHPUnit\Framework\TestCase
*/
public function testElementIndex(): void
{
$stub = $this->getMockForAbstractClass(AbstractElement::class);
if (method_exists($this, 'getMockForAbstractClass')) {
$stub = $this->getMockForAbstractClass(AbstractElement::class);
} else {
/** @var AbstractElement $stub */
$stub = new class() extends AbstractElement {
};
}
$ival = mt_rand(0, 100);
$stub->setElementIndex($ival);
self::assertEquals($ival, $stub->getElementIndex());
Expand All @@ -41,7 +47,13 @@ public function testElementIndex(): void
*/
public function testElementId(): void
{
$stub = $this->getMockForAbstractClass(AbstractElement::class);
if (method_exists($this, 'getMockForAbstractClass')) {
$stub = $this->getMockForAbstractClass(AbstractElement::class);
} else {
/** @var AbstractElement $stub */
$stub = new class() extends AbstractElement {
};
}
$stub->setElementId();
self::assertEquals(6, strlen($stub->getElementId()));
}
Expand Down
57 changes: 50 additions & 7 deletions tests/PhpWordTests/Reader/Word2007/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,14 @@ public function testPageVerticalAlign(): void
/**
* @dataProvider providerIndentation
*/
public function testIndentation(string $indent, float $left, float $right, ?float $hanging, float $firstLine): void
{
public function testIndentation(
string $indent,
float $left,
float $right,
?float $hanging,
float $firstLine,
int $firstLineChars
): void {
$documentXml = "<w:p>
<w:pPr>
$indent
Expand All @@ -359,16 +365,53 @@ public function testIndentation(string $indent, float $left, float $right, ?floa
self::assertSame($right, $indentation->getRight());
self::assertSame($hanging, $indentation->getHanging());
self::assertSame($firstLine, $indentation->getFirstLine());
self::assertSame($firstLineChars, $indentation->getFirstLineChars());
}

/**
* @return Generator<array{0:string, 1:float, 2:float, 3:null|float, 4: float}>
* @return Generator<array{0:string, 1:float, 2:float, 3:null|float, 4: float, 5: int}>
*/
public static function providerIndentation()
{
yield ['<w:ind w:left="709" w:right="488" w:hanging="10" w:firstLine="490"/>', 709.00, 488.00, 10.0, 490.00];
yield ['<w:ind w:hanging="10" w:firstLine="490"/>', 0, 0, 10.0, 490.00];
yield ['<w:ind w:left="709"/>', 709.00, 0, 0, 0];
yield ['<w:ind w:right="488"/>', 0, 488.00, 0, 0];
yield [
'<w:ind w:left="709" w:right="488" w:hanging="10" w:firstLine="490" w:firstLineChars="140"/>',
709.00,
488.00,
10.0,
490.00,
140,
];
yield [
'<w:ind w:left="709" w:right="488" w:hanging="10" w:firstLine="490"/>',
709.00,
488.00,
10.0,
490.00,
0,
];
yield [
'<w:ind w:hanging="10" w:firstLine="490"/>',
0,
0,
10.0,
490.00,
0,
];
yield [
'<w:ind w:left="709"/>',
709.00,
0,
0,
0,
0,
];
yield [
'<w:ind w:right="488"/>',
0,
488.00,
0,
0,
0,
];
}
}
Loading
Loading