/vendor/rad-mira-labs/laravel-highcharts/src/Aivo/Highchart/Series/AbstractSeries.php

https://gitlab.com/dzakiafif/cokelatklasik · PHP · 591 lines · 263 code · 98 blank · 230 comment · 27 complexity · 1a244f500bd9095e1dc74285ddf34055 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the PHP Highcharts library.
  4. *
  5. * (c) University of Cambridge
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Aivo\Highchart\Series;
  11. use Aivo\Highchart\Axis\XAxisInterface;
  12. use Aivo\Highchart\Axis\YAxisInterface;
  13. use Aivo\Highchart\DataPoint\DataPoint;
  14. use Aivo\Highchart\DataPoint\DataPointInterface;
  15. use Aivo\Highchart\Exception\InvalidArgumentException;
  16. use Aivo\Highchart\Series\Animation\Animation;
  17. use Aivo\Highchart\Series\Animation\AnimationInterface;
  18. use Aivo\Highchart\Series\Marker\Marker;
  19. use Aivo\Highchart\Series\Marker\MarkerInterface;
  20. use Aivo\Highchart\Series\State\HoverState;
  21. use Aivo\Highchart\Series\State\HoverStateInterface;
  22. use Zend\Json\Expr;
  23. /**
  24. * Abstract chart series.
  25. *
  26. * @author Chris Wilkinson <chris.wilkinson@admin.cam.ac.uk>
  27. */
  28. abstract class AbstractSeries implements SeriesInterface
  29. {
  30. /**
  31. * Constructor.
  32. */
  33. public function __construct()
  34. {
  35. $this->marker = new Marker($this);
  36. $this->animation = new Animation($this);
  37. }
  38. /**
  39. * Name.
  40. *
  41. * @var string|null
  42. */
  43. protected $name;
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getName()
  48. {
  49. return $this->name;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function setName($name)
  55. {
  56. $this->name = $name;
  57. return $this;
  58. }
  59. /**
  60. * Color.
  61. *
  62. * @var string
  63. */
  64. protected $color;
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function getColor()
  69. {
  70. return $this->color;
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function setColor($color)
  76. {
  77. $this->color = $color;
  78. return $this;
  79. }
  80. /**
  81. * Data points.
  82. *
  83. * @var DataPointInterface[]
  84. */
  85. protected $dataPoints = array();
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function getDataPoints()
  90. {
  91. return $this->dataPoints;
  92. }
  93. /**
  94. * {@inheritdoc}
  95. */
  96. public function addDataPoint(DataPointInterface $dataPoint)
  97. {
  98. $this->dataPoints[] = $dataPoint;
  99. return $this;
  100. }
  101. /**
  102. * {@inheritdoc}
  103. */
  104. public function addData(array $data)
  105. {
  106. if (null !== $this->xAxis) {
  107. $categories = array_keys($this->xAxis->getCategories());
  108. } else {
  109. $categories = array();
  110. }
  111. foreach ($data as $category => $datum) {
  112. $dataPoint = new DataPoint();
  113. if (false !== $position = array_search($category, $categories)) {
  114. $dataPoint->setXValue($position);
  115. }
  116. $dataPoint->setYValue($datum);
  117. $this->addDataPoint($dataPoint);
  118. }
  119. return $this;
  120. }
  121. /**
  122. * X-axis.
  123. *
  124. * @var XAxisInterface|null
  125. */
  126. protected $xAxis;
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function getXAxis()
  131. {
  132. return $this->xAxis;
  133. }
  134. /**
  135. * {@inheritdoc}
  136. */
  137. public function setXAxis($xAxis)
  138. {
  139. if (false === $xAxis instanceof XAxisInterface && false === is_null($xAxis)) {
  140. throw new InvalidArgumentException();
  141. }
  142. $this->xAxis = $xAxis;
  143. return $this;
  144. }
  145. /**
  146. * Y-axis.
  147. *
  148. * @var YAxisInterface|null
  149. */
  150. protected $yAxis;
  151. /**
  152. * {@inheritdoc}
  153. */
  154. public function getYAxis()
  155. {
  156. return $this->yAxis;
  157. }
  158. /**
  159. * {@inheritdoc}
  160. */
  161. public function setYAxis($yAxis)
  162. {
  163. if (false === $yAxis instanceof YAxisInterface && false === is_null($yAxis)) {
  164. throw new InvalidArgumentException();
  165. }
  166. $this->yAxis = $yAxis;
  167. return $this;
  168. }
  169. /**
  170. * Labels formatter.
  171. *
  172. * @var Expr|null
  173. */
  174. protected $labelsFormatter;
  175. /**
  176. * {@inheritdoc}
  177. */
  178. public function getLabelsFormatter()
  179. {
  180. return $this->labelsFormatter;
  181. }
  182. /**
  183. * {@inheritdoc}
  184. */
  185. public function setLabelsFormatter($labelsFormatter)
  186. {
  187. if (false === $labelsFormatter instanceof Expr && false === is_null($labelsFormatter)) {
  188. throw new InvalidArgumentException();
  189. }
  190. $this->labelsFormatter = $labelsFormatter;
  191. return $this;
  192. }
  193. /**
  194. * Marker.
  195. *
  196. * @var MarkerInterface
  197. */
  198. protected $marker;
  199. /**
  200. * {@inheritdoc}
  201. */
  202. public function getMarker()
  203. {
  204. return $this->marker;
  205. }
  206. /**
  207. * Is enable mouse tracking.
  208. *
  209. * @var bool
  210. */
  211. protected $enableMouseTracking = true;
  212. /**
  213. * {@inheritdoc}
  214. */
  215. public function isEnableMouseTracking()
  216. {
  217. return $this->enableMouseTracking;
  218. }
  219. /**
  220. * {@inheritdoc}
  221. */
  222. public function setEnableMouseTracking($enableMouseTracking = true)
  223. {
  224. if (false === is_bool($enableMouseTracking)) {
  225. throw new InvalidArgumentException();
  226. }
  227. $this->enableMouseTracking = $enableMouseTracking;
  228. return $this;
  229. }
  230. /**
  231. * Cursor.
  232. *
  233. * @var string|null
  234. */
  235. protected $cursor;
  236. /**
  237. * {@inheritdoc}
  238. */
  239. public function getCursor()
  240. {
  241. return $this->cursor;
  242. }
  243. /**
  244. * {@inheritdoc}
  245. */
  246. public function setCursor($cursor)
  247. {
  248. $this->cursor = $cursor;
  249. return $this;
  250. }
  251. /**
  252. * Weight.
  253. *
  254. * @var int
  255. */
  256. protected $weight = 0;
  257. /**
  258. * {@inheritdoc}
  259. */
  260. public function getWeight()
  261. {
  262. return $this->weight;
  263. }
  264. /**
  265. * {@inheritdoc}
  266. */
  267. public function setWeight($weight)
  268. {
  269. if (false === is_int($weight) && false === is_float($weight)) {
  270. throw new InvalidArgumentException();
  271. }
  272. $this->weight = $weight;
  273. return $this;
  274. }
  275. /**
  276. * Checkbox click event.
  277. *
  278. * @var Expr|null
  279. */
  280. protected $checkboxClickEvent;
  281. /**
  282. * {@inheritdoc}
  283. */
  284. public function getCheckboxClickEvent()
  285. {
  286. return $this->checkboxClickEvent;
  287. }
  288. /**
  289. * {@inheritdoc}
  290. */
  291. public function setCheckboxClickEvent($event)
  292. {
  293. if (false === $event instanceof Expr && false === is_null($event)) {
  294. throw new InvalidArgumentException();
  295. }
  296. $this->checkboxClickEvent = $event;
  297. return $this;
  298. }
  299. /**
  300. * Click event.
  301. *
  302. * @var Expr|null
  303. */
  304. protected $clickEvent;
  305. /**
  306. * {@inheritdoc}
  307. */
  308. public function getClickEvent()
  309. {
  310. return $this->clickEvent;
  311. }
  312. /**
  313. * {@inheritdoc}
  314. */
  315. public function setClickEvent($event)
  316. {
  317. if (false === $event instanceof Expr && false === is_null($event)) {
  318. throw new InvalidArgumentException();
  319. }
  320. $this->clickEvent = $event;
  321. return $this;
  322. }
  323. /**
  324. * event.
  325. *
  326. * @var Expr|null
  327. */
  328. protected $hideEvent;
  329. /**
  330. * {@inheritdoc}
  331. */
  332. public function getHideEvent()
  333. {
  334. return $this->hideEvent;
  335. }
  336. /**
  337. * {@inheritdoc}
  338. */
  339. public function setHideEvent($event)
  340. {
  341. if (false === $event instanceof Expr && false === is_null($event)) {
  342. throw new InvalidArgumentException();
  343. }
  344. $this->hideEvent = $event;
  345. return $this;
  346. }
  347. /**
  348. * event.
  349. *
  350. * @var Expr|null
  351. */
  352. protected $legendItemClickEvent;
  353. /**
  354. * {@inheritdoc}
  355. */
  356. public function getLegendItemClickEvent()
  357. {
  358. return $this->legendItemClickEvent;
  359. }
  360. /**
  361. * {@inheritdoc}
  362. */
  363. public function setLegendItemClickEvent($event)
  364. {
  365. if (false === $event instanceof Expr && false === is_null($event)) {
  366. throw new InvalidArgumentException();
  367. }
  368. $this->legendItemClickEvent = $event;
  369. return $this;
  370. }
  371. /**
  372. * Mouse out event.
  373. *
  374. * @var Expr|null
  375. */
  376. protected $mouseOutEvent;
  377. /**
  378. * {@inheritdoc}
  379. */
  380. public function getMouseOutEvent()
  381. {
  382. return $this->mouseOutEvent;
  383. }
  384. /**
  385. * {@inheritdoc}
  386. */
  387. public function setMouseOutEvent($event)
  388. {
  389. if (false === $event instanceof Expr && false === is_null($event)) {
  390. throw new InvalidArgumentException();
  391. }
  392. $this->mouseOutEvent = $event;
  393. return $this;
  394. }
  395. /**
  396. * Mouse over event.
  397. *
  398. * @var Expr|null
  399. */
  400. protected $mouseOverEvent;
  401. /**
  402. * {@inheritdoc}
  403. */
  404. public function getMouseOverEvent()
  405. {
  406. return $this->mouseOverEvent;
  407. }
  408. /**
  409. * {@inheritdoc}
  410. */
  411. public function setMouseOverEvent($event)
  412. {
  413. if (false === $event instanceof Expr && false === is_null($event)) {
  414. throw new InvalidArgumentException();
  415. }
  416. $this->mouseOverEvent = $event;
  417. return $this;
  418. }
  419. /**
  420. * Show event.
  421. *
  422. * @var Expr|null
  423. */
  424. protected $showEvent;
  425. /**
  426. * {@inheritdoc}
  427. */
  428. public function getShowEvent()
  429. {
  430. return $this->showEvent;
  431. }
  432. /**
  433. * {@inheritdoc}
  434. */
  435. public function setShowEvent($event)
  436. {
  437. if (false === $event instanceof Expr && false === is_null($event)) {
  438. throw new InvalidArgumentException();
  439. }
  440. $this->showEvent = $event;
  441. return $this;
  442. }
  443. /**
  444. * Animation.
  445. *
  446. * @var AnimationInterface
  447. */
  448. protected $animation;
  449. /**
  450. * {@inheritdoc}
  451. */
  452. public function getAnimation()
  453. {
  454. return $this->animation;
  455. }
  456. /**
  457. * Hover state.
  458. *
  459. * @var HoverStateInterface
  460. */
  461. protected $hoverState;
  462. /**
  463. * {@inheritdoc}
  464. */
  465. public function getHoverState()
  466. {
  467. if (null === $this->hoverState) {
  468. $this->hoverState = new HoverState($this);
  469. }
  470. return $this->hoverState;
  471. }
  472. /**
  473. * Label Style
  474. *
  475. * @var array
  476. */
  477. protected $labelStyle = array();
  478. /**
  479. * {@inheritdoc}
  480. */
  481. public function setLabelStyle($labelStyle)
  482. {
  483. $this->labelStyle = $labelStyle;
  484. return $this;
  485. }
  486. /**
  487. * {@inheritdoc}
  488. */
  489. public function getLabelStyle()
  490. {
  491. return $this->labelStyle;
  492. }
  493. }