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

how to disable autorefresh?

Open niunaiyi opened this issue 3 years ago • 8 comments

click any resource. "NovaServiceProvider" return "Cards", and nova-chartsjs will draw again, it waste time too much

niunaiyi avatar Oct 01 '20 04:10 niunaiyi

Hi, @niunaiyi . Can you please add more detail what happened and your request? Also it will be much help if you can share image or screenrecord(video) about it.

coroo avatar Oct 01 '20 12:10 coroo

https://coroo.github.io/nova-chartjs/assets/img/code-chart-bar.png

I get data from DB for series function.

NovaServiceProvider will return Cards several times when i click any Resource,
then nova-chartjs will get data from DB several times. its not necessary。

sorry for my English.

niunaiyi avatar Oct 01 '20 15:10 niunaiyi

https://github.com/insenseanalytics/nova-bar-metrics this project use "Partition" and his calcualte function to avoid. sorry for my English again.

niunaiyi avatar Oct 01 '20 15:10 niunaiyi

could u give me some help?

niunaiyi avatar Oct 02 '20 16:10 niunaiyi

Hi @niunaiyi , sorry for late response. So what I understand is, you use custom bar-chart https://coroo.github.io/nova-chartjs/#/?id=bar-chart. But unfortunately, the nova-chartjs still call data from db, am I right?

coroo avatar Oct 02 '20 23:10 coroo

looks like this:

class NovaServiceProvider extends NovaApplicationServiceProvider {

/**
 * Get the cards that should be displayed on the default Nova dashboard.
 *
 * @return array
 */
protected function cards()
{
	\Log::info('return cards');
	$data = getDataFromDB();
	$style = ...;
	$options = ...;
	return [
		(new LineChart())
		  ->title('title')
		  ->series($data, $style)
		  ->options($options)
		  ->width('full'),
	];
}

}

when i click any menu, NovaServiceProvider will return Cards serval times, then getDataFromDB will be called serval times.

[2020-10-02 22:56:07] local.INFO: return cards
[2020-10-02 22:56:07] local.INFO: return cards
[2020-10-02 22:56:08] local.INFO: return cards
[2020-10-02 22:56:08] local.INFO: return cards
[2020-10-02 22:56:08] local.INFO: return cards
[2020-10-02 22:56:08] local.INFO: return cards

niunaiyi avatar Oct 02 '20 23:10 niunaiyi

Atfer I see the documentation at laravel nova. There is an issue about that: in here, which is still in development stage in laravel nova. The best answer for now is, you can use hotfix from ibrunotome:

protected function cards()
{
   if (request()->is('nova-api/dashboards*')) { // your dashboard url
	\Log::info('return cards');
	$data = getDataFromDB();
	$style = ...;
	$options = ...;
	return [
		(new LineChart())
		  ->title('title')
		  ->series($data, $style)
		  ->options($options)
		  ->width('full'),
	];
    }
}

hope this help you

coroo avatar Oct 02 '20 23:10 coroo

wow,thanks very much.

niunaiyi avatar Oct 03 '20 04:10 niunaiyi