Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66ce742311 | ||
|
|
cd56963f6e | ||
|
|
ce43d0b97c | ||
|
|
072a98da5c | ||
|
|
27198d12b8 | ||
|
|
8bfdaa1763 | ||
|
|
aa94016b6e | ||
|
|
4a74606e4d | ||
|
|
52abe77e7e | ||
|
|
202591954d | ||
|
|
9e4d8ddf40 | ||
|
|
3e57a722b4 | ||
|
|
0c72c83dda | ||
|
|
327665919f | ||
|
|
879734fe9c | ||
|
|
6754e94cde | ||
|
|
9802ec2bcd | ||
|
|
821ac7a454 | ||
|
|
a7364ad51c | ||
|
|
47d0f028af | ||
|
|
582ad340dd | ||
|
|
35d8a80bb4 | ||
|
|
665a3370b2 | ||
|
|
84527ff809 | ||
|
|
cefb5089e8 | ||
|
|
bf644a5931 | ||
|
|
3abe96bdb0 | ||
|
|
171a333044 | ||
|
|
372d6ffcb0 | ||
|
|
0de38b041b | ||
|
|
b649aaef23 | ||
|
|
75f46fc1cf | ||
|
|
11272bd21b | ||
|
|
1e1075ba07 | ||
|
|
1bfa52ca83 | ||
|
|
3add4a148e | ||
|
|
27606ff1e9 | ||
|
|
230b706c63 | ||
|
|
8b0bb9c250 | ||
|
|
c61ca90905 |
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.0'
|
||||||
|
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, exif, imagick, bcmath
|
||||||
|
coverage: none
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install Composer dependencies
|
||||||
|
run: composer install --ignore-platform-reqs
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: ./vendor/bin/phpunit
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ vendor
|
|||||||
coverage
|
coverage
|
||||||
.DS_STORE
|
.DS_STORE
|
||||||
node_modules
|
node_modules
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
29
CHANGELOG.md
29
CHANGELOG.md
@@ -1,5 +1,34 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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
|
## 1.5.2 - 2020-11-09
|
||||||
|
|
||||||
- Fixed infinite growing charts
|
- Fixed infinite growing charts
|
||||||
|
|||||||
47
README.md
47
README.md
@@ -5,6 +5,7 @@
|
|||||||
## Preview
|
## Preview
|
||||||
|
|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
@@ -20,7 +21,13 @@ composer require asantibanez/livewire-charts
|
|||||||
|
|
||||||
Next, you must export the package public scripts. To do this run `php artisan vendor:publish`
|
Next, you must export the package public scripts. To do this run `php artisan vendor:publish`
|
||||||
and export `livewire-charts:public`. This command will export a `vendor/livewire-charts` folder under the
|
and export `livewire-charts:public`. This command will export a `vendor/livewire-charts` folder under the
|
||||||
`public` directory of your app.
|
`public` directory of your app.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php artisan vendor:publish --tag=livewire-charts:public
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note: This last step can also be done using `livewire-charts:install` command in the artisan console.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@@ -40,12 +47,16 @@ Livewire Charts supports out of the box the following types of charts
|
|||||||
- Pie Chart (`LivewirePieChart` component)
|
- Pie Chart (`LivewirePieChart` component)
|
||||||
- Column/Multi Line 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)
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
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
|
||||||
@@ -93,6 +104,8 @@ LivewireCharts::columnChartModel();
|
|||||||
LivewireCharts::multiColumnChartModel();
|
LivewireCharts::multiColumnChartModel();
|
||||||
LivewireCharts::pieChartModel();
|
LivewireCharts::pieChartModel();
|
||||||
LivewireCharts::areaChartModel();
|
LivewireCharts::areaChartModel();
|
||||||
|
LivewireCharts::radarChartModel();
|
||||||
|
LivewireCharts::treeMapChartModel();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Enabling Interactions
|
## Enabling Interactions
|
||||||
@@ -153,7 +166,7 @@ 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.
|
||||||
|
|
||||||
#### All
|
### All
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
@@ -164,11 +177,13 @@ for each type of chart.
|
|||||||
| withoutDataLabels() | Disables data labels |
|
| withoutDataLabels() | Disables data labels |
|
||||||
| withLegend() | Shows legends |
|
| withLegend() | Shows legends |
|
||||||
| withoutLegend() | Hides 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 |
|
| setXAxisCategories(array $categories) | Enables custom categories for chart X Axis |
|
||||||
| sparklined() | Enables Apex Charts sparkline feature |
|
| sparklined() | Enables Apex Charts sparkline feature |
|
||||||
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
||||||
|
|
||||||
#### LivewireLineChart
|
### LivewireLineChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
@@ -179,18 +194,21 @@ for each type of chart.
|
|||||||
| 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) |
|
| 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 |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setOpacity(int $opacity) | Sets columns' opacity |
|
| setOpacity(int $opacity) | Sets columns' opacity |
|
||||||
|
| setColumnWidth(int $columnWidth) | Sets columns' width |
|
||||||
|
| setHorizontal(boolean $value) | Sets columns or bars |
|
||||||
| multiColumn() | Sets chart to display multiple column series |
|
| multiColumn() | Sets chart to display multiple column series |
|
||||||
| singleColumn() | Sets chart to display a single column series |
|
| singleColumn() | Sets chart to display a single column series |
|
||||||
| stacked() | Sets chart to display column series stacked |
|
| 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 |
|
| 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 |
|
||||||
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||||
|
|
||||||
#### LivewirePieChart
|
### LivewirePieChart
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
@@ -198,7 +216,7 @@ for each type of chart.
|
|||||||
| 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 |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
@@ -207,6 +225,23 @@ for each type of chart.
|
|||||||
| 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 |
|
||||||
|
|
||||||
|
|
||||||
## Advanced Usage - Integrating Scripts
|
## Advanced Usage - Integrating Scripts
|
||||||
|
|
||||||
The directive `@livewireChartsScripts` adds a `script` tag that includes `public/vendor/livewire-charts/app.js`.
|
The directive `@livewireChartsScripts` adds a `script` tag that includes `public/vendor/livewire-charts/app.js`.
|
||||||
|
|||||||
@@ -16,12 +16,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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",
|
||||||
"livewire/livewire": "^2.3"
|
"livewire/livewire": "^2.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"orchestra/testbench": "^4.0|^5.0",
|
"orchestra/testbench": "^5.0|^6.0|^7.0",
|
||||||
"phpunit/phpunit": "^8.0"
|
"phpunit/phpunit": "^8.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
12136
package-lock.json
generated
12136
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,7 @@
|
|||||||
<logging>
|
<logging>
|
||||||
<log type="tap" target="build/report.tap"/>
|
<log type="tap" target="build/report.tap"/>
|
||||||
<log type="junit" target="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-html" target="build/coverage"/>
|
||||||
<log type="coverage-text" target="build/coverage.txt"/>
|
<log type="coverage-text" target="build/coverage.txt"/>
|
||||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||||
</logging>
|
</logging>
|
||||||
|
|||||||
BIN
preview_radarchart.gif
Normal file
BIN
preview_radarchart.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
File diff suppressed because one or more lines are too long
@@ -5,6 +5,8 @@ import multiColumnChart from "./multiColumnChart";
|
|||||||
import lineChart from "./lineChart"
|
import lineChart from "./lineChart"
|
||||||
import multiLineChart from "./multiLineChart"
|
import multiLineChart from "./multiLineChart"
|
||||||
import pieChart from "./pieChart"
|
import pieChart from "./pieChart"
|
||||||
|
import radarChart from "./radarChart"
|
||||||
|
import treeMapChart from "./treeMapChart"
|
||||||
|
|
||||||
window.ApexCharts = ApexCharts
|
window.ApexCharts = ApexCharts
|
||||||
window.livewireChartsAreaChart = areaChart
|
window.livewireChartsAreaChart = areaChart
|
||||||
@@ -13,3 +15,5 @@ window.livewireChartsLineChart = lineChart
|
|||||||
window.livewireChartsMultiLineChart = multiLineChart
|
window.livewireChartsMultiLineChart = multiLineChart
|
||||||
window.livewireChartsPieChart = pieChart
|
window.livewireChartsPieChart = pieChart
|
||||||
window.livewireChartsMultiColumnChart = multiColumnChart
|
window.livewireChartsMultiColumnChart = multiColumnChart
|
||||||
|
window.livewireChartsRadarChart = radarChart
|
||||||
|
window.livewireChartsTreeMapChart = treeMapChart
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ const areaChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
@@ -53,9 +59,7 @@ const areaChart = () => {
|
|||||||
|
|
||||||
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
colors: [component.get('areaChartModel.color') || '#2E93fA'],
|
||||||
|
|
||||||
stroke: {
|
stroke: component.get('areaChartModel.stroke') || {},
|
||||||
curve: 'straight'
|
|
||||||
},
|
|
||||||
|
|
||||||
title: {
|
title: {
|
||||||
text: title,
|
text: title,
|
||||||
|
|||||||
@@ -3,19 +3,35 @@ const columnChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const title = component.get('columnChartModel.title');
|
||||||
const animated = component.get('columnChartModel.animated') || false;
|
const animated = component.get('columnChartModel.animated') || false;
|
||||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
const dataLabels = component.get('columnChartModel.dataLabels') || {};
|
const dataLabels = component.get('columnChartModel.dataLabels') || {};
|
||||||
const data = component.get('columnChartModel.data');
|
|
||||||
const sparkline = component.get('columnChartModel.sparkline');
|
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 data = component.get('columnChartModel.data');
|
||||||
|
const series = [{
|
||||||
|
name: title,
|
||||||
|
data: data.map(item => item.value)
|
||||||
|
}]
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: [{ data: data.map(item => item.value)}],
|
series: series,
|
||||||
|
|
||||||
chart: {
|
chart: {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
@@ -48,12 +64,14 @@ const columnChart = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
legend: component.get('columnChartModel.legend') || {},
|
legend: legend,
|
||||||
|
|
||||||
|
grid: grid,
|
||||||
|
|
||||||
plotOptions: {
|
plotOptions: {
|
||||||
bar: {
|
bar: {
|
||||||
horizontal: false,
|
horizontal: horizontal,
|
||||||
columnWidth: '40%',
|
columnWidth: `${columnWidth}%`,
|
||||||
distributed: true,
|
distributed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -75,6 +93,12 @@ const columnChart = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const colors = component.get('columnChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ const lineChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
|
|||||||
@@ -3,18 +3,29 @@ const multiColumnChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const title = component.get('columnChartModel.title')
|
||||||
const stacked = component.get('columnChartModel.isStacked');
|
const stacked = component.get('columnChartModel.isStacked');
|
||||||
const animated = component.get('columnChartModel.animated');
|
const animated = component.get('columnChartModel.animated');
|
||||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||||
const dataLabels = component.get('columnChartModel.dataLabels');
|
const dataLabels = component.get('columnChartModel.dataLabels');
|
||||||
const data = component.get('columnChartModel.data');
|
|
||||||
const sparkline = component.get('columnChartModel.sparkline');
|
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 data = component.get('columnChartModel.data');
|
||||||
const series = Object.keys(data)
|
const series = Object.keys(data)
|
||||||
.map(seriesName => ({
|
.map(seriesName => ({
|
||||||
name: seriesName,
|
name: seriesName,
|
||||||
@@ -52,12 +63,14 @@ const multiColumnChart = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
legend: component.get('columnChartModel.legend'),
|
legend: legend,
|
||||||
|
|
||||||
|
grid: grid,
|
||||||
|
|
||||||
plotOptions: {
|
plotOptions: {
|
||||||
bar: {
|
bar: {
|
||||||
horizontal: false,
|
horizontal: horizontal,
|
||||||
columnWidth: '50%',
|
columnWidth: `${columnWidth}%`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -69,7 +82,7 @@ const multiColumnChart = () => {
|
|||||||
|
|
||||||
yaxis: {
|
yaxis: {
|
||||||
title: {
|
title: {
|
||||||
text: component.get('columnChartModel.title'),
|
text: title,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -78,6 +91,12 @@ const multiColumnChart = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const colors = component.get('columnChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ const multiLineChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
@@ -70,6 +76,12 @@ const multiLineChart = () => {
|
|||||||
yaxis: component.get('lineChartModel.yAxis') || {},
|
yaxis: component.get('lineChartModel.yAxis') || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const colors = component.get('lineChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ const pieChart = () => {
|
|||||||
return {
|
return {
|
||||||
chart: null,
|
chart: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.drawChart(this.$wire)
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
|
||||||
drawChart(component) {
|
drawChart(component) {
|
||||||
if (this.chart) {
|
if (this.chart) {
|
||||||
this.chart.destroy()
|
this.chart.destroy()
|
||||||
@@ -14,13 +20,14 @@ const pieChart = () => {
|
|||||||
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
const onSliceClickEventName = component.get('pieChartModel.onSliceClickEventName')
|
||||||
const data = component.get('pieChartModel.data')
|
const data = component.get('pieChartModel.data')
|
||||||
const sparkline = component.get('pieChartModel.sparkline')
|
const sparkline = component.get('pieChartModel.sparkline')
|
||||||
|
const type = component.get('pieChartModel.type')
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: data.map(item => item.value),
|
series: data.map(item => item.value),
|
||||||
|
|
||||||
chart: {
|
chart: {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
type: 'pie',
|
type: type,
|
||||||
|
|
||||||
...sparkline,
|
...sparkline,
|
||||||
|
|
||||||
@@ -68,6 +75,12 @@ const pieChart = () => {
|
|||||||
legend: component.get('pieChartModel.legend') || {},
|
legend: component.get('pieChartModel.legend') || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const colors = component.get('pieChartModel.colors');
|
||||||
|
|
||||||
|
if (colors && colors.length > 0) {
|
||||||
|
options['colors'] = colors
|
||||||
|
}
|
||||||
|
|
||||||
this.chart = new ApexCharts(this.$refs.container, options);
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
|
|||||||
97
resources/js/radarChart.js
Normal file
97
resources/js/radarChart.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
|
||||||
|
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 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, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default radarChart
|
||||||
78
resources/js/treeMapChart.js
Normal file
78
resources/js/treeMapChart.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
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 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.emit(onBlockClickEventName, block)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
treemap: {
|
||||||
|
distributed: distributed,
|
||||||
|
enableShades: enableShades,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
colors: colors,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default treeMapChart
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsAreaChart() }"
|
x-data="{ ...livewireChartsAreaChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsColumnChart() }"
|
x-data="{ ...livewireChartsColumnChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsLineChart() }"
|
x-data="{ ...livewireChartsLineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsMultiColumnChart() }"
|
x-data="{ ...livewireChartsMultiColumnChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsMultiLineChart() }"
|
x-data="{ ...livewireChartsMultiLineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...livewireChartsPieChart() }"
|
x-data="{ ...livewireChartsPieChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="init()"
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
</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-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>
|
||||||
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->emit($onPointClickEventName, $point);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire-charts::livewire-radar-chart');
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/Charts/LivewireTreeMapChart.php
Normal file
25
src/Charts/LivewireTreeMapChart.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?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 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
|||||||
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadarChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,6 +19,8 @@ use Illuminate\Support\Facades\Facade;
|
|||||||
* @method static ColumnChartModel multiColumnChartModel()
|
* @method static ColumnChartModel multiColumnChartModel()
|
||||||
* @method static AreaChartModel areaChartModel()
|
* @method static AreaChartModel areaChartModel()
|
||||||
* @method static PieChartModel pieChartModel()
|
* @method static PieChartModel pieChartModel()
|
||||||
|
* @method static RadarChartModel radarChartModel()
|
||||||
|
* @method static TreeMapChartModel treeMapChartModel()
|
||||||
*/
|
*/
|
||||||
class LivewireCharts extends Facade
|
class LivewireCharts extends Facade
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
|||||||
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\RadarChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
|
||||||
|
|
||||||
class LivewireCharts
|
class LivewireCharts
|
||||||
{
|
{
|
||||||
@@ -44,4 +46,14 @@ class LivewireCharts
|
|||||||
{
|
{
|
||||||
return new PieChartModel;
|
return new PieChartModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function radarChartModel()
|
||||||
|
{
|
||||||
|
return new RadarChartModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function treeMapChartModel()
|
||||||
|
{
|
||||||
|
return new TreeMapChartModel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ 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\LivewireTreeMapChart;
|
||||||
|
use Asantibanez\LivewireCharts\Console\InstallCommand;
|
||||||
use Illuminate\Support\Facades\Blade;
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
@@ -14,7 +17,9 @@ class LivewireChartsServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->registerViews();
|
$this->registerCommands();
|
||||||
|
|
||||||
|
$this->registerViews();
|
||||||
|
|
||||||
$this->registerPublishables();
|
$this->registerPublishables();
|
||||||
|
|
||||||
@@ -28,6 +33,16 @@ class LivewireChartsServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind('livewirecharts', LivewireCharts::class);
|
$this->app->bind('livewirecharts', LivewireCharts::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function registerCommands()
|
||||||
|
{
|
||||||
|
if ($this->app->runningInConsole()) {
|
||||||
|
$this->commands([
|
||||||
|
InstallCommand::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function registerViews()
|
private function registerViews()
|
||||||
{
|
{
|
||||||
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-charts');
|
||||||
@@ -56,6 +71,8 @@ class LivewireChartsServiceProvider extends ServiceProvider
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerDirectives()
|
private function registerDirectives()
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class BaseChartModel
|
|||||||
use HasLegend;
|
use HasLegend;
|
||||||
use HasDataLabels;
|
use HasDataLabels;
|
||||||
use HasSparkline;
|
use HasSparkline;
|
||||||
|
use HasGrid;
|
||||||
|
use HasColors;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -26,6 +28,8 @@ class BaseChartModel
|
|||||||
$this->initLegend();
|
$this->initLegend();
|
||||||
$this->initDataLabels();
|
$this->initDataLabels();
|
||||||
$this->initSparkline();
|
$this->initSparkline();
|
||||||
|
$this->initGrid();
|
||||||
|
$this->initColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
public function reactiveKey()
|
||||||
@@ -42,7 +46,9 @@ class BaseChartModel
|
|||||||
$this->strokeToArray(),
|
$this->strokeToArray(),
|
||||||
$this->legendToArray(),
|
$this->legendToArray(),
|
||||||
$this->dataLabelsToArray(),
|
$this->dataLabelsToArray(),
|
||||||
$this->sparklineToArray()
|
$this->sparklineToArray(),
|
||||||
|
$this->gridToArray(),
|
||||||
|
$this->colorsToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,5 +61,7 @@ class BaseChartModel
|
|||||||
$this->legendFromArray($array);
|
$this->legendFromArray($array);
|
||||||
$this->dataLabelsFromArray($array);
|
$this->dataLabelsFromArray($array);
|
||||||
$this->sparklineFromArray($array);
|
$this->sparklineFromArray($array);
|
||||||
|
$this->gridFromArray($array);
|
||||||
|
$this->colorsFromArray($array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
{
|
{
|
||||||
public $opacity;
|
public $opacity;
|
||||||
|
|
||||||
|
public $columnWidth;
|
||||||
|
|
||||||
|
public $horizontal;
|
||||||
|
|
||||||
public $isMultiColumn;
|
public $isMultiColumn;
|
||||||
|
|
||||||
public $isStacked;
|
public $isStacked;
|
||||||
@@ -27,7 +31,11 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->onColumnClickEventName = null;
|
$this->onColumnClickEventName = null;
|
||||||
|
|
||||||
$this->opacity = 0.5;
|
$this->opacity = 0.75;
|
||||||
|
|
||||||
|
$this->columnWidth = 70;
|
||||||
|
|
||||||
|
$this->horizontal = false;
|
||||||
|
|
||||||
$this->isMultiColumn = false;
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
@@ -57,6 +65,20 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setHorizontal($value)
|
||||||
|
{
|
||||||
|
$this->horizontal = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setColumnWidth($value)
|
||||||
|
{
|
||||||
|
$this->columnWidth = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setOpacity($opacity)
|
public function setOpacity($opacity)
|
||||||
{
|
{
|
||||||
$this->opacity = $opacity;
|
$this->opacity = $opacity;
|
||||||
@@ -104,6 +126,8 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'horizontal' => $this->horizontal,
|
||||||
|
'columnWidth' => $this->columnWidth,
|
||||||
'isMultiColumn' => $this->isMultiColumn,
|
'isMultiColumn' => $this->isMultiColumn,
|
||||||
'isStacked' => $this->isStacked,
|
'isStacked' => $this->isStacked,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
@@ -118,6 +142,10 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$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->isMultiColumn = data_get($array, 'isMultiColumn', false);
|
||||||
|
|
||||||
$this->isStacked = data_get($array, 'isStacked', false);
|
$this->isStacked = data_get($array, 'isStacked', false);
|
||||||
|
|||||||
67
src/Models/HasColors.php
Normal file
67
src/Models/HasColors.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/Models/HasGrid.php
Normal file
66
src/Models/HasGrid.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
trait HasStroke
|
trait HasStroke
|
||||||
{
|
{
|
||||||
private $stroke;
|
private $stroke;
|
||||||
|
private $width;
|
||||||
|
|
||||||
public function initStroke()
|
public function initStroke()
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,7 @@ trait HasStroke
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'curve' => 'straight',
|
'curve' => 'straight',
|
||||||
|
'width' => 4
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,13 @@ trait HasStroke
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStrokeWidth($width)
|
||||||
|
{
|
||||||
|
data_set($this->stroke, 'width', $width);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function strokeToArray()
|
protected function strokeToArray()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class PieChartModel extends BaseChartModel
|
|||||||
|
|
||||||
public $opacity;
|
public $opacity;
|
||||||
|
|
||||||
|
public $type;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@@ -23,6 +25,8 @@ class PieChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->opacity = 0.75;
|
$this->opacity = 0.75;
|
||||||
|
|
||||||
|
$this->type = 'pie';
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +37,13 @@ class PieChartModel extends BaseChartModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setType($type)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withOnSliceClickEvent($onSliceClickEventName)
|
public function withOnSliceClickEvent($onSliceClickEventName)
|
||||||
{
|
{
|
||||||
$this->onSliceClickEventName = $onSliceClickEventName;
|
$this->onSliceClickEventName = $onSliceClickEventName;
|
||||||
@@ -57,6 +68,7 @@ class PieChartModel extends BaseChartModel
|
|||||||
return array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'onSliceClickEventName' => $this->onSliceClickEventName,
|
'onSliceClickEventName' => $this->onSliceClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'type' => $this->type,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -69,6 +81,8 @@ class PieChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$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', []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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', []));
|
||||||
|
}
|
||||||
|
}
|
||||||
84
src/Models/TreeMapChartModel.php
Normal file
84
src/Models/TreeMapChartModel.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class TreeMapChartModel
|
||||||
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
*/
|
||||||
|
class TreeMapChartModel extends BaseChartModel
|
||||||
|
{
|
||||||
|
use HasTitle;
|
||||||
|
use HasColors;
|
||||||
|
|
||||||
|
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->title, $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\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewireAreaChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireAreaChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/LivewireColumnChartTest.php
Executable file
25
tests/LivewireColumnChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewireColumnChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireColumnChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
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\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewireLineChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireLineChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/LivewirePieChartTest.php
Executable file
25
tests/LivewirePieChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewirePieChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewirePieChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
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\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewireRadarChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireRadarChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
tests/LivewireTreeMapChartTest.php
Executable file
25
tests/LivewireTreeMapChartTest.php
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Tests;
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Charts\LivewireTreeMapChart;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Livewire\Testing\TestableLivewire;
|
||||||
|
|
||||||
|
class LivewireTreeMapChartTest extends TestCase
|
||||||
|
{
|
||||||
|
private function buildComponent() : TestableLivewire
|
||||||
|
{
|
||||||
|
return Livewire::test(LivewireTreeMapChart::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function can_build_component()
|
||||||
|
{
|
||||||
|
//Act
|
||||||
|
$component = $this->buildComponent();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
$this->assertNotNull($component);
|
||||||
|
}
|
||||||
|
}
|
||||||
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=');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user