123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- <?php
- /**
- * This file is part of PHPWord - A pure PHP library for reading and writing
- * word processing documents.
- *
- * PHPWord is free software distributed under the terms of the GNU Lesser
- * General Public License version 3 as published by the Free Software Foundation.
- *
- * For the full copyright and license information, please read the LICENSE
- * file that was distributed with this source code. For the full list of
- * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
- *
- * @see https://github.com/PHPOffice/PHPWord
- * @copyright 2010-2018 PHPWord contributors
- * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
- */
- namespace PhpOffice\PhpWord\Style;
- /**
- * Chart style
- *
- * @since 0.12.0
- */
- class Chart extends AbstractStyle
- {
- /**
- * Width (in EMU)
- *
- * @var int
- */
- private $width = 1000000;
- /**
- * Height (in EMU)
- *
- * @var int
- */
- private $height = 1000000;
- /**
- * Is 3D; applies to pie, bar, line, area
- *
- * @var bool
- */
- private $is3d = false;
- /**
- * A list of colors to use in the chart
- *
- * @var array
- */
- private $colors = array();
- /**
- * Chart title
- *
- * @var string
- */
- private $title = null;
- /**
- * Chart legend visibility
- *
- * @var bool
- */
- private $showLegend = false;
- /**
- * Chart legend Position.
- * Possible values are 'r', 't', 'b', 'l', 'tr'
- *
- * @var string
- */
- private $legendPosition = 'r';
- /**
- * A list of display options for data labels
- *
- * @var array
- */
- private $dataLabelOptions = array(
- 'showVal' => true, // value
- 'showCatName' => true, // category name
- 'showLegendKey' => false, //show the cart legend
- 'showSerName' => false, // series name
- 'showPercent' => false,
- 'showLeaderLines' => false,
- 'showBubbleSize' => false,
- );
- /**
- * A string that tells the writer where to write chart labels or to skip
- * "nextTo" - sets labels next to the axis (bar graphs on the left) (default)
- * "low" - labels on the left side of the graph
- * "high" - labels on the right side of the graph
- *
- * @var string
- */
- private $categoryLabelPosition = 'nextTo';
- /**
- * A string that tells the writer where to write chart labels or to skip
- * "nextTo" - sets labels next to the axis (bar graphs on the bottom) (default)
- * "low" - labels are below the graph
- * "high" - labels above the graph
- *
- * @var string
- */
- private $valueLabelPosition = 'nextTo';
- /**
- * @var string
- */
- private $categoryAxisTitle;
- /**
- * @var string
- */
- private $valueAxisTitle;
- /**
- * The position for major tick marks
- * Possible values are 'in', 'out', 'cross', 'none'
- *
- * @var string
- */
- private $majorTickMarkPos = 'none';
- /**
- * Show labels for axis
- *
- * @var bool
- */
- private $showAxisLabels = false;
- /**
- * Show Gridlines for Y-Axis
- *
- * @var bool
- */
- private $gridY = false;
- /**
- * Show Gridlines for X-Axis
- *
- * @var bool
- */
- private $gridX = false;
- /**
- * Create a new instance
- *
- * @param array $style
- */
- public function __construct($style = array())
- {
- $this->setStyleByArray($style);
- }
- /**
- * Get width
- *
- * @return int
- */
- public function getWidth()
- {
- return $this->width;
- }
- /**
- * Set width
- *
- * @param int $value
- * @return self
- */
- public function setWidth($value = null)
- {
- $this->width = $this->setIntVal($value, $this->width);
- return $this;
- }
- /**
- * Get height
- *
- * @return int
- */
- public function getHeight()
- {
- return $this->height;
- }
- /**
- * Set height
- *
- * @param int $value
- * @return self
- */
- public function setHeight($value = null)
- {
- $this->height = $this->setIntVal($value, $this->height);
- return $this;
- }
- /**
- * Is 3D
- *
- * @return bool
- */
- public function is3d()
- {
- return $this->is3d;
- }
- /**
- * Set 3D
- *
- * @param bool $value
- * @return self
- */
- public function set3d($value = true)
- {
- $this->is3d = $this->setBoolVal($value, $this->is3d);
- return $this;
- }
- /**
- * Get the list of colors to use in a chart.
- *
- * @return array
- */
- public function getColors()
- {
- return $this->colors;
- }
- /**
- * Set the colors to use in a chart.
- *
- * @param array $value a list of colors to use in the chart
- * @return self
- */
- public function setColors($value = array())
- {
- $this->colors = $value;
- return $this;
- }
- /**
- * Get the chart title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * Set the chart title
- *
- * @param string $value
- * @return self
- */
- public function setTitle($value = null)
- {
- $this->title = $value;
- return $this;
- }
- /**
- * Get chart legend visibility
- *
- * @return bool
- */
- public function isShowLegend()
- {
- return $this->showLegend;
- }
- /**
- * Set chart legend visibility
- *
- * @param bool $value
- * @return self
- */
- public function setShowLegend($value = false)
- {
- $this->showLegend = $value;
- return $this;
- }
- /**
- * Get chart legend position
- *
- * @return string
- */
- public function getLegendPosition()
- {
- return $this->legendPosition;
- }
- /**
- * Set chart legend position. choices:
- * "r" - right of chart
- * "b" - bottom of chart
- * "t" - top of chart
- * "l" - left of chart
- * "tr" - top right of chart
- *
- * default: right
- *
- * @param string $legendPosition
- * @return self
- */
- public function setLegendPosition($legendPosition = 'r')
- {
- $enum = array('r', 'b', 't', 'l', 'tr');
- $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition);
- return $this;
- }
- /*
- * Show labels for axis
- *
- * @return bool
- */
- public function showAxisLabels()
- {
- return $this->showAxisLabels;
- }
- /**
- * Set show Gridlines for Y-Axis
- *
- * @param bool $value
- * @return self
- */
- public function setShowAxisLabels($value = true)
- {
- $this->showAxisLabels = $this->setBoolVal($value, $this->showAxisLabels);
- return $this;
- }
- /**
- * get the list of options for data labels
- *
- * @return array
- */
- public function getDataLabelOptions()
- {
- return $this->dataLabelOptions;
- }
- /**
- * Set values for data label options.
- * This will only change values for options defined in $this->dataLabelOptions, and cannot create new ones.
- *
- * @param array $values [description]
- */
- public function setDataLabelOptions($values = array())
- {
- foreach (array_keys($this->dataLabelOptions) as $option) {
- if (isset($values[$option])) {
- $this->dataLabelOptions[$option] = $this->setBoolVal(
- $values[$option],
- $this->dataLabelOptions[$option]
- );
- }
- }
- }
- /*
- * Show Gridlines for Y-Axis
- *
- * @return bool
- */
- public function showGridY()
- {
- return $this->gridY;
- }
- /**
- * Set show Gridlines for Y-Axis
- *
- * @param bool $value
- * @return self
- */
- public function setShowGridY($value = true)
- {
- $this->gridY = $this->setBoolVal($value, $this->gridY);
- return $this;
- }
- /**
- * Get the categoryLabelPosition setting
- *
- * @return string
- */
- public function getCategoryLabelPosition()
- {
- return $this->categoryLabelPosition;
- }
- /**
- * Set the categoryLabelPosition setting
- * "none" - skips writing labels
- * "nextTo" - sets labels next to the (bar graphs on the left)
- * "low" - labels on the left side of the graph
- * "high" - labels on the right side of the graph
- *
- * @param mixed $labelPosition
- * @return self
- */
- public function setCategoryLabelPosition($labelPosition)
- {
- $enum = array('nextTo', 'low', 'high');
- $this->categoryLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->categoryLabelPosition);
- return $this;
- }
- /**
- * Get the valueAxisLabelPosition setting
- *
- * @return string
- */
- public function getValueLabelPosition()
- {
- return $this->valueLabelPosition;
- }
- /**
- * Set the valueLabelPosition setting
- * "none" - skips writing labels
- * "nextTo" - sets labels next to the value
- * "low" - sets labels are below the graph
- * "high" - sets labels above the graph
- *
- * @param string
- * @param mixed $labelPosition
- */
- public function setValueLabelPosition($labelPosition)
- {
- $enum = array('nextTo', 'low', 'high');
- $this->valueLabelPosition = $this->setEnumVal($labelPosition, $enum, $this->valueLabelPosition);
- return $this;
- }
- /**
- * Get the categoryAxisTitle
- * @return string
- */
- public function getCategoryAxisTitle()
- {
- return $this->categoryAxisTitle;
- }
- /**
- * Set the title that appears on the category side of the chart
- * @param string $axisTitle
- */
- public function setCategoryAxisTitle($axisTitle)
- {
- $this->categoryAxisTitle = $axisTitle;
- return $this;
- }
- /**
- * Get the valueAxisTitle
- * @return string
- */
- public function getValueAxisTitle()
- {
- return $this->valueAxisTitle;
- }
- /**
- * Set the title that appears on the value side of the chart
- * @param string $axisTitle
- */
- public function setValueAxisTitle($axisTitle)
- {
- $this->valueAxisTitle = $axisTitle;
- return $this;
- }
- public function getMajorTickPosition()
- {
- return $this->majorTickMarkPos;
- }
- /**
- * Set the position for major tick marks
- * @param string $position
- */
- public function setMajorTickPosition($position)
- {
- $enum = array('in', 'out', 'cross', 'none');
- $this->majorTickMarkPos = $this->setEnumVal($position, $enum, $this->majorTickMarkPos);
- }
- /**
- * Show Gridlines for X-Axis
- *
- * @return bool
- */
- public function showGridX()
- {
- return $this->gridX;
- }
- /**
- * Set show Gridlines for X-Axis
- *
- * @param bool $value
- * @return self
- */
- public function setShowGridX($value = true)
- {
- $this->gridX = $this->setBoolVal($value, $this->gridX);
- return $this;
- }
- }
|