elegantly/filament-kpi

Plugin for elegantly/laravel-kpi

v1.0.0 2024-09-17 16:07 UTC

This package is auto-updated.

Last update: 2024-10-19 17:14:46 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This plugin allows you to create charts and stats using elegantly/laravel-kpi like this:

use Elegantly\FilamentKpi\Widgets\KpiStat;
use App\Kpis\Users\UsersCountKpi;

KpiStat::kpi(UsersCountKpi::class);
class UsersChart extends KpiChart
{
    protected static string $kpi = UsersCountKpi::class;
}

Installation

You can install the package via composer:

composer require elegantly/filament-kpi

Usage

Display a Kpi Stat

namespace App\Filament\Resources\UserResource\Widgets;

use Elegantly\FilamentKpi\Widgets\KpiStat;
use App\Kpis\Users\UsersCountKpi;
use Filament\Widgets\StatsOverviewWidget;

class UsersStatsOverview extends StatsOverviewWidget
{
    protected static ?string $pollingInterval = null;

    protected function getCards(): array
    {
        return [
            KpiStat::kpi(
                definition: UsersCountKpi::class,
                interval: KpiInterval::Day, // (optional) default to UsersCountKpi::getSnapshotInterval()
                diff: true, // (optional) default to is_subclass_of(UsersCountKpi::class, HasDifference::class)
            ),
        ];
    }
}

Display a Kpi Chart

namespace App\Filament\Resources\UserResource\Widgets;

use Elegantly\FilamentKpi\Widgets\KpiChart;
use App\Kpis\Users\UsersCountKpi;

class UsersChart extends KpiChart
{
    protected static string $kpi = UsersCountKpi::class;
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.