19 Commits

Author SHA1 Message Date
asantibanez
35324eace3 Added Radial chart 2024-08-22 14:42:07 -05:00
asantibanez
c30c408fe2 Fixed property access 2024-08-22 13:04:12 -05:00
asantibanez
b182546766 Removed duplicate traits 2024-08-22 12:56:22 -05:00
asantibanez
3014bb1ab3 Namespaced traits 2024-08-22 12:56:14 -05:00
asantibanez
343ebbaeee Improved README 2024-08-22 10:41:44 -05:00
asantibanez
79f61f15f6 Fixed CI 2024-08-22 10:19:16 -05:00
asantibanez
af540f428c Fixed CI 2024-08-22 10:15:17 -05:00
asantibanez
e2f9c814e2 Fixed CI 2024-08-22 10:10:15 -05:00
asantibanez
b04c338283 Changed CI to 8.2 2024-08-22 09:21:00 -05:00
asantibanez
98ffca8cf3 Changed CI to 8.3 2024-08-22 09:17:49 -05:00
asantibanez
d31ed188a9 Migrated configuration 2024-08-22 09:17:32 -05:00
Andrés Santibáñez
08d60e1ffa Merge pull request #122 from laravel-shift/l11-compatibility
Laravel 11.x Compatibility
2024-08-22 08:48:46 -05:00
Shift
fc0c122926 Bump dependencies for Laravel 11 2024-02-27 15:28:13 +00:00
Andrés Santibáñez
d58465084e Merge pull request #105 from redsquirrelstudio/livewire-3-event-fix
Changed 'emit' functions in Area,Line, and Radar chart to 'dispatch' …
2023-11-07 14:50:23 -05:00
Andrés Santibáñez
5a222abdbf Merge pull request #108 from stijnvanouplines/master
Added missing jsonConfig
2023-11-07 14:40:56 -05:00
Stijn Vanouplines
af44417115 Added missing jsonConfig 2023-10-27 17:37:09 +02:00
Lewis Raggett
4c70acd41c Changed 'emit' functions in Area,Line, and Radar chart to 'dispatch' to work with Livewire 3 2023-10-05 11:41:49 +01:00
asantibanez
ca044277ee Updated README 2023-08-24 10:04:02 -05:00
asantibanez
badbd7d872 Fixed README 2023-07-25 17:22:42 -05:00
38 changed files with 413 additions and 86 deletions

View File

@@ -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

View 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}}

View File

@@ -1,5 +1,15 @@
# Changelog
## 4.1.0 - 2024-08-22
- Added Radial chart
## 4.0.0 - 2024-08-22
- Added Laravel 11 support
## 3.1.0 - 2023-11-07
- Added missing jsonConfig (thanks to @stijnvanouplines)
- Changed 'emit' functions in Area,Line, and Radar chart to 'dispatch' (thanks to @redsquirrelstudio)
## 3.0.0 - 2023-07-25
- Added Livewire v3 support
- Added ability to set chart theme (thanks to @syntaxlexx)

View File

