Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
32
vendor/filament/widgets/composer.json
vendored
Normal file
32
vendor/filament/widgets/composer.json
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "filament/widgets",
|
||||
"description": "Easily add beautiful dashboard widgets to any Livewire component.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/filamentphp/filament",
|
||||
"support": {
|
||||
"issues": "https://github.com/filamentphp/filament/issues",
|
||||
"source": "https://github.com/filamentphp/filament"
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"filament/schemas": "self.version",
|
||||
"filament/support": "self.version"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Filament\\Widgets\\": "src"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Filament\\Widgets\\WidgetsServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
31
vendor/filament/widgets/dist/components/chart.js
vendored
Normal file
31
vendor/filament/widgets/dist/components/chart.js
vendored
Normal file
File diff suppressed because one or more lines are too long
20
vendor/filament/widgets/dist/components/stats-overview/stat/chart.js
vendored
Normal file
20
vendor/filament/widgets/dist/components/stats-overview/stat/chart.js
vendored
Normal file
File diff suppressed because one or more lines are too long
348
vendor/filament/widgets/docs/01-overview.md
vendored
Normal file
348
vendor/filament/widgets/docs/01-overview.md
vendored
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
---
|
||||
title: Overview
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament allows you to build dynamic dashboards, comprised of "widgets". Each widget is an element on the dashboard that displays data in a specific way. For example, you can display [stats](stats-overview), [chart](charts), or a [table](#table-widgets).
|
||||
|
||||
<AutoScreenshot name="panels/dashboard" alt="Dashboard with widgets" version="5.x" />
|
||||
|
||||
## Creating a widget
|
||||
|
||||
To create a widget, you can use the `make:filament-widget` command:
|
||||
|
||||
```bash
|
||||
php artisan make:filament-widget MyWidget
|
||||
```
|
||||
|
||||
This command will ask you which type of widget you want to create. You can choose from the following options:
|
||||
|
||||
- **Custom**: A custom widget that you can build from scratch.
|
||||
- **Chart**: A widget that displays a [chart](charts).
|
||||
- **Stats overview**: A widget that displays [statistics](stats-overview).
|
||||
- **Table**: A widget that displays a [table](#table-widgets).
|
||||
|
||||
## Sorting widgets
|
||||
|
||||
Each widget class contains a `$sort` property that may be used to change its order on the page, relative to other widgets:
|
||||
|
||||
```php
|
||||
protected static ?int $sort = 2;
|
||||
```
|
||||
|
||||
## Customizing the dashboard page
|
||||
|
||||
If you want to customize the dashboard class, for example, to [change the number of widget columns](#customizing-the-widgets-grid), create a new file at `app/Filament/Pages/Dashboard.php`:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Finally, remove the original `Dashboard` class from [configuration file](../panel-configuration):
|
||||
|
||||
```php
|
||||
use Filament\Panel;
|
||||
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
|
||||
->pages([]);
|
||||
}
|
||||
```
|
||||
|
||||
If you don't discover pages with `discoverPages()` in the directory you created the new dashboard class, you should manually register the class in the `pages()` method:
|
||||
|
||||
```php
|
||||
use App\Filament\Pages\Dashboard;
|
||||
use Filament\Panel;
|
||||
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->pages([
|
||||
Dashboard::class,
|
||||
]);
|
||||
}
|
||||
```
|
||||
|
||||
### Creating multiple dashboards
|
||||
|
||||
If you want to create multiple dashboards, you can do so by repeating [the process described above](#customizing-the-dashboard-page). Creating new pages that extend the `Dashboard` class will allow you to create as many dashboards as you need.
|
||||
|
||||
You will also need to define the URL path to the extra dashboard, otherwise it will be at `/`:
|
||||
|
||||
```php
|
||||
protected static string $routePath = 'finance';
|
||||
```
|
||||
|
||||
You may also customize the title of the dashboard by overriding the `$title` property:
|
||||
|
||||
```php
|
||||
protected static ?string $title = 'Finance dashboard';
|
||||
```
|
||||
|
||||
The primary dashboard shown to a user is the first one they have access to (controlled by [`canAccess()` method](../navigation/custom-pages#authorization)), according to the defined navigation sort order.
|
||||
|
||||
The default sort order for dashboards is `-2`. You can control the sort order of custom dashboards with `$navigationSort`:
|
||||
|
||||
```php
|
||||
protected static ?int $navigationSort = 15;
|
||||
```
|
||||
|
||||
### Customizing the widgets' grid
|
||||
|
||||
You may change how many grid columns are used to display widgets.
|
||||
|
||||
Firstly, you must [replace the original Dashboard page](#customizing-the-dashboard-page).
|
||||
|
||||
Now, in your new `app/Filament/Pages/Dashboard.php` file, you may override the `getColumns()` method to return a number of grid columns to use:
|
||||
|
||||
```php
|
||||
public function getColumns(): int | array
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
```
|
||||
|
||||
#### Responsive widgets grid
|
||||
|
||||
You may wish to change the number of widget grid columns based on the responsive [breakpoint](https://tailwindcss.com/docs/responsive-design#overview) of the browser. You can do this using an array that contains the number of columns that should be used at each breakpoint:
|
||||
|
||||
```php
|
||||
public function getColumns(): int | array
|
||||
{
|
||||
return [
|
||||
'md' => 4,
|
||||
'xl' => 5,
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
This pairs well with [responsive widget widths](#responsive-widget-widths).
|
||||
|
||||
#### Customizing widget width
|
||||
|
||||
You may customize the width of a widget using the `$columnSpan` property. You may use a number between 1 and 12 to indicate how many columns the widget should span, or `full` to make it occupy the full width of the page:
|
||||
|
||||
```php
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
```
|
||||
|
||||
##### Responsive widget widths
|
||||
|
||||
You may wish to change the widget width based on the responsive [breakpoint](https://tailwindcss.com/docs/responsive-design#overview) of the browser. You can do this using an array that contains the number of columns that the widget should occupy at each breakpoint:
|
||||
|
||||
```php
|
||||
protected int | string | array $columnSpan = [
|
||||
'md' => 2,
|
||||
'xl' => 3,
|
||||
];
|
||||
```
|
||||
|
||||
This is especially useful when using a [responsive widgets grid](#responsive-widgets-grid).
|
||||
|
||||
<AutoScreenshot name="panels/dashboard-column-spans" alt="Dashboard with customized widget column spans" version="5.x" />
|
||||
|
||||
## Conditionally hiding widgets
|
||||
|
||||
You may override the static `canView()` method on widgets to conditionally hide them:
|
||||
|
||||
```php
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
```
|
||||
|
||||
## Table widgets
|
||||
|
||||
You may easily add tables to your dashboard. Start by creating a widget with the command:
|
||||
|
||||
```bash
|
||||
php artisan make:filament-widget LatestOrders --table
|
||||
```
|
||||
|
||||
You may now [customize the table](../tables) by editing the widget file.
|
||||
|
||||
## Custom widgets
|
||||
|
||||
To get started building a `BlogPostsOverview` widget:
|
||||
|
||||
```bash
|
||||
php artisan make:filament-widget BlogPostsOverview
|
||||
```
|
||||
|
||||
This command will create two files - a widget class in the `/Widgets` directory of the Filament directory, and a view in the `/widgets` directory of the Filament views directory.
|
||||
|
||||
The class is a [Livewire component](https://livewire.laravel.com/docs/components), so any Livewire features are available to you. The Blade view can contain any HTML you like, and you can access any public Livewire properties in the view. You can also access the Livewire component instance in the view using `$this`.
|
||||
|
||||
## Filtering widget data
|
||||
|
||||
You may add a form to the dashboard that allows the user to filter the data displayed across all widgets. When the filters are updated, the widgets will be reloaded with the new data.
|
||||
|
||||
Firstly, you must [replace the original Dashboard page](#customizing-the-dashboard-page).
|
||||
|
||||
Now, in your new `app/Filament/Pages/Dashboard.php` file, you may add the `HasFiltersForm` trait, and add the `filtersForm()` method to return form components:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
use HasFiltersForm;
|
||||
|
||||
public function filtersForm(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make()
|
||||
->schema([
|
||||
DatePicker::make('startDate'),
|
||||
DatePicker::make('endDate'),
|
||||
// ...
|
||||
])
|
||||
->columns(3),
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="panels/dashboard-filters" alt="Dashboard with filter form" version="5.x" />
|
||||
|
||||
In widget classes that require data from the filters, you need to add the `InteractsWithPageFilters` trait, which will allow you to use the `$this->pageFilters` property to access the raw data from the filters form:
|
||||
|
||||
```php
|
||||
use App\Models\BlogPost;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BlogPostsOverview extends StatsOverviewWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
public function getStats(): array
|
||||
{
|
||||
$startDate = $this->pageFilters['startDate'] ?? null;
|
||||
$endDate = $this->pageFilters['endDate'] ?? null;
|
||||
|
||||
return [
|
||||
StatsOverviewWidget\Stat::make(
|
||||
label: 'Total posts',
|
||||
value: BlogPost::query()
|
||||
->when($startDate, fn (Builder $query) => $query->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn (Builder $query) => $query->whereDate('created_at', '<=', $endDate))
|
||||
->count(),
|
||||
),
|
||||
// ...
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `$this->pageFilters` array will always reflect the current form data. Please note that this data is not validated, as it is available live and not intended to be used for anything other than querying the database. You must ensure that the data is valid before using it. In this example, we check if the start date is set before using it in the query.
|
||||
|
||||
### Filtering widget data using an action modal
|
||||
|
||||
Alternatively, you can swap out the filters form for an action modal, that can be opened by clicking a button in the header of the page. There are many benefits to using this approach:
|
||||
|
||||
- The filters form is not always visible, which allows you to use the full height of the page for widgets.
|
||||
- The filters do not update the widgets until the user clicks the "Apply" button, which means that the widgets are not reloaded until the user is ready. This can improve performance if the widgets are expensive to load.
|
||||
- Validation can be performed on the filters form, which means that the widgets can rely on the fact that the data is valid - the user cannot submit the form until it is. Canceling the modal will discard the user's changes.
|
||||
|
||||
To use an action modal instead of a filters form, you can use the `HasFiltersAction` trait instead of `HasFiltersForm`. Then, register the `FilterAction` class as an action in `getHeaderActions()`:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Pages\Dashboard\Actions\FilterAction;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersAction;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
use HasFiltersAction;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
FilterAction::make()
|
||||
->schema([
|
||||
DatePicker::make('startDate'),
|
||||
DatePicker::make('endDate'),
|
||||
// ...
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Handling data from the filter action is the same as handling data from the filters header form, except that the data is validated before being passed to the widget. The `InteractsWithPageFilters` trait still applies.
|
||||
|
||||
<AutoScreenshot name="panels/dashboard-filter-action" alt="Dashboard with filter action modal" version="5.x" />
|
||||
|
||||
### Persisting widget filters in the user's session
|
||||
|
||||
By default, the dashboard filters applied will persist in the user's session between page loads. To disable this, override the `$persistsFiltersInSession` property in the dashboard page class:
|
||||
|
||||
```php
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
use HasFiltersForm;
|
||||
|
||||
protected bool $persistsFiltersInSession = false;
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively, override the `persistsFiltersInSession()` method in the dashboard page class:
|
||||
|
||||
```php
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
use HasFiltersForm;
|
||||
|
||||
public function persistsFiltersInSession(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Disabling the default widgets
|
||||
|
||||
By default, two widgets are displayed on the dashboard. These widgets can be disabled by updating the `widgets()` array of the [configuration](../panel-configuration):
|
||||
|
||||
```php
|
||||
use Filament\Panel;
|
||||
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
return $panel
|
||||
// ...
|
||||
->widgets([]);
|
||||
}
|
||||
```
|
||||
259
vendor/filament/widgets/docs/02-stats-overview.md
vendored
Normal file
259
vendor/filament/widgets/docs/02-stats-overview.md
vendored
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
---
|
||||
title: Stats overview widgets
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament comes with a "stats overview" widget template, which you can use to display a number of different stats in a single widget, without needing to write a custom view.
|
||||
|
||||
Start by creating a widget with the command:
|
||||
|
||||
```bash
|
||||
php artisan make:filament-widget StatsOverview --stats-overview
|
||||
```
|
||||
|
||||
This command will create a new `StatsOverview.php` file. Open it, and return `Stat` instances from the `getStats()` method:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class StatsOverview extends BaseWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Unique views', '192.1k'),
|
||||
Stat::make('Bounce rate', '21%'),
|
||||
Stat::make('Average time on page', '3:12'),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now, check out your widget in the dashboard.
|
||||
|
||||
<AutoScreenshot name="widgets/stats-overview/simple" alt="Stats overview" version="5.x" />
|
||||
|
||||
## Adding a description and icon to a stat
|
||||
|
||||
You may add a `description()` to provide additional information, along with a `descriptionIcon()`:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Unique views', '192.1k')
|
||||
->description('32k increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up'),
|
||||
Stat::make('Bounce rate', '21%')
|
||||
->description('7% decrease')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-down'),
|
||||
Stat::make('Average time on page', '3:12')
|
||||
->description('3% increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up'),
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
The `descriptionIcon()` method also accepts a second parameter to put the icon before the description instead of after it:
|
||||
|
||||
```php
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
Stat::make('Unique views', '192.1k')
|
||||
->description('32k increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up', IconPosition::Before)
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/stats-overview/description" alt="Stats overview with descriptions" version="5.x" />
|
||||
|
||||
## Changing the color of the stat
|
||||
|
||||
You may also give stats a [color](../styling/colors):
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Unique views', '192.1k')
|
||||
->description('32k increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->color('success'),
|
||||
Stat::make('Bounce rate', '21%')
|
||||
->description('7% increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-down')
|
||||
->color('danger'),
|
||||
Stat::make('Average time on page', '3:12')
|
||||
->description('3% increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->color('success'),
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/stats-overview/color" alt="Stats overview with colors" version="5.x" />
|
||||
|
||||
## Adding extra HTML attributes to a stat
|
||||
|
||||
You may also pass extra HTML attributes to stats using `extraAttributes()`:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Processed', '192.1k')
|
||||
->color('success')
|
||||
->extraAttributes([
|
||||
'class' => 'cursor-pointer',
|
||||
'wire:click' => "\$dispatch('setStatusFilter', { filter: 'processed' })",
|
||||
]),
|
||||
// ...
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we are deliberately escaping the `$` in `$dispatch()` since this needs to be passed directly to the HTML, it is not a PHP variable.
|
||||
|
||||
## Setting a placeholder for a stat
|
||||
|
||||
Sometimes a stat's value may not be available — for example, when a dashboard has nothing to show for a specific period. You can use `placeholder()` to define what should be displayed instead when the value is blank:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
Stat::make('Unique views', $uniqueViews)
|
||||
->placeholder('-')
|
||||
```
|
||||
|
||||
A value is considered blank according to Laravel's `blank()` helper. For example, `null` and empty strings are blank, while `0` and `'0'` are not.
|
||||
|
||||
### Setting a default placeholder globally
|
||||
|
||||
If you'd like every stat in your app to fall back to the same placeholder by default, you can use the static `configureUsing()` method in a service provider's `boot()` method:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
Stat::configureUsing(function (Stat $component): void {
|
||||
$component->placeholder('-');
|
||||
});
|
||||
```
|
||||
|
||||
Individual stats can still override this by calling `placeholder()` themselves.
|
||||
|
||||
## Adding a chart to a stat
|
||||
|
||||
You may also add or chain a `chart()` to each stat to provide historical data. The `chart()` method accepts an array of data points to plot:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Unique views', '192.1k')
|
||||
->description('32k increase')
|
||||
->descriptionIcon('heroicon-m-arrow-trending-up')
|
||||
->chart([7, 2, 10, 3, 15, 4, 17])
|
||||
->color('success'),
|
||||
// ...
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/stats-overview/chart" alt="Stats overview with charts" version="5.x" />
|
||||
|
||||
## Styling stat charts in a theme
|
||||
|
||||
Chart.js paints a stat's chart onto a `<canvas>`, so its line cannot be reached from a stylesheet. A [custom theme](../styling/overview) is CSS only, so Filament exposes the shape of that line as CSS custom properties, which you may set on `.fi-wi-stats-overview-stat`, or on any element above it to cover every stat in the panel at once:
|
||||
|
||||
```css
|
||||
.fi-wi-stats-overview-stat {
|
||||
--stat-chart-border-width: 1;
|
||||
--stat-chart-line-tension: 0;
|
||||
--stat-chart-fill: none;
|
||||
}
|
||||
```
|
||||
|
||||
`--stat-chart-border-width` thickens the line, `--stat-chart-line-tension` curves it, from `0` for straight segments up to `1`, and `--stat-chart-fill` shades the area beneath it, accepting `start`, `end`, `origin` or `stack`, as well as `none` to leave the line bare.
|
||||
|
||||
These values are handed to Chart.js rather than used by the browser, so they are plain numbers and keywords, without units. If you set one to something Chart.js cannot use, it is ignored and the chart keeps its default. They are also read again whenever the color scheme changes, so you may give light and dark mode different values.
|
||||
|
||||
The chart takes its colors from the [color of the stat](#changing-the-color-of-the-stat). To change them in a theme, style the `.fi-wi-stats-overview-stat-chart-bg-color` and `.fi-wi-stats-overview-stat-chart-border-color` elements with an ordinary `color` declaration:
|
||||
|
||||
```css
|
||||
.fi-wi-stats-overview-stat {
|
||||
& .fi-wi-stats-overview-stat-chart-border-color {
|
||||
@apply text-gray-400 dark:text-gray-500;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Aside variant="info">
|
||||
These properties only affect the charts inside stats. [Chart widgets](charts#styling-charts-in-a-theme) are styled with their own set, prefixed `--chart-`.
|
||||
</Aside>
|
||||
|
||||
## Live updating stats (polling)
|
||||
|
||||
By default, stats overview widgets refresh their data every 5 seconds.
|
||||
|
||||
To customize this, you may override the `$pollingInterval` property on the class to a new interval:
|
||||
|
||||
```php
|
||||
protected ?string $pollingInterval = '10s';
|
||||
```
|
||||
|
||||
Alternatively, you may disable polling altogether:
|
||||
|
||||
```php
|
||||
protected ?string $pollingInterval = null;
|
||||
```
|
||||
|
||||
## Disabling lazy loading
|
||||
|
||||
By default, widgets are lazy-loaded. This means that they will only be loaded when they are visible on the page.
|
||||
|
||||
To disable this behavior, you may override the `$isLazy` property on the widget class:
|
||||
|
||||
```php
|
||||
protected static bool $isLazy = false;
|
||||
```
|
||||
|
||||
## Adding a heading and description
|
||||
|
||||
You may also add heading and description text above the widget by overriding the `$heading` and `$description` properties:
|
||||
|
||||
```php
|
||||
protected ?string $heading = 'Analytics';
|
||||
|
||||
protected ?string $description = 'An overview of some analytics.';
|
||||
```
|
||||
|
||||
If you need to dynamically generate the heading or description text, you can instead override the `getHeading()` and `getDescription()` methods:
|
||||
|
||||
```php
|
||||
protected function getHeading(): ?string
|
||||
{
|
||||
return 'Analytics';
|
||||
}
|
||||
|
||||
protected function getDescription(): ?string
|
||||
{
|
||||
return 'An overview of some analytics.';
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/stats-overview/heading" alt="Stats overview with heading and description" version="5.x" />
|
||||
662
vendor/filament/widgets/docs/03-charts.md
vendored
Normal file
662
vendor/filament/widgets/docs/03-charts.md
vendored
Normal file
|
|
@ -0,0 +1,662 @@
|
|||
---
|
||||
title: Chart widgets
|
||||
---
|
||||
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
||||
import Aside from "@components/Aside.astro"
|
||||
|
||||
## Introduction
|
||||
|
||||
Filament comes with many "chart" widget templates, which you can use to display real-time, interactive charts.
|
||||
|
||||
Start by creating a widget with the command:
|
||||
|
||||
```bash
|
||||
php artisan make:filament-widget BlogPostsChart --chart
|
||||
```
|
||||
|
||||
There is a single `ChartWidget` class that is used for all charts. The type of chart is set by the `getType()` method. In this example, that method returns the string `'line'`.
|
||||
|
||||
The `protected ?string $heading` variable is used to set the heading that describes the chart. If you need to set the heading dynamically, you can override the `getHeading()` method.
|
||||
|
||||
The `getData()` method is used to return an array of datasets and labels. Each dataset is a labeled array of points to plot on the chart, and each label is a string. This structure is identical to the [Chart.js](https://www.chartjs.org/docs) library, which Filament uses to render charts. You may use the [Chart.js documentation](https://www.chartjs.org/docs) to fully understand the possibilities to return from `getData()`, based on the chart type.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class BlogPostsChart extends ChartWidget
|
||||
{
|
||||
protected ?string $heading = 'Blog Posts';
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Blog posts created',
|
||||
'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
|
||||
],
|
||||
],
|
||||
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now, check out your widget in the dashboard.
|
||||
|
||||
<AutoScreenshot name="widgets/chart/line" alt="Line chart" version="5.x" />
|
||||
|
||||
## Available chart types
|
||||
|
||||
Below is a list of available chart widget classes which you may extend, and their corresponding [Chart.js](https://www.chartjs.org/docs) documentation page, for inspiration on what to return from `getData()`:
|
||||
|
||||
- Bar chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/bar)
|
||||
- Bubble chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/bubble)
|
||||
- Doughnut chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/doughnut)
|
||||
- Line chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/line)
|
||||
- Pie chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/doughnut.html#pie)
|
||||
- Polar area chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/polar)
|
||||
- Radar chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/radar)
|
||||
- Scatter chart - [Chart.js documentation](https://www.chartjs.org/docs/latest/charts/scatter)
|
||||
|
||||
For example, you could use a bar chart by returning `'bar'` from the `getType()` method:
|
||||
|
||||
<AutoScreenshot name="widgets/chart/bar" alt="Bar chart" version="5.x" />
|
||||
|
||||
Here are examples of the other available chart types:
|
||||
|
||||
<AutoScreenshot name="widgets/chart/pie" alt="Pie chart" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="widgets/chart/doughnut" alt="Doughnut chart" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="widgets/chart/radar" alt="Radar chart" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="widgets/chart/polar-area" alt="Polar area chart" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="widgets/chart/scatter" alt="Scatter chart" version="5.x" />
|
||||
|
||||
<AutoScreenshot name="widgets/chart/bubble" alt="Bubble chart" version="5.x" />
|
||||
|
||||
## Customizing the chart color
|
||||
|
||||
You can customize the [color](../styling/colors) of the chart data by setting the `$color` property:
|
||||
|
||||
```php
|
||||
protected string $color = 'info';
|
||||
```
|
||||
|
||||
If you're looking to customize the color further, or use multiple colors across multiple datasets, you can still make use of Chart.js's [color options](https://www.chartjs.org/docs/latest/general/colors.html) in the data:
|
||||
|
||||
```php
|
||||
protected function getData(): array
|
||||
{
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Blog posts created',
|
||||
'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
|
||||
'backgroundColor' => '#36A2EB',
|
||||
'borderColor' => '#9BD0F5',
|
||||
],
|
||||
],
|
||||
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
## Generating chart data from an Eloquent model
|
||||
|
||||
To generate chart data from an Eloquent model, Filament recommends that you install the `flowframe/laravel-trend` package. You can view the [documentation](https://github.com/Flowframe/laravel-trend).
|
||||
|
||||
Here is an example of generating chart data from a model using the `laravel-trend` package:
|
||||
|
||||
```php
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Trend::model(BlogPost::class)
|
||||
->between(
|
||||
start: now()->startOfYear(),
|
||||
end: now()->endOfYear(),
|
||||
)
|
||||
->perMonth()
|
||||
->count();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Blog posts',
|
||||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn (TrendValue $value) => $value->date),
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
## Filtering chart data
|
||||
|
||||
### Basic Select filter
|
||||
|
||||
You can set up chart filters to change the data that is presented. Commonly, this is used to change the time period that chart data is rendered for.
|
||||
|
||||
To set a default filter value, set the `$filter` property:
|
||||
|
||||
```php
|
||||
public ?string $filter = 'today';
|
||||
```
|
||||
|
||||
Then, define the `getFilters()` method to return an array of values and labels for your filter:
|
||||
|
||||
```php
|
||||
protected function getFilters(): ?array
|
||||
{
|
||||
return [
|
||||
'today' => 'Today',
|
||||
'week' => 'Last week',
|
||||
'month' => 'Last month',
|
||||
'year' => 'This year',
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
You can use the active filter value within your `getData()` method:
|
||||
|
||||
```php
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/chart/filter" alt="Chart with filter" version="5.x" />
|
||||
|
||||
<Aside variant="danger">
|
||||
The `$filter` property is user-controllable. Although the `<select>` element only offers the keys returned from `getFilters()`, a crafted request can set `$this->filter` to any string, so it is not limited to those keys. You must ensure the value is valid before using it in a query — for example, by checking it against the keys of `getFilters()`, or by using a `match` expression with a safe default. Never interpolate `$this->filter` directly into a raw query.
|
||||
</Aside>
|
||||
|
||||
### Custom filters
|
||||
|
||||
You can use [schema components](../schemas) to build custom filters for your chart widget. This approach offers a more flexible way to define filters.
|
||||
|
||||
To get started, use the `HasFiltersSchema` trait and implement the `filtersSchema()` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Widgets\ChartWidget\Concerns\HasFiltersSchema;
|
||||
|
||||
class BlogPostsChart extends ChartWidget
|
||||
{
|
||||
use HasFiltersSchema;
|
||||
|
||||
// ...
|
||||
|
||||
public function filtersSchema(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
DatePicker::make('startDate')
|
||||
->default(now()->subDays(30)),
|
||||
DatePicker::make('endDate')
|
||||
->default(now()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The filter values are accessible via the `$this->filters` array. You can use these values inside your `getData()` method:
|
||||
|
||||
```php
|
||||
protected function getData(): array
|
||||
{
|
||||
$startDate = $this->filters['startDate'] ?? null;
|
||||
$endDate = $this->filters['endDate'] ?? null;
|
||||
|
||||
return [
|
||||
// ...
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
The `$this->filters` array will always reflect the current form data. Please note that this data is not validated, as it is available live and not intended to be used for anything other than querying the database. You must ensure that the data is valid before using it.
|
||||
|
||||
<AutoScreenshot name="widgets/chart/custom-filters" alt="Chart with custom filters" version="5.x" />
|
||||
|
||||
<Aside variant="info">
|
||||
If you want to add filters that apply to multiple widgets at once, see [filtering widget data](overview#filtering-widget-data) in the dashboard.
|
||||
</Aside>
|
||||
|
||||
#### Deferring filter updates
|
||||
|
||||
By default, filters using the `filtersSchema()` method update the chart data immediately as they are changed. However, for complex queries or better user experience, you may want to **defer** filter updates until the user clicks an "Apply" button.
|
||||
|
||||
When deferred, filter changes are only applied when the user clicks the "Apply" button. This ensures that the chart only re-renders when the user has finished adjusting all of their filters.
|
||||
|
||||
The chart will display data using the default filter values when the page first loads, ensuring users see meaningful data immediately without needing to take action.
|
||||
|
||||
To enable deferred filters, set the `$hasDeferredFilters` property to `true`:
|
||||
|
||||
```php
|
||||
use Filament\Widgets\ChartWidget\Concerns\HasFiltersSchema;
|
||||
|
||||
class BlogPostsChart extends ChartWidget
|
||||
{
|
||||
use HasFiltersSchema;
|
||||
|
||||
protected bool $hasDeferredFilters = true;
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
If you need dynamic control over whether filters are deferred, you may override the `hasDeferredFilters()` method:
|
||||
|
||||
```php
|
||||
public function hasDeferredFilters(): bool
|
||||
{
|
||||
return auth()->user()->prefersDeferredFilters();
|
||||
}
|
||||
```
|
||||
|
||||
#### Resetting filters to defaults
|
||||
|
||||
When using deferred filters, a "Reset" link appears in the filter dropdown footer alongside the "Apply" button. Clicking this link restores all filters to their default values as defined in the `filtersSchema()` method. For example, if you set `->default(now()->subDays(30))` on a `DatePicker`, the reset action will restore that default date, not an empty value.
|
||||
|
||||
#### Customizing filter actions
|
||||
|
||||
You may customize the apply and reset actions that appear when using deferred filters. All methods that are available to [customize action trigger buttons](../actions/overview) can be used:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
public function filtersApplyAction(Action $action): Action
|
||||
{
|
||||
return $action
|
||||
->label('Update Chart')
|
||||
->color('success');
|
||||
}
|
||||
|
||||
public function filtersResetAction(Action $action): Action
|
||||
{
|
||||
return $action
|
||||
->label('Clear Filters')
|
||||
->color('danger');
|
||||
}
|
||||
```
|
||||
|
||||
## Empty state
|
||||
|
||||
When the `getData()` method returns an empty array, the chart widget renders an "empty state" instead of the chart.
|
||||
|
||||
To customize when the empty state is rendered, override the `isEmpty()` method:
|
||||
|
||||
```php
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
$data = $this->getCachedData();
|
||||
|
||||
return empty($data['datasets'][0]['data'] ?? []);
|
||||
}
|
||||
```
|
||||
|
||||
### Setting the empty state heading
|
||||
|
||||
To customize the heading of the empty state, set the `$emptyStateHeading` property:
|
||||
|
||||
```php
|
||||
protected ?string $emptyStateHeading = 'No data available';
|
||||
```
|
||||
|
||||
Alternatively, you can override the `getEmptyStateHeading()` method to return a dynamic heading:
|
||||
|
||||
```php
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
public function getEmptyStateHeading(): string | Htmlable
|
||||
{
|
||||
return "No sales yet for {$this->filter}";
|
||||
}
|
||||
```
|
||||
|
||||
### Setting the empty state description
|
||||
|
||||
To customize the description of the empty state, set the `$emptyStateDescription` property:
|
||||
|
||||
```php
|
||||
protected ?string $emptyStateDescription = 'Check back later once data has been collected.';
|
||||
```
|
||||
|
||||
Alternatively, you can override the `getEmptyStateDescription()` method to return a dynamic description:
|
||||
|
||||
```php
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
public function getEmptyStateDescription(): string | Htmlable | null
|
||||
{
|
||||
return 'Sales data will appear here once orders are placed.';
|
||||
}
|
||||
```
|
||||
|
||||
### Setting the empty state icon
|
||||
|
||||
To customize the [icon](../styling/icons) of the empty state, set the `$emptyStateIcon` property:
|
||||
|
||||
```php
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
protected string | BackedEnum | null $emptyStateIcon = Heroicon::OutlinedChartBar;
|
||||
```
|
||||
|
||||
Alternatively, you can override the `getEmptyStateIcon()` method to return a dynamic icon:
|
||||
|
||||
```php
|
||||
use BackedEnum;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
public function getEmptyStateIcon(): string | BackedEnum | Htmlable
|
||||
{
|
||||
return Heroicon::OutlinedShoppingCart;
|
||||
}
|
||||
```
|
||||
|
||||
### Adding empty state actions
|
||||
|
||||
You can add [actions](../actions/overview) to the empty state to prompt users to take action by overriding the `getEmptyStateActions()` method:
|
||||
|
||||
```php
|
||||
use Filament\Actions\Action;
|
||||
|
||||
public function getEmptyStateActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('refresh')
|
||||
->label('Refresh')
|
||||
->action('refresh'),
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
### Using a custom empty state view
|
||||
|
||||
You may use a completely custom empty state view by overriding the `getEmptyState()` method:
|
||||
|
||||
```php
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
public function getEmptyState(): View | Htmlable | null
|
||||
{
|
||||
return view('widgets.charts.custom-empty-state');
|
||||
}
|
||||
```
|
||||
|
||||
## Live updating chart data (polling)
|
||||
|
||||
By default, chart widgets refresh their data every 5 seconds.
|
||||
|
||||
To customize this, you may override the `$pollingInterval` property on the class to a new interval:
|
||||
|
||||
```php
|
||||
protected ?string $pollingInterval = '10s';
|
||||
```
|
||||
|
||||
Alternatively, you may disable polling altogether:
|
||||
|
||||
```php
|
||||
protected ?string $pollingInterval = null;
|
||||
```
|
||||
|
||||
## Setting a maximum chart height
|
||||
|
||||
You may place a maximum height on the chart to ensure that it doesn't get too big, using the `$maxHeight` property:
|
||||
|
||||
```php
|
||||
protected ?string $maxHeight = '300px';
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/chart/max-height" alt="Chart with maximum height" version="5.x" />
|
||||
|
||||
## Setting chart configuration options
|
||||
|
||||
You may specify an `$options` variable on the chart class to control the many configuration options that the Chart.js library provides. For instance, you could turn off the [legend](https://www.chartjs.org/docs/latest/configuration/legend.html) for a line chart:
|
||||
|
||||
```php
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'display' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
Alternatively, you can override the `getOptions()` method to return a dynamic array of options:
|
||||
|
||||
```php
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'display' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
These PHP arrays will get transformed into JSON objects when the chart is rendered. If you want to return raw JavaScript from this method instead, you can return a `RawJs` object. This is useful if you want to use a JavaScript callback function, for example:
|
||||
|
||||
```php
|
||||
use Filament\Support\RawJs;
|
||||
|
||||
protected function getOptions(): RawJs
|
||||
{
|
||||
return RawJs::make(<<<JS
|
||||
{
|
||||
scales: {
|
||||
y: {
|
||||
ticks: {
|
||||
callback: (value) => '€' + value,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
JS);
|
||||
}
|
||||
```
|
||||
|
||||
## Styling charts in a theme
|
||||
|
||||
Chart.js paints a chart onto a `<canvas>`, so almost none of it can be reached from a stylesheet. A [custom theme](../styling/overview) is CSS only and cannot call `getOptions()`, so Filament exposes the parts of a chart that a theme is most likely to want to change as CSS custom properties. You may set them on `.fi-wi-chart`, or on any element above it to cover every chart in the panel at once:
|
||||
|
||||
```css
|
||||
.fi-wi-chart {
|
||||
--chart-border-width: 1;
|
||||
--chart-line-tension: 0.4;
|
||||
--chart-point-radius: 3;
|
||||
--chart-point-style: rect;
|
||||
--chart-bar-border-radius: 4;
|
||||
}
|
||||
```
|
||||
|
||||
`--chart-border-width` sets the thickness of the line that a chart draws around its data. `--chart-line-tension` curves the line of a line chart, from `0` for straight segments up to `1`. `--chart-point-radius` sizes the markers on a line, radar or scatter chart, and `--chart-point-style` shapes them, accepting any of Chart.js' point styles - `circle`, `cross`, `crossRot`, `dash`, `line`, `rect`, `rectRounded`, `rectRot`, `star` or `triangle` - as well as `none` to hide them entirely. `--chart-bar-border-radius` rounds the corners of the bars in a bar chart, which are already slightly rounded by default. Set it to `0` for square bars.
|
||||
|
||||
These values are handed to Chart.js rather than used by the browser, so they are plain numbers and keywords, without units. If you set one to something Chart.js cannot use, it is ignored and the chart keeps its default. They are also read again whenever the color scheme changes, so you may give light and dark mode different values.
|
||||
|
||||
<Aside variant="info">
|
||||
These properties are for styling every chart in a panel at once, which is what a theme usually wants. To change a single chart, use [`getOptions()`](#setting-chart-configuration-options) instead - anything you set there wins over the properties here.
|
||||
</Aside>
|
||||
|
||||
### Styling the chart legend
|
||||
|
||||
The legend beneath a chart is drawn onto the canvas as well. Two properties control the color swatch next to each label:
|
||||
|
||||
```css
|
||||
.fi-wi-chart {
|
||||
--chart-legend-box-width: 16;
|
||||
--chart-legend-border-radius: 0;
|
||||
}
|
||||
```
|
||||
|
||||
`--chart-legend-box-width` sets how wide each swatch is, and `--chart-legend-border-radius` rounds its corners, which are slightly rounded by default to match the bars of a bar chart. Set it to `0` for square swatches.
|
||||
|
||||
### Styling chart tooltips
|
||||
|
||||
The tooltip that appears when hovering over a chart is drawn onto the canvas as well. Its shape comes from two more properties:
|
||||
|
||||
```css
|
||||
.fi-wi-chart {
|
||||
--chart-tooltip-corner-radius: 0;
|
||||
--chart-tooltip-border-width: 1;
|
||||
}
|
||||
```
|
||||
|
||||
Its colors are set differently, so that you can use the same palette and dark mode variants as the rest of your theme. Filament reads them from elements that you style with an ordinary `color` declaration:
|
||||
|
||||
```css
|
||||
.fi-wi-chart {
|
||||
& .fi-wi-chart-tooltip-bg-color {
|
||||
@apply text-gray-900 dark:text-white;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-tooltip-text-color {
|
||||
@apply text-white dark:text-gray-900;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-tooltip-border-color {
|
||||
@apply text-gray-700 dark:text-gray-200;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
A tooltip has no border until you give it a width, so `--chart-tooltip-border-width` and `.fi-wi-chart-tooltip-border-color` usually change together.
|
||||
|
||||
The colors of the chart itself work in the same way: `.fi-wi-chart-bg-color` and `.fi-wi-chart-border-color` fill and outline the data, `.fi-wi-chart-grid-color` draws the grid lines, and `.fi-wi-chart-text-color` labels the axes.
|
||||
|
||||
The small charts inside a [stats overview widget](stats-overview#styling-stat-charts-in-a-theme) are styled separately, with their own set of properties.
|
||||
|
||||
## Adding a description
|
||||
|
||||
You may add a description, below the heading of the chart, using the `getDescription()` method:
|
||||
|
||||
```php
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return 'The number of blog posts published per month.';
|
||||
}
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/chart/description" alt="Chart with description" version="5.x" />
|
||||
|
||||
## Disabling lazy loading
|
||||
|
||||
By default, widgets are lazy-loaded. This means that they will only be loaded when they are visible on the page.
|
||||
|
||||
To disable this behavior, you may override the `$isLazy` property on the widget class:
|
||||
|
||||
```php
|
||||
protected static bool $isLazy = false;
|
||||
```
|
||||
|
||||
## Making the chart collapsible
|
||||
|
||||
You may allow the chart to be collapsible by setting the `$isCollapsible` property on the widget class to be `true`:
|
||||
|
||||
```php
|
||||
protected bool $isCollapsible = true;
|
||||
```
|
||||
|
||||
<AutoScreenshot name="widgets/chart/collapsible" alt="Collapsible chart" version="5.x" />
|
||||
|
||||
## Using custom Chart.js plugins
|
||||
|
||||
Chart.js offers a powerful plugin system that allows you to extend its functionality and create custom chart behaviors. This guide details how to use them in a chart widget.
|
||||
|
||||
### Step 1: Install the plugin with NPM
|
||||
|
||||
To start with, install the plugin using NPM into your project. In this guide, we will install [`chartjs-plugin-datalabels`](https://chartjs-plugin-datalabels.netlify.app/guide/getting-started.html#installation):
|
||||
|
||||
```bash
|
||||
npm install chartjs-plugin-datalabels --save-dev
|
||||
```
|
||||
|
||||
### Step 2: Create a JavaScript file importing the plugin
|
||||
|
||||
Create a new JavaScript file where you will define your custom plugin. In this guide, we'll call it `filament-chart-js-plugins.js`. Import the plugin, and add it to the `window.filamentChartJsPlugins` array:
|
||||
|
||||
```javascript
|
||||
import ChartDataLabels from 'chartjs-plugin-datalabels'
|
||||
|
||||
window.filamentChartJsPlugins ??= []
|
||||
window.filamentChartJsPlugins.push(ChartDataLabels)
|
||||
```
|
||||
|
||||
This is equivalent to including the plugins "inline" via `new Chart(..., { plugins: [...] })` when instantiating a Chart.js chart.
|
||||
|
||||
It's important to initialise the array if it has not been already, before pushing onto it. This ensures that multiple JavaScript files (especially those from Filament plugins) that register Chart.js plugins do not overwrite each other, regardless of the order they are booted in.
|
||||
|
||||
You can push as many plugins to the array as you would like to install, you do not need a separate file to import each plugin.
|
||||
|
||||
Additionally, you can also register any "global plugins" which will use `Chart.register([...])` in the `window.filamentChartJsGlobalPlugins` array:
|
||||
|
||||
```javascript
|
||||
import ChartDataLabels from 'chartjs-plugin-datalabels'
|
||||
|
||||
window.filamentChartJsGlobalPlugins ??= []
|
||||
window.filamentChartJsGlobalPlugins.push(ChartDataLabels)
|
||||
```
|
||||
|
||||
### Step 3: Compile the JavaScript file with Vite
|
||||
|
||||
Now, you need to build the JavaScript file with Vite, or your bundler of choice. Include the file in your Vite configuration (usually `vite.config.js`). For example:
|
||||
|
||||
```javascript
|
||||
import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
laravel({
|
||||
input: [
|
||||
'resources/css/app.css',
|
||||
'resources/js/app.js',
|
||||
'resources/css/filament/admin/theme.css',
|
||||
'resources/js/filament-chart-js-plugins.js', // Include the new file in the `input` array so it is built
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
Build the file with `npm run build`.
|
||||
|
||||
### Step 4: Register the JavaScript file in Filament
|
||||
|
||||
Filament needs to know to include this JavaScript file when rendering chart widgets. You can do this in the `boot()` method of a service provider like `AppServiceProvider`:
|
||||
|
||||
```php
|
||||
use Filament\Support\Assets\Js;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
|
||||
FilamentAsset::register([
|
||||
Js::make('chart-js-plugins', Vite::asset('resources/js/filament-chart-js-plugins.js'))->module(),
|
||||
]);
|
||||
```
|
||||
|
||||
You can find out more about [asset registration](../advanced/assets), and even [register assets for a specific panel](../panel-configuration#registering-assets-for-a-panel).
|
||||
88
vendor/filament/widgets/resources/css/chart-widget.css
vendored
Normal file
88
vendor/filament/widgets/resources/css/chart-widget.css
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
.fi-wi-chart {
|
||||
& .fi-wi-chart-frame {
|
||||
@apply mx-auto flex w-full items-center justify-center;
|
||||
|
||||
&:not(.fi-wi-chart-frame-no-aspect-ratio) {
|
||||
@apply aspect-square;
|
||||
}
|
||||
}
|
||||
|
||||
@supports (container-type: inline-size) {
|
||||
& .fi-section-content {
|
||||
@apply @container;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-frame:not(.fi-wi-chart-frame-no-aspect-ratio) {
|
||||
@apply @sm:aspect-[1.5];
|
||||
}
|
||||
}
|
||||
|
||||
@supports not (container-type: inline-size) {
|
||||
& .fi-wi-chart-frame:not(.fi-wi-chart-frame-no-aspect-ratio) {
|
||||
@apply sm:aspect-[1.5];
|
||||
}
|
||||
}
|
||||
|
||||
& .fi-wi-chart-filter {
|
||||
&.fi-input-wrp {
|
||||
@apply w-max sm:-my-2;
|
||||
}
|
||||
|
||||
&.fi-dropdown {
|
||||
& .fi-wi-chart-filter-content {
|
||||
@apply grid gap-y-4 p-6;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-filter-content-actions-ctn {
|
||||
@apply flex gap-3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
& .fi-color {
|
||||
& .fi-wi-chart-bg-color {
|
||||
@apply text-color-50 dark:text-color-400/10;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-border-color {
|
||||
@apply text-color-500 dark:text-color-400;
|
||||
}
|
||||
}
|
||||
|
||||
& .fi-wi-chart-bg-color {
|
||||
@apply text-gray-100 dark:text-gray-800;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-border-color {
|
||||
@apply text-gray-400;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-grid-color {
|
||||
@apply text-gray-200 dark:text-gray-800;
|
||||
}
|
||||
|
||||
& .fi-wi-chart-text-color {
|
||||
@apply text-gray-500 dark:text-gray-400;
|
||||
}
|
||||
|
||||
/* Tooltips are painted onto the canvas, so these three elements are the only way to
|
||||
color them. Their values are Chart.js' own tooltip colors rather than Filament
|
||||
palette values, which is why they are written out longhand instead of `@apply`.
|
||||
The border only appears once `--chart-tooltip-border-width` is set, so its
|
||||
color defaults to a hairline that suits the background above it. */
|
||||
& .fi-wi-chart-tooltip-bg-color {
|
||||
color: rgb(0 0 0 / 0.8);
|
||||
}
|
||||
|
||||
& .fi-wi-chart-tooltip-text-color {
|
||||
color: rgb(255 255 255);
|
||||
}
|
||||
|
||||
& .fi-wi-chart-tooltip-border-color {
|
||||
color: rgb(255 255 255 / 0.2);
|
||||
}
|
||||
|
||||
& .fi-empty-state {
|
||||
@apply p-0;
|
||||
}
|
||||
}
|
||||
3
vendor/filament/widgets/resources/css/index.css
vendored
Normal file
3
vendor/filament/widgets/resources/css/index.css
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@import './chart-widget.css' layer(components);
|
||||
@import './stats-overview-widget.css' layer(components);
|
||||
@import './widget.css' layer(components);
|
||||
67
vendor/filament/widgets/resources/css/stats-overview-widget.css
vendored
Normal file
67
vendor/filament/widgets/resources/css/stats-overview-widget.css
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
.fi-wi-stats-overview-stat {
|
||||
@apply focus-visible:ring-primary-600 dark:focus-visible:ring-primary-500 relative block h-full rounded-xl bg-white p-6 shadow-sm ring-1 ring-gray-950/5 outline-none focus-visible:ring-2 dark:bg-gray-900 dark:ring-white/10;
|
||||
|
||||
& .fi-icon {
|
||||
@apply shrink-0 text-gray-400 dark:text-gray-500;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-content {
|
||||
@apply grid gap-y-2;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-label-ctn {
|
||||
@apply flex items-center gap-x-2;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-label {
|
||||
@apply text-sm font-medium text-gray-500 dark:text-gray-400;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-value {
|
||||
/* Tabular figures: stat values are near-always numeric, and polled
|
||||
widgets would otherwise reflow as digit widths change. */
|
||||
@apply text-3xl font-semibold tracking-tight text-gray-950 tabular-nums dark:text-white;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-placeholder {
|
||||
@apply text-3xl font-medium text-gray-500 dark:text-gray-400;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-description {
|
||||
@apply flex items-center gap-x-1 text-sm text-gray-500 dark:text-gray-400;
|
||||
|
||||
&.fi-color {
|
||||
@apply text-(--text) dark:text-(--dark-text);
|
||||
|
||||
& .fi-icon {
|
||||
@apply text-color-500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-chart {
|
||||
@apply absolute inset-x-0 bottom-0 overflow-hidden rounded-b-xl;
|
||||
|
||||
& > canvas {
|
||||
@apply h-6;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-chart-bg-color {
|
||||
@apply text-gray-100 dark:text-gray-800;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-chart-border-color {
|
||||
@apply text-gray-400;
|
||||
}
|
||||
|
||||
&.fi-color {
|
||||
& .fi-wi-stats-overview-stat-chart-bg-color {
|
||||
@apply text-color-50 dark:text-color-400/10;
|
||||
}
|
||||
|
||||
& .fi-wi-stats-overview-stat-chart-border-color {
|
||||
@apply text-color-500 dark:text-color-400;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
vendor/filament/widgets/resources/css/widget.css
vendored
Normal file
3
vendor/filament/widgets/resources/css/widget.css
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.fi-wi {
|
||||
@apply gap-6;
|
||||
}
|
||||
434
vendor/filament/widgets/resources/js/components/chart.js
vendored
Normal file
434
vendor/filament/widgets/resources/js/components/chart.js
vendored
Normal file
|
|
@ -0,0 +1,434 @@
|
|||
import Chart from 'chart.js/auto'
|
||||
import { color } from 'chart.js/helpers'
|
||||
import 'chartjs-adapter-luxon'
|
||||
import readCustomProperties from '../custom-properties'
|
||||
|
||||
const darken = (value, amount) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry) => darken(entry, amount))
|
||||
}
|
||||
|
||||
const parsed = color(value)
|
||||
|
||||
return parsed.valid ? parsed.darken(amount).rgbString() : value
|
||||
}
|
||||
|
||||
if (
|
||||
window.filamentChartJsGlobalPlugins &&
|
||||
Array.isArray(window.filamentChartJsGlobalPlugins) &&
|
||||
window.filamentChartJsGlobalPlugins.length > 0
|
||||
) {
|
||||
Chart.register(...window.filamentChartJsGlobalPlugins)
|
||||
}
|
||||
|
||||
Chart.defaults.plugins.legend.position = 'bottom'
|
||||
|
||||
export default function chart({ cachedData, options, type }) {
|
||||
return {
|
||||
userBackgroundColor: options?.backgroundColor,
|
||||
userBorderColor: options?.borderColor,
|
||||
userTextColor: options?.color,
|
||||
userPointBackgroundColor: options?.pointBackgroundColor,
|
||||
userXGridColor: options?.scales?.x?.grid?.color,
|
||||
userYGridColor: options?.scales?.y?.grid?.color,
|
||||
userRadialGridColor: options?.scales?.r?.grid?.color,
|
||||
userRadialTicksColor: options?.scales?.r?.ticks?.color,
|
||||
userTooltipBackgroundColor: options?.plugins?.tooltip?.backgroundColor,
|
||||
userTooltipTitleColor: options?.plugins?.tooltip?.titleColor,
|
||||
userTooltipBodyColor: options?.plugins?.tooltip?.bodyColor,
|
||||
userTooltipBorderColor: options?.plugins?.tooltip?.borderColor,
|
||||
userLineTension: options?.tension,
|
||||
userPointStyle: options?.pointStyle,
|
||||
userBarBorderRadius: options?.borderRadius,
|
||||
userTooltipCornerRadius: options?.plugins?.tooltip?.cornerRadius,
|
||||
userTooltipBorderWidth: options?.plugins?.tooltip?.borderWidth,
|
||||
userLegendBorderRadius: options?.plugins?.legend?.labels?.borderRadius,
|
||||
userLegendUseBorderRadius:
|
||||
options?.plugins?.legend?.labels?.useBorderRadius,
|
||||
userLegendBoxWidth: options?.plugins?.legend?.labels?.boxWidth,
|
||||
userBorderWidth: options?.borderWidth,
|
||||
userPointRadius: options?.pointRadius,
|
||||
|
||||
init() {
|
||||
this.$wire.$on('updateChartData', ({ data }) =>
|
||||
this.updateChartData(data),
|
||||
)
|
||||
|
||||
Alpine.effect(() => {
|
||||
Alpine.store('theme')
|
||||
|
||||
this.$nextTick(() => this.updateChartTheme())
|
||||
})
|
||||
|
||||
this.systemThemeMediaQuery = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)',
|
||||
)
|
||||
this.systemThemeListener = () => {
|
||||
if (Alpine.store('theme') !== 'system') {
|
||||
return
|
||||
}
|
||||
|
||||
this.$nextTick(() => this.updateChartTheme())
|
||||
}
|
||||
this.systemThemeMediaQuery.addEventListener(
|
||||
'change',
|
||||
this.systemThemeListener,
|
||||
)
|
||||
|
||||
// Defer `initChart()` to `$nextTick` so the `Alpine.effect` above runs its
|
||||
// mandatory first invocation before the chart exists. `updateChartTheme()` then
|
||||
// exits early on that first run; otherwise the effect would tear down and
|
||||
// recreate the chart on every mount.
|
||||
this.$nextTick(() => {
|
||||
this.initChart()
|
||||
|
||||
this.resizeObserver = new ResizeObserver(() =>
|
||||
this.getChart()?.resize(),
|
||||
)
|
||||
this.resizeObserver.observe(this.$el)
|
||||
|
||||
this.dprChangeHandler = Alpine.debounce(
|
||||
() => this.handleDprChange(),
|
||||
250,
|
||||
)
|
||||
window.addEventListener('resize', this.dprChangeHandler)
|
||||
})
|
||||
},
|
||||
|
||||
initChart() {
|
||||
if (
|
||||
!this.$refs.canvas ||
|
||||
!this.$refs.backgroundColorElement ||
|
||||
!this.$refs.borderColorElement ||
|
||||
!this.$refs.textColorElement ||
|
||||
!this.$refs.gridColorElement
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const fontFamily = getComputedStyle(this.$el).fontFamily
|
||||
const hasMaxHeight = this.$refs.canvas.style.maxHeight !== '100%'
|
||||
|
||||
options ??= {}
|
||||
options.animation ??= {}
|
||||
options.animation.duration ??= 0
|
||||
options.font ??= {}
|
||||
options.font.family ??= fontFamily
|
||||
options.responsive ??= false
|
||||
options.maintainAspectRatio ??= hasMaxHeight
|
||||
options.pointHitRadius ??= 4
|
||||
options.scales ??= {}
|
||||
options.scales.x ??= {}
|
||||
options.scales.x.border ??= {}
|
||||
options.scales.x.border.display ??= false
|
||||
options.scales.x.grid ??= {}
|
||||
options.scales.x.grid.display ??= false
|
||||
options.scales.y ??= {}
|
||||
options.scales.y.border ??= {}
|
||||
options.scales.y.border.display ??= false
|
||||
options.scales.y.grid ??= {}
|
||||
|
||||
if (['doughnut', 'pie', 'polarArea'].includes(type)) {
|
||||
options.scales.x.display ??= false
|
||||
options.scales.y.display ??= false
|
||||
options.scales.y.grid.display ??= false
|
||||
|
||||
options.elements ??= {}
|
||||
options.elements.arc ??= {}
|
||||
|
||||
options.plugins ??= {}
|
||||
options.plugins.legend ??= {}
|
||||
options.plugins.legend.labels ??= {}
|
||||
options.plugins.legend.labels.generateLabels ??= (chart) => {
|
||||
const labels =
|
||||
Chart.overrides[
|
||||
type
|
||||
].plugins.legend.labels.generateLabels(chart)
|
||||
|
||||
for (const label of labels) {
|
||||
label.strokeStyle = darken(label.fillStyle, 0.2)
|
||||
}
|
||||
|
||||
return labels
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'polarArea') {
|
||||
options.scales.r ??= {}
|
||||
options.scales.r.grid ??= {}
|
||||
options.scales.r.ticks ??= {}
|
||||
options.scales.r.ticks.backdropColor ??= 'transparent'
|
||||
}
|
||||
|
||||
this.applyChartColors(options)
|
||||
this.applyChartCustomProperties(options)
|
||||
this.normalizeDatasets(cachedData)
|
||||
|
||||
new Chart(this.$refs.canvas, {
|
||||
type,
|
||||
data: cachedData,
|
||||
options,
|
||||
plugins: window.filamentChartJsPlugins ?? [],
|
||||
})
|
||||
},
|
||||
|
||||
updateChartData(newData) {
|
||||
const chart = this.getChart()
|
||||
|
||||
if (!chart) {
|
||||
return
|
||||
}
|
||||
|
||||
this.normalizeDatasets(newData)
|
||||
chart.data = newData
|
||||
chart.update('resize')
|
||||
},
|
||||
|
||||
normalizeDatasets(data) {
|
||||
for (const dataset of data?.datasets ?? []) {
|
||||
if (type === 'bar' && dataset.backgroundColor !== undefined) {
|
||||
dataset.borderColor ??= darken(dataset.backgroundColor, 0.2)
|
||||
dataset.hoverBorderColor ??= darken(
|
||||
dataset.backgroundColor,
|
||||
0.3,
|
||||
)
|
||||
}
|
||||
|
||||
if (
|
||||
type === 'scatter' &&
|
||||
dataset.backgroundColor !== undefined
|
||||
) {
|
||||
dataset.borderColor ??= dataset.backgroundColor
|
||||
}
|
||||
|
||||
if (
|
||||
['line', 'scatter'].includes(type) &&
|
||||
dataset.borderColor !== undefined
|
||||
) {
|
||||
dataset.pointBackgroundColor ??= dataset.borderColor
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateChartTheme() {
|
||||
const chart = this.getChart()
|
||||
|
||||
if (!chart) {
|
||||
return
|
||||
}
|
||||
|
||||
this.applyChartColors(chart.options)
|
||||
this.applyChartCustomProperties(chart.options)
|
||||
|
||||
// Not `'none'`: that is one of Chart.js' "direct update" modes, which reuse a
|
||||
// cached snapshot of the options shared between a dataset's elements instead of
|
||||
// refreshing it. Every per-element option - bar and arc colors, point colors,
|
||||
// point radius and style - would keep the value it was built with. `'resize'`
|
||||
// refreshes them, and its transition is already zero-duration, so nothing
|
||||
// animates. It is the mode `updateChartData()` uses for the same reason.
|
||||
chart.update('resize')
|
||||
},
|
||||
|
||||
applyChartColors(options) {
|
||||
const {
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
textColor,
|
||||
gridColor,
|
||||
tooltipBackgroundColor,
|
||||
tooltipTextColor,
|
||||
tooltipBorderColor,
|
||||
} = this.getChartColors()
|
||||
|
||||
const resolvedBorderColor = this.userBorderColor ?? borderColor
|
||||
|
||||
options.backgroundColor =
|
||||
this.userBackgroundColor ?? backgroundColor
|
||||
options.borderColor = resolvedBorderColor
|
||||
options.color = this.userTextColor ?? textColor
|
||||
options.pointBackgroundColor =
|
||||
this.userPointBackgroundColor ?? resolvedBorderColor
|
||||
|
||||
options.elements ??= {}
|
||||
options.elements.bar ??= {}
|
||||
options.elements.bar.borderColor = resolvedBorderColor
|
||||
|
||||
// The tooltip color elements arrived after the others, so a published copy of
|
||||
// the view may not have them; without them Chart.js keeps its own colors.
|
||||
if (this.$refs.tooltipBackgroundColorElement) {
|
||||
options.plugins ??= {}
|
||||
options.plugins.tooltip ??= {}
|
||||
options.plugins.tooltip.backgroundColor =
|
||||
this.userTooltipBackgroundColor ?? tooltipBackgroundColor
|
||||
options.plugins.tooltip.titleColor =
|
||||
this.userTooltipTitleColor ?? tooltipTextColor
|
||||
options.plugins.tooltip.bodyColor =
|
||||
this.userTooltipBodyColor ?? tooltipTextColor
|
||||
options.plugins.tooltip.borderColor =
|
||||
this.userTooltipBorderColor ?? tooltipBorderColor
|
||||
}
|
||||
|
||||
if (['doughnut', 'pie', 'polarArea'].includes(type)) {
|
||||
options.elements.arc ??= {}
|
||||
options.elements.arc.borderColor =
|
||||
this.getSurroundingBackgroundColor()
|
||||
}
|
||||
|
||||
options.scales.x.grid.color = this.userXGridColor ?? gridColor
|
||||
options.scales.y.grid.color = this.userYGridColor ?? gridColor
|
||||
|
||||
if (type === 'polarArea') {
|
||||
options.scales.r.grid.color =
|
||||
this.userRadialGridColor ?? gridColor
|
||||
options.scales.r.ticks.color =
|
||||
this.userRadialTicksColor ?? textColor
|
||||
}
|
||||
},
|
||||
|
||||
handleDprChange() {
|
||||
const chart = this.getChart()
|
||||
|
||||
if (!chart) {
|
||||
return
|
||||
}
|
||||
|
||||
if (chart.currentDevicePixelRatio !== window.devicePixelRatio) {
|
||||
chart.resize()
|
||||
}
|
||||
},
|
||||
|
||||
getChart() {
|
||||
if (!this.$refs.canvas) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Chart.getChart(this.$refs.canvas)
|
||||
},
|
||||
|
||||
getSurroundingBackgroundColor() {
|
||||
let element = this.$el.parentElement
|
||||
|
||||
while (element) {
|
||||
const backgroundColor =
|
||||
getComputedStyle(element).backgroundColor
|
||||
|
||||
if (
|
||||
backgroundColor &&
|
||||
backgroundColor !== 'rgba(0, 0, 0, 0)' &&
|
||||
backgroundColor !== 'transparent'
|
||||
) {
|
||||
return backgroundColor
|
||||
}
|
||||
|
||||
element = element.parentElement
|
||||
}
|
||||
|
||||
return '#ffffff'
|
||||
},
|
||||
|
||||
getChartColors() {
|
||||
const sentinelColor = (element) =>
|
||||
element ? getComputedStyle(element).color : null
|
||||
|
||||
return {
|
||||
backgroundColor: getComputedStyle(
|
||||
this.$refs.backgroundColorElement,
|
||||
).color,
|
||||
borderColor: getComputedStyle(this.$refs.borderColorElement)
|
||||
.color,
|
||||
textColor: getComputedStyle(this.$refs.textColorElement).color,
|
||||
gridColor: getComputedStyle(this.$refs.gridColorElement).color,
|
||||
tooltipBackgroundColor: sentinelColor(
|
||||
this.$refs.tooltipBackgroundColorElement,
|
||||
),
|
||||
tooltipTextColor: sentinelColor(
|
||||
this.$refs.tooltipTextColorElement,
|
||||
),
|
||||
tooltipBorderColor: sentinelColor(
|
||||
this.$refs.tooltipBorderColorElement,
|
||||
),
|
||||
}
|
||||
},
|
||||
|
||||
applyChartCustomProperties(options) {
|
||||
const {
|
||||
lineTension,
|
||||
pointStyle,
|
||||
barBorderRadius,
|
||||
tooltipCornerRadius,
|
||||
tooltipBorderWidth,
|
||||
legendBorderRadius,
|
||||
legendBoxWidth,
|
||||
borderWidth,
|
||||
pointRadius,
|
||||
} = this.getChartCustomProperties()
|
||||
|
||||
options.borderWidth = this.userBorderWidth ?? borderWidth
|
||||
options.tension = this.userLineTension ?? lineTension
|
||||
options.pointStyle = this.userPointStyle ?? pointStyle
|
||||
options.pointRadius = this.userPointRadius ?? pointRadius
|
||||
|
||||
if (type === 'bar') {
|
||||
options.borderRadius =
|
||||
this.userBarBorderRadius ?? barBorderRadius
|
||||
}
|
||||
|
||||
options.plugins ??= {}
|
||||
options.plugins.tooltip ??= {}
|
||||
options.plugins.tooltip.cornerRadius =
|
||||
this.userTooltipCornerRadius ?? tooltipCornerRadius
|
||||
options.plugins.tooltip.borderWidth =
|
||||
this.userTooltipBorderWidth ?? tooltipBorderWidth
|
||||
|
||||
const resolvedLegendBorderRadius =
|
||||
this.userLegendBorderRadius ?? legendBorderRadius
|
||||
|
||||
options.plugins.legend ??= {}
|
||||
options.plugins.legend.labels ??= {}
|
||||
options.plugins.legend.labels.borderRadius =
|
||||
resolvedLegendBorderRadius
|
||||
// Chart.js ignores the radius unless this is on, and treats a radius of `0` as
|
||||
// "inherit from the data" rather than "square", so it is derived rather than
|
||||
// exposed as a property of its own.
|
||||
options.plugins.legend.labels.useBorderRadius =
|
||||
this.userLegendUseBorderRadius ?? resolvedLegendBorderRadius > 0
|
||||
options.plugins.legend.labels.boxWidth =
|
||||
this.userLegendBoxWidth ?? legendBoxWidth
|
||||
},
|
||||
|
||||
// The parts of a chart that a stylesheet cannot otherwise reach, since Chart.js
|
||||
// paints them onto a bare `<canvas>`. This covers the static appearance of what is
|
||||
// painted, including everything Filament pins to a value of its own; how a chart
|
||||
// behaves - animation, hit areas, which scales it shows - belongs in `getOptions()`.
|
||||
// Each fallback is the default it stands in for: Chart.js' own, except where the
|
||||
// panel's design language asks for something else. Bars and legend swatches are
|
||||
// slightly rounded, since nothing else in Filament has square corners, and the
|
||||
// tooltip's `4` is the radius `tippy.js` gives every other tooltip in a panel.
|
||||
getChartCustomProperties() {
|
||||
const { number, keyword } = readCustomProperties(this.$el)
|
||||
|
||||
return {
|
||||
lineTension: number('--chart-line-tension', 0),
|
||||
pointStyle: keyword('--chart-point-style', 'circle'),
|
||||
barBorderRadius: number('--chart-bar-border-radius', 2),
|
||||
tooltipCornerRadius: number('--chart-tooltip-corner-radius', 4),
|
||||
tooltipBorderWidth: number('--chart-tooltip-border-width', 0),
|
||||
legendBorderRadius: number('--chart-legend-border-radius', 2),
|
||||
legendBoxWidth: number('--chart-legend-box-width', 12),
|
||||
borderWidth: number('--chart-border-width', 2),
|
||||
pointRadius: number('--chart-point-radius', 2),
|
||||
}
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.resizeObserver?.disconnect()
|
||||
this.dprChangeHandler &&
|
||||
window.removeEventListener('resize', this.dprChangeHandler)
|
||||
this.systemThemeMediaQuery?.removeEventListener(
|
||||
'change',
|
||||
this.systemThemeListener,
|
||||
)
|
||||
this.getChart()?.destroy()
|
||||
},
|
||||
}
|
||||
}
|
||||
197
vendor/filament/widgets/resources/js/components/stats-overview/stat/chart.js
vendored
Normal file
197
vendor/filament/widgets/resources/js/components/stats-overview/stat/chart.js
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
import {
|
||||
CategoryScale,
|
||||
Chart,
|
||||
Filler,
|
||||
LineController,
|
||||
LineElement,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
} from 'chart.js'
|
||||
|
||||
import readCustomProperties from '../../../custom-properties'
|
||||
|
||||
Chart.register(
|
||||
CategoryScale,
|
||||
Filler,
|
||||
LineController,
|
||||
LineElement,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
)
|
||||
|
||||
export default function statsOverviewStatChart({ key, labels, values }) {
|
||||
return {
|
||||
key,
|
||||
|
||||
init() {
|
||||
this.$wire.$on('updateStatsOverviewChartData', (event) => {
|
||||
if (event.key === this.key) {
|
||||
this.updateChartData(event.data)
|
||||
}
|
||||
})
|
||||
|
||||
Alpine.effect(() => {
|
||||
Alpine.store('theme')
|
||||
|
||||
this.$nextTick(() => this.updateChartTheme())
|
||||
})
|
||||
|
||||
this.systemThemeMediaQuery = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)',
|
||||
)
|
||||
this.systemThemeListener = () => {
|
||||
if (Alpine.store('theme') !== 'system') {
|
||||
return
|
||||
}
|
||||
|
||||
this.$nextTick(() => this.updateChartTheme())
|
||||
}
|
||||
this.systemThemeMediaQuery.addEventListener(
|
||||
'change',
|
||||
this.systemThemeListener,
|
||||
)
|
||||
|
||||
// Defer `initChart()` to `$nextTick` so the `Alpine.effect` above runs its
|
||||
// mandatory first invocation before the chart exists. `updateChartTheme()` then
|
||||
// exits early on that first run.
|
||||
this.$nextTick(() => this.initChart())
|
||||
},
|
||||
|
||||
initChart() {
|
||||
if (
|
||||
!this.$refs.canvas ||
|
||||
!this.$refs.backgroundColorElement ||
|
||||
!this.$refs.borderColorElement
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
// Defensively tear down any pre-existing chart bound to this canvas before
|
||||
// constructing a new one (the canvas is reused if the component re-initializes).
|
||||
this.getChart()?.destroy()
|
||||
|
||||
const { backgroundColor, borderColor } = this.getChartColors()
|
||||
const { borderWidth, fill, lineTension } =
|
||||
this.getChartCustomProperties()
|
||||
|
||||
new Chart(this.$refs.canvas, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
data: values,
|
||||
borderWidth,
|
||||
fill,
|
||||
tension: lineTension,
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
animation: {
|
||||
duration: 0,
|
||||
},
|
||||
elements: {
|
||||
point: {
|
||||
radius: 0,
|
||||
},
|
||||
},
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
tooltip: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
display: false,
|
||||
},
|
||||
y: {
|
||||
display: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
updateChartData(newValues) {
|
||||
const chart = this.getChart()
|
||||
|
||||
if (!chart) {
|
||||
return
|
||||
}
|
||||
|
||||
chart.data.labels = newValues.map((value, index) => index)
|
||||
chart.data.datasets[0].data = newValues
|
||||
chart.update('none')
|
||||
},
|
||||
|
||||
updateChartTheme() {
|
||||
const chart = this.getChart()
|
||||
|
||||
if (!chart) {
|
||||
return
|
||||
}
|
||||
|
||||
const { backgroundColor, borderColor } = this.getChartColors()
|
||||
|
||||
// The custom properties are re-read too: a theme may legitimately give light
|
||||
// and dark mode a different line.
|
||||
const { borderWidth, fill, lineTension } =
|
||||
this.getChartCustomProperties()
|
||||
|
||||
chart.data.datasets[0].backgroundColor = backgroundColor
|
||||
chart.data.datasets[0].borderColor = borderColor
|
||||
chart.data.datasets[0].borderWidth = borderWidth
|
||||
chart.data.datasets[0].fill = fill
|
||||
chart.data.datasets[0].tension = lineTension
|
||||
|
||||
// `'resize'` rather than `'none'`, for the reason given in the chart widget.
|
||||
chart.update('resize')
|
||||
},
|
||||
|
||||
getChart() {
|
||||
if (!this.$refs.canvas) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Chart.getChart(this.$refs.canvas)
|
||||
},
|
||||
|
||||
getChartColors() {
|
||||
return {
|
||||
backgroundColor: getComputedStyle(
|
||||
this.$refs.backgroundColorElement,
|
||||
).color,
|
||||
borderColor: getComputedStyle(this.$refs.borderColorElement)
|
||||
.color,
|
||||
}
|
||||
},
|
||||
|
||||
// The parts of the sparkline that a stylesheet cannot otherwise reach, since
|
||||
// Chart.js paints them onto a bare `<canvas>`. Each fallback is the value the
|
||||
// sparkline has always used.
|
||||
getChartCustomProperties() {
|
||||
const { number, keyword } = readCustomProperties(this.$el)
|
||||
|
||||
return {
|
||||
borderWidth: number('--stat-chart-border-width', 2),
|
||||
fill: keyword('--stat-chart-fill', 'start'),
|
||||
lineTension: number('--stat-chart-line-tension', 0.5),
|
||||
}
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this.systemThemeMediaQuery?.removeEventListener(
|
||||
'change',
|
||||
this.systemThemeListener,
|
||||
)
|
||||
this.getChart()?.destroy()
|
||||
},
|
||||
}
|
||||
}
|
||||
28
vendor/filament/widgets/resources/js/custom-properties.js
vendored
Normal file
28
vendor/filament/widgets/resources/js/custom-properties.js
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Chart.js paints a chart onto a bare `<canvas>`, so its shape is unreachable from a
|
||||
// stylesheet. The `--chart-*` and `--stat-chart-*` custom properties bridge that
|
||||
// gap, and this is how the chart components read them.
|
||||
//
|
||||
// An unset property reads back as an empty string, so every call passes the default it
|
||||
// stands in for as a `fallback`. That keeps each default in one place, and leaves a value
|
||||
// Chart.js cannot use to be ignored by Chart.js rather than second-guessed here.
|
||||
export default function readCustomProperties(element) {
|
||||
const styles = getComputedStyle(element)
|
||||
|
||||
const read = (property) => styles.getPropertyValue(property).trim()
|
||||
|
||||
return {
|
||||
number: (property, fallback) => {
|
||||
const value = parseFloat(read(property))
|
||||
|
||||
return Number.isNaN(value) ? fallback : value
|
||||
},
|
||||
|
||||
// Chart.js switches a feature off with boolean `false`, and a custom property can
|
||||
// only ever yield the string `'false'`, which is truthy — hence the `none` keyword.
|
||||
keyword: (property, fallback) => {
|
||||
const value = read(property) || fallback
|
||||
|
||||
return value === 'none' ? false : value
|
||||
},
|
||||
}
|
||||
}
|
||||
13
vendor/filament/widgets/resources/lang/am/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/am/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'ማጣርያ',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
31
vendor/filament/widgets/resources/lang/ar/chart.php
vendored
Normal file
31
vendor/filament/widgets/resources/lang/ar/chart.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
'filter' => [
|
||||
'label' => 'تصفية',
|
||||
],
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
'actions' => [
|
||||
'apply' => [
|
||||
'label' => 'تطبيق',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'إعادة تعيين',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'لا توجد بيانات للعرض',
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'تصفية بيانات الرسم البياني',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/bn/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/bn/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'ফিল্টার করুন',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/ca/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/ca/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrar',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Aplicar',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Reestablir',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/ckb/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/ckb/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'پاڵاوتن',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/cs/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/cs/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtr',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrovat data grafu',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Použít',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Resetovat',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Žádná data k zobrazení',
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/de/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/de/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtern',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Diagrammdaten filtern',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Anwenden',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Zurücksetzen',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Keine Daten vorhanden',
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/en/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/en/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter chart data',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Apply',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Reset',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'No data to display',
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/es/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/es/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrar',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrar los datos del gráfico',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Aplicar',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Restablecer',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'No hay datos para mostrar',
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/et/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/et/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtreeri',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtreeri andmed',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Rakenda',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Lähtesta',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Andmeid ei ole',
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/eu/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/eu/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Iragazki',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Aplikatu',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Berrezarri',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
25
vendor/filament/widgets/resources/lang/fil/chart.php
vendored
Normal file
25
vendor/filament/widgets/resources/lang/fil/chart.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'actions' => [
|
||||
'filter' => [
|
||||
'label' => 'I-filter',
|
||||
],
|
||||
],
|
||||
'filter' => [
|
||||
'label' => 'I-filter ang data ng chart',
|
||||
],
|
||||
'filters' => [
|
||||
'actions' => [
|
||||
'apply' => [
|
||||
'label' => 'I-apply',
|
||||
],
|
||||
'reset' => [
|
||||
'label' => 'I-reset',
|
||||
],
|
||||
],
|
||||
],
|
||||
'empty' => [
|
||||
'heading' => 'Walang data na maipapakita',
|
||||
],
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/fr/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/fr/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrer',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/he/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/he/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'סינון',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'סינון נתוני התרשים',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'החל',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'איפוס',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'אין נתונים להצגה',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/hu/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/hu/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Szűrés',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/id/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/id/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Terapkan',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Atur ulang',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/it/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/it/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtra',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Applica',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Reimposta',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/ja/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/ja/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'フィルター',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => '適用',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'リセット',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/km/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/km/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'តម្រង',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'ត្រងទិន្នន័យគំនូសតាង',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'អនុវត្ត',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'កំណត់ឡើងវិញ',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'គ្មានទិន្នន័យត្រូវបង្ហាញទេ',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/ko/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/ko/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => '필터',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/lt/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/lt/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtruoti',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Taikyti',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Atstatyti',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/lus/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/lus/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Thlit fîmna',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Chart data thlitfîmna',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Apply',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Tihṭhatna',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Data târchhuah tur a awm lo',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/mk/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/mk/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Филтер',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
25
vendor/filament/widgets/resources/lang/my/chart.php
vendored
Normal file
25
vendor/filament/widgets/resources/lang/my/chart.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'actions' => [
|
||||
'filter' => [
|
||||
'label' => 'စစ်ထုတ်ရန်',
|
||||
],
|
||||
],
|
||||
'filter' => [
|
||||
'label' => 'ဇယားဒေတာကို စစ်ထုတ်ရန်',
|
||||
],
|
||||
'filters' => [
|
||||
'actions' => [
|
||||
'apply' => [
|
||||
'label' => 'အသုံးပြုရန်',
|
||||
],
|
||||
'reset' => [
|
||||
'label' => 'မူလအတိုင်း ပြန်ထားရန်',
|
||||
],
|
||||
],
|
||||
],
|
||||
'empty' => [
|
||||
'heading' => 'ပြသရန် ဒေတာမရှိပါ',
|
||||
],
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/nb/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/nb/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/nl/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/nl/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filteren',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Toepassen',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Resetten',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/pl/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/pl/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtruj',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtruj dane wykresu',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Zastosuj',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Resetuj',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Brak danych do wyświetlenia',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/pt/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/pt/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrar',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/pt_BR/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/pt_BR/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtro',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrar dados do gráfico',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Aplicar',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Redefinir',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Sem dados para exibir',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/ro/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/ro/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtru',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/ru/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/ru/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Фильтр',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Применить',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Сбросить',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/sk/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/sk/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrovať dáta grafu',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Použiť',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Resetovať',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Žiadne dáta na zobrazenie',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/sr_Cyrl/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/sr_Cyrl/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Филтер',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/sr_Latn/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/sr_Latn/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/sv/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/sv/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filter',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtrera diagramdata',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Tillämpa',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Återställ',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Ingen data att visa',
|
||||
],
|
||||
|
||||
];
|
||||
31
vendor/filament/widgets/resources/lang/sw/chart.php
vendored
Normal file
31
vendor/filament/widgets/resources/lang/sw/chart.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
'filter' => [
|
||||
'label' => 'Chuja',
|
||||
],
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Chuja data ya chati',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
'actions' => [
|
||||
'apply' => [
|
||||
'label' => 'Tekeleza',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Weka upya',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Hakuna data ya kuonyesha',
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/tg/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/tg/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Филтр',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Татбиқ кардан',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Аз нав барқарор кардан',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
37
vendor/filament/widgets/resources/lang/tr/chart.php
vendored
Normal file
37
vendor/filament/widgets/resources/lang/tr/chart.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Filtre',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Grafik verilerini filtrele',
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => 'Uygula',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => 'Sıfırla',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'empty' => [
|
||||
'heading' => 'Görüntülenecek veri yok',
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/uk/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/uk/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Фільтр',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/ur/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/ur/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'فلٹر کریں',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
13
vendor/filament/widgets/resources/lang/vi/chart.php
vendored
Normal file
13
vendor/filament/widgets/resources/lang/vi/chart.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => 'Bộ lọc',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
29
vendor/filament/widgets/resources/lang/zh_CN/chart.php
vendored
Normal file
29
vendor/filament/widgets/resources/lang/zh_CN/chart.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'filter' => [
|
||||
'label' => '筛选',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
'filters' => [
|
||||
|
||||
'actions' => [
|
||||
|
||||
'apply' => [
|
||||
'label' => '应用',
|
||||
],
|
||||
|
||||
'reset' => [
|
||||
'label' => '重置',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
205
vendor/filament/widgets/resources/views/chart-widget.blade.php
vendored
Normal file
205
vendor/filament/widgets/resources/views/chart-widget.blade.php
vendored
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
@php
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Widgets\View\Components\ChartWidgetComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
$color = $this->getColor();
|
||||
$heading = $this->getHeading();
|
||||
$description = $this->getDescription();
|
||||
$filters = $this->getFilters();
|
||||
$isCollapsible = $this->isCollapsible();
|
||||
$type = $this->getType();
|
||||
$maxHeight = $this->getMaxHeight();
|
||||
$hasMaxHeight = filled($maxHeight) && $maxHeight !== '100%';
|
||||
$isEmpty = $this->isEmpty();
|
||||
|
||||
// The chart paints onto a bare `<canvas>`, which exposes no accessible name, so build a text
|
||||
// alternative from the widget's heading and description (WCAG 1.1.1) for `role="img"` + `aria-label`.
|
||||
$chartAccessibleLabel = trim(implode('. ', array_filter([
|
||||
$heading instanceof Htmlable ? strip_tags($heading->toHtml()) : $heading,
|
||||
$description instanceof Htmlable ? strip_tags($description->toHtml()) : $description,
|
||||
], fn ($value): bool => filled($value))));
|
||||
@endphp
|
||||
|
||||
<x-filament-widgets::widget class="fi-wi-chart">
|
||||
<x-filament::section
|
||||
:description="$description"
|
||||
:heading="$heading"
|
||||
:collapsible="$isCollapsible"
|
||||
>
|
||||
@if ($filters || method_exists($this, 'getFiltersSchema'))
|
||||
<x-slot name="afterHeader">
|
||||
@if ($filters)
|
||||
<x-filament::input.wrapper
|
||||
inline-prefix
|
||||
wire:target="filter"
|
||||
class="fi-wi-chart-filter"
|
||||
>
|
||||
<x-filament::input.select
|
||||
:aria-label="__('filament-widgets::chart.filter.label')"
|
||||
inline-prefix
|
||||
wire:model.live="filter"
|
||||
>
|
||||
@foreach ($filters as $value => $label)
|
||||
<option value="{{ $value }}">
|
||||
{{ $label }}
|
||||
</option>
|
||||
@endforeach
|
||||
</x-filament::input.select>
|
||||
</x-filament::input.wrapper>
|
||||
@endif
|
||||
|
||||
@if (method_exists($this, 'getFiltersSchema'))
|
||||
<x-filament::dropdown
|
||||
placement="bottom-end"
|
||||
shift
|
||||
width="xs"
|
||||
class="fi-wi-chart-filter"
|
||||
>
|
||||
<x-slot name="trigger">
|
||||
{{ $this->getFiltersTriggerAction() }}
|
||||
</x-slot>
|
||||
|
||||
<div class="fi-wi-chart-filter-content">
|
||||
{{ $this->getFiltersSchema() }}
|
||||
|
||||
@if (method_exists($this, 'hasDeferredFilters') && $this->hasDeferredFilters())
|
||||
<div
|
||||
class="fi-wi-chart-filter-content-actions-ctn"
|
||||
>
|
||||
{{ $this->getFiltersApplyAction() }}
|
||||
|
||||
{{ $this->getFiltersResetAction() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</x-filament::dropdown>
|
||||
@endif
|
||||
</x-slot>
|
||||
@endif
|
||||
|
||||
<div
|
||||
@if ($pollingInterval = $this->getPollingInterval())
|
||||
wire:poll.{{ $pollingInterval }}="updateChartData"
|
||||
@endif
|
||||
@if ($isEmpty)
|
||||
style="display: none"
|
||||
@endif
|
||||
>
|
||||
<div
|
||||
x-load
|
||||
x-load-src="{{ FilamentAsset::getAlpineComponentSrc('chart', 'filament/widgets') }}"
|
||||
wire:ignore
|
||||
data-chart-type="{{ $type }}"
|
||||
x-data="chart({
|
||||
cachedData: @js($this->getCachedData()),
|
||||
options: @js($this->getOptions()),
|
||||
type: @js($type),
|
||||
})"
|
||||
{{
|
||||
(new FilamentComponentAttributeBag)
|
||||
->color(ChartWidgetComponent::class, $color)
|
||||
->class([
|
||||
'fi-wi-chart-frame',
|
||||
'fi-wi-chart-canvas-ctn',
|
||||
'fi-wi-chart-frame-no-aspect-ratio' => $hasMaxHeight,
|
||||
])
|
||||
}}
|
||||
>
|
||||
<canvas
|
||||
x-ref="canvas"
|
||||
@if (filled($chartAccessibleLabel))
|
||||
role="img"
|
||||
aria-label="{{ $chartAccessibleLabel }}"
|
||||
@endif
|
||||
@style([
|
||||
'width: 100%',
|
||||
'height: 100%; max-height: 100%' => ! $hasMaxHeight,
|
||||
('max-height: ' . e($maxHeight)) => $hasMaxHeight,
|
||||
])
|
||||
></canvas>
|
||||
|
||||
{{--
|
||||
Chart.js paints the chart onto the canvas, where a stylesheet cannot reach it. These empty
|
||||
elements carry the colors it should use, so that a theme can set them with an ordinary
|
||||
`color` declaration and they follow light and dark mode like any other element.
|
||||
--}}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="backgroundColorElement"
|
||||
class="fi-wi-chart-bg-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="borderColorElement"
|
||||
class="fi-wi-chart-border-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="gridColorElement"
|
||||
class="fi-wi-chart-grid-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="textColorElement"
|
||||
class="fi-wi-chart-text-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="tooltipBackgroundColorElement"
|
||||
class="fi-wi-chart-tooltip-bg-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="tooltipTextColorElement"
|
||||
class="fi-wi-chart-tooltip-text-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="tooltipBorderColorElement"
|
||||
class="fi-wi-chart-tooltip-border-color"
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($isEmpty)
|
||||
@if ($emptyState = $this->getEmptyState())
|
||||
{{ $emptyState }}
|
||||
@else
|
||||
<div
|
||||
@class([
|
||||
'fi-wi-chart-frame',
|
||||
'fi-wi-chart-frame-no-aspect-ratio' => $hasMaxHeight,
|
||||
])
|
||||
@style([
|
||||
('min-height: ' . e($maxHeight)) => $hasMaxHeight,
|
||||
])
|
||||
>
|
||||
<x-filament::empty-state
|
||||
:contained="false"
|
||||
:description="$this->getEmptyStateDescription()"
|
||||
:heading="$this->getEmptyStateHeading()"
|
||||
:icon="$this->getEmptyStateIcon()"
|
||||
icon-color="gray"
|
||||
>
|
||||
@if ($emptyStateActions = $this->getEmptyStateActions())
|
||||
<x-slot name="footer">
|
||||
<x-filament::actions
|
||||
:actions="$emptyStateActions"
|
||||
alignment="center"
|
||||
/>
|
||||
</x-slot>
|
||||
@endif
|
||||
</x-filament::empty-state>
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
</x-filament::section>
|
||||
</x-filament-widgets::widget>
|
||||
5
vendor/filament/widgets/resources/views/components/widget.blade.php
vendored
Normal file
5
vendor/filament/widgets/resources/views/components/widget.blade.php
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<div
|
||||
{{ $attributes->gridColumn($this->getColumnSpan(), $this->getColumnStart())->class(['fi-wi-widget']) }}
|
||||
>
|
||||
{{ $slot }}
|
||||
</div>
|
||||
41
vendor/filament/widgets/resources/views/components/widgets.blade.php
vendored
Normal file
41
vendor/filament/widgets/resources/views/components/widgets.blade.php
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{{-- @deprecated Use a schema to render widgets. --}}
|
||||
|
||||
@props([
|
||||
'columns' => [
|
||||
'lg' => 2,
|
||||
],
|
||||
'data' => [],
|
||||
'widgets' => [],
|
||||
])
|
||||
|
||||
@php
|
||||
use Filament\Widgets\WidgetConfiguration;
|
||||
|
||||
if (is_array($columns)) {
|
||||
$columns['lg'] ??= ($columns ? (is_array($columns) ? null : $columns) : 2);
|
||||
}
|
||||
@endphp
|
||||
|
||||
<div {{ $attributes->grid($columns)->class(['fi-wi']) }}>
|
||||
@php
|
||||
$normalizeWidgetClass = function (string | WidgetConfiguration $widget): string {
|
||||
if ($widget instanceof WidgetConfiguration) {
|
||||
return $widget->widget;
|
||||
}
|
||||
|
||||
return $widget;
|
||||
};
|
||||
@endphp
|
||||
|
||||
@foreach ($widgets as $widgetKey => $widget)
|
||||
@php
|
||||
$widgetClass = $normalizeWidgetClass($widget);
|
||||
@endphp
|
||||
|
||||
@livewire(
|
||||
$widgetClass,
|
||||
[...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? [...$widget->widget::getDefaultProperties(), ...$widget->getProperties()] : $widget::getDefaultProperties()), ...$data],
|
||||
key("{$widgetClass}-{$widgetKey}"),
|
||||
)
|
||||
@endforeach
|
||||
</div>
|
||||
25
vendor/filament/widgets/resources/views/stats-overview-widget.blade.php
vendored
Normal file
25
vendor/filament/widgets/resources/views/stats-overview-widget.blade.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
@php
|
||||
use Filament\Support\View\ComponentAttributeBag;
|
||||
|
||||
$columns = $this->getColumns();
|
||||
$pollingInterval = $this->getPollingInterval();
|
||||
|
||||
$heading = $this->getHeading();
|
||||
$description = $this->getDescription();
|
||||
$hasHeading = filled($heading);
|
||||
$hasDescription = filled($description);
|
||||
@endphp
|
||||
|
||||
<x-filament-widgets::widget
|
||||
:attributes="
|
||||
(new ComponentAttributeBag)
|
||||
->merge([
|
||||
'wire:poll.' . $pollingInterval => $pollingInterval ? true : null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-wi-stats-overview',
|
||||
])
|
||||
"
|
||||
>
|
||||
{{ $this->content }}
|
||||
</x-filament-widgets::widget>
|
||||
100
vendor/filament/widgets/resources/views/stats-overview-widget/stat.blade.php
vendored
Normal file
100
vendor/filament/widgets/resources/views/stats-overview-widget/stat.blade.php
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
@php
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Widgets\View\Components\StatsOverviewWidgetComponent\StatComponent\DescriptionComponent;
|
||||
use Filament\Widgets\View\Components\StatsOverviewWidgetComponent\StatComponent\StatsOverviewWidgetStatChartComponent;
|
||||
|
||||
$chartColor = $getChartColor() ?? 'gray';
|
||||
$descriptionColor = $getDescriptionColor() ?? 'gray';
|
||||
$descriptionIcon = $getDescriptionIcon();
|
||||
$descriptionIconPosition = $getDescriptionIconPosition();
|
||||
$url = $getUrl();
|
||||
$tag = $url ? 'a' : 'div';
|
||||
@endphp
|
||||
|
||||
<{!! $tag !!}
|
||||
@if ($url)
|
||||
{{ \Filament\Support\generate_href_html($url, $shouldOpenUrlInNewTab()) }}
|
||||
@endif
|
||||
{{
|
||||
$getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-wi-stats-overview-stat',
|
||||
])
|
||||
}}
|
||||
>
|
||||
<div class="fi-wi-stats-overview-stat-content">
|
||||
<div class="fi-wi-stats-overview-stat-label-ctn">
|
||||
{{ \Filament\Support\generate_icon_html($getIcon()) }}
|
||||
|
||||
<span class="fi-wi-stats-overview-stat-label">
|
||||
{{ $getLabel() }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@if (filled($value = $getValue()))
|
||||
<div class="fi-wi-stats-overview-stat-value">
|
||||
{{ $value }}
|
||||
</div>
|
||||
@else
|
||||
<div class="fi-wi-stats-overview-stat-placeholder">
|
||||
{{ $getPlaceholder() }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($description = $getDescription())
|
||||
<div
|
||||
{{ (new FilamentComponentAttributeBag)->color(DescriptionComponent::class, $descriptionColor)->class(['fi-wi-stats-overview-stat-description']) }}
|
||||
>
|
||||
@if ($descriptionIcon && in_array($descriptionIconPosition, [IconPosition::Before, 'before']))
|
||||
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new FilamentComponentAttributeBag)) }}
|
||||
@endif
|
||||
|
||||
<span>
|
||||
{{ $description }}
|
||||
</span>
|
||||
|
||||
@if ($descriptionIcon && in_array($descriptionIconPosition, [IconPosition::After, 'after']))
|
||||
{{ \Filament\Support\generate_icon_html($descriptionIcon, attributes: (new FilamentComponentAttributeBag)) }}
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($chart = $getChart())
|
||||
{{-- An empty function to initialize the Alpine component with until it's loaded with `x-load`. --}}
|
||||
<div x-data="{ statsOverviewStatChart() {} }">
|
||||
<div
|
||||
x-load
|
||||
x-load-src="{{ FilamentAsset::getAlpineComponentSrc('stats-overview/stat/chart', 'filament/widgets') }}"
|
||||
wire:ignore
|
||||
x-data="statsOverviewStatChart({
|
||||
key: @js($getKey(false)),
|
||||
labels: @js(array_keys($chart)),
|
||||
values: @js(array_values($chart)),
|
||||
})"
|
||||
{{ (new FilamentComponentAttributeBag)->color(StatsOverviewWidgetStatChartComponent::class, $chartColor)->class(['fi-wi-stats-overview-stat-chart']) }}
|
||||
>
|
||||
{{-- The label and value are already exposed as text, so the trend sparkline is decorative. --}}
|
||||
<canvas x-ref="canvas" aria-hidden="true"></canvas>
|
||||
|
||||
{{--
|
||||
These empty elements carry the colors the chart should be painted in, so that a theme
|
||||
can set them with an ordinary `color` declaration.
|
||||
--}}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="backgroundColorElement"
|
||||
class="fi-wi-stats-overview-stat-chart-bg-color"
|
||||
></span>
|
||||
|
||||
<span
|
||||
aria-hidden="true"
|
||||
x-ref="borderColorElement"
|
||||
class="fi-wi-stats-overview-stat-chart-border-color"
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</{!! $tag !!}>
|
||||
12
vendor/filament/widgets/resources/views/table-widget.blade.php
vendored
Normal file
12
vendor/filament/widgets/resources/views/table-widget.blade.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
@php
|
||||
use Filament\Support\Facades\FilamentView;
|
||||
use Filament\Widgets\View\WidgetsRenderHook;
|
||||
@endphp
|
||||
|
||||
<x-filament-widgets::widget class="fi-wi-table">
|
||||
{{ FilamentView::renderHook(WidgetsRenderHook::TABLE_WIDGET_START, scopes: static::class) }}
|
||||
|
||||
{{ $this->table ?? null }}
|
||||
|
||||
{{ FilamentView::renderHook(WidgetsRenderHook::TABLE_WIDGET_END, scopes: static::class) }}
|
||||
</x-filament-widgets::widget>
|
||||
14
vendor/filament/widgets/src/BarChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/BarChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class BarChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/BubbleChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/BubbleChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class BubbleChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bubble';
|
||||
}
|
||||
}
|
||||
138
vendor/filament/widgets/src/ChartWidget.php
vendored
Normal file
138
vendor/filament/widgets/src/ChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Widgets\ChartWidget\Concerns\HasEmptyState;
|
||||
use Filament\Widgets\Concerns\CanPoll;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Livewire\Attributes\Locked;
|
||||
|
||||
abstract class ChartWidget extends Widget implements HasSchemas
|
||||
{
|
||||
use CanPoll;
|
||||
use HasEmptyState;
|
||||
use InteractsWithSchemas;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | null
|
||||
*/
|
||||
protected ?array $cachedData = null;
|
||||
|
||||
#[Locked]
|
||||
public ?string $dataChecksum = null;
|
||||
|
||||
public ?string $filter = null;
|
||||
|
||||
protected string $color = 'primary';
|
||||
|
||||
protected ?string $heading = null;
|
||||
|
||||
protected ?string $description = null;
|
||||
|
||||
protected ?string $maxHeight = null;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | null
|
||||
*/
|
||||
protected ?array $options = null;
|
||||
|
||||
protected bool $isCollapsible = false;
|
||||
|
||||
/**
|
||||
* @var view-string
|
||||
*/
|
||||
protected string $view = 'filament-widgets::chart-widget';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->dataChecksum = $this->generateDataChecksum();
|
||||
}
|
||||
|
||||
abstract protected function getType(): string;
|
||||
|
||||
protected function generateDataChecksum(): string
|
||||
{
|
||||
return md5(json_encode($this->getCachedData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getCachedData(): array
|
||||
{
|
||||
return $this->cachedData ??= $this->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<scalar, scalar> | null
|
||||
*/
|
||||
protected function getFilters(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getHeading(): string | Htmlable | null
|
||||
{
|
||||
return $this->heading;
|
||||
}
|
||||
|
||||
public function getDescription(): string | Htmlable | null
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
protected function getMaxHeight(): ?string
|
||||
{
|
||||
return $this->maxHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> | RawJs | null
|
||||
*/
|
||||
protected function getOptions(): array | RawJs | null
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function updateChartData(): void
|
||||
{
|
||||
$newDataChecksum = $this->generateDataChecksum();
|
||||
|
||||
if ($newDataChecksum !== $this->dataChecksum) {
|
||||
$this->dataChecksum = $newDataChecksum;
|
||||
|
||||
$this->dispatch('updateChartData', data: $this->getCachedData());
|
||||
}
|
||||
}
|
||||
|
||||
public function rendering(): void
|
||||
{
|
||||
$this->updateChartData();
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
public function isCollapsible(): bool
|
||||
{
|
||||
return $this->isCollapsible;
|
||||
}
|
||||
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
return empty($this->getCachedData());
|
||||
}
|
||||
}
|
||||
51
vendor/filament/widgets/src/ChartWidget/Concerns/HasEmptyState.php
vendored
Normal file
51
vendor/filament/widgets/src/ChartWidget/Concerns/HasEmptyState.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\ChartWidget\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Widgets\View\WidgetsIconAlias;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
trait HasEmptyState
|
||||
{
|
||||
protected ?string $emptyStateDescription = null;
|
||||
|
||||
protected ?string $emptyStateHeading = null;
|
||||
|
||||
protected string | BackedEnum | null $emptyStateIcon = null;
|
||||
|
||||
public function getEmptyState(): View | Htmlable | null
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getEmptyStateActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getEmptyStateDescription(): string | Htmlable | null
|
||||
{
|
||||
return $this->emptyStateDescription;
|
||||
}
|
||||
|
||||
public function getEmptyStateHeading(): string | Htmlable
|
||||
{
|
||||
return $this->emptyStateHeading ?? __('filament-widgets::chart.empty.heading');
|
||||
}
|
||||
|
||||
public function getEmptyStateIcon(): string | BackedEnum | Htmlable
|
||||
{
|
||||
return $this->emptyStateIcon
|
||||
?? FilamentIcon::resolve(WidgetsIconAlias::CHART_WIDGET_EMPTY_STATE)
|
||||
?? Heroicon::OutlinedXMark;
|
||||
}
|
||||
}
|
||||
122
vendor/filament/widgets/src/ChartWidget/Concerns/HasFiltersSchema.php
vendored
Normal file
122
vendor/filament/widgets/src/ChartWidget/Concerns/HasFiltersSchema.php
vendored
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\ChartWidget\Concerns;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Widgets\View\WidgetsIconAlias;
|
||||
|
||||
trait HasFiltersSchema /** @phpstan-ignore trait.unused */
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed> | null
|
||||
*/
|
||||
public ?array $filters = [];
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | null
|
||||
*/
|
||||
public ?array $deferredFilters = null;
|
||||
|
||||
public function filtersSchema(Schema $schema): Schema
|
||||
{
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function hasDeferredFilters(): bool
|
||||
{
|
||||
return property_exists($this, 'hasDeferredFilters') && $this->hasDeferredFilters;
|
||||
}
|
||||
|
||||
public function mountHasFiltersSchema(): void
|
||||
{
|
||||
$this->getFiltersSchema()->fill();
|
||||
|
||||
if ($this->hasDeferredFilters()) {
|
||||
$this->filters = $this->deferredFilters;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFiltersTriggerAction(): Action
|
||||
{
|
||||
return Action::make('filter')
|
||||
->label(__('filament-widgets::chart.actions.filter.label'))
|
||||
->iconButton()
|
||||
->icon(FilamentIcon::resolve(WidgetsIconAlias::CHART_WIDGET_FILTER) ?? Heroicon::Funnel)
|
||||
->color('gray')
|
||||
->livewireClickHandlerEnabled(false);
|
||||
}
|
||||
|
||||
public function getFiltersSchema(): Schema
|
||||
{
|
||||
if ((! $this->isCachingSchemas) && $this->hasCachedSchema('filtersSchema')) {
|
||||
return $this->getSchema('filtersSchema');
|
||||
}
|
||||
|
||||
return $this->filtersSchema($this->makeSchema())
|
||||
->when(
|
||||
$this->hasDeferredFilters(),
|
||||
fn (Schema $schema) => $schema
|
||||
->statePath('deferredFilters')
|
||||
->partiallyRender(),
|
||||
fn (Schema $schema) => $schema
|
||||
->statePath('filters')
|
||||
->live(),
|
||||
);
|
||||
}
|
||||
|
||||
public function updatedFilters(): void
|
||||
{
|
||||
$this->cachedData = null;
|
||||
}
|
||||
|
||||
public function applyFilters(): void
|
||||
{
|
||||
$this->filters = $this->deferredFilters;
|
||||
$this->cachedData = null;
|
||||
}
|
||||
|
||||
public function resetFiltersForm(): void
|
||||
{
|
||||
$this->getFiltersSchema()->fill();
|
||||
|
||||
if ($this->hasDeferredFilters()) {
|
||||
$this->applyFilters();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->cachedData = null;
|
||||
}
|
||||
|
||||
public function getFiltersApplyAction(): Action
|
||||
{
|
||||
$action = Action::make('applyFilters')
|
||||
->label(__('filament-widgets::chart.filters.actions.apply.label'))
|
||||
->action('applyFilters')
|
||||
->button();
|
||||
|
||||
if (method_exists($this, 'filtersApplyAction')) {
|
||||
$action = $this->filtersApplyAction($action);
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function getFiltersResetAction(): Action
|
||||
{
|
||||
$action = Action::make('resetFilters')
|
||||
->label(__('filament-widgets::chart.filters.actions.reset.label'))
|
||||
->action('resetFiltersForm')
|
||||
->color('danger')
|
||||
->button();
|
||||
|
||||
if (method_exists($this, 'filtersResetAction')) {
|
||||
$action = $this->filtersResetAction($action);
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
}
|
||||
114
vendor/filament/widgets/src/Commands/FileGenerators/ChartWidgetClassGenerator.php
vendored
Normal file
114
vendor/filament/widgets/src/Commands/FileGenerators/ChartWidgetClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Commands\FileGenerators;
|
||||
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Literal;
|
||||
use Nette\PhpGenerator\Method;
|
||||
use Nette\PhpGenerator\Property;
|
||||
|
||||
class ChartWidgetClassGenerator extends ClassGenerator
|
||||
{
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $type,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
$extends = $this->getExtends();
|
||||
$extendsBasename = class_basename($extends);
|
||||
|
||||
return [
|
||||
...(($extendsBasename === class_basename($this->getFqn())) ? [$extends => "Base{$extendsBasename}"] : [$extends]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return ChartWidget::class;
|
||||
}
|
||||
|
||||
protected function addPropertiesToClass(ClassType $class): void
|
||||
{
|
||||
$this->addHeadingPropertyToClass($class);
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addGetDataMethodToClass($class);
|
||||
$this->addGetTypeMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addHeadingPropertyToClass(ClassType $class): void
|
||||
{
|
||||
$property = $class->addProperty(
|
||||
'heading',
|
||||
(string) str($this->getBasename())
|
||||
->classBasename()
|
||||
->kebab()
|
||||
->replace('-', ' ')
|
||||
->ucwords(),
|
||||
)
|
||||
->setProtected()
|
||||
->setType('?string');
|
||||
$this->configureHeadingProperty($property);
|
||||
}
|
||||
|
||||
protected function configureHeadingProperty(Property $property): void {}
|
||||
|
||||
protected function addGetDataMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('getData')
|
||||
->setProtected()
|
||||
->setReturnType('array')
|
||||
->setBody(<<<'PHP'
|
||||
return [
|
||||
//
|
||||
];
|
||||
PHP);
|
||||
|
||||
$this->configureGetDataMethod($method);
|
||||
}
|
||||
|
||||
protected function configureGetDataMethod(Method $method): void {}
|
||||
|
||||
protected function addGetTypeMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('getType')
|
||||
->setProtected()
|
||||
->setReturnType('string')
|
||||
->setBody(new Literal(<<<'PHP'
|
||||
return ?;
|
||||
PHP, [$this->getType()]));
|
||||
|
||||
$this->configureGetTypeMethod($method);
|
||||
}
|
||||
|
||||
protected function configureGetTypeMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
61
vendor/filament/widgets/src/Commands/FileGenerators/CustomWidgetClassGenerator.php
vendored
Normal file
61
vendor/filament/widgets/src/Commands/FileGenerators/CustomWidgetClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Commands\FileGenerators;
|
||||
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Support\Commands\FileGenerators\Concerns\CanGenerateViewProperty;
|
||||
use Filament\Widgets\Widget;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
|
||||
class CustomWidgetClassGenerator extends ClassGenerator
|
||||
{
|
||||
use CanGenerateViewProperty;
|
||||
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $view,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
$extends = $this->getExtends();
|
||||
$extendsBasename = class_basename($extends);
|
||||
|
||||
return [
|
||||
...(($extendsBasename === class_basename($this->getFqn())) ? [$extends => "Base{$extendsBasename}"] : [$extends]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return Widget::class;
|
||||
}
|
||||
|
||||
protected function addPropertiesToClass(ClassType $class): void
|
||||
{
|
||||
$this->addViewPropertyToClass($class);
|
||||
}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
public function getView(): string
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
}
|
||||
71
vendor/filament/widgets/src/Commands/FileGenerators/StatsOverviewWidgetClassGenerator.php
vendored
Normal file
71
vendor/filament/widgets/src/Commands/FileGenerators/StatsOverviewWidgetClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Commands\FileGenerators;
|
||||
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Method;
|
||||
|
||||
class StatsOverviewWidgetClassGenerator extends ClassGenerator
|
||||
{
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
$extends = $this->getExtends();
|
||||
$extendsBasename = class_basename($extends);
|
||||
|
||||
return [
|
||||
...(($extendsBasename === class_basename($this->getFqn())) ? [$extends => "Base{$extendsBasename}"] : [$extends]),
|
||||
Stat::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return StatsOverviewWidget::class;
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addGetStatsMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addGetStatsMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('getStats')
|
||||
->setProtected()
|
||||
->setReturnType('array')
|
||||
->setBody(<<<'PHP'
|
||||
return [
|
||||
//
|
||||
];
|
||||
PHP);
|
||||
|
||||
$this->configureGetStatsMethod($method);
|
||||
}
|
||||
|
||||
protected function configureGetStatsMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
}
|
||||
98
vendor/filament/widgets/src/Commands/FileGenerators/TableWidgetClassGenerator.php
vendored
Normal file
98
vendor/filament/widgets/src/Commands/FileGenerators/TableWidgetClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Commands\FileGenerators;
|
||||
|
||||
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
|
||||
use Filament\Tables\Commands\FileGenerators\Concerns\CanGenerateModelTables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Method;
|
||||
|
||||
class TableWidgetClassGenerator extends ClassGenerator implements HasSkippedColumns
|
||||
{
|
||||
use CanGenerateModelTables;
|
||||
use CanReadModelSchemas;
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $modelFqn
|
||||
*/
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $modelFqn,
|
||||
protected bool $isGenerated,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
$extends = $this->getExtends();
|
||||
$extendsBasename = class_basename($extends);
|
||||
|
||||
return [
|
||||
...(($extendsBasename === class_basename($this->getFqn())) ? [$extends => "Base{$extendsBasename}"] : [$extends]),
|
||||
Table::class,
|
||||
...($this->hasPartialImports() ? ['Filament\Tables'] : []),
|
||||
Builder::class,
|
||||
$this->getModelFqn(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return TableWidget::class;
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addTableMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addTableMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('table')
|
||||
->setPublic()
|
||||
->setReturnType(Table::class)
|
||||
->setBody($this->generateTableMethodBody($this->getModelFqn()));
|
||||
$method->addParameter('table')
|
||||
->setType(Table::class);
|
||||
|
||||
$this->configureTableMethod($method);
|
||||
}
|
||||
|
||||
protected function configureTableMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Model>
|
||||
*/
|
||||
public function getModelFqn(): string
|
||||
{
|
||||
return $this->modelFqn;
|
||||
}
|
||||
|
||||
public function isGenerated(): bool
|
||||
{
|
||||
return $this->isGenerated;
|
||||
}
|
||||
}
|
||||
526
vendor/filament/widgets/src/Commands/MakeWidgetCommand.php
vendored
Normal file
526
vendor/filament/widgets/src/Commands/MakeWidgetCommand.php
vendored
Normal file
|
|
@ -0,0 +1,526 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Commands;
|
||||
|
||||
use Filament\Support\Commands\Concerns\CanAskForLivewireComponentLocation;
|
||||
use Filament\Support\Commands\Concerns\CanAskForResource;
|
||||
use Filament\Support\Commands\Concerns\CanAskForViewLocation;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Concerns\HasCluster;
|
||||
use Filament\Support\Commands\Concerns\HasPanel;
|
||||
use Filament\Support\Commands\Concerns\HasResourcesLocation;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Filament\Support\Commands\FileGenerators\Concerns\CanCheckFileGenerationFlags;
|
||||
use Filament\Support\Facades\FilamentCli;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Commands\FileGenerators\ChartWidgetClassGenerator;
|
||||
use Filament\Widgets\Commands\FileGenerators\CustomWidgetClassGenerator;
|
||||
use Filament\Widgets\Commands\FileGenerators\StatsOverviewWidgetClassGenerator;
|
||||
use Filament\Widgets\Commands\FileGenerators\TableWidgetClassGenerator;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Widgets\Widget;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Stringable;
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Filament\Support\discover_app_classes;
|
||||
use function Filament\Support\is_path_within_vendor_directory;
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\search;
|
||||
use function Laravel\Prompts\select;
|
||||
use function Laravel\Prompts\suggest;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'make:filament-widget', aliases: [
|
||||
'filament:make-widget',
|
||||
'filament:widget',
|
||||
])]
|
||||
class MakeWidgetCommand extends Command
|
||||
{
|
||||
use CanAskForLivewireComponentLocation;
|
||||
use CanAskForResource;
|
||||
use CanAskForViewLocation;
|
||||
use CanCheckFileGenerationFlags;
|
||||
use CanManipulateFiles;
|
||||
use HasCluster;
|
||||
use HasPanel;
|
||||
use HasResourcesLocation;
|
||||
|
||||
protected $description = 'Create a new Filament widget class';
|
||||
|
||||
protected $name = 'make:filament-widget';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:make-widget',
|
||||
'filament:widget',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var class-string
|
||||
*/
|
||||
protected string $fqn;
|
||||
|
||||
protected string $fqnEnd;
|
||||
|
||||
protected ?string $view = null;
|
||||
|
||||
protected ?string $viewPath = null;
|
||||
|
||||
protected bool $hasResource;
|
||||
|
||||
/**
|
||||
* @var ?class-string
|
||||
*/
|
||||
protected ?string $resourceFqn = null;
|
||||
|
||||
/**
|
||||
* @var class-string<Widget> | null
|
||||
*/
|
||||
protected ?string $type = null;
|
||||
|
||||
protected string $widgetsNamespace;
|
||||
|
||||
protected string $widgetsDirectory;
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'name',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the widget to generate, optionally prefixed with directories',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'chart',
|
||||
shortcut: 'C',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Create a chart widget',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'cluster',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: 'The cluster that the resource belongs to',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'panel',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_REQUIRED,
|
||||
description: 'The panel to create the widget in',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'resource',
|
||||
shortcut: 'R',
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: 'The resource to create the widget in',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'resource-namespace',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_OPTIONAL,
|
||||
description: 'The namespace of the resource class, such as [' . app()->getNamespace() . 'Filament\\Resources]',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'stats-overview',
|
||||
shortcut: 'S',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Create a stats overview widget',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'table',
|
||||
shortcut: 'T',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Create a table widget',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->configureFqnEnd();
|
||||
$this->configureType();
|
||||
$this->configurePanel(
|
||||
question: 'Which panel would you like to create this widget in?',
|
||||
initialQuestion: 'Would you like to create this widget in a panel?',
|
||||
);
|
||||
$this->configureHasResource();
|
||||
$this->configureCluster();
|
||||
$this->configureResource();
|
||||
$this->configureWidgetsLocation();
|
||||
|
||||
$this->configureLocation();
|
||||
|
||||
$this->createCustomWidget();
|
||||
$this->createChartWidget();
|
||||
$this->createStatsOverviewWidget();
|
||||
$this->createTableWidget();
|
||||
$this->createView();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->components->info("Filament widget [{$this->fqn}] created successfully.");
|
||||
|
||||
if (filled($this->resourceFqn)) {
|
||||
$this->components->info("Make sure to register the widget in [{$this->resourceFqn}::getWidgets()], and add it to a page in the resource.");
|
||||
} elseif ($this->panel && empty($this->panel->getWidgetNamespaces())) {
|
||||
$this->components->info('Make sure to register the widget with [widgets()] or discover it with [discoverWidgets()] in the panel service provider.');
|
||||
}
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function configureFqnEnd(): void
|
||||
{
|
||||
$this->fqnEnd = (string) str($this->argument('name') ?? text(
|
||||
label: 'What is the widget name?',
|
||||
placeholder: 'BlogPostsChart',
|
||||
required: true,
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
protected function configureType(): void
|
||||
{
|
||||
$this->type = match (true) {
|
||||
boolval($this->option('chart')) => ChartWidget::class,
|
||||
boolval($this->option('stats-overview')) => StatsOverviewWidget::class,
|
||||
boolval($this->option('table')) => TableWidget::class,
|
||||
default => null,
|
||||
} ?? select(
|
||||
label: 'Which type of widget would you like to create?',
|
||||
options: [
|
||||
Widget::class => 'Custom',
|
||||
ChartWidget::class => 'Chart',
|
||||
StatsOverviewWidget::class => 'Stats overview',
|
||||
TableWidget::class => 'Table',
|
||||
],
|
||||
default: $this->input->isInteractive() ? null : Widget::class,
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureHasResource(): void
|
||||
{
|
||||
if (! $this->panel) {
|
||||
$this->hasResource = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->hasResource = $this->option('resource') || confirm(
|
||||
label: 'Would you like to create this widget in a resource?',
|
||||
default: false,
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureCluster(): void
|
||||
{
|
||||
if (! $this->hasResource) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configureClusterFqn(
|
||||
initialQuestion: 'Is the resource in a cluster?',
|
||||
question: 'Which cluster is the resource in?',
|
||||
);
|
||||
|
||||
if (blank($this->clusterFqn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configureClusterResourcesLocation();
|
||||
}
|
||||
|
||||
protected function configureResource(): void
|
||||
{
|
||||
if (! $this->hasResource) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configureResourcesLocation(question: 'Which namespace would you like to search for resources in?');
|
||||
|
||||
$this->resourceFqn = $this->askForResource(
|
||||
question: 'Which resource would you like to create this widget in?',
|
||||
initialResource: $this->option('resource'),
|
||||
);
|
||||
|
||||
$pluralResourceBasenameBeforeResource = (string) str($this->resourceFqn)
|
||||
->classBasename()
|
||||
->beforeLast('Resource')
|
||||
->plural();
|
||||
|
||||
$resourceNamespacePartBeforeBasename = (string) str($this->resourceFqn)
|
||||
->beforeLast('\\')
|
||||
->classBasename();
|
||||
|
||||
if ($pluralResourceBasenameBeforeResource === $resourceNamespacePartBeforeBasename) {
|
||||
$this->widgetsNamespace = (string) str($this->resourceFqn)
|
||||
->beforeLast('\\')
|
||||
->append('\\Widgets');
|
||||
$this->widgetsDirectory = (string) str((new ReflectionClass($this->resourceFqn))->getFileName())
|
||||
->beforeLast(DIRECTORY_SEPARATOR)
|
||||
->append('/Widgets');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->widgetsNamespace = "{$this->resourceFqn}\\Widgets";
|
||||
$this->widgetsDirectory = (string) str((new ReflectionClass($this->resourceFqn))->getFileName())
|
||||
->beforeLast('.')
|
||||
->append('/Widgets');
|
||||
}
|
||||
|
||||
protected function configureWidgetsLocation(): void
|
||||
{
|
||||
if (filled($this->resourceFqn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->panel) {
|
||||
[
|
||||
$this->widgetsNamespace,
|
||||
$this->widgetsDirectory,
|
||||
] = $this->askForLivewireComponentLocation(
|
||||
question: 'Where would you like to create the widget?',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$directories = $this->panel->getWidgetDirectories();
|
||||
$namespaces = $this->panel->getWidgetNamespaces();
|
||||
|
||||
foreach ($directories as $index => $directory) {
|
||||
if (is_path_within_vendor_directory($directory, base_path())) {
|
||||
unset($directories[$index]);
|
||||
unset($namespaces[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($namespaces) < 2) {
|
||||
$this->widgetsNamespace = (Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Widgets');
|
||||
$this->widgetsDirectory = (Arr::first($directories) ?? app_path('Filament/Widgets/'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$keyedNamespaces = array_combine(
|
||||
$namespaces,
|
||||
$namespaces,
|
||||
);
|
||||
|
||||
$this->widgetsNamespace = search(
|
||||
label: 'Which namespace would you like to create this widget in?',
|
||||
options: function (?string $search) use ($keyedNamespaces): array {
|
||||
if (blank($search)) {
|
||||
return $keyedNamespaces;
|
||||
}
|
||||
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return array_filter($keyedNamespaces, fn (string $namespace): bool => str($namespace)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
|
||||
},
|
||||
);
|
||||
$this->widgetsDirectory = $directories[array_search($this->widgetsNamespace, $namespaces)];
|
||||
}
|
||||
|
||||
protected function configureLocation(): void
|
||||
{
|
||||
$this->fqn = $this->widgetsNamespace . '\\' . $this->fqnEnd;
|
||||
|
||||
if ($this->type === Widget::class) {
|
||||
$componentLocations = FilamentCli::getLivewireComponentLocations();
|
||||
|
||||
$matchingComponentLocationNamespaces = collect($componentLocations)
|
||||
->keys()
|
||||
->filter(fn (string $namespace): bool => str($this->fqn)->startsWith($namespace));
|
||||
|
||||
[
|
||||
$this->view,
|
||||
$this->viewPath,
|
||||
] = $this->askForViewLocation(
|
||||
view: str($this->fqn)
|
||||
->whenContains(
|
||||
'Filament\\',
|
||||
fn (Stringable $fqn) => $fqn->after('Filament\\')->prepend('Filament\\'),
|
||||
fn (Stringable $fqn) => $fqn
|
||||
->afterLast('\\Livewire\\')
|
||||
->prepend('Livewire\\'),
|
||||
)
|
||||
->replace('\\', '/')
|
||||
->explode('/')
|
||||
->map(Str::kebab(...))
|
||||
->implode('.'),
|
||||
question: 'Where would you like to create the Blade view for the widget?',
|
||||
defaultNamespace: (count($matchingComponentLocationNamespaces) === 1)
|
||||
? $componentLocations[Arr::first($matchingComponentLocationNamespaces)]['viewNamespace'] ?? null
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createCustomWidget(): void
|
||||
{
|
||||
if ($this->type !== Widget::class) {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = (string) str("{$this->widgetsDirectory}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($path, app(CustomWidgetClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'view' => $this->view,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createChartWidget(): void
|
||||
{
|
||||
if ($this->type !== ChartWidget::class) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = select(
|
||||
label: 'Which type of chart would you like to create?',
|
||||
options: [
|
||||
'bar' => 'Bar chart',
|
||||
'bubble' => 'Bubble chart',
|
||||
'doughnut' => 'Doughnut chart',
|
||||
'line' => 'Line chart',
|
||||
'pie' => 'Pie chart',
|
||||
'polarArea' => 'Polar area chart',
|
||||
'radar' => 'Radar chart',
|
||||
'scatter' => 'Scatter chart',
|
||||
],
|
||||
default: 'line',
|
||||
);
|
||||
|
||||
$path = (string) str("{$this->widgetsDirectory}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($path, app(ChartWidgetClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'type' => $type,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createStatsOverviewWidget(): void
|
||||
{
|
||||
if ($this->type !== StatsOverviewWidget::class) {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = (string) str("{$this->widgetsDirectory}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($path, app(StatsOverviewWidgetClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createTableWidget(): void
|
||||
{
|
||||
if ($this->type !== TableWidget::class) {
|
||||
return;
|
||||
}
|
||||
|
||||
$modelFqns = discover_app_classes(parentClass: Model::class);
|
||||
|
||||
$modelFqn = suggest(
|
||||
label: 'What is the model?',
|
||||
options: function (string $search) use ($modelFqns): array {
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
if (blank($search)) {
|
||||
return $modelFqns;
|
||||
}
|
||||
|
||||
return array_filter(
|
||||
$modelFqns,
|
||||
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
|
||||
);
|
||||
},
|
||||
placeholder: app()->getNamespace() . 'Models\\BlogPost',
|
||||
);
|
||||
|
||||
$isGenerated = confirm(
|
||||
label: 'Should the table columns be generated from the current database columns?',
|
||||
default: false,
|
||||
);
|
||||
|
||||
$path = (string) str("{$this->widgetsDirectory}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($path, app(TableWidgetClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'modelFqn' => $modelFqn ?: Model::class,
|
||||
'isGenerated' => $isGenerated,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createView(): void
|
||||
{
|
||||
if (blank($this->view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($this->viewPath)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->copyStubToApp('WidgetView', $this->viewPath);
|
||||
}
|
||||
}
|
||||
11
vendor/filament/widgets/src/Concerns/CanAuthorizeAccess.php
vendored
Normal file
11
vendor/filament/widgets/src/Concerns/CanAuthorizeAccess.php
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Concerns;
|
||||
|
||||
trait CanAuthorizeAccess
|
||||
{
|
||||
public function hydrateCanAuthorizeAccess(): void
|
||||
{
|
||||
abort_unless(static::canView(), 403);
|
||||
}
|
||||
}
|
||||
13
vendor/filament/widgets/src/Concerns/CanPoll.php
vendored
Normal file
13
vendor/filament/widgets/src/Concerns/CanPoll.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\Concerns;
|
||||
|
||||
trait CanPoll
|
||||
{
|
||||
protected ?string $pollingInterval = '5s';
|
||||
|
||||
protected function getPollingInterval(): ?string
|
||||
{
|
||||
return $this->pollingInterval;
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/DoughnutChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/DoughnutChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class DoughnutChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'doughnut';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/LineChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/LineChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class LineChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/PieChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/PieChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class PieChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'pie';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/PolarAreaChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/PolarAreaChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class PolarAreaChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'polarArea';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/RadarChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/RadarChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class RadarChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'radar';
|
||||
}
|
||||
}
|
||||
14
vendor/filament/widgets/src/ScatterChartWidget.php
vendored
Normal file
14
vendor/filament/widgets/src/ScatterChartWidget.php
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
/**
|
||||
* @deprecated Extend `ChartWidget` instead and define the `getType()` method.
|
||||
*/
|
||||
class ScatterChartWidget extends ChartWidget
|
||||
{
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'scatter';
|
||||
}
|
||||
}
|
||||
128
vendor/filament/widgets/src/StatsOverviewWidget.php
vendored
Normal file
128
vendor/filament/widgets/src/StatsOverviewWidget.php
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Widgets\StatsOverviewWidget\Concerns\HasChartData;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class StatsOverviewWidget extends Widget implements HasSchemas
|
||||
{
|
||||
use Concerns\CanPoll;
|
||||
use HasChartData;
|
||||
use InteractsWithSchemas;
|
||||
|
||||
/**
|
||||
* @var array<Stat> | null
|
||||
*/
|
||||
protected ?array $cachedStats = null;
|
||||
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
protected ?string $heading = null;
|
||||
|
||||
protected ?string $description = null;
|
||||
|
||||
/**
|
||||
* @var int | array<string, ?int> | null
|
||||
*/
|
||||
protected int | array | null $columns = null;
|
||||
|
||||
/**
|
||||
* @var view-string
|
||||
*/
|
||||
protected string $view = 'filament-widgets::stats-overview-widget';
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
$this->getSectionContentComponent(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSectionContentComponent(): Component
|
||||
{
|
||||
return Section::make()
|
||||
->heading($this->getHeading())
|
||||
->description($this->getDescription())
|
||||
->schema($this->getCachedStats())
|
||||
->columns($this->getColumns())
|
||||
->contained(false)
|
||||
->gridContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | array<string, ?int> | null
|
||||
*/
|
||||
protected function getColumns(): int | array | null
|
||||
{
|
||||
if ($this->columns) {
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
$count = count($this->getCachedStats());
|
||||
|
||||
if ($count < 3) {
|
||||
return ['@xl' => 3, '!@lg' => 3];
|
||||
}
|
||||
|
||||
if (($count % 3) !== 1) {
|
||||
return ['@xl' => 3, '!@lg' => 3];
|
||||
}
|
||||
|
||||
return ['@xl' => 4, '!@lg' => 4];
|
||||
}
|
||||
|
||||
protected function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
protected function getHeading(): ?string
|
||||
{
|
||||
return $this->heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Stat>
|
||||
*/
|
||||
protected function getCachedStats(): array
|
||||
{
|
||||
if ($this->cachedStats !== null) {
|
||||
return $this->cachedStats;
|
||||
}
|
||||
|
||||
$stats = array_values($this->getStats());
|
||||
|
||||
foreach ($stats as $index => $stat) {
|
||||
if (($stat->getChart() !== null) && blank($stat->getKey(isAbsolute: false))) {
|
||||
$stat->key('stats-overview-stat-' . $index);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cachedStats = $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getStats()` instead.
|
||||
*
|
||||
* @return array<Stat>
|
||||
*/
|
||||
protected function getCards(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Stat>
|
||||
*/
|
||||
protected function getStats(): array
|
||||
{
|
||||
return $this->getCards();
|
||||
}
|
||||
}
|
||||
73
vendor/filament/widgets/src/StatsOverviewWidget/Concerns/HasChartData.php
vendored
Normal file
73
vendor/filament/widgets/src/StatsOverviewWidget/Concerns/HasChartData.php
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\StatsOverviewWidget\Concerns;
|
||||
|
||||
use Livewire\Attributes\Locked;
|
||||
|
||||
trait HasChartData
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
#[Locked]
|
||||
public array $chartDataChecksums = [];
|
||||
|
||||
public function mountHasChartData(): void
|
||||
{
|
||||
$this->chartDataChecksums = $this->getStatChartDataChecksums();
|
||||
}
|
||||
|
||||
public function renderingHasChartData(): void
|
||||
{
|
||||
$this->updateChartData();
|
||||
}
|
||||
|
||||
public function updateChartData(): void
|
||||
{
|
||||
foreach ($this->getCachedStats() as $stat) {
|
||||
if ($stat->getChart() === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $stat->getKey(isAbsolute: false);
|
||||
|
||||
if ($key === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newChecksum = $stat->generateChartDataChecksum();
|
||||
|
||||
if (($this->chartDataChecksums[$key] ?? null) === $newChecksum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->chartDataChecksums[$key] = $newChecksum;
|
||||
|
||||
$this->dispatch('updateStatsOverviewChartData', key: $key, data: array_values($stat->getChart()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function getStatChartDataChecksums(): array
|
||||
{
|
||||
$checksums = [];
|
||||
|
||||
foreach ($this->getCachedStats() as $stat) {
|
||||
if ($stat->getChart() === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $stat->getKey(isAbsolute: false);
|
||||
|
||||
if ($key === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$checksums[$key] = $stat->generateChartDataChecksum();
|
||||
}
|
||||
|
||||
return $checksums;
|
||||
}
|
||||
}
|
||||
187
vendor/filament/widgets/src/StatsOverviewWidget/Stat.php
vendored
Normal file
187
vendor/filament/widgets/src/StatsOverviewWidget/Stat.php
vendored
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\StatsOverviewWidget;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Concerns\CanOpenUrl;
|
||||
use Filament\Schemas\Components\Concerns\HasDescription;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Support\Concerns\HasColor;
|
||||
use Filament\Support\Concerns\HasPlaceholder;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Stat extends Component
|
||||
{
|
||||
use CanOpenUrl;
|
||||
use HasColor;
|
||||
use HasDescription;
|
||||
use HasLabel;
|
||||
use HasPlaceholder;
|
||||
|
||||
protected string $view = 'filament-widgets::stats-overview-widget.stat';
|
||||
|
||||
/**
|
||||
* @var array<float> | null
|
||||
*/
|
||||
protected ?array $chart = null;
|
||||
|
||||
/**
|
||||
* @var string | array<string> | null
|
||||
*/
|
||||
protected string | array | null $chartColor = null;
|
||||
|
||||
protected string | BackedEnum | null $icon = null;
|
||||
|
||||
protected string | BackedEnum | null $descriptionIcon = null;
|
||||
|
||||
protected IconPosition | string | null $descriptionIconPosition = null;
|
||||
|
||||
/**
|
||||
* @var string | array<string> | null
|
||||
*/
|
||||
protected string | array | null $descriptionColor = null;
|
||||
|
||||
/**
|
||||
* @var scalar | Htmlable | Closure | null
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* @param scalar | Htmlable | Closure | null $value
|
||||
*/
|
||||
final public function __construct(string | Htmlable $label, $value)
|
||||
{
|
||||
$this->label($label);
|
||||
$this->value($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scalar | Htmlable | Closure | null $value
|
||||
*/
|
||||
public static function make(string | Htmlable $label, $value): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label, 'value' => $value]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $color
|
||||
*/
|
||||
public function chartColor(string | array | null $color): static
|
||||
{
|
||||
$this->chartColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function icon(string | BackedEnum | null $icon): static
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $color
|
||||
*/
|
||||
public function descriptionColor(string | array | null $color): static
|
||||
{
|
||||
$this->descriptionColor = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function descriptionIcon(string | BackedEnum | null $icon, IconPosition | string | null $position = null): static
|
||||
{
|
||||
$this->descriptionIcon = $icon;
|
||||
$this->descriptionIconPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<float> | Arrayable | null $chart
|
||||
*/
|
||||
public function chart(array | Arrayable | null $chart): static
|
||||
{
|
||||
if (is_null($chart)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($chart instanceof Arrayable) {
|
||||
$chart = $chart->toArray();
|
||||
}
|
||||
|
||||
$this->chart = $chart;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scalar | Htmlable | Closure | null $value
|
||||
*/
|
||||
public function value($value): static
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<float> | null
|
||||
*/
|
||||
public function getChart(): ?array
|
||||
{
|
||||
return $this->chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getChartColor(): string | array | null
|
||||
{
|
||||
return $this->chartColor ?? $this->getColor();
|
||||
}
|
||||
|
||||
public function getIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getDescriptionColor(): string | array | null
|
||||
{
|
||||
return $this->descriptionColor ?? $this->getColor();
|
||||
}
|
||||
|
||||
public function getDescriptionIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->descriptionIcon;
|
||||
}
|
||||
|
||||
public function getDescriptionIconPosition(): IconPosition | string
|
||||
{
|
||||
return $this->descriptionIconPosition ?? IconPosition::After;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return scalar | Htmlable | null
|
||||
*/
|
||||
public function getValue(): mixed
|
||||
{
|
||||
return $this->evaluate($this->value);
|
||||
}
|
||||
|
||||
public function generateChartDataChecksum(): string
|
||||
{
|
||||
return md5(json_encode($this->getChart()));
|
||||
}
|
||||
}
|
||||
53
vendor/filament/widgets/src/TableWidget.php
vendored
Normal file
53
vendor/filament/widgets/src/TableWidget.php
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Enums\PaginationMode;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class TableWidget extends Widget implements HasActions, HasSchemas, HasTable
|
||||
{
|
||||
use InteractsWithActions;
|
||||
use InteractsWithSchemas;
|
||||
use InteractsWithTable {
|
||||
makeTable as makeBaseTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var view-string
|
||||
*/
|
||||
protected string $view = 'filament-widgets::table-widget';
|
||||
|
||||
/**
|
||||
* @deprecated Override the `table()` method to configure the table.
|
||||
*/
|
||||
protected static ?string $heading = null;
|
||||
|
||||
/**
|
||||
* @deprecated Override the `table()` method to configure the table.
|
||||
*/
|
||||
protected function getTableHeading(): string | Htmlable | null
|
||||
{
|
||||
return static::$heading;
|
||||
}
|
||||
|
||||
protected function makeTable(): Table
|
||||
{
|
||||
return $this->makeBaseTable()
|
||||
->heading(
|
||||
$this->getTableHeading() ?? (string) str(class_basename(static::class))
|
||||
->beforeLast('Widget')
|
||||
->kebab()
|
||||
->replace('-', ' ')
|
||||
->ucwords(),
|
||||
)
|
||||
->paginationMode(PaginationMode::Simple);
|
||||
}
|
||||
}
|
||||
18
vendor/filament/widgets/src/View/Components/ChartWidgetComponent.php
vendored
Normal file
18
vendor/filament/widgets/src/View/Components/ChartWidgetComponent.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\View\Components;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class ChartWidgetComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\View\Components\StatsOverviewWidgetComponent\StatComponent;
|
||||
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\View\Components\ColorMaps\ComponentColorMap;
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class DescriptionComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
$gray = FilamentColor::getColor('gray');
|
||||
|
||||
return ComponentColorMap::make($color)
|
||||
->slot('text', surface: 'oklch(1 0 0)', minShade: 600, fallback: 950)
|
||||
->slot('dark:text', surface: $gray[900], maxShade: 400, shouldStartFromDarkest: true, fallback: 200)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\View\Components\StatsOverviewWidgetComponent\StatComponent;
|
||||
|
||||
use Filament\Support\View\Components\Contracts\HasColor;
|
||||
use Filament\Support\View\Components\Contracts\HasDefaultGrayColor;
|
||||
|
||||
class StatsOverviewWidgetStatChartComponent implements HasColor, HasDefaultGrayColor
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $color
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getColorMap(array $color): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
10
vendor/filament/widgets/src/View/WidgetsIconAlias.php
vendored
Normal file
10
vendor/filament/widgets/src/View/WidgetsIconAlias.php
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\View;
|
||||
|
||||
class WidgetsIconAlias
|
||||
{
|
||||
const CHART_WIDGET_FILTER = 'widgets::chart-widget.filter';
|
||||
|
||||
const CHART_WIDGET_EMPTY_STATE = 'widgets::chart-widget.empty-state';
|
||||
}
|
||||
10
vendor/filament/widgets/src/View/WidgetsRenderHook.php
vendored
Normal file
10
vendor/filament/widgets/src/View/WidgetsRenderHook.php
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets\View;
|
||||
|
||||
class WidgetsRenderHook
|
||||
{
|
||||
const TABLE_WIDGET_END = 'widgets::table-widget.end';
|
||||
|
||||
const TABLE_WIDGET_START = 'widgets::table-widget.start';
|
||||
}
|
||||
110
vendor/filament/widgets/src/Widget.php
vendored
Normal file
110
vendor/filament/widgets/src/Widget.php
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
use Filament\Support\Concerns\CanBeLazy;
|
||||
use Filament\Widgets\Concerns\CanAuthorizeAccess;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
abstract class Widget extends Component
|
||||
{
|
||||
use CanAuthorizeAccess;
|
||||
use CanBeLazy;
|
||||
|
||||
protected static bool $isDiscovered = true;
|
||||
|
||||
protected static ?int $sort = null;
|
||||
|
||||
/**
|
||||
* @var view-string
|
||||
*/
|
||||
protected string $view;
|
||||
|
||||
/**
|
||||
* @var int | string | array<string, int | null>
|
||||
*/
|
||||
protected int | string | array $columnSpan = 1;
|
||||
|
||||
/**
|
||||
* @var int | string | array<string, int | null>
|
||||
*/
|
||||
protected int | string | array $columnStart = [];
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getSort(): int
|
||||
{
|
||||
return static::$sort ?? -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | string | array<string, int | null>
|
||||
*/
|
||||
public function getColumnSpan(): int | string | array
|
||||
{
|
||||
return $this->columnSpan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | string | array<string, int | null>
|
||||
*/
|
||||
public function getColumnStart(): int | string | array
|
||||
{
|
||||
return $this->columnStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getViewData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function isDiscovered(): bool
|
||||
{
|
||||
return static::$isDiscovered;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view($this->view, $this->getViewData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public static function make(array $properties = []): WidgetConfiguration
|
||||
{
|
||||
return app(WidgetConfiguration::class, ['widget' => static::class, 'properties' => $properties]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getPlaceholderData(): array
|
||||
{
|
||||
return [
|
||||
'columnSpan' => $this->getColumnSpan(),
|
||||
'columnStart' => $this->getColumnStart(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function getDefaultProperties(): array
|
||||
{
|
||||
$properties = [];
|
||||
|
||||
if (static::isLazy()) {
|
||||
$properties['lazy'] = true;
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
}
|
||||
23
vendor/filament/widgets/src/WidgetConfiguration.php
vendored
Normal file
23
vendor/filament/widgets/src/WidgetConfiguration.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
class WidgetConfiguration
|
||||
{
|
||||
/**
|
||||
* @param class-string<Widget> $widget
|
||||
* @param array<string, mixed> $properties
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $widget,
|
||||
protected array $properties = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getProperties(): array
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
}
|
||||
39
vendor/filament/widgets/src/WidgetsServiceProvider.php
vendored
Normal file
39
vendor/filament/widgets/src/WidgetsServiceProvider.php
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Widgets;
|
||||
|
||||
use Filament\Support\Assets\AlpineComponent;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
|
||||
class WidgetsServiceProvider extends PackageServiceProvider
|
||||
{
|
||||
public function configurePackage(Package $package): void
|
||||
{
|
||||
$package
|
||||
->name('filament-widgets')
|
||||
->hasCommands([
|
||||
Commands\MakeWidgetCommand::class,
|
||||
])
|
||||
->hasTranslations()
|
||||
->hasViews();
|
||||
}
|
||||
|
||||
public function packageBooted(): void
|
||||
{
|
||||
FilamentAsset::register([
|
||||
AlpineComponent::make('chart', __DIR__ . '/../dist/components/chart.js'),
|
||||
AlpineComponent::make('stats-overview/stat/chart', __DIR__ . '/../dist/components/stats-overview/stat/chart.js'),
|
||||
], 'filament/widgets');
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) {
|
||||
$this->publishes([
|
||||
$file->getRealPath() => base_path("stubs/filament/{$file->getFilename()}"),
|
||||
], 'filament-stubs');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
vendor/filament/widgets/stubs/WidgetView.stub
vendored
Normal file
5
vendor/filament/widgets/stubs/WidgetView.stub
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<x-filament-widgets::widget>
|
||||
<x-filament::section>
|
||||
{{-- Widget content --}}
|
||||
</x-filament::section>
|
||||
</x-filament-widgets::widget>
|
||||
Loading…
Add table
Add a link
Reference in a new issue