@@ -10,31 +10,31 @@ |
||
| 10 | 10 | trait NumberUtils |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $input |
|
| 15 | - * |
|
| 16 | - * @return array |
|
| 17 | - */ |
|
| 18 | - public function recursiveToFloat(array $input) |
|
| 19 | - { |
|
| 20 | - array_walk_recursive($input, function (&$value) { |
|
| 21 | - $value = floatval($value); |
|
| 22 | - }); |
|
| 13 | + /** |
|
| 14 | + * @param array $input |
|
| 15 | + * |
|
| 16 | + * @return array |
|
| 17 | + */ |
|
| 18 | + public function recursiveToFloat(array $input) |
|
| 19 | + { |
|
| 20 | + array_walk_recursive($input, function (&$value) { |
|
| 21 | + $value = floatval($value); |
|
| 22 | + }); |
|
| 23 | 23 | |
| 24 | - return $input; |
|
| 25 | - } |
|
| 24 | + return $input; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param array $input |
|
| 29 | - * |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function recursiveToInt(array $input) |
|
| 33 | - { |
|
| 34 | - array_walk_recursive($input, function (&$value) { |
|
| 35 | - $value = intval($value); |
|
| 36 | - }); |
|
| 27 | + /** |
|
| 28 | + * @param array $input |
|
| 29 | + * |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function recursiveToInt(array $input) |
|
| 33 | + { |
|
| 34 | + array_walk_recursive($input, function (&$value) { |
|
| 35 | + $value = intval($value); |
|
| 36 | + }); |
|
| 37 | 37 | |
| 38 | - return $input; |
|
| 39 | - } |
|
| 38 | + return $input; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -11,26 +11,26 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | trait ArraySerializable |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Returns an array copy of the properties and their current values in this class |
|
| 16 | - * |
|
| 17 | - * @return array |
|
| 18 | - */ |
|
| 19 | - public function getArrayCopy() |
|
| 20 | - { |
|
| 21 | - $currentValues = array_map(function ($value) { |
|
| 22 | - if (is_object($value)) { |
|
| 23 | - if ($value instanceof ArraySerializableInterface) { |
|
| 24 | - return $value->getArrayCopy(); |
|
| 25 | - } |
|
| 26 | - } |
|
| 14 | + /** |
|
| 15 | + * Returns an array copy of the properties and their current values in this class |
|
| 16 | + * |
|
| 17 | + * @return array |
|
| 18 | + */ |
|
| 19 | + public function getArrayCopy() |
|
| 20 | + { |
|
| 21 | + $currentValues = array_map(function ($value) { |
|
| 22 | + if (is_object($value)) { |
|
| 23 | + if ($value instanceof ArraySerializableInterface) { |
|
| 24 | + return $value->getArrayCopy(); |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - return $value; |
|
| 29 | - }, get_object_vars($this)); |
|
| 28 | + return $value; |
|
| 29 | + }, get_object_vars($this)); |
|
| 30 | 30 | |
| 31 | - // Filter out null values and return the remaining. |
|
| 32 | - return array_filter($currentValues, function ($value) { |
|
| 33 | - return ! is_null($value); |
|
| 34 | - }); |
|
| 35 | - } |
|
| 31 | + // Filter out null values and return the remaining. |
|
| 32 | + return array_filter($currentValues, function ($value) { |
|
| 33 | + return ! is_null($value); |
|
| 34 | + }); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -9,17 +9,17 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | trait StringUtils |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param array $input |
|
| 14 | - * |
|
| 15 | - * @return array |
|
| 16 | - */ |
|
| 17 | - public function recursiveToString(array $input) |
|
| 18 | - { |
|
| 19 | - array_walk_recursive($input, function (&$value) { |
|
| 20 | - $value = strval($value); |
|
| 21 | - }); |
|
| 12 | + /** |
|
| 13 | + * @param array $input |
|
| 14 | + * |
|
| 15 | + * @return array |
|
| 16 | + */ |
|
| 17 | + public function recursiveToString(array $input) |
|
| 18 | + { |
|
| 19 | + array_walk_recursive($input, function (&$value) { |
|
| 20 | + $value = strval($value); |
|
| 21 | + }); |
|
| 22 | 22 | |
| 23 | - return $input; |
|
| 24 | - } |
|
| 23 | + return $input; |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -11,238 +11,238 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class Chart implements ChartInterface |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * The internal type of chart. |
|
| 16 | - */ |
|
| 17 | - const TYPE = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The list of models that should be used for this chart type. |
|
| 21 | - */ |
|
| 22 | - const MODEL = [ |
|
| 23 | - 'dataset' => DataSet::class, |
|
| 24 | - 'options' => Options::class, |
|
| 25 | - ]; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $id; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - protected $height; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var int |
|
| 39 | - */ |
|
| 40 | - protected $width; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $title; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var LabelsCollection |
|
| 49 | - */ |
|
| 50 | - protected $labels; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var Options |
|
| 54 | - */ |
|
| 55 | - protected $options; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var DataSetCollection |
|
| 59 | - */ |
|
| 60 | - protected $dataSets; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getId() |
|
| 66 | - { |
|
| 67 | - if (is_null($this->id)) { |
|
| 68 | - $this->id = uniqid('chart'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return $this->id; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $id |
|
| 76 | - * |
|
| 77 | - * @return Chart |
|
| 78 | - */ |
|
| 79 | - public function setId($id) |
|
| 80 | - { |
|
| 81 | - $this->id = strval($id); |
|
| 82 | - |
|
| 83 | - return $this; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @return int |
|
| 88 | - */ |
|
| 89 | - public function getHeight() |
|
| 90 | - { |
|
| 91 | - return $this->height; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param int $height |
|
| 96 | - * |
|
| 97 | - * @return Chart |
|
| 98 | - */ |
|
| 99 | - public function setHeight($height) |
|
| 100 | - { |
|
| 101 | - $this->height = intval($height); |
|
| 102 | - |
|
| 103 | - return $this; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return int |
|
| 108 | - */ |
|
| 109 | - public function getWidth() |
|
| 110 | - { |
|
| 111 | - return $this->width; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param int $width |
|
| 116 | - * |
|
| 117 | - * @return Chart |
|
| 118 | - */ |
|
| 119 | - public function setWidth($width) |
|
| 120 | - { |
|
| 121 | - $this->width = intval($width); |
|
| 122 | - |
|
| 123 | - return $this; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getTitle() |
|
| 130 | - { |
|
| 131 | - return $this->title; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param string $title |
|
| 136 | - * |
|
| 137 | - * @return Chart |
|
| 138 | - */ |
|
| 139 | - public function setTitle($title) |
|
| 140 | - { |
|
| 141 | - $this->title = strval($title); |
|
| 142 | - |
|
| 143 | - return $this; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return LabelsCollection |
|
| 148 | - */ |
|
| 149 | - public function labels() |
|
| 150 | - { |
|
| 151 | - if (is_null($this->labels)) { |
|
| 152 | - $this->labels = new LabelsCollection(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return $this->labels; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param string $label |
|
| 160 | - * |
|
| 161 | - * @return $this |
|
| 162 | - */ |
|
| 163 | - public function addLabel($label) |
|
| 164 | - { |
|
| 165 | - $this->labels()->append($label); |
|
| 166 | - |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param $offset |
|
| 172 | - * |
|
| 173 | - * @return string|bool |
|
| 174 | - */ |
|
| 175 | - public function getLabel($offset) |
|
| 176 | - { |
|
| 177 | - return $this->labels()->offsetGet($offset); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @return DataSetCollection |
|
| 182 | - */ |
|
| 183 | - public function dataSets() |
|
| 184 | - { |
|
| 185 | - if (is_null($this->dataSets)) { |
|
| 186 | - $this->dataSets = new DataSetCollection(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $this->dataSets; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @param DataSet $dataSet |
|
| 194 | - * |
|
| 195 | - * @return $this |
|
| 196 | - */ |
|
| 197 | - public function addDataSet(DataSet $dataSet) |
|
| 198 | - { |
|
| 199 | - $this->dataSets()->append($dataSet->setOwner($this)); |
|
| 200 | - |
|
| 201 | - return $this; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @param $offset |
|
| 206 | - * |
|
| 207 | - * @return DataSet|bool |
|
| 208 | - */ |
|
| 209 | - public function getDataSet($offset) |
|
| 210 | - { |
|
| 211 | - return $this->dataSets()->offsetGet($offset); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param bool $pretty |
|
| 216 | - * |
|
| 217 | - * @return string |
|
| 218 | - */ |
|
| 219 | - public function render($pretty = false) |
|
| 220 | - { |
|
| 221 | - $renderer = new Html($this); |
|
| 222 | - |
|
| 223 | - return $renderer->render($pretty ? $renderer::RENDER_PRETTY : null); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return DataSet |
|
| 228 | - */ |
|
| 229 | - public function createDataSet() |
|
| 230 | - { |
|
| 231 | - $datasetClass = static::MODEL['dataset']; |
|
| 232 | - |
|
| 233 | - return new $datasetClass(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @return Options |
|
| 238 | - */ |
|
| 239 | - public function options() |
|
| 240 | - { |
|
| 241 | - if (is_null($this->options)) { |
|
| 242 | - $optionsClass = static::MODEL['options']; |
|
| 243 | - $this->options = new $optionsClass($this); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return $this->options; |
|
| 247 | - } |
|
| 14 | + /** |
|
| 15 | + * The internal type of chart. |
|
| 16 | + */ |
|
| 17 | + const TYPE = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The list of models that should be used for this chart type. |
|
| 21 | + */ |
|
| 22 | + const MODEL = [ |
|
| 23 | + 'dataset' => DataSet::class, |
|
| 24 | + 'options' => Options::class, |
|
| 25 | + ]; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $id; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + protected $height; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var int |
|
| 39 | + */ |
|
| 40 | + protected $width; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $title; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var LabelsCollection |
|
| 49 | + */ |
|
| 50 | + protected $labels; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var Options |
|
| 54 | + */ |
|
| 55 | + protected $options; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var DataSetCollection |
|
| 59 | + */ |
|
| 60 | + protected $dataSets; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getId() |
|
| 66 | + { |
|
| 67 | + if (is_null($this->id)) { |
|
| 68 | + $this->id = uniqid('chart'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return $this->id; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $id |
|
| 76 | + * |
|
| 77 | + * @return Chart |
|
| 78 | + */ |
|
| 79 | + public function setId($id) |
|
| 80 | + { |
|
| 81 | + $this->id = strval($id); |
|
| 82 | + |
|
| 83 | + return $this; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @return int |
|
| 88 | + */ |
|
| 89 | + public function getHeight() |
|
| 90 | + { |
|
| 91 | + return $this->height; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param int $height |
|
| 96 | + * |
|
| 97 | + * @return Chart |
|
| 98 | + */ |
|
| 99 | + public function setHeight($height) |
|
| 100 | + { |
|
| 101 | + $this->height = intval($height); |
|
| 102 | + |
|
| 103 | + return $this; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return int |
|
| 108 | + */ |
|
| 109 | + public function getWidth() |
|
| 110 | + { |
|
| 111 | + return $this->width; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param int $width |
|
| 116 | + * |
|
| 117 | + * @return Chart |
|
| 118 | + */ |
|
| 119 | + public function setWidth($width) |
|
| 120 | + { |
|
| 121 | + $this->width = intval($width); |
|
| 122 | + |
|
| 123 | + return $this; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getTitle() |
|
| 130 | + { |
|
| 131 | + return $this->title; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param string $title |
|
| 136 | + * |
|
| 137 | + * @return Chart |
|
| 138 | + */ |
|
| 139 | + public function setTitle($title) |
|
| 140 | + { |
|
| 141 | + $this->title = strval($title); |
|
| 142 | + |
|
| 143 | + return $this; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return LabelsCollection |
|
| 148 | + */ |
|
| 149 | + public function labels() |
|
| 150 | + { |
|
| 151 | + if (is_null($this->labels)) { |
|
| 152 | + $this->labels = new LabelsCollection(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return $this->labels; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param string $label |
|
| 160 | + * |
|
| 161 | + * @return $this |
|
| 162 | + */ |
|
| 163 | + public function addLabel($label) |
|
| 164 | + { |
|
| 165 | + $this->labels()->append($label); |
|
| 166 | + |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param $offset |
|
| 172 | + * |
|
| 173 | + * @return string|bool |
|
| 174 | + */ |
|
| 175 | + public function getLabel($offset) |
|
| 176 | + { |
|
| 177 | + return $this->labels()->offsetGet($offset); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @return DataSetCollection |
|
| 182 | + */ |
|
| 183 | + public function dataSets() |
|
| 184 | + { |
|
| 185 | + if (is_null($this->dataSets)) { |
|
| 186 | + $this->dataSets = new DataSetCollection(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $this->dataSets; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param DataSet $dataSet |
|
| 194 | + * |
|
| 195 | + * @return $this |
|
| 196 | + */ |
|
| 197 | + public function addDataSet(DataSet $dataSet) |
|
| 198 | + { |
|
| 199 | + $this->dataSets()->append($dataSet->setOwner($this)); |
|
| 200 | + |
|
| 201 | + return $this; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @param $offset |
|
| 206 | + * |
|
| 207 | + * @return DataSet|bool |
|
| 208 | + */ |
|
| 209 | + public function getDataSet($offset) |
|
| 210 | + { |
|
| 211 | + return $this->dataSets()->offsetGet($offset); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param bool $pretty |
|
| 216 | + * |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 219 | + public function render($pretty = false) |
|
| 220 | + { |
|
| 221 | + $renderer = new Html($this); |
|
| 222 | + |
|
| 223 | + return $renderer->render($pretty ? $renderer::RENDER_PRETTY : null); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return DataSet |
|
| 228 | + */ |
|
| 229 | + public function createDataSet() |
|
| 230 | + { |
|
| 231 | + $datasetClass = static::MODEL['dataset']; |
|
| 232 | + |
|
| 233 | + return new $datasetClass(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return Options |
|
| 238 | + */ |
|
| 239 | + public function options() |
|
| 240 | + { |
|
| 241 | + if (is_null($this->options)) { |
|
| 242 | + $optionsClass = static::MODEL['options']; |
|
| 243 | + $this->options = new $optionsClass($this); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return $this->options; |
|
| 247 | + } |
|
| 248 | 248 | } |