@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | trait JsonSerializable |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @return array |
|
| 17 | - */ |
|
| 18 | - public function jsonSerialize() |
|
| 19 | - { |
|
| 20 | - return array_map(function ($value) { |
|
| 21 | - if ($value instanceof JsonSerializableInterface) { |
|
| 22 | - return $value->jsonSerialize(); |
|
| 23 | - } elseif ($value instanceof ArraySerializableInterface) { |
|
| 24 | - return $value->getArrayCopy(); |
|
| 25 | - } |
|
| 15 | + /** |
|
| 16 | + * @return array |
|
| 17 | + */ |
|
| 18 | + public function jsonSerialize() |
|
| 19 | + { |
|
| 20 | + return array_map(function ($value) { |
|
| 21 | + if ($value instanceof JsonSerializableInterface) { |
|
| 22 | + return $value->jsonSerialize(); |
|
| 23 | + } elseif ($value instanceof ArraySerializableInterface) { |
|
| 24 | + return $value->getArrayCopy(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - return $value; |
|
| 28 | - }, $this->getArrayCopy()); |
|
| 29 | - } |
|
| 27 | + return $value; |
|
| 28 | + }, $this->getArrayCopy()); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -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, $key) { |
|
| 33 | - return ! is_null($value) && $key !== 'owner'; |
|
| 34 | - }, ARRAY_FILTER_USE_BOTH); |
|
| 35 | - } |
|
| 31 | + // Filter out null values and return the remaining. |
|
| 32 | + return array_filter($currentValues, function ($value, $key) { |
|
| 33 | + return ! is_null($value) && $key !== 'owner'; |
|
| 34 | + }, ARRAY_FILTER_USE_BOTH); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -11,40 +11,40 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Json extends Renderer |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Render the necessary JSON for the chart to function in the frontend. |
|
| 16 | - * |
|
| 17 | - * @param int|false $flags |
|
| 18 | - * |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function render($flags = null) |
|
| 22 | - { |
|
| 23 | - $config = [ |
|
| 24 | - 'type' => constant(get_class($this->chart) . "::TYPE"), |
|
| 25 | - 'data' => [], |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - $labels = $this->chart->labels()->jsonSerialize(); |
|
| 29 | - if ($labels) { |
|
| 30 | - $config['data']['labels'] = $labels; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - $dataSets = $this->chart->dataSets()->jsonSerialize(); |
|
| 34 | - if ($dataSets) { |
|
| 35 | - $config['data']['datasets'] = $dataSets; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - $options = $this->chart->options()->jsonSerialize(); |
|
| 39 | - if (! empty($options)) { |
|
| 40 | - $config['options'] = $options; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $output = JsonHelper::encode($config, false, ['enableJsonExprFinder' => true]); |
|
| 44 | - if ($flags & Renderer::RENDER_PRETTY) { |
|
| 45 | - $output = JsonHelper::prettyPrint($output); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return $output; |
|
| 49 | - } |
|
| 14 | + /** |
|
| 15 | + * Render the necessary JSON for the chart to function in the frontend. |
|
| 16 | + * |
|
| 17 | + * @param int|false $flags |
|
| 18 | + * |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function render($flags = null) |
|
| 22 | + { |
|
| 23 | + $config = [ |
|
| 24 | + 'type' => constant(get_class($this->chart) . "::TYPE"), |
|
| 25 | + 'data' => [], |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + $labels = $this->chart->labels()->jsonSerialize(); |
|
| 29 | + if ($labels) { |
|
| 30 | + $config['data']['labels'] = $labels; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + $dataSets = $this->chart->dataSets()->jsonSerialize(); |
|
| 34 | + if ($dataSets) { |
|
| 35 | + $config['data']['datasets'] = $dataSets; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + $options = $this->chart->options()->jsonSerialize(); |
|
| 39 | + if (! empty($options)) { |
|
| 40 | + $config['options'] = $options; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $output = JsonHelper::encode($config, false, ['enableJsonExprFinder' => true]); |
|
| 44 | + if ($flags & Renderer::RENDER_PRETTY) { |
|
| 45 | + $output = JsonHelper::prettyPrint($output); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return $output; |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -9,28 +9,28 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | class JavaScript extends Renderer |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Renders the necessary JavaScript for the chart to function in the frontend. |
|
| 14 | - * |
|
| 15 | - * @param int|null $flags |
|
| 16 | - * |
|
| 17 | - * @return string |
|
| 18 | - */ |
|
| 19 | - public function render($flags = null) |
|
| 20 | - { |
|
| 21 | - $script = []; |
|
| 12 | + /** |
|
| 13 | + * Renders the necessary JavaScript for the chart to function in the frontend. |
|
| 14 | + * |
|
| 15 | + * @param int|null $flags |
|
| 16 | + * |
|
| 17 | + * @return string |
|
| 18 | + */ |
|
| 19 | + public function render($flags = null) |
|
| 20 | + { |
|
| 21 | + $script = []; |
|
| 22 | 22 | |
| 23 | - // First, setup the canvas context |
|
| 24 | - $script[] = "var ctx = document.getElementById( \"{$this->chart->getId()}\" ).getContext( \"2d\" );"; |
|
| 23 | + // First, setup the canvas context |
|
| 24 | + $script[] = "var ctx = document.getElementById( \"{$this->chart->getId()}\" ).getContext( \"2d\" );"; |
|
| 25 | 25 | |
| 26 | - // Now, setup the chart instance |
|
| 27 | - $jsonRenderer = new Json($this->chart); |
|
| 28 | - $json = $jsonRenderer->render($flags); |
|
| 29 | - $script[] = "var chart = new Chart( ctx, {$json} );"; |
|
| 30 | - $scriptString = implode("\n", $script); |
|
| 26 | + // Now, setup the chart instance |
|
| 27 | + $jsonRenderer = new Json($this->chart); |
|
| 28 | + $json = $jsonRenderer->render($flags); |
|
| 29 | + $script[] = "var chart = new Chart( ctx, {$json} );"; |
|
| 30 | + $scriptString = implode("\n", $script); |
|
| 31 | 31 | |
| 32 | - // Return the script |
|
| 33 | - return <<<JS |
|
| 32 | + // Return the script |
|
| 33 | + return <<<JS |
|
| 34 | 34 | window.onload=(function(oldLoad){return function(){ |
| 35 | 35 | if (oldLoad) { |
| 36 | 36 | oldLoad(); |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | window.chartInstances['{$this->chart->getId()}'] = chart; |
| 46 | 46 | }})(window.onload); |
| 47 | 47 | JS |
| 48 | - ; |
|
| 49 | - } |
|
| 48 | + ; |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -13,5 +13,5 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Data extends ArrayAccess implements JsonSerializableInterface |
| 15 | 15 | { |
| 16 | - use Delegate\JsonSerializable; |
|
| 16 | + use Delegate\JsonSerializable; |
|
| 17 | 17 | } |