Skip to content

armgit / core

Public Imported from GitHub
0

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

Init or-chart component for or-asset-viewer

Robin Dekkersd2b7141a79b3
diff --git a/ui/app/main/src/components/pages/page-assets.ts b/ui/app/main/src/components/pages/page-assets.ts
index 882c1b54f..3241d563a 100644
--- a/ui/app/main/src/components/pages/page-assets.ts
+++ b/ui/app/main/src/components/pages/page-assets.ts
@@ -48,102 +48,293 @@ const style = css`
`;
const viewerConfig: ViewerConfig = {
+ historyConfig: {
+ table: {
+ attributeNames: {
+ "gunshotEvent": {
+ columns: [
+ {
+ header: "area",
+ type: "prop",
+ path: "$.content.area",
+ styles: {
+ width: "20%"
+ }
+ },
+ {
+ header: "location",
+ type: "prop",
+ path: "$.content.triggers[0].position.coordinates",
+ styles: {
+ width: "30%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (Array.isArray(value)) {
+ return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
+ }
+ }
+ },
+ {
+ header: "intensity",
+ type: "prop",
+ path: "$.content.triggers[0].intensity",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ }
+ },
+ {
+ header: "timestamp",
+ type: "prop",
+ path: "$.content.time",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (value) {
+ return moment(value).format("L HH:mm:ss");
+ }
+ }
+ }
+ ]
+ },
+ "aggressionEvent": {
+ columns: [
+ {
+ header: "area",
+ type: "prop",
+ path: "$.content.area",
+ styles: {
+ width: "20%"
+ }
+ },
+ {
+ header: "location",
+ type: "prop",
+ path: "$.content.triggers[0].position.coordinates",
+ styles: {
+ width: "30%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (Array.isArray(value)) {
+ return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
+ }
+ }
+ },
+ {
+ header: "intensity",
+ type: "prop",
+ path: "$.content.triggers[0].intensity",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ }
+ },
+ {
+ header: "timestamp",
+ type: "prop",
+ path: "$.content.time",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (value) {
+ return moment(value).format("L HH:mm:ss");
+ }
+ }
+ }
+ ]
+ },
+ "alarmEvent": {
+ columns: [
+ {
+ header: "area",
+ type: "prop",
+ path: "$.content.area",
+ styles: {
+ width: "20%"
+ }
+ },
+ {
+ header: "location",
+ type: "prop",
+ path: "$.content.triggers[0].position.coordinates",
+ styles: {
+ width: "30%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (Array.isArray(value)) {
+ return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
+ }
+ }
+ },
+ {
+ header: "intensity",
+ type: "prop",
+ path: "$.content.triggers[0].intensity",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ }
+ },
+ {
+ header: "timestamp",
+ type: "prop",
+ path: "$.content.time",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (value) {
+ return moment(value).format("L HH:mm:ss");
+ }
+ }
+ }
+ ]
+ },
+ "intensityEvent": {
+ columns: [
+ {
+ header: "area",
+ type: "prop",
+ path: "$.content.area",
+ styles: {
+ width: "20%"
+ }
+ },
+ {
+ header: "location",
+ type: "prop",
+ path: "$.content.triggers[0].position.coordinates",
+ styles: {
+ width: "30%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (Array.isArray(value)) {
+ return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
+ }
+ }
+ },
+ {
+ header: "intensity",
+ type: "prop",
+ path: "$.content.triggers[0].intensity",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ }
+ },
+ {
+ header: "timestamp",
+ type: "prop",
+ path: "$.content.time",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (value) {
+ return moment(value).format("L HH:mm:ss");
+ }
+ }
+ }
+ ]
+ },
+ "breakingGlassEvent": {
+ columns: [
+ {
+ header: "area",
+ type: "prop",
+ path: "$.content.area",
+ styles: {
+ width: "20%"
+ }
+ },
+ {
+ header: "location",
+ type: "prop",
+ path: "$.content.triggers[0].position.coordinates",
+ styles: {
+ width: "30%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (Array.isArray(value)) {
+ return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
+ }
+ }
+ },
+ {
+ header: "intensity",
+ type: "prop",
+ path: "$.content.triggers[0].intensity",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ }
+ },
+ {
+ header: "timestamp",
+ type: "prop",
+ path: "$.content.time",
+ styles: {
+ width: "25%"
+ },
+ contentProvider: (datapoint, value, config) => {
+ if (value) {
+ return moment(value).format("L HH:mm:ss");
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
default: {
panels: {
"attributes": {
exclude: ["location"]
+ },
+ "info": {
+ exclude: ["accessPublicRead"]
}
}
},
assetTypes: {
- "urn:openremote:asset:residence": {
+ "urn:openremote:asset:topic": {
panels: {
"attributes": {
- exclude: [
- "dayScene",
- "daySceneEnabledFRIDAY",
- "daySceneEnabledMONDAY",
- "daySceneEnabledTUESDAY",
- "daySceneEnabledWEDNESDAY",
- "daySceneEnabledTHURSDAY",
- "daySceneEnabledSATURDAY",
- "daySceneEnabledSUNDAY",
- "daySceneTimeFRIDAY",
- "daySceneTimeMONDAY",
- "daySceneTimeTUESDAY",
- "daySceneTimeWEDNESDAY",
- "daySceneTimeTHURSDAY",
- "daySceneTimeSATURDAY",
- "daySceneTimeSUNDAY",
- "disableSceneTimer",
- "enableSceneTimer",
- "eveningScene",
- "dayScene",
- "eveningSceneEnabledFRIDAY",
- "eveningSceneEnabledMONDAY",
- "eveningSceneEnabledTUESDAY",
- "eveningSceneEnabledWEDNESDAY",
- "eveningSceneEnabledTHURSDAY",
- "eveningSceneEnabledSATURDAY",
- "eveningSceneEnabledSUNDAY",
- "eveningSceneTimeFRIDAY",
- "eveningSceneTimeMONDAY",
- "eveningSceneTimeTUESDAY",
- "eveningSceneTimeWEDNESDAY",
- "eveningSceneTimeTHURSDAY",
- "eveningSceneTimeSATURDAY",
- "eveningSceneTimeSUNDAY",
- "morningScene",
- "nightscene",
- "morningSceneEnabledFRIDAY",
- "morningSceneEnabledMONDAY",
- "morningSceneEnabledTUESDAY",
- "morningSceneEnabledWEDNESDAY",
- "morningSceneEnabledTHURSDAY",
- "morningSceneEnabledSATURDAY",
- "morningSceneEnabledSUNDAY",
- "morningSceneTimeFRIDAY",
- "morningSceneTimeMONDAY",
- "morningSceneTimeTUESDAY",
- "morningSceneTimeWEDNESDAY",
- "morningSceneTimeTHURSDAY",
- "morningSceneTimeSATURDAY",
- "morningSceneTimeSUNDAY",
- "nightSceneEnabledFRIDAY",
- "nightSceneEnabledMONDAY",
- "nightSceneEnabledTUESDAY",
- "nightSceneEnabledWEDNESDAY",
- "nightSceneEnabledTHURSDAY",
- "nightSceneEnabledSATURDAY",
- "nightSceneEnabledSUNDAY",
- "nightSceneTimeFRIDAY",
- "nightSceneTimeMONDAY",
- "nightSceneTimeTUESDAY",
- "nightSceneTimeWEDNESDAY",
- "nightSceneTimeTHURSDAY",
- "nightSceneTimeSATURDAY",
- "nightSceneTimeSUNDAY",
- "vacationUntil",
- "ventilationLevel",
- "location",
- "firstPresenceDetected",
- "lastPresenceDetected",
- "smartSwitchStartTimeA",
- "smartSwitchStartTimeB",
- "smartSwitchStartTimeC",
- "smartSwitchEnabledA",
- "smartSwitchEnabledB",
- "smartSwitchEnabledC",
- "smartSwitchStopTimeA",
- "smartSwitchStopTimeB",
- "smartSwitchStopTimeC",
- "smartSwitchBeginEndA",
- "smartSwitchBeginEndB",
- "smartSwitchBeginEndC",
- "smartSwitchModeA",
- "smartSwitchModeB",
- "smartSwitchModeC"
- ]
+ exclude: ["location", "status"]
+ }
+ }
+ },
+ "urn:openremote:asset:tcn:soilmoisture": {
+ panels: {
+ "attributes": {
+ exclude: ["location", "name", "id", "code", "type"]
+ }
+ }
+ },
+ "urn:openremote:asset:tcn:meteo": {
+ panels: {
+ "attributes": {
+ exclude: ["location", "name", "id", "code", "type"]
+ }
+ }
+ },
+ "urn:openremote:asset:tcn:point": {
+ panels: {
+ "attributes": {
+ exclude: ["location", "name", "id", "code", "type"]
}
}
}
@@ -160,15 +351,14 @@ class PageAssets extends connect(store)(LitElement) {
@property()
protected _assetId;
- constructor() {
- super();
- this.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, (evt) => this._onTreeSelectionChanged(evt));
+ firstUpdated() {
+ this.shadowRoot.getElementById('pageAssetTree').addEventListener(OrAssetTreeSelectionChangedEvent.NAME, (evt) => this._onTreeSelectionChanged(evt));
}
protected render(): TemplateResult | void {
const selectedIds = [this._assetId];
return html`
- <or-asset-tree class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
+ <or-asset-tree id="pageAssetTree" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
<or-asset-viewer class="${!this._assetId ? "hideMobile" : ""}" .config="${viewerConfig}" .assetId="${this._assetId}"></or-asset-viewer>
`;
}
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index 536243b6d..7cb5c7893 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -520,7 +520,6 @@ export class OrAssetTree extends LitElement {
select: {
excludePath: true,
excludeRealm: true,
- excludeAttributes: true,
excludeParentInfo: false
}
};
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 5e1edc01a..fd0b71927 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -3,12 +3,14 @@ import "@openremote/or-icon";
import "@openremote/or-input";
import "@openremote/or-attribute-input";
import "@openremote/or-attribute-history";
+import "@openremote/or-chart";
import "@openremote/or-translate";
import {translate} from "@openremote/or-translate";
import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";
import "@openremote/or-map";
import manager, {subscribe, Util, AssetModelUtil} from "@openremote/core";
import "@openremote/or-panel";
+import {ChartConfig, OrChartEvent} from "@openremote/or-chart";
import {HistoryConfig, OrAttributeHistory, OrAttributeHistoryEvent} from "@openremote/or-attribute-history";
import {Type as MapType, Util as MapUtil} from "@openremote/or-map";
import {
@@ -27,7 +29,7 @@ import i18next from "i18next";
import {styleMap} from "lit-html/directives/style-map";
import {classMap} from "lit-html/directives/class-map";
-export type PanelType = "property" | "location" | "attribute" | "history";
+export type PanelType = "property" | "location" | "attribute" | "history" | "chart";
export interface PanelConfig {
type?: PanelType;
@@ -48,6 +50,7 @@ export interface AssetViewerConfig {
panelViewProvider?: (attributes: AssetAttribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
mapType?: MapType;
historyConfig?: HistoryConfig;
+ chartConfig?: ChartConfig;
}
export interface ViewerConfig {
@@ -129,6 +132,13 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
type: "history",
panelStyles: {
}
+ },
+ "chart": {
+ type: "chart",
+ panelStyles: {
+ gridColumn: "1 / -1",
+ gridRowStart: "1"
+ }
}
}
};
@@ -166,7 +176,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
constructor() {
super();
window.addEventListener('resize', () => OrAssetViewer.generateGrid(this.shadowRoot));
-
+
+ this.addEventListener(OrChartEvent.NAME,() => OrAssetViewer.generateGrid(this.shadowRoot));
this.addEventListener(OrAttributeHistoryEvent.NAME,() => OrAssetViewer.generateGrid(this.shadowRoot));
}
@@ -367,6 +378,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
}
};
+
const options = historyAttrs.map((attr) => [attr.name, Util.getAttributeLabel(attr, undefined)]);
const attrName:string = historyAttrs[0].name!;
onRenderComplete.addCallback(() => attributeChanged(attrName));
@@ -422,6 +434,13 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
`;
}
+
+ } else if (panelConfig && panelConfig.type === "chart") {
+
+ content = html`
+ <or-chart id="chart" .config="${viewerConfig.chartConfig}"></or-chart>
+ `;
+
} else if (panelConfig && panelConfig.type === "location") {
const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);
if (attribute) {
diff --git a/ui/component/or-chart/.npmignore b/ui/component/or-chart/.npmignore
new file mode 100644
index 000000000..17e64b1ad
--- /dev/null
+++ b/ui/component/or-chart/.npmignore
@@ -0,0 +1,8 @@
+build/
+build.gradle
+test/
+src/
+webpack.config.js
+tsconfig.json
+dist/*.map
+.tsbuildinfo
\ No newline at end of file
diff --git a/ui/component/or-chart/README.md b/ui/component/or-chart/README.md
new file mode 100644
index 000000000..218c473c4
--- /dev/null
+++ b/ui/component/or-chart/README.md
@@ -0,0 +1,31 @@
+# @openremote/or-chart \<or-attribute-history\>
+[![NPM Version][npm-image]][npm-url]
+[![Linux Build][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
+
+Web Component for displaying chart values.
+
+## Install
+```bash
+npm i @openremote/or-chart
+yarn add @openremote/or-chart
+```
+
+## Usage
+For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().
+
+
+## Supported Browsers
+The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,
+Internet Explorer 11 is also supported.
+
+
+## License
+[GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)
+
+[npm-image]: https://img.shields.io/npm/v/live-xxx.svg
+[npm-url]: https://npmjs.org/package/@openremote/or-input
+[travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg
+[travis-url]: https://travis-ci.org/live-js/live-xxx
+[coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg
+[coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=master
diff --git a/ui/component/or-chart/build.gradle b/ui/component/or-chart/build.gradle
new file mode 100644
index 000000000..98cdcb8e2
--- /dev/null
+++ b/ui/component/or-chart/build.gradle
@@ -0,0 +1,15 @@
+buildDir = "dist"
+
+task clean() {
+ doLast {
+ delete "dist"
+ }
+}
+
+task prepareUi() {
+ dependsOn clean, npmPrepare
+}
+
+task publishUi() {
+ dependsOn clean, npmPublish
+}
\ No newline at end of file
diff --git a/ui/component/or-chart/package-lock.json b/ui/component/or-chart/package-lock.json
new file mode 100644
index 000000000..0b2a5d468
--- /dev/null
+++ b/ui/component/or-chart/package-lock.json
@@ -0,0 +1,205 @@
+{
+ "name": "@openremote/or-chart",
+ "version": "1.1.0",
+ "lockfileVersion": 1,
+ "requires": true,
+ "dependencies": {
+ "@material/animation": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/animation/-/animation-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-reEvoJue3XYRTZaNmVOj+1l41w1N8ix7KgzICHSR7d474G0VHQPp9v6ylvvB/QUsyew3xcE7YaqTSdP67nA54A==",
+ "requires": {
+ "tslib": "^1.9.3"
+ }
+ },
+ "@material/base": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/base/-/base-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-K23UTOxLrbEqAkbKb0aYSkLJ4L8d6vSlzx908iGTho9ybFLUcamRvQfav0mgpACmlPIxwrkbN40KAzGApTt4Gw==",
+ "requires": {
+ "tslib": "^1.9.3"
+ }
+ },
+ "@material/dialog": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/dialog/-/dialog-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-ikDUG7ATIK44IBwVS4kh8A7r34xl4591WnIOIQpxTQv8geIXPbVd1TIilvJKg0mdGjA5yybTxdyOoBkPxDycbg==",
+ "requires": {
+ "@material/animation": "5.0.0-canary.1c494e567.0",
+ "@material/base": "5.0.0-canary.1c494e567.0",
+ "@material/dom": "5.0.0-canary.1c494e567.0",
+ "@material/elevation": "5.0.0-canary.1c494e567.0",
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0",
+ "@material/ripple": "5.0.0-canary.1c494e567.0",
+ "@material/rtl": "5.0.0-canary.1c494e567.0",
+ "@material/shape": "5.0.0-canary.1c494e567.0",
+ "@material/theme": "5.0.0-canary.1c494e567.0",
+ "@material/touch-target": "5.0.0-canary.1c494e567.0",
+ "@material/typography": "5.0.0-canary.1c494e567.0",
+ "focus-trap": "^5.0.0",
+ "tslib": "^1.9.3"
+ }
+ },
+ "@material/dom": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/dom/-/dom-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-O4GDLRXFA9PJbTfkqEhuI+Yow6dKHiDLdDDNX366rLpbpPyOXrblOW7WVRhLE+L/iuocdPqNYs9sUKQMiW75UQ==",
+ "requires": {
+ "tslib": "^1.9.3"
+ }
+ },
+ "@material/elevation": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/elevation/-/elevation-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-4jmBnUbdqTfqY0SgHSU5j8w0nDLR4Tk/GX49ulvttcjsjv5ZLOrsUez62qx0Q9xWIjCra2kBSOmU+Gbz/D5uDQ==",
+ "requires": {
+ "@material/animation": "5.0.0-canary.1c494e567.0",
+ "@material/base": "5.0.0-canary.1c494e567.0",
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0",
+ "@material/theme": "5.0.0-canary.1c494e567.0"
+ }
+ },
+ "@material/feature-targeting": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/feature-targeting/-/feature-targeting-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-Ti3CIVLJMXmTZsZjtUeAP2sdAb9nNTHK7EIdLLZjcrYe2GexWtJPS//AXDK7PDkBj7kYqIP7xUdUGfVYSz+g4Q=="
+ },
+ "@material/mwc-base": {
+ "version": "0.12.0",
+ "resolved": "https://registry.npmjs.org/@material/mwc-base/-/mwc-base-0.12.0.tgz",
+ "integrity": "sha512-JjhZbzrs6WM9Gjo6IIsdMXORh4F4BTESa+SnV4lqhpfBdDJhWcADvPD9WrU23MS3p+/f/1SzUrRKyQ9dfumCSw==",
+ "requires": {
+ "@material/base": "=5.0.0-canary.1c494e567.0",
+ "@material/dom": "=5.0.0-canary.1c494e567.0",
+ "@material/ripple": "=5.0.0-canary.1c494e567.0",
+ "lit-element": "^2.2.1",
+ "tslib": "^1.10.0"
+ },
+ "dependencies": {
+ "lit-element": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/lit-element/-/lit-element-2.2.1.tgz",
+ "integrity": "sha512-ipDcgQ1EpW6Va2Z6dWm79jYdimVepO5GL0eYkZrFvdr0OD/1N260Q9DH+K5HXHFrRoC7dOg+ZpED2XE0TgGdXw==",
+ "requires": {
+ "lit-html": "^1.0.0"
+ }
+ }
+ }
+ },
+ "@material/mwc-dialog": {
+ "version": "0.12.0",
+ "resolved": "https://registry.npmjs.org/@material/mwc-dialog/-/mwc-dialog-0.12.0.tgz",
+ "integrity": "sha512-5WmBd2flbqJsNHXBBpQXon3tVzFbEC9COQYulaZJWNs6HFaPNFkHELrgfhn66yIb2UDCgd3DTKFZdhdfuqvykQ==",
+ "requires": {
+ "@material/dialog": "=5.0.0-canary.1c494e567.0",
+ "@material/dom": "=5.0.0-canary.1c494e567.0",
+ "@material/mwc-base": "^0.12.0",
+ "@material/touch-target": "=5.0.0-canary.1c494e567.0",
+ "blocking-elements": "^0.1.0",
+ "lit-element": "^2.2.1",
+ "lit-html": "^1.1.2",
+ "tslib": "^1.10.0",
+ "wicg-inert": "^3.0.0"
+ },
+ "dependencies": {
+ "lit-element": {
+ "version": "2.2.1",
+ "resolved": "https://registry.npmjs.org/lit-element/-/lit-element-2.2.1.tgz",
+ "integrity": "sha512-ipDcgQ1EpW6Va2Z6dWm79jYdimVepO5GL0eYkZrFvdr0OD/1N260Q9DH+K5HXHFrRoC7dOg+ZpED2XE0TgGdXw==",
+ "requires": {
+ "lit-html": "^1.0.0"
+ }
+ }
+ }
+ },
+ "@material/ripple": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/ripple/-/ripple-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-AJZ/eL2dFF6kVa5w6Tl8TiLjoBE1IcA96sZFUPdNJqBM4ddHpHoFejrkJOt7dVxmAIOgHjktUo8+5vHDOAE14w==",
+ "requires": {
+ "@material/animation": "5.0.0-canary.1c494e567.0",
+ "@material/base": "5.0.0-canary.1c494e567.0",
+ "@material/dom": "5.0.0-canary.1c494e567.0",
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0",
+ "@material/theme": "5.0.0-canary.1c494e567.0",
+ "tslib": "^1.9.3"
+ }
+ },
+ "@material/rtl": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/rtl/-/rtl-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-Xmfp0UWS7MN7IyHDEl0dgn30Gpb/G5B22gwbi/lfrwjt5/gVM8EBUTKR07+a8y54K8pgmapaJUhopOzNs4DpGg=="
+ },
+ "@material/shape": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/shape/-/shape-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-WG/C8y/r+PgZ07E6syrVJYY2hjOPg9SypFvMd4LQeKYahMTRuZr4T+CEg9WxR496e51UrrUFtAL8D6oqMLiY2A==",
+ "requires": {
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0"
+ }
+ },
+ "@material/theme": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/theme/-/theme-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-U4u326P7h3r3dz+0y3LlqlBqh2oyhXdpzuhdBuhVBKyW/3cMup+BWMBaNBcx/W9igFKWdkk5Z9AoLguoDpBLqg==",
+ "requires": {
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0"
+ }
+ },
+ "@material/touch-target": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/touch-target/-/touch-target-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-K6he0fCA63ruaR1I19M7PMNJW1m2t50YiX/UUQSJFtGq72WmA6NXu8CEWjuPI8mPXNbl8pMFCnv7UXsLANyvSg==",
+ "requires": {
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0"
+ }
+ },
+ "@material/typography": {
+ "version": "5.0.0-canary.1c494e567.0",
+ "resolved": "https://registry.npmjs.org/@material/typography/-/typography-5.0.0-canary.1c494e567.0.tgz",
+ "integrity": "sha512-Mg2nTMokH9Y+5/Omd/jUKV5CHUO6zCVmDKqAOxeFpjsYVMRi2NwrAhplMmKNwipmQFoguP84zN8jhpl3gK6gbw==",
+ "requires": {
+ "@material/feature-targeting": "5.0.0-canary.1c494e567.0"
+ }
+ },
+ "blocking-elements": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/blocking-elements/-/blocking-elements-0.1.0.tgz",
+ "integrity": "sha512-m9UvynAHLhlWH4vSovSDAopW7DyJ91qeDnNrJqy+DE+tjhUYiXW1x7pOm3DZBczlQPPypWpOwOz5xd5A76vNvg=="
+ },
+ "focus-trap": {
+ "version": "5.1.0",
+ "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-5.1.0.tgz",
+ "integrity": "sha512-CkB/nrO55069QAUjWFBpX6oc+9V90Qhgpe6fBWApzruMq5gnlh90Oo7iSSDK7pKiV5ugG6OY2AXM5mxcmL3lwQ==",
+ "requires": {
+ "tabbable": "^4.0.0",
+ "xtend": "^4.0.1"
+ }
+ },
+ "lit-html": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/lit-html/-/lit-html-1.1.2.tgz",
+ "integrity": "sha512-FFlUMKHKi+qG1x1iHNZ1hrtc/zHmfYTyrSvs3/wBTvaNtpZjOZGWzU7efGYVpgp6KvWeKF6ql9/KsCq6Z/mEDA=="
+ },
+ "tabbable": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-4.0.0.tgz",
+ "integrity": "sha512-H1XoH1URcBOa/rZZWxLxHCtOdVUEev+9vo5YdYhC9tCY4wnybX+VQrCYuy9ubkg69fCBxCONJOSLGfw0DWMffQ=="
+ },
+ "tslib": {
+ "version": "1.10.0",
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
+ "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
+ },
+ "wicg-inert": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/wicg-inert/-/wicg-inert-3.0.1.tgz",
+ "integrity": "sha512-ge5a5cTzkESRLPx7saeKVnJsxEZCs2h8Yx9Jnl3IAuYpeL7AO06CVWem7GU2P/HP8X+s6u3OcAiMHOBYpXSNkg=="
+ },
+ "xtend": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
+ "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
+ }
+ }
+}
diff --git a/ui/component/or-chart/package.json b/ui/component/or-chart/package.json
new file mode 100644
index 000000000..2eb8a89ac
--- /dev/null
+++ b/ui/component/or-chart/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "@openremote/or-chart",
+ "version": "1.1.0",
+ "description": "OpenRemote chart",
+ "main": "dist/umd/index.bundle.js",
+ "module": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "scripts": {
+ "test": "echo \"No tests\" && exit 0",
+ "prepublishOnly": "npx tsc -b && npx webpack"
+ },
+ "author": "OpenRemote",
+ "license": "AGPL-3.0-or-later",
+ "dependencies": {
+ "@material/data-table": "^4.0.0",
+ "@material/mwc-dialog": "^0.12.0",
+ "@openremote/core": "^1.1.0",
+ "@openremote/or-input": "^1.1.0",
+ "@openremote/or-panel": "^1.1.0",
+ "@openremote/or-translate": "^1.1.0",
+ "chart.js": "^2.8.0",
+ "jsonpath-plus": "^1.1.0",
+ "lit-element": "^2.2.1",
+ "moment": "^2.24.0"
+ },
+ "devDependencies": {
+ "@types/chart.js": "^2.8.5",
+ "tslint": ">=5.11.0",
+ "typescript": ">=3.4.5",
+ "webpack": "^4.41.2",
+ "webpack-cli": "^3.3.9"
+ }
+}
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
new file mode 100644
index 000000000..6948d6c9d
--- /dev/null
+++ b/ui/component/or-chart/src/index.ts
@@ -0,0 +1,614 @@
+import {
+ css,
+ customElement,
+ html,
+ LitElement,
+ property,
+ PropertyValues,
+ query,
+ TemplateResult,
+ unsafeCSS
+} from "lit-element";
+import i18next from "i18next";
+import {translate} from "@openremote/or-translate";
+import {AssetAttribute, AttributeRef, DatapointInterval, ValueDatapoint, ValueType, Asset, MetaItemType, Attribute, AssetEvent} from "@openremote/model";
+import manager, {
+ AssetModelUtil,
+ DefaultColor2,
+ DefaultColor3,
+ DefaultColor4,
+ DefaultColor5,
+ Util
+} from "@openremote/core";
+import "@openremote/or-asset-tree";
+import "@openremote/or-input";
+import "@openremote/or-panel";
+import "@material/mwc-dialog";
+import {Dialog} from "@material/mwc-dialog";
+import "@openremote/or-translate";
+import Chart, {ChartTooltipCallback, ChartDataSets} from "chart.js";
+import {InputType, OrInputChangedEvent} from "@openremote/or-input";
+import {MDCDataTable} from "@material/data-table";
+import {JSONPath} from "jsonpath-plus";
+import moment from "moment";
+import {styleMap} from "lit-html/directives/style-map";
+import { OrAssetTreeSelectionChangedEvent } from "@openremote/or-asset-tree";
+
+
+export class OrChartEvent extends CustomEvent<OrChartEventDetail> {
+
+ public static readonly NAME = "or-chart-event";
+
+ constructor(value?: any, previousValue?: any) {
+ super(OrChartEvent.NAME, {
+ detail: {
+ value: value,
+ previousValue: previousValue
+ },
+ bubbles: true,
+ composed: true
+ });
+ }
+}
+
+export interface OrChartEventDetail {
+ value?: any;
+ previousValue?: any;
+}
+
+declare global {
+ export interface HTMLElementEventMap {
+ [OrChartEvent.NAME]: OrChartEvent;
+ }
+}
+
+export interface ChartConfig {
+ xLabel?: string;
+ yLabel?: string;
+}
+
+
+// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
+const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-table.css");
+
+// language=CSS
+const style = css`
+ :host {
+ --internal-or-chart-dataset-1-color: #9257A9;
+ --internal-or-chart-dataset-2-color: #CC9423;
+ --internal-or-chart-dataset-3-color: #8A273B;
+ --internal-or-chart-dataset-4-color: #1C7C8A;
+
+
+
+ --internal-or-chart-background-color: var(--or-chart-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));
+ --internal-or-chart-text-color: var(--or-chart-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
+ --internal-or-chart-controls-margin: var(--or-chart-controls-margin, 0 0 20px 0);
+ --internal-or-chart-controls-margin-children: var(--or-chart-controls-margin-children, 0 auto 20px auto);
+ --internal-or-chart-graph-fill-color: var(--or-chart-graph-fill-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
+ --internal-or-chart-graph-fill-opacity: var(--or-chart-graph-fill-opacity, 1);
+ --internal-or-chart-graph-line-color: var(--or-chart-graph-line-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
+ --internal-or-chart-graph-point-color: var(--or-chart-graph-point-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
+ --internal-or-chart-graph-point-border-color: var(--or-chart-graph-point-border-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));
+ --internal-or-chart-graph-point-radius: var(--or-chart-graph-point-radius, 4);
+ --internal-or-chart-graph-point-hit-radius: var(--or-chart-graph-point-hit-radius, 20);
+ --internal-or-chart-graph-point-border-width: var(--or-chart-graph-point-border-width, 2);
+ --internal-or-chart-graph-point-hover-color: var(--or-chart-graph-point-hover-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));
+ --internal-or-chart-graph-point-hover-border-color: var(--or-chart-graph-point-hover-border-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
+ --internal-or-chart-graph-point-hover-radius: var(--or-chart-graph-point-hover-radius, 4);
+ --internal-or-chart-graph-point-hover-border-width: var(--or-chart-graph-point-hover-border-width, 2);
+
+ width: 100%;
+ display: block;
+ }
+
+ mwc-dialog {
+ z-index: 9999;
+ --mdc-dialog-min-width: 600px;
+ --mdc-dialog-max-height: calc(100vh - 50%);
+ }
+
+ :host([hidden]) {
+ display: none;
+ }
+
+ #container {
+ display: flex;
+ min-width: 0;
+ flex-direction: row;
+ }
+
+ #msg {
+ height: 100%;
+ width: 100%;
+ justify-content: center;
+ align-items: center;
+ text-align: center;
+ }
+
+ #msg:not([hidden]) {
+ display: flex;
+ }
+
+ #controls {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ margin: var(--internal-or-chart-controls-margin);
+ min-width: 300px;
+ padding-left: 40px;
+ flex-direction: column;
+ margin: 0;
+ }
+
+ #attribute-list {
+ overflow: auto;
+ flex: 1 1 0;
+
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+
+ }
+
+ .attribute-list-item {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ padding: 0;
+ }
+
+ .attribute-list-item-label {
+ display: flex;
+ flex: 1 1 0;
+ flex-direction: column;
+ }
+
+ .attribute-list-item-bullet {
+ width: 14px;
+ height: 14px;
+ border-radius: 7px;
+ margin-right: 10px;
+ }
+
+ #controls > * {
+ margin: 5px 0;
+ }
+
+ .dialog-container {
+ display: flex;
+ flex-direction: row;
+ flex: 1 1 0;
+ }
+
+ .dialog-container > * {
+ flex: 1 1 0;
+ }
+
+ .dialog-container > or-input{
+ background-color: var(--or-app-color2);
+ border-left: 3px solid var(--or-app-color4);
+ }
+
+ #chart-container {
+ flex: 1 1 0;
+ position: relative;
+ }
+`;
+
+
+@customElement("or-chart")
+export class OrChart extends translate(i18next)(LitElement) {
+
+ public static DEFAULT_TIMESTAMP_FORMAT = "L HH:mm:ss";
+
+ static get styles() {
+ return [
+ css`${unsafeCSS(tableStyle)}`,
+ style
+ ];
+ }
+
+ @property({type: Object})
+ private _assets: Asset[] = [];
+
+ @property({type: Object})
+ private _activeAsset?: Asset;
+
+ @property({type: Object})
+ private _attributes: AssetAttribute[] = [];
+
+ @property({type: Object})
+ public attributeRef?: AttributeRef;
+
+ @property({type: String})
+ public interval?: DatapointInterval = DatapointInterval.DAY;
+
+ @property({type: Number})
+ public timestamp?: Date = new Date();
+
+ @property({type: Object})
+ public config?: ChartConfig;
+
+ @property()
+ protected _loading: boolean = false;
+
+ @property()
+ protected _data?: ValueDatapoint<any>[] | any = [];
+
+ @property()
+ protected _tableTemplate?: TemplateResult;
+
+ @query("#chart")
+ protected _chartElem!: HTMLCanvasElement;
+
+ protected _chart?: Chart;
+ protected _style!: CSSStyleDeclaration;
+
+ firstUpdated() {
+
+ if(this.shadowRoot) {
+ const assetTreeElement = this.shadowRoot.getElementById('chart-asset-tree');
+ if(assetTreeElement){
+ assetTreeElement.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, (evt) => this._onTreeSelectionChanged(evt));
+ }
+ }
+ }
+
+
+ protected _onTreeSelectionChanged(event: OrAssetTreeSelectionChangedEvent) {
+ const nodes = event.detail;
+ if(nodes[0] && nodes[0].asset){
+ this._activeAsset = nodes[0].asset;
+ }
+ }
+
+ connectedCallback() {
+ super.connectedCallback();
+ this._style = window.getComputedStyle(this);
+ }
+
+ disconnectedCallback(): void {
+ super.disconnectedCallback();
+ this._cleanup();
+ }
+
+ shouldUpdate(_changedProperties: PropertyValues): boolean {
+
+ let reloadData = _changedProperties.has("interval") || _changedProperties.has("timestamp") || _changedProperties.has("_attributes");
+
+ if (reloadData) {
+ this._data = [];
+ this._loadData();
+ }
+
+ return super.shouldUpdate(_changedProperties);
+ }
+
+ render() {
+
+ const disabled = this._loading;
+ const endDateInputType = this.getInputType();
+ return html`
+ <div id="container">
+
+ <div id="chart-container">
+ <canvas id="chart"></canvas>
+ </div>
+
+ <div id="controls">
+ <or-input .type="${InputType.SELECT}" ?disabled="${disabled}"
+ .label="${i18next.t("period")}"
+ .value="${this.interval}"
+ .options="${this._getIntervalOptions()}"
+ @or-input-changed="${(evt: OrInputChangedEvent) => this.interval = evt.detail.value}"></or-input>
+
+ <div id="ending-controls">
+ <or-input class="button" .type="${InputType.BUTTON}" ?disabled="${disabled}" icon="chevron-left" @click="${() => this._updateTimestamp(this.timestamp!, false)}"></or-input>
+ <or-input id="ending-date"
+ .type="${endDateInputType}"
+ ?disabled="${disabled}"
+ label="${i18next.t("ending")}"
+ .value="${this.timestamp}"
+ @or-input-changed="${(evt: OrInputChangedEvent) => this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
+ <or-input class="button" .type="${InputType.BUTTON}" ?disabled="${disabled}" icon="chevron-right" @click="${() => this._updateTimestamp(this.timestamp!, true)}"></or-input>
+ </div>
+ <div id="attribute-list">
+ ${this._attributes?.map((attr, index) => {
+ return html`
+ <span class="attribute-list-item">
+ <span class="attribute-list-item-bullet" style="background-color:${this._data[index].borderColor};"></span>
+ <div class="attribute-list-item-label">
+ <strong>${this._assets[index].name}</strong>
+ <span>${i18next.t(attr.name ? attr.name : "")}</span>
+ </div>
+ <or-input style="--or-icon-width: 20px;" class="button" .type="${InputType.BUTTON}" icon="close" @click="${() => this._deleteAttribute(index)}"></or-input>
+
+ </div>
+ `
+ })}
+ </div>
+ <or-input class="button" .type="${InputType.BUTTON}" ?disabled="${disabled}" label="Add attribute" icon="plus" @click="${() => this._openDialog()}"></or-input>
+
+ </div>
+ </div>
+
+ <mwc-dialog id="mwc-dialog-attr" heading="Add attribute">
+ <div class="dialog-container">
+ <or-asset-tree id="chart-asset-tree"></or-asset-tree>
+ ${this._activeAsset && this._activeAsset.attributes ? html`
+ <or-input id="chart-attribute-picker"
+ .label="${i18next.t("attribute")}"
+ .type="${InputType.LIST}"
+ .options="${this._getAttributeOptions()}"></or-input>
+ `:``}
+ </div>
+
+
+ <or-input class="button"
+ slot="primaryAction"
+ .type="${InputType.BUTTON}"
+ label="${i18next.t("Add")}"
+ dialogAction="discard"
+ @click="${this.addAttribute}"></or-input>
+
+ <or-input class="button"
+ slot="secondaryAction"
+ .type="${InputType.BUTTON}"
+ label="${i18next.t("Cancel")}"
+ dialogAction="cancel"></or-input>
+ </mwc-dialog>
+ `;
+ }
+
+
+ getInputType() {
+ switch(this.interval) {
+ case DatapointInterval.HOUR:
+ return InputType.TIME
+ break;
+ case DatapointInterval.DAY:
+ return InputType.DATE
+ break;
+ case DatapointInterval.WEEK:
+ return InputType.WEEK
+ break;
+ case DatapointInterval.MONTH:
+ return InputType.MONTH
+ break;
+ case DatapointInterval.YEAR:
+ return InputType.MONTH
+ break;
+ }
+ }
+
+ updated(changedProperties: PropertyValues) {
+ super.updated(changedProperties);
+
+ if (!this._data) {
+ return;
+ }
+ if (!this._chart) {
+ this._chart = new Chart(this._chartElem, {
+ type: "line",
+ data: {
+ datasets: this._data
+ },
+ options: {
+ // maintainAspectRatio: false,
+ // REMOVED AS DOESN'T SIZE CORRECTLY responsive: true,
+ onResize:() => this.dispatchEvent(new OrChartEvent('resize')),
+ legend: {
+ display: false
+ },
+ tooltips: {
+ displayColors: false,
+ callbacks: {
+ label: (tooltipItem, data) => {
+ return tooltipItem.yLabel; // Removes the colon before the label
+ },
+ footer: () => {
+ return " "; // Hack the broken vertical alignment of body with footerFontSize: 0
+ }
+ } as ChartTooltipCallback
+ },
+ scales: {
+ yAxes: [{
+ ticks: {
+ beginAtZero: true
+ },
+ gridLines: {
+ color: "#cccccc"
+ }
+ }],
+ xAxes: [{
+ type: "time",
+ time: {
+ displayFormats: {
+ millisecond: 'HH:mm:ss.SSS',
+ second: 'HH:mm:ss',
+ minute: "HH:mm",
+ hour: "HH:mm",
+ week: "w"
+ }
+ },
+ ticks: {
+ autoSkip: true,
+ maxTicksLimit: 30,
+ fontColor: "#000",
+ fontFamily: "'Open Sans', Helvetica, Arial, Lucida, sans-serif",
+ fontSize: 9,
+ fontStyle: "normal"
+ },
+ gridLines: {
+ color: "#cccccc"
+ }
+ }]
+ }
+ }
+ });
+ } else {
+ if (changedProperties.has("_data")) {
+ this._chart.data.datasets = this._data;
+ this._chart.update();
+ }
+ }
+
+ this.onCompleted().then(() => {
+ this.dispatchEvent(new OrChartEvent('rendered'));
+ });
+
+ }
+
+ _openDialog() {
+ if(this.shadowRoot){
+ const dialog = this.shadowRoot.getElementById('mwc-dialog-attr') as Dialog;
+ if(dialog){
+ dialog.show();
+ }
+ }
+ }
+
+ addAttribute() {
+ if(this.shadowRoot && this.shadowRoot.getElementById('chart-attribute-picker')){
+ const elm = this.shadowRoot.getElementById('chart-attribute-picker') as HTMLInputElement;
+ if(this._activeAsset){
+ const attr = Util.getAssetAttribute(this._activeAsset, elm.value);
+
+ if(attr){
+ this._assets = [...this._assets, this._activeAsset];
+ this._attributes = [...this._attributes, attr];
+ }
+ }
+ }
+ }
+
+
+ async onCompleted() {
+ await this.updateComplete;
+ }
+
+ protected _cleanup() {
+ if (this._chart) {
+ this._chart.destroy();
+ this._chart = undefined;
+ }
+ }
+
+ protected _deleteAttribute (index:number) {
+ this._attributes = [...this._attributes.slice(0, index).concat(this._attributes.slice(index + 1, this._attributes.length))]
+ }
+
+ protected _getAttributeOptions() {
+ if(!this._activeAsset || !this._activeAsset.attributes) {
+ return;
+ }
+
+ let attributes = [...Util.getAssetAttributes(this._activeAsset)];
+ if(attributes && attributes.length > 0) {
+ // TODO change when assets have store_data_points
+ // attributes = attributes.filter((attr:Attribute) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));
+
+ const options = attributes.map((attr:Attribute) => [attr.name, Util.getAttributeLabel(attr, undefined)]);
+ return options
+ }
+ }
+
+ protected _getIntervalOptions(): [string, string][] {
+ return [
+ DatapointInterval.HOUR,
+ DatapointInterval.DAY,
+ DatapointInterval.WEEK,
+ DatapointInterval.MONTH,
+ DatapointInterval.YEAR
+ ].map((interval) => {
+ return [interval, i18next.t(interval.toLowerCase())];
+ });
+ }
+
+ protected async _loadData() {
+ if(!this._attributes) {
+ return;
+ }
+
+ const data = this._attributes.map(async (attribute, index) => {
+ const valuepoints = await this._loadAttributeData(attribute);
+ let bgColor = this._style.getPropertyValue("--internal-or-chart-dataset-"+(index+1)+"-color").trim();
+ const dataset: ChartDataSets = {
+ data: valuepoints,
+ borderColor: bgColor,
+ backgroundColor: "transparent"
+ }
+ return dataset;
+ });
+
+ Promise.all(data).then((completed=> {
+ this._data = completed;
+
+ }))
+ }
+
+ protected async _loadAttributeData(attribute:AssetAttribute) {
+ if (!attribute) {
+ return [];
+ }
+
+ this._loading = true;
+
+ if (!this.interval || !this.timestamp) {
+ this._loading = false;
+ return [];
+ }
+
+ if(attribute.assetId && attribute.name){
+ const response = await manager.rest.api.AssetDatapointResource.getDatapoints(
+ attribute.assetId,
+ attribute.name,
+ {
+ interval: this.interval || DatapointInterval.DAY,
+ timestamp: this.timestamp.getTime()
+ }
+ );
+ this._loading = false;
+
+ if (response.status === 200) {
+ if(response.data) {
+ response.data.map(item => {
+ item.y = Math.random();
+ });
+ }
+ return response.data;
+ }
+ }
+ }
+
+ protected _updateTimestamp(timestamp: Date, forward?: boolean) {
+ if (!this.interval) {
+ return;
+ }
+
+ const newMoment = moment(timestamp);
+
+ if (forward !== undefined) {
+ switch (this.interval) {
+ case DatapointInterval.HOUR:
+ newMoment.add(forward ? 1 : -1, "hour");
+ break;
+ case DatapointInterval.DAY:
+ newMoment.add(forward ? 1 : -1, "day");
+ break;
+ case DatapointInterval.WEEK:
+ newMoment.add(forward ? 1 : -1, "week");
+ break;
+ case DatapointInterval.MONTH:
+ newMoment.add(forward ? 1 : -1, "month");
+ break;
+ case DatapointInterval.YEAR:
+ newMoment.add(forward ? 1 : -1, "year");
+ break;
+ }
+ }
+
+ this.timestamp = newMoment.toDate();
+ }
+}
diff --git a/ui/component/or-chart/tsconfig.json b/ui/component/or-chart/tsconfig.json
new file mode 100644
index 000000000..1814cb1ed
--- /dev/null
+++ b/ui/component/or-chart/tsconfig.json
@@ -0,0 +1,17 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "./dist",
+ "tsBuildInfoFile": "./dist/.tsbuildinfo",
+ "rootDir": "src"
+ },
+ "include": [
+ "./src"
+ ],
+ "references": [
+ { "path": "../core" },
+ { "path": "../or-panel" },
+ { "path": "../or-input" },
+ { "path": "../or-translate" }
+ ]
+}
\ No newline at end of file
diff --git a/ui/component/or-chart/webpack.config.js b/ui/component/or-chart/webpack.config.js
new file mode 100644
index 000000000..aa67f2961
--- /dev/null
+++ b/ui/component/or-chart/webpack.config.js
@@ -0,0 +1,18 @@
+const util = require("../webpack.util");
+
+bundles = {
+ "index": {
+ vendor: {
+ "chart.js": "Chart",
+ "jsonpath-plus": "JSONPath",
+ "moment": "moment"
+ },
+ excludeOr: true
+ },
+ "index.bundle": {
+ excludeOr: true,
+ },
+ "index.orbundle": undefined
+};
+
+module.exports = util.generateExports(__dirname);
\ No newline at end of file
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index b95ea13bf..7630a6785 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -6,7 +6,9 @@ import {MDCComponent} from "@material/base";
import {MDCRipple} from "@material/ripple";
import {MDCCheckbox} from "@material/checkbox";
import {MDCSwitch} from "@material/switch";
-import {MDCSelect, MDCSelectEvent, } from "@material/select";
+import {MDCSelect, MDCSelectEvent } from "@material/select";
+import {MDCList, MDCListActionEvent} from '@material/list';
+
import {MDCFormField, MDCFormFieldInput} from "@material/form-field";
import {MDCIconButtonToggle, MDCIconButtonToggleEventDetail} from "@material/icon-button";
import moment from "moment";
@@ -77,7 +79,8 @@ export enum InputType {
TIME = "time",
URL = "url",
WEEK = "week",
- SELECT = "select"
+ SELECT = "select",
+ LIST = "list"
}
// language=CSS
@@ -367,6 +370,43 @@ export class OrInput extends LitElement {
<label for="elem">${this.label}</label>
</span>
`;
+ case InputType.LIST:
+ const classesList = {
+ "mdc-select--outlined": outlined,
+ "mdc-select--disabled": this.disabled,
+ "mdc-select--required": this.required,
+ "mdc-select--dense": false, // this.dense,
+ "mdc-select--no-label": !this.label,
+ "mdc-select--with-leading-icon": !!this.icon
+ };
+ const helperClassesList = {
+ "mdc-select-helper-text--persistent": this.helperPersistent,
+ "mdc-select-helper-text--validation-msg": showValidationMessage,
+ };
+
+ let optsList: [string, string][] | undefined;
+ if (this.options && this.options.length > 0) {
+ if (Array.isArray(this.options[0])) {
+ optsList = this.options as [string, string][];
+ } else {
+ optsList = (this.options as string[]).map((option) => [option, option]);
+ }
+ }
+
+ this._selectedIndex = -1;
+
+ return html`
+ <div id="component" class="mdc-select ${classMap(classesList)}" @MDCList:action="${(e: MDCListActionEvent) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options![e.detail.index]) ? this.options![e.detail.index][0] : this.options![e.detail.index])}">
+ <ul class="mdc-list">
+ ${optsList ? optsList.map(([optValue, optDisplay], index) => {
+ if (this.value === optValue) {
+ this._selectedIndex = index;
+ }
+ return html`<li class="mdc-list-item" role="option" data-value="${optValue}">${optDisplay}</li>`;
+ }) : ``}
+ </ul>
+ </div>
+ `;
case InputType.SELECT:
const classes = {
"mdc-select--outlined": outlined,
@@ -394,28 +434,28 @@ export class OrInput extends LitElement {
return html`
<div id="component" class="mdc-select ${classMap(classes)}" @MDCSelect:change="${(e: MDCSelectEvent) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options![e.detail.index]) ? this.options![e.detail.index][0] : this.options![e.detail.index])}">
- <div id="menu-anchor" class="mdc-select__anchor select-class">
- <or-icon class="mdc-select__dropdown-icon" icon="menu-down"></or-icon>
- <div id="elem" class="mdc-select__selected-text" role="button" aria-haspopup="listbox" aria-controls="component-helper-text" aria-describedby="component-helper-text" aria-labelledby="component-label component"></div>
- ${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}
- ${!outlined ? html`<div class="mdc-line-ripple"></div>` : ``}
- </div>
-
- <div class="mdc-select__menu mdc-menu mdc-menu-surface select-class" role="listbox">
- <ul class="mdc-list">
- ${opts ? opts.map(([optValue, optDisplay], index) => {
- if (this.value === optValue) {
- this._selectedIndex = index;
- }
- return html`<li class="mdc-list-item" role="option" data-value="${optValue}">${optDisplay}</li>`;
- }) : ``}
- </ul>
- </div>
-
- ${hasHelper ? html`
- <p id="component-helper-text" class="mdc-select-helper-text ${classMap(helperClasses)}" aria-hidden="true">
- ${showValidationMessage ? this.validationMessage : this.helperText}
- </p>` : ``}
+ <div id="menu-anchor" class="mdc-select__anchor select-class">
+ <or-icon class="mdc-select__dropdown-icon" icon="menu-down"></or-icon>
+ <div id="elem" class="mdc-select__selected-text" role="button" aria-haspopup="listbox" aria-controls="component-helper-text" aria-describedby="component-helper-text" aria-labelledby="component-label component"></div>
+ ${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}
+ ${!outlined ? html`<div class="mdc-line-ripple"></div>` : ``}
+ </div>
+
+ <div class="mdc-select__menu mdc-menu mdc-menu-surface select-class" role="listbox">
+ <ul class="mdc-list">
+ ${opts ? opts.map(([optValue, optDisplay], index) => {
+ if (this.value === optValue) {
+ this._selectedIndex = index;
+ }
+ return html`<li class="mdc-list-item" role="option" data-value="${optValue}">${optDisplay}</li>`;
+ }) : ``}
+ </ul>
+ </div>
+
+ ${hasHelper ? html`
+ <p id="component-helper-text" class="mdc-select-helper-text ${classMap(helperClasses)}" aria-hidden="true">
+ ${showValidationMessage ? this.validationMessage : this.helperText}
+ </p>` : ``}
</div>
`;
case InputType.BUTTON_TOGGLE:
@@ -495,8 +535,27 @@ export class OrInput extends LitElement {
if (typeof(val) !== "string") {
switch (this.type) {
+ case InputType.TIME:
+ if (val instanceof Date) {
+ val = moment(val).format("HH:mm");
+ }
+ break;
+ case InputType.DATE:
+ if (val instanceof Date) {
+ val = moment(val).format("YYYY-MM-DD");
+ }
+ break;
+ case InputType.WEEK:
+ if (val instanceof Date) {
+ val = moment(val).format("YYYY-")+"W"+moment(val).format("WW");
+ }
+ break;
+ case InputType.MONTH:
+ if (val instanceof Date) {
+ val = moment(val).format("YYYY-MM");
+ }
+ break;
case InputType.DATETIME:
- // Date time conversion for UNIX timestamps in millis
if (val instanceof Date) {
val = moment(val).format("YYYY-MM-DDTHH:mm");
} else if (typeof(val) === "number") {
@@ -592,6 +651,11 @@ export class OrInput extends LitElement {
if (component && this.type) {
switch (this.type) {
+ case InputType.LIST:
+ const mdcList = new MDCList(component);
+ this._mdcComponent = mdcList;
+ mdcList.selectedIndex = this._selectedIndex;
+ break;
case InputType.SELECT:
const mdcSelect = new MDCSelect(component);
this._mdcComponent = mdcSelect;
@@ -666,7 +730,6 @@ export class OrInput extends LitElement {
}
protected onValueChange(elem: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined, newValue: any | undefined) {
-
let valid = true;
if (elem && this._mdcComponent) {