From 3b545508bec317c36a0cb83809de6e6cc8397832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 17:48:25 +0300 Subject: [PATCH 01/30] fixed class name --- src/Options/Annotations.php | 2 +- src/Options/Chart.php | 48 +++++++++++++++--------------- src/Options/DataLabels.php | 2 +- src/Options/Fill.php | 2 +- src/Options/ForecastDataPoints.php | 2 +- src/Options/Grid.php | 2 +- src/Options/Legend.php | 2 +- src/Options/Markers.php | 2 +- src/Options/NoData.php | 2 +- src/Options/PlotOptions.php | 2 +- src/Options/Responsive.php | 2 +- src/Options/States.php | 2 +- src/Options/Stroke.php | 2 +- src/Options/Subtitle.php | 2 +- src/Options/Theme.php | 2 +- src/Options/Title.php | 2 +- src/Options/Tooltip.php | 2 +- src/Options/Xaxis.php | 2 +- src/Options/Yaxis.php | 2 +- src/Provider.php | 6 ++-- src/Types/Area.php | 4 +-- src/Types/Bar.php | 4 +-- src/Types/Donut.php | 4 +-- src/Types/HeatMap.php | 4 +-- src/Types/HorizontalBar.php | 4 +-- src/Types/Line.php | 4 +-- src/Types/Pie.php | 4 +-- src/Types/PolarArea.php | 4 +-- src/Types/Radar.php | 4 +-- src/Types/Radial.php | 4 +-- tests/Feature/ChartsTest.php | 26 ++++++++-------- tests/Unit/ChartsTest.php | 8 ++--- 32 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/Options/Annotations.php b/src/Options/Annotations.php index aa63e9a..75afea4 100644 --- a/src/Options/Annotations.php +++ b/src/Options/Annotations.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Annotations { diff --git a/src/Options/Chart.php b/src/Options/Chart.php index c6511ea..fa35c1a 100644 --- a/src/Options/Chart.php +++ b/src/Options/Chart.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart as MainChart; trait Chart { @@ -52,7 +52,7 @@ trait Chart public array $zoom = []; - public function setAnimations(array $animations): Chart + public function setAnimations(array $animations): MainChart { $this->animations = $animations; @@ -70,7 +70,7 @@ public function getAnimations(): array return $this->animations; } - public function setBackground(string $background): Chart + public function setBackground(string $background): MainChart { $this->background = $background; @@ -88,7 +88,7 @@ public function getBackground(): string return $this->background; } - public function setBrush(array $brush): Chart + public function setBrush(array $brush): MainChart { $this->brush = $brush; @@ -106,7 +106,7 @@ public function getBrush(): array return $this->brush; } - public function setDefaultLocale(string $defaultLocale): Chart + public function setDefaultLocale(string $defaultLocale): MainChart { $this->defaultLocale = $defaultLocale; @@ -124,7 +124,7 @@ public function getDefaultLocale(): string return $this->defaultLocale; } - public function setDropShadow(array $dropShadow): Chart + public function setDropShadow(array $dropShadow): MainChart { $this->dropShadow = $dropShadow; @@ -142,7 +142,7 @@ public function getDropShadow(): array return $this->dropShadow; } - public function setFontFamily(string $fontFamily): Chart + public function setFontFamily(string $fontFamily): MainChart { $this->fontFamily = $fontFamily; @@ -160,7 +160,7 @@ public function getFontFamily(): string return $this->fontFamily; } - public function setForeColor(string $foreColor): Chart + public function setForeColor(string $foreColor): MainChart { $this->foreColor = $foreColor; @@ -178,7 +178,7 @@ public function getForeColor(): string return $this->foreColor; } - public function setGroup(string $group): Chart + public function setGroup(string $group): MainChart { $this->group = $group; @@ -196,7 +196,7 @@ public function getGroup(): string return $this->group; } - public function setEvents(array $events): Chart + public function setEvents(array $events): MainChart { $this->events = $events; @@ -214,7 +214,7 @@ public function getEvents(): array return $this->events; } - public function setHeight(int|string|null $height): Chart + public function setHeight(int|string|null $height): MainChart { $this->height = $height; @@ -232,7 +232,7 @@ public function getHeight(): int|string|null return $this->height; } - public function setLocales(array $locales): Chart + public function setLocales(array $locales): MainChart { $this->locales = $locales; @@ -250,7 +250,7 @@ public function getLocales(): array return $this->locales; } - public function setOffsetX(int $offsetX): Chart + public function setOffsetX(int $offsetX): MainChart { $this->offsetX = $offsetX; @@ -268,7 +268,7 @@ public function getOffsetX(): int return $this->offsetX; } - public function setOffsetY(int $offsetY): Chart + public function setOffsetY(int $offsetY): MainChart { $this->offsetY = $offsetY; @@ -286,7 +286,7 @@ public function getOffsetY(): int return $this->offsetY; } - public function setParentHeightOffset(int $parentHeightOffset): Chart + public function setParentHeightOffset(int $parentHeightOffset): MainChart { $this->parentHeightOffset = $parentHeightOffset; @@ -304,7 +304,7 @@ public function getParentHeightOffset(): int return $this->parentHeightOffset; } - public function setRedrawOnParentResize(bool $redrawOnParentResize): Chart + public function setRedrawOnParentResize(bool $redrawOnParentResize): MainChart { $this->redrawOnParentResize = $redrawOnParentResize; @@ -322,7 +322,7 @@ public function getRedrawOnParentResize(): bool return $this->redrawOnParentResize; } - public function setRedrawOnWindowResize(bool $redrawOnWindowResize): Chart + public function setRedrawOnWindowResize(bool $redrawOnWindowResize): MainChart { $this->redrawOnWindowResize = $redrawOnWindowResize; @@ -340,7 +340,7 @@ public function getRedrawOnWindowResize(): bool return $this->redrawOnWindowResize; } - public function setSelection(array $selection): Chart + public function setSelection(array $selection): MainChart { $this->selection = $selection; @@ -358,7 +358,7 @@ public function getSelection(): array return $this->selection; } - public function setSparkline(array $sparkline): Chart + public function setSparkline(array $sparkline): MainChart { $this->sparkline = $sparkline; @@ -376,7 +376,7 @@ public function getSparkline(): array return $this->sparkline; } - public function setStacked(bool $stacked): Chart + public function setStacked(bool $stacked): MainChart { $this->stacked = $stacked; @@ -394,7 +394,7 @@ public function getStacked(): bool return $this->stacked; } - public function setStackType(string $stackType): Chart + public function setStackType(string $stackType): MainChart { $this->stackType = $stackType; @@ -412,7 +412,7 @@ public function getStackType(): string return $this->stackType; } - public function setToolbar(array $toolbar): Chart + public function setToolbar(array $toolbar): MainChart { $this->toolbar = $toolbar; @@ -430,7 +430,7 @@ public function getToolbar(): array return $this->toolbar; } - public function setWidth(int|string|null $width): Chart + public function setWidth(int|string|null $width): MainChart { $this->width = $width; @@ -448,7 +448,7 @@ public function getWidth(): int|string|null return $this->width; } - public function setZoom(array $zoom): Chart + public function setZoom(array $zoom): MainChart { $this->zoom = $zoom; diff --git a/src/Options/DataLabels.php b/src/Options/DataLabels.php index c7ea2ec..633dbaf 100644 --- a/src/Options/DataLabels.php +++ b/src/Options/DataLabels.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait DataLabels { diff --git a/src/Options/Fill.php b/src/Options/Fill.php index 3888f17..d94e037 100644 --- a/src/Options/Fill.php +++ b/src/Options/Fill.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Fill { diff --git a/src/Options/ForecastDataPoints.php b/src/Options/ForecastDataPoints.php index c5b03c0..9ee44a2 100644 --- a/src/Options/ForecastDataPoints.php +++ b/src/Options/ForecastDataPoints.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait ForecastDataPoints { diff --git a/src/Options/Grid.php b/src/Options/Grid.php index de1a53f..369a4c2 100644 --- a/src/Options/Grid.php +++ b/src/Options/Grid.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Grid { diff --git a/src/Options/Legend.php b/src/Options/Legend.php index 87f9a5c..e3bf672 100644 --- a/src/Options/Legend.php +++ b/src/Options/Legend.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Legend { diff --git a/src/Options/Markers.php b/src/Options/Markers.php index 1b924cd..8f7179a 100644 --- a/src/Options/Markers.php +++ b/src/Options/Markers.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Markers { diff --git a/src/Options/NoData.php b/src/Options/NoData.php index b9d294c..6ad2a95 100644 --- a/src/Options/NoData.php +++ b/src/Options/NoData.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait NoData { diff --git a/src/Options/PlotOptions.php b/src/Options/PlotOptions.php index 8dbaf4f..de80d8c 100644 --- a/src/Options/PlotOptions.php +++ b/src/Options/PlotOptions.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait PlotOptions { diff --git a/src/Options/Responsive.php b/src/Options/Responsive.php index 5a8a68b..085c033 100644 --- a/src/Options/Responsive.php +++ b/src/Options/Responsive.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Responsive { diff --git a/src/Options/States.php b/src/Options/States.php index 6b4237a..4042716 100644 --- a/src/Options/States.php +++ b/src/Options/States.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait States { diff --git a/src/Options/Stroke.php b/src/Options/Stroke.php index afa238f..f4b0928 100644 --- a/src/Options/Stroke.php +++ b/src/Options/Stroke.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Stroke { diff --git a/src/Options/Subtitle.php b/src/Options/Subtitle.php index 8519ba1..0f9fc36 100644 --- a/src/Options/Subtitle.php +++ b/src/Options/Subtitle.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Subtitle { diff --git a/src/Options/Theme.php b/src/Options/Theme.php index e4d60a9..4d58b29 100644 --- a/src/Options/Theme.php +++ b/src/Options/Theme.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Theme { diff --git a/src/Options/Title.php b/src/Options/Title.php index e02d614..7e778c0 100644 --- a/src/Options/Title.php +++ b/src/Options/Title.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Title { diff --git a/src/Options/Tooltip.php b/src/Options/Tooltip.php index b749b9c..7dea916 100644 --- a/src/Options/Tooltip.php +++ b/src/Options/Tooltip.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Tooltip { diff --git a/src/Options/Xaxis.php b/src/Options/Xaxis.php index e82a3d6..324383b 100644 --- a/src/Options/Xaxis.php +++ b/src/Options/Xaxis.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Xaxis { diff --git a/src/Options/Yaxis.php b/src/Options/Yaxis.php index 98337ba..1f7dc29 100644 --- a/src/Options/Yaxis.php +++ b/src/Options/Yaxis.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Options; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; trait Yaxis { diff --git a/src/Provider.php b/src/Provider.php index c251955..4c7e093 100644 --- a/src/Provider.php +++ b/src/Provider.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\ServiceProvider; use Illuminate\View\Compilers\BladeCompiler; @@ -13,7 +13,7 @@ class Provider extends ServiceProvider */ public function register(): void { - $this->app->alias(Charts::class, 'apexcharts'); + $this->app->alias(Chart::class, 'apexcharts'); $this->mergeConfigFrom(__DIR__ . '/Config/apexcharts.php', 'apexcharts'); } @@ -38,7 +38,7 @@ public function registerBladeDirectives(): void { $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { $bladeCompiler->directive('apexchartsScripts', function ($expression) { - return '{!! \Akaunting\Apexcharts\Charts::loadScript(' . $expression . ') !!}'; + return '{!! \Akaunting\Apexcharts\Chart::loadScript(' . $expression . ') !!}'; }); }); } diff --git a/src/Types/Area.php b/src/Types/Area.php index ce95a65..d336c9d 100644 --- a/src/Types/Area.php +++ b/src/Types/Area.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class Area extends Charts +class Area extends Chart { public function __construct() { diff --git a/src/Types/Bar.php b/src/Types/Bar.php index d962e26..9ced8f3 100644 --- a/src/Types/Bar.php +++ b/src/Types/Bar.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class Bar extends Charts +class Bar extends Chart { public function __construct() { diff --git a/src/Types/Donut.php b/src/Types/Donut.php index 35f1cd8..041d9b9 100644 --- a/src/Types/Donut.php +++ b/src/Types/Donut.php @@ -2,9 +2,9 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; -class Donut extends Charts +class Donut extends Chart { public function __construct() { diff --git a/src/Types/HeatMap.php b/src/Types/HeatMap.php index 73190af..f29cd17 100644 --- a/src/Types/HeatMap.php +++ b/src/Types/HeatMap.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class HeatMap extends Charts +class HeatMap extends Chart { public function __construct() { diff --git a/src/Types/HorizontalBar.php b/src/Types/HorizontalBar.php index 4151e1a..33ed800 100644 --- a/src/Types/HorizontalBar.php +++ b/src/Types/HorizontalBar.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class HorizontalBar extends Charts +class HorizontalBar extends Chart { public function __construct() { diff --git a/src/Types/Line.php b/src/Types/Line.php index f853f14..9ddc1a1 100644 --- a/src/Types/Line.php +++ b/src/Types/Line.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class Line extends Charts +class Line extends Chart { public function __construct() { diff --git a/src/Types/Pie.php b/src/Types/Pie.php index 0319d0c..d9db193 100644 --- a/src/Types/Pie.php +++ b/src/Types/Pie.php @@ -2,9 +2,9 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; -class Pie extends Charts +class Pie extends Chart { public function __construct() { diff --git a/src/Types/PolarArea.php b/src/Types/PolarArea.php index 9d3ce1b..baaf5d2 100644 --- a/src/Types/PolarArea.php +++ b/src/Types/PolarArea.php @@ -2,9 +2,9 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; -class PolarArea extends Charts +class PolarArea extends Chart { public function __construct() { diff --git a/src/Types/Radar.php b/src/Types/Radar.php index be76b7f..bf13b23 100644 --- a/src/Types/Radar.php +++ b/src/Types/Radar.php @@ -2,10 +2,10 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Illuminate\Support\Collection; -class Radar extends Charts +class Radar extends Chart { public function __construct() { diff --git a/src/Types/Radial.php b/src/Types/Radial.php index 8dfd1f3..6ead994 100644 --- a/src/Types/Radial.php +++ b/src/Types/Radial.php @@ -2,9 +2,9 @@ namespace Akaunting\Apexcharts\Types; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; -class Radial extends Charts +class Radial extends Chart { public function __construct() { diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index aade5e0..b03ac6b 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Tests\Feature; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Akaunting\Apexcharts\Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -13,17 +13,17 @@ class ChartsTest extends TestCase /** @test */ public function it_tests_apexcharts_can_render_pie_charts_by_default() { - $chart = (new Charts)->setTitle('Users Test Chart'); + $chart = (new Chart)->setTitle('Users Test Chart'); $this->assertEquals('donut', $chart->type()); - $anotherChart = (new Charts)->areaChart(); + $anotherChart = (new Chart)->areaChart(); $this->assertEquals('area', $anotherChart->type()); } /** @test */ public function it_tests_apexcharts_can_render_pie_chart() { - $chart = (new Charts)->pieChart() + $chart = (new Chart)->pieChart() ->setTitle('Posts') ->setSubtitle('From January To March') ->setLabels(['Product One', 'Product Two', 'Product Three']) @@ -37,7 +37,7 @@ public function it_tests_apexcharts_can_render_pie_chart() /** @test */ public function it_tests_apexcharts_can_render_donut_chart() { - $chart = (new Charts)->donutChart() + $chart = (new Chart)->donutChart() ->setTitle('Posts') ->setXAxis(['Jan', 'Feb', 'Mar']) ->setDataset([150, 120]); @@ -49,7 +49,7 @@ public function it_tests_apexcharts_can_render_donut_chart() /** @test */ public function it_tests_larapex_can_render_radial_bar_charts() { - $chart = (new Charts)->radialChart() + $chart = (new Chart)->radialChart() ->setTitle('Products with more profit') ->setXAxis(['Jan', 'Feb', 'Mar']) ->setDataset([60, 40, 79]); @@ -61,7 +61,7 @@ public function it_tests_larapex_can_render_radial_bar_charts() /** @test */ public function it_tests_apexcharts_can_render_polar_chart() { - $chart = (new Charts)->polarAreaChart() + $chart = (new Chart)->polarAreaChart() ->setTitle('Products with more profit') ->setXAxis(['Jan', 'Feb', 'Mar']) ->setDataset([60, 40, 79]); @@ -73,7 +73,7 @@ public function it_tests_apexcharts_can_render_polar_chart() /** @test */ public function larapex_can_render_line_charts() { - $chart = (new Charts)->lineChart() + $chart = (new Chart)->lineChart() ->setTitle('Total Users Monthly') ->setSubtitle('From January to March') ->setXAxis([ @@ -97,7 +97,7 @@ public function larapex_can_render_line_charts() /** @test */ public function it_tests_apexcharts_can_create_an_area_chart() { - $chart = (new Charts)->areaChart() + $chart = (new Chart)->areaChart() ->setTitle('Total Users Monthly') ->setSubtitle('From January to March') ->setXAxis([ @@ -122,7 +122,7 @@ public function it_tests_apexcharts_can_create_an_area_chart() /** @test */ public function it_tests_apexcharts_can_render_bar_charts() { - $chart = (new Charts)->barChart() + $chart = (new Chart)->barChart() ->setTitle('Net Profit') ->setXAxis(['Jan', 'Feb', 'Mar']) ->setDataset([ @@ -160,7 +160,7 @@ public function it_tests_apexcharts_can_render_bar_charts() /** @test */ public function it_tests_apexcharts_can_render_horizontal_bar_chart() { - $chart = (new Charts)->barChart() + $chart = (new Chart)->barChart() ->setTitle('Net Profit') ->setHorizontal(true) ->setXAxis(['Jan', 'Feb', 'Mar']) @@ -189,7 +189,7 @@ public function it_tests_apexcharts_can_render_horizontal_bar_chart() /** @test */ public function it_tests_apexcharts_can_render_heatmap_chart() { - $chart = (new Charts)->heatMapChart() + $chart = (new Chart)->heatMapChart() ->setTitle('Total Users') ->setXAxis([ 'Jan', 'Feb', 'Mar' @@ -213,7 +213,7 @@ public function it_tests_apexcharts_can_render_heatmap_chart() /** @test */ public function it_tests_apexcharts_can_render_radar_chart() { - $chart = (new Charts)->radarChart() + $chart = (new Chart)->radarChart() ->setTitle('Total Users') ->setXAxis([ 'Jan', 'Feb', 'Mar' diff --git a/tests/Unit/ChartsTest.php b/tests/Unit/ChartsTest.php index 90b1b43..0d0b059 100644 --- a/tests/Unit/ChartsTest.php +++ b/tests/Unit/ChartsTest.php @@ -2,7 +2,7 @@ namespace Akaunting\Apexcharts\Tests\Unit; -use Akaunting\Apexcharts\Charts; +use Akaunting\Apexcharts\Chart; use Akaunting\Apexcharts\Tests\TestCase; class ChartsTest extends TestCase @@ -27,7 +27,7 @@ public function it_tests_apexcharts_install_add_chart_stubs() /** @test */ public function it_tests_apexcharts_can_load_script_correctly() { - $chart = (new Charts) + $chart = (new Chart) ->setTitle('Posts') ->setXAxis(['Jan', 'Feb', 'Mar']) ->setDataset([150, 120]) @@ -39,7 +39,7 @@ public function it_tests_apexcharts_can_load_script_correctly() /** @test */ public function it_tests_apexcharts_can_change_default_config_colors() { - $chart = (new Charts)->setTitle('Posts')->setXAxis(['Jan', 'Feb', 'Mar'])->setDataset([150, 120]); + $chart = (new Chart)->setTitle('Posts')->setXAxis(['Jan', 'Feb', 'Mar'])->setDataset([150, 120]); $oldColors = $chart->colors(); @@ -50,6 +50,6 @@ public function it_tests_apexcharts_can_change_default_config_colors() /** @test */ public function it_tests_larapex_chart_cdn_returns_a_correct_url() { - $this->assertEquals('https://cdn.jsdelivr.net/npm/apexcharts', (new Charts)->cdn()); + $this->assertEquals('https://cdn.jsdelivr.net/npm/apexcharts', (new Chart)->cdn()); } } From 4636e94a01510cff14be2da9d2a638b68b281188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 18:10:01 +0300 Subject: [PATCH 02/30] added live example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e9c837f..21304fe 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ This package allows you to generate modern and interactive charts using the [Ape It covers all of the chart [types](https://apexcharts.com/docs/chart-types/line-chart) and [options](https://apexcharts.com/docs/options/annotations) available within the `ApexChart` library. +Check out the [Akaunting](https://github.com/akaunting/akaunting) project to see it live. + ## Getting Started ### 1. Install From ec950b926d13d1d6cfd28077929d4101de3e6e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 23:22:16 +0300 Subject: [PATCH 03/30] fixed tests --- .github/workflows/tests.yml | 38 +++++++++++++ composer.json | 6 +- src/Options/PlotOptions.php | 14 +++++ src/Types/HorizontalBar.php | 4 +- tests/Feature/ChartsTest.php | 105 +++++++++++++++++------------------ tests/Unit/ChartsTest.php | 55 ------------------ 6 files changed, 108 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 tests/Unit/ChartsTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7260303 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,38 @@ +name: Tests + +on: [push, pull_request] + +jobs: + tests: + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} + + runs-on: ubuntu-latest + + strategy: + matrix: + php: ['8.0', '8.1'] + laravel: [8.*, 9.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 8.* + testbench: ^6.6 + - laravel: 9.* + testbench: 7.* + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: bcmath, ctype, dom, fileinfo, intl, gd, json, mbstring, pdo, pdo_sqlite, openssl, sqlite, xml, zip + coverage: none + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + - name: Execute tests + run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 0591b01..7d48c4b 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ } ], "require": { - "php": ">=8.0", + "php": "^8.0", "ext-json": "*", "balping/json-raw-encoder": "^1.0", "illuminate/support": ">=8.0" }, "require-dev": { - "phpunit/phpunit": ">=9.0", - "orchestra/testbench": ">=6.0" + "phpunit/phpunit":"^9.5", + "orchestra/testbench": "^6.23|^7.4" }, "autoload": { "psr-4": { diff --git a/src/Options/PlotOptions.php b/src/Options/PlotOptions.php index de80d8c..e7e17c7 100644 --- a/src/Options/PlotOptions.php +++ b/src/Options/PlotOptions.php @@ -227,4 +227,18 @@ public function getRadialBar(): array { return $this->radialBar; } + + public function setHorizontal(bool $horizontal): Chart + { + $this->setBar([ + 'horizontal' => $horizontal, + ]); + + return $this; + } + + public function getHorizontal(): bool + { + return $this->getBar()['horizontal']; + } } diff --git a/src/Types/HorizontalBar.php b/src/Types/HorizontalBar.php index 33ed800..848a718 100644 --- a/src/Types/HorizontalBar.php +++ b/src/Types/HorizontalBar.php @@ -13,9 +13,7 @@ public function __construct() $this->setType('bar'); - $this->setBar([ - 'horizontal' => true, - ]); + $this->setHorizontal(true); } public function addBar(string $name, array|Collection $data): HorizontalBar diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index b03ac6b..845611e 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -14,96 +14,96 @@ class ChartsTest extends TestCase public function it_tests_apexcharts_can_render_pie_charts_by_default() { $chart = (new Chart)->setTitle('Users Test Chart'); - $this->assertEquals('donut', $chart->type()); + $this->assertEquals('line', $chart->getType()); - $anotherChart = (new Chart)->areaChart(); - $this->assertEquals('area', $anotherChart->type()); + $anotherChart = (new Chart)->setType('area'); + $this->assertEquals('area', $anotherChart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_pie_chart() { - $chart = (new Chart)->pieChart() + $chart = (new Chart)->setType('pie') ->setTitle('Posts') ->setSubtitle('From January To March') ->setLabels(['Product One', 'Product Two', 'Product Three']) - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([150, 120]); + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('posts', 'pie', [150, 120]); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('pie', $chart->type()); + $this->assertEquals('pie', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_donut_chart() { - $chart = (new Chart)->donutChart() + $chart = (new Chart)->setType('donut') ->setTitle('Posts') - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([150, 120]); + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('posts', 'donut', [150, 120]); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('donut', $chart->type()); + $this->assertEquals('donut', $chart->getType()); } /** @test */ public function it_tests_larapex_can_render_radial_bar_charts() { - $chart = (new Chart)->radialChart() + $chart = (new Chart)->setType('radial') ->setTitle('Products with more profit') - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([60, 40, 79]); + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('products', 'radial', [60, 40, 79]); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('radialBar', $chart->type()); + $this->assertEquals('radial', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_polar_chart() { - $chart = (new Chart)->polarAreaChart() + $chart = (new Chart)->setType('polarArea') ->setTitle('Products with more profit') - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([60, 40, 79]); + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('polarArea', 'radial', [60, 40, 79]); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('polarArea', $chart->type()); + $this->assertEquals('polarArea', $chart->getType()); } /** @test */ public function larapex_can_render_line_charts() { - $chart = (new Chart)->lineChart() + $chart = (new Chart)->setType('line') ->setTitle('Total Users Monthly') ->setSubtitle('From January to March') - ->setXAxis([ + ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset([ + ->setDataset('line', 'users', [ [ 'name' => 'Active Users', 'data' => [250, 700, 1200] ] ]) ->setHeight(250) - ->setGrid(true) - ->setStroke(1); + ->setGridShow(true) + ->setStrokeShow(true); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('line', $chart->type()); + $this->assertEquals('line', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_create_an_area_chart() { - $chart = (new Chart)->areaChart() + $chart = (new Chart)->setType('area') ->setTitle('Total Users Monthly') ->setSubtitle('From January to March') - ->setXAxis([ + ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset([ + ->setDataset('area', 'users', [ [ 'name' => 'Active Users', 'data' => [250, 700, 1200] @@ -114,18 +114,18 @@ public function it_tests_apexcharts_can_create_an_area_chart() ] ]); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('area', $chart->type()); + $this->assertEquals('area', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_bar_charts() { - $chart = (new Chart)->barChart() + $chart = (new Chart)->setType('bar') ->setTitle('Net Profit') - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([ + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('bar', 'profit', [ [ 'name' => 'Company A', 'data' => [500, 1000, 1900] @@ -152,19 +152,19 @@ public function it_tests_apexcharts_can_render_bar_charts() ] ]); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('bar', $chart->type()); + $this->assertEquals('bar', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_horizontal_bar_chart() { - $chart = (new Chart)->barChart() + $chart = (new Chart)->setType('bar') ->setTitle('Net Profit') ->setHorizontal(true) - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([ + ->setSeries(['Jan', 'Feb', 'Mar']) + ->setDataset('bar', 'profit', [ [ 'name' => 'Company A', 'data' => [500, 1000, 1900] @@ -179,22 +179,21 @@ public function it_tests_apexcharts_can_render_horizontal_bar_chart() ] ]); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('bar', $chart->type()); - $chartHorizontalOrientation = json_decode($chart->horizontal(), 1)['horizontal']; - $this->assertTrue($chartHorizontalOrientation); + $this->assertEquals('bar', $chart->getType()); + $this->assertTrue($chart->getHorizontal()); } /** @test */ public function it_tests_apexcharts_can_render_heatmap_chart() { - $chart = (new Chart)->heatMapChart() + $chart = (new Chart)->setType('heatmap') ->setTitle('Total Users') - ->setXAxis([ + ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset([ + ->setDataset('heatmap', 'users', [ [ 'name' => 'Users of Basic Plan', 'data' => [250, 700, 1200] @@ -205,20 +204,20 @@ public function it_tests_apexcharts_can_render_heatmap_chart() ] ]); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('heatmap', $chart->type()); + $this->assertEquals('heatmap', $chart->getType()); } /** @test */ public function it_tests_apexcharts_can_render_radar_chart() { - $chart = (new Chart)->radarChart() + $chart = (new Chart)->setType('radar') ->setTitle('Total Users') - ->setXAxis([ + ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset([ + ->setDataset('radar', 'users', [ [ 'name' => 'Users of Basic Plan', 'data' => [250, 700, 1200] @@ -229,8 +228,8 @@ public function it_tests_apexcharts_can_render_radar_chart() ] ]); - $this->assertEquals($chart->id(), $chart->container()['id']); + $this->assertEquals($chart->getId(), $chart->container()['chart']->getId()); $this->assertEquals($chart, $chart->script()['chart']); - $this->assertEquals('radar', $chart->type()); + $this->assertEquals('radar', $chart->getType()); } } diff --git a/tests/Unit/ChartsTest.php b/tests/Unit/ChartsTest.php deleted file mode 100644 index 0d0b059..0000000 --- a/tests/Unit/ChartsTest.php +++ /dev/null @@ -1,55 +0,0 @@ -setTitle('Posts') - ->setXAxis(['Jan', 'Feb', 'Mar']) - ->setDataset([150, 120]) - ->setLabels([__('Published'), __('No Published')]); - - $this->assertEquals($chart->dataset(), $chart->script()['chart']->dataset()); - } - - /** @test */ - public function it_tests_apexcharts_can_change_default_config_colors() - { - $chart = (new Chart)->setTitle('Posts')->setXAxis(['Jan', 'Feb', 'Mar'])->setDataset([150, 120]); - - $oldColors = $chart->colors(); - - $chart->setColors(['#fe9700', '#607c8a']); - $this->assertNotEquals($oldColors, $chart->colors()); - } - - /** @test */ - public function it_tests_larapex_chart_cdn_returns_a_correct_url() - { - $this->assertEquals('https://cdn.jsdelivr.net/npm/apexcharts', (new Chart)->cdn()); - } -} From 788e1530b37efd7237d040e204f38e0456c20763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 23:40:32 +0300 Subject: [PATCH 04/30] test fix --- README.md | 6 ++++++ composer.json | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21304fe..89faadc 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,12 @@ Finally, call the `container` and `script` method wherever you want to display t {!! $chart->script() !!} ``` +## Testing + +```bash +composer test +``` + ## Changelog Please see [Releases](../../releases) for more information what has changed recently. diff --git a/composer.json b/composer.json index 7d48c4b..5ba6758 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "illuminate/support": ">=8.0" }, "require-dev": { - "phpunit/phpunit":"^9.5", + "mockery/mockery": "^1.5", + "phpunit/phpunit": "^9.5", "orchestra/testbench": "^6.23|^7.4" }, "autoload": { @@ -39,6 +40,9 @@ "Akaunting\\Apexcharts\\Tests\\": "tests" } }, + "scripts": { + "test": "vendor/bin/phpunit" + }, "extra": { "laravel": { "providers": [ From 5d584f362afc080c5506abe13ac7d6ac3865d68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 23:42:18 +0300 Subject: [PATCH 05/30] increase laravel version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5ba6758..027f78c 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php": "^8.0", "ext-json": "*", "balping/json-raw-encoder": "^1.0", - "illuminate/support": ">=8.0" + "illuminate/support": "^8.67|^9.0" }, "require-dev": { "mockery/mockery": "^1.5", From 4e3488d4c246c82cb3b6745a6357ad14e286cf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Thu, 16 Jun 2022 23:50:06 +0300 Subject: [PATCH 06/30] correct name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89faadc..ae8e330 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This package allows you to generate modern and interactive charts using the [ApexCharts](https://apexcharts.com) library directly from `Laravel` without interacting with JavaScript, CSS, etc. -It covers all of the chart [types](https://apexcharts.com/docs/chart-types/line-chart) and [options](https://apexcharts.com/docs/options/annotations) available within the `ApexChart` library. +It covers all of the chart [types](https://apexcharts.com/docs/chart-types/line-chart) and [options](https://apexcharts.com/docs/options/annotations) available within the `ApexCharts` library. Check out the [Akaunting](https://github.com/akaunting/akaunting) project to see it live. From 85701efe6d8df9682c2b81d82b3ff45b33f7219a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Fri, 17 Jun 2022 00:11:36 +0300 Subject: [PATCH 07/30] renamed test functions --- README.md | 9 +++---- tests/Feature/ChartsTest.php | 50 +++++++++++++++++------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ae8e330..bc4fbe6 100644 --- a/README.md +++ b/README.md @@ -42,14 +42,11 @@ use Akaunting\Apexcharts\Chart; ... -$chart = new Chart(); - -$chart->setType('donut') +$chart = (new Chart)->setType('donut') ->setWidth('100%') ->setHeight(300) - ->setLabels(['Sales', 'Deposit']); - -$chart->setDataset('Name', 'donut', [1907, 1923]); + ->setLabels(['Sales', 'Deposit']) + ->setDataset('Income by Category', 'donut', [1907, 1923]); ``` Then, include the JavaScript (on every page using charts). diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index 845611e..5442dc2 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -4,74 +4,70 @@ use Akaunting\Apexcharts\Chart; use Akaunting\Apexcharts\Tests\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; class ChartsTest extends TestCase { - use RefreshDatabase; - /** @test */ - public function it_tests_apexcharts_can_render_pie_charts_by_default() + public function testDefaultChart() { $chart = (new Chart)->setTitle('Users Test Chart'); - $this->assertEquals('line', $chart->getType()); - $anotherChart = (new Chart)->setType('area'); - $this->assertEquals('area', $anotherChart->getType()); + $this->assertEquals($chart, $chart->script()['chart']); + $this->assertEquals('line', $chart->getType()); } /** @test */ - public function it_tests_apexcharts_can_render_pie_chart() + public function testPieChart() { $chart = (new Chart)->setType('pie') ->setTitle('Posts') ->setSubtitle('From January To March') ->setLabels(['Product One', 'Product Two', 'Product Three']) ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('posts', 'pie', [150, 120]); + ->setDataset('Posts', 'pie', [150, 120]); $this->assertEquals($chart, $chart->script()['chart']); $this->assertEquals('pie', $chart->getType()); } /** @test */ - public function it_tests_apexcharts_can_render_donut_chart() + public function testDonutChart() { $chart = (new Chart)->setType('donut') ->setTitle('Posts') ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('posts', 'donut', [150, 120]); + ->setDataset('Posts', 'donut', [150, 120]); $this->assertEquals($chart, $chart->script()['chart']); $this->assertEquals('donut', $chart->getType()); } /** @test */ - public function it_tests_larapex_can_render_radial_bar_charts() + public function testRadialChart() { $chart = (new Chart)->setType('radial') ->setTitle('Products with more profit') ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('products', 'radial', [60, 40, 79]); + ->setDataset('Products', 'radial', [60, 40, 79]); $this->assertEquals($chart, $chart->script()['chart']); $this->assertEquals('radial', $chart->getType()); } /** @test */ - public function it_tests_apexcharts_can_render_polar_chart() + public function testPolarChart() { $chart = (new Chart)->setType('polarArea') ->setTitle('Products with more profit') ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('polarArea', 'radial', [60, 40, 79]); + ->setDataset('Products', 'polarArea', [60, 40, 79]); $this->assertEquals($chart, $chart->script()['chart']); $this->assertEquals('polarArea', $chart->getType()); } /** @test */ - public function larapex_can_render_line_charts() + public function testLineChart() { $chart = (new Chart)->setType('line') ->setTitle('Total Users Monthly') @@ -79,7 +75,7 @@ public function larapex_can_render_line_charts() ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset('line', 'users', [ + ->setDataset('Users', 'line', [ [ 'name' => 'Active Users', 'data' => [250, 700, 1200] @@ -95,7 +91,7 @@ public function larapex_can_render_line_charts() } /** @test */ - public function it_tests_apexcharts_can_create_an_area_chart() + public function testAreaChart() { $chart = (new Chart)->setType('area') ->setTitle('Total Users Monthly') @@ -103,7 +99,7 @@ public function it_tests_apexcharts_can_create_an_area_chart() ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset('area', 'users', [ + ->setDataset('Users', 'area', [ [ 'name' => 'Active Users', 'data' => [250, 700, 1200] @@ -120,12 +116,12 @@ public function it_tests_apexcharts_can_create_an_area_chart() } /** @test */ - public function it_tests_apexcharts_can_render_bar_charts() + public function testBarChart() { $chart = (new Chart)->setType('bar') ->setTitle('Net Profit') ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('bar', 'profit', [ + ->setDataset('Net Profit', 'bar', [ [ 'name' => 'Company A', 'data' => [500, 1000, 1900] @@ -158,13 +154,13 @@ public function it_tests_apexcharts_can_render_bar_charts() } /** @test */ - public function it_tests_apexcharts_can_render_horizontal_bar_chart() + public function testHorizontalBarChart() { $chart = (new Chart)->setType('bar') ->setTitle('Net Profit') ->setHorizontal(true) ->setSeries(['Jan', 'Feb', 'Mar']) - ->setDataset('bar', 'profit', [ + ->setDataset('Net Profit', 'bar', [ [ 'name' => 'Company A', 'data' => [500, 1000, 1900] @@ -186,14 +182,14 @@ public function it_tests_apexcharts_can_render_horizontal_bar_chart() } /** @test */ - public function it_tests_apexcharts_can_render_heatmap_chart() + public function testHeatmapChart() { $chart = (new Chart)->setType('heatmap') ->setTitle('Total Users') ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset('heatmap', 'users', [ + ->setDataset('Users', 'heatmap', [ [ 'name' => 'Users of Basic Plan', 'data' => [250, 700, 1200] @@ -210,14 +206,14 @@ public function it_tests_apexcharts_can_render_heatmap_chart() } /** @test */ - public function it_tests_apexcharts_can_render_radar_chart() + public function testRadarChart() { $chart = (new Chart)->setType('radar') ->setTitle('Total Users') ->setSeries([ 'Jan', 'Feb', 'Mar' ]) - ->setDataset('radar', 'users', [ + ->setDataset('Users', 'radar', [ [ 'name' => 'Users of Basic Plan', 'data' => [250, 700, 1200] From e21687886162efb3717efc5cab57943eed20b366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 24 Jun 2022 15:24:10 +0300 Subject: [PATCH 08/30] Fixed options some option function method issue solved. --- src/Chart.php | 5 ++-- src/Views/script.blade copy.php | 43 --------------------------------- src/Views/script.blade.php | 2 +- 3 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 src/Views/script.blade copy.php diff --git a/src/Chart.php b/src/Chart.php index 7e2d5b6..65bb014 100644 --- a/src/Chart.php +++ b/src/Chart.php @@ -24,6 +24,7 @@ use Akaunting\Apexcharts\Support\DatasetClass; use Akaunting\Apexcharts\Traits\Formatter; use Akaunting\Apexcharts\Traits\Types; +use Balping\JsonRaw\Encoder; use Illuminate\Support\Collection; use Illuminate\Support\Facades\View as ViewFacade; use Illuminate\View\View; @@ -182,9 +183,9 @@ public function setOptions(array|Collection $options = [], bool $overwrite = fal return $this; } - public function getOptions(): array + public function getOptions(): string { - return $this->options; + return Encoder::encode($this->options); } public function container(string $container = null): Chart|View diff --git a/src/Views/script.blade copy.php b/src/Views/script.blade copy.php deleted file mode 100644 index 5b5770a..0000000 --- a/src/Views/script.blade copy.php +++ /dev/null @@ -1,43 +0,0 @@ - diff --git a/src/Views/script.blade.php b/src/Views/script.blade.php index 53af546..ba9e23b 100644 --- a/src/Views/script.blade.php +++ b/src/Views/script.blade.php @@ -1,5 +1,5 @@ +``` + +Then, create an instance of `Chart` and call `toVue()` when passing it to your page: + +```php +Route::get('dashboard', function () { + $chart = (new Chart)->setType('...'); + + return inertia('dashboard', [ + 'chart' => $chart->toVue(), + ]); +}); +``` + +Finally, render the chart: + +```vue + + + + + +``` + ## Testing ```bash From 506e3e6b166b44f22f06b821deadb8039c3cfd1b Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Tue, 2 Apr 2024 11:52:46 -0400 Subject: [PATCH 28/30] Add npm install docs --- README.md | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dae4844..24d10d9 100644 --- a/README.md +++ b/README.md @@ -75,10 +75,32 @@ Finally, call the `container` and `script` method wherever you want to display t ### Vue -If you're using Vue and Inertia, create a simple `chart.vue` component: +If you're using Vue and Inertia, install Apexcharts and their Vue 3 adapter: + +```bash +npm install --save apexcharts +npm install --save vue3-apexcharts +``` + +```js +// resources/js/app.js + +import VueApexCharts from 'vue3-apexcharts'; + +createInertiaApp({ + // ... + setup({el, App, props, plugin}) { + return createApp({ render: () => h(App, props) }) + .use(VueApexCharts) + .mount(el); + }, +}); +``` + +Then, create a simple `chart.vue` component: ```vue - +