Compare commits
128 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35324eace3 | ||
|
|
c30c408fe2 | ||
|
|
b182546766 | ||
|
|
3014bb1ab3 | ||
|
|
343ebbaeee | ||
|
|
79f61f15f6 | ||
|
|
af540f428c | ||
|
|
e2f9c814e2 | ||
|
|
b04c338283 | ||
|
|
98ffca8cf3 | ||
|
|
d31ed188a9 | ||
|
|
08d60e1ffa | ||
|
|
fc0c122926 | ||
|
|
d58465084e | ||
|
|
5a222abdbf | ||
|
|
af44417115 | ||
|
|
4c70acd41c | ||
|
|
ca044277ee | ||
|
|
badbd7d872 | ||
|
|
802416ee7a | ||
|
|
d957e698bb | ||
|
|
46d82cf6bc | ||
|
|
1f26a9ed39 | ||
|
|
55d76bcecd | ||
|
|
5034771e57 | ||
|
|
6b2667f590 | ||
|
|
c5784b0ced | ||
|
|
2d9bcfe480 | ||
|
|
aa822000af | ||
|
|
682b282fe8 | ||
|
|
de936c77d6 | ||
|
|
17efda3ed0 | ||
|
|
25b13b3573 | ||
|
|
30eae50c04 | ||
|
|
c79dfeb0ab | ||
|
|
3dcc97bef3 | ||
|
|
c408b639e9 | ||
|
|
ac1e6130d4 | ||
|
|
756781c3a9 | ||
|
|
93dbaffc61 | ||
|
|
6926a504b1 | ||
|
|
40828df23e | ||
|
|
9f9554314e | ||
|
|
c7997758bd | ||
|
|
5bc85376a3 | ||
|
|
e6c34e2d49 | ||
|
|
66ce742311 | ||
|
|
cd56963f6e | ||
|
|
ce43d0b97c | ||
|
|
d1ce67f9e5 | ||
|
|
1e04ebf6d9 | ||
|
|
072a98da5c | ||
|
|
27198d12b8 | ||
|
|
8bfdaa1763 | ||
|
|
aa94016b6e | ||
|
|
4a74606e4d | ||
|
|
52abe77e7e | ||
|
|
202591954d | ||
|
|
9e4d8ddf40 | ||
|
|
3e57a722b4 | ||
|
|
0c72c83dda | ||
|
|
327665919f | ||
|
|
879734fe9c | ||
|
|
6754e94cde | ||
|
|
9802ec2bcd | ||
|
|
821ac7a454 | ||
|
|
a7364ad51c | ||
|
|
47d0f028af | ||
|
|
9ad481000c | ||
|
|
fe0c62be75 | ||
|
|
582ad340dd | ||
|
|
35d8a80bb4 | ||
|
|
665a3370b2 | ||
|
|
84527ff809 | ||
|
|
cefb5089e8 | ||
|
|
bf644a5931 | ||
|
|
3abe96bdb0 | ||
|
|
171a333044 | ||
|
|
372d6ffcb0 | ||
|
|
0de38b041b | ||
|
|
b649aaef23 | ||
|
|
75f46fc1cf | ||
|
|
11272bd21b | ||
|
|
1e1075ba07 | ||
|
|
1bfa52ca83 | ||
|
|
3add4a148e | ||
|
|
27606ff1e9 | ||
|
|
230b706c63 | ||
|
|
8b0bb9c250 | ||
|
|
3d89d210b5 | ||
|
|
f72c5294d9 | ||
|
|
76b64536d1 | ||
|
|
fd4961d7ae | ||
|
|
c61ca90905 | ||
|
|
67bd18bc48 | ||
|
|
940109ef03 | ||
|
|
0457a9a007 | ||
|
|
2c7317c3b8 | ||
|
|
98df89eca4 | ||
|
|
de8ed5c844 | ||
|
|
81b502fd10 | ||
|
|
01176c001e | ||
|
|
8e9aed484e | ||
|
|
f5b40ec73d | ||
|
|
dbbbf8eca2 | ||
|
|
a002d2f041 | ||
|
|
e11c5ca375 | ||
|
|
0af61a2997 | ||
|
|
cb3e4180a1 | ||
|
|
1e7ac1bffb | ||
|
|
0aedf541a9 | ||
|
|
316bb5a976 | ||
|
|
05c9f5c605 | ||
|
|
63fe7a1533 | ||
|
|
22b72c1980 | ||
|
|
5e7cabfd16 | ||
|
|
71e2168b6c | ||
|
|
9b74d45a86 | ||
|
|
19f3ce70ae | ||
|
|
4c55e19486 | ||
|
|
1b7f928f94 | ||
|
|
28fa9421ad | ||
|
|
09f8b354f7 | ||
|
|
8586357077 | ||
|
|
9df03c36a8 | ||
|
|
8126b95593 | ||
|
|
472dfd8a4a | ||
|
|
865c1fe13f |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* @asantibanez
|
||||||
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. '...'
|
||||||
|
2. '...'
|
||||||
|
3. '...'
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
**Solution Ideas**
|
||||||
|
Initial thoughts or details about how this could be fixed
|
||||||
14
.github/ISSUE_TEMPLATE/feature.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE/feature.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
name: Feature
|
||||||
|
about: New feature idea
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Summary
|
||||||
|
What's the new feature about? What should it do?
|
||||||
|
|
||||||
|
### Proposal
|
||||||
|
How should it work? API ideas?
|
||||||
|
|
||||||
|
### Additional Notes
|
||||||
|
Reference links or comments
|
||||||
18
.github/PULL_REQUEST_TEMPLATE
vendored
Normal file
18
.github/PULL_REQUEST_TEMPLATE
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
## Summary
|
||||||
|
|
||||||
|
[Provide a summary of the change.]
|
||||||
|
|
||||||
|
## Issue
|
||||||
|
|
||||||
|
[If exists, provide a link to the corresponding issue(s).]
|
||||||
|
|
||||||
|
## Type of Change
|
||||||
|
|
||||||
|
- [ ] :rocket: New Feature
|
||||||
|
- [ ] :bug: Bug Fix
|
||||||
|
- [ ] :hammer: Refactor
|
||||||
|
- [ ] :question: [Other]
|
||||||
|
|
||||||
|
## Screenshot/Video
|
||||||
|
|
||||||
|
[Provide a screenshot or video that describes the change if applicable]
|
||||||
29
.github/workflows/phpunit.yml
vendored
Normal file
29
.github/workflows/phpunit.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: PHPUnit
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
phpunit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Cancel Previous Run
|
||||||
|
uses: styfle/cancel-workflow-action@0.6.0
|
||||||
|
with:
|
||||||
|
access_token: ${{ github.token }}
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, exif, imagick, bcmath
|
||||||
|
coverage: xdebug
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install Composer dependencies
|
||||||
|
run: composer install
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,3 +4,6 @@ composer.lock
|
|||||||
docs
|
docs
|
||||||
vendor
|
vendor
|
||||||
coverage
|
coverage
|
||||||
|
.DS_STORE
|
||||||
|
node_modules
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
1
.phpunit.cache/test-results
Normal file
1
.phpunit.cache/test-results
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":1,"defects":{"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::can_build_component":7},"times":{"Asantibanez\\LivewireCharts\\Tests\\LivewireAreaChartTest::can_build_component":0.026,"Asantibanez\\LivewireCharts\\Tests\\LivewireColumnChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewireColumnChartTest::should_emit_event_if_present":0.01,"Asantibanez\\LivewireCharts\\Tests\\LivewireLineChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::can_build_component":0.025,"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::should_emit_event_if_present":0.011,"Asantibanez\\LivewireCharts\\Tests\\LivewireRadarChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewireTreeMapChartTest::can_build_component":0.004,"Asantibanez\\LivewireCharts\\Tests\\LivewireTreeMapChartTest::should_emit_event_if_present":0.008}}
|
||||||
79
CHANGELOG.md
79
CHANGELOG.md
@@ -1,5 +1,84 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 4.1.0 - 2024-08-22
|
||||||
|
- Added Radial chart
|
||||||
|
|
||||||
|
## 4.0.0 - 2024-08-22
|
||||||
|
- Added Laravel 11 support
|
||||||
|
|
||||||
|
## 3.1.0 - 2023-11-07
|
||||||
|
- Added missing jsonConfig (thanks to @stijnvanouplines)
|
||||||
|
- Changed 'emit' functions in Area,Line, and Radar chart to 'dispatch' (thanks to @redsquirrelstudio)
|
||||||
|
|
||||||
|
## 3.0.0 - 2023-07-25
|
||||||
|
- Added Livewire v3 support
|
||||||
|
- Added ability to set chart theme (thanks to @syntaxlexx)
|
||||||
|
- Added ability to configure chart via JSON properties
|
||||||
|
|
||||||
|
## 2.5.0 - 2023-02-01
|
||||||
|
- Added tooltip override via `extras.tooltip`
|
||||||
|
|
||||||
|
## 2.4.2 - 2023-02-01
|
||||||
|
- Fixed hover title on column chart
|
||||||
|
|
||||||
|
## 2.4.1 - 2022-02-18
|
||||||
|
- Fixed xAxis auto-categories for MultiColumnChart
|
||||||
|
|
||||||
|
## 2.4.0 - 2022-02-14
|
||||||
|
- Added Radar Chart (thanks to @AlexHupe)
|
||||||
|
- Added Tree Map Chart
|
||||||
|
- Added "donut" type to Pie Chart (thanks to @nicko170)
|
||||||
|
|
||||||
|
## 2.3.0 - 2021-02-12
|
||||||
|
- Added `init()` method for better boot and $wire hoisting
|
||||||
|
- Added color customization for columns, multiline and pie chart
|
||||||
|
|
||||||
|
## 2.2.0 - 2020-12-16
|
||||||
|
- Added support for PHP 8
|
||||||
|
- Updated docs
|
||||||
|
- Added base tests for components and CI
|
||||||
|
|
||||||
|
## 2.1.0 - 2020-11-30
|
||||||
|
- Added stroke width customization
|
||||||
|
- Added stroke support for Area Chart
|
||||||
|
|
||||||
|
## 2.0.0 - 2020-11-30
|
||||||
|
- Added build system for JS charts code
|
||||||
|
- Added Blade directive to include assets
|
||||||
|
- Updated installation and advanced usage instructions
|
||||||
|
|
||||||
|
## 1.5.2 - 2020-11-09
|
||||||
|
|
||||||
|
- Fixed infinite growing charts
|
||||||
|
|
||||||
|
## 1.5.1 - 2020-11-09
|
||||||
|
|
||||||
|
- Removed unused Alpine directives
|
||||||
|
|
||||||
|
## 1.5.0 - 2020-11-09
|
||||||
|
|
||||||
|
- Added `LivewireCharts` facade to create any chart model
|
||||||
|
- Added `sparklined` Apex Chart feature to all charts (https://apexcharts.com/javascript-chart-demos/sparklines/basic/)
|
||||||
|
|
||||||
|
## 1.4.0 - 2020-11-07
|
||||||
|
|
||||||
|
- Added Multi Column Chart
|
||||||
|
- Added Stacked Multi Column Chart
|
||||||
|
- Added support for custom X Axis categories
|
||||||
|
|
||||||
|
## 1.3.0 - 2020-11-03
|
||||||
|
|
||||||
|
- Added Multi Line Chart
|
||||||
|
- Added Data Labels configuration for all charts
|
||||||
|
- Refactored title and animation to traits
|
||||||
|
|
||||||
|
## 1.2.0 - 2020-10-25
|
||||||
|
|
||||||
|
- Fixed column chart growing infinitely
|
||||||
|
- Improved customization API
|
||||||
|
- Added Legend configuration
|
||||||
|
- Refactored configuration traits
|
||||||
|
|
||||||
## 1.1.0 - 2020-10-20
|
## 1.1.0 - 2020-10-20
|
||||||
|
|
||||||
- Added Area Chart
|
- Added Area Chart
|
||||||
|
|||||||
214
README.md
214
README.md
@@ -1,10 +1,15 @@
|
|||||||
# Livewire Charts
|
[](https://github.com/asantibanez/livewire-charts/releases/)
|
||||||
|
|
||||||
Neat Livewire Charts for your Laravel projects.
|

|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
|
|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
https://github.com/asantibanez/livewire-charts-demo
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -14,30 +19,44 @@ You can install the package via composer:
|
|||||||
composer require asantibanez/livewire-charts
|
composer require asantibanez/livewire-charts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Next, you must export the package public scripts. To do this run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan livewire-charts:install
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will export a `vendor/livewire-charts` folder under the `public` directory of your app which is used
|
||||||
|
by the `@livewireChartsScripts` directive. More on this topic later.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
This package requires the following packages/libraries to work:
|
This package requires the following packages/libraries to work:
|
||||||
- `Laravel Livewire v2` (https://laravel-livewire.com/)
|
- `Laravel Livewire v3` (https://livewire.laravel.com/)
|
||||||
- `Alpine Js` (https://github.com/alpinejs/alpine)
|
|
||||||
- `Apex Charts` (https://apexcharts.com/)
|
- `Apex Charts` (https://apexcharts.com/)
|
||||||
|
|
||||||
Please follow each package/library instructions on how to set them properly in your project.
|
Please follow each package/library instructions on how to set them properly in your project.
|
||||||
|
|
||||||
> Note: At the moment, `Apex Charts` is only supported for drawing charts.
|
>Note: At the moment, `Apex Charts` is only supported for drawing charts.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Livewire Charts supports out of the box the following types of charts
|
Livewire Charts supports out of the box the following types of charts
|
||||||
- Line Chart (`LivewireLineChart` component)
|
- Line/Multi Line Chart (`LivewireLineChart` component)
|
||||||
- Pie Chart (`LivewirePieChart` component)
|
- Pie Chart (`LivewirePieChart` component)
|
||||||
- Column Chart (`LivewireColumnChart` component)
|
- Column/Multi Line Chart (`LivewireColumnChart` component)
|
||||||
- Area Chart (`LivewireAreaChart` component)
|
- Area Chart (`LivewireAreaChart` component)
|
||||||
|
- Radar Chart (`LivewireRadarChart` component)
|
||||||
|
- Tree Map Chart (`LivewireTreeMapChart` component)
|
||||||
|
- Radial Chart (`LivewireRadialChart` component)
|
||||||
|
|
||||||
Each one comes with its own "model" class that allows you to define the chart's data and render behavior.
|
Each one comes with its own "model" class that allows you to define the chart's data and render behavior.
|
||||||
- `LivewireLineChart` uses `LineChartModel` to set up data points, markers, events and other ui customizations.
|
- `LivewireLineChart` uses `LineChartModel` to set up data points, markers, events and other ui customizations.
|
||||||
- `LivewirePieChart` uses `PieChartModel` to set up data slices, events and other ui customizations.
|
- `LivewirePieChart` uses `PieChartModel` to set up data slices, events and other ui customizations.
|
||||||
- `LivewireColumnChart` uses `ColumnChartModel` to set up data columns, events and other ui customizations.
|
- `LivewireColumnChart` uses `ColumnChartModel` to set up data columns, events and other ui customizations.
|
||||||
- `LivewireAreaChart` uses `AreaChartModel` to set up data points, events and other ui customizations.
|
- `LivewireAreaChart` uses `AreaChartModel` to set up data points, events and other ui customizations.
|
||||||
|
- `LivewireRadarChart` uses `RadarChartModel` to set up data points, events and other ui customizations.
|
||||||
|
- `LivewireTreeMapChart` uses `TreeMapChartModel` to set up data blocks, events and other ui customizations.
|
||||||
|
- `LivewireRadialChart` uses `RadialChartModel` to set up data bars, events and other ui customizations.
|
||||||
|
|
||||||
For example, to render a column chart, we can create an instance of `ColumnChartModel` and add some data to it
|
For example, to render a column chart, we can create an instance of `ColumnChartModel` and add some data to it
|
||||||
```php
|
```php
|
||||||
@@ -50,22 +69,47 @@ $columnChartModel =
|
|||||||
;
|
;
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: Chart model methods are chainable 💪
|
>Note: Chart model methods are chainable 💪
|
||||||
|
|
||||||
With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` component in our Blade template.
|
With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` component in our Blade template.
|
||||||
|
|
||||||
```blade
|
```blade
|
||||||
<livewire:livewire-column-chart
|
<livewire:livewire-column-chart
|
||||||
|
{{-- key="{{ $columnChartModel->reactiveKey() }}" --}}
|
||||||
:column-chart-model="$columnChartModel"
|
:column-chart-model="$columnChartModel"
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
>Note: Optionally add "key" to enable props reactivity if needed 💪
|
||||||
|
|
||||||
|
Next, include the `@livewireChartsScripts` directive next to your other app scripts
|
||||||
|
|
||||||
|
```html
|
||||||
|
@livewireScripts
|
||||||
|
@livewireChartsScripts
|
||||||
|
```
|
||||||
|
|
||||||
And that's it! You have a beautiful rendered chart in seconds. 👌
|
And that's it! You have a beautiful rendered chart in seconds. 👌
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
> Note: You can use these charts inside other Livewire components too. Just render them in your Blade template and you
|
>Note: You can use these charts inside other Livewire components too. Just render them in your Blade template and you
|
||||||
are good to go. 👍
|
are good to go. 👍
|
||||||
|
|
||||||
|
## LivewireCharts facade
|
||||||
|
|
||||||
|
Chart models can also be created using the `LivewireCharts` facade.
|
||||||
|
|
||||||
|
```php
|
||||||
|
LivewireCharts::lineChartModel();
|
||||||
|
LivewireCharts::multiLineChartModel();
|
||||||
|
LivewireCharts::columnChartModel();
|
||||||
|
LivewireCharts::multiColumnChartModel();
|
||||||
|
LivewireCharts::pieChartModel();
|
||||||
|
LivewireCharts::areaChartModel();
|
||||||
|
LivewireCharts::radarChartModel();
|
||||||
|
LivewireCharts::treeMapChartModel();
|
||||||
|
LivewireCharts::radialChartModel();
|
||||||
|
```
|
||||||
|
|
||||||
## Enabling Interactions
|
## Enabling Interactions
|
||||||
|
|
||||||
@@ -85,10 +129,12 @@ $columnChartModel =
|
|||||||
We can listen to the `onClickEvent` registering a listener in any other Livewire component.
|
We can listen to the `onClickEvent` registering a listener in any other Livewire component.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
protected $listeners = [
|
#[On('onColumnClick')]
|
||||||
'onColumnClick' => 'handleOnColumnClick',
|
public function handleOnColumnClick($event)
|
||||||
];
|
{
|
||||||
```
|
// Handle event
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## "Reactive" Charts
|
## "Reactive" Charts
|
||||||
|
|
||||||
@@ -125,47 +171,141 @@ The parent component renders the charts as follows
|
|||||||
For each chart, a specific model class needs to be used. Here, it is detailed the api available
|
For each chart, a specific model class needs to be used. Here, it is detailed the api available
|
||||||
for each type of chart.
|
for each type of chart.
|
||||||
|
|
||||||
#### LivewireLineChart
|
### All
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| setTitle(string $title) | Sets chart title |
|
||||||
|
| setAnimated(boolean $animated) | Enables/disables animation |
|
||||||
|
| setDataLabelsEnabled(boolean $enabled) | Enables/disables data labels |
|
||||||
|
| withDataLabels() | Enables data labels |
|
||||||
|
| withoutDataLabels() | Disables data labels |
|
||||||
|
| withLegend() | Shows legends |
|
||||||
|
| withoutLegend() | Hides legends |
|
||||||
|
| setColors(array $colors) | Set colors for chart |
|
||||||
|
| addColors(string $color) | Append $color to $colors set |
|
||||||
|
| setXAxisCategories(array $categories) | Enables custom categories for chart X Axis |
|
||||||
|
| sparklined() | Enables Apex Charts sparkline feature |
|
||||||
|
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
||||||
|
| setJsonConfig(array $config) | Adds extra customization to charts by passing Apex charts properties keys and values. Nested keys must be added using dot (.) notation |
|
||||||
|
|
||||||
|
### LivewireLineChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
| multiLine() | Adds multiline support for line chart |
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
| singleLine() | Adds single support for line chart |
|
||||||
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the line chart. `$extras` is forwarded on click event |
|
| addPoint(string $title, double $value, array $extras = []) | Adds a point to a single line chart. `$extras` is forwarded on click event |
|
||||||
| addMarker(string $title, double $value) | Adds a marker point to the line chart. Markers are used to emphasize particular points in the chart |
|
| addSeriesPoint(string $seriesName, string $title, double $value, array $extras = []) | Adds a point to series to a multi line chart. `$extras` is forwarded on click event |
|
||||||
|
| addMarker(string $title, double $value) | Adds a marker point to the line chart. Markers are used to emphasize particular points in the chart (singleLine only) |
|
||||||
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point/marker of the chart is clicked |
|
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point/marker of the chart is clicked |
|
||||||
|
|
||||||
#### LivewireColumnChart
|
### LivewireColumnChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
| setOpacity(int $opacity) | Sets columns' opacity |
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
| setColumnWidth(int $columnWidth) | Sets columns' width |
|
||||||
| setOpacity(int $opacity) | Sets columns' opacity |
|
| setHorizontal() | Displays columns horizontally |
|
||||||
| addColumn(string $title, double $value, string $color, array $extras = []) | Adds a column to the chart with the specified color. `$extras` is forwarded on click event |
|
| setVertical() | Displays columns vertically |
|
||||||
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
| multiColumn() | Sets chart to display multiple column series |
|
||||||
|
| singleColumn() | Sets chart to display a single column series |
|
||||||
|
| stacked() | Sets chart to display column series stacked |
|
||||||
|
| addColumn(string $title, double $value, string $color, array $extras = []) | Adds a column to the chart with the specified color. `$extras` is forwarded on click event |
|
||||||
|
| addSeriesColumn(string $seriesName, string $title, double $value, array $extras = []) | Adds a column to a multicolumn chart. `$extras` is forwarded on click event |
|
||||||
|
| withOnColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||||
|
|
||||||
#### LivewirePieChart
|
### LivewirePieChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
| setOpacity(int $opacity) | Sets slices' opacity |
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
| asPie() | Displays chart as pie |
|
||||||
| setOpacity(int $opacity) | Sets slices' opacity |
|
| asDonut() | Displays chart as donut |
|
||||||
| addSlice(string $title, double $value, string $color, array $extras = []) | Adds a slice to the chart with the specified color. `$extras` is forwarded on click event |
|
| addSlice(string $title, double $value, string $color, array $extras = []) | Adds a slice to the chart with the specified color. `$extras` is forwarded on click event |
|
||||||
| withOnSliceClickEvent(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
| withOnSliceClickEvent(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||||
|
|
||||||
#### LivewireAreaChart
|
### LivewireAreaChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setTitle(string $title) | Sets chart title |
|
|
||||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
|
||||||
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the area chart. `$extras` is forwarded on click event |
|
| addPoint(string $title, double $value, array $extras = []) | Adds a point to the area chart. `$extras` is forwarded on click event |
|
||||||
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point of the chart is clicked |
|
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point of the chart is clicked |
|
||||||
| setXAxisVisible(boolean $visible) | Shows/hides xAxis labels |
|
| setXAxisVisible(boolean $visible) | Shows/hides xAxis labels |
|
||||||
| setYAxisVisible(boolean $visible) | Shows/hides yAxis labels |
|
| setYAxisVisible(boolean $visible) | Shows/hides yAxis labels |
|
||||||
|
|
||||||
|
### LivewireRadarChart
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| addSeries(string $seriesName, string $title, double $value, array $extras = []) | |
|
||||||
|
| withOnPointClickEvent(string $eventName) | Event Name that will be fired when a point of the chart is clicked |
|
||||||
|
|
||||||
|
### LivewireTreeMapChart
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| addBlock(string $title, double $value, array $extras = []) | Adds a block to the default series|
|
||||||
|
| addSeriesBlock(string $seriesName, string $title, double $value, array $extras = []) | Adds a block to the specified series|
|
||||||
|
| withOnBlockClickEvent(string $eventName) | Event Name that will be fired when a block of the chart is clicked |
|
||||||
|
| setDistributed(bool $distributed) | Set whether the chart uses distribution or not |
|
||||||
|
|
||||||
|
### LivewireRadialChart
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------------------------------------------------------------------------------|------------------------------------------------------------------|
|
||||||
|
| addBar(string $title, double $value, string $color = null, array $extras = []) | Adds a bar to the default series |
|
||||||
|
| withOnBarClickEvent(string $eventName) | Event Name that will be fired when a bar of the chart is clicked |
|
||||||
|
| showTotal() | Show the total percetage to the graph |
|
||||||
|
| hideTotal() | Hides the total percetage to the graph |
|
||||||
|
|
||||||
|
## Advanced Usage - Integrating Scripts
|
||||||
|
|
||||||
|
The directive `@livewireChartsScripts` adds a `script` tag that includes `public/vendor/livewire-charts/app.js`.
|
||||||
|
If you want to include this script in your build system, you can export the package scripts
|
||||||
|
with `php artisan vendor:publish` and selecting `livewire-charts:scripts`. This will export `js/vendor/livewire-charts`
|
||||||
|
inside your resources folder. You can then adjust imports as you see fit in your project.
|
||||||
|
|
||||||
|
>Note: You must remove @livewireChartsScripts directive so it doesn't clash with the scripts in your build system.
|
||||||
|
|
||||||
|
|
||||||
|
## Advanced Usage - Custom Json Configs
|
||||||
|
|
||||||
|
The `setJsonConfig()` method on every chart allows adding custom Apex properties not provided first hand by the package.
|
||||||
|
This means that any chart property supported by Apex chart can be passed down using this method.
|
||||||
|
|
||||||
|
```php
|
||||||
|
$chart->setJsonConfig([
|
||||||
|
'plotOptions.pie.startAngle' => -90,
|
||||||
|
'plotOptions.pie.endAngle' => 90,
|
||||||
|
'plotOptions.pie.offsetY' => 10,
|
||||||
|
'grid.padding.bottom' => -180,
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
>Note: If you want to add nested properties, you can use dot (.) notation for this matter.
|
||||||
|
|
||||||
|
You can even pass down simple JS functions. For example, for formatting you can pass down your own closure
|
||||||
|
|
||||||
|
```php
|
||||||
|
$chart->setJsonConfig([
|
||||||
|
'tooltip.y.formatter' => '(val) => `$${val} million dollars baby!`'
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
Chart components must be placed inside a container with fixed height. This is because the chart will use all the given
|
||||||
|
vertical space. A fixed height is needed to render properly.
|
||||||
|
|
||||||
|
```blade
|
||||||
|
<div style="height: 32rem;">
|
||||||
|
<livewire:livewire-column-chart .../>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
>Note: if a fixed height is not given, the chart will grow vertically infinitely. That's not what we want, right?
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2|^7.3|^7.4",
|
"php": "^7.2|^7.3|^7.4|^8.0",
|
||||||
"illuminate/support": "^7.0|^8.0",
|
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0",
|
||||||
"livewire/livewire": "^2.3"
|
"livewire/livewire": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"orchestra/testbench": "^4.0|^5.0",
|
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
"phpunit/phpunit": "^8.0"
|
"phpunit/phpunit": "^8.0|^9.5.10|^10.5"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -37,7 +37,6 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vendor/bin/phpunit",
|
"test": "vendor/bin/phpunit",
|
||||||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
|
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
|
||||||
|
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"sort-packages": true
|
"sort-packages": true
|
||||||
@@ -51,5 +50,7 @@
|
|||||||
"LivewireCharts": "Asantibanez\\LivewireCharts\\LivewireChartsFacade"
|
"LivewireCharts": "Asantibanez\\LivewireCharts\\LivewireChartsFacade"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
|||||||
3
mix-manifest.json
Normal file
3
mix-manifest.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"/public/app.js": "/public/app.js"
|
||||||
|
}
|
||||||
24163
package-lock.json
generated
Normal file
24163
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
package.json
Normal file
19
package.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"dev": "npm run development",
|
||||||
|
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||||
|
"watch": "npm run development -- --watch",
|
||||||
|
"watch-poll": "npm run watch -- --watch-poll",
|
||||||
|
"prod": "npm run production",
|
||||||
|
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"apexcharts": "^3.22.2",
|
||||||
|
"cross-env": "^7.0.2",
|
||||||
|
"laravel-mix": "^5.0.9",
|
||||||
|
"vue-template-compiler": "^2.6.12"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"deepmerge": "^2.2.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,33 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit bootstrap="vendor/autoload.php"
|
<phpunit
|
||||||
backupGlobals="false"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
backupStaticAttributes="false"
|
bootstrap="vendor/autoload.php"
|
||||||
colors="true"
|
backupGlobals="false"
|
||||||
verbose="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
processIsolation="false"
|
||||||
convertNoticesToExceptions="true"
|
stopOnFailure="false"
|
||||||
convertWarningsToExceptions="true"
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
|
||||||
processIsolation="false"
|
cacheDirectory=".phpunit.cache"
|
||||||
stopOnFailure="false">
|
backupStaticProperties="false"
|
||||||
|
>
|
||||||
|
<coverage>
|
||||||
|
<report>
|
||||||
|
<clover outputFile="build/logs/clover.xml"/>
|
||||||
|
<html outputDirectory="build/coverage"/>
|
||||||
|
<text outputFile="build/coverage.txt"/>
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Test Suite">
|
<testsuite name="Test Suite">
|
||||||
<directory>tests</directory>
|
<directory>tests</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory suffix=".php">src/</directory>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
<logging>
|
<logging>
|
||||||
<log type="tap" target="build/report.tap"/>
|
<junit outputFile="build/report.junit.xml"/>
|
||||||
<log type="junit" target="build/report.junit.xml"/>
|
|
||||||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
|
|
||||||
<log type="coverage-text" target="build/coverage.txt"/>
|
|
||||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
|
||||||
</logging>
|
</logging>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">src/</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
BIN
preview_radarchart.gif
Normal file
BIN
preview_radarchart.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
2
public/app.js
Normal file
2
public/app.js
Normal file
File diff suppressed because one or more lines are too long
13
public/app.js.LICENSE.txt
Normal file
13
public/app.js.LICENSE.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/*!
|
||||||
|
* ApexCharts v3.41.0
|
||||||
|
* (c) 2018-2023 ApexCharts
|
||||||
|
* Released under the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! svg.draggable.js - v2.2.2 - 2019-01-08
|
||||||
|
* https://github.com/svgdotjs/svg.draggable.js
|
||||||
|
* Copyright (c) 2019 Wout Fierens; Licensed MIT */
|
||||||
|
|
||||||
|
/*! svg.filter.js - v2.0.2 - 2016-02-24
|
||||||
|
* https://github.com/wout/svg.filter.js
|
||||||
|
* Copyright (c) 2016 Wout Fierens; Licensed MIT */
|
||||||
21
resources/js/app.js
Normal file
21
resources/js/app.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import ApexCharts from 'apexcharts'
|
||||||
|
import areaChart from "./areaChart"
|
||||||
|
import columnChart from "./columnChart"
|
||||||
|
import multiColumnChart from "./multiColumnChart"
|
||||||
|
import lineChart from "./lineChart"
|
||||||
|
import multiLineChart from "./multiLineChart"
|
||||||
|
import pieChart from "./pieChart"
|
||||||
|
import radarChart from "./radarChart"
|
||||||
|
import treeMapChart from "./treeMapChart"
|
||||||
|
import radialChart from "./radialChart"
|
||||||
|
|
||||||
|
window.ApexCharts = ApexCharts
|
||||||
|
window.livewireChartsAreaChart = areaChart
|
||||||
|
window.livewireChartsColumnChart = columnChart
|
||||||
|
window.livewireChartsLineChart = lineChart
|
||||||
|
window.livewireChartsMultiLineChart = multiLineChart
|
||||||
|
window.livewireChartsPieChart = pieChart
|
||||||
|
window.livewireChartsMultiColumnChart = multiColumnChart
|
||||||
|
window.livewireChartsRadarChart = radarChart
|
||||||
|
window.livewireChartsTreeMapChart = treeMapChart
|
||||||
|
window.livewireChartsRadialChart = radialChart
|
||||||
99
resources/js/areaChart.js
Normal file
99
resources/js/areaChart.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const areaChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('areaChartModel.title');
|
||||||
|
const animated = component.get('areaChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('areaChartModel.dataLabels') || {};
|
||||||
|
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
||||||
|
const data = component.get('areaChartModel.data');
|
||||||
|
const sparkline = component.get('areaChartModel.sparkline');
|
||||||
|
const jsonConfig = component.get('areaChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const categories = component.get('areaChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('areaChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
series: [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value)
|
||||||
|
}],
|
||||||
|
chart: {
|
||||||
|
type: 'area',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
||||||
|
|
||||||
|
stroke: component.get('areaChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('areaChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('areaChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
grid: {
|
||||||
|
padding: {
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
theme: component.get('areaChartModel.theme') || {},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default areaChart
|
||||||
121
resources/js/columnChart.js
Normal file
121
resources/js/columnChart.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const columnChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('columnChartModel.title')
|
||||||
|
const animated = component.get('columnChartModel.animated') || false;
|
||||||
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
|
const dataLabels = component.get('columnChartModel.dataLabels') || {};
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
const legend = component.get('columnChartModel.legend')
|
||||||
|
const grid = component.get('columnChartModel.grid');
|
||||||
|
const columnWidth = component.get('columnChartModel.columnWidth');
|
||||||
|
const horizontal = component.get('columnChartModel.horizontal');
|
||||||
|
const jsonConfig = component.get('columnChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const data = component.get('columnChartModel.data');
|
||||||
|
const series = [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value)
|
||||||
|
}]
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'bar',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
if (!onColumnClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dataPointIndex } = config
|
||||||
|
const column = data[dataPointIndex]
|
||||||
|
component.call('onColumnClick', column)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
|
||||||
|
labels: {
|
||||||
|
style: {
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: legend,
|
||||||
|
|
||||||
|
grid: grid,
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: horizontal,
|
||||||
|
columnWidth: `${columnWidth}%`,
|
||||||
|
distributed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: data.map(item => item.title),
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: {
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('columnChartModel.opacity') || 0.5
|
||||||
|
},
|
||||||
|
|
||||||
|
theme: component.get('columnChartModel.theme') || {},
|
||||||
|
|
||||||
|
tooltip: {
|
||||||
|
y: {
|
||||||
|
formatter: function(value, series) {
|
||||||
|
return data[series.dataPointIndex].extras.tooltip || value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const colors = component.get('columnChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default columnChart
|
||||||
27
resources/js/helpers.js
Normal file
27
resources/js/helpers.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import deepmerge from 'deepmerge'
|
||||||
|
|
||||||
|
export const addPathToObjectWithValue = (obj, path, value) => {
|
||||||
|
const pList = path.split('.');
|
||||||
|
const key = pList.pop();
|
||||||
|
const pointer = pList.reduce((accumulator, currentValue) => {
|
||||||
|
if (accumulator[currentValue] === undefined) accumulator[currentValue] = {};
|
||||||
|
return accumulator[currentValue];
|
||||||
|
}, obj);
|
||||||
|
pointer[key] = value;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const mergedOptionsWithJsonConfig = (options, jsonConfig) => {
|
||||||
|
const customOptions = Object.keys(jsonConfig)
|
||||||
|
.reduce(function (obj, key) {
|
||||||
|
const value = jsonConfig[key]
|
||||||
|
|
||||||
|
if (typeof value === 'string' && value.includes('function')) {
|
||||||
|
return addPathToObjectWithValue(obj, key, eval('(' + value + ')'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return addPathToObjectWithValue(obj, key, eval(value))
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
return deepmerge(options, customOptions)
|
||||||
|
}
|
||||||
120
resources/js/lineChart.js
Normal file
120
resources/js/lineChart.js
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const lineChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('lineChartModel.title');
|
||||||
|
const animated = component.get('lineChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
|
const data = component.get('lineChartModel.data');
|
||||||
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
const jsonConfig = component.get('lineChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const series = [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value),
|
||||||
|
}]
|
||||||
|
|
||||||
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'line',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
stroke: component.get('lineChartModel.stroke') || {},
|
||||||
|
|
||||||
|
theme: component.get('lineChartModel.theme') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('lineChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
annotations: {
|
||||||
|
points: component.get('lineChartModel.markers').map(item => {
|
||||||
|
return {
|
||||||
|
x: item.title,
|
||||||
|
y: item.value,
|
||||||
|
marker: {
|
||||||
|
size: 6,
|
||||||
|
fillColor: '#fff',
|
||||||
|
strokeColor: item.strokeColor,
|
||||||
|
radius: 2,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
offsetY: 0,
|
||||||
|
style: {
|
||||||
|
color: item.textColor,
|
||||||
|
background: item.textBackgroundColor,
|
||||||
|
},
|
||||||
|
text: item.text || '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
tooltip: {
|
||||||
|
y: {
|
||||||
|
formatter: function(value, series) {
|
||||||
|
return data[series.dataPointIndex].extras.tooltip || value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default lineChart
|
||||||
111
resources/js/multiColumnChart.js
Normal file
111
resources/js/multiColumnChart.js
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const multiColumnChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('columnChartModel.title')
|
||||||
|
const stacked = component.get('columnChartModel.isStacked');
|
||||||
|
const animated = component.get('columnChartModel.animated');
|
||||||
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
|
const dataLabels = component.get('columnChartModel.dataLabels');
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
const legend = component.get('columnChartModel.legend')
|
||||||
|
const grid = component.get('columnChartModel.grid');
|
||||||
|
const columnWidth = component.get('columnChartModel.columnWidth');
|
||||||
|
const horizontal = component.get('columnChartModel.horizontal');
|
||||||
|
const jsonConfig = component.get('columnChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const data = component.get('columnChartModel.data');
|
||||||
|
const series = Object.keys(data)
|
||||||
|
.map(seriesName => ({
|
||||||
|
name: seriesName,
|
||||||
|
data: data[seriesName].map(item => item.value)
|
||||||
|
}))
|
||||||
|
|
||||||
|
const categories = component.get('columnChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('columnChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'bar',
|
||||||
|
height: '100%',
|
||||||
|
stacked: stacked,
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, {seriesIndex, dataPointIndex}) {
|
||||||
|
if (!onColumnClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const column = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
component.call('onColumnClick', column)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: legend,
|
||||||
|
|
||||||
|
grid: grid,
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: horizontal,
|
||||||
|
columnWidth: `${columnWidth}%`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: {
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('columnChartModel.opacity'),
|
||||||
|
},
|
||||||
|
|
||||||
|
theme: component.get('columnChartModel.theme') || {},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const colors = component.get('columnChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default multiColumnChart
|
||||||
95
resources/js/multiLineChart.js
Normal file
95
resources/js/multiLineChart.js
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const multiLineChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('lineChartModel.title');
|
||||||
|
const animated = component.get('lineChartModel.animated') || false;
|
||||||
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
|
const data = component.get('lineChartModel.data');
|
||||||
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
const jsonConfig = component.get('lineChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const series = Object.keys(data).map(key => {
|
||||||
|
return {
|
||||||
|
name: key,
|
||||||
|
data: data[key].map(item => item.value),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'line',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
zoom: { enabled: false },
|
||||||
|
|
||||||
|
toolbar: { show: false },
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
stroke: component.get('lineChartModel.stroke') || {},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center'
|
||||||
|
},
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: component.get('lineChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
theme: component.get('lineChartModel.theme') || {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const colors = component.get('lineChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default multiLineChart
|
||||||
102
resources/js/pieChart.js
Normal file
102
resources/js/pieChart.js
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import {mergedOptionsWithJsonConfig} from './helpers'
|
||||||
|
|
||||||
|
const pieChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('pieChartModel.title');
|
||||||
|
const animated = component.get('pieChartModel.animated') || false
|
||||||
|
const dataLabels = component.get('pieChartModel.dataLabels') || {}
|
||||||
|
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
||||||
|
const data = component.get('pieChartModel.data')
|
||||||
|
const sparkline = component.get('pieChartModel.sparkline')
|
||||||
|
const type = component.get('pieChartModel.type')
|
||||||
|
const jsonConfig = component.get('pieChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: data.map(item => item.value),
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
height: '100%',
|
||||||
|
type: type,
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
animations: { enabled: animated },
|
||||||
|
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
if (!onSliceClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dataPointIndex } = config
|
||||||
|
const slice = data[dataPointIndex]
|
||||||
|
component.call('onSliceClick', slice)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
colors: data.map(item => item.color),
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('pieChartModel.opacity'),
|
||||||
|
},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
text: title,
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
|
||||||
|
responsive: [
|
||||||
|
{
|
||||||
|
breakpoint: 600,
|
||||||
|
options: {
|
||||||
|
legend: {
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
legend: component.get('pieChartModel.legend') || {},
|
||||||
|
|
||||||
|
theme: component.get('pieChartModel.theme') || {},
|
||||||
|
|
||||||
|
tooltip: {
|
||||||
|
y: {
|
||||||
|
formatter: function(value, series) {
|
||||||
|
return data[series.dataPointIndex].extras.tooltip || value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const colors = component.get('pieChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default pieChart
|
||||||
99
resources/js/radarChart.js
Normal file
99
resources/js/radarChart.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const radarChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('radarChartModel.title');
|
||||||
|
const animated = component.get('radarChartModel.animated');
|
||||||
|
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName');
|
||||||
|
const dataLabels = component.get('radarChartModel.dataLabels');
|
||||||
|
const data = component.get('radarChartModel.data');
|
||||||
|
const sparkline = component.get('radarChartModel.sparkline');
|
||||||
|
const colors = component.get('radarChartModel.colors');
|
||||||
|
const jsonConfig = component.get('radarChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const series = Object.keys(data)
|
||||||
|
.map(seriesName => ({
|
||||||
|
name: seriesName,
|
||||||
|
data: data[seriesName].map(item => item.value)
|
||||||
|
}))
|
||||||
|
|
||||||
|
const categories = component.get('radarChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('radarChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
type: 'radar',
|
||||||
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
|
toolbar: {show: false},
|
||||||
|
|
||||||
|
animations: {enabled: animated},
|
||||||
|
|
||||||
|
events: {
|
||||||
|
markerClick: function(event, chartContext, {seriesIndex, dataPointIndex}) {
|
||||||
|
if (!onPointClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const point = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
|
||||||
|
component.call('onPointClick', point)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: component.get('radarChartModel.legend'),
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: false,
|
||||||
|
columnWidth: '50%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
title: { text: title },
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('radarChartModel.opacity'),
|
||||||
|
},
|
||||||
|
|
||||||
|
colors: colors,
|
||||||
|
|
||||||
|
markers: {
|
||||||
|
size: 4
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default radarChart
|
||||||
74
resources/js/radialChart.js
Normal file
74
resources/js/radialChart.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from "./helpers";
|
||||||
|
|
||||||
|
const radialChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire);
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = component.get("radialChartModel.data");
|
||||||
|
const showTotal = component.get("radialChartModel.showTotal");
|
||||||
|
const onBarClickEventName = component.get(
|
||||||
|
"radialChartModel.onBarClickEventName"
|
||||||
|
);
|
||||||
|
const jsonConfig = component.get("radialChartModel.jsonConfig");
|
||||||
|
|
||||||
|
const colors = component.get("radialChartModel.colors");
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: data.map((item) => item.value),
|
||||||
|
labels: data.map((item) => item.title),
|
||||||
|
colors: Object.values(colors).filter(Boolean),
|
||||||
|
chart: {
|
||||||
|
height: "100%",
|
||||||
|
type: "radialBar",
|
||||||
|
events: {
|
||||||
|
dataPointSelection: function (
|
||||||
|
event,
|
||||||
|
chartContext,
|
||||||
|
payload
|
||||||
|
) {
|
||||||
|
console.log(payload);
|
||||||
|
|
||||||
|
if (!onBarClickEventName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bar = data[payload.dataPointIndex];
|
||||||
|
console.log(bar);
|
||||||
|
|
||||||
|
component.call("onBarClick", bar);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
radialBar: {
|
||||||
|
dataLabels: {
|
||||||
|
total: {
|
||||||
|
show: showTotal,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(
|
||||||
|
this.$refs.container,
|
||||||
|
mergedOptionsWithJsonConfig(options, jsonConfig)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.chart.render();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default radialChart;
|
||||||
80
resources/js/treeMapChart.js
Normal file
80
resources/js/treeMapChart.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||||
|
|
||||||
|
const treeMapChart = () => {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = component.get('treeMapChartModel.title');
|
||||||
|
const animated = component.get('treeMapChartModel.animated');
|
||||||
|
const distributed = component.get('treeMapChartModel.distributed');
|
||||||
|
const onBlockClickEventName = component.get('treeMapChartModel.onBlockClickEventName');
|
||||||
|
const data = component.get('treeMapChartModel.data');
|
||||||
|
const colors = component.get('treeMapChartModel.colors');
|
||||||
|
const enableShades = component.get('treeMapChartModel.enableShades');
|
||||||
|
const jsonConfig = component.get('treeMapChartModel.jsonConfig');
|
||||||
|
|
||||||
|
const series = Object.keys(data)
|
||||||
|
.map(seriesName => ({
|
||||||
|
name: seriesName,
|
||||||
|
data: data[seriesName].map(item => ({
|
||||||
|
x: item.title,
|
||||||
|
y: item.value,
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
series: series,
|
||||||
|
|
||||||
|
legend: { show: false },
|
||||||
|
|
||||||
|
title: { text: title },
|
||||||
|
|
||||||
|
chart: {
|
||||||
|
height: '100%',
|
||||||
|
type: 'treemap',
|
||||||
|
|
||||||
|
toolbar: {show: false},
|
||||||
|
|
||||||
|
animations: {enabled: animated},
|
||||||
|
|
||||||
|
events: {
|
||||||
|
click: function(event, chartContext, {seriesIndex, dataPointIndex}) {
|
||||||
|
if (!onBlockClickEventName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const block = data[series[seriesIndex].name][dataPointIndex]
|
||||||
|
|
||||||
|
component.call('onBlockClick', block)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
treemap: {
|
||||||
|
distributed: distributed,
|
||||||
|
enableShades: enableShades,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
colors: colors,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default treeMapChart
|
||||||
@@ -1,87 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...areaChart() }"
|
x-data="{ ...livewireChartsAreaChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function areaChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
series: [{
|
|
||||||
name: component.get('areaChartModel.title'),
|
|
||||||
data: component.get('areaChartModel.data').map(item => item.value)
|
|
||||||
}],
|
|
||||||
chart: {
|
|
||||||
type: 'area',
|
|
||||||
height: '100%',
|
|
||||||
|
|
||||||
zoom: { enabled: false },
|
|
||||||
|
|
||||||
toolbar: { show: false },
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('areaChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
|
||||||
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
|
||||||
if (!onPointClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const point = component.get('areaChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
|
||||||
|
|
||||||
stroke: {
|
|
||||||
curve: 'straight'
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
text: component.get('areaChartModel.title'),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
|
|
||||||
labels: component.get('areaChartModel.data').map(item => item.title),
|
|
||||||
|
|
||||||
xaxis: component.get('areaChartModel.xAxis') || {},
|
|
||||||
|
|
||||||
yaxis: component.get('areaChartModel.yAxis') || {},
|
|
||||||
|
|
||||||
grid: {
|
|
||||||
padding: {
|
|
||||||
left: 0,
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,95 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full relative"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...columnChart() }"
|
x-data="{ ...livewireChartsColumnChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function columnChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
this.renderApex(component)
|
|
||||||
},
|
|
||||||
|
|
||||||
renderApex(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: [{ data: component.get('columnChartModel.data').map(item => item.value)}],
|
|
||||||
|
|
||||||
chart: {
|
|
||||||
type: 'bar',
|
|
||||||
height: '100%',
|
|
||||||
|
|
||||||
toolbar: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('columnChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
|
||||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
|
||||||
|
|
||||||
if (!onColumnClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { dataPointIndex } = config
|
|
||||||
const column = component.get('columnChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onColumnClick', column)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: component.get('columnChartModel.data').map(item => item.color),
|
|
||||||
|
|
||||||
labels: {
|
|
||||||
style: {
|
|
||||||
colors: component.get('columnChartModel.data').map(item => item.color),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
plotOptions: {
|
|
||||||
bar: {
|
|
||||||
horizontal: false,
|
|
||||||
columnWidth: '40%',
|
|
||||||
distributed: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
xaxis: {
|
|
||||||
categories: component.get('columnChartModel.data').map(item => item.title),
|
|
||||||
},
|
|
||||||
|
|
||||||
yaxis: {
|
|
||||||
title: {
|
|
||||||
text: component.get('columnChartModel.title'),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fill: {
|
|
||||||
opacity: component.get('columnChartModel.opacity') || 0.5
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,97 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...lineChart() }"
|
x-data="{ ...livewireChartsLineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function lineChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
this.renderApex(component)
|
|
||||||
},
|
|
||||||
|
|
||||||
renderApex(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: [{
|
|
||||||
name: component.get('lineChartModel.title'),
|
|
||||||
data: component.get('lineChartModel.data').map(item => item.value),
|
|
||||||
}],
|
|
||||||
chart: {
|
|
||||||
type: 'line',
|
|
||||||
height: '100%',
|
|
||||||
zoom: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
toolbar: {
|
|
||||||
show: false
|
|
||||||
},
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('lineChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
events: {
|
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
|
||||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName')
|
|
||||||
if (!onPointClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const point = component.get('lineChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
stroke: {
|
|
||||||
curve: 'straight'
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
text: component.get('lineChartModel.title'),
|
|
||||||
align: 'center'
|
|
||||||
},
|
|
||||||
xaxis: {
|
|
||||||
categories: component.get('lineChartModel.data').map(item => item.title),
|
|
||||||
},
|
|
||||||
annotations: {
|
|
||||||
points: component.get('lineChartModel.markers').map(item => {
|
|
||||||
return {
|
|
||||||
x: item.title,
|
|
||||||
y: item.value,
|
|
||||||
marker: {
|
|
||||||
size: 6,
|
|
||||||
fillColor: '#fff',
|
|
||||||
strokeColor: item.strokeColor,
|
|
||||||
radius: 2,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
offsetY: 0,
|
|
||||||
style: {
|
|
||||||
color: item.textColor,
|
|
||||||
background: item.textBackgroundColor,
|
|
||||||
},
|
|
||||||
text: item.text || '',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
8
resources/views/livewire-multi-column-chart.blade.php
Normal file
8
resources/views/livewire-multi-column-chart.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsMultiColumnChart() }"
|
||||||
|
x-init="init()"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
8
resources/views/livewire-multi-line-chart.blade.php
Normal file
8
resources/views/livewire-multi-line-chart.blade.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsMultiLineChart() }"
|
||||||
|
x-init="init()"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,85 +1,8 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...pieChart() }"
|
x-data="{ ...livewireChartsPieChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function pieChart() {
|
|
||||||
return {
|
|
||||||
chart: null,
|
|
||||||
|
|
||||||
drawChart(component) {
|
|
||||||
this.renderApex(component)
|
|
||||||
},
|
|
||||||
|
|
||||||
renderApex(component) {
|
|
||||||
if (this.chart) {
|
|
||||||
this.chart.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
series: component.get('pieChartModel.data').map(item => item.value),
|
|
||||||
|
|
||||||
chart: {
|
|
||||||
height: '100%',
|
|
||||||
type: 'pie',
|
|
||||||
|
|
||||||
animations: {
|
|
||||||
enabled: component.get('pieChartModel.animated') || false,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
|
||||||
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
|
||||||
|
|
||||||
if (!onSliceClickEventName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { dataPointIndex } = config
|
|
||||||
const slice = component.get('pieChartModel.data')[dataPointIndex]
|
|
||||||
component.call('onSliceClick', slice)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
labels: component.get('pieChartModel.data').map(item => item.title),
|
|
||||||
|
|
||||||
dataLabels: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
colors: component.get('pieChartModel.data').map(item => item.color),
|
|
||||||
|
|
||||||
fill: {
|
|
||||||
opacity: component.get('pieChartModel.opacity'),
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
|
||||||
text: component.get('pieChartModel.title'),
|
|
||||||
align: 'center',
|
|
||||||
},
|
|
||||||
|
|
||||||
responsive: [
|
|
||||||
{
|
|
||||||
breakpoint: 600,
|
|
||||||
options: {
|
|
||||||
legend: {
|
|
||||||
position: 'bottom'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
|
||||||
this.chart.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
7
resources/views/livewire-radar-chart.blade.php
Normal file
7
resources/views/livewire-radar-chart.blade.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsRadarChart() }"
|
||||||
|
x-init="init()"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
7
resources/views/livewire-radial-chart.blade.php
Normal file
7
resources/views/livewire-radial-chart.blade.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsRadialChart() }"
|
||||||
|
x-init="init()"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
7
resources/views/livewire-tree-map-chart.blade.php
Normal file
7
resources/views/livewire-tree-map-chart.blade.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...livewireChartsTreeMapChart() }"
|
||||||
|
x-init="init()"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
</div>
|
||||||
@@ -26,7 +26,7 @@ class LivewireAreaChart extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->emit($onPointClickEventName, $point);
|
$this->dispatch($onPointClickEventName, $point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|||||||
@@ -26,11 +26,15 @@ class LivewireColumnChart extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->emit($onColumnClickEventName, $column);
|
$this->dispatch($onColumnClickEventName, $column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->columnChartModel['isMultiColumn']) {
|
||||||
|
return view('livewire-charts::livewire-multi-column-chart');
|
||||||
|
}
|
||||||
|
|
||||||
return view('livewire-charts::livewire-column-chart');
|
return view('livewire-charts::livewire-column-chart');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,15 @@ class LivewireLineChart extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->emit($onPointClickEventName, $point);
|
$this->dispatch($onPointClickEventName, $point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
|
if ($this->lineChartModel['isMultiLine']) {
|
||||||
|
return view('livewire-charts::livewire-multi-line-chart');
|
||||||
|
}
|
||||||
|
|
||||||
return view('livewire-charts::livewire-line-chart');
|
return view('livewire-charts::livewire-line-chart');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class LivewirePieChart extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->emit($onSliceClickEventName, $slice);
|
$this->dispatch($onSliceClickEventName, $slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|||||||
36
src/Charts/LivewireRadarChart.php
Normal file
36
src/Charts/LivewireRadarChart.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Charts;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadarChartModel;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LivewireRadarChart
|
||||||
|
* @package Asantibanez\LivewireCharts\Charts
|
||||||
|
*/
|
||||||
|
class LivewireRadarChart extends Component
|
||||||
|
{
|
||||||
|
public $radarChartModel;
|
||||||
|
|
||||||
|
public function mount(RadarChartModel $radarChartModel)
|
||||||
|
{
|
||||||
|
$this->radarChartModel = $radarChartModel->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPointClick($point)
|
||||||
|
{
|
||||||
|
$onPointClickEventName = data_get($this->radarChartModel, 'onPointClickEventName', null);
|
||||||
|
|
||||||
|
if ($onPointClickEventName === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch($onPointClickEventName, $point);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire-charts::livewire-radar-chart');
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/Charts/LivewireRadialChart.php
Normal file
36
src/Charts/LivewireRadialChart.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Charts;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadialChartModel;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LivewireRadialChart
|
||||||
|
* @package Asantibanez\LivewireCharts\Charts
|
||||||
|
*/
|
||||||
|
class LivewireRadialChart extends Component
|
||||||
|
{
|
||||||
|
public $radialChartModel;
|
||||||
|
|
||||||
|
public function mount(RadialChartModel $radialChartModel)
|
||||||
|
{
|
||||||
|
$this->radialChartModel = $radialChartModel->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBarClick($bar): void
|
||||||
|
{
|
||||||
|
$onBarClickEventName = data_get($this->radialChartModel, 'onBarClickEventName');
|
||||||
|
|
||||||
|
if ($onBarClickEventName === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch($onBarClickEventName, $bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire-charts::livewire-radial-chart');
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/Charts/LivewireTreeMapChart.php
Normal file
36
src/Charts/LivewireTreeMapChart.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Charts;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LivewireTreeMapChart
|
||||||
|
* @package Asantibanez\LivewireCharts\Charts
|
||||||
|
*/
|
||||||
|
class LivewireTreeMapChart extends Component
|
||||||
|
{
|
||||||
|
public $treeMapChartModel;
|
||||||
|
|
||||||
|
public function mount(TreeMapChartModel $treeMapChartModel)
|
||||||
|
{
|
||||||
|
$this->treeMapChartModel = $treeMapChartModel->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBlockClick($block)
|
||||||
|
{
|
||||||
|
$onBlockClickEventName = data_get($this->treeMapChartModel, 'onBlockClickEventName');
|
||||||
|
|
||||||
|
if ($onBlockClickEventName === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch($onBlockClickEventName, $block);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire-charts::livewire-tree-map-chart');
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/Console/InstallCommand.php
Normal file
17
src/Console/InstallCommand.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Console;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class InstallCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'livewire-charts:install';
|
||||||
|
|
||||||
|
protected $description = 'Installs Livewire Charts';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->call('vendor:publish', ['--tag' => 'livewire-charts:public']);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/Facades/LivewireCharts.php
Normal file
33
src/Facades/LivewireCharts.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Facades;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadarChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadialChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class LivewireCharts
|
||||||
|
* @package Asantibanez\LivewireCharts\Facades
|
||||||
|
* @method static LineChartModel lineChartModel()
|
||||||
|
* @method static LineChartModel multiLineChartModel()
|
||||||
|
* @method static ColumnChartModel columnChartModel()
|
||||||
|
* @method static ColumnChartModel multiColumnChartModel()
|
||||||
|
* @method static AreaChartModel areaChartModel()
|
||||||
|
* @method static PieChartModel pieChartModel()
|
||||||
|
* @method static RadarChartModel radarChartModel()
|
||||||
|
* @method static TreeMapChartModel treeMapChartModel()
|
||||||
|
* @method static RadialChartModel radialChartModel()
|
||||||
|
*/
|
||||||
|
class LivewireCharts extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'livewirecharts';
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/LivewireCharts.php
Normal file
65
src/LivewireCharts.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts;
|
||||||
|
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadarChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadialChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
|
||||||
|
|
||||||
|
class LivewireCharts
|
||||||
|
{
|
||||||
|
public function lineChartModel()
|
||||||
|
{
|
||||||
|
return (new LineChartModel)
|
||||||
|
->singleLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function multiLineChartModel()
|
||||||
|
{
|
||||||
|
return (new LineChartModel)
|
||||||
|
->multiLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function columnChartModel()
|
||||||
|
{
|
||||||
|
return (new ColumnChartModel)
|
||||||
|
->singleColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function multiColumnChartModel()
|
||||||
|
{
|
||||||
|
return (new ColumnChartModel)
|
||||||
|
->multiColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function areaChartModel()
|
||||||
|
{
|
||||||
|
return new AreaChartModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pieChartModel()
|
||||||
|
{
|
||||||
|
return new PieChartModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function radarChartModel()
|
||||||
|
{
|
||||||
|
return new RadarChartModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function treeMapChartModel(): TreeMapChartModel
|
||||||
|
{
|
||||||
|
return new TreeMapChartModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function radialChartModel(): RadialChartModel
|
||||||
|
{
|
||||||
|
return new RadialChartModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,35 +6,84 @@ use Asantibanez\LivewireCharts\Charts\LivewireAreaChart;
|
|||||||
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
||||||
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
|
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
|
||||||
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireRadarChart;
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireRadialChart;
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireTreeMapChart;
|
||||||
|
use Asantibanez\LivewireCharts\Console\InstallCommand;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
|
|
||||||
class LivewireChartsServiceProvider extends ServiceProvider
|
class LivewireChartsServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Bootstrap the application services.
|
|
||||||
*/
|
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
$this->registerCommands();
|
||||||
|
|
||||||
|
$this->registerViews();
|
||||||
|
|
||||||
|
$this->registerPublishables();
|
||||||
|
|
||||||
|
$this->registerComponents();
|
||||||
|
|
||||||
|
$this->registerDirectives();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind('livewirecharts', LivewireCharts::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerCommands()
|
||||||
|
{
|
||||||
|
if ($this->app->runningInConsole()) {
|
||||||
|
$this->commands([
|
||||||
|
InstallCommand::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function registerViews()
|
||||||
|
{
|
||||||
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerPublishables()
|
||||||
|
{
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__.'/../resources/views' => resource_path('views/vendor/livewire-charts'),
|
__DIR__.'/../resources/views' => resource_path('views/vendor/livewire-charts'),
|
||||||
], 'livewire-charts-views');
|
], 'livewire-charts:views');
|
||||||
}
|
|
||||||
|
|
||||||
|
$this->publishes([
|
||||||
|
__DIR__.'/../resources/js' => resource_path('js/vendor/livewire-charts'),
|
||||||
|
], 'livewire-charts:scripts');
|
||||||
|
|
||||||
|
$this->publishes([
|
||||||
|
__DIR__.'/../public' => public_path('vendor/livewire-charts'),
|
||||||
|
], 'livewire-charts:public');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerComponents()
|
||||||
|
{
|
||||||
Livewire::component('livewire-line-chart', LivewireLineChart::class);
|
Livewire::component('livewire-line-chart', LivewireLineChart::class);
|
||||||
Livewire::component('livewire-column-chart', LivewireColumnChart::class);
|
Livewire::component('livewire-column-chart', LivewireColumnChart::class);
|
||||||
Livewire::component('livewire-pie-chart', LivewirePieChart::class);
|
Livewire::component('livewire-pie-chart', LivewirePieChart::class);
|
||||||
Livewire::component('livewire-area-chart', LivewireAreaChart::class);
|
Livewire::component('livewire-area-chart', LivewireAreaChart::class);
|
||||||
|
Livewire::component('livewire-radar-chart', LivewireRadarChart::class);
|
||||||
|
Livewire::component('livewire-tree-map-chart', LivewireTreeMapChart::class);
|
||||||
|
Livewire::component('livewire-radial-chart', LivewireRadialChart::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function registerDirectives()
|
||||||
* Register the application services.
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
{
|
||||||
//
|
Blade::directive('livewireChartsScripts', function () {
|
||||||
|
$scriptsUrl = asset('/vendor/livewire-charts/app.js');
|
||||||
|
return <<<EOF
|
||||||
|
<script src="$scriptsUrl"></script>
|
||||||
|
EOF;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
*/
|
*/
|
||||||
class AreaChartModel extends BaseChartModel
|
class AreaChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $color;
|
public $color;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
@@ -23,10 +19,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->title = '';
|
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->color = '#90cdf4';
|
$this->color = '#90cdf4';
|
||||||
|
|
||||||
$this->onPointClickEventName = null;
|
$this->onPointClickEventName = null;
|
||||||
@@ -34,20 +26,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAnimated($animated)
|
|
||||||
{
|
|
||||||
$this->animated = $animated;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setColor($color)
|
public function setColor($color)
|
||||||
{
|
{
|
||||||
$this->color = $color;
|
$this->color = $color;
|
||||||
@@ -76,8 +54,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'color' => $this->color,
|
'color' => $this->color,
|
||||||
'onPointClickEventName' => $this->onPointClickEventName,
|
'onPointClickEventName' => $this->onPointClickEventName,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
@@ -88,10 +64,6 @@ class AreaChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
parent::fromArray($array);
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->title = data_get($array, 'title', '');
|
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->color = data_get($array, 'color', '#90cdf4');
|
$this->color = data_get($array, 'color', '#90cdf4');
|
||||||
|
|
||||||
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||||
|
|||||||
@@ -3,17 +3,49 @@
|
|||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Models;
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasAnimation;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasAxis;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasColors;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasDataLabels;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasGrid;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasJsonConfig;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasLegend;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasSparkline;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasStroke;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasTheme;
|
||||||
|
use Asantibanez\LivewireCharts\Models\Traits\HasTitle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseChartModel
|
* Class BaseChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
*/
|
*/
|
||||||
class BaseChartModel
|
class BaseChartModel
|
||||||
{
|
{
|
||||||
use HasAxisConfiguration;
|
use HasTitle;
|
||||||
|
use HasAnimation;
|
||||||
|
use HasAxis;
|
||||||
|
use HasStroke;
|
||||||
|
use HasLegend;
|
||||||
|
use HasDataLabels;
|
||||||
|
use HasSparkline;
|
||||||
|
use HasGrid;
|
||||||
|
use HasColors;
|
||||||
|
use HasTheme;
|
||||||
|
use HasJsonConfig;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->setupAxis();
|
$this->initTitle();
|
||||||
|
$this->initAnimation();
|
||||||
|
$this->initAxis();
|
||||||
|
$this->initStroke();
|
||||||
|
$this->initLegend();
|
||||||
|
$this->initDataLabels();
|
||||||
|
$this->initSparkline();
|
||||||
|
$this->initGrid();
|
||||||
|
$this->initColors();
|
||||||
|
$this->initTheme();
|
||||||
|
$this->initJsonConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
public function reactiveKey()
|
||||||
@@ -23,14 +55,33 @@ class BaseChartModel
|
|||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return [
|
return array_merge(
|
||||||
'xAxis' => $this->xAxis,
|
$this->titleToArray(),
|
||||||
'yAxis' => $this->yAxis,
|
$this->animationToArray(),
|
||||||
];
|
$this->axisToArray(),
|
||||||
|
$this->strokeToArray(),
|
||||||
|
$this->legendToArray(),
|
||||||
|
$this->dataLabelsToArray(),
|
||||||
|
$this->sparklineToArray(),
|
||||||
|
$this->gridToArray(),
|
||||||
|
$this->colorsToArray(),
|
||||||
|
$this->themeToArray(),
|
||||||
|
$this->jsonConfigToArray(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray($array)
|
public function fromArray($array)
|
||||||
{
|
{
|
||||||
$this->setupAxis($array);
|
$this->titleFromArray($array);
|
||||||
|
$this->animationFromArray($array);
|
||||||
|
$this->axisFromArray($array);
|
||||||
|
$this->strokeFromArray($array);
|
||||||
|
$this->legendFromArray($array);
|
||||||
|
$this->dataLabelsFromArray($array);
|
||||||
|
$this->sparklineFromArray($array);
|
||||||
|
$this->gridFromArray($array);
|
||||||
|
$this->colorsFromArray($array);
|
||||||
|
$this->themeFromArray($array);
|
||||||
|
$this->jsonConfigFromArray($array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,47 +3,85 @@
|
|||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Models;
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ColumnChartModel
|
* Class ColumnChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiColumn
|
||||||
|
* @property boolean $isStacked
|
||||||
*/
|
*/
|
||||||
class ColumnChartModel
|
class ColumnChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
private $opacity;
|
||||||
|
|
||||||
public $animated;
|
private $columnWidth;
|
||||||
|
|
||||||
public $opacity;
|
private $horizontal;
|
||||||
|
|
||||||
public $onColumnClickEventName;
|
private $isMultiColumn;
|
||||||
|
|
||||||
public $data;
|
private $isStacked;
|
||||||
|
|
||||||
|
private $onColumnClickEventName;
|
||||||
|
|
||||||
|
private $data;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->title = '';
|
parent::__construct();
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->onColumnClickEventName = null;
|
$this->onColumnClickEventName = null;
|
||||||
|
|
||||||
$this->opacity = 0.5;
|
$this->opacity = 0.75;
|
||||||
|
|
||||||
|
$this->columnWidth = 70;
|
||||||
|
|
||||||
|
$this->horizontal = false;
|
||||||
|
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
$this->isStacked = false;
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
public function multiColumn()
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
$this->isMultiColumn = true;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnimated($animated)
|
public function singleColumn()
|
||||||
{
|
{
|
||||||
$this->animated = $animated;
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stacked()
|
||||||
|
{
|
||||||
|
$this->isStacked = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHorizontal()
|
||||||
|
{
|
||||||
|
$this->horizontal = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setVertical()
|
||||||
|
{
|
||||||
|
$this->horizontal = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setColumnWidth($value)
|
||||||
|
{
|
||||||
|
$this->columnWidth = $value;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -74,33 +112,51 @@ class ColumnChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addSeriesColumn($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'horizontal' => $this->horizontal,
|
||||||
|
'columnWidth' => $this->columnWidth,
|
||||||
|
'isMultiColumn' => $this->isMultiColumn,
|
||||||
|
'isStacked' => $this->isStacked,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray($array)
|
public function fromArray($array)
|
||||||
{
|
{
|
||||||
$this->title = data_get($array, 'title', '');
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null);
|
$this->onColumnClickEventName = data_get($array, 'onColumnClickEventName', null);
|
||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.5);
|
$this->opacity = data_get($array, 'opacity', 0.5);
|
||||||
|
|
||||||
|
$this->columnWidth = data_get($array, 'columnWidth', 70);
|
||||||
|
|
||||||
|
$this->horizontal = data_get($array, 'horizontal', false);
|
||||||
|
|
||||||
|
$this->isMultiColumn = data_get($array, 'isMultiColumn', false);
|
||||||
|
|
||||||
|
$this->isStacked = data_get($array, 'isStacked', false);
|
||||||
|
|
||||||
$this->data = collect(data_get($array, 'data', []));
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
|
||||||
{
|
|
||||||
return md5(json_encode($this->toArray()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Models;
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LineChartModel
|
* Class LineChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiLine
|
||||||
*/
|
*/
|
||||||
class LineChartModel
|
class LineChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
public $isMultiLine;
|
||||||
|
|
||||||
public $animated;
|
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
@@ -21,9 +22,9 @@ class LineChartModel
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->title = '';
|
parent::__construct();
|
||||||
|
|
||||||
$this->animated = false;
|
$this->isMultiLine = false;
|
||||||
|
|
||||||
$this->onPointClickEventName = null;
|
$this->onPointClickEventName = null;
|
||||||
|
|
||||||
@@ -32,16 +33,20 @@ class LineChartModel
|
|||||||
$this->markers = collect();
|
$this->markers = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
public function multiLine()
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
$this->isMultiLine = true;
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAnimated($animated)
|
public function singleLine()
|
||||||
{
|
{
|
||||||
$this->animated = $animated;
|
$this->isMultiLine = false;
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -57,6 +62,22 @@ class LineChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addSeriesPoint($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function addMarker($title,
|
public function addMarker($title,
|
||||||
$value,
|
$value,
|
||||||
$strokeColor = 'green',
|
$strokeColor = 'green',
|
||||||
@@ -85,20 +106,19 @@ class LineChartModel
|
|||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
'isMultiLine' => $this->isMultiLine,
|
||||||
'animated' => $this->animated,
|
|
||||||
'onPointClickEventName' => $this->onPointClickEventName,
|
'onPointClickEventName' => $this->onPointClickEventName,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
'markers' => $this->markers->toArray(),
|
'markers' => $this->markers->toArray(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray($array)
|
public function fromArray($array)
|
||||||
{
|
{
|
||||||
$this->title = data_get($array, 'title', '');
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
$this->isMultiLine = data_get($array, 'isMultiLine', false);
|
||||||
|
|
||||||
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||||
|
|
||||||
@@ -106,9 +126,4 @@ class LineChartModel
|
|||||||
|
|
||||||
$this->markers = collect(data_get($array, 'markers', []));
|
$this->markers = collect(data_get($array, 'markers', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
|
||||||
{
|
|
||||||
return md5(json_encode($this->toArray()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,45 +7,29 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
* Class PieChartModel
|
* Class PieChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
*/
|
*/
|
||||||
class PieChartModel
|
class PieChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $title;
|
private $onSliceClickEventName;
|
||||||
|
|
||||||
public $animated;
|
private $opacity;
|
||||||
|
|
||||||
public $onSliceClickEventName;
|
private $type;
|
||||||
|
|
||||||
public $opacity;
|
private $data;
|
||||||
|
|
||||||
public $data;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->title = '';
|
parent::__construct();
|
||||||
|
|
||||||
$this->animated = false;
|
|
||||||
|
|
||||||
$this->onSliceClickEventName = null;
|
$this->onSliceClickEventName = null;
|
||||||
|
|
||||||
$this->opacity = 0.75;
|
$this->opacity = 0.75;
|
||||||
|
|
||||||
|
$this->type = 'pie';
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle($title)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAnimated($animated)
|
|
||||||
{
|
|
||||||
$this->animated = $animated;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setOpacity($opacity)
|
public function setOpacity($opacity)
|
||||||
{
|
{
|
||||||
$this->opacity = $opacity;
|
$this->opacity = $opacity;
|
||||||
@@ -53,6 +37,23 @@ class PieChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setType($type)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asPie()
|
||||||
|
{
|
||||||
|
return $this->setType('pie');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asDonut()
|
||||||
|
{
|
||||||
|
return $this->setType('donut');
|
||||||
|
}
|
||||||
|
|
||||||
public function withOnSliceClickEvent($onSliceClickEventName)
|
public function withOnSliceClickEvent($onSliceClickEventName)
|
||||||
{
|
{
|
||||||
$this->onSliceClickEventName = $onSliceClickEventName;
|
$this->onSliceClickEventName = $onSliceClickEventName;
|
||||||
@@ -74,30 +75,24 @@ class PieChartModel
|
|||||||
|
|
||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return [
|
return array_merge(parent::toArray(), [
|
||||||
'title' => $this->title,
|
|
||||||
'animated' => $this->animated,
|
|
||||||
'onSliceClickEventName' => $this->onSliceClickEventName,
|
'onSliceClickEventName' => $this->onSliceClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'type' => $this->type,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray($array)
|
public function fromArray($array)
|
||||||
{
|
{
|
||||||
$this->title = data_get($array, 'title', '');
|
parent::fromArray($array);
|
||||||
|
|
||||||
$this->animated = data_get($array, 'animated', false);
|
|
||||||
|
|
||||||
$this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null);
|
$this->onSliceClickEventName = data_get($array, 'onSliceClickEventName', null);
|
||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.75);
|
$this->opacity = data_get($array, 'opacity', 0.75);
|
||||||
|
|
||||||
|
$this->type = data_get($array, 'type', 'pie');
|
||||||
|
|
||||||
$this->data = collect(data_get($array, 'data', []));
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
|
||||||
{
|
|
||||||
return md5(json_encode($this->toArray()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
95
src/Models/RadarChartModel.php
Normal file
95
src/Models/RadarChartModel.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ColumnChartModel
|
||||||
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiColumn
|
||||||
|
* @property boolean $isStacked
|
||||||
|
*/
|
||||||
|
class RadarChartModel extends BaseChartModel
|
||||||
|
{
|
||||||
|
public $opacity;
|
||||||
|
|
||||||
|
public $colors;
|
||||||
|
|
||||||
|
public $onPointClickEventName;
|
||||||
|
|
||||||
|
public $data;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->onPointClickEventName = null;
|
||||||
|
|
||||||
|
$this->opacity = 0.5;
|
||||||
|
|
||||||
|
$this->colors = ['#2E93fA', '#66DA26', '#546E7A', '#E91E63', '#FF9800'];
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setColors($colors)
|
||||||
|
{
|
||||||
|
$this->colors = $colors;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOpacity($opacity)
|
||||||
|
{
|
||||||
|
$this->opacity = $opacity;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withOnPointClickEvent($onPointClickEventName)
|
||||||
|
{
|
||||||
|
$this->onPointClickEventName = $onPointClickEventName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addSeries($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return array_merge(parent::toArray(), [
|
||||||
|
'onPointClickEventName' => $this->onPointClickEventName,
|
||||||
|
'opacity' => $this->opacity,
|
||||||
|
'colors' => $this->colors,
|
||||||
|
'data' => $this->data->toArray(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromArray($array)
|
||||||
|
{
|
||||||
|
parent::fromArray($array);
|
||||||
|
|
||||||
|
$this->onPointClickEventName = data_get($array, 'onPointClickEventName', null);
|
||||||
|
|
||||||
|
$this->opacity = data_get($array, 'opacity', 0.5);
|
||||||
|
|
||||||
|
$this->colors = data_get($array, 'color', '#90cdf4');
|
||||||
|
|
||||||
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
|
}
|
||||||
|
}
|
||||||
76
src/Models/RadialChartModel.php
Normal file
76
src/Models/RadialChartModel.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RadialChartModel
|
||||||
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
*/
|
||||||
|
class RadialChartModel extends BaseChartModel
|
||||||
|
{
|
||||||
|
public $data;
|
||||||
|
public $showTotal;
|
||||||
|
public $onBarClickEventName;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
|
$this->showTotal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showTotal(): self
|
||||||
|
{
|
||||||
|
$this->showTotal = true;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hideTotal(): self
|
||||||
|
{
|
||||||
|
$this->showTotal = false;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBar($title, $value, $color = null, $extras = []): self
|
||||||
|
{
|
||||||
|
$this->data->push([
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->addColor($color);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withOnBarClickEvent($onBarClickEvent): self
|
||||||
|
{
|
||||||
|
$this->onBarClickEventName = $onBarClickEvent;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return array_merge(parent::toArray(), [
|
||||||
|
'data' => $this->data->toArray(),
|
||||||
|
'showTotal' => $this->showTotal,
|
||||||
|
'onBarClickEventName' => $this->onBarClickEventName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromArray($array)
|
||||||
|
{
|
||||||
|
parent::fromArray($array);
|
||||||
|
|
||||||
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
|
|
||||||
|
$this->showTotal = data_get($array, 'showTotal', true);
|
||||||
|
|
||||||
|
$this->onBarClickEventName = data_get($array, 'onBarClickEventName', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Models/Traits/HasAnimation.php
Normal file
39
src/Models/Traits/HasAnimation.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasAnimation
|
||||||
|
{
|
||||||
|
private $animated;
|
||||||
|
|
||||||
|
public function setAnimated($animated)
|
||||||
|
{
|
||||||
|
$this->animated = $animated;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initAnimation()
|
||||||
|
{
|
||||||
|
$this->animated = $this->defaultAnimated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultAnimated()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function animationFromArray($array)
|
||||||
|
{
|
||||||
|
$this->animated = data_get($array, 'animated', $this->defaultAnimated());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function animationToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'animated' => $this->animated,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Models;
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
trait HasAxisConfiguration
|
trait HasAxis
|
||||||
{
|
{
|
||||||
private $xAxis;
|
private $xAxis;
|
||||||
|
|
||||||
private $yAxis;
|
private $yAxis;
|
||||||
|
|
||||||
public function setXAxisVisible($visible)
|
protected function initAxis()
|
||||||
{
|
{
|
||||||
data_set($this->xAxis, 'labels.show', $visible);
|
$this->xAxis = $this->defaultXAxis();
|
||||||
|
$this->yAxis = $this->defaultYAxis();
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setYAxisVisible($visible)
|
|
||||||
{
|
|
||||||
data_set($this->yAxis, 'show', $visible);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setupAxis($array = [])
|
|
||||||
{
|
|
||||||
$this->xAxis = data_get($array, 'xAxis', $this->defaultXAxis());
|
|
||||||
|
|
||||||
$this->yAxis = data_get($array, 'yAxis', $this->defaultYAxis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function defaultXAxis()
|
private function defaultXAxis()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'categories' => [],
|
||||||
'labels' => [
|
'labels' => [
|
||||||
'show' => true,
|
'show' => true,
|
||||||
],
|
],
|
||||||
@@ -46,4 +32,40 @@ trait HasAxisConfiguration
|
|||||||
'show' => true,
|
'show' => true,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setXAxisVisible($visible)
|
||||||
|
{
|
||||||
|
data_set($this->xAxis, 'labels.show', $visible);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setXAxisCategories($categories = [])
|
||||||
|
{
|
||||||
|
data_set($this->xAxis, 'categories', $categories);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setYAxisVisible($visible)
|
||||||
|
{
|
||||||
|
data_set($this->yAxis, 'show', $visible);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function axisFromArray($array)
|
||||||
|
{
|
||||||
|
$this->xAxis = data_get($array, 'xAxis', $this->defaultXAxis());
|
||||||
|
|
||||||
|
$this->yAxis = data_get($array, 'yAxis', $this->defaultYAxis());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function axisToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'xAxis' => $this->xAxis,
|
||||||
|
'yAxis' => $this->yAxis,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
67
src/Models/Traits/HasColors.php
Normal file
67
src/Models/Traits/HasColors.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasColors
|
||||||
|
{
|
||||||
|
private $colors;
|
||||||
|
|
||||||
|
private $enableShades;
|
||||||
|
|
||||||
|
public function setColors($colors)
|
||||||
|
{
|
||||||
|
$this->colors = $colors;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addColor($color)
|
||||||
|
{
|
||||||
|
$this->colors[] = $color;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableShades()
|
||||||
|
{
|
||||||
|
$this->enableShades = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableShades()
|
||||||
|
{
|
||||||
|
$this->enableShades = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initColors()
|
||||||
|
{
|
||||||
|
$this->colors = $this->defaultColors();
|
||||||
|
|
||||||
|
$this->enableShades = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultColors()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function colorsFromArray($array)
|
||||||
|
{
|
||||||
|
$this->colors = data_get($array, 'colors', $this->defaultColors());
|
||||||
|
|
||||||
|
$this->enableShades = data_get($array, 'enableShades', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function colorsToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'colors' => $this->colors,
|
||||||
|
'enableShades' => $this->enableShades,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/Models/Traits/HasDataLabels.php
Normal file
55
src/Models/Traits/HasDataLabels.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasDataLabels
|
||||||
|
{
|
||||||
|
private $dataLabels;
|
||||||
|
|
||||||
|
public function setDataLabelsEnabled($enabled)
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', $enabled);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withDataLabels()
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', true);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withoutDataLabels()
|
||||||
|
{
|
||||||
|
data_set($this->dataLabels, 'enabled', false);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initDataLabels()
|
||||||
|
{
|
||||||
|
$this->dataLabels = $this->defaultDataLabels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultDataLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'enabled' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function dataLabelsFromArray($array)
|
||||||
|
{
|
||||||
|
$this->dataLabels = data_get($array, 'dataLabels', $this->defaultDataLabels());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function dataLabelsToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'dataLabels' => $this->dataLabels,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/Models/Traits/HasGrid.php
Normal file
66
src/Models/Traits/HasGrid.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasGrid
|
||||||
|
{
|
||||||
|
private $grid;
|
||||||
|
|
||||||
|
public function setGridVisible($visible)
|
||||||
|
{
|
||||||
|
data_set($this->grid, 'show', $visible);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withGrid()
|
||||||
|
{
|
||||||
|
data_set($this->grid, 'show', true);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withoutGrid()
|
||||||
|
{
|
||||||
|
data_set($this->grid, 'show', false);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initGrid()
|
||||||
|
{
|
||||||
|
$this->grid = $this->defaultGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultGrid()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'show' => false,
|
||||||
|
'position' => 'back',
|
||||||
|
'xaxis' => [
|
||||||
|
'lines' => [
|
||||||
|
'show' => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'yaxis' => [
|
||||||
|
'lines' => [
|
||||||
|
'show' => true,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function gridFromArray($array)
|
||||||
|
{
|
||||||
|
$this->grid = data_get($array, 'grid', $this->defaultGrid());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function gridToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'grid' => $this->grid,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Models/Traits/HasJsonConfig.php
Normal file
39
src/Models/Traits/HasJsonConfig.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasJsonConfig
|
||||||
|
{
|
||||||
|
private $jsonConfig;
|
||||||
|
|
||||||
|
public function setJsonConfig($jsonConfig)
|
||||||
|
{
|
||||||
|
$this->jsonConfig = $jsonConfig;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initJsonConfig()
|
||||||
|
{
|
||||||
|
$this->jsonConfig = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultJsonConfig()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function jsonConfigFromArray($array)
|
||||||
|
{
|
||||||
|
$this->jsonConfig = data_get($array, 'jsonConfig', $this->defaultJsonConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function jsonConfigToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'jsonConfig' => $this->jsonConfig,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
102
src/Models/Traits/HasLegend.php
Normal file
102
src/Models/Traits/HasLegend.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasLegend
|
||||||
|
{
|
||||||
|
private $legend;
|
||||||
|
|
||||||
|
public function initLegend()
|
||||||
|
{
|
||||||
|
$this->legend = $this->defaultLegend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultLegend()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'show' => true,
|
||||||
|
'position' => 'bottom',
|
||||||
|
'horizontalAlign' => 'center',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLegendVisibility($visible)
|
||||||
|
{
|
||||||
|
data_set($this->legend, 'show', $visible);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLegendPosition($position)
|
||||||
|
{
|
||||||
|
data_set($this->legend, 'position', $position);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLegendHorizontalAlign($horizontalAlign)
|
||||||
|
{
|
||||||
|
data_set($this->legend, 'horizontalAlign', $horizontalAlign);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withoutLegend()
|
||||||
|
{
|
||||||
|
return $this->setLegendVisibility(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withLegend()
|
||||||
|
{
|
||||||
|
return $this->setLegendVisibility(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendPositionTop()
|
||||||
|
{
|
||||||
|
return $this->setLegendPosition('top');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendPositionLeft()
|
||||||
|
{
|
||||||
|
return $this->setLegendPosition('left');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendPositionRight()
|
||||||
|
{
|
||||||
|
return $this->setLegendPosition('right');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendPositionBottom()
|
||||||
|
{
|
||||||
|
return $this->setLegendPosition('bottom');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendHorizontallyAlignedLeft()
|
||||||
|
{
|
||||||
|
return $this->setLegendHorizontalAlign('left');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendHorizontallyAlignedCenter()
|
||||||
|
{
|
||||||
|
return $this->setLegendHorizontalAlign('center');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function legendHorizontallyAlignedRight()
|
||||||
|
{
|
||||||
|
return $this->setLegendHorizontalAlign('right');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function legendToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'legend' => $this->legend,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function legendFromArray($array)
|
||||||
|
{
|
||||||
|
$this->legend = data_get($array, 'legend', $this->defaultLegend());
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/Models/Traits/HasSparkline.php
Normal file
48
src/Models/Traits/HasSparkline.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasSparkline
|
||||||
|
{
|
||||||
|
private $sparkline;
|
||||||
|
|
||||||
|
public function setSparklineEnabled($isEnabled)
|
||||||
|
{
|
||||||
|
data_set($this->sparkline, 'sparkline.enabled', $isEnabled);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sparklined()
|
||||||
|
{
|
||||||
|
return $this->setSparklineEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initSparkline()
|
||||||
|
{
|
||||||
|
$this->sparkline = $this->defaultSparkline();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultSparkline()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'sparkline' => [
|
||||||
|
'enabled' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sparklineFromArray($array)
|
||||||
|
{
|
||||||
|
$this->sparkline = data_get($array, 'sparkline', $this->defaultSparkline());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sparklineToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'sparkline' => $this->sparkline,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
57
src/Models/Traits/HasStroke.php
Normal file
57
src/Models/Traits/HasStroke.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasStroke
|
||||||
|
{
|
||||||
|
private $stroke;
|
||||||
|
private $width;
|
||||||
|
|
||||||
|
public function initStroke()
|
||||||
|
{
|
||||||
|
$this->stroke = $this->defaultStroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultStroke()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'curve' => 'straight',
|
||||||
|
'width' => 4
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSmoothCurve()
|
||||||
|
{
|
||||||
|
data_set($this->stroke, 'curve', 'smooth');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStraightCurve()
|
||||||
|
{
|
||||||
|
data_set($this->stroke, 'curve', 'straight');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStrokeWidth($width)
|
||||||
|
{
|
||||||
|
data_set($this->stroke, 'width', $width);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function strokeToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'stroke' => $this->stroke,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function strokeFromArray($array)
|
||||||
|
{
|
||||||
|
$this->stroke = data_get($array, 'stroke', $this->defaultStroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
125
src/Models/Traits/HasTheme.php
Normal file
125
src/Models/Traits/HasTheme.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasTheme
|
||||||
|
{
|
||||||
|
private $theme;
|
||||||
|
private $mode;
|
||||||
|
private $palette;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize
|
||||||
|
*/
|
||||||
|
public function initTheme()
|
||||||
|
{
|
||||||
|
$this->theme = $this->defaultTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set default theme
|
||||||
|
*
|
||||||
|
* @return array $theme
|
||||||
|
*/
|
||||||
|
private function defaultTheme()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'mode' => 'light',
|
||||||
|
'palette' => 'palette1'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set theme mode
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setThemeMode(string $mode)
|
||||||
|
{
|
||||||
|
data_set($this->theme, 'mode', $mode);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set theme mode to dark theme
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function darkMode()
|
||||||
|
{
|
||||||
|
data_set($this->theme, 'mode', 'dark');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set theme mode to light theme
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function lightMode()
|
||||||
|
{
|
||||||
|
data_set($this->theme, 'mode', 'light');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the dark mode option to on or off
|
||||||
|
*
|
||||||
|
* @param bool $status = true
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDarkMode(bool $status = true)
|
||||||
|
{
|
||||||
|
data_set($this->theme, 'mode', $status ? 'dark' : 'light');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set theme pallete
|
||||||
|
*
|
||||||
|
* @param string $pallete
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setThemePalette(string $palette)
|
||||||
|
{
|
||||||
|
data_set($this->theme, 'palette', $palette);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert the theme to array
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function themeToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'theme' => $this->theme,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set theme from array
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function themeFromArray($array)
|
||||||
|
{
|
||||||
|
$this->theme = data_get($array, 'theme', $this->defaultTheme());
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/Models/Traits/HasTitle.php
Normal file
44
src/Models/Traits/HasTitle.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models\Traits;
|
||||||
|
|
||||||
|
|
||||||
|
trait HasTitle
|
||||||
|
{
|
||||||
|
private $title;
|
||||||
|
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initTitle()
|
||||||
|
{
|
||||||
|
$this->title = $this->defaultTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function defaultTitle()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function titleFromArray($array)
|
||||||
|
{
|
||||||
|
$this->title = data_get($array, 'title', $this->defaultTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function titleToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => $this->title,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
81
src/Models/TreeMapChartModel.php
Normal file
81
src/Models/TreeMapChartModel.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TreeMapChartModel
|
||||||
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
*/
|
||||||
|
class TreeMapChartModel extends BaseChartModel
|
||||||
|
{
|
||||||
|
public $data;
|
||||||
|
public $distributed;
|
||||||
|
public $onBlockClickEventName;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->data = collect();
|
||||||
|
|
||||||
|
$this->distributed = false;
|
||||||
|
|
||||||
|
$this->setColors(['#2E93fA']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDistributed($distributed)
|
||||||
|
{
|
||||||
|
$this->distributed = $distributed;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBlock($title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
return $this->addSeriesBlock($this->getTitle(), $title, $value, $extras);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSeriesBlock($seriesName, $title, $value, $extras = [])
|
||||||
|
{
|
||||||
|
$series = $this->data->get($seriesName, collect());
|
||||||
|
|
||||||
|
$series->push([
|
||||||
|
'seriesName' => $seriesName,
|
||||||
|
'title' => $title,
|
||||||
|
'value' => $value,
|
||||||
|
'extras' => $extras,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->data->put($seriesName, $series);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withOnBlockClickEvent($onBlockClickEventName)
|
||||||
|
{
|
||||||
|
$this->onBlockClickEventName = $onBlockClickEventName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
return array_merge(parent::toArray(), [
|
||||||
|
'data' => $this->data->toArray(),
|
||||||
|
'distributed' => $this->distributed,
|
||||||
|
'onBlockClickEventName' => $this->onBlockClickEventName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromArray($array)
|
||||||
|
{
|
||||||
|
parent::fromArray($array);
|
||||||
|
|
||||||
|
$this->data = collect(data_get($array, 'data', []));
|
||||||
|
|
||||||
|
$this->distributed = data_get($array, 'distributed', false);
|
||||||
|
|
||||||
|
$this->onBlockClickEventName = data_get($array, 'onBlockClickEventName', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Asantibanez\LivewireCharts\Tests;
|
|
||||||
|
|
||||||
use Orchestra\Testbench\TestCase;
|
|
||||||
use Asantibanez\LivewireCharts\LivewireChartsServiceProvider;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
protected function getPackageProviders($app)
|
|
||||||
{
|
|
||||||
return [LivewireChartsServiceProvider::class];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function true_is_true()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
tests/LivewireAreaChartTest.php
Executable file
25
tests/LivewireAreaChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireAreaChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireAreaChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireAreaChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/LivewireColumnChartTest.php
Executable file
44
tests/LivewireColumnChartTest.php
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireColumnChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireColumnChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function should_emit_event_if_present()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
$columnChartModel = $component->columnChartModel;
|
||||||
|
|
||||||
|
data_set($columnChartModel, 'onColumnClickEventName', 'custom-event');
|
||||||
|
|
||||||
|
$component->set('columnChartModel', $columnChartModel);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
$component->runAction('onColumnClick', []);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$component->assertDispatched('custom-event');
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/LivewireLineChartTest.php
Executable file
25
tests/LivewireLineChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireLineChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireLineChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/LivewirePieChartTest.php
Executable file
44
tests/LivewirePieChartTest.php
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewirePieChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewirePieChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function should_emit_event_if_present()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
$pieChartModel = $component->pieChartModel;
|
||||||
|
|
||||||
|
data_set($pieChartModel, 'onSliceClickEventName', 'custom-event');
|
||||||
|
|
||||||
|
$component->set('pieChartModel', $pieChartModel);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
$component->runAction('onSliceClick', []);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$component->assertDispatched('custom-event');
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/LivewireRadarChartTest.php
Executable file
25
tests/LivewireRadarChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireRadarChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireRadarChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireRadarChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/LivewireRadialChartTest.php
Executable file
44
tests/LivewireRadialChartTest.php
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireRadialChart;
|
||||||
|
use Asantibanez\LivewireCharts\Tests\TestCase;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireRadialChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireRadialChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function should_emit_event_if_present()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
$radialChartModel = $component->radialChartModel;
|
||||||
|
|
||||||
|
data_set($radialChartModel, 'onBarClickEventName', 'custom-event');
|
||||||
|
|
||||||
|
$component->set('radialChartModel', $radialChartModel);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
$component->runAction('onBarClick', []);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$component->assertDispatched('custom-event');
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/LivewireTreeMapChartTest.php
Executable file
44
tests/LivewireTreeMapChartTest.php
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireTreeMapChart;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
class LivewireTreeMapChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireTreeMapChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function should_emit_event_if_present()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
$treeMapChartModel = $component->treeMapChartModel;
|
||||||
|
|
||||||
|
data_set($treeMapChartModel, 'onBlockClickEventName', 'custom-event');
|
||||||
|
|
||||||
|
$component->set('treeMapChartModel', $treeMapChartModel);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
$component->runAction('onBlockClick', []);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$component->assertDispatched('custom-event');
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/TestCase.php
Executable file
25
tests/TestCase.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\LivewireChartsServiceProvider;
|
||||||
|
use Livewire\LivewireServiceProvider;
|
||||||
|
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||||
|
|
||||||
|
class TestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function getPackageProviders($app)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
LivewireServiceProvider::class,
|
||||||
|
LivewireChartsServiceProvider::class
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
$app['config']->set('app.key', 'base64:Hupx3yAySikrM2/edkZQNQHslgDWYfiBfCuSThJ5SK8=');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
3
webpack.mix.js
Normal file
3
webpack.mix.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
let mix = require('laravel-mix')
|
||||||
|
|
||||||
|
mix.js('resources/js/app.js', 'public/')
|
||||||
Reference in New Issue
Block a user