Skip to content

Commit

Permalink
Helper function for series name and ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBernskiold committed Aug 30, 2024
1 parent 48b77de commit a97211c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Data/Series.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public function withoutDataLabels(): self
return $this->set('dataLabels.enabled', false);
}

public function name(string $name): self
{
return $this->set('name', $name);
}

public function id(string $id): self
{
return $this->set('id', $id);
}

/**
* @param array<DataPoint|string|array> $data
*/
Expand All @@ -64,21 +74,21 @@ public function data(array $data): self

public function toArray(): array
{
$data = $this->options;
$series = $this->options;

if ($this->data) {
$data['data'] = collect($this->data)
$series['data'] = collect($this->data)
->map(fn ($dataPoint) => $dataPoint instanceof DataPoint
? $dataPoint->toArray()
: $dataPoint)
->toArray();
}

if ($this->type) {
$data['type'] = $this->type;
$series['type'] = $this->type;
}

return $data;
return $series;
}

public function dump(...$args)
Expand Down

0 comments on commit a97211c

Please sign in to comment.