Added Stroke configuration
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
41
src/Models/HasStrokeConfiguration.php
Normal file
41
src/Models/HasStrokeConfiguration.php
Normal 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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user