Added ability to specify custom json config to charts

This commit is contained in:
asantibanez
2023-02-01 18:23:46 -05:00
parent 9f9554314e
commit 40828df23e
2 changed files with 44 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ class BaseChartModel
use HasSparkline;
use HasGrid;
use HasColors;
use HasJsonConfig;
public function __construct()
{
@@ -30,6 +31,7 @@ class BaseChartModel
$this->initSparkline();
$this->initGrid();
$this->initColors();
$this->initJsonConfig();
}
public function reactiveKey()
@@ -48,7 +50,8 @@ class BaseChartModel
$this->dataLabelsToArray(),
$this->sparklineToArray(),
$this->gridToArray(),
$this->colorsToArray()
$this->colorsToArray(),
$this->jsonConfigToArray()
);
}
@@ -63,5 +66,6 @@ class BaseChartModel
$this->sparklineFromArray($array);
$this->gridFromArray($array);
$this->colorsFromArray($array);
$this->jsonConfigFromArray($array);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
trait HasJsonConfig
{
private $jsonConfig;
public function setJsonConfig($jsonConfig)
{
$this->jsonConfig = $jsonConfig;
return $this;
}
protected function initJsonConfig()
{
$this->jsonConfig = [];
}
private function defaultJsonConfig()
{
return [];
}
protected function jsonConfigFromArray($array)
{
$this->jsonConfig = data_get($array, 'jsonConfig', $this->defaultJsonConfig());
}
protected function jsonConfigToArray()
{
return [
'jsonConfig' => $this->jsonConfig,
];
}
}