diff --git a/.idea/larapex-charts.iml b/.idea/larapex-charts.iml
index d26b5dc..4d02413 100644
--- a/.idea/larapex-charts.iml
+++ b/.idea/larapex-charts.iml
@@ -118,6 +118,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/php.xml b/.idea/php.xml
index ee40c77..21db12d 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -112,9 +112,19 @@
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results
new file mode 100644
index 0000000..2450d5a
--- /dev/null
+++ b/.phpunit.cache/test-results
@@ -0,0 +1 @@
+{"version":1,"defects":[],"times":{"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_bar_charts":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_pie_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_heatmap_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_create_an_area_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_horizontal_bar_chart":0.001,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_stacked_bar_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::larapex_can_render_line_charts":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_polar_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_pie_charts_by_default":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_donut_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_can_render_radial_bar_charts":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Feature\\ChartsTest::it_tests_larapex_charts_can_render_radar_chart":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Unit\\ChartsTest::it_tests_larapex_charts_can_load_script_correctly":0.019,"ArielMejiaDev\\LarapexCharts\\Tests\\Unit\\ChartsTest::it_tests_larapex_charts_can_change_default_config_colors":0.001,"ArielMejiaDev\\LarapexCharts\\Tests\\Unit\\ChartsTest::it_tests_larapex_chart_cdn_returns_a_correct_url":0,"ArielMejiaDev\\LarapexCharts\\Tests\\Unit\\ChartsTest::it_tests_larapex_charts_install_add_chart_stubs":0.04}}
\ No newline at end of file
diff --git a/build/report.junit.xml b/build/report.junit.xml
new file mode 100644
index 0000000..3a9c848
--- /dev/null
+++ b/build/report.junit.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index f55add8..b2b223b 100644
--- a/composer.json
+++ b/composer.json
@@ -17,13 +17,14 @@
}
],
"require": {
- "php": "^7.4|^8.0",
- "illuminate/support": "^8.0|^9.0",
+ "php": "^7.4|^8.0|^8.2",
+ "illuminate/support": "^8.0|^9.0|^10.0",
"ext-json": "*"
},
"require-dev": {
- "orchestra/testbench": "^6.0",
- "phpunit/phpunit": "^9.0"
+ "orchestra/testbench": "^6.0|^7.0|^8.0",
+ "phpunit/phpunit": "^9.0|^10.0",
+ "nunomaduro/collision": "^7.5"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
deleted file mode 100644
index 07386bc..0000000
--- a/phpunit.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- ./tests/Unit
-
-
-
- ./tests/Feature
-
-
-
-
- ./src
-
-
-
-
-
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..cfd42cb
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,23 @@
+
+
+
+
+ tests
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak
new file mode 100644
index 0000000..b27abe1
--- /dev/null
+++ b/phpunit.xml.dist.bak
@@ -0,0 +1,36 @@
+
+
+
+
+ tests
+
+
+
+
+ ./src
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/LarapexChart.php b/src/LarapexChart.php
index 8d13834..f2dcb48 100644
--- a/src/LarapexChart.php
+++ b/src/LarapexChart.php
@@ -15,28 +15,29 @@ class LarapexChart
|
*/
- public $id;
- protected $title;
- protected $subtitle;
- protected $subtitlePosition;
- protected $type = 'donut';
- protected $labels;
- protected $fontFamily;
- protected $foreColor;
- protected $dataset;
- protected $height = 500;
- protected $width;
- protected $colors;
- protected $horizontal;
- protected $xAxis;
- protected $grid;
- protected $markers;
- protected $stroke;
- protected $toolbar;
- protected $zoom;
- protected $dataLabels;
- protected $sparkline;
- private $chartLetters = 'abcdefghijklmnopqrstuvwxyz';
+ public string $id;
+ protected string $title = '';
+ protected string $subtitle = '';
+ protected string $subtitlePosition = 'left';
+ protected string $type = 'donut';
+ protected array $labels = [];
+ protected string $fontFamily;
+ protected string $foreColor;
+ protected string $dataset = '';
+ protected int $height = 500;
+ protected int|string $width = '100%';
+ protected string $colors;
+ protected string $horizontal;
+ protected string $xAxis;
+ protected string $grid;
+ protected string $markers;
+ protected bool $stacked = false;
+ protected string $stroke = '';
+ protected string $toolbar;
+ protected string $zoom;
+ protected string $dataLabels;
+ protected string $sparkline;
+ private string $chartLetters = 'abcdefghijklmnopqrstuvwxyz';
/*
|--------------------------------------------------------------------------
@@ -58,7 +59,6 @@ public function __construct()
$this->sparkline = json_encode(['enabled' => false]);
$this->fontFamily = config('larapex-charts.font_family');
$this->foreColor = config('larapex-charts.font_color');
- return $this;
}
public function pieChart() :PieChart
@@ -141,7 +141,7 @@ public function setFontColor($fontColor) :LarapexChart
return $this;
}
- public function setDataset($dataset): LarapexChart
+ public function setDataset(array $dataset): LarapexChart
{
$this->dataset = json_encode($dataset);
return $this;
@@ -261,17 +261,19 @@ public function setSparkline(bool $enabled = true): LarapexChart
return $this;
}
+ public function setStacked(bool $stacked = true): LarapexChart
+ {
+ $this->stacked = $stacked;
+ return $this;
+ }
+
/*
|--------------------------------------------------------------------------
| Getters
|--------------------------------------------------------------------------
*/
- /**
- * @param array $array
- * @return array|false|string
- */
- public function transformLabels(array $array)
+ public function transformLabels(array $array): bool|string
{
$stringArray = array_filter($array, function($string){
return "{$string}";
@@ -279,18 +281,12 @@ public function transformLabels(array $array)
return json_encode(['"' . implode('","', $stringArray) . '"']);
}
- /**
- * @return mixed
- */
- public function container()
+ public function container(): mixed
{
return View::make('larapex-charts::chart.container', ['id' => $this->id()]);
}
- /**
- * @return mixed
- */
- public function script()
+ public function script(): mixed
{
return View::make('larapex-charts::chart.script', ['chart' => $this]);
}
@@ -300,81 +296,51 @@ public static function cdn() :string
return 'https://cdn.jsdelivr.net/npm/apexcharts';
}
- /**
- * @return false|string
- */
- public function id()
+ public function id(): string
{
return $this->id;
}
- /**
- * @return mixed
- */
- public function title()
+ public function title(): string
{
return $this->title;
}
- /**
- * @return mixed
- */
- public function subtitle()
+ public function subtitle(): string
{
return $this->subtitle;
}
- /**
- * @return mixed
- */
- public function subtitlePosition()
+ public function subtitlePosition(): string
{
return $this->subtitlePosition;
}
- /**
- * @return string
- */
- public function type()
+ public function type(): string
{
return $this->type;
}
- /**
- * @return string
- */
- public function fontFamily()
- {
+ public function fontFamily(): string
+ {
return $this->fontFamily;
}
- /**
- * @return string
- */
- public function foreColor()
+ public function foreColor(): string
{
return $this->foreColor;
}
- /**
- * @return mixed
- */
- public function labels()
+ public function labels(): array
{
return $this->labels;
}
- /**
- * @return mixed
- */
- public function dataset()
+ public function dataset(): string
{
return $this->dataset;
}
- /**
- * @return int
- */
public function height() :int
{
return $this->height;
@@ -382,96 +348,71 @@ public function height() :int
public function width() :string
{
- return $this->width ? $this->width : '100%';
+ return $this->width;
}
- /**
- * @return false|string
- */
- public function colors()
+ public function colors(): bool|string
{
return $this->colors;
}
- /**
- * @return false|string
- */
- public function horizontal()
+ public function horizontal(): bool|string
{
return $this->horizontal;
}
- /**
- * @return mixed
- */
- public function xAxis()
+ public function xAxis(): string
{
return $this->xAxis;
}
- /**
- * @return false|string
- */
- public function grid()
+ public function grid(): bool|string
{
return $this->grid;
}
- /**
- * @return false|string
- */
- public function markers()
+ public function markers(): bool|string
{
return $this->markers;
}
- /**
- * @return mixed
- */
- public function stroke()
+ public function stroke(): string
{
return $this->stroke;
}
- /**
- * @return true|boolean
- */
- public function toolbar()
+ public function toolbar(): bool|string
{
return $this->toolbar;
}
- /**
- * @return true|boolean
- */
- public function zoom()
+ public function zoom(): bool|string
{
return $this->zoom;
}
- /**
- * @return true|boolean
- */
- public function dataLabels()
+ public function dataLabels(): bool|string
{
return $this->dataLabels;
}
- /**
- * @return true|boolean
- */
- public function sparkline()
+ public function sparkline(): bool|string
{
return $this->sparkline;
}
+ public function stacked(): bool
+ {
+ return $this->stacked;
+ }
+
/*
|--------------------------------------------------------------------------
- | JSON Helper
+ | JSON Options Builder
|--------------------------------------------------------------------------
*/
- public function toJson()
+ public function toJson(): \Illuminate\Http\JsonResponse
{
$options = [
'chart' => [
@@ -483,6 +424,7 @@ public function toJson()
'fontFamily' => json_decode($this->fontFamily()),
'foreColor' => $this->foreColor(),
'sparkline' => $this->sparkline(),
+ 'stacked' => $this->stacked(),
],
'plotOptions' => [
'bar' => json_decode($this->horizontal()),
@@ -518,6 +460,12 @@ public function toJson()
]);
}
+ /*
+ |--------------------------------------------------------------------------
+ | Vue Options Builder
+ |--------------------------------------------------------------------------
+ */
+
public function toVue() :array
{
$options = [
@@ -528,6 +476,7 @@ public function toVue() :array
'fontFamily' => json_decode($this->fontFamily()),
'foreColor' => $this->foreColor(),
'sparkline' => json_decode($this->sparkline()),
+ 'stacked' => $this->stacked(),
],
'plotOptions' => [
'bar' => json_decode($this->horizontal()),
@@ -564,5 +513,4 @@ public function toVue() :array
'series' => json_decode($this->dataset()),
];
}
-
}
diff --git a/src/Traits/ComplexChartDataAggregator.php b/src/Traits/ComplexChartDataAggregator.php
index 1c00c58..e1fd3e0 100644
--- a/src/Traits/ComplexChartDataAggregator.php
+++ b/src/Traits/ComplexChartDataAggregator.php
@@ -6,14 +6,14 @@ trait ComplexChartDataAggregator
{
public function addData(string $name, array $data) :self
{
- $this->dataset = json_decode($this->dataset);
+ $dataset = json_decode($this->dataset);
- $this->dataset[] = [
+ $dataset[] = [
'name' => $name,
'data' => $data
];
- $this->dataset = json_encode($this->dataset);
+ $this->dataset = json_encode($dataset);
return $this;
}
diff --git a/src/Traits/SimpleChartDataAggregator.php b/src/Traits/SimpleChartDataAggregator.php
index c909916..12145c9 100644
--- a/src/Traits/SimpleChartDataAggregator.php
+++ b/src/Traits/SimpleChartDataAggregator.php
@@ -10,9 +10,7 @@ trait SimpleChartDataAggregator
{
public function addData(array $data) :self
{
- $this->dataset = $data;
-
- $this->dataset = json_encode($this->dataset);
+ $this->dataset = json_encode($data);
return $this;
}
diff --git a/stubs/resources/views/chart/script.blade.php b/stubs/resources/views/chart/script.blade.php
index 1272423..17ba356 100644
--- a/stubs/resources/views/chart/script.blade.php
+++ b/stubs/resources/views/chart/script.blade.php
@@ -9,7 +9,10 @@
zoom: {!! $chart->zoom() !!},
fontFamily: '{!! $chart->fontFamily() !!}',
foreColor: '{!! $chart->foreColor() !!}',
- sparkline: {!! $chart->sparkline() !!}
+ sparkline: {!! $chart->sparkline() !!},
+ @if($chart->stacked())
+ stacked: {!! $chart->stacked() !!},
+ @endif
},
plotOptions: {
bar: {!! $chart->horizontal() !!}
diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php
index 51190d5..eda205e 100644
--- a/tests/Feature/ChartsTest.php
+++ b/tests/Feature/ChartsTest.php
@@ -9,7 +9,7 @@ class ChartsTest extends TestCase
use RefreshDatabase;
/** @test */
- public function it_tests_larapex_charts_can_render_pie_charts_by_default()
+ public function it_tests_larapex_charts_can_render_pie_charts_by_default(): void
{
$chart = (new LarapexChart)->setTitle('Users Test Chart');
$this->assertEquals('donut', $chart->type());
@@ -18,7 +18,7 @@ public function it_tests_larapex_charts_can_render_pie_charts_by_default()
}
/** @test */
- public function it_tests_larapex_charts_can_render_pie_chart()
+ public function it_tests_larapex_charts_can_render_pie_chart(): void
{
$chart = (new LarapexChart)->pieChart()
->setTitle('Posts')
@@ -32,7 +32,7 @@ public function it_tests_larapex_charts_can_render_pie_chart()
}
/** @test */
- public function it_tests_larapex_charts_can_render_donut_chart()
+ public function it_tests_larapex_charts_can_render_donut_chart(): void
{
$chart = (new LarapexChart)->donutChart()
->setTitle('Posts')
@@ -44,7 +44,7 @@ public function it_tests_larapex_charts_can_render_donut_chart()
}
/** @test */
- public function it_tests_larapex_can_render_radial_bar_charts()
+ public function it_tests_larapex_can_render_radial_bar_charts(): void
{
$chart = (new LarapexChart)->radialChart()
->setTitle('Products with more profit')
@@ -56,7 +56,7 @@ public function it_tests_larapex_can_render_radial_bar_charts()
}
/** @test */
- public function it_tests_larapex_charts_can_render_polar_chart()
+ public function it_tests_larapex_charts_can_render_polar_chart(): void
{
$chart = (new LarapexChart)->polarAreaChart()
->setTitle('Products with more profit')
@@ -68,7 +68,7 @@ public function it_tests_larapex_charts_can_render_polar_chart()
}
/** @test */
- public function larapex_can_render_line_charts()
+ public function larapex_can_render_line_charts(): void
{
$chart = (new LarapexChart)->lineChart()
->setTitle('Total Users Monthly')
@@ -87,12 +87,12 @@ public function larapex_can_render_line_charts()
->setStroke(1);
$this->assertEquals($chart->id(), $chart->container()['id']);
- $this->assertEquals( $chart, $chart->script()['chart']);
+ $this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('line', $chart->type());
}
/** @test */
- public function it_tests_larapex_charts_can_create_an_area_chart()
+ public function it_tests_larapex_charts_can_create_an_area_chart(): void
{
$chart = (new LarapexChart)->areaChart()
->setTitle('Total Users Monthly')
@@ -117,7 +117,7 @@ public function it_tests_larapex_charts_can_create_an_area_chart()
}
/** @test */
- public function it_tests_larapex_charts_can_render_bar_charts()
+ public function it_tests_larapex_charts_can_render_bar_charts(): void
{
$chart = (new LarapexChart)->barChart()
->setTitle('Net Profit')
@@ -155,7 +155,35 @@ public function it_tests_larapex_charts_can_render_bar_charts()
}
/** @test */
- public function it_tests_larapex_charts_can_render_horizontal_bar_chart()
+ public function it_tests_larapex_charts_can_render_stacked_bar_chart(): void
+ {
+ $chart = (new LarapexChart)->barChart()
+ ->setTitle('Net Profit')
+ ->setStacked(true)
+ ->setXAxis(['Jan', 'Feb', 'Mar'])
+ ->setDataset([
+ [
+ 'name' => 'Company A',
+ 'data' => [500, 1000, 1900]
+ ],
+ [
+ 'name' => 'Company B',
+ 'data' => [300, 800, 1400]
+ ],
+ [
+ 'name' => 'Company C',
+ 'data' => [304, 231, 500]
+ ]
+ ]);
+
+ $this->assertEquals($chart->id(), $chart->container()['id']);
+ $this->assertEquals($chart, $chart->script()['chart']);
+ $this->assertEquals('bar', $chart->type());
+ $this->assertTrue($chart->stacked());
+ }
+
+ /** @test */
+ public function it_tests_larapex_charts_can_render_horizontal_bar_chart(): void
{
$chart = (new LarapexChart)->barChart()
->setTitle('Net Profit')
@@ -184,7 +212,7 @@ public function it_tests_larapex_charts_can_render_horizontal_bar_chart()
}
/** @test */
- public function it_tests_larapex_charts_can_render_heatmap_chart()
+ public function it_tests_larapex_charts_can_render_heatmap_chart(): void
{
$chart = (new LarapexChart)->heatMapChart()
->setTitle('Total Users')
@@ -208,7 +236,7 @@ public function it_tests_larapex_charts_can_render_heatmap_chart()
}
/** @test */
- public function it_tests_larapex_charts_can_render_radar_chart()
+ public function it_tests_larapex_charts_can_render_radar_chart(): void
{
$chart = (new LarapexChart)->radarChart()
->setTitle('Total Users')
diff --git a/tests/TestCase.php b/tests/TestCase.php
index d431371..ca59a0e 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -11,7 +11,7 @@ class TestCase extends TestbenchTestCase
* @param [type] $app
* @return void
*/
- protected function getEnvironmentSetUp($app)
+ protected function getEnvironmentSetUp($app): void
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connection.testing', [
@@ -32,7 +32,7 @@ protected function getPackageProviders($app): array
protected function getPackageAliases($app): array
{
return [
- 'FirstPackage' => \ArielMejiaDev\LarapexCharts\Facades\LarapexChart::class
+ 'LarapexChart' => \ArielMejiaDev\LarapexCharts\Facades\LarapexChart::class
];
}
diff --git a/tests/Unit/ChartsTest.php b/tests/Unit/ChartsTest.php
index b37f3b6..df9646f 100644
--- a/tests/Unit/ChartsTest.php
+++ b/tests/Unit/ChartsTest.php
@@ -1,13 +1,13 @@
each(function ($chart) {
- $this->assertTrue(
- file_exists(base_path("stubs/charts/Default/{$chart}.stub"))
+ $this->assertFileExists(
+ base_path("stubs/charts/Default/{$chart}.stub")
);
- $this->assertTrue(
- file_exists(base_path("stubs/charts/Vue/{$chart}.stub"))
+ $this->assertFileExists(
+ base_path("stubs/charts/Vue/{$chart}.stub")
);
- $this->assertTrue(
- file_exists(base_path("stubs/charts/Json/{$chart}.stub"))
+ $this->assertFileExists(
+ base_path("stubs/charts/Json/{$chart}.stub")
);
});
}
/** @test */
- public function it_tests_larapex_charts_can_load_script_correctly()
+ public function it_tests_larapex_charts_can_load_script_correctly(): void
{
$chart = (new LarapexChart)
->setTitle('Posts')
@@ -52,7 +52,7 @@ public function it_tests_larapex_charts_can_load_script_correctly()
}
/** @test */
- public function it_tests_larapex_charts_can_change_default_config_colors()
+ public function it_tests_larapex_charts_can_change_default_config_colors(): void
{
$chart = (new LarapexChart)->setTitle('Posts')->setXAxis(['Jan', 'Feb', 'Mar'])->setDataset([150, 120]);
$oldColors = $chart->colors();
@@ -61,7 +61,7 @@ public function it_tests_larapex_charts_can_change_default_config_colors()
}
/** @test */
- public function it_tests_larapex_chart_cdn_returns_a_correct_url()
+ public function it_tests_larapex_chart_cdn_returns_a_correct_url(): void
{
$this->assertEquals('https://cdn.jsdelivr.net/npm/apexcharts' , (new LarapexChart)->cdn());
}