@openremote/or-gauge 1.8.0-snapshot.20250725070921 → 1.8.0-snapshot.20250725120000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/gaugeJS.d.ts +121 -121
- package/README.md +4 -4
- package/dist/umd/index.bundle.js +93 -93
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +93 -93
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +151 -151
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/index.js +329 -83
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1,94 +1,340 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { css, html, LitElement } from "lit";
|
|
17
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
18
|
+
import { AssetModelUtil } from "@openremote/model";
|
|
19
|
+
import { Gauge } from "gaugeJS";
|
|
20
|
+
import manager, { Util } from "@openremote/core";
|
|
21
|
+
import { i18next } from "@openremote/or-translate";
|
|
22
|
+
import { debounce } from "lodash";
|
|
23
|
+
import { getAssetDescriptorIconTemplate } from "@openremote/or-icon";
|
|
24
|
+
//language=css
|
|
25
|
+
const styling = css `
|
|
26
|
+
:host {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#chart-wrapper {
|
|
33
|
+
position: relative;
|
|
34
|
+
width: 100%;
|
|
35
|
+
height: 100%;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
justify-content: center;
|
|
38
|
+
align-items: center;
|
|
39
|
+
}
|
|
40
|
+
#chart-container {
|
|
41
|
+
display: flex;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
align-items: center;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#chart {
|
|
47
|
+
width: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.chart-description {
|
|
51
|
+
margin: 0 20px;
|
|
52
|
+
font-size: 16px;
|
|
53
|
+
z-index: 3;
|
|
54
|
+
}
|
|
55
|
+
.mainvalue-wrapper {
|
|
56
|
+
width: 100%;
|
|
57
|
+
display: flex;
|
|
58
|
+
flex: 0 0 60px;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
}
|
|
62
|
+
.main-number {
|
|
63
|
+
color: var(--internal-or-asset-viewer-title-text-color);
|
|
64
|
+
font-size: 42px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.main-number-icon {
|
|
68
|
+
font-size: 24px;
|
|
69
|
+
margin-right: 10px;
|
|
70
|
+
display: flex;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.main-number-unit {
|
|
74
|
+
font-size: 42px;
|
|
75
|
+
color: var(--internal-or-asset-viewer-title-text-color);
|
|
76
|
+
font-weight: 200;
|
|
77
|
+
margin-left: 5px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.main-number.xs, .main-number-unit.xs {
|
|
81
|
+
font-size: 18px;
|
|
82
|
+
}
|
|
83
|
+
.main-number.s, .main-number-unit.s {
|
|
84
|
+
font-size: 24px;
|
|
85
|
+
}
|
|
86
|
+
.main-number.m, .main-number-unit.m {
|
|
87
|
+
font-size: 30px;
|
|
88
|
+
}
|
|
89
|
+
.main-number.l, .main-number-unit.l {
|
|
90
|
+
font-size: 36px;
|
|
91
|
+
}
|
|
92
|
+
.main-number.xl, .main-number-unit.xl {
|
|
93
|
+
font-size: 42px;
|
|
94
|
+
}
|
|
95
|
+
.main-number.unknown, .main-number-unit.unknown {
|
|
96
|
+
font-size: unset;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
let OrGauge = class OrGauge extends LitElement {
|
|
100
|
+
static get styles() {
|
|
101
|
+
return [styling];
|
|
6
102
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
103
|
+
constructor() {
|
|
104
|
+
super();
|
|
105
|
+
this.decimals = 0;
|
|
106
|
+
this.loading = false;
|
|
107
|
+
if (!this.config) {
|
|
108
|
+
this.config = this.getDefaultConfig();
|
|
109
|
+
}
|
|
110
|
+
// Register observer when gauge size changes
|
|
111
|
+
this.updateComplete.then(() => {
|
|
112
|
+
this.resizeObserver = new ResizeObserver(debounce((entries) => {
|
|
113
|
+
const size = entries[0].contentRect;
|
|
114
|
+
this.gaugeSize = {
|
|
115
|
+
width: size.width,
|
|
116
|
+
height: size.height
|
|
117
|
+
};
|
|
118
|
+
this.updateComplete.then(() => {
|
|
119
|
+
this.setupGauge(); // recreate gauge since the library is not 100% responsive.
|
|
120
|
+
});
|
|
121
|
+
}, 200));
|
|
122
|
+
this.resizeObserver.observe(this._wrapperElem);
|
|
123
|
+
});
|
|
15
124
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
125
|
+
// Processing changes before update, to prevent extra render
|
|
126
|
+
willUpdate(changedProps) {
|
|
127
|
+
if (changedProps.has('assetAttribute')) {
|
|
128
|
+
const attr = this.assetAttribute[1];
|
|
129
|
+
const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(attr.name, this.asset.type);
|
|
130
|
+
this.unit = Util.resolveUnits(Util.getAttributeUnits(attr, attributeDescriptor, this.asset.type));
|
|
131
|
+
this.value = attr.value != null ? attr.value : NaN;
|
|
132
|
+
}
|
|
20
133
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
134
|
+
// After render took place...
|
|
135
|
+
updated(changedProperties) {
|
|
136
|
+
var _a, _b, _c, _d;
|
|
137
|
+
if (changedProperties.has('value')) {
|
|
138
|
+
(_a = this.gauge) === null || _a === void 0 ? void 0 : _a.set(this.value != null ? this.value : NaN);
|
|
139
|
+
}
|
|
140
|
+
if (changedProperties.has('attrRef')) {
|
|
141
|
+
if (this.attrRef) {
|
|
142
|
+
this.loadData(this.attrRef);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.assetAttribute = undefined;
|
|
146
|
+
this.value = undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Render gauge again if..
|
|
150
|
+
if (changedProperties.has('min') && this.min != null && this.gauge) {
|
|
151
|
+
this.gauge.setMinValue(this.min);
|
|
152
|
+
this.gauge.set(this.value != null ? this.value : NaN);
|
|
153
|
+
}
|
|
154
|
+
if (changedProperties.has('max') && this.max != null && this.gauge) {
|
|
155
|
+
this.gauge.maxValue = this.max;
|
|
156
|
+
this.gauge.set(this.value != null ? this.value : NaN);
|
|
157
|
+
}
|
|
158
|
+
if (changedProperties.has('thresholds') && this.thresholds) {
|
|
159
|
+
// Make staticZones out of the thresholds.
|
|
160
|
+
// If below the minimum or above the maximum, set the value according to it.
|
|
161
|
+
this.config.options.staticZones = [];
|
|
162
|
+
this.thresholds.sort((x, y) => (x[0] < y[0]) ? -1 : 1).forEach(((threshold, index) => {
|
|
163
|
+
var _a, _b, _c;
|
|
164
|
+
const min = threshold[0];
|
|
165
|
+
const max = (this.thresholds[index + 1] ? this.thresholds[index + 1][0] : this.max);
|
|
166
|
+
const zone = {
|
|
167
|
+
strokeStyle: threshold[1],
|
|
168
|
+
min: ((this.min && min && this.min > min) ? this.min : ((this.max && min && this.max < min) ? this.max : min)),
|
|
169
|
+
max: ((this.max && max && this.max < max) ? this.max : ((this.min && max && this.min > max) ? this.min : max))
|
|
170
|
+
};
|
|
171
|
+
(_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.staticZones) === null || _c === void 0 ? void 0 : _c.push(zone);
|
|
172
|
+
}));
|
|
173
|
+
// The lowest staticZone should ALWAYS have the minimum value, to prevent the graphic displaying incorrectly.
|
|
174
|
+
if (this.min && ((_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.staticZones)) {
|
|
175
|
+
this.config.options.staticZones[0].min = this.min;
|
|
176
|
+
}
|
|
177
|
+
// Applying the options we changed.
|
|
178
|
+
if (this.gauge) {
|
|
179
|
+
this.gauge.setOptions((_d = this.config) === null || _d === void 0 ? void 0 : _d.options);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
24
182
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
183
|
+
setupGauge() {
|
|
184
|
+
var _a;
|
|
185
|
+
this.gauge = new Gauge(this._gaugeElem);
|
|
186
|
+
this.gauge.setOptions((_a = this.config) === null || _a === void 0 ? void 0 : _a.options);
|
|
187
|
+
this.gauge.maxValue = (this.max ? this.max : 100);
|
|
188
|
+
this.gauge.setMinValue(this.min ? this.min : 0);
|
|
189
|
+
this.gauge.animationSpeed = 1;
|
|
190
|
+
this.gauge.set(this.value != null ? this.value : NaN);
|
|
191
|
+
if (this.value == null && this.attrRef) {
|
|
192
|
+
this.loadData(this.attrRef);
|
|
193
|
+
}
|
|
30
194
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
195
|
+
getGaugeWidth(gaugeSize, includeLabelHeight = true) {
|
|
196
|
+
if (!gaugeSize) {
|
|
197
|
+
return "unset";
|
|
198
|
+
}
|
|
199
|
+
const width = gaugeSize.width;
|
|
200
|
+
const height = (includeLabelHeight ? (gaugeSize.height - this._detailsElem.clientHeight) : gaugeSize.height) * 1.5;
|
|
201
|
+
return Math.min(width, height) + "px";
|
|
37
202
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
font-size: 42px;
|
|
203
|
+
shouldShowLabel(gaugeSize) {
|
|
204
|
+
return (gaugeSize.width > 70) && (gaugeSize.height > 100);
|
|
41
205
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
206
|
+
getLabelSize(width) {
|
|
207
|
+
if (width < 120) {
|
|
208
|
+
return "s";
|
|
209
|
+
}
|
|
210
|
+
else if (width < 240) {
|
|
211
|
+
return "m";
|
|
212
|
+
}
|
|
213
|
+
else if (width < 320) {
|
|
214
|
+
return "l";
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return "xl";
|
|
218
|
+
}
|
|
47
219
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
220
|
+
render() {
|
|
221
|
+
const formattedVal = (this.value != null ? +this.value.toFixed(this.decimals) : NaN); // + operator prevents str return
|
|
222
|
+
// Set width/height values based on size
|
|
223
|
+
const showLabel = this.gaugeSize ? this.shouldShowLabel(this.gaugeSize) : true;
|
|
224
|
+
const labelSize = showLabel && this.gaugeSize ? this.getLabelSize(this.gaugeSize.width) : "unknown";
|
|
225
|
+
const gaugeWidth = this.getGaugeWidth(this.gaugeSize, showLabel);
|
|
226
|
+
return html `
|
|
227
|
+
<div style="position: relative; height: 100%; width: 100%;">
|
|
228
|
+
<div id="chart-wrapper" style="display: ${this.loading ? 'none' : 'flex'};">
|
|
229
|
+
<div id="chart-container" style="flex: 0 0 0; width: ${gaugeWidth};">
|
|
230
|
+
<canvas id="chart"></canvas>
|
|
231
|
+
</div>
|
|
232
|
+
<div id="details-container">
|
|
233
|
+
${showLabel ? html `
|
|
234
|
+
<div class="mainvalue-wrapper">
|
|
235
|
+
<span class="main-number-icon">${this.asset ? getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.asset.type)) : ""}</span>
|
|
236
|
+
<span class="main-number ${labelSize}">${formattedVal}</span>
|
|
237
|
+
<span class="main-number-unit ${labelSize}">${this.unit ? this.unit : ""}</span>
|
|
238
|
+
</div>
|
|
239
|
+
` : undefined}
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
${this.loading ? html `
|
|
244
|
+
<span>${i18next.t('loading')}</span>
|
|
245
|
+
` : undefined}
|
|
246
|
+
`;
|
|
54
247
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
248
|
+
loadData(attrRef) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
const response = yield manager.rest.api.AssetResource.queryAssets({ ids: [attrRef.id] });
|
|
251
|
+
const assets = response.data;
|
|
252
|
+
const assetAttributes = [attrRef].map((attrRef) => {
|
|
253
|
+
const assetIndex = assets.findIndex((asset) => asset.id === attrRef.id);
|
|
254
|
+
const asset = assetIndex >= 0 ? assets[assetIndex] : undefined;
|
|
255
|
+
return asset && asset.attributes ? [assetIndex, asset.attributes[attrRef.name]] : undefined;
|
|
256
|
+
}).filter((indexAndAttr) => !!indexAndAttr);
|
|
257
|
+
this.asset = assets[0];
|
|
258
|
+
this.assetAttribute = assetAttributes[0];
|
|
259
|
+
});
|
|
58
260
|
}
|
|
59
|
-
|
|
60
|
-
|
|
261
|
+
getDefaultConfig() {
|
|
262
|
+
return {
|
|
263
|
+
attributeRef: undefined,
|
|
264
|
+
options: {
|
|
265
|
+
angle: 0,
|
|
266
|
+
lineWidth: 0.4,
|
|
267
|
+
radiusScale: 1,
|
|
268
|
+
pointer: {
|
|
269
|
+
length: 0.5,
|
|
270
|
+
strokeWidth: 0.035,
|
|
271
|
+
color: "#000000",
|
|
272
|
+
},
|
|
273
|
+
staticZones: [],
|
|
274
|
+
limitMax: true,
|
|
275
|
+
limitMin: true,
|
|
276
|
+
colorStart: "#000000",
|
|
277
|
+
colorStop: "#707070",
|
|
278
|
+
strokeColor: "#ABCDEF",
|
|
279
|
+
generateGradient: false,
|
|
280
|
+
highDpiSupport: true
|
|
281
|
+
}
|
|
282
|
+
};
|
|
61
283
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
284
|
+
};
|
|
285
|
+
__decorate([
|
|
286
|
+
property({ type: Object })
|
|
287
|
+
], OrGauge.prototype, "attrRef", void 0);
|
|
288
|
+
__decorate([
|
|
289
|
+
property({ type: Object })
|
|
290
|
+
], OrGauge.prototype, "asset", void 0);
|
|
291
|
+
__decorate([
|
|
292
|
+
property({ type: Object })
|
|
293
|
+
], OrGauge.prototype, "assetAttribute", void 0);
|
|
294
|
+
__decorate([
|
|
295
|
+
property()
|
|
296
|
+
], OrGauge.prototype, "value", void 0);
|
|
297
|
+
__decorate([
|
|
298
|
+
property()
|
|
299
|
+
], OrGauge.prototype, "decimals", void 0);
|
|
300
|
+
__decorate([
|
|
301
|
+
property()
|
|
302
|
+
], OrGauge.prototype, "unit", void 0);
|
|
303
|
+
__decorate([
|
|
304
|
+
property()
|
|
305
|
+
], OrGauge.prototype, "min", void 0);
|
|
306
|
+
__decorate([
|
|
307
|
+
property()
|
|
308
|
+
], OrGauge.prototype, "max", void 0);
|
|
309
|
+
__decorate([
|
|
310
|
+
property()
|
|
311
|
+
], OrGauge.prototype, "thresholds", void 0);
|
|
312
|
+
__decorate([
|
|
313
|
+
property()
|
|
314
|
+
], OrGauge.prototype, "config", void 0);
|
|
315
|
+
__decorate([
|
|
316
|
+
property({ type: String })
|
|
317
|
+
], OrGauge.prototype, "realm", void 0);
|
|
318
|
+
__decorate([
|
|
319
|
+
state()
|
|
320
|
+
], OrGauge.prototype, "loading", void 0);
|
|
321
|
+
__decorate([
|
|
322
|
+
state()
|
|
323
|
+
], OrGauge.prototype, "gauge", void 0);
|
|
324
|
+
__decorate([
|
|
325
|
+
state()
|
|
326
|
+
], OrGauge.prototype, "gaugeSize", void 0);
|
|
327
|
+
__decorate([
|
|
328
|
+
query("#chart")
|
|
329
|
+
], OrGauge.prototype, "_gaugeElem", void 0);
|
|
330
|
+
__decorate([
|
|
331
|
+
query("#chart-wrapper")
|
|
332
|
+
], OrGauge.prototype, "_wrapperElem", void 0);
|
|
333
|
+
__decorate([
|
|
334
|
+
query("#details-container")
|
|
335
|
+
], OrGauge.prototype, "_detailsElem", void 0);
|
|
336
|
+
OrGauge = __decorate([
|
|
337
|
+
customElement("or-gauge")
|
|
338
|
+
], OrGauge);
|
|
339
|
+
export { OrGauge };
|
|
340
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openremote/or-gauge",
|
|
3
|
-
"version": "1.8.0-snapshot.
|
|
3
|
+
"version": "1.8.0-snapshot.20250725120000",
|
|
4
4
|
"description": "OpenRemote gauge",
|
|
5
5
|
"customElements": "custom-elements.json",
|
|
6
6
|
"main": "dist/umd/index.bundle.js",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"author": "OpenRemote",
|
|
19
19
|
"license": "AGPL-3.0-or-later",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@openremote/core": "1.8.0-snapshot.
|
|
22
|
-
"@openremote/or-components": "1.8.0-snapshot.
|
|
23
|
-
"@openremote/or-icon": "1.8.0-snapshot.
|
|
24
|
-
"@openremote/or-mwc-components": "1.8.0-snapshot.
|
|
25
|
-
"@openremote/or-translate": "1.8.0-snapshot.
|
|
21
|
+
"@openremote/core": "1.8.0-snapshot.20250725120000",
|
|
22
|
+
"@openremote/or-components": "1.8.0-snapshot.20250725120000",
|
|
23
|
+
"@openremote/or-icon": "1.8.0-snapshot.20250725120000",
|
|
24
|
+
"@openremote/or-mwc-components": "1.8.0-snapshot.20250725120000",
|
|
25
|
+
"@openremote/or-translate": "1.8.0-snapshot.20250725120000",
|
|
26
26
|
"gaugeJS": "^1.3.7",
|
|
27
27
|
"lit": "^2.0.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@openremote/util": "1.8.0-snapshot.
|
|
30
|
+
"@openremote/util": "1.8.0-snapshot.20250725120000"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|