Commit 588955c7 by Daniel Lee

Merge branch 'jifwin-load_on_Scroll'

parents 4f06202e bd348a47
...@@ -12,6 +12,7 @@ import * as dateMath from 'app/core/utils/datemath'; ...@@ -12,6 +12,7 @@ import * as dateMath from 'app/core/utils/datemath';
import {Subject} from 'vendor/npm/rxjs/Subject'; import {Subject} from 'vendor/npm/rxjs/Subject';
class MetricsPanelCtrl extends PanelCtrl { class MetricsPanelCtrl extends PanelCtrl {
scope: any;
loading: boolean; loading: boolean;
datasource: any; datasource: any;
datasourceName: any; datasourceName: any;
...@@ -40,6 +41,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -40,6 +41,7 @@ class MetricsPanelCtrl extends PanelCtrl {
this.datasourceSrv = $injector.get('datasourceSrv'); this.datasourceSrv = $injector.get('datasourceSrv');
this.timeSrv = $injector.get('timeSrv'); this.timeSrv = $injector.get('timeSrv');
this.templateSrv = $injector.get('templateSrv'); this.templateSrv = $injector.get('templateSrv');
this.scope = $scope;
if (!this.panel.targets) { if (!this.panel.targets) {
this.panel.targets = [{}]; this.panel.targets = [{}];
......
...@@ -35,6 +35,8 @@ export class PanelCtrl { ...@@ -35,6 +35,8 @@ export class PanelCtrl {
containerHeight: any; containerHeight: any;
events: Emitter; events: Emitter;
timing: any; timing: any;
skippedLastRefresh: boolean;
isPanelVisible: any;
constructor($scope, $injector) { constructor($scope, $injector) {
this.$injector = $injector; this.$injector = $injector;
...@@ -74,7 +76,18 @@ export class PanelCtrl { ...@@ -74,7 +76,18 @@ export class PanelCtrl {
profiler.renderingCompleted(this.panel.id, this.timing); profiler.renderingCompleted(this.panel.id, this.timing);
} }
private isRenderingPng () {
return window.location.href.indexOf("/dashboard-solo/db") >= 0;
}
refresh() { refresh() {
if (!this.isPanelVisible() && !this.isRenderingPng() && !this.dashboard.snapshot) {
this.skippedLastRefresh = true;
return;
}
this.skippedLastRefresh = false;
this.events.emit('refresh', null); this.events.emit('refresh', null);
} }
......
...@@ -57,7 +57,7 @@ var panelTemplate = ` ...@@ -57,7 +57,7 @@ var panelTemplate = `
</div> </div>
`; `;
module.directive('grafanaPanel', function($rootScope) { module.directive('grafanaPanel', function($rootScope, $document) {
return { return {
restrict: 'E', restrict: 'E',
template: panelTemplate, template: panelTemplate,
...@@ -175,9 +175,23 @@ module.directive('grafanaPanel', function($rootScope) { ...@@ -175,9 +175,23 @@ module.directive('grafanaPanel', function($rootScope) {
elem.on('mouseenter', mouseEnter); elem.on('mouseenter', mouseEnter);
elem.on('mouseleave', mouseLeave); elem.on('mouseleave', mouseLeave);
ctrl.isPanelVisible = function () {
var position = panelContainer[0].getBoundingClientRect();
return (0 < position.top) && (position.top < window.innerHeight);
};
const refreshOnScroll = _.debounce(function () {
if (ctrl.skippedLastRefresh) {
ctrl.refresh();
}
}, 250);
$document.on('scroll', refreshOnScroll);
scope.$on('$destroy', function() { scope.$on('$destroy', function() {
elem.off(); elem.off();
cornerInfoElem.off(); cornerInfoElem.off();
$document.off('scroll', refreshOnScroll);
if (infoDrop) { if (infoDrop) {
infoDrop.destroy(); infoDrop.destroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment