Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
940109ef03 | ||
|
|
0457a9a007 | ||
|
|
2c7317c3b8 | ||
|
|
98df89eca4 | ||
|
|
de8ed5c844 | ||
|
|
81b502fd10 | ||
|
|
01176c001e | ||
|
|
8e9aed484e | ||
|
|
f5b40ec73d | ||
|
|
dbbbf8eca2 | ||
|
|
a002d2f041 | ||
|
|
e11c5ca375 | ||
|
|
0af61a2997 | ||
|
|
cb3e4180a1 | ||
|
|
1e7ac1bffb |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,5 +1,24 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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
|
## 1.3.0 - 2020-11-03
|
||||||
|
|
||||||
- Added Multi Line Chart
|
- Added Multi Line Chart
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -1,3 +1,5 @@
|
|||||||
|
[](https://github.com/asantibanez/livewire-charts/releases/)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
@@ -69,6 +71,19 @@ 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();
|
||||||
|
```
|
||||||
|
|
||||||
## Enabling Interactions
|
## Enabling Interactions
|
||||||
|
|
||||||
To enable click events, you must use the `with[XXX]ClickEvent($eventName)` method present in every model class and
|
To enable click events, you must use the `with[XXX]ClickEvent($eventName)` method present in every model class and
|
||||||
@@ -138,6 +153,9 @@ for each type of chart.
|
|||||||
| withoutDataLabels() | Disables data labels |
|
| withoutDataLabels() | Disables data labels |
|
||||||
| withLegends() | Shows legends |
|
| withLegends() | Shows legends |
|
||||||
| withoutLegends() | Hides legends |
|
| withoutLegends() | Hides legends |
|
||||||
|
| 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 |
|
||||||
|
|
||||||
#### LivewireLineChart
|
#### LivewireLineChart
|
||||||
|
|
||||||
@@ -155,6 +173,9 @@ for each type of chart.
|
|||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| setOpacity(int $opacity) | Sets columns' opacity |
|
| setOpacity(int $opacity) | Sets columns' opacity |
|
||||||
|
| 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 |
|
| 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 |
|
||||||
| 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 |
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...areaChart() }"
|
x-data="{ ...areaChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
@@ -21,6 +20,12 @@
|
|||||||
const dataLabels = component.get('areaChartModel.dataLabels') || {};
|
const dataLabels = component.get('areaChartModel.dataLabels') || {};
|
||||||
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
||||||
const data = component.get('areaChartModel.data');
|
const data = component.get('areaChartModel.data');
|
||||||
|
const sparkline = component.get('areaChartModel.sparkline');
|
||||||
|
|
||||||
|
const categories = component.get('areaChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('areaChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
series: [{
|
series: [{
|
||||||
@@ -31,13 +36,13 @@
|
|||||||
type: 'area',
|
type: 'area',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
|
|
||||||
|
...sparkline,
|
||||||
|
|
||||||
zoom: { enabled: false },
|
zoom: { enabled: false },
|
||||||
|
|
||||||
toolbar: { show: false },
|
toolbar: { show: false },
|
||||||
|
|
||||||
animations: {
|
animations: { enabled: animated },
|
||||||
enabled: animated,
|
|
||||||
},
|
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
@@ -66,7 +71,10 @@
|
|||||||
|
|
||||||
labels: data.map(item => item.title),
|
labels: data.map(item => item.title),
|
||||||
|
|
||||||
xaxis: component.get('areaChartModel.xAxis') || {},
|
xaxis: {
|
||||||
|
labels: component.get('areaChartModel.xAxis.labels'),
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
yaxis: component.get('areaChartModel.yAxis') || {},
|
yaxis: component.get('areaChartModel.yAxis') || {},
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...columnChart() }"
|
x-data="{ ...columnChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
x-on:draw-column-chart.window="drawChart(@this)"
|
|
||||||
>
|
>
|
||||||
<div wire:ignore x-ref="container"></div>
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
@@ -20,6 +19,7 @@
|
|||||||
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 data = component.get('columnChartModel.data');
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: [{ data: data.map(item => item.value)}],
|
series: [{ data: data.map(item => item.value)}],
|
||||||
@@ -28,13 +28,11 @@
|
|||||||
type: 'bar',
|
type: 'bar',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
|
|
||||||
toolbar: {
|
...sparkline,
|
||||||
show: false
|
|
||||||
},
|
|
||||||
|
|
||||||
animations: {
|
toolbar: { show: false },
|
||||||
enabled: animated,
|
|
||||||
},
|
animations: { enabled: animated },
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...lineChart() }"
|
x-data="{ ...lineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
>
|
>
|
||||||
@@ -20,13 +20,16 @@
|
|||||||
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
const data = component.get('lineChartModel.data');
|
const data = component.get('lineChartModel.data');
|
||||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
|
||||||
const series = [{
|
const series = [{
|
||||||
name: title,
|
name: title,
|
||||||
data: data.map(item => item.value),
|
data: data.map(item => item.value),
|
||||||
}]
|
}]
|
||||||
|
|
||||||
const categories = data.map(item => item.title)
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data.map(item => item.title)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: series,
|
series: series,
|
||||||
@@ -34,15 +37,15 @@
|
|||||||
chart: {
|
chart: {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
zoom: {
|
|
||||||
enabled: false
|
...sparkline,
|
||||||
},
|
|
||||||
toolbar: {
|
zoom: { enabled: false },
|
||||||
show: false
|
|
||||||
},
|
toolbar: { show: false },
|
||||||
animations: {
|
|
||||||
enabled: animated,
|
animations: { enabled: animated },
|
||||||
},
|
|
||||||
events: {
|
events: {
|
||||||
markerClick: function(event, chartContext, { dataPointIndex }) {
|
markerClick: function(event, chartContext, { dataPointIndex }) {
|
||||||
if (!onPointClickEventName) {
|
if (!onPointClickEventName) {
|
||||||
@@ -65,7 +68,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
xaxis: {
|
xaxis: {
|
||||||
...component.get('lineChartModel.xAxis') || {},
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
categories: categories,
|
categories: categories,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
95
resources/views/livewire-multi-column-chart.blade.php
Normal file
95
resources/views/livewire-multi-column-chart.blade.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<div
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
x-data="{ ...multiColumnChart() }"
|
||||||
|
x-init="drawChart(@this)"
|
||||||
|
>
|
||||||
|
<div wire:ignore x-ref="container"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function multiColumnChart() {
|
||||||
|
return {
|
||||||
|
chart: null,
|
||||||
|
|
||||||
|
drawChart(component) {
|
||||||
|
if (this.chart) {
|
||||||
|
this.chart.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
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 data = component.get('columnChartModel.data');
|
||||||
|
const sparkline = component.get('columnChartModel.sparkline');
|
||||||
|
|
||||||
|
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: component.get('columnChartModel.legend'),
|
||||||
|
|
||||||
|
plotOptions: {
|
||||||
|
bar: {
|
||||||
|
horizontal: false,
|
||||||
|
columnWidth: '50%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
dataLabels: dataLabels,
|
||||||
|
|
||||||
|
xaxis: {
|
||||||
|
categories: categories,
|
||||||
|
},
|
||||||
|
|
||||||
|
yaxis: {
|
||||||
|
title: {
|
||||||
|
text: component.get('columnChartModel.title'),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fill: {
|
||||||
|
opacity: component.get('columnChartModel.opacity'),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chart = new ApexCharts(this.$refs.container, options);
|
||||||
|
this.chart.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...multiLineChart() }"
|
x-data="{ ...multiLineChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
>
|
>
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
const dataLabels = component.get('lineChartModel.dataLabels') || {};
|
||||||
const data = component.get('lineChartModel.data');
|
const data = component.get('lineChartModel.data');
|
||||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||||
|
const sparkline = component.get('lineChartModel.sparkline');
|
||||||
|
|
||||||
const series = Object.keys(data).map(key => {
|
const series = Object.keys(data).map(key => {
|
||||||
return {
|
return {
|
||||||
@@ -28,7 +29,9 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const categories = []
|
const categories = component.get('lineChartModel.xAxis.categories').length > 0
|
||||||
|
? component.get('lineChartModel.xAxis.categories')
|
||||||
|
: data[series[0].name].map(item => item.title)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
series: series,
|
series: series,
|
||||||
@@ -36,23 +39,22 @@
|
|||||||
chart: {
|
chart: {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
zoom: {
|
|
||||||
enabled: false
|
...sparkline,
|
||||||
},
|
|
||||||
toolbar: {
|
zoom: { enabled: false },
|
||||||
show: false
|
|
||||||
},
|
toolbar: { show: false },
|
||||||
animations: {
|
|
||||||
enabled: animated,
|
animations: { enabled: animated },
|
||||||
},
|
|
||||||
events: {
|
events: {
|
||||||
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
markerClick: function(event, chartContext, { seriesIndex, dataPointIndex }) {
|
||||||
if (!onPointClickEventName) {
|
if (!onPointClickEventName) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const seriesName = Object.keys(data)[Object.keys(data).findIndex((el, index) => index === seriesIndex)]
|
const point = data[series[seriesIndex].name][dataPointIndex]
|
||||||
const point = data[seriesName][dataPointIndex]
|
|
||||||
component.call('onPointClick', point)
|
component.call('onPointClick', point)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +70,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
xaxis: {
|
xaxis: {
|
||||||
...component.get('lineChartModel.xAxis') || {},
|
labels: component.get('lineChartModel.xAxis.labels'),
|
||||||
categories: categories,
|
categories: categories,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
class="w-full h-full"
|
style="width: 100%; height: 100%;"
|
||||||
x-data="{ ...pieChart() }"
|
x-data="{ ...pieChart() }"
|
||||||
x-init="drawChart(@this)"
|
x-init="drawChart(@this)"
|
||||||
>
|
>
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
const dataLabels = component.get('pieChartModel.dataLabels') || {}
|
const dataLabels = component.get('pieChartModel.dataLabels') || {}
|
||||||
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 options = {
|
const options = {
|
||||||
series: data.map(item => item.value),
|
series: data.map(item => item.value),
|
||||||
@@ -28,9 +29,9 @@
|
|||||||
height: '100%',
|
height: '100%',
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
|
|
||||||
animations: {
|
...sparkline,
|
||||||
enabled: animated,
|
|
||||||
},
|
animations: { enabled: animated },
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
dataPointSelection: function(event, chartContext, config) {
|
dataPointSelection: function(event, chartContext, config) {
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ class LivewireColumnChart extends Component
|
|||||||
|
|
||||||
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/Facades/LivewireCharts.php
Normal file
27
src/Facades/LivewireCharts.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?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 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()
|
||||||
|
*/
|
||||||
|
class LivewireCharts extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'livewirecharts';
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/LivewireCharts.php
Normal file
47
src/LivewireCharts.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts;
|
||||||
|
|
||||||
|
|
||||||
|
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||||
|
use Asantibanez\LivewireCharts\Models\PieChartModel;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,6 @@ class LivewireChartsServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
//
|
$this->app->bind('livewirecharts', LivewireCharts::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class BaseChartModel
|
|||||||
use HasStroke;
|
use HasStroke;
|
||||||
use HasLegend;
|
use HasLegend;
|
||||||
use HasDataLabels;
|
use HasDataLabels;
|
||||||
|
use HasSparkline;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -24,6 +25,7 @@ class BaseChartModel
|
|||||||
$this->initStroke();
|
$this->initStroke();
|
||||||
$this->initLegend();
|
$this->initLegend();
|
||||||
$this->initDataLabels();
|
$this->initDataLabels();
|
||||||
|
$this->initSparkline();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reactiveKey()
|
public function reactiveKey()
|
||||||
@@ -39,7 +41,8 @@ class BaseChartModel
|
|||||||
$this->axisToArray(),
|
$this->axisToArray(),
|
||||||
$this->strokeToArray(),
|
$this->strokeToArray(),
|
||||||
$this->legendToArray(),
|
$this->legendToArray(),
|
||||||
$this->dataLabelsToArray()
|
$this->dataLabelsToArray(),
|
||||||
|
$this->sparklineToArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,5 +54,6 @@ class BaseChartModel
|
|||||||
$this->strokeFromArray($array);
|
$this->strokeFromArray($array);
|
||||||
$this->legendFromArray($array);
|
$this->legendFromArray($array);
|
||||||
$this->dataLabelsFromArray($array);
|
$this->dataLabelsFromArray($array);
|
||||||
|
$this->sparklineFromArray($array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,17 @@ namespace Asantibanez\LivewireCharts\Models;
|
|||||||
/**
|
/**
|
||||||
* Class ColumnChartModel
|
* Class ColumnChartModel
|
||||||
* @package Asantibanez\LivewireCharts\Models
|
* @package Asantibanez\LivewireCharts\Models
|
||||||
|
* @property boolean $isMultiColumn
|
||||||
|
* @property boolean $isStacked
|
||||||
*/
|
*/
|
||||||
class ColumnChartModel extends BaseChartModel
|
class ColumnChartModel extends BaseChartModel
|
||||||
{
|
{
|
||||||
public $opacity;
|
public $opacity;
|
||||||
|
|
||||||
|
public $isMultiColumn;
|
||||||
|
|
||||||
|
public $isStacked;
|
||||||
|
|
||||||
public $onColumnClickEventName;
|
public $onColumnClickEventName;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
@@ -23,9 +29,34 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->opacity = 0.5;
|
$this->opacity = 0.5;
|
||||||
|
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
$this->isStacked = false;
|
||||||
|
|
||||||
$this->data = collect();
|
$this->data = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function multiColumn()
|
||||||
|
{
|
||||||
|
$this->isMultiColumn = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function singleColumn()
|
||||||
|
{
|
||||||
|
$this->isMultiColumn = false;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stacked()
|
||||||
|
{
|
||||||
|
$this->isStacked = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setOpacity($opacity)
|
public function setOpacity($opacity)
|
||||||
{
|
{
|
||||||
$this->opacity = $opacity;
|
$this->opacity = $opacity;
|
||||||
@@ -52,11 +83,29 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
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 array_merge(parent::toArray(), [
|
return array_merge(parent::toArray(), [
|
||||||
'onColumnClickEventName' => $this->onColumnClickEventName,
|
'onColumnClickEventName' => $this->onColumnClickEventName,
|
||||||
'opacity' => $this->opacity,
|
'opacity' => $this->opacity,
|
||||||
|
'isMultiColumn' => $this->isMultiColumn,
|
||||||
|
'isStacked' => $this->isStacked,
|
||||||
'data' => $this->data->toArray(),
|
'data' => $this->data->toArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -69,6 +118,10 @@ class ColumnChartModel extends BaseChartModel
|
|||||||
|
|
||||||
$this->opacity = data_get($array, 'opacity', 0.5);
|
$this->opacity = data_get($array, 'opacity', 0.5);
|
||||||
|
|
||||||
|
$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', []));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait HasAxis
|
|||||||
|
|
||||||
private $yAxis;
|
private $yAxis;
|
||||||
|
|
||||||
public function initAxis()
|
protected function initAxis()
|
||||||
{
|
{
|
||||||
$this->xAxis = $this->defaultXAxis();
|
$this->xAxis = $this->defaultXAxis();
|
||||||
$this->yAxis = $this->defaultYAxis();
|
$this->yAxis = $this->defaultYAxis();
|
||||||
@@ -19,6 +19,7 @@ trait HasAxis
|
|||||||
private function defaultXAxis()
|
private function defaultXAxis()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'categories' => [],
|
||||||
'labels' => [
|
'labels' => [
|
||||||
'show' => true,
|
'show' => true,
|
||||||
],
|
],
|
||||||
@@ -39,6 +40,13 @@ trait HasAxis
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setXAxisCategories($categories = [])
|
||||||
|
{
|
||||||
|
data_set($this->xAxis, 'categories', $categories);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setYAxisVisible($visible)
|
public function setYAxisVisible($visible)
|
||||||
{
|
{
|
||||||
data_set($this->yAxis, 'show', $visible);
|
data_set($this->yAxis, 'show', $visible);
|
||||||
|
|||||||
48
src/Models/HasSparkline.php
Normal file
48
src/Models/HasSparkline.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Asantibanez\LivewireCharts\Models;
|
||||||
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user