Merge pull request #7055 from vvlladd28/bug/flot/predefined-threshold/not-work

[3.4.1] UI: Fixed didn't work predefined thresholds in Flot widgets
This commit is contained in:
Igor Kulikov 2022-08-08 15:14:16 +03:00 committed by GitHub
commit 579dc21bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,19 +28,13 @@ import {
isUndefined isUndefined
} from '@app/core/utils'; } from '@app/core/utils';
import { IWidgetSubscription, WidgetSubscriptionOptions } from '@core/api/widget-api.models'; import { IWidgetSubscription, WidgetSubscriptionOptions } from '@core/api/widget-api.models';
import { import { DataKey, Datasource, DatasourceData, DatasourceType, widgetType } from '@app/shared/models/widget.models';
DataKey,
Datasource,
DatasourceData,
DatasourceType,
JsonSettingsSchema,
widgetType
} from '@app/shared/models/widget.models';
import { import {
ChartType, ChartType,
TbFlotAxisOptions, TbFlotAxisOptions,
TbFlotHoverInfo, TbFlotHoverInfo,
TbFlotKeySettings, TbFlotLatestKeySettings, TbFlotKeySettings,
TbFlotLatestKeySettings,
TbFlotPlotAxis, TbFlotPlotAxis,
TbFlotPlotDataSeries, TbFlotPlotDataSeries,
TbFlotPlotItem, TbFlotPlotItem,
@ -481,8 +475,11 @@ export class TbFlot {
for (const threshold of keySettings.thresholds) { for (const threshold of keySettings.thresholds) {
if (threshold.thresholdValueSource === 'predefinedValue' && isFinite(threshold.thresholdValue)) { if (threshold.thresholdValueSource === 'predefinedValue' && isFinite(threshold.thresholdValue)) {
const colorIndex = this.subscription.data.length + predefinedThresholds.length; const colorIndex = this.subscription.data.length + predefinedThresholds.length;
this.generateThreshold(predefinedThresholds, series.yaxis, threshold.lineWidth, const predefinedThreshold = this.generateThreshold(predefinedThresholds, series.yaxis, threshold.lineWidth,
threshold.color, colorIndex, threshold.thresholdValue); threshold.color, colorIndex, threshold.thresholdValue);
if (predefinedThreshold != null) {
predefinedThresholds.push(predefinedThreshold);
}
} else if (threshold.thresholdEntityAlias && threshold.thresholdAttribute) { } else if (threshold.thresholdEntityAlias && threshold.thresholdAttribute) {
const entityAliasId = this.ctx.aliasController.getEntityAliasId(threshold.thresholdEntityAlias); const entityAliasId = this.ctx.aliasController.getEntityAliasId(threshold.thresholdEntityAlias);
if (!entityAliasId) { if (!entityAliasId) {
@ -696,7 +693,7 @@ export class TbFlot {
private scalingPieRadius() { private scalingPieRadius() {
let scalingLine; let scalingLine;
this.ctx.width > this.ctx.height ? scalingLine = this.ctx.height : scalingLine = this.ctx.width; this.ctx.width > this.ctx.height ? scalingLine = this.ctx.height : scalingLine = this.ctx.width;
let changeRadius = this.options.series.pie.stroke.width / scalingLine; const changeRadius = this.options.series.pie.stroke.width / scalingLine;
this.options.series.pie.radius = changeRadius < 1 ? this.settings.radius - changeRadius : 0; this.options.series.pie.radius = changeRadius < 1 ? this.settings.radius - changeRadius : 0;
} }
@ -985,8 +982,7 @@ export class TbFlot {
return item.datasource.entityId === series.datasource.entityId; return item.datasource.entityId === series.datasource.entityId;
}); });
let label = createLabelFromDatasource(series.datasource, series.dataKey.pattern); let label = createLabelFromDatasource(series.datasource, series.dataKey.pattern);
for (let i = 0; i < seriesLabelPatternsSourcesData.length; i++) { seriesLabelPatternsSourcesData.forEach(keyData => {
const keyData = seriesLabelPatternsSourcesData[i];
if (keyData && keyData.data && keyData.data[0]) { if (keyData && keyData.data && keyData.data[0]) {
const attrValue = keyData.data[0][1]; const attrValue = keyData.data[0][1];
const attrName = keyData.dataKey.name; const attrName = keyData.dataKey.name;
@ -994,7 +990,7 @@ export class TbFlot {
label = insertVariable(label, attrName, attrValue); label = insertVariable(label, attrName, attrValue);
} }
} }
} });
if (isDefined(this.subscription.legendData)) { if (isDefined(this.subscription.legendData)) {
const targetLegendKeyIndex = this.subscription.legendData.keys.findIndex((key) => { const targetLegendKeyIndex = this.subscription.legendData.keys.findIndex((key) => {
return key.dataIndex === seriesIndex; return key.dataIndex === seriesIndex;