diff --git a/src/DatesFunctions.php b/src/DatesFunctions.php index 457c246..b656675 100644 --- a/src/DatesFunctions.php +++ b/src/DatesFunctions.php @@ -206,7 +206,10 @@ protected function getLabelsData(): array $result = []; $labelColumn = explode('.', $this->labelColumn)[1]; - $missingDataLabels = DB::table($this->table)->get()->pluck($labelColumn)->toArray(); + + $missingDataLabels = empty($this->missingDataLabels) + ? DB::table($this->table)->get()->pluck($labelColumn)->toArray() + : $this->missingDataLabels; foreach ($missingDataLabels as $label) { $result[$label] = $this->missingDataValue; diff --git a/src/LaravelMetrics.php b/src/LaravelMetrics.php index 3439b6c..47d213c 100644 --- a/src/LaravelMetrics.php +++ b/src/LaravelMetrics.php @@ -51,6 +51,8 @@ class LaravelMetrics protected bool $fillMissingData = false; + protected array $missingDataLabels = []; + protected int $missingDataValue = 0; protected string $groupBy; @@ -441,10 +443,11 @@ public function labelColumn(string $column): self return $this; } - public function fillMissingData(int $missingDataValue = 0): self + public function fillMissingData(int $missingDataValue = 0, array $missingDataLabels = []): self { $this->fillMissingData = true; $this->missingDataValue = $missingDataValue; + $this->missingDataLabels = $missingDataLabels; return $this; } @@ -592,7 +595,7 @@ protected function asData(): string return "$this->aggregate($this->column) as data"; } - protected function asLabel(string $label = null, bool $format = true): string + protected function asLabel(?string $label = null, bool $format = true): string { if (is_null($this->labelColumn)) { $label = ! $format ? $label : $this->formatPeriod($label);