Added Stroke configuration

This commit is contained in:
Andrés Santibáñez
2020-10-25 00:18:20 -05:00
parent 472dfd8a4a
commit 8126b95593
5 changed files with 64 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ namespace Asantibanez\LivewireCharts\Models;
class BaseChartModel
{
use HasAxisConfiguration;
use HasStrokeConfiguration;
public function __construct()
{
@@ -26,11 +27,13 @@ class BaseChartModel
return [
'xAxis' => $this->xAxis,
'yAxis' => $this->yAxis,
'stroke' => $this->stroke,
];
}
public function fromArray($array)
{
$this->setupAxis($array);
$this->setupStroke($array);
}
}

View File

@@ -10,6 +10,12 @@ trait HasAxisConfiguration
private $yAxis;
public function __construct()
{
$this->xAxis = $this->defaultXAxis();
$this->yAxis = $this->defaultYAxis();
}
public function setXAxisVisible($visible)
{
data_set($this->xAxis, 'labels.show', $visible);

View File

@@ -0,0 +1,41 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
trait HasStrokeConfiguration
{
private $stroke;
public function __construct()
{
$this->stroke = $this->defaultStroke();
}
public function setSmoothCurve()
{
data_set($this->stroke, 'curve', 'smooth');
return $this;
}
public function setStraightCurve()
{
data_set($this->stroke, 'curve', 'straight');
return $this;
}
protected function setupStroke($array = [])
{
$this->stroke = data_get($array, 'stroke', $this->defaultStroke());
}
private function defaultStroke()
{
return [
'curve' => 'straight',
];
}
}

View File

@@ -7,7 +7,7 @@ namespace Asantibanez\LivewireCharts\Models;
* Class LineChartModel
* @package Asantibanez\LivewireCharts\Models
*/
class LineChartModel
class LineChartModel extends BaseChartModel
{
public $title;
@@ -21,6 +21,8 @@ class LineChartModel
public function __construct()
{
parent::__construct();
$this->title = '';
$this->animated = false;
@@ -85,17 +87,19 @@ class LineChartModel
public function toArray()
{
return [
return array_merge(parent::toArray(), [
'title' => $this->title,
'animated' => $this->animated,
'onPointClickEventName' => $this->onPointClickEventName,
'data' => $this->data->toArray(),
'markers' => $this->markers->toArray(),
];
]);
}
public function fromArray($array)
{
parent::fromArray($array);
$this->title = data_get($array, 'title', '');
$this->animated = data_get($array, 'animated', false);