Added new traits for colors and grid handling
This commit is contained in:
@@ -16,6 +16,8 @@ class BaseChartModel
|
||||
use HasLegend;
|
||||
use HasDataLabels;
|
||||
use HasSparkline;
|
||||
use HasGrid;
|
||||
use HasColors;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -26,6 +28,8 @@ class BaseChartModel
|
||||
$this->initLegend();
|
||||
$this->initDataLabels();
|
||||
$this->initSparkline();
|
||||
$this->initGrid();
|
||||
$this->initColors();
|
||||
}
|
||||
|
||||
public function reactiveKey()
|
||||
@@ -42,7 +46,9 @@ class BaseChartModel
|
||||
$this->strokeToArray(),
|
||||
$this->legendToArray(),
|
||||
$this->dataLabelsToArray(),
|
||||
$this->sparklineToArray()
|
||||
$this->sparklineToArray(),
|
||||
$this->gridToArray(),
|
||||
$this->colorsToArray()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,5 +61,7 @@ class BaseChartModel
|
||||
$this->legendFromArray($array);
|
||||
$this->dataLabelsFromArray($array);
|
||||
$this->sparklineFromArray($array);
|
||||
$this->gridFromArray($array);
|
||||
$this->colorsFromArray($array);
|
||||
}
|
||||
}
|
||||
|
||||
46
src/Models/HasColors.php
Normal file
46
src/Models/HasColors.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
|
||||
trait HasColors
|
||||
{
|
||||
private $colors;
|
||||
|
||||
public function setColors($colors)
|
||||
{
|
||||
$this->colors = $colors;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addColor($color)
|
||||
{
|
||||
$this->colors[] = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function initColors()
|
||||
{
|
||||
$this->colors = $this->defaultColors();
|
||||
}
|
||||
|
||||
private function defaultColors()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function colorsFromArray($array)
|
||||
{
|
||||
$this->colors = data_get($array, 'colors', $this->defaultColors());
|
||||
}
|
||||
|
||||
protected function colorsToArray()
|
||||
{
|
||||
return [
|
||||
'colors' => $this->colors,
|
||||
];
|
||||
}
|
||||
}
|
||||
66
src/Models/HasGrid.php
Normal file
66
src/Models/HasGrid.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
|
||||
trait HasGrid
|
||||
{
|
||||
private $grid;
|
||||
|
||||
public function setGridVisible($visible)
|
||||
{
|
||||
data_set($this->grid, 'show', $visible);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withGrid()
|
||||
{
|
||||
data_set($this->grid, 'show', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withoutGrid()
|
||||
{
|
||||
data_set($this->grid, 'show', false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function initGrid()
|
||||
{
|
||||
$this->grid = $this->defaultGrid();
|
||||
}
|
||||
|
||||
private function defaultGrid()
|
||||
{
|
||||
return [
|
||||
'show' => false,
|
||||
'position' => 'back',
|
||||
'xaxis' => [
|
||||
'lines' => [
|
||||
'show' => true,
|
||||
],
|
||||
],
|
||||
'yaxis' => [
|
||||
'lines' => [
|
||||
'show' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function gridFromArray($array)
|
||||
{
|
||||
$this->grid = data_get($array, 'grid', $this->defaultGrid());
|
||||
}
|
||||
|
||||
protected function gridToArray()
|
||||
{
|
||||
return [
|
||||
'grid' => $this->grid,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user