From 3f4eaa4bc2f549dd8ecce0d381e6fa7e9a7292ef Mon Sep 17 00:00:00 2001 From: James Mills Date: Tue, 12 Jul 2022 11:41:13 +0400 Subject: [PATCH 1/2] Initial sparkline magic --- src/LarapexChart.php | 16 ++++++++++++++++ stubs/resources/views/chart/script.blade.php | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/LarapexChart.php b/src/LarapexChart.php index 283d50d..9d7d586 100644 --- a/src/LarapexChart.php +++ b/src/LarapexChart.php @@ -35,6 +35,7 @@ class LarapexChart protected $toolbar; protected $zoom; protected $dataLabels; + protected $sparklines; private $chartLetters = 'abcdefghijklmnopqrstuvwxyz'; /* @@ -54,6 +55,7 @@ public function __construct() $this->toolbar = json_encode(['show' => false]); $this->zoom = json_encode(['enabled' => true]); $this->dataLabels = json_encode(['enabled' => false]); + $this->sparklines = json_encode(['enabled' => false]); $this->fontFamily = json_encode(config('larapex-charts.font_family')); $this->foreColor = config('larapex-charts.font_color'); return $this; @@ -257,6 +259,12 @@ public function setDataLabels(bool $enabled = true) :LarapexChart return $this; } + public function setSparklines(bool $enabled = true): LarapexChart + { + $this->sparklines = json_encode(['enabled' => $enabled]); + return $this; + } + /* |-------------------------------------------------------------------------- | Getters @@ -453,6 +461,14 @@ public function dataLabels() return $this->dataLabels; } + /** + * @return true|boolean + */ + public function sparklines() + { + return $this->sparklines; + } + /* |-------------------------------------------------------------------------- | JSON Helper diff --git a/stubs/resources/views/chart/script.blade.php b/stubs/resources/views/chart/script.blade.php index d3fd028..51b9884 100644 --- a/stubs/resources/views/chart/script.blade.php +++ b/stubs/resources/views/chart/script.blade.php @@ -8,7 +8,8 @@ toolbar: {!! $chart->toolbar() !!}, zoom: {!! $chart->zoom() !!}, fontFamily: '{!! $chart->fontFamily() !!}', - foreColor: '{!! $chart->foreColor() !!}' + foreColor: '{!! $chart->foreColor() !!}', + sparkline: {!! $chart->sparklines() !!} }, plotOptions: { bar: {!! $chart->horizontal() !!} From 7583c0ac00b1e84703bf06b0ed890f51a00a2c11 Mon Sep 17 00:00:00 2001 From: James Mills Date: Tue, 12 Jul 2022 11:51:53 +0400 Subject: [PATCH 2/2] Adding data for toVue & toJson --- src/LarapexChart.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/LarapexChart.php b/src/LarapexChart.php index 9d7d586..fb7fe33 100644 --- a/src/LarapexChart.php +++ b/src/LarapexChart.php @@ -486,6 +486,7 @@ public function toJson() 'zoom' => json_decode($this->zoom()), 'fontFamily' => json_decode($this->fontFamily()), 'foreColor' => $this->foreColor(), + 'sparklines' => $this->sparklines(), ], 'plotOptions' => [ 'bar' => json_decode($this->horizontal()), @@ -530,6 +531,7 @@ public function toVue() :array 'zoom' => json_decode($this->zoom()), 'fontFamily' => json_decode($this->fontFamily()), 'foreColor' => $this->foreColor(), + 'sparkline' => json_decode($this->sparklines()), ], 'plotOptions' => [ 'bar' => json_decode($this->horizontal()),