|
|
|
@ -18,7 +18,7 @@ |
|
|
|
import { WidgetContext } from '@home/models/widget-component.models'; |
|
|
|
import { |
|
|
|
createLabelFromDatasource, |
|
|
|
deepClone, |
|
|
|
deepClone, formattedDataFormDatasourceData, |
|
|
|
insertVariable, |
|
|
|
isDefined, |
|
|
|
isDefinedAndNotNull, |
|
|
|
@ -28,7 +28,14 @@ import { |
|
|
|
isUndefined |
|
|
|
} from '@app/core/utils'; |
|
|
|
import { IWidgetSubscription, WidgetSubscriptionOptions } from '@core/api/widget-api.models'; |
|
|
|
import { DataKey, Datasource, DatasourceData, DatasourceType, widgetType } from '@app/shared/models/widget.models'; |
|
|
|
import { |
|
|
|
DataKey, |
|
|
|
Datasource, |
|
|
|
DatasourceData, |
|
|
|
DatasourceType, |
|
|
|
FormattedData, |
|
|
|
widgetType |
|
|
|
} from '@app/shared/models/widget.models'; |
|
|
|
import { |
|
|
|
ChartType, |
|
|
|
TbFlotAxisOptions, |
|
|
|
@ -88,6 +95,8 @@ export class TbFlot { |
|
|
|
private latestDataThresholds: TbFlotThresholdMarking[]; |
|
|
|
private attributesThresholds: TbFlotThresholdMarking[]; |
|
|
|
|
|
|
|
private latestData: FormattedData[]; |
|
|
|
|
|
|
|
private labelPatternsSourcesSubscription: IWidgetSubscription; |
|
|
|
private labelPatternsSourcesData: DatasourceData[]; |
|
|
|
|
|
|
|
@ -379,7 +388,7 @@ export class TbFlot { |
|
|
|
let tooltipValueFormatFunction: TooltipValueFormatFunction = null; |
|
|
|
if (this.settings.tooltipValueFormatter && this.settings.tooltipValueFormatter.length) { |
|
|
|
try { |
|
|
|
tooltipValueFormatFunction = new Function('value', this.settings.tooltipValueFormatter) as TooltipValueFormatFunction; |
|
|
|
tooltipValueFormatFunction = new Function('value', 'latestData', this.settings.tooltipValueFormatter) as TooltipValueFormatFunction; |
|
|
|
} catch (e) { |
|
|
|
tooltipValueFormatFunction = null; |
|
|
|
} |
|
|
|
@ -392,7 +401,7 @@ export class TbFlot { |
|
|
|
series.dataKey.tooltipValueFormatFunction = tooltipValueFormatFunction; |
|
|
|
if (keySettings.tooltipValueFormatter && keySettings.tooltipValueFormatter.length) { |
|
|
|
try { |
|
|
|
series.dataKey.tooltipValueFormatFunction = new Function('value', |
|
|
|
series.dataKey.tooltipValueFormatFunction = new Function('value', 'latestData', |
|
|
|
keySettings.tooltipValueFormatter) as TooltipValueFormatFunction; |
|
|
|
} catch (e) { |
|
|
|
series.dataKey.tooltipValueFormatFunction = tooltipValueFormatFunction; |
|
|
|
@ -546,6 +555,13 @@ export class TbFlot { |
|
|
|
} |
|
|
|
this.latestDataThresholds = this.thresholdsSourcesDataUpdated(allThresholds, this.subscription.latestData, true); |
|
|
|
this.options.grid.markings = allThresholds.concat(this.latestDataThresholds); |
|
|
|
if (this.subscription.latestData) { |
|
|
|
this.latestData = formattedDataFormDatasourceData(this.subscription.latestData); |
|
|
|
} else { |
|
|
|
this.latestData = []; |
|
|
|
} |
|
|
|
} else if (this.chartType === 'pie') { |
|
|
|
this.latestData = formattedDataFormDatasourceData(this.subscription.data); |
|
|
|
} |
|
|
|
|
|
|
|
this.checkMouseEvents(); |
|
|
|
@ -653,6 +669,7 @@ export class TbFlot { |
|
|
|
this.updateData(); |
|
|
|
} |
|
|
|
} else if (this.chartType === 'pie') { |
|
|
|
this.latestData = formattedDataFormDatasourceData(this.subscription.data); |
|
|
|
if (this.animatedPie) { |
|
|
|
this.nextPieDataAnimation(true); |
|
|
|
} else { |
|
|
|
@ -683,6 +700,11 @@ export class TbFlot { |
|
|
|
this.plot.getOptions().grid.markings = this.options.grid.markings; |
|
|
|
this.updateData(); |
|
|
|
} |
|
|
|
if (this.subscription.latestData) { |
|
|
|
this.latestData = formattedDataFormDatasourceData(this.subscription.latestData); |
|
|
|
} else { |
|
|
|
this.latestData = []; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (this.isMouseInteraction && this.plot) { |
|
|
|
this.latestUpdateTimeoutHandle = setTimeout(this.latestDataUpdate.bind(this), 30); |
|
|
|
@ -690,6 +712,14 @@ export class TbFlot { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private latestDataByDataIndex(index: number): FormattedData { |
|
|
|
if (this.latestData[index]) { |
|
|
|
return this.latestData[index]; |
|
|
|
} else { |
|
|
|
return {} as FormattedData; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private scalingPieRadius() { |
|
|
|
let scalingLine; |
|
|
|
this.ctx.width > this.ctx.height ? scalingLine = this.ctx.height : scalingLine = this.ctx.width; |
|
|
|
@ -1004,7 +1034,8 @@ export class TbFlot { |
|
|
|
|
|
|
|
private seriesInfoDiv(label: string, color: string, value: any, |
|
|
|
units: string, trackDecimals: number, active: boolean, |
|
|
|
percent: number, valueFormatFunction: TooltipValueFormatFunction): JQuery<HTMLElement> { |
|
|
|
percent: number, seriesIndex: number, |
|
|
|
valueFormatFunction: TooltipValueFormatFunction): JQuery<HTMLElement> { |
|
|
|
const divElement = $('<div></div>'); |
|
|
|
divElement.css({ |
|
|
|
display: 'flex', |
|
|
|
@ -1034,7 +1065,7 @@ export class TbFlot { |
|
|
|
divElement.append(labelSpan); |
|
|
|
let valueContent: string; |
|
|
|
if (valueFormatFunction) { |
|
|
|
valueContent = valueFormatFunction(value); |
|
|
|
valueContent = valueFormatFunction(value, this.latestDataByDataIndex(seriesIndex)); |
|
|
|
} else { |
|
|
|
valueContent = this.ctx.utils.formatValue(value, trackDecimals, units); |
|
|
|
} |
|
|
|
@ -1059,7 +1090,8 @@ export class TbFlot { |
|
|
|
const units = seriesHoverInfo.units && seriesHoverInfo.units.length ? seriesHoverInfo.units : this.trackUnits; |
|
|
|
const decimals = isDefinedAndNotNull(seriesHoverInfo.decimals) ? seriesHoverInfo.decimals : this.trackDecimals; |
|
|
|
const divElement = this.seriesInfoDiv(seriesHoverInfo.label, seriesHoverInfo.color, |
|
|
|
seriesHoverInfo.value, units, decimals, seriesHoverInfo.index === seriesIndex, null, seriesHoverInfo.tooltipValueFormatFunction); |
|
|
|
seriesHoverInfo.value, units, decimals, seriesHoverInfo.index === seriesIndex, null, seriesHoverInfo.index, |
|
|
|
seriesHoverInfo.tooltipValueFormatFunction); |
|
|
|
return divElement.prop('outerHTML'); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1086,7 +1118,8 @@ export class TbFlot { |
|
|
|
const units = item.series.dataKey.units && item.series.dataKey.units.length ? item.series.dataKey.units : this.trackUnits; |
|
|
|
const decimals = isDefinedAndNotNull(item.series.dataKey.decimals) ? item.series.dataKey.decimals : this.trackDecimals; |
|
|
|
const divElement = this.seriesInfoDiv(item.series.dataKey.label, item.series.dataKey.color, |
|
|
|
item.datapoint[1][0][1], units, decimals, true, item.series.percent, item.series.dataKey.tooltipValueFormatFunction); |
|
|
|
item.datapoint[1][0][1], units, decimals, true, item.series.percent, 0, |
|
|
|
item.series.dataKey.tooltipValueFormatFunction); |
|
|
|
return divElement.prop('outerHTML'); |
|
|
|
} |
|
|
|
|
|
|
|
|