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

63
src/Models/HasAxis.php Normal file
View File

@@ -0,0 +1,63 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
trait HasAxis
{
private $xAxis;
private $yAxis;
public function initAxis()
{
$this->xAxis = $this->defaultXAxis();
$this->yAxis = $this->defaultYAxis();
}
private function defaultXAxis()
{
return [
'labels' => [
'show' => true,
],
];
}
private function defaultYAxis()
{
return [
'show' => true,
];
}
public function setXAxisVisible($visible)
{
data_set($this->xAxis, 'labels.show', $visible);
return $this;
}
public function setYAxisVisible($visible)
{
data_set($this->yAxis, 'show', $visible);
return $this;
}
protected function axisFromArray($array)
{
$this->xAxis = data_get($array, 'xAxis', $this->defaultXAxis());
$this->yAxis = data_get($array, 'yAxis', $this->defaultYAxis());
}
protected function axisToArray()
{
return [
'xAxis' => $this->xAxis,
'yAxis' => $this->yAxis,
];
}
}