Skip to content

Commit

Permalink
Merge pull request #50 from syntaxlexx/theme-mods
Browse files Browse the repository at this point in the history
Feat: added theme setting options - dark mode, palette
  • Loading branch information
asantibanez authored Jul 25, 2023
2 parents ac1e613 + c408b63 commit 25b13b3
Show file tree
Hide file tree
Showing 11 changed files with 1,432 additions and 1,112 deletions.
2,393 changes: 1,284 additions & 1,109 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion public/app.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/app.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
*/

Expand Down
3 changes: 3 additions & 0 deletions resources/js/areaChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const areaChart = () => {
bottom: 0,
}
},

theme: component.get('areaChartModel.theme') || {},

};

this.chart = new ApexCharts(this.$refs.container, options);
Expand Down
3 changes: 3 additions & 0 deletions resources/js/columnChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,16 @@ const columnChart = () => {
opacity: component.get('columnChartModel.opacity') || 0.5
},

theme: component.get('columnChartModel.theme') || {},

tooltip: {
y: {
formatter: function(value, series) {
return data[series.dataPointIndex].extras.tooltip || value;
}
}
},

};

const colors = component.get('columnChartModel.colors');
Expand Down
2 changes: 2 additions & 0 deletions resources/js/lineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const lineChart = () => {

stroke: component.get('lineChartModel.stroke') || {},

theme: component.get('lineChartModel.theme') || {},

title: {
text: title,
align: 'center'
Expand Down
3 changes: 3 additions & 0 deletions resources/js/multiColumnChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const multiColumnChart = () => {
fill: {
opacity: component.get('columnChartModel.opacity'),
},

theme: component.get('columnChartModel.theme') || {},

};

const colors = component.get('columnChartModel.colors');
Expand Down
2 changes: 2 additions & 0 deletions resources/js/multiLineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const multiLineChart = () => {
},

yaxis: component.get('lineChartModel.yAxis') || {},

theme: component.get('lineChartModel.theme') || {},
};

const colors = component.get('lineChartModel.colors');
Expand Down
2 changes: 2 additions & 0 deletions resources/js/pieChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const pieChart = () => {

legend: component.get('pieChartModel.legend') || {},

theme: component.get('pieChartModel.theme') || {},

tooltip: {
y: {
formatter: function(value, series) {
Expand Down
4 changes: 4 additions & 0 deletions src/Models/BaseChartModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BaseChartModel
use HasSparkline;
use HasGrid;
use HasColors;
use HasTheme;
use HasJsonConfig;

public function __construct()
Expand All @@ -31,6 +32,7 @@ public function __construct()
$this->initSparkline();
$this->initGrid();
$this->initColors();
$this->initTheme();
$this->initJsonConfig();
}

Expand All @@ -51,6 +53,7 @@ public function toArray()
$this->sparklineToArray(),
$this->gridToArray(),
$this->colorsToArray(),
$this->themeToArray()
$this->jsonConfigToArray()
);
}
Expand All @@ -66,6 +69,7 @@ public function fromArray($array)
$this->sparklineFromArray($array);
$this->gridFromArray($array);
$this->colorsFromArray($array);
$this->themeFromArray($array);
$this->jsonConfigFromArray($array);
}
}
125 changes: 125 additions & 0 deletions src/Models/HasTheme.php
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 25b13b3

Please sign in to comment.