Skip to content

Commit

Permalink
Merge pull request #33 from pandigresik/master
Browse files Browse the repository at this point in the history
add options to custom override config in chart
  • Loading branch information
ArielMejiaDev committed Jan 24, 2024
2 parents f2afe8d + 4b09f79 commit 5a5bc9b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"nuxt.isNuxtApp": false
}
2 changes: 2 additions & 0 deletions src/LarapexChart.php
@@ -1,9 +1,11 @@
<?php namespace ArielMejiaDev\LarapexCharts;

use ArielMejiaDev\LarapexCharts\Traits\HasOptions;
use Illuminate\Support\Facades\View;

class LarapexChart
{
use HasOptions;
/*
|--------------------------------------------------------------------------
| Chart
Expand Down
6 changes: 5 additions & 1 deletion src/LarapexChartsServiceProvider.php
Expand Up @@ -47,7 +47,11 @@ public function boot()

$this->publishes([
$this->packageBasePath('config/larapex-charts.php') => base_path('config/larapex-charts.php')
], 'larapex-charts-config');
], 'larapex-charts-config');

$this->publishes([
$this->packageBasePath('stubs/Console/Commands') => app_path('Console/Commands')
], 'larapex-charts-commands');

$this->publishes([
$this->packageBasePath('stubs/stubs') => base_path('stubs')
Expand Down
56 changes: 56 additions & 0 deletions src/Traits/HasOptions.php
@@ -0,0 +1,56 @@
<?php
namespace ArielMejiaDev\LarapexCharts\Traits;
trait HasOptions{
protected $options;
/**
* Get the value of options
*/
public function getOptions()
{
return $this->options ? array_merge_recursive($this->getDefaultOption() ,$this->options) : $this->getDefaultOption();
}

/**
* Set the value of options
*
* @return self
*/
public function setOptions($options)
{
$this->options = $options;

return $this;
}

private function getDefaultOption(){
return [
'chart' => [
'type' => $this->type(),
'height' => $this->height(),
'width' => $this->width(),
'toolbar' => json_decode($this->toolbar()),
'zoom' => json_decode($this->zoom()),
'fontFamily' => json_decode($this->fontFamily()),
'foreColor' => $this->foreColor(),
],
'plotOptions' => [
'bar' => json_decode($this->horizontal()),
],
'colors' => json_decode($this->colors()),
'series' => json_decode($this->dataset()),
'dataLabels' => json_decode($this->dataLabels()),
'title' => [
'text' => $this->title()
],
'subtitle' => [
'text' => $this->subtitle() ? $this->subtitle() : '',
'align' => $this->subtitlePosition() ? $this->subtitlePosition() : '',
],
'xaxis' => [
'categories' => json_decode($this->xAxis()),
],
'grid' => json_decode($this->grid()),
'markers' => json_decode($this->markers()),
];
}
}

0 comments on commit 5a5bc9b

Please sign in to comment.