Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
343ebbaeee | ||
|
|
79f61f15f6 | ||
|
|
af540f428c | ||
|
|
e2f9c814e2 | ||
|
|
b04c338283 | ||
|
|
98ffca8cf3 | ||
|
|
d31ed188a9 | ||
|
|
08d60e1ffa | ||
|
|
fc0c122926 | ||
|
|
d58465084e | ||
|
|
5a222abdbf | ||
|
|
af44417115 | ||
|
|
4c70acd41c | ||
|
|
ca044277ee | ||
|
|
badbd7d872 |
8
.github/workflows/phpunit.yml
vendored
8
.github/workflows/phpunit.yml
vendored
@@ -15,15 +15,15 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
php-version: '8.3'
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, exif, imagick, bcmath
|
||||
coverage: none
|
||||
coverage: xdebug
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Composer dependencies
|
||||
run: composer install --ignore-platform-reqs
|
||||
run: composer install
|
||||
|
||||
- name: Run tests
|
||||
run: ./vendor/bin/phpunit
|
||||
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text
|
||||
|
||||
1
.phpunit.cache/test-results
Normal file
1
.phpunit.cache/test-results
Normal file
@@ -0,0 +1 @@
|
||||
{"version":1,"defects":{"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::can_build_component":7},"times":{"Asantibanez\\LivewireCharts\\Tests\\LivewireAreaChartTest::can_build_component":0.026,"Asantibanez\\LivewireCharts\\Tests\\LivewireColumnChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewireColumnChartTest::should_emit_event_if_present":0.01,"Asantibanez\\LivewireCharts\\Tests\\LivewireLineChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::can_build_component":0.025,"Asantibanez\\LivewireCharts\\Tests\\LivewirePieChartTest::should_emit_event_if_present":0.011,"Asantibanez\\LivewireCharts\\Tests\\LivewireRadarChartTest::can_build_component":0.003,"Asantibanez\\LivewireCharts\\Tests\\LivewireTreeMapChartTest::can_build_component":0.004,"Asantibanez\\LivewireCharts\\Tests\\LivewireTreeMapChartTest::should_emit_event_if_present":0.008}}
|
||||
58
README.md
58
README.md
@@ -82,7 +82,7 @@ With `$columnChartModel` at hand, we pass it to our `LivewireColumnChart` compon
|
||||
Next, include the `@livewireChartsScripts` directive next to your other app scripts
|
||||
|
||||
```html
|
||||
<livewire:scripts />
|
||||
@livewireScripts
|
||||
@livewireChartsScripts
|
||||
```
|
||||
|
||||
@@ -170,20 +170,21 @@ for each type of chart.
|
||||
|
||||
### All
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| setTitle(string $title) | Sets chart title |
|
||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
||||
| setDataLabelsEnabled(boolean $enabled) | Enables/disables data labels |
|
||||
| withDataLabels() | Enables data labels |
|
||||
| withoutDataLabels() | Disables data labels |
|
||||
| withLegend() | Shows legends |
|
||||
| withoutLegend() | Hides legends |
|
||||
| setColors(array $colors) | Set colors for chart |
|
||||
| addColors(string $color) | Append $color to $colors set |
|
||||
| setXAxisCategories(array $categories) | Enables custom categories for chart X Axis |
|
||||
| sparklined() | Enables Apex Charts sparkline feature |
|
||||
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
||||
| Method | Description |
|
||||
|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| setTitle(string $title) | Sets chart title |
|
||||
| setAnimated(boolean $animated) | Enables/disables animation |
|
||||
| setDataLabelsEnabled(boolean $enabled) | Enables/disables data labels |
|
||||
| withDataLabels() | Enables data labels |
|
||||
| withoutDataLabels() | Disables data labels |
|
||||
| withLegend() | Shows legends |
|
||||
| withoutLegend() | Hides legends |
|
||||
| setColors(array $colors) | Set colors for chart |
|
||||
| addColors(string $color) | Append $color to $colors set |
|
||||
| setXAxisCategories(array $categories) | Enables custom categories for chart X Axis |
|
||||
| sparklined() | Enables Apex Charts sparkline feature |
|
||||
| setSparklineEnabled(boolean $isEnabled) | Enables/Disables Apex Charts sparkline feature |
|
||||
| setJsonConfig(array $config) | Adds extra customization to charts by passing Apex charts properties keys and values. Nested keys must be added using dot (.) notation |
|
||||
|
||||
### LivewireLineChart
|
||||
|
||||
@@ -209,7 +210,7 @@ for each type of chart.
|
||||
| stacked() | Sets chart to display column series stacked |
|
||||
| addColumn(string $title, double $value, string $color, array $extras = []) | Adds a column to the chart with the specified color. `$extras` is forwarded on click event |
|
||||
| addSeriesColumn(string $seriesName, string $title, double $value, array $extras = []) | Adds a column to a multicolumn chart. `$extras` is forwarded on click event |
|
||||
| onColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||
| withOnColumnClickEventName(string $eventName) | Event Name that will be fired when a column of the chart is clicked |
|
||||
|
||||
### LivewirePieChart
|
||||
|
||||
@@ -256,6 +257,31 @@ inside your resources folder. You can then adjust imports as you see fit in your
|
||||
|
||||
>Note: You must remove @livewireChartsScripts directive so it doesn't clash with the scripts in your build system.
|
||||
|
||||
|
||||
## Advanced Usage - Custom Json Configs
|
||||
|
||||
The `setJsonConfig()` method on every chart allows adding custom Apex properties not provided first hand by the package.
|
||||
This means that any chart property supported by Apex chart can be passed down using this method.
|
||||
|
||||
```php
|
||||
$chart->setJsonConfig([
|
||||
'plotOptions.pie.startAngle' => -90,
|
||||
'plotOptions.pie.endAngle' => 90,
|
||||
'plotOptions.pie.offsetY' => 10,
|
||||
'grid.padding.bottom' => -180,
|
||||
]);
|
||||
```
|
||||
|
||||
>Note: If you want to add nested properties, you can use dot (.) notation for this matter.
|
||||
|
||||
You can even pass down simple JS functions. For example, for formatting you can pass down your own closure
|
||||
|
||||
```php
|
||||
$chart->setJsonConfig([
|
||||
'tooltip.y.formatter' => '(val) => `$${val} million dollars baby!`'
|
||||
])
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Chart components must be placed inside a container with fixed height. This is because the chart will use all the given
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2|^7.3|^7.4|^8.0",
|
||||
"illuminate/support": "^7.0|^8.0|^9.0|^10.0",
|
||||
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0",
|
||||
"livewire/livewire": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0",
|
||||
"phpunit/phpunit": "^8.0|^9.5.10"
|
||||
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0|^9.0",
|
||||
"phpunit/phpunit": "^8.0|^9.5.10|^10.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<phpunit
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
backupStaticProperties="false"
|
||||
>
|
||||
<coverage>
|
||||
<report>
|
||||
<clover outputFile="build/logs/clover.xml"/>
|
||||
<html outputDirectory="build/coverage"/>
|
||||
<text outputFile="build/coverage.txt"/>
|
||||
</report>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="tap" target="build/report.tap"/>
|
||||
<log type="junit" target="build/report.junit.xml"/>
|
||||
<log type="coverage-html" target="build/coverage"/>
|
||||
<log type="coverage-text" target="build/coverage.txt"/>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
<junit outputFile="build/report.junit.xml"/>
|
||||
</logging>
|
||||
<source>
|
||||
<include>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const areaChart = () => {
|
||||
return {
|
||||
@@ -20,6 +21,7 @@ const areaChart = () => {
|
||||
const onPointClickEventName = component.get('areaChartModel.onPointClickEventName')
|
||||
const data = component.get('areaChartModel.data');
|
||||
const sparkline = component.get('areaChartModel.sparkline');
|
||||
const jsonConfig = component.get('areaChartModel.jsonConfig');
|
||||
|
||||
const categories = component.get('areaChartModel.xAxis.categories').length > 0
|
||||
? component.get('areaChartModel.xAxis.categories')
|
||||
@@ -88,7 +90,7 @@ const areaChart = () => {
|
||||
|
||||
};
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const lineChart = () => {
|
||||
return {
|
||||
@@ -20,6 +21,7 @@ const lineChart = () => {
|
||||
const data = component.get('lineChartModel.data');
|
||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||
const sparkline = component.get('lineChartModel.sparkline');
|
||||
const jsonConfig = component.get('lineChartModel.jsonConfig');
|
||||
|
||||
const series = [{
|
||||
name: title,
|
||||
@@ -108,7 +110,7 @@ const lineChart = () => {
|
||||
},
|
||||
};
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const multiColumnChart = () => {
|
||||
return {
|
||||
@@ -24,6 +25,7 @@ const multiColumnChart = () => {
|
||||
const grid = component.get('columnChartModel.grid');
|
||||
const columnWidth = component.get('columnChartModel.columnWidth');
|
||||
const horizontal = component.get('columnChartModel.horizontal');
|
||||
const jsonConfig = component.get('columnChartModel.jsonConfig');
|
||||
|
||||
const data = component.get('columnChartModel.data');
|
||||
const series = Object.keys(data)
|
||||
@@ -100,7 +102,7 @@ const multiColumnChart = () => {
|
||||
options['colors'] = colors
|
||||
}
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const multiLineChart = () => {
|
||||
return {
|
||||
@@ -20,6 +21,7 @@ const multiLineChart = () => {
|
||||
const data = component.get('lineChartModel.data');
|
||||
const onPointClickEventName = component.get('lineChartModel.onPointClickEventName');
|
||||
const sparkline = component.get('lineChartModel.sparkline');
|
||||
const jsonConfig = component.get('lineChartModel.jsonConfig');
|
||||
|
||||
const series = Object.keys(data).map(key => {
|
||||
return {
|
||||
@@ -84,7 +86,7 @@ const multiLineChart = () => {
|
||||
options['colors'] = colors
|
||||
}
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const radarChart = () => {
|
||||
return {
|
||||
@@ -21,6 +22,7 @@ const radarChart = () => {
|
||||
const data = component.get('radarChartModel.data');
|
||||
const sparkline = component.get('radarChartModel.sparkline');
|
||||
const colors = component.get('radarChartModel.colors');
|
||||
const jsonConfig = component.get('radarChartModel.jsonConfig');
|
||||
|
||||
const series = Object.keys(data)
|
||||
.map(seriesName => ({
|
||||
@@ -88,7 +90,7 @@ const radarChart = () => {
|
||||
|
||||
};
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const treeMapChart = () => {
|
||||
return {
|
||||
@@ -21,6 +22,7 @@ const treeMapChart = () => {
|
||||
const data = component.get('treeMapChartModel.data');
|
||||
const colors = component.get('treeMapChartModel.colors');
|
||||
const enableShades = component.get('treeMapChartModel.enableShades');
|
||||
const jsonConfig = component.get('treeMapChartModel.jsonConfig');
|
||||
|
||||
const series = Object.keys(data)
|
||||
.map(seriesName => ({
|
||||
@@ -69,7 +71,7 @@ const treeMapChart = () => {
|
||||
colors: colors,
|
||||
};
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class LivewireAreaChart extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emit($onPointClickEventName, $point);
|
||||
$this->dispatch($onPointClickEventName, $point);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -26,7 +26,7 @@ class LivewireLineChart extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emit($onPointClickEventName, $point);
|
||||
$this->dispatch($onPointClickEventName, $point);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -26,7 +26,7 @@ class LivewireRadarChart extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$this->emit($onPointClickEventName, $point);
|
||||
$this->dispatch($onPointClickEventName, $point);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
Reference in New Issue
Block a user