From 19dac7d5aa64c5210f6b83537e42ff2413245653 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 25 Feb 2020 12:30:38 +0200 Subject: [PATCH] Propagate UI changes --- .../src/app/core/api/widget-subscription.ts | 4 +- .../components/widget/legend.component.html | 2 +- .../components/widget/legend.component.ts | 13 +++-- .../widget/lib/flot-widget.models.ts | 51 +++++++++++++++++++ .../home/components/widget/lib/flot-widget.ts | 12 ++--- ui-ngx/src/app/shared/models/widget.models.ts | 1 + 6 files changed, 70 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index 68a03d53b2..2bf0048a3a 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -352,6 +352,7 @@ export class WidgetSubscription implements IWidgetSubscription { initDataSubscriptionSubject.complete(); }, (err) => { + this.notifyDataLoaded(); initDataSubscriptionSubject.error(err); } ); @@ -368,7 +369,8 @@ export class WidgetSubscription implements IWidgetSubscription { const additionalDataKeys: DataKey[] = []; let datasourceAdditionalKeysNumber = 0; datasource.dataKeys.forEach((dataKey) => { - dataKey.hidden = false; + dataKey.hidden = dataKey.settings.hideDataByDefault ? true : false; + dataKey.inLegend = dataKey.settings.removeFromLegend ? false : true; dataKey.pattern = dataKey.label; if (this.comparisonEnabled && dataKey.settings.comparisonSettings && dataKey.settings.comparisonSettings.showValuesForComparison) { datasourceAdditionalKeysNumber++; diff --git a/ui-ngx/src/app/modules/home/components/widget/legend.component.html b/ui-ngx/src/app/modules/home/components/widget/legend.component.html index 901cdd7169..96e6438711 100644 --- a/ui-ngx/src/app/modules/home/components/widget/legend.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/legend.component.html @@ -26,7 +26,7 @@ - + this.legendData.keys[legendKey.dataIndex].dataKey.inLegend); } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts index 1818e87ef0..def651d22b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/flot-widget.models.ts @@ -160,6 +160,9 @@ export declare type TbFlotXAxisPosition = 'top' | 'bottom'; export interface TbFlotKeySettings { excludeFromStacking: boolean; + hideDataByDefault: boolean; + disableDataHiding: boolean; + removeFromLegend: boolean; showLines: boolean; fillLines: boolean; showPoints: boolean; @@ -612,6 +615,36 @@ export const flotPieSettingsSchema: JsonSettingsSchema = { ] }; +export const flotPieDatakeySettingsSchema: JsonSettingsSchema = { + schema: { + type: 'object', + title: 'DataKeySettings', + properties: { + hideDataByDefault: { + title: 'Data is hidden by default', + type: 'boolean', + default: false + }, + disableDataHiding: { + title: 'Disable data hiding', + type: 'boolean', + default: false + }, + removeFromLegend: { + title: 'Remove datakey from legend', + type: 'boolean', + default: false + } + }, + required: [] + }, + form: [ + 'hideDataByDefault', + 'disableDataHiding', + 'removeFromLegend' + ] +}; + export function flotDatakeySettingsSchema(defaultShowLines: boolean, chartType: ChartType): JsonSettingsSchema { const schema: JsonSettingsSchema = { schema: { @@ -623,6 +656,21 @@ export function flotDatakeySettingsSchema(defaultShowLines: boolean, chartType: type: 'boolean', default: false }, + hideDataByDefault: { + title: 'Data is hidden by default', + type: 'boolean', + default: false + }, + disableDataHiding: { + title: 'Disable data hiding', + type: 'boolean', + default: false + }, + removeFromLegend: { + title: 'Remove datakey from legend', + type: 'boolean', + default: false + }, showLines: { title: 'Show lines', type: 'boolean', @@ -711,6 +759,9 @@ export function flotDatakeySettingsSchema(defaultShowLines: boolean, chartType: required: ['showLines', 'fillLines', 'showPoints'] }, form: [ + 'hideDataByDefault', + 'disableDataHiding', + 'removeFromLegend', 'excludeFromStacking', 'showLines', 'fillLines', 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 c042a8f5cf..292956b1b7 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 @@ -21,7 +21,7 @@ import { IWidgetSubscription } from '@core/api/widget-api.models'; import { DatasourceData, JsonSettingsSchema } from '@app/shared/models/widget.models'; import { ChartType, - flotDatakeySettingsSchema, + flotDatakeySettingsSchema, flotPieDatakeySettingsSchema, flotPieSettingsSchema, flotSettingsSchema, TbFlotAxisOptions, @@ -47,6 +47,7 @@ const tinycolor = tinycolor_; const moment = moment_; const flotPieSettingsSchemaValue = flotPieSettingsSchema; +const flotPieDatakeySettingsSchemaValue = flotPieDatakeySettingsSchema; export class TbFlot { @@ -103,7 +104,7 @@ export class TbFlot { } static pieDatakeySettingsSchema(): JsonSettingsSchema { - return {}; + return flotPieDatakeySettingsSchemaValue; } static settingsSchema(chartType: ChartType): JsonSettingsSchema { @@ -814,12 +815,7 @@ export class TbFlot { return seriesHover.index === seriesIndex; }); if (found && found.length) { - let timestamp: number; - if (!isNumber(hoverInfo[0].time) || (found[0].time < hoverInfo[0].time)) { - timestamp = parseInt(hoverInfo[1].time, 10); - } else { - timestamp = parseInt(hoverInfo[0].time, 10); - } + const timestamp = parseInt(found[0].time, 10); const date = moment(timestamp).format('YYYY-MM-DD HH:mm:ss'); const dateDiv = $('
' + date + '
'); dateDiv.css({ diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index bfd3f23e9c..fb4ac3401d 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -231,6 +231,7 @@ export interface DataKey extends KeyInfo { settings?: any; usePostProcessing?: boolean; hidden?: boolean; + inLegend?: boolean; _hash?: number; }