diff --git a/src/Models/AreaChartModel.php b/src/Models/AreaChartModel.php index 0708c1f..eb25d5c 100644 --- a/src/Models/AreaChartModel.php +++ b/src/Models/AreaChartModel.php @@ -11,8 +11,6 @@ class AreaChartModel extends BaseChartModel { public $title; - public $animated; - public $color; public $data; @@ -25,8 +23,6 @@ class AreaChartModel extends BaseChartModel $this->title = ''; - $this->animated = false; - $this->color = '#90cdf4'; $this->onPointClickEventName = null; @@ -41,13 +37,6 @@ class AreaChartModel extends BaseChartModel return $this; } - public function setAnimated($animated) - { - $this->animated = $animated; - - return $this; - } - public function setColor($color) { $this->color = $color; @@ -77,7 +66,6 @@ class AreaChartModel extends BaseChartModel { return array_merge(parent::toArray(), [ 'title' => $this->title, - 'animated' => $this->animated, 'color' => $this->color, 'onPointClickEventName' => $this->onPointClickEventName, 'data' => $this->data->toArray(), @@ -90,8 +78,6 @@ class AreaChartModel extends BaseChartModel $this->title = data_get($array, 'title', ''); - $this->animated = data_get($array, 'animated', false); - $this->color = data_get($array, 'color', '#90cdf4'); $this->onPointClickEventName = data_get($array, 'onPointClickEventName', null); diff --git a/src/Models/BaseChartModel.php b/src/Models/BaseChartModel.php index 14956ee..761507c 100644 --- a/src/Models/BaseChartModel.php +++ b/src/Models/BaseChartModel.php @@ -9,12 +9,14 @@ namespace Asantibanez\LivewireCharts\Models; */ class BaseChartModel { + use HasAnimation; use HasAxis; use HasStroke; use HasLegend; public function __construct() { + $this->initAnimation(); $this->initAxis(); $this->initStroke(); $this->initLegend(); @@ -28,6 +30,7 @@ class BaseChartModel public function toArray() { return array_merge( + $this->animationToArray(), $this->axisToArray(), $this->strokeToArray(), $this->legendToArray() @@ -36,6 +39,7 @@ class BaseChartModel public function fromArray($array) { + $this->animationFromArray($array); $this->axisFromArray($array); $this->strokeFromArray($array); $this->legendFromArray($array); diff --git a/src/Models/ColumnChartModel.php b/src/Models/ColumnChartModel.php index 27d7272..498c18f 100644 --- a/src/Models/ColumnChartModel.php +++ b/src/Models/ColumnChartModel.php @@ -11,8 +11,6 @@ class ColumnChartModel extends BaseChartModel { public $title; - public $animated; - public $opacity; public $onColumnClickEventName; @@ -25,8 +23,6 @@ class ColumnChartModel extends BaseChartModel $this->title = ''; - $this->animated = false; - $this->onColumnClickEventName = null; $this->opacity = 0.5; @@ -41,13 +37,6 @@ class ColumnChartModel extends BaseChartModel return $this; } - public function setAnimated($animated) - { - $this->animated = $animated; - - return $this; - } - public function setOpacity($opacity) { $this->opacity = $opacity; @@ -78,7 +67,6 @@ class ColumnChartModel extends BaseChartModel { return array_merge(parent::toArray(), [ 'title' => $this->title, - 'animated' => $this->animated, 'onColumnClickEventName' => $this->onColumnClickEventName, 'opacity' => $this->opacity, 'data' => $this->data->toArray(), @@ -91,8 +79,6 @@ class ColumnChartModel extends BaseChartModel $this->title = data_get($array, 'title', ''); - $this->animated = data_get($array, 'animated', false); - $this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null); $this->opacity = data_get($array, 'opacity', 0.5); diff --git a/src/Models/HasAnimation.php b/src/Models/HasAnimation.php new file mode 100644 index 0000000..c149430 --- /dev/null +++ b/src/Models/HasAnimation.php @@ -0,0 +1,39 @@ +animated = $animated; + + return $this; + } + + protected function initAnimation() + { + $this->animated = $this->defaultAnimated(); + } + + private function defaultAnimated() + { + return false; + } + + protected function animationFromArray($array) + { + $this->animated = data_get($array, 'animated', $this->defaultAnimated()); + } + + protected function animationToArray() + { + return [ + 'animated' => $this->animated, + ]; + } +} diff --git a/src/Models/PieChartModel.php b/src/Models/PieChartModel.php index ebe0f36..858079d 100644 --- a/src/Models/PieChartModel.php +++ b/src/Models/PieChartModel.php @@ -11,8 +11,6 @@ class PieChartModel extends BaseChartModel { public $title; - public $animated; - public $onSliceClickEventName; public $opacity; @@ -25,8 +23,6 @@ class PieChartModel extends BaseChartModel $this->title = ''; - $this->animated = false; - $this->onSliceClickEventName = null; $this->opacity = 0.75; @@ -41,13 +37,6 @@ class PieChartModel extends BaseChartModel return $this; } - public function setAnimated($animated) - { - $this->animated = $animated; - - return $this; - } - public function setOpacity($opacity) { $this->opacity = $opacity; @@ -78,7 +67,6 @@ class PieChartModel extends BaseChartModel { return array_merge(parent::toArray(), [ 'title' => $this->title, - 'animated' => $this->animated, 'onSliceClickEventName' => $this->onSliceClickEventName, 'opacity' => $this->opacity, 'data' => $this->data->toArray(), @@ -91,8 +79,6 @@ class PieChartModel extends BaseChartModel $this->title = data_get($array, 'title', ''); - $this->animated = data_get($array, 'animated', false); - $this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null); $this->opacity = data_get($array, 'opacity', 0.75);