From 40828df23ec62cbfc49d18dafcfab49a23a08879 Mon Sep 17 00:00:00 2001 From: asantibanez Date: Wed, 1 Feb 2023 18:23:46 -0500 Subject: [PATCH] Added ability to specify custom json config to charts --- src/Models/BaseChartModel.php | 6 +++++- src/Models/HasJsonConfig.php | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/Models/HasJsonConfig.php diff --git a/src/Models/BaseChartModel.php b/src/Models/BaseChartModel.php index ed6dc88..bec3d12 100644 --- a/src/Models/BaseChartModel.php +++ b/src/Models/BaseChartModel.php @@ -18,6 +18,7 @@ class BaseChartModel use HasSparkline; use HasGrid; use HasColors; + use HasJsonConfig; public function __construct() { @@ -30,6 +31,7 @@ class BaseChartModel $this->initSparkline(); $this->initGrid(); $this->initColors(); + $this->initJsonConfig(); } public function reactiveKey() @@ -48,7 +50,8 @@ class BaseChartModel $this->dataLabelsToArray(), $this->sparklineToArray(), $this->gridToArray(), - $this->colorsToArray() + $this->colorsToArray(), + $this->jsonConfigToArray() ); } @@ -63,5 +66,6 @@ class BaseChartModel $this->sparklineFromArray($array); $this->gridFromArray($array); $this->colorsFromArray($array); + $this->jsonConfigFromArray($array); } } diff --git a/src/Models/HasJsonConfig.php b/src/Models/HasJsonConfig.php new file mode 100644 index 0000000..3c9544b --- /dev/null +++ b/src/Models/HasJsonConfig.php @@ -0,0 +1,39 @@ +jsonConfig = $jsonConfig; + + return $this; + } + + protected function initJsonConfig() + { + $this->jsonConfig = []; + } + + private function defaultJsonConfig() + { + return []; + } + + protected function jsonConfigFromArray($array) + { + $this->jsonConfig = data_get($array, 'jsonConfig', $this->defaultJsonConfig()); + } + + protected function jsonConfigToArray() + { + return [ + 'jsonConfig' => $this->jsonConfig, + ]; + } +}