Namespaced traits

This commit is contained in:
asantibanez
2024-08-22 12:56:14 -05:00
parent 343ebbaeee
commit 3014bb1ab3
12 changed files with 39 additions and 27 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasStroke
{
private $stroke;
private $width;
public function initStroke()
{
$this->stroke = $this->defaultStroke();
}
private function defaultStroke()
{
return [
'curve' => 'straight',
'width' => 4
];
}
public function setSmoothCurve()
{
data_set($this->stroke, 'curve', 'smooth');
return $this;
}
public function setStraightCurve()
{
data_set($this->stroke, 'curve', 'straight');
return $this;
}
public function setStrokeWidth($width)
{
data_set($this->stroke, 'width', $width);
return $this;
}
protected function strokeToArray()
{
return [
'stroke' => $this->stroke,
];
}
protected function strokeFromArray($array)
{
$this->stroke = data_get($array, 'stroke', $this->defaultStroke());
}
}