Simplify chart.js plugin initialization code and using kebab-case instead of snake_case for file names.

This commit is contained in:
Majid Al Zariey
2024-05-01 15:00:01 +03:00
parent 060101ffc3
commit 870f552985
3 changed files with 5 additions and 7 deletions
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -260,7 +260,7 @@ Here's a comprehensive guide on how to add custom plugins:
### Step 1: Create a Custom JavaScript File
Let's start by creating a new JavaScript file where you will define your custom plugin. In this case, we'll call it `custom_chart_plugins.js`.
Let's start by creating a new JavaScript file where you will define your custom plugin. In this case, we'll call it `custom-chart-plugins.js`.
### Step 2: Plugin Inclusion
@@ -288,7 +288,7 @@ export default defineConfig({
'resources/css/app.css',
'resources/js/app.js',
'resources/css/filament/admin/theme.css',
'resources/js/custom_chart_plugins.js' // Include the new file in the input array
'resources/js/custom-chart-plugins.js' // Include the new file in the input array
],
}),
],
@@ -309,7 +309,7 @@ class AppServiceProvider extends ServiceProvider
public function boot(): void
{
FilamentAsset::register([
Js::make('custom_plugins', Vite::asset('resources/js/custom_chart_plugins.js'))->module(), // Register the new file
Js::make('custom-plugins', Vite::asset('resources/js/custom-chart-plugins.js'))->module(), // Register the new file
]);
}
}
@@ -81,13 +81,11 @@ export default function chart({ cachedData, options, type }) {
options.scales.y.grid.color = gridColor
options.scales.y.grid.drawBorder ??= false
const plugins = window.customChartPlugins ?? [];
return new Chart(this.$refs.canvas, {
type: type,
data: data ?? cachedData,
options: options,
plugins: plugins,
plugins: window.customChartPlugins ?? [],
})
},