mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Remove static props
This commit is contained in:
@@ -9,6 +9,8 @@ use Filament\Pages\Page;
|
||||
use Filament\Pages\SimplePage;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\Widget;
|
||||
use PhpParser\Modifiers;
|
||||
use PhpParser\Node;
|
||||
@@ -92,6 +94,39 @@ class SimplePropertyChangesRector extends AbstractRector
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => [
|
||||
ChartWidget::class,
|
||||
StatsOverviewWidget::class,
|
||||
],
|
||||
'changes' => [
|
||||
'pollingInterval' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => [
|
||||
ChartWidget::class,
|
||||
],
|
||||
'changes' => [
|
||||
'color' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
'heading' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
'description' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
'maxHeight' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
'options' => function (Property $node) {
|
||||
$node->flags &= ~Modifiers::STATIC;
|
||||
},
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -147,13 +147,13 @@ 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 static ?string $pollingInterval = '10s';
|
||||
protected ?string $pollingInterval = '10s';
|
||||
```
|
||||
|
||||
Alternatively, you may disable polling altogether:
|
||||
|
||||
```php
|
||||
protected static ?string $pollingInterval = null;
|
||||
protected ?string $pollingInterval = null;
|
||||
```
|
||||
|
||||
## Disabling lazy loading
|
||||
|
||||
@@ -14,7 +14,7 @@ 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 static ?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 `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.
|
||||
|
||||
@@ -27,7 +27,7 @@ use Filament\Widgets\ChartWidget;
|
||||
|
||||
class BlogPostsChart extends ChartWidget
|
||||
{
|
||||
protected static ?string $heading = 'Blog Posts';
|
||||
protected ?string $heading = 'Blog Posts';
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
@@ -69,7 +69,7 @@ Below is a list of available chart widget classes which you may extend, and thei
|
||||
You can customize the [color](../styling/colors) of the chart data by setting the `$color` property:
|
||||
|
||||
```php
|
||||
protected static string $color = 'info';
|
||||
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:
|
||||
@@ -165,13 +165,13 @@ 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 static ?string $pollingInterval = '10s';
|
||||
protected ?string $pollingInterval = '10s';
|
||||
```
|
||||
|
||||
Alternatively, you may disable polling altogether:
|
||||
|
||||
```php
|
||||
protected static ?string $pollingInterval = null;
|
||||
protected ?string $pollingInterval = null;
|
||||
```
|
||||
|
||||
## Setting a maximum chart height
|
||||
@@ -179,7 +179,7 @@ protected static ?string $pollingInterval = null;
|
||||
You may place a maximum height on the chart to ensure that it doesn't get too big, using the `$maxHeight` property:
|
||||
|
||||
```php
|
||||
protected static ?string $maxHeight = '300px';
|
||||
protected ?string $maxHeight = '300px';
|
||||
```
|
||||
|
||||
## Setting chart configuration options
|
||||
@@ -187,7 +187,7 @@ protected static ?string $maxHeight = '300px';
|
||||
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 static ?array $options = [
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'display' => false,
|
||||
|
||||
@@ -23,18 +23,18 @@ abstract class ChartWidget extends Widget implements HasSchemas
|
||||
|
||||
public ?string $filter = null;
|
||||
|
||||
protected static string $color = 'primary';
|
||||
protected string $color = 'primary';
|
||||
|
||||
protected static ?string $heading = null;
|
||||
protected ?string $heading = null;
|
||||
|
||||
protected static ?string $description = null;
|
||||
protected ?string $description = null;
|
||||
|
||||
protected static ?string $maxHeight = null;
|
||||
protected ?string $maxHeight = null;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | null
|
||||
*/
|
||||
protected static ?array $options = null;
|
||||
protected ?array $options = null;
|
||||
|
||||
/**
|
||||
* @var view-string
|
||||
@@ -83,17 +83,17 @@ abstract class ChartWidget extends Widget implements HasSchemas
|
||||
|
||||
public function getHeading(): string | Htmlable | null
|
||||
{
|
||||
return static::$heading;
|
||||
return $this->heading;
|
||||
}
|
||||
|
||||
public function getDescription(): string | Htmlable | null
|
||||
{
|
||||
return static::$description;
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
protected function getMaxHeight(): ?string
|
||||
{
|
||||
return static::$maxHeight;
|
||||
return $this->maxHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ abstract class ChartWidget extends Widget implements HasSchemas
|
||||
*/
|
||||
protected function getOptions(): array | RawJs | null
|
||||
{
|
||||
return static::$options;
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function updateChartData(): void
|
||||
@@ -122,6 +122,6 @@ abstract class ChartWidget extends Widget implements HasSchemas
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return static::$color;
|
||||
return $this->color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ namespace Filament\Widgets\Concerns;
|
||||
|
||||
trait CanPoll
|
||||
{
|
||||
protected static ?string $pollingInterval = '5s';
|
||||
protected ?string $pollingInterval = '5s';
|
||||
|
||||
protected function getPollingInterval(): ?string
|
||||
{
|
||||
return static::$pollingInterval;
|
||||
return $this->pollingInterval;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user