Added DataLabels support for charts
This commit is contained in:
@@ -14,6 +14,7 @@ class BaseChartModel
|
||||
use HasAxis;
|
||||
use HasStroke;
|
||||
use HasLegend;
|
||||
use HasDataLabels;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -22,6 +23,7 @@ class BaseChartModel
|
||||
$this->initAxis();
|
||||
$this->initStroke();
|
||||
$this->initLegend();
|
||||
$this->initDataLabels();
|
||||
}
|
||||
|
||||
public function reactiveKey()
|
||||
@@ -36,7 +38,8 @@ class BaseChartModel
|
||||
$this->animationToArray(),
|
||||
$this->axisToArray(),
|
||||
$this->strokeToArray(),
|
||||
$this->legendToArray()
|
||||
$this->legendToArray(),
|
||||
$this->dataLabelsToArray()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,5 +50,6 @@ class BaseChartModel
|
||||
$this->axisFromArray($array);
|
||||
$this->strokeFromArray($array);
|
||||
$this->legendFromArray($array);
|
||||
$this->dataLabelsFromArray($array);
|
||||
}
|
||||
}
|
||||
|
||||
55
src/Models/HasDataLabels.php
Normal file
55
src/Models/HasDataLabels.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Asantibanez\LivewireCharts\Models;
|
||||
|
||||
|
||||
trait HasDataLabels
|
||||
{
|
||||
private $dataLabels;
|
||||
|
||||
public function setDataLabelsEnabled($enabled)
|
||||
{
|
||||
data_set($this->dataLabels, 'enabled', $enabled);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withDataLabels()
|
||||
{
|
||||
data_set($this->dataLabels, 'enabled', true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withoutDataLabels()
|
||||
{
|
||||
data_set($this->dataLabels, 'enabled', false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function initDataLabels()
|
||||
{
|
||||
$this->dataLabels = $this->defaultDataLabels();
|
||||
}
|
||||
|
||||
private function defaultDataLabels()
|
||||
{
|
||||
return [
|
||||
'enabled' => false,
|
||||
];
|
||||
}
|
||||
|
||||
protected function dataLabelsFromArray($array)
|
||||
{
|
||||
$this->dataLabels = data_get($array, 'dataLabels', $this->defaultDataLabels());
|
||||
}
|
||||
|
||||
protected function dataLabelsToArray()
|
||||
{
|
||||
return [
|
||||
'dataLabels' => $this->dataLabels,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user