From f5f8d09ba5e0791672c382ed3e372db2b5b63fe9 Mon Sep 17 00:00:00 2001 From: fabio-ivona Date: Fri, 7 Oct 2022 09:46:53 +0000 Subject: [PATCH] Fix styling --- src/Charts/Chart.php | 6 +++--- src/Data/Dataset.php | 20 ++++++++++++++------ src/Uncharted.php | 6 +----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Charts/Chart.php b/src/Charts/Chart.php index 265b927..4d7e2fb 100644 --- a/src/Charts/Chart.php +++ b/src/Charts/Chart.php @@ -3,7 +3,6 @@ namespace DefStudio\Uncharted\Charts; use DefStudio\Uncharted\Data\Dataset; -use Dflydev\DotAccessData\Data; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; @@ -20,7 +19,7 @@ abstract class Chart private array $options = []; /** - * @param Dataset[]|Collection|Dataset $datasets + * @param Dataset[]|Collection|Dataset $datasets */ public function __construct(array|Collection|Dataset $datasets) { @@ -52,11 +51,12 @@ public function time(string $unit): self } /** - * @param string[] $labels + * @param string[] $labels */ public function labels(array $labels): self { $this->labels = $labels; + return $this; } diff --git a/src/Data/Dataset.php b/src/Data/Dataset.php index 9ddface..da83307 100644 --- a/src/Data/Dataset.php +++ b/src/Data/Dataset.php @@ -8,9 +8,13 @@ class Dataset { private array $data = []; + private string $borderColor; + private string $backgroundColor; + private string $textColor; + private float $tension = 1.0; private function __construct(private readonly string $label) @@ -23,8 +27,7 @@ public static function make(string $label): self } /** - * @param int|float|array|Collection $data - * + * @param int|float|array|Collection $data * @return $this */ public function data(int|float|array|Collection $data): self @@ -36,30 +39,35 @@ public function data(int|float|array|Collection $data): self foreach (Arr::wrap($data) as $datum) { $this->data[] = $datum; } + return $this; } public function borderColor(string $color): self { $this->borderColor = $color; + return $this; } public function textColor(string $color): self { $this->textColor = $color; + return $this; } public function backgroundColor(string $color): self { $this->backgroundColor = $color; + return $this; } public function tension(float $tension): self { $this->tension = $tension; + return $this; } @@ -69,10 +77,10 @@ public function config(): array $backgroundColor = $this->backgroundColor ?? $this->borderColor ?? null; return collect(['label' => $this->label, 'data' => $this->data]) - ->when($borderColor, fn(Collection $collection) => $collection->put('borderColor', $borderColor)) - ->when($backgroundColor, fn(Collection $collection) => $collection->put('backgroundColor', $backgroundColor)) - ->when(isset($this->textColor), fn(Collection $collection) => $collection->put('color', $this->textColor)) - ->when(isset($this->tension), fn(Collection $collection) => $collection->put('tension', $this->tension)) + ->when($borderColor, fn (Collection $collection) => $collection->put('borderColor', $borderColor)) + ->when($backgroundColor, fn (Collection $collection) => $collection->put('backgroundColor', $backgroundColor)) + ->when(isset($this->textColor), fn (Collection $collection) => $collection->put('color', $this->textColor)) + ->when(isset($this->tension), fn (Collection $collection) => $collection->put('tension', $this->tension)) ->toArray(); } } diff --git a/src/Uncharted.php b/src/Uncharted.php index 2beab74..b954a62 100755 --- a/src/Uncharted.php +++ b/src/Uncharted.php @@ -2,18 +2,14 @@ namespace DefStudio\Uncharted; - -use DefStudio\Uncharted\Charts\Chart; use DefStudio\Uncharted\Charts\LineChart; use DefStudio\Uncharted\Data\Dataset; -use Dflydev\DotAccessData\Data; use Illuminate\Support\Collection; -use Illuminate\Support\HtmlString; class Uncharted { /** - * @param Dataset[]|Collection|Dataset $datasets + * @param Dataset[]|Collection|Dataset $datasets */ public function line(array|Collection|Dataset $datasets): LineChart {