DataSet.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\UI\Widget\Graphs\Models;
  3. /**
  4. * Description of ChartData
  5. *
  6. * @autor ThurData <info@thurdata.ch>
  7. */
  8. class DataSet
  9. {
  10. const POINT_STYLE_CIRCLE = 'circle';
  11. const POINT_STYLE_CROSS_ROT = 'crossRot';
  12. const POINT_STYLE_DASH = 'dash';
  13. const POINT_STYLE_LINE = 'line';
  14. const POINT_STYLE_RECT = 'rect';
  15. const POINT_STYLE_RECT_ROUNDED = 'rectRounded';
  16. const POINT_STYLE_RECT_ROT = 'rectRot';
  17. const POINT_STYLE_STAR = 'star';
  18. const POINT_STYLE_TRIANGLE = 'triangle';
  19. const STEPPED_LINE_FALSE = false;
  20. const STEPPED_LINE_TRUE = false;
  21. const STEPPED_LINE_BEFORE = 'before';
  22. const STEPPED_LINE_AFTER = 'after';
  23. protected $label = null;
  24. protected $type = null;
  25. /**
  26. * @var double[]|integer[]|array
  27. */
  28. protected $data = [];
  29. /**
  30. * @var string[]|string
  31. */
  32. protected $backgroundColor = [];
  33. /**
  34. * @var string[]|string
  35. */
  36. protected $borderColor = [];
  37. /**
  38. * @var double[]|integer[]
  39. */
  40. protected $borderDash = [];
  41. /**
  42. * @var string[]|string[]
  43. */
  44. protected $hoverBackgroundColor = [];
  45. /**
  46. * @var string[]|string[]
  47. */
  48. protected $hoverBorderColor = [];
  49. /**
  50. * @var double[]|double|integer[]|integer
  51. */
  52. protected $hoverBorderWidth = [];
  53. /**
  54. * @var string[]|string
  55. */
  56. protected $pointBackgroundColor= [];
  57. /**
  58. * @var string[]|string
  59. */
  60. protected $pointBorderColor = [];
  61. /**
  62. * @var double[]|double|integer[]|integer
  63. */
  64. protected $pointBorderWidth = [];
  65. /**
  66. * @var double[]|double|integer[]|integer
  67. */
  68. protected $pointRadius = [];
  69. /**
  70. * @var string[]|string
  71. */
  72. protected $pointStyle = [];
  73. /**
  74. * @var double[]|double|integer[]|integer
  75. */
  76. protected $pointHitRadius = [];
  77. /**
  78. * @var string[]|string
  79. */
  80. protected $pointHoverBackgroundColor = [];
  81. /**
  82. * @var string[]|string
  83. */
  84. protected $pointHoverBorderColor = [];
  85. /**
  86. * @var double[]|double|integer[]|integer
  87. */
  88. protected $pointHoverBorderWidth = [];
  89. /**
  90. * @var double[]|double|integer[]|integer
  91. */
  92. protected $pointHoverRadius = [];
  93. /**
  94. * @var double[]|double|integer[]|integer
  95. */
  96. protected $borderWidth = [];
  97. /**
  98. * @var double|integer
  99. */
  100. protected $borderDashOffset = null;
  101. /**
  102. * @var string
  103. */
  104. protected $xAxisID = null;
  105. /**
  106. * @var string
  107. */
  108. protected $yAxisID = null;
  109. /**
  110. * @var string
  111. */
  112. protected $borderCapStyle = null;
  113. /**
  114. * @var string
  115. */
  116. protected $borderJoinStyle = null;
  117. /**
  118. * @var string
  119. */
  120. protected $cubicInterpolationMode = null;
  121. /**
  122. * @var boolean|string
  123. */
  124. protected $fill = null;
  125. /**
  126. * @var double|integer
  127. */
  128. protected $lineTension = null;
  129. /**
  130. * @var boolean
  131. */
  132. protected $showLine = null;
  133. /**
  134. * @var boolean
  135. */
  136. protected $spanGaps = null;
  137. /**
  138. * @var boolean|string
  139. */
  140. protected $steppedLine = false;
  141. /**
  142. * @var string
  143. */
  144. protected $borderSkipped = null;
  145. public function addDataItem($value, array $configuration = [])
  146. {
  147. $this->data[] = $value;
  148. foreach ($configuration as $key => $value)
  149. {
  150. if (property_exists($this, $key))
  151. {
  152. $this->{$key}[] = $value;
  153. }
  154. }
  155. return $this;
  156. }
  157. public function setConfigurationDataSet(array $configuration = [])
  158. {
  159. foreach ($configuration as $key => $value)
  160. {
  161. if (property_exists($this, $key))
  162. {
  163. $this->{$key} = $value;
  164. }
  165. }
  166. return $this;
  167. }
  168. /**
  169. * Title label in Legend
  170. *
  171. * @param string $label
  172. * @return $this
  173. */
  174. public function setLabel($label = '')
  175. {
  176. $this->label = $label;
  177. return $this;
  178. }
  179. /**
  180. * @param string $type
  181. * @return $this
  182. */
  183. public function setType($type = 'line')
  184. {
  185. $this->type = $type;
  186. return $this;
  187. }
  188. /**
  189. * @param float $borderDashOffset
  190. * @return $this
  191. */
  192. public function setBorderDashOffset($borderDashOffset = 0)
  193. {
  194. $this->borderDashOffset = $borderDashOffset;
  195. return $this;
  196. }
  197. /**
  198. *
  199. * @param float $borderWidth
  200. * @return $this
  201. */
  202. public function setBorderWidth($borderWidth = 0)
  203. {
  204. $this->borderWidth = $borderWidth;
  205. return $this;
  206. }
  207. public function setXAxisID($xAxisID = '')
  208. {
  209. $this->xAxisID = $xAxisID;
  210. return $this;
  211. }
  212. public function setYAxisID($yAxisID = '')
  213. {
  214. $this->yAxisID = $yAxisID;
  215. return $this;
  216. }
  217. public function setBorderCapStyle($borderCapStyle = '')
  218. {
  219. $this->borderCapStyle = $borderCapStyle;
  220. return $this;
  221. }
  222. public function setBorderJoinStyle($borderJoinStyle = '')
  223. {
  224. $this->borderJoinStyle = $borderJoinStyle;
  225. return $this;
  226. }
  227. public function setCubicInterpolationMode($cubicInterpolationMode = '')
  228. {
  229. $this->cubicInterpolationMode = $cubicInterpolationMode;
  230. return $this;
  231. }
  232. public function setFill($fill = '')
  233. {
  234. $this->fill = $fill;
  235. return $this;
  236. }
  237. public function setLineTension($lineTension = 0)
  238. {
  239. $this->lineTension = $lineTension;
  240. return $this;
  241. }
  242. public function setShowLine($showLine = true)
  243. {
  244. $this->showLine = $showLine;
  245. return $this;
  246. }
  247. public function setSpanGaps($spanGaps = true)
  248. {
  249. $this->spanGaps = $spanGaps;
  250. return $this;
  251. }
  252. public function setBorderSkipped($borderSkipped = true)
  253. {
  254. $this->borderSkipped = $borderSkipped;
  255. return $this;
  256. }
  257. public function setSteppedLine($steppedLine = self::STEPPED_LINE_FALSE)
  258. {
  259. if (in_array($steppedLine, [self::STEPPED_LINE_FALSE, self::STEPPED_LINE_TRUE, self::STEPPED_LINE_BEFORE, self::STEPPED_LINE_AFTER], true))
  260. {
  261. $this->steppedLine = $steppedLine;
  262. }
  263. return $this;
  264. }
  265. public function toArray()
  266. {
  267. $return = [];
  268. foreach ($this as $key => $value)
  269. {
  270. if (property_exists($this, $key) && ($value !== null && !is_array($value) || is_array($value) && count($value) > 0))
  271. {
  272. $return[$key] = $value;
  273. }
  274. }
  275. return $return;
  276. }
  277. public function setTitle($title = '')
  278. {
  279. $this->setLabel($title);
  280. return $this;
  281. }
  282. public function setData($data = [])
  283. {
  284. foreach ($data as $value)
  285. {
  286. $this->addDataItem($value, []);
  287. }
  288. return $this;
  289. }
  290. }