Skip to content

Commit

Permalink
Allow treemaps and other custom chart types via plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Thomson committed May 29, 2024
1 parent 9dd848f commit 4a87ed9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions config/chartjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@

'custom_view' => false,

/*
|--------------------------------------------------------------------------
| Custom Chart Type Plugins
|--------------------------------------------------------------------------
|
| You can add plugins to Charjs for various custom chart types
| by adding the name of the chart type and the URL to the plugin.
| This is useful for adding custom chart types to the package
| without having to modify the package itself.
|
| Available choices are type labels and urls to CDNs. such as:
| 'treemap' => 'https://cdn.jsdelivr.net/npm/chartjs-chart-treemap@2.3.1/dist/chartjs-chart-treemap.min.js'
|
*/

'custom_chart_types' => []

];
7 changes: 5 additions & 2 deletions src/Support/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ class Config
{
public static function allowedChartTypes()
{
$base_types = ['bar', 'horizontalBar', 'bubble', 'scatter', 'doughnut', 'line', 'pie', 'polarArea', 'radar'];

if (self::chartJsVersion() > 3) {
return ['bar', 'bubble', 'scatter', 'doughnut', 'line', 'pie', 'polarArea', 'radar'];
$base_types = ['bar', 'bubble', 'scatter', 'doughnut', 'line', 'pie', 'polarArea', 'radar'];
}
return ['bar', 'horizontalBar', 'bubble', 'scatter', 'doughnut', 'line', 'pie', 'polarArea', 'radar'];

return array_merge($base_types, array_keys(config('chartjs.custom_chart_types', [])));
}

public static function chartJsVersion()
Expand Down
5 changes: 5 additions & 0 deletions src/resources/views/chart-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
@endif
<script src="https://cdn.jsdelivr.net/npm/numeral@2.0.6/numeral.min.js"></script>
@endif
@if(Config::get('chartjs.custom_chart_types'))
@foreach(Config::get('chartjs.custom_chart_types') as $label => $cdn)
<script src="{{ $cdn }}"></script>
@endforeach
@endif
@elseif($delivery == 'publish')
@if($version == 4)
<script type="module" src="{{ asset('vendor/laravelchartjs/chart.js') }}"></script>
Expand Down

0 comments on commit 4a87ed9

Please sign in to comment.