@@ -47,6 +47,7 @@ Livewire Charts supports out of the box the following types of charts
- Area Chart (`LivewireAreaChart` component)
- Radar Chart (`LivewireRadarChart` component)
- Tree Map Chart (`LivewireTreeMapChart` component)
- Radial Chart (`LivewireRadialChart` component)
Each one comes with its own "model" class that allows you to define the chart's data and render behavior.
- `LivewireLineChart` uses `LineChartModel` to set up data points, markers, events and other ui customizations.
@@ -55,6 +56,7 @@ Each one comes with its own "model" class that allows you to define the chart's
- `LivewireAreaChart` uses `AreaChartModel` to set up data points, events and other ui customizations.
- `LivewireRadarChart` uses `RadarChartModel` to set up data points, events and other ui customizations.
- `LivewireTreeMapChart` uses `TreeMapChartModel` to set up data blocks, events and other ui customizations.
- `LivewireRadialChart` uses `RadialChartModel` to set up data bars, events and other ui customizations.
For example, to render a column chart, we can create an instance of `ColumnChartModel` and add some data to it
```php
@@ -82,7 +84,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
```
@@ -106,6 +108,7 @@ LivewireCharts::pieChartModel();
LivewireCharts::areaChartModel();
LivewireCharts::radarChartModel();
LivewireCharts::treeMapChartModel();
LivewireCharts::radialChartModel();
```
## Enabling Interactions
@@ -170,20 +173,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 +213,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
@@ -246,6 +250,14 @@ for each type of chart.
| withOnBlockClickEvent(string $eventName) | Event Name that will be fired when a block of the chart is clicked |
| setDistributed(bool $distributed) | Set whether the chart uses distribution or not |
### LivewireRadialChart
| Method | Description |
|--------------------------------------------------------------------------------|------------------------------------------------------------------|
| addBar(string $title, double $value, string $color = null, array $extras = []) | Adds a bar to the default series |
| withOnBarClickEvent(string $eventName) | Event Name that will be fired when a bar of the chart is clicked |
| showTotal() | Show the total percetage to the graph |
| hideTotal() | Hides the total percetage to the graph |
## Advanced Usage - Integrating Scripts
@@ -256,6 +268,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

View File

@@ -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": {

View File

@@ -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

View File

@@ -1,12 +1,13 @@
import ApexCharts from 'apexcharts'
import areaChart from "./areaChart"
import columnChart from "./columnChart"
import multiColumnChart from "./multiColumnChart";
import multiColumnChart from "./multiColumnChart"
import lineChart from "./lineChart"
import multiLineChart from "./multiLineChart"
import pieChart from "./pieChart"
import radarChart from "./radarChart"
import treeMapChart from "./treeMapChart"
import radialChart from "./radialChart"
window.ApexCharts = ApexCharts
window.livewireChartsAreaChart = areaChart
@@ -17,3 +18,4 @@ window.livewireChartsPieChart = pieChart
window.livewireChartsMultiColumnChart = multiColumnChart
window.livewireChartsRadarChart = radarChart
window.livewireChartsTreeMapChart = treeMapChart
window.livewireChartsRadialChart = radialChart

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,74 @@
import { mergedOptionsWithJsonConfig } from "./helpers";
const radialChart = () => {
return {
chart: null,
init() {
setTimeout(() => {
this.drawChart(this.$wire);
}, 0);
},
drawChart(component) {
if (this.chart) {
this.chart.destroy();
}
const data = component.get("radialChartModel.data");
const showTotal = component.get("radialChartModel.showTotal");
const onBarClickEventName = component.get(
"radialChartModel.onBarClickEventName"
);
const jsonConfig = component.get("radialChartModel.jsonConfig");
const colors = component.get("radialChartModel.colors");
const options = {
series: data.map((item) => item.value),
labels: data.map((item) => item.title),
colors: Object.values(colors).filter(Boolean),
chart: {
height: "100%",
type: "radialBar",
events: {
dataPointSelection: function (
event,
chartContext,
payload
) {
console.log(payload);
if (!onBarClickEventName) {
return;
}
const bar = data[payload.dataPointIndex];
console.log(bar);
component.call("onBarClick", bar);
},
},
},
plotOptions: {
radialBar: {
dataLabels: {
total: {
show: showTotal,
},
},
},
},
};
this.chart = new ApexCharts(
this.$refs.container,
mergedOptionsWithJsonConfig(options, jsonConfig)
);
this.chart.render();
},
};
};
export default radialChart;

View File

@@ -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();
}
}

View File

@@ -0,0 +1,7 @@
<div
style="width: 100%; height: 100%;"
x-data="{ ...livewireChartsRadialChart() }"
x-init="init()"
>
<div wire:ignore x-ref="container"></div>
</div>

View File

@@ -26,7 +26,7 @@ class LivewireAreaChart extends Component
return;
}
$this->emit($onPointClickEventName, $point);
$this->dispatch($onPointClickEventName, $point);
}
public function render()

View File

@@ -26,7 +26,7 @@ class LivewireLineChart extends Component
return;
}
$this->emit($onPointClickEventName, $point);
$this->dispatch($onPointClickEventName, $point);
}
public function render()

View File

@@ -26,7 +26,7 @@ class LivewireRadarChart extends Component
return;
}
$this->emit($onPointClickEventName, $point);
$this->dispatch($onPointClickEventName, $point);
}
public function render()

View File

@@ -0,0 +1,36 @@
<?php
namespace Asantibanez\LivewireCharts\Charts;
use Asantibanez\LivewireCharts\Models\RadialChartModel;
use Livewire\Component;
/**
* Class LivewireRadialChart
* @package Asantibanez\LivewireCharts\Charts
*/
class LivewireRadialChart extends Component
{
public $radialChartModel;
public function mount(RadialChartModel $radialChartModel)
{
$this->radialChartModel = $radialChartModel->toArray();
}
public function onBarClick($bar): void
{
$onBarClickEventName = data_get($this->radialChartModel, 'onBarClickEventName');
if ($onBarClickEventName === null) {
return;
}
$this->dispatch($onBarClickEventName, $bar);
}
public function render()
{
return view('livewire-charts::livewire-radial-chart');
}
}

View File

@@ -7,6 +7,7 @@ use Asantibanez\LivewireCharts\Models\ColumnChartModel;
use Asantibanez\LivewireCharts\Models\LineChartModel;
use Asantibanez\LivewireCharts\Models\PieChartModel;
use Asantibanez\LivewireCharts\Models\RadarChartModel;
use Asantibanez\LivewireCharts\Models\RadialChartModel;
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
use Illuminate\Support\Facades\Facade;
@@ -21,6 +22,7 @@ use Illuminate\Support\Facades\Facade;
* @method static PieChartModel pieChartModel()
* @method static RadarChartModel radarChartModel()
* @method static TreeMapChartModel treeMapChartModel()
* @method static RadialChartModel radialChartModel()
*/
class LivewireCharts extends Facade
{

View File

@@ -9,6 +9,7 @@ use Asantibanez\LivewireCharts\Models\ColumnChartModel;
use Asantibanez\LivewireCharts\Models\LineChartModel;
use Asantibanez\LivewireCharts\Models\PieChartModel;
use Asantibanez\LivewireCharts\Models\RadarChartModel;
use Asantibanez\LivewireCharts\Models\RadialChartModel;
use Asantibanez\LivewireCharts\Models\TreeMapChartModel;
class LivewireCharts
@@ -52,8 +53,13 @@ class LivewireCharts
return new RadarChartModel();
}
public function treeMapChartModel()
public function treeMapChartModel(): TreeMapChartModel
{
return new TreeMapChartModel();
}
public function radialChartModel(): RadialChartModel
{
return new RadialChartModel();
}
}

View File

@@ -7,6 +7,7 @@ use Asantibanez\LivewireCharts\Charts\LivewireColumnChart;
use Asantibanez\LivewireCharts\Charts\LivewireLineChart;
use Asantibanez\LivewireCharts\Charts\LivewirePieChart;
use Asantibanez\LivewireCharts\Charts\LivewireRadarChart;
use Asantibanez\LivewireCharts\Charts\LivewireRadialChart;
use Asantibanez\LivewireCharts\Charts\LivewireTreeMapChart;
use Asantibanez\LivewireCharts\Console\InstallCommand;
use Illuminate\Support\Facades\Blade;
@@ -73,6 +74,7 @@ class LivewireChartsServiceProvider extends ServiceProvider
Livewire::component('livewire-area-chart', LivewireAreaChart::class);
Livewire::component('livewire-radar-chart', LivewireRadarChart::class);
Livewire::component('livewire-tree-map-chart', LivewireTreeMapChart::class);
Livewire::component('livewire-radial-chart', LivewireRadialChart::class);
}
private function registerDirectives()

View File

@@ -3,6 +3,18 @@
namespace Asantibanez\LivewireCharts\Models;
use Asantibanez\LivewireCharts\Models\Traits\HasAnimation;
use Asantibanez\LivewireCharts\Models\Traits\HasAxis;
use Asantibanez\LivewireCharts\Models\Traits\HasColors;
use Asantibanez\LivewireCharts\Models\Traits\HasDataLabels;
use Asantibanez\LivewireCharts\Models\Traits\HasGrid;
use Asantibanez\LivewireCharts\Models\Traits\HasJsonConfig;
use Asantibanez\LivewireCharts\Models\Traits\HasLegend;
use Asantibanez\LivewireCharts\Models\Traits\HasSparkline;
use Asantibanez\LivewireCharts\Models\Traits\HasStroke;
use Asantibanez\LivewireCharts\Models\Traits\HasTheme;
use Asantibanez\LivewireCharts\Models\Traits\HasTitle;
/**
* Class BaseChartModel
* @package Asantibanez\LivewireCharts\Models

View File

@@ -0,0 +1,76 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
/**
* Class RadialChartModel
* @package Asantibanez\LivewireCharts\Models
*/
class RadialChartModel extends BaseChartModel
{
public $data;
public $showTotal;
public $onBarClickEventName;
public function __construct()
{
parent::__construct();
$this->data = collect();
$this->showTotal = true;
}
public function showTotal(): self
{
$this->showTotal = true;
return $this;
}
public function hideTotal(): self
{
$this->showTotal = false;
return $this;
}
public function addBar($title, $value, $color = null, $extras = []): self
{
$this->data->push([
'title' => $title,
'value' => $value,
'extras' => $extras,
]);
$this->addColor($color);
return $this;
}
public function withOnBarClickEvent($onBarClickEvent): self
{
$this->onBarClickEventName = $onBarClickEvent;
return $this;
}
public function toArray()
{
return array_merge(parent::toArray(), [
'data' => $this->data->toArray(),
'showTotal' => $this->showTotal,
'onBarClickEventName' => $this->onBarClickEventName,
]);
}
public function fromArray($array)
{
parent::fromArray($array);
$this->data = collect(data_get($array, 'data', []));
$this->showTotal = data_get($array, 'showTotal', true);
$this->onBarClickEventName = data_get($array, 'onBarClickEventName', null);
}
}

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasAnimation

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasAxis

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasColors

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasDataLabels

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasGrid

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasJsonConfig

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasLegend

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasSparkline

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasStroke

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasTheme
@@ -11,7 +11,7 @@ trait HasTheme
private $palette;
/**
* Initialize
* Initialize
*/
public function initTheme()
{
@@ -20,7 +20,7 @@ trait HasTheme
/**
* set default theme
*
*
* @return array $theme
*/
private function defaultTheme()
@@ -33,9 +33,9 @@ trait HasTheme
/**
* set theme mode
*
*
* @param string $mode
*
*
* @return $this
*/
public function setThemeMode(string $mode)
@@ -44,10 +44,10 @@ trait HasTheme
return $this;
}
/**
* set theme mode to dark theme
*
*
* @return $this
*/
public function darkMode()
@@ -59,7 +59,7 @@ trait HasTheme
/**
* set theme mode to light theme
*
*
* @return $this
*/
public function lightMode()
@@ -68,12 +68,12 @@ trait HasTheme
return $this;
}
/**
* set the dark mode option to on or off
*
*
* @param bool $status = true
*
*
* @return $this
*/
public function setDarkMode(bool $status = true)
@@ -85,9 +85,9 @@ trait HasTheme
/**
* set theme pallete
*
*
* @param string $pallete
*
*
* @return $this
*/
public function setThemePalette(string $palette)
@@ -99,9 +99,9 @@ trait HasTheme
/**
* convert the theme to array
*
*
* @param string $mode
*
*
* @return $this
*/
protected function themeToArray()
@@ -113,9 +113,9 @@ trait HasTheme
/**
* set theme from array
*
*
* @param string $mode
*
*
* @return $this
*/
protected function themeFromArray($array)

View File

@@ -1,7 +1,7 @@
<?php
namespace Asantibanez\LivewireCharts\Models;
namespace Asantibanez\LivewireCharts\Models\Traits;
trait HasTitle
@@ -15,6 +15,11 @@ trait HasTitle
return $this;
}
public function getTitle()
{
return $this->title;
}
protected function initTitle()
{
$this->title = $this->defaultTitle();

View File

@@ -9,9 +9,6 @@ namespace Asantibanez\LivewireCharts\Models;
*/
class TreeMapChartModel extends BaseChartModel
{
use HasTitle;
use HasColors;
public $data;
public $distributed;
public $onBlockClickEventName;
@@ -36,7 +33,7 @@ class TreeMapChartModel extends BaseChartModel
public function addBlock($title, $value, $extras = [])
{
return $this->addSeriesBlock($this->title, $title, $value, $extras);
return $this->addSeriesBlock($this->getTitle(), $title, $value, $extras);
}
public function addSeriesBlock($seriesName, $title, $value, $extras = [])

View File

@@ -0,0 +1,44 @@
<?php
use Asantibanez\LivewireCharts\Charts\LivewireRadialChart;
use Asantibanez\LivewireCharts\Tests\TestCase;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
class LivewireRadialChartTest extends TestCase
{
private function buildComponent() : Testable
{
return Livewire::test(LivewireRadialChart::class);
}
/** @test */
public function can_build_component()
{
//Act
$component = $this->buildComponent();
//Assert
$this->assertNotNull($component);
}
/** @test */
public function should_emit_event_if_present()
{
//Arrange
$component = $this->buildComponent();
$radialChartModel = $component->radialChartModel;
data_set($radialChartModel, 'onBarClickEventName', 'custom-event');
$component->set('radialChartModel', $radialChartModel);
//Act
$component->runAction('onBarClick', []);
//Assert
$component->assertDispatched('custom-event');
}
}