|
| 1 | +# Nova Threemap Chart Card |
| 2 | + |
| 3 | + |
| 4 | +This package allows you to add three-map fields to your resource details page and dashboards in [Nova](https://nova.laravel.com). |
| 5 | + |
| 6 | +It basically takes a field with a decimal value between 0 and 1 and shows it as a percentage progress bar. |
| 7 | + |
| 8 | +To edit a field, we recommend using the standard Number (\Laravel\Nova\Fields\Number) field. |
| 9 | + |
| 10 | +<img src="https://github.com/flatroy/nova-progressbar-field/blob/main/img/img.png" alt="example"> |
| 11 | + |
| 12 | +#### DISCLAIMER: |
| 13 | + |
| 14 | +This package is still work in progress. Feel free to help improve it. |
| 15 | + |
| 16 | +- [Requirements](#requirements) |
| 17 | +- [Installation](#installation) |
| 18 | +- [Basic Usage](#basic-usage) |
| 19 | +- [Advanced Options](#advanced-options) |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Requirements |
| 24 | + |
| 25 | +- [Laravel v9.0.\*](https://laravel.com/docs/9.0) |
| 26 | +- [Laravel Nova v4.\*](https://nova.laravel.com/docs/4.0/) |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +Just run: |
| 33 | + |
| 34 | +```bash |
| 35 | +composer require flatroy/nova-treemap-chart-card |
| 36 | +``` |
| 37 | + |
| 38 | +After this the setup will be complete, you can use the components listed here. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Basic Usage |
| 43 | + |
| 44 | +```php |
| 45 | +// in App\Nova\User |
| 46 | +... |
| 47 | +use Flatroy\FieldProgressbar\FieldProgressbar; |
| 48 | +use Laravel\Nova\Fields\Number; |
| 49 | +... |
| 50 | + |
| 51 | +/** |
| 52 | + * Get the fields displayed by the resource. |
| 53 | + * |
| 54 | + * @param \Laravel\Nova\Http\Requests\NovaRequest $request |
| 55 | + * @return array |
| 56 | + */ |
| 57 | +public function fields(NovaRequest $request) |
| 58 | +{ |
| 59 | + $data = [ |
| 60 | + ['x' => 'Design', 'y' => 0.051], |
| 61 | + ['x' => 'Accounting', 'y' => 0.050], |
| 62 | + ['x' => 'Data Science', 'y' => 0.048], |
| 63 | + ['x' => 'Marketing', 'y' => 0.046], |
| 64 | + ['x' => 'Quality Assurance', 'y' => 0.046], |
| 65 | + ['x' => 'R&D', 'y' => 0.046], |
| 66 | + ]; |
| 67 | + |
| 68 | + return [ |
| 69 | + ... |
| 70 | + (new NovaTreemapChartCard()) |
| 71 | + ->title('Some custom title') |
| 72 | + ->series($data) |
| 73 | + ->onlyOnDetail(), |
| 74 | + // or you can use like that: |
| 75 | + (new NovaTreemapChartCard()) |
| 76 | + ->title('Some other custom title') |
| 77 | + ->series($this->model()?->find($request->resourceId)?->chartData) |
| 78 | + ->onlyOnDetail(), |
| 79 | + // or you can suggest how to do it better? |
| 80 | + ... |
| 81 | + ]; |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +// if you want to put logic inside model - add this inside model: |
| 86 | + |
| 87 | +namespace App\Models; |
| 88 | +... |
| 89 | +class User extends Model |
| 90 | +{ |
| 91 | +... |
| 92 | + protected function getChartDataAttribute() |
| 93 | + { |
| 94 | + return [ |
| 95 | + ['x' => 'Design', 'y' => 0.051], |
| 96 | + ['x' => 'Accounting', 'y' => 0.050], |
| 97 | + ['x' => 'Data Science', 'y' => 0.048], |
| 98 | + ['x' => 'Marketing', 'y' => 0.046], |
| 99 | + ['x' => 'Quality Assurance', 'y' => 0.046], |
| 100 | + ['x' => 'R&D', 'y' => 0.046], |
| 101 | + ]; |
| 102 | + } |
| 103 | +... |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +Feel free to come with suggestions for improvements. |
0 commit comments