Files
livewire-charts/src/Models/HasAxis.php
Andrés Santibáñez 9df03c36a8 Added HasLegend trait
- Refactored component to use BaseChartModel and traits
2020-10-25 00:40:06 -05:00

64 lines
1.1 KiB
PHP

<?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,
];
}
}