|null */ private ?Models $collections = null; public function getHeading(): string { return __('admin.dashboard.collection_chart'); } public function getDescription(): string { return __('admin.dashboard.chart_description', ['limit' => Number::format(self::LIMIT, locale: 'fa')]); } public function getEmptyStateHeading(): string { return __('admin.dashboard.empty_chart'); } protected function getData(): array { $collections = $this->collections(); if (! $collections->max('designs_count')) { return []; } return [ 'labels' => $collections->map(fn (Collection $collection): string => Str::limit($collection->name_fa, 22))->all(), 'datasets' => [ [ 'label' => __('admin.dashboard.on_site'), 'data' => $collections->pluck('visible_count')->all(), 'backgroundColor' => '#ad263f', 'maxBarThickness' => 24, ], [ 'label' => __('admin.dashboard.off_site'), 'data' => $collections->map(fn (Collection $collection): int => $collection->designs_count - $collection->visible_count)->all(), 'backgroundColor' => '#90827b', 'maxBarThickness' => 24, ], ], ]; } public function getChartAssistiveContent(): string { return $this->collections()->map(fn (Collection $collection): string => __('admin.dashboard.chart_row', [ 'name' => $collection->name_fa, 'visible' => Number::format($collection->visible_count, locale: 'fa'), 'hidden' => Number::format($collection->designs_count - $collection->visible_count, locale: 'fa'), ]))->implode(' '); } protected function getOptions(): array { return [ 'indexAxis' => 'y', 'locale' => 'fa-IR', 'scales' => [ 'x' => ['stacked' => true, 'reverse' => true, 'beginAtZero' => true, 'ticks' => ['precision' => 0]], 'y' => ['stacked' => true, 'position' => 'right', 'ticks' => ['autoSkip' => false]], ], 'plugins' => [ 'legend' => ['rtl' => true, 'textDirection' => 'rtl'], 'tooltip' => ['rtl' => true, 'textDirection' => 'rtl'], ], ]; } /** @return Models */ private function collections(): Models { return $this->collections ??= Collection::query() ->withCount(['designs', 'designs as visible_count' => fn (Builder $query) => $query->visible()]) ->orderByDesc('designs_count') ->orderBy('id') ->limit(self::LIMIT) ->get(); } }