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
introduce a delta formatter
Vincent5793a6a351d5
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex 4db0da1eb..2116f0b9f 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -71,13 +71,14 @@ export class OrAttributeCard extends LitElement {private mainValue?: number;@property()private mainValueLastPeriod?: number;+ @property()+ private delta: string = "";private period: moment.unitOfTime.Base = "month";private now?: Date = new Date();private asset: Asset = {};private formattedMainValue?: string;- private delta: string = "";@query("#chart")private _chartElem!: HTMLCanvasElement;@@ -154,8 +155,7 @@ export class OrAttributeCard extends LitElement {if (changedProperties.has("mainValue") || changedProperties.has("mainValueLastPeriod")) {if (this.mainValueLastPeriod && this.mainValue) {- console.log(Math.round(((this.mainValueLastPeriod! / this.mainValue!) * 100)));- this.delta = Math.round(((this.mainValueLastPeriod! / this.mainValue!) * 100)).toString() + "%";+ this.delta = this.getFormattedDelta(this.mainValue, this.mainValueLastPeriod);}}if (changedProperties.has("mainValue")) {@@ -302,6 +302,15 @@ export class OrAttributeCard extends LitElement {return i18next.t(format, { postProcess: "sprintf", sprintf: [value] }).trim();}+ protected getFormattedDelta(currentPeriodVal: number, lastPeriodVal: number): string {+ if (currentPeriodVal && lastPeriodVal) {+ const math = Math.round(lastPeriodVal - currentPeriodVal);+ return math.toString();+ } else {+ return "0";+ }+ }+protected _getPeriodOptions() {return [{