PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/include/PHPExcel/Chart.php

https://bitbucket.org/sleininger/stock_online
PHP | 479 lines | 186 code | 76 blank | 217 comment | 13 complexity | 2d98e1ce64f2bc1cbf1d6f815e44b139 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2012 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Chart
  23. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.7, 2012-05-19
  26. */
  27. /**
  28. * PHPExcel_Chart
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Chart
  32. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Chart
  35. {
  36. /**
  37. * Chart Name
  38. *
  39. * @var string
  40. */
  41. private $_name = '';
  42. /**
  43. * Worksheet
  44. *
  45. * @var PHPExcel_Worksheet
  46. */
  47. private $_worksheet = null;
  48. /**
  49. * Chart Title
  50. *
  51. * @var PHPExcel_Chart_Title
  52. */
  53. private $_title = null;
  54. /**
  55. * Chart Legend
  56. *
  57. * @var PHPExcel_Chart_Legend
  58. */
  59. private $_legend = null;
  60. /**
  61. * X-Axis Label
  62. *
  63. * @var PHPExcel_Chart_Title
  64. */
  65. private $_xAxisLabel = null;
  66. /**
  67. * Y-Axis Label
  68. *
  69. * @var PHPExcel_Chart_Title
  70. */
  71. private $_yAxisLabel = null;
  72. /**
  73. * Chart Plot Area
  74. *
  75. * @var PHPExcel_Chart_PlotArea
  76. */
  77. private $_plotArea = null;
  78. /**
  79. * Plot Visible Only
  80. *
  81. * @var boolean
  82. */
  83. private $_plotVisibleOnly = true;
  84. /**
  85. * Display Blanks as
  86. *
  87. * @var string
  88. */
  89. private $_displayBlanksAs = '0';
  90. /**
  91. * Top-Left Cell Position
  92. *
  93. * @var string
  94. */
  95. private $_topLeftCellRef = 'A1';
  96. /**
  97. * Top-Left X-Offset
  98. *
  99. * @var integer
  100. */
  101. private $_topLeftXOffset = 0;
  102. /**
  103. * Top-Left Y-Offset
  104. *
  105. * @var integer
  106. */
  107. private $_topLeftYOffset = 0;
  108. /**
  109. * Bottom-Right Cell Position
  110. *
  111. * @var string
  112. */
  113. private $_bottomRightCellRef = 'A1';
  114. /**
  115. * Bottom-Right X-Offset
  116. *
  117. * @var integer
  118. */
  119. private $_bottomRightXOffset = 10;
  120. /**
  121. * Bottom-Right Y-Offset
  122. *
  123. * @var integer
  124. */
  125. private $_bottomRightYOffset = 10;
  126. /**
  127. * Create a new PHPExcel_Chart
  128. */
  129. public function __construct($name, PHPExcel_Chart_Title $title = null, PHPExcel_Chart_Legend $legend = null, PHPExcel_Chart_PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', PHPExcel_Chart_Title $xAxisLabel = null, PHPExcel_Chart_Title $yAxisLabel = null)
  130. {
  131. $this->_name = $name;
  132. $this->_title = $title;
  133. $this->_legend = $legend;
  134. $this->_xAxisLabel = $xAxisLabel;
  135. $this->_yAxisLabel = $yAxisLabel;
  136. $this->_plotArea = $plotArea;
  137. $this->_plotVisibleOnly = $plotVisibleOnly;
  138. $this->_displayBlanksAs = $displayBlanksAs;
  139. }
  140. /**
  141. * Get Name
  142. *
  143. * @return string
  144. */
  145. public function getName() {
  146. return $this->_name;
  147. }
  148. /**
  149. * Get Worksheet
  150. *
  151. * @return PHPExcel_Worksheet
  152. */
  153. public function getWorksheet() {
  154. return $this->_worksheet;
  155. }
  156. /**
  157. * Set Worksheet
  158. *
  159. * @param PHPExcel_Worksheet $pValue
  160. * @throws Exception
  161. * @return PHPExcel_Chart
  162. */
  163. public function setWorksheet(PHPExcel_Worksheet $pValue = null) {
  164. $this->_worksheet = $pValue;
  165. return $this;
  166. }
  167. /**
  168. * Get Title
  169. *
  170. * @return PHPExcel_Chart_Title
  171. */
  172. public function getTitle() {
  173. return $this->_title;
  174. }
  175. /**
  176. * Get Legend
  177. *
  178. * @return PHPExcel_Chart_Legend
  179. */
  180. public function getLegend() {
  181. return $this->_legend;
  182. }
  183. /**
  184. * Get X-Axis Label
  185. *
  186. * @return PHPExcel_Chart_Title
  187. */
  188. public function getXAxisLabel() {
  189. return $this->_xAxisLabel;
  190. }
  191. /**
  192. * Get Y-Axis Label
  193. *
  194. * @return PHPExcel_Chart_Title
  195. */
  196. public function getYAxisLabel() {
  197. return $this->_yAxisLabel;
  198. }
  199. /**
  200. * Get Plot Area
  201. *
  202. * @return PHPExcel_Chart_PlotArea
  203. */
  204. public function getPlotArea() {
  205. return $this->_plotArea;
  206. }
  207. /**
  208. * Get Plot Visible Only
  209. *
  210. * @return boolean
  211. */
  212. public function getPlotVisibleOnly() {
  213. return $this->_plotVisibleOnly;
  214. }
  215. /**
  216. * Set Plot Visible Only
  217. *
  218. * @param boolean $plotVisibleOnly
  219. * @return PHPExcel_Chart
  220. */
  221. public function setPlotVisibleOnly($plotVisibleOnly = true) {
  222. $this->_plotVisibleOnly = $plotVisibleOnly;
  223. return $this;
  224. }
  225. /**
  226. * Get Display Blanks as
  227. *
  228. * @return string
  229. */
  230. public function getDisplayBlanksAs() {
  231. return $this->_displayBlanksAs;
  232. }
  233. /**
  234. * Set Display Blanks as
  235. *
  236. * @param string $displayBlanksAs
  237. * @return PHPExcel_Chart
  238. */
  239. public function setDisplayBlanksAs($displayBlanksAs = '0') {
  240. $this->_displayBlanksAs = $displayBlanksAs;
  241. }
  242. /**
  243. * Set the Top Left position for the chart
  244. *
  245. * @param string $cell
  246. * @param integer $xOffset
  247. * @param integer $yOffset
  248. * @return PHPExcel_Chart
  249. */
  250. public function setTopLeftPosition($cell, $xOffset=null, $yOffset=null) {
  251. $this->_topLeftCellRef = $cell;
  252. if (!is_null($xOffset))
  253. $this->setTopLeftXOffset($xOffset);
  254. if (!is_null($yOffset))
  255. $this->setTopLeftYOffset($yOffset);
  256. return $this;
  257. }
  258. /**
  259. * Get the top left position of the chart
  260. *
  261. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  262. */
  263. public function getTopLeftPosition() {
  264. return array( 'cell' => $this->_topLeftCellRef,
  265. 'xOffset' => $this->_topLeftXOffset,
  266. 'yOffset' => $this->_topLeftYOffset
  267. );
  268. }
  269. /**
  270. * Get the cell address where the top left of the chart is fixed
  271. *
  272. * @return string
  273. */
  274. public function getTopLeftCell() {
  275. return $this->_topLeftCellRef;
  276. }
  277. /**
  278. * Set the Top Left cell position for the chart
  279. *
  280. * @param string $cell
  281. * @return PHPExcel_Chart
  282. */
  283. public function setTopLeftCell($cell) {
  284. $this->_topLeftCellRef = $cell;
  285. return $this;
  286. }
  287. public function setTopLeftOffset($xOffset=null,$yOffset=null) {
  288. if (!is_null($xOffset))
  289. $this->setTopLeftXOffset($xOffset);
  290. if (!is_null($yOffset))
  291. $this->setTopLeftYOffset($yOffset);
  292. return $this;
  293. }
  294. public function getTopLeftOffset() {
  295. return array( 'X' => $this->_topLeftXOffset,
  296. 'Y' => $this->_topLeftYOffset
  297. );
  298. }
  299. public function setTopLeftXOffset($xOffset) {
  300. $this->_topLeftXOffset = $xOffset;
  301. return $this;
  302. }
  303. public function getTopLeftXOffset() {
  304. return $this->_topLeftXOffset;
  305. }
  306. public function setTopLeftYOffset($yOffset) {
  307. $this->_topLeftYOffset = $yOffset;
  308. return $this;
  309. }
  310. public function getTopLeftYOffset() {
  311. return $this->_topLeftYOffset;
  312. }
  313. /**
  314. * Set the Bottom Right position of the chart
  315. *
  316. * @param string $cell
  317. * @param integer $xOffset
  318. * @param integer $yOffset
  319. * @return PHPExcel_Chart
  320. */
  321. public function setBottomRightPosition($cell, $xOffset=null, $yOffset=null) {
  322. $this->_bottomRightCellRef = $cell;
  323. if (!is_null($xOffset))
  324. $this->setBottomRightXOffset($xOffset);
  325. if (!is_null($yOffset))
  326. $this->setBottomRightYOffset($yOffset);
  327. return $this;
  328. }
  329. /**
  330. * Get the bottom right position of the chart
  331. *
  332. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  333. */
  334. public function getBottomRightPosition() {
  335. return array( 'cell' => $this->_bottomRightCellRef,
  336. 'xOffset' => $this->_bottomRightXOffset,
  337. 'yOffset' => $this->_bottomRightYOffset
  338. );
  339. }
  340. public function setBottomRightCell($cell) {
  341. $this->_bottomRightCellRef = $cell;
  342. return $this;
  343. }
  344. /**
  345. * Get the cell address where the bottom right of the chart is fixed
  346. *
  347. * @return string
  348. */
  349. public function getBottomRightCell() {
  350. return $this->_bottomRightCellRef;
  351. }
  352. public function setBottomRightOffset($xOffset=null,$yOffset=null) {
  353. if (!is_null($xOffset))
  354. $this->setBottomRightXOffset($xOffset);
  355. if (!is_null($yOffset))
  356. $this->setBottomRightYOffset($yOffset);
  357. return $this;
  358. }
  359. public function getBottomRightOffset() {
  360. return array( 'X' => $this->_bottomRightXOffset,
  361. 'Y' => $this->_bottomRightYOffset
  362. );
  363. }
  364. public function setBottomRightXOffset($xOffset) {
  365. $this->_bottomRightXOffset = $xOffset;
  366. return $this;
  367. }
  368. public function getBottomRightXOffset() {
  369. return $this->_bottomRightXOffset;
  370. }
  371. public function setBottomRightYOffset($yOffset) {
  372. $this->_bottomRightYOffset = $yOffset;
  373. return $this;
  374. }
  375. public function getBottomRightYOffset() {
  376. return $this->_bottomRightYOffset;
  377. }
  378. public function refresh() {
  379. if ($this->_worksheet !== NULL) {
  380. $this->_plotArea->refresh($this->_worksheet);
  381. }
  382. }
  383. public function render($outputDestination = null) {
  384. $libraryName = PHPExcel_Settings::getChartRendererName();
  385. if (is_null($libraryName)) {
  386. return false;
  387. }
  388. // Ensure that data series values are up-to-date before we render
  389. $this->refresh();
  390. $libraryPath = PHPExcel_Settings::getChartRendererPath();
  391. $includePath = str_replace('\\','/',get_include_path());
  392. $rendererPath = str_replace('\\','/',$libraryPath);
  393. if (strpos($rendererPath,$includePath) === false) {
  394. set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath);
  395. }
  396. $rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName;
  397. $renderer = new $rendererName($this);
  398. if ($outputDestination == 'php://output') {
  399. $outputDestination = null;
  400. }
  401. return $renderer->render($outputDestination);
  402. }
  403. }