nova-chartjs icon indicating copy to clipboard operation
nova-chartjs copied to clipboard

[Feature Request] Async charts for cases when data/series calculation is heavy (separate chart instantiation and calculation)

Open alies-dev opened this issue 4 years ago • 1 comments

Is your feature request related to a problem? Please describe. If a chart requires heavy to calculate data, the whole page will be empty unless data calculate. This is how response of available cards looks like (for dashboard, UEL example /nova-api/dashboards/users): image

Describe the solution you'd like What Nova does with their default charts is to serialise meta data about the Metric and then associated vue component produces a request to fetch data for the Metric.

I tried to use LineChart is the same fashion:

final class MembershipLifetimeLIneChart extends Metric

    /** This method is called by {@see \Laravel\Nova\Metrics\Metric::resolve} */
    public function calculate(Request $request): \JsonSerializable
    {
        return LineChart::make()
            ->title($this->name())
            ->series([
                [...

but it also requires to update vue components to support such behaviour: existing components can't parse metric metadata and then produce an API request.

Nova bug makes it even more important

For every request to a Metric, added to a dashboard, Nova calls public static function allAvailableDashboardCards(NovaRequest $request) that initialises all cards and metrics. In case of this package that means if you have 20 charts on a dashboard, Nova will initialise them 20*20 times. Of course, that means a lot of DB queries if you fetch info for charts from DB. Implementation of this feature will solve this problem: chart instantiation and calculation will be different processes

alies-dev avatar Jan 20 '22 10:01 alies-dev

I'm glad I saw this, thank you, I'll have to hold off on this package for now. I was wondering if this was the case given how the docs didn't suggest to build an object for each metric, but put it directly in the dashboard object itself...

bkuhl avatar Jan 04 '23 02:01 bkuhl