From 0de38b041b9bb97980d7b762d1e965c4efd75ef8 Mon Sep 17 00:00:00 2001 From: asantibanez Date: Thu, 11 Feb 2021 22:35:59 -0500 Subject: [PATCH] Added new traits for colors and grid handling --- src/Models/BaseChartModel.php | 10 +++++- src/Models/HasColors.php | 46 ++++++++++++++++++++++++ src/Models/HasGrid.php | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/Models/HasColors.php create mode 100644 src/Models/HasGrid.php diff --git a/src/Models/BaseChartModel.php b/src/Models/BaseChartModel.php index 61f4998..ed6dc88 100644 --- a/src/Models/BaseChartModel.php +++ b/src/Models/BaseChartModel.php @@ -16,6 +16,8 @@ class BaseChartModel use HasLegend; use HasDataLabels; use HasSparkline; + use HasGrid; + use HasColors; public function __construct() { @@ -26,6 +28,8 @@ class BaseChartModel $this->initLegend(); $this->initDataLabels(); $this->initSparkline(); + $this->initGrid(); + $this->initColors(); } public function reactiveKey() @@ -42,7 +46,9 @@ class BaseChartModel $this->strokeToArray(), $this->legendToArray(), $this->dataLabelsToArray(), - $this->sparklineToArray() + $this->sparklineToArray(), + $this->gridToArray(), + $this->colorsToArray() ); } @@ -55,5 +61,7 @@ class BaseChartModel $this->legendFromArray($array); $this->dataLabelsFromArray($array); $this->sparklineFromArray($array); + $this->gridFromArray($array); + $this->colorsFromArray($array); } } diff --git a/src/Models/HasColors.php b/src/Models/HasColors.php new file mode 100644 index 0000000..bfe57b1 --- /dev/null +++ b/src/Models/HasColors.php @@ -0,0 +1,46 @@ +colors = $colors; + + return $this; + } + + public function addColor($color) + { + $this->colors[] = $color; + + return $this; + } + + protected function initColors() + { + $this->colors = $this->defaultColors(); + } + + private function defaultColors() + { + return []; + } + + protected function colorsFromArray($array) + { + $this->colors = data_get($array, 'colors', $this->defaultColors()); + } + + protected function colorsToArray() + { + return [ + 'colors' => $this->colors, + ]; + } +} diff --git a/src/Models/HasGrid.php b/src/Models/HasGrid.php new file mode 100644 index 0000000..37ef778 --- /dev/null +++ b/src/Models/HasGrid.php @@ -0,0 +1,66 @@ +grid, 'show', $visible); + + return $this; + } + + public function withGrid() + { + data_set($this->grid, 'show', true); + + return $this; + } + + public function withoutGrid() + { + data_set($this->grid, 'show', false); + + return $this; + } + + protected function initGrid() + { + $this->grid = $this->defaultGrid(); + } + + private function defaultGrid() + { + return [ + 'show' => false, + 'position' => 'back', + 'xaxis' => [ + 'lines' => [ + 'show' => true, + ], + ], + 'yaxis' => [ + 'lines' => [ + 'show' => true, + ], + ], + ]; + } + + protected function gridFromArray($array) + { + $this->grid = data_get($array, 'grid', $this->defaultGrid()); + } + + protected function gridToArray() + { + return [ + 'grid' => $this->grid, + ]; + } +}