From 56c79bc90616938f9aa30f21f41ecd4703a83a67 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Thu, 28 May 2020 15:22:03 +0200 Subject: [PATCH] Disable graph refresh when it is not visible (#5198) --- package-lock.json | 20 ++++++++++++++++--- package.json | 1 + .../common/components/graph/component.ts | 12 +++++++++-- .../common/components/graph/template.html | 3 +++ src/app/frontend/shared.module.ts | 2 ++ src/app/frontend/typings/frontendapi.ts | 5 +++++ 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index ffc159de6..8c81636ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11930,9 +11930,9 @@ "integrity": "sha1-ksnBN0w1CF912zWexWzCV8u5P6Q=" }, "http-proxy": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz", - "integrity": "sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==", + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", "dev": true, "requires": { "eventemitter3": "^4.0.0", @@ -12375,6 +12375,11 @@ "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", "dev": true }, + "intersection-observer": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/intersection-observer/-/intersection-observer-0.10.0.tgz", + "integrity": "sha512-fn4bQ0Xq8FTej09YC/jqKZwtijpvARlRp6wxL5WTA6yPe2YWSJ5RJh7Nm79rK2qB0wr6iDQzH60XGq5V/7u8YQ==" + }, "invariant": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", @@ -15861,6 +15866,15 @@ "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", "dev": true }, + "ng-in-viewport": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ng-in-viewport/-/ng-in-viewport-6.1.0.tgz", + "integrity": "sha512-mJlsiGBhOLiqgM4S36zg9IWjv0YsOPuoVB1T4mKaq4NZ2aHB/8t5n5pB+pP93k1mmSUhp+cPscGua5o7gJrURg==", + "requires": { + "intersection-observer": ">=0.5.1", + "tslib": ">=1.9.0" + } + }, "ngx-cookie-service": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/ngx-cookie-service/-/ngx-cookie-service-2.4.0.tgz", diff --git a/package.json b/package.json index 62b148ed6..6ac21c4ba 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "highlight.js": "10.0.3", "js-yaml": "3.13.1", "material-design-icons": "3.0.1", + "ng-in-viewport": "6.1.0", "ngx-cookie-service": "2.4.0", "ngx-filter-pipe": "2.1.2", "normalize.css": "8.0.1", diff --git a/src/app/frontend/common/components/graph/component.ts b/src/app/frontend/common/components/graph/component.ts index 41bd104d3..0e10805d8 100644 --- a/src/app/frontend/common/components/graph/component.ts +++ b/src/app/frontend/common/components/graph/component.ts @@ -14,6 +14,7 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import {DataPoint, Metric} from '@api/backendapi'; +import {ViewportMetadata} from '@api/frontendapi'; import {curveMonotoneX, timeFormat} from 'd3'; import {FormattedValue} from './helper'; @@ -38,6 +39,7 @@ export class GraphComponent implements OnInit, OnChanges { private suffixMap_: Map = new Map(); private yAxisSuffix_ = ''; + private visible_ = false; ngOnInit(): void { if (!this.graphType) { @@ -50,8 +52,14 @@ export class GraphComponent implements OnInit, OnChanges { } ngOnChanges(_: SimpleChanges): void { - this.suffixMap_.clear(); - this.series = this.generateSeries_(); + if (this.visible_) { + this.suffixMap_.clear(); + this.series = this.generateSeries_(); + } + } + + changeState(isInViewPort: ViewportMetadata): void { + this.visible_ = isInViewPort.visible; } getTooltipValue(value: number): string { diff --git a/src/app/frontend/common/components/graph/template.html b/src/app/frontend/common/components/graph/template.html index 66c8d9bf0..bcf4fc538 100644 --- a/src/app/frontend/common/components/graph/template.html +++ b/src/app/frontend/common/components/graph/template.html @@ -15,6 +15,9 @@ limitations under the License. -->