You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a need to group the trend by a particular column (for use in a stacked bar chart). I extended the class to permit a ->groupBy('type') on the Trend definition; the resulting trend is an array of trend data for each value of the type field. Is there any interest in working this up for inclusion in the package?
<?php
use Flowframe\Trend\Trend;
use Illuminate\Support\Collection;
class GroupedTrend extends Trend
{
public string $groupColumn;
public function groupBy(string $groupColumn): self
{
$this->groupColumn = $groupColumn;
return $this;
}
public function aggregate(string $column, string $aggregate): Collection
{
$values = $this->builder
->toBase()
->selectRaw("
{$this->getSqlDate()} as {$this->dateAlias},
{$aggregate}({$column}) as aggregate,
{$this->groupColumn} as group
")
->whereBetween($this->dateColumn, [$this->start, $this->end])
->groupBy($this->dateAlias, $this->groupColumn)
->orderBy($this->dateAlias)
->get();
return $values->groupBy('group')
->map(fn($group) => $this->mapValuesToDates($group));
}
}
The text was updated successfully, but these errors were encountered:
We have a need to group the trend by a particular column (for use in a stacked bar chart). I extended the class to permit a
->groupBy('type')
on the Trend definition; the resulting trend is an array of trend data for each value of thetype
field. Is there any interest in working this up for inclusion in the package?The text was updated successfully, but these errors were encountered: