├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── codecov.yml ├── composer.json ├── examples ├── ExampleBarChart.php ├── ExampleDoughnutChart.php ├── ExampleLineChart.php └── ExamplePieChart.php ├── resources └── views │ ├── chart_refresh.blade.php │ └── tile.blade.php └── src ├── ChartTileServiceProvider.php ├── Charts └── Chart.php ├── Components ├── ChartComponent.php └── ChartRefreshComponent.php ├── Contracts └── ChartFactory.php └── Factories └── DefaultChartFactory.php /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `fidum/laravel-dashboard-chart-tile` will be documented in this file 4 | 5 | ## 6.2.0 - 2025-02-24 6 | 7 | ### What's Changed 8 | 9 | * Run tests on PHP 8.4 by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/30 10 | * Adds Laravel 12.x Support by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/31 11 | 12 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/6.1.0...6.2.0 13 | 14 | ## 6.1.0 - 2024-03-13 15 | 16 | ### What's Changed 17 | 18 | * Support Laravel 11 by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/29 19 | 20 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/6.0.0...6.1.0 21 | 22 | ## 6.0.0 - 2023-12-02 23 | 24 | ### What's Changed 25 | 26 | * Run tests on PHP 8.3 by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/26 27 | * Upgrade to Laravel Dashboard 3.x by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/27 28 | 29 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/5.0.1...6.0.0 30 | 31 | ## 5.0.1 - 2023-02-08 32 | 33 | ### What's Changed 34 | 35 | - Add Laravel 10 support by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/25 36 | 37 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/5.0.0...5.0.1 38 | 39 | ## 5.0.0 - 2022-08-19 40 | 41 | ### What's Changed 42 | 43 | - Revert to ConsoleTvs/Charts v6 by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/24 44 | 45 | > If you're wondering what happened to the ConsoleTVs/Charts v7 version please read this: https://github.com/ConsoleTVs/Charts/issues/1#issuecomment-1208550258 46 | 47 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/4.1.0...5.0.0 48 | 49 | ## 4.1.0 - 2022-02-10 50 | 51 | ## What's Changed 52 | 53 | - Run tests in PHP 8.1 by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/21 54 | - Add Laravel 9 Support by @dmason30 in https://github.com/fidum/laravel-dashboard-chart-tile/pull/22 55 | 56 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-chart-tile/compare/4.0.1...4.1.0 57 | 58 | ## 4.0.1 - 2020-12-12 59 | 60 | **Added** 61 | 62 | - Added PHP 8 Support 63 | 64 | ## 4.0.0 - 2020-09-10 65 | 66 | **Added** 67 | 68 | - Added Laravel 8 Support 69 | - Added `spatie/laravel-dashboard` 2.0.0 support 70 | 71 | **Changed** 72 | 73 | - Updated `consoletvs/charts` to 7.1 74 | 75 | **Breaking** 76 | 77 | - Dropped Laravel 7 support 78 | - Dropped `spatie/laravel-dashboard` 1.x support 79 | 80 | ## 3.1.1 - 2020-07-17 81 | 82 | **Changed** 83 | 84 | - Switch to chartisan 2.1.* UMD build ([#12](https://github.com/fidum/laravel-dashboard-chart-tile/pull/12)) 85 | 86 | ## 3.1.0 - 2020-07-17 87 | 88 | **Fixed** 89 | 90 | - Fix scripts getting the latest versions that contain breaking changes ([#11](https://github.com/fidum/laravel-dashboard-chart-tile/pull/11)) 91 | 92 | ## 3.0.3 - 2020-07-06 93 | 94 | **Added** 95 | 96 | - Add support to use any frontend chart library ([#9](https://github.com/fidum/laravel-dashboard-chart-tile/pull/9)) 97 | 98 | ## 3.0.2 - 2020-07-05 99 | 100 | **Fixed** 101 | 102 | - Chart API url was incorrectly escaped in view 103 | 104 | ## 3.0.1 - 2020-07-05 105 | 106 | **Fixed** 107 | 108 | - Move psalm dependencies to require-dev 109 | 110 | ## 3.0.0 - 2020-07-05 111 | 112 | **Breaking** 113 | 114 | - Changed to v7 of ConsoleTVs/Charts package. ([#7](https://github.com/fidum/laravel-dashboard-chart-tile/pull/7)) 115 | - Changed `chartSettings` tile property name to `chartFilters` 116 | 117 | The v7 release of the Charts package was a complete rewrite. Therefore it was not possible to support this version and 118 | keep it backwards compatible. This has resulted in another breaking change and another major version. 119 | 120 | The `ChartFactory` interface no longer exists. All charts must now extend `Fidum\ChartTile\Charts\Chart` abstract class. 121 | 122 | See README for updated documentation. 123 | 124 | ## 2.0.0 - 2020-05-15 125 | 126 | **Added** 127 | 128 | - Add `chartSettings` tile property ([#3](https://github.com/fidum/laravel-dashboard-chart-tile/pull/3)) 129 | 130 | **Breaking** 131 | 132 | - `Fidum\ChartTile\Contracts\ChartFactory::make` signature has changed to have the `array $settings` argument. 133 | 134 | ## 1.1.0 - 2020-05-15 135 | 136 | **Added** 137 | 138 | - Add `refreshIntervalInSeconds` tile property ([#2](https://github.com/fidum/laravel-dashboard-chart-tile/pull/2)) 139 | 140 | ## 1.0.0 - 2020-05-14 141 | 142 | - initial release 143 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - We automatically manage this in our CI so you don't need to worry about this too much when submitting your changes. 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Fidum 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Dashboard Charting Tile 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/fidum/laravel-dashboard-chart-tile.svg?style=for-the-badge)](https://packagist.org/packages/fidum/laravel-dashboard-chart-tile) 4 | [![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/fidum/laravel-dashboard-chart-tile/run-tests.yml?branch=main&style=for-the-badge)](https://github.com/fidum/laravel-dashboard-chart-tile/actions?query=workflow%3Arun-tests+branch%3Amaster) 5 | [![Codecov](https://img.shields.io/codecov/c/github/fidum/laravel-dashboard-chart-tile?logo=codecov&logoColor=white&style=for-the-badge)](https://codecov.io/gh/fidum/laravel-dashboard-chart-tile) 6 | [![Twitter Follow](https://img.shields.io/badge/follow-%40danmasonmp-1DA1F2?logo=twitter&style=for-the-badge)](https://twitter.com/danmasonmp) 7 | 8 | Show off your charting skills with this easy to use tile. Supports line, bar, pie, doughnut and many more! 9 | 10 | ![Preview](docs/preview.png) 11 | 12 | ## Installation 13 | 14 | You can install the package via composer: 15 | 16 | ```bash 17 | composer require fidum/laravel-dashboard-chart-tile 18 | ``` 19 | 20 | ## Usage 21 | In the `dashboard` config file, you can optionally add this configuration in the `tiles` key. 22 | 23 | ```php 24 | // in config/dashboard.php 25 | return [ 26 | // ... 27 | 'tiles' => [ 28 | 'charts' => [ 29 | 'refresh_interval_in_seconds' => 300, // Default: 300 seconds (5 minutes) 30 | ], 31 | ], 32 | ]; 33 | ``` 34 | This tile uses `chart.js` to render the charts with the help of `Laravel Charts` package see links to 35 | documentation for both below: 36 | 37 | - [Laravel Charts Documentation](https://charts.erik.cat/) 38 | - [Chart.js Documentation](https://www.chartjs.org/docs/latest/charts/) 39 | 40 | 41 | So that you can easily add your datasets and configure your charts exactly how you want them you need to create 42 | a chart class that implements the `Fidum\ChartTile\Contracts\ChartFactory` interface. 43 | 44 | See chart example below: 45 | 46 | ```php 47 | namespace App\Charts; 48 | 49 | use Carbon\Carbon; 50 | use Fidum\ChartTile\Charts\Chart; 51 | use Fidum\ChartTile\Contracts\ChartFactory; 52 | 53 | class ExampleBarChart implements ChartFactory 54 | { 55 | public static function make(array $settings): ChartFactory 56 | { 57 | return new static; 58 | } 59 | 60 | public function chart(): Chart 61 | { 62 | $date = Carbon::now()->subMonth()->startOfDay(); 63 | 64 | $data = collect(range(0, 12))->map(function ($days) use ($date) { 65 | return [ 66 | 'x' => $date->clone()->addDays($days)->toDateString(), 67 | 'y' => rand(100, 500), 68 | ]; 69 | }); 70 | 71 | $chart = (new Chart) 72 | ->labels($data->pluck('x')->toArray()) 73 | ->options([ 74 | 'responsive' => true, 75 | 'maintainAspectRatio' => false, 76 | // etc... 77 | ], true); 78 | 79 | $chart->dataset('Example Data', 'bar', $data->toArray()) 80 | ->backgroundColor('#848584'); 81 | 82 | return $chart; 83 | } 84 | } 85 | ``` 86 | 87 | In your dashboard view you can use the below component as many times as needed. Pass your chart class 88 | reference to the component and that will be used to generate the chart. 89 | 90 | ```blade 91 | 92 | 93 | 94 | ``` 95 | 96 | ### Optional properties: 97 | - `chartFilters` optional key value array of settings that is passed to your chart `static::make` method. 98 | **Only use this for passing simple values `strings`, `integers`, `arrays` etc.** 99 | To use this you will have to use `@livewire` syntax over the component syntax in order set the array value. 100 | ```blade 101 | @livewire('chart-tile', [ 102 | 'chartFactory' => App\Charts\DailyUsersChart::class, 103 | 'chartFilters' => ['type' => 'customer'], 104 | ]) 105 | ``` 106 | 107 | - `height` sets the height of the chart, depending on your dashboard layout you may need to adjust this (defaults to `100%`). 108 | 109 | - `refreshIntervalInSeconds` use this to override the refresh rate of an individual tile (defaults to `300` seconds) 110 | 111 | ## Examples 112 | We have provided some chart factory examples to help get you started [here](examples). 113 | You can use the below dashboard layout to have an instant showcase of these examples: 114 | 115 | ```blade 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | ``` 129 | 130 | ## Testing 131 | ```bash 132 | composer test 133 | ``` 134 | 135 | ## Changelog 136 | 137 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 138 | 139 | ## Contributing 140 | 141 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 142 | 143 | ## Security 144 | 145 | If you discover any security related issues, please email :author_email instead of using the issue tracker. 146 | 147 | ## Credits 148 | 149 | - [All Contributors](../../contributors) 150 | 151 | ## License 152 | 153 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 154 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | informational: true 6 | patch: 7 | default: 8 | informational: true 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fidum/laravel-dashboard-chart-tile", 3 | "description": "Generic chart tiles for laravel dashboard", 4 | "keywords": [ 5 | "fidum", 6 | "laravel-dashboard", 7 | "laravel-dashboard-chart-tile", 8 | "chart" 9 | ], 10 | "homepage": "https://github.com/fidum/laravel-dashboard-chart-tile", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Daniel Mason", 15 | "email": "fidum.dev@gmail.com", 16 | "homepage": "https://fidum.uk", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php": "^8.3", 22 | "consoletvs/charts": "^6.6.0", 23 | "spatie/laravel-dashboard": "^3.0" 24 | }, 25 | "require-dev": { 26 | "mockery/mockery": "^1.4", 27 | "orchestra/testbench": "^8.0|^9.0|^10.0", 28 | "phpunit/phpunit": "^10.5|^11.5.3" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "Fidum\\ChartTile\\": "src", 33 | "Fidum\\ChartTile\\Examples\\": "examples" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Fidum\\ChartTile\\Tests\\": "tests" 39 | } 40 | }, 41 | "scripts": { 42 | "psalm": "vendor/bin/psalm", 43 | "test": "vendor/bin/phpunit" 44 | }, 45 | "config": { 46 | "sort-packages": true 47 | }, 48 | "extra": { 49 | "laravel": { 50 | "providers": [ 51 | "Fidum\\ChartTile\\ChartTileServiceProvider" 52 | ] 53 | } 54 | }, 55 | "minimum-stability": "dev", 56 | "prefer-stable": true 57 | } 58 | -------------------------------------------------------------------------------- /examples/ExampleBarChart.php: -------------------------------------------------------------------------------- 1 | subMonth()->startOfDay(); 19 | 20 | $data = collect(range(0, 12))->map(function ($days) use ($date) { 21 | return [ 22 | 'x' => $date->clone()->addDays($days)->toDateString(), 23 | 'y' => rand(100, 500), 24 | ]; 25 | }); 26 | 27 | $chart = (new Chart()) 28 | ->labels($data->pluck('x')->toArray()) 29 | ->options($this->options(), true); 30 | 31 | $chart->dataset('Example Data', 'bar', $data->toArray()) 32 | ->backgroundColor('#848584'); 33 | 34 | return $chart; 35 | } 36 | 37 | private function options(): array 38 | { 39 | return [ 40 | 'responsive' => true, 41 | 'maintainAspectRatio' => false, 42 | 'legend' => [ 43 | 'display' => true, 44 | 'labels' => [ 45 | 'boxWidth' => 0, 46 | ], 47 | ], 48 | 'scales' => [ 49 | 'xAxes' => [[ 50 | 'display' => true, 51 | 'offset' => true, 52 | 'type' => 'time', 53 | 'ticks' => [ 54 | 'source' => 'auto', 55 | 'maxRotation' => 0, 56 | ], 57 | 'time' => [ 58 | 'unit' => 'day', 59 | 'round' => true, 60 | 'displayFormats' => [ 61 | 'day' => 'MMM D', 62 | ], 63 | ], 64 | ]], 65 | ], 66 | ]; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/ExampleDoughnutChart.php: -------------------------------------------------------------------------------- 1 | labels(['Tea', 'Coffee', 'Soda', 'Juice']) 23 | ->options([ 24 | 'responsive' => true, 25 | 'maintainAspectRatio' => true, 26 | 'animation' => [ 27 | 'duration' => 0, 28 | ], 29 | 'legend' => [ 30 | 'display' => true, 31 | 'position' => 'right', 32 | ], 33 | 'scales' => [ 34 | 'xAxes' => ['display' => false], 35 | 'yAxes' => ['display' => false], 36 | ], 37 | ]) 38 | ->dataset('Drinks', 'doughnut', $data) 39 | ->backgroundColor(['#FF9CEE', '#B28DFF', '#6EB5FF', '#BFFCC6']); 40 | 41 | return $chart; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/ExampleLineChart.php: -------------------------------------------------------------------------------- 1 | subMonth()->startOfDay(); 19 | 20 | $data = collect(range(0, 12))->map(function ($days) use ($date) { 21 | return [ 22 | 'x' => $date->clone()->addDays($days)->toDateString(), 23 | 'y' => rand(100, 500), 24 | ]; 25 | }); 26 | 27 | $chart = (new Chart()) 28 | ->labels($data->pluck('x')->toArray()) 29 | ->options($this->options(), true); 30 | 31 | $chart->dataset('Example Data', 'line', $data->toArray()) 32 | ->backgroundColor('#B28CFF'); 33 | 34 | return $chart; 35 | } 36 | 37 | private function options(): array 38 | { 39 | return [ 40 | 'responsive' => true, 41 | 'maintainAspectRatio' => false, 42 | 'animation' => [ 43 | 'duration' => 0, 44 | ], 45 | 'legend' => [ 46 | 'display' => true, 47 | 'labels' => [ 48 | 'boxWidth' => 0, 49 | ], 50 | ], 51 | 'scales' => [ 52 | 'xAxes' => [[ 53 | 'display' => true, 54 | 'offset' => true, 55 | 'type' => 'time', 56 | 'ticks' => [ 57 | 'source' => 'auto', 58 | 'maxRotation' => 0, 59 | ], 60 | 'time' => [ 61 | 'unit' => 'day', 62 | 'round' => true, 63 | 'displayFormats' => [ 64 | 'day' => 'MMM D', 65 | ], 66 | ], 67 | ]], 68 | ], 69 | ]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/ExamplePieChart.php: -------------------------------------------------------------------------------- 1 | labels(['Tea', 'Coffee', 'Soda', 'Juice']) 23 | ->options([ 24 | 'responsive' => true, 25 | 'maintainAspectRatio' => true, 26 | 'animation' => [ 27 | 'duration' => 0, 28 | ], 29 | 'legend' => [ 30 | 'display' => true, 31 | 'position' => 'right', 32 | ], 33 | 'scales' => [ 34 | 'xAxes' => ['display' => false], 35 | 'yAxes' => ['display' => false], 36 | ], 37 | ]) 38 | ->dataset('Drinks', 'pie', $data) 39 | ->backgroundColor(['#FF9CEE', '#B28DFF', '#6EB5FF', '#BFFCC6']); 40 | 41 | return $chart; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /resources/views/chart_refresh.blade.php: -------------------------------------------------------------------------------- 1 | @php /** @var \Fidum\ChartTile\Charts\Chart $chart */ @endphp 2 | 3 | 4 | 5 | @push('scripts') 6 | 17 | @endpush 18 | -------------------------------------------------------------------------------- /resources/views/tile.blade.php: -------------------------------------------------------------------------------- 1 | @php /** @var \Fidum\ChartTile\Charts\Chart $chart */ @endphp 2 | 3 | 4 |
5 | {!! $chart->container() !!} 6 |
7 | @livewire('chart-refresh-tile', compact('chartFactory', 'chartFilters', 'height','refreshIntervalInSeconds', 'wireId')) 8 |
9 | 10 | @push('scripts') 11 | {!! str_replace( 12 | '', 13 | '', 14 | str_replace('', '', $chart->script()), 15 | ) !!} 16 | @endpush 17 | -------------------------------------------------------------------------------- /src/ChartTileServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 22 | __DIR__.'/../resources/views' => resource_path('views/vendor/dashboard-chart-tiles'), 23 | ], 'dashboard-chart-tiles'); 24 | 25 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'dashboard-chart-tiles'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Charts/Chart.php: -------------------------------------------------------------------------------- 1 | height = $height; 13 | 14 | return $this; 15 | } 16 | 17 | public function id(string $id): self 18 | { 19 | $this->id = 'chart_'.$id; 20 | 21 | return $this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Components/ChartComponent.php: -------------------------------------------------------------------------------- 1 | height = $height; 35 | $this->position = $position; 36 | $this->chartFactory = $chartFactory ?? DefaultChartFactory::class; 37 | $this->chartFilters = $chartFilters; 38 | $this->wireId = $wireId ?? $this->getId(); 39 | $this->eventName = 'chartDataRefreshed'.$this->wireId; 40 | 41 | $this->refreshIntervalInSeconds = $refreshIntervalInSeconds 42 | ?? config('dashboard.tiles.charts.refresh_interval_in_seconds', 300); 43 | } 44 | 45 | public function render() 46 | { 47 | return view('dashboard-chart-tiles::tile', $this->viewData()); 48 | } 49 | 50 | protected function chart(): Chart 51 | { 52 | /** @var ChartTileContract $factory */ 53 | $factory = $this->chartFactory; 54 | 55 | return $factory::make($this->chartFilters) 56 | ->chart() 57 | ->height($this->height) 58 | ->id($this->wireId); 59 | } 60 | 61 | protected function viewData(): array 62 | { 63 | return [ 64 | 'wireId' => $this->wireId, 65 | 'chart' => $this->chart(), 66 | 'chartFactory' => $this->chartFactory, 67 | 'eventName' => $this->eventName, 68 | ]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Components/ChartRefreshComponent.php: -------------------------------------------------------------------------------- 1 | viewData()); 12 | } 13 | 14 | protected function chart(): Chart 15 | { 16 | $chart = parent::chart(); 17 | 18 | $this->dispatch($this->eventName, [ 19 | 'labels' => $chart->labels, 20 | 'datasets' => $chart->formatDatasets(), 21 | 'options' => $chart->options, 22 | ]); 23 | 24 | return $chart; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Contracts/ChartFactory.php: -------------------------------------------------------------------------------- 1 |