Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona authored and github-actions[bot] committed Oct 7, 2022
1 parent fbd1130 commit f5f8d09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/Charts/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +19,7 @@ abstract class Chart
private array $options = [];

/**
* @param Dataset[]|Collection<int, Dataset>|Dataset $datasets
* @param Dataset[]|Collection<int, Dataset>|Dataset $datasets
*/
public function __construct(array|Collection|Dataset $datasets)
{
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 14 additions & 6 deletions src/Data/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,8 +27,7 @@ public static function make(string $label): self
}

/**
* @param int|float|array<array-key, int|float>|Collection<array-key, int|float> $data
*
* @param int|float|array<array-key, int|float>|Collection<array-key, int|float> $data
* @return $this
*/
public function data(int|float|array|Collection $data): self
Expand All @@ -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;
}

Expand All @@ -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();
}
}
6 changes: 1 addition & 5 deletions src/Uncharted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Dataset>|Dataset $datasets
* @param Dataset[]|Collection<int, Dataset>|Dataset $datasets
*/
public function line(array|Collection|Dataset $datasets): LineChart
{
Expand Down

0 comments on commit f5f8d09

Please sign in to comment.