Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export default class StatisticsWidget extends DashboardWidget {
}
: this.periods![this.selectedPeriod!];
const periodLength = period.end - period.start;
const labels = [];
const labels: string[] = [];
const thisPeriod = [];
const lastPeriod = [];

Expand All @@ -361,7 +361,7 @@ export default class StatisticsWidget extends DashboardWidget {
labels.push(label);

thisPeriod.push(this.getPeriodCount(this.selectedEntity, { start: i, end: i + period.step }));
lastPeriod.push(this.getPeriodCount(this.selectedEntity, { start: i - periodLength, end: i - periodLength + period.step }));
lastPeriod.push(this.getPeriodCount(this.selectedEntity, { start: i - periodLength, end: i - periodLength }));
}

if (thisPeriod.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,15 @@ private function getTimedStatistics(string $model)

private function getTimedCounts(Builder $query, string $column, ?DateTime $startDate = null, ?DateTime $endDate = null)
{
$diff = $startDate && $endDate ? $startDate->diff($endDate) : null;

if (! isset($startDate)) {
$startDate = new DateTime('-365 days');
// need -12 months and period before that
$startDate = new DateTime('-2 years');
} else {
// If the start date is custom, we need to include an equal amount beforehand
// to show the data for the previous period.
$startDate = (new Carbon($startDate))->subtract($diff)->toDateTime();
}

if (! isset($endDate)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ public function can_request_timed_stats()
'users' => [
$timeStart->copy()->getTimestamp() => 1,
$timeStart->copy()->subDays(1)->getTimestamp() => 1,
$timeStart->copy()->subDays(2)->getTimestamp() => 1,
], 'discussions' => [
$timeStart->copy()->getTimestamp() => 1,
$timeStart->copy()->subDays(1)->getTimestamp() => 2,
$timeStart->copy()->subDays(2)->getTimestamp() => 1,
], 'posts' => [
$timeStart->copy()->getTimestamp() => 2,
$timeStart->copy()->subDays(1)->getTimestamp() => 2,
$timeStart->copy()->subDays(2)->getTimestamp() => 1,
]
];

Expand Down