Added HasLegend trait
- Refactored component to use BaseChartModel and traits
This commit is contained in:
63
src/Models/HasAxis.php
Normal file
63
src/Models/HasAxis.php
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user