From a311a6984f2e9cd17d4b0012ea8fc0e4d7f5126a Mon Sep 17 00:00:00 2001 From: devaskim Date: Fri, 28 Oct 2022 12:34:42 +0500 Subject: [PATCH 1/3] Flot threshold value now supports array of values. --- .../home/components/widget/lib/flot-widget.ts | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts index c601df72d4..62680bdca7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts @@ -909,41 +909,42 @@ export class TbFlot { isLatest = false): TbFlotThresholdMarking[] { const thresholds: TbFlotThresholdMarking[] = []; data.forEach((keyData) => { - let skip = false; - let latestSettings: TbFlotLatestKeySettings; - if (isLatest) { - latestSettings = keyData.dataKey.settings; - if (!latestSettings.useAsThreshold) { - skip = true; - } - } + const skip = isLatest && !keyData.dataKey.settings.useAsThreshold; if (!skip && keyData && keyData.data && keyData.data[0]) { - const attrValue = keyData.data[0][1]; - if (isNumeric(attrValue) && isFinite(attrValue)) { - let yaxis: number; - let lineWidth: number; - let color: string; - if (isLatest) { - yaxis = 1; - lineWidth = latestSettings.thresholdLineWidth; - color = latestSettings.thresholdColor || keyData.dataKey.color; - } else { - const settings: TbFlotThresholdKeySettings = keyData.dataKey.settings; - yaxis = settings.yaxis; - lineWidth = settings.lineWidth; - color = settings.color || keyData.dataKey.color; - } - const colorIndex = this.subscription.data.length + existingThresholds.length; - const threshold = this.generateThreshold(existingThresholds, yaxis, lineWidth, color, colorIndex, attrValue); + const value = keyData.data[0][1]; + const values = Array.isArray(value) ? value : [value]; + values.forEach(v => { + const threshold = this.processSingleDataValue(v, keyData, keyData.dataKey.settings, existingThresholds, isLatest); if (threshold != null) { thresholds.push(threshold); } - } + }); } }); return thresholds; } + private processSingleDataValue(attrValue: number, keyData: DatasourceData, latestSettings: TbFlotLatestKeySettings, existingThresholds: TbFlotThresholdMarking[], isLatest = false) { + if (isNumeric(attrValue) && isFinite(attrValue)) { + let yaxis: number; + let lineWidth: number; + let color: string; + if (isLatest) { + yaxis = 1; + lineWidth = latestSettings.thresholdLineWidth; + color = latestSettings.thresholdColor || keyData.dataKey.color; + } else { + const settings: TbFlotThresholdKeySettings = keyData.dataKey.settings; + yaxis = settings.yaxis; + lineWidth = settings.lineWidth; + color = settings.color || keyData.dataKey.color; + } + const colorIndex = this.subscription.data.length + existingThresholds.length; + return this.generateThreshold(existingThresholds, yaxis, lineWidth, color, colorIndex, attrValue); + + } + } + private generateThreshold(existingThresholds: TbFlotThresholdMarking[], yaxis: number, lineWidth: number, color: string, defaultColorIndex: number, thresholdValue: number): TbFlotThresholdMarking { const marking: TbFlotThresholdMarking = {}; From 4d12e4a1e7ceb026286176e1ed17a17b2ffc3394 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Wed, 2 Nov 2022 10:16:25 +0200 Subject: [PATCH 2/3] UI: Improvement parse threshold data --- .../home/components/widget/lib/flot-widget.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts index 62680bdca7..3b3b31e8a0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts @@ -911,8 +911,7 @@ export class TbFlot { data.forEach((keyData) => { const skip = isLatest && !keyData.dataKey.settings.useAsThreshold; if (!skip && keyData && keyData.data && keyData.data[0]) { - const value = keyData.data[0][1]; - const values = Array.isArray(value) ? value : [value]; + const values = this.parsThresholdData(keyData.data[0][1]); values.forEach(v => { const threshold = this.processSingleDataValue(v, keyData, keyData.dataKey.settings, existingThresholds, isLatest); if (threshold != null) { @@ -924,7 +923,19 @@ export class TbFlot { return thresholds; } - private processSingleDataValue(attrValue: number, keyData: DatasourceData, latestSettings: TbFlotLatestKeySettings, existingThresholds: TbFlotThresholdMarking[], isLatest = false) { + private parsThresholdData(value: any): Array { + let values; + try { + const parseData = JSON.parse(value); + values = Array.isArray(parseData) ? parseData : [parseData]; + } catch (e) { + values = [value]; + } + return values; + } + + private processSingleDataValue(attrValue: number, keyData: DatasourceData, latestSettings: TbFlotLatestKeySettings, + existingThresholds: TbFlotThresholdMarking[], isLatest = false) { if (isNumeric(attrValue) && isFinite(attrValue)) { let yaxis: number; let lineWidth: number; @@ -941,7 +952,6 @@ export class TbFlot { } const colorIndex = this.subscription.data.length + existingThresholds.length; return this.generateThreshold(existingThresholds, yaxis, lineWidth, color, colorIndex, attrValue); - } } From d61b38fc8d715e935a38af3c80ac7f94822be448 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 2 Nov 2022 15:34:45 +0200 Subject: [PATCH 3/3] Update flot-widget.ts --- .../app/modules/home/components/widget/lib/flot-widget.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts index 3b3b31e8a0..d71d9e84f2 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.ts @@ -911,7 +911,7 @@ export class TbFlot { data.forEach((keyData) => { const skip = isLatest && !keyData.dataKey.settings.useAsThreshold; if (!skip && keyData && keyData.data && keyData.data[0]) { - const values = this.parsThresholdData(keyData.data[0][1]); + const values = this.parseThresholdData(keyData.data[0][1]); values.forEach(v => { const threshold = this.processSingleDataValue(v, keyData, keyData.dataKey.settings, existingThresholds, isLatest); if (threshold != null) { @@ -923,11 +923,11 @@ export class TbFlot { return thresholds; } - private parsThresholdData(value: any): Array { + private parseThresholdData(value: any): Array { let values; try { - const parseData = JSON.parse(value); - values = Array.isArray(parseData) ? parseData : [parseData]; + const parsedData = JSON.parse(value); + values = Array.isArray(parsedData) ? parsedData : [parsedData]; } catch (e) { values = [value]; }