Merge branch 'master' of github.com:asantibanez/livewire-charts

This commit is contained in:
asantibanez
2023-07-25 13:50:56 -05:00
11 changed files with 1414 additions and 1094 deletions

2357
package-lock.json generated

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
/*!
* ApexCharts v3.22.2
* (c) 2018-2020 Juned Chhipa
* ApexCharts v3.27.3
* (c) 2018-2021 Juned Chhipa
* Released under the MIT License.
*/

View File

@@ -83,6 +83,9 @@ const areaChart = () => {
bottom: 0,
}
},
theme: component.get('areaChartModel.theme') || {},
};
this.chart = new ApexCharts(this.$refs.container, options);

View File

@@ -94,6 +94,8 @@ const columnChart = () => {
opacity: component.get('columnChartModel.opacity') || 0.5
},
theme: component.get('columnChartModel.theme') || {},
tooltip: {
y: {
formatter: function(value, series) {
@@ -101,6 +103,7 @@ const columnChart = () => {
}
}
},
};
const colors = component.get('columnChartModel.colors');

View File

@@ -61,6 +61,8 @@ const lineChart = () => {
stroke: component.get('lineChartModel.stroke') || {},
theme: component.get('lineChartModel.theme') || {},
title: {
text: title,
align: 'center'

View File

@@ -89,6 +89,9 @@ const multiColumnChart = () => {
fill: {
opacity: component.get('columnChartModel.opacity'),
},
theme: component.get('columnChartModel.theme') || {},
};
const colors = component.get('columnChartModel.colors');

View File

@@ -74,6 +74,8 @@ const multiLineChart = () => {
},
yaxis: component.get('lineChartModel.yAxis') || {},
theme: component.get('lineChartModel.theme') || {},
};
const colors = component.get('lineChartModel.colors');

View File

@@ -76,6 +76,8 @@ const pieChart = () => {
legend: component.get('pieChartModel.legend') || {},
theme: component.get('pieChartModel.theme') || {},
tooltip: {
y: {
formatter: function(value, series) {

View File

@@ -18,6 +18,7 @@ class BaseChartModel
use HasSparkline;
use HasGrid;
use HasColors;
use HasTheme;
use HasJsonConfig;
public function __construct()
@@ -31,6 +32,7 @@ class BaseChartModel
$this->initSparkline();
$this->initGrid();
$this->initColors();
$this->initTheme();
$this->initJsonConfig();
}
@@ -51,6 +53,7 @@ class BaseChartModel
$this->sparklineToArray(),
$this->gridToArray(),
$this->colorsToArray(),
$this->themeToArray()
$this->jsonConfigToArray()
);
}
@@ -66,6 +69,7 @@ class BaseChartModel
$this->sparklineFromArray($array);
$this->gridFromArray($array);
$this->colorsFromArray($array);
$this->themeFromArray($array);
$this->jsonConfigFromArray($array);
}
}

125
src/Models/HasTheme.php Normal file
View File

@@ -0,0 +1,125 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
trait HasTheme
{
private $theme;
private $mode;
private $palette;
/**
* Initialize
*/
public function initTheme()
{
$this->theme = $this->defaultTheme();
}
/**
* set default theme
*
* @return array $theme
*/
private function defaultTheme()
{
return [
'mode' => 'light',
'palette' => 'palette1'
];
}
/**
* set theme mode
*
* @param string $mode
*
* @return $this
*/
public function setThemeMode(string $mode)
{
data_set($this->theme, 'mode', $mode);
return $this;
}
/**
* set theme mode to dark theme
*
* @return $this
*/
public function darkMode()
{
data_set($this->theme, 'mode', 'dark');
return $this;
}
/**
* set theme mode to light theme
*
* @return $this
*/
public function lightMode()
{
data_set($this->theme, 'mode', 'light');
return $this;
}
/**
* set the dark mode option to on or off
*
* @param bool $status = true
*
* @return $this
*/
public function setDarkMode(bool $status = true)
{
data_set($this->theme, 'mode', $status ? 'dark' : 'light');
return $this;
}
/**
* set theme pallete
*
* @param string $pallete
*
* @return $this
*/
public function setThemePalette(string $palette)
{
data_set($this->theme, 'palette', $palette);
return $this;
}
/**
* convert the theme to array
*
* @param string $mode
*
* @return $this
*/
protected function themeToArray()
{
return [
'theme' => $this->theme,
];
}
/**
* set theme from array
*
* @param string $mode
*
* @return $this
*/
protected function themeFromArray($array)
{
$this->theme = data_get($array, 'theme', $this->defaultTheme());
}
}