Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Attribute detail card bugs (#189)

vlichtenberg39728640b99b
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index 0929aa4cc..830976fa1 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -2,7 +2,7 @@ import {css, customElement, html, LitElement, property, PropertyValues, query, u
import {classMap} from "lit-html/directives/class-map";
import i18next from "i18next";
import {Asset, AssetAttribute, Attribute, DatapointInterval, MetaItemType, ValueDatapoint} from "@openremote/model";
-import {manager, DefaultColor4, DefaultColor5, Util} from "@openremote/core";
+import {manager, DefaultColor3, DefaultColor4, DefaultColor5, Util} from "@openremote/core";
import Chart, {ChartTooltipCallback} from "chart.js";
import {getContentWithMenuTemplate, OrChartConfig} from "@openremote/or-chart";
import {InputType} from "@openremote/or-input";
@@ -18,6 +18,7 @@ const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css")
const style = css`
:host {
+ --internal-or-attribute-history-graph-line-color: var(--or-attribute-history-graph-line-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
width: 100%;
}
@@ -97,10 +98,11 @@ const style = css`
display: flex;
flex: 0 0 24px;
align-items: center;
+ margin-top: 10px;
}
.period-label {
- color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
+ color: var(--or-app-color3, ${unsafeCSS(DefaultColor3)});
}
.main-number {
@@ -142,14 +144,9 @@ const style = css`
}
.delta {
+ color: var(--or-app-color3, ${unsafeCSS(DefaultColor3)});
font-weight: bold;
}
- .delta.delta-min {
- color: red;
- }
- .delta.delta-plus {
- color: #4D9D2A;
- }
`;
export class OrAttributeCardAddAttributeEvent extends CustomEvent<string> {
@@ -182,13 +179,13 @@ export class OrAttributeCard extends LitElement {
@property()
public panelName?: string;
+ protected _style!: CSSStyleDeclaration;
+
@property({type: Object})
private assetAttributes: AssetAttribute[] = [];
@property()
private data: ValueDatapoint<any>[] = [];
- @property()
- private graphColour: "#4D9D2A" | "#FF0000" = "#4D9D2A";
@property()
private mainValue?: number;
@@ -202,7 +199,7 @@ export class OrAttributeCard extends LitElement {
private error: boolean = false;
private period: moment.unitOfTime.Base = "month";
- private now?: Date = new Date();
+ private now: Date = new Date();
private currentPeriod?: { start: number; end: number };
private asset: Asset = {};
@@ -231,6 +228,7 @@ export class OrAttributeCard extends LitElement {
connectedCallback() {
super.connectedCallback();
+ this._style = window.getComputedStyle(this);
this.getData();
}
@@ -286,7 +284,7 @@ export class OrAttributeCard extends LitElement {
lineTension: 0.1,
spanGaps: true,
backgroundColor: "transparent",
- borderColor: this.graphColour,
+ borderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-line-color"),
pointBorderColor: "transparent",
}
]
@@ -325,7 +323,6 @@ export class OrAttributeCard extends LitElement {
} else {
if (changedProperties.has("data")) {
this._chart.data.datasets![0].data = this.data;
- this._chart.data.datasets![0].borderColor = this.graphColour;
this._chart.update();
}
}
@@ -539,7 +536,7 @@ export class OrAttributeCard extends LitElement {
<div class="panel-content-wrapper">
<div class="panel-title">
<span class="panel-title-text">${this.asset.name} - ${i18next.t(this.attributeName)}</span>
- <or-input icon="plus-minus" type="button" @click="${() => this._openDialog()}"></or-input>
+ <or-input icon="pencil" type="button" @click="${() => this._openDialog()}"></or-input>
</div>
<div class="panel-content">
<div class="top-row">
@@ -551,7 +548,7 @@ export class OrAttributeCard extends LitElement {
<canvas id="chart"></canvas>
</div>
<div class="delta-wrapper">
- <span class=${classMap({"delta": true, "delta-min": this.delta.val! < 0, "delta-plus": this.delta.val! > 0})}>${this.deltaPlus}${this.delta.val}${this.delta.unit}</span>
+ <span class="delta">${this.deltaPlus}${this.delta.val}${this.delta.unit}</span>
</div>
</div>
<div class="bottom-row">
@@ -621,10 +618,9 @@ export class OrAttributeCard extends LitElement {
const thisMoment = moment(this.now);
this.asset = await this.getAssetById(this.assetId);
- console.log(this.asset);
this.currentPeriod = {
- start: thisMoment.startOf(this.period).toDate().getTime(),
- end: thisMoment.endOf(this.period).toDate().getTime()
+ start: thisMoment.clone().subtract(1, this.period).toDate().getTime(),
+ end: thisMoment.clone().toDate().getTime()
};
const lastPeriod = {
start: thisMoment.clone().subtract(1, this.period).startOf(this.period).toDate().getTime(),
@@ -634,20 +630,20 @@ export class OrAttributeCard extends LitElement {
const p1 = this.getDatapointsByAttribute(this.assetId, this.attributeName, this.currentPeriod.start, this.currentPeriod.end)
.then((datapoints: ValueDatapoint<any>[]) => {
this.data = datapoints || [];
- this.mainValue = this.getHighestValue(this.sanitiseDataPoints(this.data));
+ this.mainValue = this.getHighestValue(this.data);
+ this.formattedMainValue = this.getFormattedValue(this.mainValue);
return this.mainValue;
});
const p2 = this.getDatapointsByAttribute(this.assetId, this.attributeName, lastPeriod.start, lastPeriod.end)
.then((datapoints: ValueDatapoint<any>[]) => {
- this.mainValueLastPeriod = this.getHighestValue(this.sanitiseDataPoints(datapoints));
+ this.mainValueLastPeriod = this.getHighestValue(datapoints);
return this.mainValueLastPeriod;
});
Promise.all([p1, p2])
.then((returnvalues) => {
this.delta = this.getFormattedDelta(returnvalues[0], returnvalues[1]);
- this.graphColour = (this.delta.val! < 0) ? "#FF0000" : "#4D9D2A";
this.error = false;
})
.catch((err) => {
@@ -657,21 +653,6 @@ export class OrAttributeCard extends LitElement {
}
- protected sanitiseDataPoints(data: ValueDatapoint<any>[]): ValueDatapoint<any>[] {
-
- // if there's no measurement for the first data point in time, assume 0
- if (data[0] && !data[0].y) {
- data[0].y = 0;
- }
-
- // if there's no measurement for the last data point, use the highest available
- if (data[(data.length - 1)] && !data[(data.length - 1)].y) {
- data[(data.length - 1)].y = this.getHighestValue(data);
- }
-
- return data;
- }
-
protected getTotalValue(data: ValueDatapoint<any>[]): number {
return data.reduce(( acc: number, val: ValueDatapoint<any> ) => {
return val.y ? acc + Math.round(val.y) : acc;
@@ -684,6 +665,11 @@ export class OrAttributeCard extends LitElement {
protected getFormattedValue(value: number): {value: number, unit: string, formattedValue: string} {
const format = getMetaValue(MetaItemType.FORMAT, this.asset.attributes![this.attributeName!], undefined);
+
+ if (!format) {
+ return {value: value, unit: "", formattedValue: value.toString()};
+ }
+
const unit = format.split(" ").pop();
return {
value: value,
@@ -703,7 +689,7 @@ export class OrAttributeCard extends LitElement {
return {val: math, unit: "%"};
}
} else {
- return {};
+ return {val: 0, unit: "%"};
}
}
diff --git a/ui/component/or-data-viewer/src/index.ts b/ui/component/or-data-viewer/src/index.ts
index 0e850b9c5..207a21740 100644
--- a/ui/component/or-data-viewer/src/index.ts
+++ b/ui/component/or-data-viewer/src/index.ts
@@ -182,16 +182,7 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitEleme
return html`
- <div class=${classMap({"panel": true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
- <div class="panel-content-wrapper">
- <div class="panel-title">
- <or-translate value="${name}"></or-translate>
- </div>
- <div class="panel-content">
- ${content}
- </div>
- </div>
- </div>
+ ${content}
`;
}
@@ -204,7 +195,16 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitEleme
if (panelConfig && panelConfig.type === "chart") {
content = html`
- <or-chart id="chart" panelName="${panelName}" .config="${this.config.chartConfig}"></or-chart>
+ <div class=${classMap({"panel": true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
+ <div class="panel-content-wrapper">
+ <div class="panel-title">
+ <or-translate value="${name}"></or-translate>
+ </div>
+ <div class="panel-content">
+ <or-chart id="chart" panelName="${panelName}" .config="${this.config.chartConfig}"></or-chart>
+ </div>
+ </div>
+ </div>
`;
}