Extracted animated property to trait
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
39
src/Models/HasAnimation.php
Normal file
39
src/Models/HasAnimation.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
|
||||
trait HasAnimation
|
||||
{
|
||||
private $animated;
|
||||
|
||||
public function setAnimated($animated)
|
||||
{
|
||||
$this->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user