PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/application/third_party/PHPExcel/Chart.php

https://bitbucket.org/matyhaty/senses-designertravelv3
PHP | 527 lines | 202 code | 84 blank | 241 comment | 13 complexity | 36577a1bad7120adf1fe0f0245a9d8ab MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.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 ##VERSION##, ##DATE##
  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. * Set Title
  177. *
  178. * @param PHPExcel_Chart_Title $title
  179. * @return PHPExcel_Chart
  180. */
  181. public function setTitle(PHPExcel_Chart_Title $title) {
  182. $this->_title = $title;
  183. return $this;
  184. }
  185. /**
  186. * Get Legend
  187. *
  188. * @return PHPExcel_Chart_Legend
  189. */
  190. public function getLegend() {
  191. return $this->_legend;
  192. }
  193. /**
  194. * Set Legend
  195. *
  196. * @param PHPExcel_Chart_Legend $legend
  197. * @return PHPExcel_Chart
  198. */
  199. public function setLegend(PHPExcel_Chart_Legend $legend) {
  200. $this->_legend = $legend;
  201. return $this;
  202. }
  203. /**
  204. * Get X-Axis Label
  205. *
  206. * @return PHPExcel_Chart_Title
  207. */
  208. public function getXAxisLabel() {
  209. return $this->_xAxisLabel;
  210. }
  211. /**
  212. * Set X-Axis Label
  213. *
  214. * @param PHPExcel_Chart_Title $label
  215. * @return PHPExcel_Chart
  216. */
  217. public function setXAxisLabel(PHPExcel_Chart_Title $label) {
  218. $this->_xAxisLabel = $label;
  219. return $this;
  220. }
  221. /**
  222. * Get Y-Axis Label
  223. *
  224. * @return PHPExcel_Chart_Title
  225. */
  226. public function getYAxisLabel() {
  227. return $this->_yAxisLabel;
  228. }
  229. /**
  230. * Set Y-Axis Label
  231. *
  232. * @param PHPExcel_Chart_Title $label
  233. * @return PHPExcel_Chart
  234. */
  235. public function setYAxisLabel(PHPExcel_Chart_Title $label) {
  236. $this->_yAxisLabel = $label;
  237. return $this;
  238. }
  239. /**
  240. * Get Plot Area
  241. *
  242. * @return PHPExcel_Chart_PlotArea
  243. */
  244. public function getPlotArea() {
  245. return $this->_plotArea;
  246. }
  247. /**
  248. * Get Plot Visible Only
  249. *
  250. * @return boolean
  251. */
  252. public function getPlotVisibleOnly() {
  253. return $this->_plotVisibleOnly;
  254. }
  255. /**
  256. * Set Plot Visible Only
  257. *
  258. * @param boolean $plotVisibleOnly
  259. * @return PHPExcel_Chart
  260. */
  261. public function setPlotVisibleOnly($plotVisibleOnly = true) {
  262. $this->_plotVisibleOnly = $plotVisibleOnly;
  263. return $this;
  264. }
  265. /**
  266. * Get Display Blanks as
  267. *
  268. * @return string
  269. */
  270. public function getDisplayBlanksAs() {
  271. return $this->_displayBlanksAs;
  272. }
  273. /**
  274. * Set Display Blanks as
  275. *
  276. * @param string $displayBlanksAs
  277. * @return PHPExcel_Chart
  278. */
  279. public function setDisplayBlanksAs($displayBlanksAs = '0') {
  280. $this->_displayBlanksAs = $displayBlanksAs;
  281. }
  282. /**
  283. * Set the Top Left position for the chart
  284. *
  285. * @param string $cell
  286. * @param integer $xOffset
  287. * @param integer $yOffset
  288. * @return PHPExcel_Chart
  289. */
  290. public function setTopLeftPosition($cell, $xOffset=null, $yOffset=null) {
  291. $this->_topLeftCellRef = $cell;
  292. if (!is_null($xOffset))
  293. $this->setTopLeftXOffset($xOffset);
  294. if (!is_null($yOffset))
  295. $this->setTopLeftYOffset($yOffset);
  296. return $this;
  297. }
  298. /**
  299. * Get the top left position of the chart
  300. *
  301. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  302. */
  303. public function getTopLeftPosition() {
  304. return array( 'cell' => $this->_topLeftCellRef,
  305. 'xOffset' => $this->_topLeftXOffset,
  306. 'yOffset' => $this->_topLeftYOffset
  307. );
  308. }
  309. /**
  310. * Get the cell address where the top left of the chart is fixed
  311. *
  312. * @return string
  313. */
  314. public function getTopLeftCell() {
  315. return $this->_topLeftCellRef;
  316. }
  317. /**
  318. * Set the Top Left cell position for the chart
  319. *
  320. * @param string $cell
  321. * @return PHPExcel_Chart
  322. */
  323. public function setTopLeftCell($cell) {
  324. $this->_topLeftCellRef = $cell;
  325. return $this;
  326. }
  327. public function setTopLeftOffset($xOffset=null,$yOffset=null) {
  328. if (!is_null($xOffset))
  329. $this->setTopLeftXOffset($xOffset);
  330. if (!is_null($yOffset))
  331. $this->setTopLeftYOffset($yOffset);
  332. return $this;
  333. }
  334. public function getTopLeftOffset() {
  335. return array( 'X' => $this->_topLeftXOffset,
  336. 'Y' => $this->_topLeftYOffset
  337. );
  338. }
  339. public function setTopLeftXOffset($xOffset) {
  340. $this->_topLeftXOffset = $xOffset;
  341. return $this;
  342. }
  343. public function getTopLeftXOffset() {
  344. return $this->_topLeftXOffset;
  345. }
  346. public function setTopLeftYOffset($yOffset) {
  347. $this->_topLeftYOffset = $yOffset;
  348. return $this;
  349. }
  350. public function getTopLeftYOffset() {
  351. return $this->_topLeftYOffset;
  352. }
  353. /**
  354. * Set the Bottom Right position of the chart
  355. *
  356. * @param string $cell
  357. * @param integer $xOffset
  358. * @param integer $yOffset
  359. * @return PHPExcel_Chart
  360. */
  361. public function setBottomRightPosition($cell, $xOffset=null, $yOffset=null) {
  362. $this->_bottomRightCellRef = $cell;
  363. if (!is_null($xOffset))
  364. $this->setBottomRightXOffset($xOffset);
  365. if (!is_null($yOffset))
  366. $this->setBottomRightYOffset($yOffset);
  367. return $this;
  368. }
  369. /**
  370. * Get the bottom right position of the chart
  371. *
  372. * @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell
  373. */
  374. public function getBottomRightPosition() {
  375. return array( 'cell' => $this->_bottomRightCellRef,
  376. 'xOffset' => $this->_bottomRightXOffset,
  377. 'yOffset' => $this->_bottomRightYOffset
  378. );
  379. }
  380. public function setBottomRightCell($cell) {
  381. $this->_bottomRightCellRef = $cell;
  382. return $this;
  383. }
  384. /**
  385. * Get the cell address where the bottom right of the chart is fixed
  386. *
  387. * @return string
  388. */
  389. public function getBottomRightCell() {
  390. return $this->_bottomRightCellRef;
  391. }
  392. public function setBottomRightOffset($xOffset=null,$yOffset=null) {
  393. if (!is_null($xOffset))
  394. $this->setBottomRightXOffset($xOffset);
  395. if (!is_null($yOffset))
  396. $this->setBottomRightYOffset($yOffset);
  397. return $this;
  398. }
  399. public function getBottomRightOffset() {
  400. return array( 'X' => $this->_bottomRightXOffset,
  401. 'Y' => $this->_bottomRightYOffset
  402. );
  403. }
  404. public function setBottomRightXOffset($xOffset) {
  405. $this->_bottomRightXOffset = $xOffset;
  406. return $this;
  407. }
  408. public function getBottomRightXOffset() {
  409. return $this->_bottomRightXOffset;
  410. }
  411. public function setBottomRightYOffset($yOffset) {
  412. $this->_bottomRightYOffset = $yOffset;
  413. return $this;
  414. }
  415. public function getBottomRightYOffset() {
  416. return $this->_bottomRightYOffset;
  417. }
  418. public function refresh() {
  419. if ($this->_worksheet !== NULL) {
  420. $this->_plotArea->refresh($this->_worksheet);
  421. }
  422. }
  423. public function render($outputDestination = null) {
  424. $libraryName = PHPExcel_Settings::getChartRendererName();
  425. if (is_null($libraryName)) {
  426. return false;
  427. }
  428. // Ensure that data series values are up-to-date before we render
  429. $this->refresh();
  430. $libraryPath = PHPExcel_Settings::getChartRendererPath();
  431. $includePath = str_replace('\\','/',get_include_path());
  432. $rendererPath = str_replace('\\','/',$libraryPath);
  433. if (strpos($rendererPath,$includePath) === false) {
  434. set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath);
  435. }
  436. $rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName;
  437. $renderer = new $rendererName($this);
  438. if ($outputDestination == 'php://output') {
  439. $outputDestination = null;
  440. }
  441. return $renderer->render($outputDestination);
  442. }
  443. }