100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI fix for symbol being visible when too many datapoints are shown (#2390)
Martin Peetersf5993fd6581a
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex dff72f27b..807eb1674 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -903,13 +903,15 @@ export class OrChart extends translate(i18next)(LitElement) {if(chart){const options = chart.getOption();if (options.series && Array.isArray(options.series)) {- options.series.forEach(function (series) {+ options.series.forEach(series => {if (series.lineStyle.opacity === 0.2 || series.lineStyle.opacity === 0.99) {series.lineStyle.opacity = 0.31;series.showSymbol = false;} else {series.lineStyle.opacity = 1;- series.showSymbol = true;+ series.showSymbol = this._canShowSymbols(+ (options.series as LineChartData[]).filter(s => s.assetId === series.assetId && s.attrName === series.attrName)+ );}});}@@ -926,9 +928,10 @@ export class OrChart extends translate(i18next)(LitElement) {_addDatasetHighlight(attrRef: AttributeRef, chart = this._chart) {if (chart) {const options = chart.getOption();+ const isAttrRef = (s: any) => s.assetId === attrRef.id && s.attrName === attrRef.name;if (options.series && Array.isArray(options.series)) {options.series.forEach(series => {- if (series.assetId !== attrRef.id || series.attrName !== attrRef.name) {+ if (!isAttrRef(series)) {if (series.lineStyle.opacity === 0.31) { // 0.31 is faint setting, 1 is normalseries.lineStyle.opacity = 0.2;} else {@@ -937,7 +940,9 @@ export class OrChart extends translate(i18next)(LitElement) {}} else if (series.lineStyle.opacity === 0.31) { // extra highlight if selected is faintseries.lineStyle.opacity = 0.99;- series.showSymbol = true;+ series.showSymbol = this._canShowSymbols(+ (options.series as LineChartData[]).filter(s => isAttrRef(s))+ );}});}@@ -1265,6 +1270,7 @@ export class OrChart extends translate(i18next)(LitElement) {this._dataAbortController = new AbortController();promises = this.assetAttributes?.map(async ([assetIndex, attribute], index) => {+ const lineData: LineChartData[] = [];const asset = this.assets[assetIndex];const shownOnRightAxis = !!this.attributeConfig?.rightAxisAttributes?.find(ar => ar.id === asset.id && ar.name === attribute.name);const smooth = !!this.attributeConfig?.smoothAttributes?.find(ar => ar.id === asset.id && ar.name === attribute.name);@@ -1282,24 +1288,35 @@ export class OrChart extends translate(i18next)(LitElement) {// Load Historic Datalet dataset = await this._loadAttributeData(asset, attribute, color ?? this.colors[colourIndex], false, smooth, stacked, stepped, area, faint, false, `${asset.name} | ${label}`, options, unit);- dataset.assetId = asset.id;- dataset.attrName = attribute.name;- dataset.unit = unit;- dataset.yAxisIndex = shownOnRightAxis ? 1 : 0;- data.push(dataset);+ lineData.push(dataset);// Load Predicted Datadataset = await this._loadAttributeData(this.assets[assetIndex], attribute, color ?? this.colors[colourIndex], true, smooth, stacked, stepped, area, faint, false , `${asset.name} | ${label} ${i18next.t("predicted")}`, options, unit);- dataset.yAxisIndex = shownOnRightAxis ? 1 : 0;- data.push(dataset);+ lineData.push(dataset);// If necessary, load Extended Dataif (extended) {dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, color ?? this.colors[colourIndex], false, false, stacked, false, area, faint, extended, `${asset.name} | ${label} lastKnown`, options, unit);- dataset.yAxisIndex = shownOnRightAxis ? 1 : 0;- data.push(dataset);+ lineData.push(dataset);}+ // Add metadata such as asset ID and attribute name+ lineData.forEach(d => {+ d.assetId = asset.id;+ d.attrName = attribute.name;+ d.unit = unit;+ d.yAxisIndex = shownOnRightAxis ? 1 : 0;+ });++ // Turn off symbols when the amount of points is too dense+ const datasetsWithoutFaint = lineData.filter(s => s.showSymbol);+ if(datasetsWithoutFaint.length > 0) {+ const showSymbols = this._canShowSymbols(lineData);+ datasetsWithoutFaint.forEach(d => d.showSymbol = showSymbols);+ }++ // Add line data to the chart+ data.push(...lineData);});}@@ -1609,6 +1626,12 @@ export class OrChart extends translate(i18next)(LitElement) {return tooltipArray.map(t => t.text).join('');}+ protected _canShowSymbols(datasets: LineChartData[], chartElem = this._chartElem) {+ const maxSymbolCount = Math.min(chartElem ? chartElem.clientWidth / 25 : 50, 50);+ const totalSymbolCount = datasets.flatMap(item => item.data ?? []).length;+ return totalSymbolCount <= maxSymbolCount;+ }+/*** Internal function to get the default Chart attribute config.* @protected