Added HasLegend trait

- Refactored component to use BaseChartModel and traits
This commit is contained in:
Andrés Santibáñez
2020-10-25 00:40:06 -05:00
parent 8126b95593
commit 9df03c36a8
9 changed files with 123 additions and 72 deletions

View File

@@ -7,7 +7,7 @@ namespace Asantibanez\LivewireCharts\Models;
* Class PieChartModel
* @package Asantibanez\LivewireCharts\Models
*/
class PieChartModel
class PieChartModel extends BaseChartModel
{
public $title;
@@ -21,6 +21,8 @@ class PieChartModel
public function __construct()
{
parent::__construct();
$this->title = '';
$this->animated = false;
@@ -74,17 +76,19 @@ class PieChartModel
public function toArray()
{
return [
return array_merge(parent::toArray(), [
'title' => $this->title,
'animated' => $this->animated,
'onSliceClickEventName' => $this->onSliceClickEventName,
'opacity' => $this->opacity,
'data' => $this->data->toArray(),
];
]);
}
public function fromArray($array)
{
parent::fromArray($array);
$this->title = data_get($array, 'title', '');
$this->animated = data_get($array, 'animated', false);
@@ -95,9 +99,4 @@ class PieChartModel
$this->data = collect(data_get($array, 'data', []));
}
public function reactiveKey()
{
return md5(json_encode($this->toArray()));
}
}