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
Two axis support on charts (#1174)
Martin Peeters7006ff260c2f
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.jsonindex 3505c62ab..f0b051395 100644--- a/manager/src/web/shared/locales/en/or.json+++ b/manager/src/web/shared/locales/en/or.json@@ -34,6 +34,8 @@"FR": "FR","SA": "SA","SU": "SU",+ "left": "left",+ "right": "right","sceneStartTime": "Scene start time","sceneConfiguration": "Scene Configuration","temperature": "Temperature",@@ -605,7 +607,9 @@"widgets": "Widgets","widget-kpi": "KPI","widget-linechart": "Line Chart",- "chartConfig": "Chart Configuration",+ "axisConfig": "Axis Configuration",+ "leftAxis": "Left axis",+ "rightAxis": "Right axis","markerCoordinates": "Marker Coordinates","imageSettings": "Image Settings","dataManagement": "Data Options",@@ -646,6 +650,7 @@"deleteWidgetWarning": "This will remove the widget from your board, and be permanently deleted after saving.","widgetTooSmall": "Widget is too small.","allowTimerangeSelect": "Allow time range selection",+ "toggleAxis": "Toggle axis","showLegend": "Show legend","showGeoJson": "Show GeoJSON overlay","showValueAs": "Show value as",diff --git a/manager/src/web/shared/locales/nl/or.json b/manager/src/web/shared/locales/nl/or.jsonindex 7ae73de78..316fed375 100644--- a/manager/src/web/shared/locales/nl/or.json+++ b/manager/src/web/shared/locales/nl/or.json@@ -34,6 +34,8 @@"FR": "VR","SA": "ZA","SU": "ZO",+ "left": "links",+ "right": "rechts","sceneStartTime": "Scene start tijd","sceneConfiguration": "Scene configuratie","temperature": "Temperatuur",@@ -605,7 +607,9 @@"widgets": "Widgets","widget-kpi": "KPI","widget-linechart": "Lijngrafiek",- "chartConfig": "Grafiek configuratie",+ "axisConfig": "Assen configuratie",+ "leftAxis": "Linker as",+ "rightAxis": "Rechter as","markerCoordinates": "Marker coordinaten","imageSettings": "Afbeeldingsinstellingen","dataManagement": "Weergave van data",@@ -646,6 +650,7 @@"deleteWidgetWarning": "De widget zal worden weggehaald van het bord, en zal permanent worden verwijderd als u opslaat.","widgetTooSmall": "Widget is te klein.","allowTimerangeSelect": "Sta tijdselectie toe",+ "toggleAxis": "As wisselen","showLegend": "Toon legenda","showGeoJson": "Toon GeoJSON overlay","showValueAs": "Laat waarde zien als",diff --git a/manager/src/web/shared/locales/ro/or.json b/manager/src/web/shared/locales/ro/or.jsonindex 4c8cbcca8..154e644ca 100644--- a/manager/src/web/shared/locales/ro/or.json+++ b/manager/src/web/shared/locales/ro/or.json@@ -593,7 +593,7 @@"widgets": "Widget-uri","widget-kpi": "KPI","widget-linechart": "Diagramă cu linii",- "chartConfig": "Configurare diagramă",+ "axisConfig": "Configurația axelor","presets.wrap_to_single_column": "Înfașoară pe o singură coloană","presets.keep_layout": "Pastrează aspectul","presets.block_device": "Blochează acest dispozitiv",diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex a35e2656f..ce787adda 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -52,6 +52,7 @@ import {cache} from "lit/directives/cache.js";import {throttle} from "lodash";import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";+import { when } from "lit/directives/when.js";Chart.register(LineController, ScatterController, LineElement, PointElement, LinearScale, TimeScale, Title, Filler, Legend, Tooltip, ChartAnnotation);@@ -370,6 +371,9 @@ export class OrChart extends translate(i18next)(LitElement) {@property({type: Object})public assetAttributes: [number, Attribute<any>][] = [];+ @property({type: Array}) // List of AttributeRef that are shown on the right axis instead.+ public rightAxisAttributes: AttributeRef[] = [];+@property()public dataProvider?: (startOfPeriod: number, endOfPeriod: number, timeUnits: TimeUnit, stepSize: number) => Promise<ChartDataset<"line", ScatterDataPoint[]>[]>@@ -460,7 +464,7 @@ export class OrChart extends translate(i18next)(LitElement) {}}- const reloadData = changedProperties.has("datapointQuery") || changedProperties.has("timePresetKey") ||+ const reloadData = changedProperties.has("datapointQuery") || changedProperties.has("timePresetKey") || changedProperties.has("rightAxisAttributes") ||changedProperties.has("assetAttributes") || changedProperties.has("realm") || changedProperties.has("dataProvider");if (reloadData) {@@ -528,6 +532,16 @@ export class OrChart extends translate(i18next)(LitElement) {color: "#cccccc"}},+ y1: {+ display: this.rightAxisAttributes.length > 0,+ position: 'right',+ ticks: {+ beginAtZero: true+ },+ grid: {+ drawOnChartArea: false+ }+ },x: {type: "time",min: this._startOfPeriod,@@ -659,15 +673,20 @@ export class OrChart extends translate(i18next)(LitElement) {</div>` : undefined}${this.assetAttributes && this.assetAttributes.map(([assetIndex, attr], index) => {+ const asset: Asset | undefined = this.assets[assetIndex];const colourIndex = index % this.colors.length;- const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.assets[assetIndex]!.type, attr.name, attr);- const label = Util.getAttributeLabel(attr, descriptors[0], this.assets[assetIndex]!.type, true);+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset!.type, attr.name, attr);+ const label = Util.getAttributeLabel(attr, descriptors[0], asset!.type, true);+ const axisNote = (this.rightAxisAttributes.find(ar => asset!.id === ar.id && attr.name === ar.name)) ? i18next.t('right') : undefined;const bgColor = this.colors[colourIndex] || "";return html`<div class="attribute-list-item ${this.denseLegend ? 'attribute-list-item-dense' : undefined}" @mouseover="${()=> this.addDatasetHighlight(this.assets[assetIndex]!.id, attr.name)}" @mouseout="${()=> this.removeDatasetHighlight(bgColor)}"><span style="margin-right: 10px; --or-icon-width: 20px;">${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.assets[assetIndex]!.type!), undefined, undefined, bgColor.split('#')[1])}</span><div class="attribute-list-item-label ${this.denseLegend ? 'attribute-list-item-label-dense' : undefined}">- <span style="font-size:12px; ${this.denseLegend ? 'margin-right: 8px' : undefined}">${this.assets[assetIndex].name}</span>+ <div style="display: flex; justify-content: space-between;">+ <span style="font-size:12px; ${this.denseLegend ? 'margin-right: 8px' : undefined}">${this.assets[assetIndex].name}</span>+ ${when(axisNote, () => html`<span style="font-size:12px; color:grey">(${axisNote})</span>`)}+ </div><span style="font-size:12px; color:grey;">${label}</span></div></div>@@ -1027,6 +1046,7 @@ export class OrChart extends translate(i18next)(LitElement) {promises = this.assetAttributes.map(async ([assetIndex, attribute], index) => {const asset = this.assets[assetIndex];+ const shownOnRightAxis = !!this.rightAxisAttributes.find(ar => ar.id === asset.id && ar.name === attribute.name);const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attribute.name, attribute);const label = Util.getAttributeLabel(attribute, descriptors[0], asset.type, false);const unit = Util.resolveUnits(Util.getAttributeUnits(attribute, descriptors[0], asset.type));@@ -1035,6 +1055,7 @@ export class OrChart extends translate(i18next)(LitElement) {(dataset as any).assetId = asset.id;(dataset as any).attrName = attribute.name;(dataset as any).unit = unit;+ (dataset as any).yAxisID = shownOnRightAxis ? 'y1' : 'y';data.push(dataset);dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, this.colors[colourIndex], predictedFromTimestamp, this._endOfPeriod!, true, asset.name + " " + label + " " + i18next.t("predicted"));diff --git a/ui/component/or-dashboard-builder/src/controls/dashboard-refresh-controls.ts b/ui/component/or-dashboard-builder/src/controls/dashboard-refresh-controls.tsindex 923efe932..e60492122 100644--- a/ui/component/or-dashboard-builder/src/controls/dashboard-refresh-controls.ts+++ b/ui/component/or-dashboard-builder/src/controls/dashboard-refresh-controls.ts@@ -62,10 +62,18 @@ export class DashboardRefreshControls extends LitElement {return html`<div style="height: 100%; display: flex; align-items: center;">${when(this.readonly, () => html`- <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}" disabled="true"></or-mwc-input>+ ${when(this.interval === DashboardRefreshInterval.OFF, () => html`+ <or-mwc-input .type="${InputType.BUTTON}" icon="pause" disabled="true" style="height: 36px; margin-top: -12px;"></or-mwc-input>+ `, () => html`+ <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}" disabled="true"></or-mwc-input>+ `)}`, () => html`${getContentWithMenuTemplate(- html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}"></or-mwc-input>`,+ this.interval === DashboardRefreshInterval.OFF ? html`+ <or-mwc-input .type="${InputType.BUTTON}" icon="pause" style="height: 36px; margin-top: -12px;"></or-mwc-input>+ ` : html`+ <or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t(value)}"></or-mwc-input>+ `,intervalOptions.map(o => ({value: o} as ListItem)),value,(newVal) => this.onIntervalSelect(intervalOptions, newVal as string),diff --git a/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts b/ui/component/or-dashboard-builder/src/panels/attributes-panel.tsindex a8ab8a23e..94dcd9c97 100644--- a/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts+++ b/ui/component/or-dashboard-builder/src/panels/attributes-panel.ts@@ -13,6 +13,28 @@ import {OrAttributePicker, OrAttributePickerPickedEvent} from "@openremote/or-atimport {showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";+export interface AttributeAction {+ icon: string,+ tooltip: string,+ disabled: boolean+}++export class AttributeActionEvent extends CustomEvent<{ attributeRef: AttributeRef, action: AttributeAction }> {++ public static readonly NAME = "attribute-action"++ constructor(attributeRef: AttributeRef, action: AttributeAction) {+ super(AttributeActionEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: {+ attributeRef: attributeRef,+ action: action+ }+ });+ }+}+export class AttributesSelectEvent extends CustomEvent<AttributeRef[]> {public static readonly NAME = "attribute-select";@@ -36,20 +58,37 @@ const styling = css`}.attribute-list-item {+ position: relative;cursor: pointer;display: flex;flex-direction: row;- align-items: center;+ align-items: stretch;+ gap: 10px;padding: 0;min-height: 50px;}++ .attribute-list-item-icon {+ display: flex;+ align-items: center;+ --or-icon-width: 20px;+ }.attribute-list-item-label {display: flex;+ justify-content: center;flex: 1 1 0;line-height: 16px;flex-direction: column;}++ .attribute-list-item-actions {+ flex: 1;+ justify-content: end;+ align-items: center;+ display: flex;+ gap: 8px;+ }.attribute-list-item-bullet {width: 14px;@@ -66,7 +105,7 @@ const styling = css`display: block;}- .button-clear {+ .button-action {background: none;visibility: hidden;color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});@@ -77,11 +116,16 @@ const styling = css`cursor: pointer;}- .attribute-list-item:hover .button-clear {+ .attribute-list-item:hover .attribute-list-item-actions {+ background: white;+ z-index: 1;+ }++ .attribute-list-item:hover .button-action {visibility: visible;}- .button-clear:hover {+ .button-action:hover {--or-icon-fill: var(--or-app-color4);}`@@ -101,6 +145,12 @@ export class AttributesPanel extends LitElement {@property()protected attributeFilter?: (attribute: Attribute<any>) => boolean;+ @property()+ protected attributeLabelCallback?: (asset: Asset, attribute: Attribute<any>, attributeLabel: string) => TemplateResult;++ @property()+ protected attributeActionCallback?: (attribute: AttributeRef) => AttributeAction[]+@state()protected loadedAssets: Asset[] = [];@@ -161,6 +211,10 @@ export class AttributesPanel extends LitElement {return assets;}+ protected onAttributeActionClick(attributeRef: AttributeRef, action: AttributeAction) {+ this.dispatchEvent(new AttributeActionEvent(attributeRef, action));+ }+protected openAttributeSelector(attributeRefs: AttributeRef[], multi: boolean, onlyDataAttrs = true, attributeFilter?: (attribute: Attribute<any>) => boolean) {let dialog: OrAttributePicker;if (attributeRefs != null) {@@ -179,7 +233,7 @@ export class AttributesPanel extends LitElement {${when(this.attributeRefs.length > 0, () => html`<div id="attribute-list">- ${guard([this.attributeRefs, this.loadedAssets], () => html`+ ${guard([this.attributeRefs, this.loadedAssets, this.attributeActionCallback, this.attributeLabelCallback], () => html`${map(this.attributeRefs, (attributeRef: AttributeRef) => {const asset = this.getLoadedAsset(attributeRef);if (asset) {@@ -188,15 +242,33 @@ export class AttributesPanel extends LitElement {const label = Util.getAttributeLabel(attribute, descriptors[0], asset.type, true);return html`<div class="attribute-list-item">- <span style="margin-right: 10px; --or-icon-width: 20px;">${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(asset.type))}</span>+ <div class="attribute-list-item-icon">+ <span>${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(asset.type))}</span>+ </div><div class="attribute-list-item-label">- <span>${asset.name}</span>- <span style="font-size:14px; color:grey;">${label}</span>+ ${when(!!this.attributeLabelCallback,+ () => this.attributeLabelCallback!(asset, attribute, label),+ () => html`+ <span>${asset.name}</span>+ <span style="font-size:14px; color:grey;">${label}</span>+ `+ )}+ </div>+ <div class="attribute-list-item-actions">++ <!-- Custom actions defined by callback -->+ ${when(!!this.attributeActionCallback, () => {+ return this.attributeActionCallback!(attributeRef).map((action) => html`+ <button class="button-action" .disabled="${action.disabled}" title="${action.tooltip}" @click="${() => this.onAttributeActionClick(attributeRef, action)}">+ <or-icon icon="${action.icon}"></or-icon>+ </button>+ `);+ })}+ <!-- Remove attribute button -->+ <button class="button-action" title="${i18next.t('delete')}" @click="${() => this.removeWidgetAttribute(attributeRef)}">+ <or-icon icon="close-circle"></or-icon>+ </button></div>- <button class="button-clear"- @click="${() => this.removeWidgetAttribute(attributeRef)}">- <or-icon icon="close-circle"></or-icon>- </button></div>`;} else {diff --git a/ui/component/or-dashboard-builder/src/settings/chart-settings.ts b/ui/component/or-dashboard-builder/src/settings/chart-settings.tsindex 618acb24e..2e624b821 100644--- a/ui/component/or-dashboard-builder/src/settings/chart-settings.ts+++ b/ui/component/or-dashboard-builder/src/settings/chart-settings.ts@@ -4,11 +4,12 @@ import {WidgetSettings} from "../util/widget-settings";import "../panels/attributes-panel";import "../util/settings-panel";import {i18next} from "@openremote/or-translate";-import {AttributesSelectEvent} from "../panels/attributes-panel";-import {AssetDatapointIntervalQuery, AssetDatapointIntervalQueryFormula, Attribute, AttributeRef} from "@openremote/model";+import {AttributeAction, AttributeActionEvent, AttributesSelectEvent} from "../panels/attributes-panel";+import {Asset, AssetDatapointIntervalQuery, AssetDatapointIntervalQueryFormula, Attribute, AttributeRef} from "@openremote/model";import {ChartWidgetConfig} from "../widgets/chart-widget";-import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";import {TimePresetCallback} from "@openremote/or-chart";+import {when} from "lit/directives/when.js";const styling = css`.switch-container {@@ -45,12 +46,32 @@ export class ChartSettings extends WidgetSettings {};const min = this.widgetConfig.chartOptions.options?.scales?.y?.min;const max = this.widgetConfig.chartOptions.options?.scales?.y?.max;+ const isMultiAxis = this.widgetConfig.rightAxisAttributes.length > 0;const samplingValue = Array.from(this.samplingOptions.entries()).find((entry => entry[1] === this.widgetConfig.datapointQuery.type))![0]+ const attributeLabelCallback = (asset: Asset, attribute: Attribute<any>, attributeLabel: string) => {+ const isOnRightAxis = isMultiAxis && this.widgetConfig.rightAxisAttributes.find(ar => ar.id === asset.id && ar.name === attribute.name) !== undefined;+ return html`+ <span>${asset.name}</span>+ <span style="font-size:14px; color:grey;">${attributeLabel}</span>+ ${when(isOnRightAxis, () => html`+ <span style="position: absolute; right: 0; margin-bottom: 16px; font-size:14px; color:grey;">(${i18next.t('right')})</span>+ `)}+ `+ }+ const attributeActionCallback = (attributeRef: AttributeRef): AttributeAction[] => {+ return [{+ icon: this.widgetConfig.rightAxisAttributes.includes(attributeRef) ? "arrow-right-bold" : "arrow-left-bold",+ tooltip: i18next.t('dashboard.toggleAxis'),+ disabled: false+ }]+ }return html`<div><!-- Attribute selection --><settings-panel displayName="${i18next.t('attributes')}" expanded="${true}">- <attributes-panel .attributeRefs="${this.widgetConfig.attributeRefs}" onlyDataAttrs="${true}" .attributeFilter="${attributeFilter}" multi="${true}" style="padding-bottom: 12px;"+ <attributes-panel .attributeRefs="${this.widgetConfig.attributeRefs}" multi="${true}" onlyDataAttrs="${true}" .attributeFilter="${attributeFilter}" style="padding-bottom: 12px;"+ .attributeLabelCallback="${attributeLabelCallback}" .attributeActionCallback="${attributeActionCallback}"+ @attribute-action="${(ev: AttributeActionEvent) => this.onAttributeAction(ev)}"@attribute-select="${(ev: AttributesSelectEvent) => this.onAttributesSelect(ev)}"></attributes-panel></settings-panel>@@ -83,33 +104,81 @@ export class ChartSettings extends WidgetSettings {</div></settings-panel>- <!-- Chart configuration -->- <settings-panel displayName="${i18next.t('dashboard.chartConfig')}" expanded="${true}">- <div style="padding-bottom: 12px;">- <div style="display: flex;">- ${max !== undefined ? html`- <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" .value="${max}" style="width: 100%;"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('max', ev)}"+ <!-- Axis configuration -->+ <settings-panel displayName="${i18next.t('dashboard.axisConfig')}" expanded="${true}">+ <div style="padding-bottom: 12px; display: flex; flex-direction: column; gap: 16px;">++ <!-- Left axis configuration -->+ <div>+ ${when(isMultiAxis, () => html`+ <div style="margin-bottom: 8px;">+ <span>${i18next.t('dashboard.leftAxis')}</span>+ </div>+ `)}+ <div style="display: flex;">+ ${max !== undefined ? html`+ <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" .value="${max}" style="width: 100%;"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('left', 'max', ev)}"+ ></or-mwc-input>+ ` : html`+ <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" disabled="true" value="auto" style="width: 100%;"></or-mwc-input>+ `}+ <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${max !== undefined}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('left', 'max', ev)}"></or-mwc-input>- ` : html`- <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" disabled="true" value="auto" style="width: 100%;"></or-mwc-input>- `}- <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${max !== undefined}"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('max', ev)}"- ></or-mwc-input>- </div>- <div style="display: flex; margin-top: 12px;">- ${min !== undefined ? html`- <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" .value="${min}" style="width: 100%;"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('min', ev)}"+ </div>+ <div style="display: flex; margin-top: 12px;">+ ${min !== undefined ? html`+ <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" .value="${min}" style="width: 100%;"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('left', 'min', ev)}"+ ></or-mwc-input>+ ` : html`+ <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" disabled="true" value="auto" style="width: 100%;"></or-mwc-input>+ `}+ <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${min !== undefined}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('left', 'min', ev)}"></or-mwc-input>- ` : html`- <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" disabled="true" value="auto" style="width: 100%;"></or-mwc-input>- `}- <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${min !== undefined}"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('min', ev)}"- ></or-mwc-input>+ </div></div>++ <!-- Right axis configuration -->+ ${when(isMultiAxis, () => {+ const rightMin = this.widgetConfig.chartOptions.options?.scales?.y1?.min;+ const rightMax = this.widgetConfig.chartOptions.options?.scales?.y1?.max;+ return html`+ <div>+ <div style="margin-bottom: 8px;">+ <span>${i18next.t('dashboard.rightAxis')}</span>+ </div>+ <div style="display: flex;">+ ${rightMax !== undefined ? html`+ <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" .value="${rightMax}" style="width: 100%;"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('right', 'max', ev)}"+ ></or-mwc-input>+ ` : html`+ <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('max')}" disabled="true" value="auto"+ style="width: 100%;"></or-mwc-input>+ `}+ <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${rightMax !== undefined}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('right', 'max', ev)}"+ ></or-mwc-input>+ </div>+ <div style="display: flex; margin-top: 12px;">+ ${rightMin !== undefined ? html`+ <or-mwc-input .type="${InputType.NUMBER}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" .value="${rightMin}" style="width: 100%;"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueChange('right', 'min', ev)}"+ ></or-mwc-input>+ ` : html`+ <or-mwc-input .type="${InputType.TEXT}" label="${i18next.t('yAxis') + ' ' + i18next.t('min')}" disabled="true" value="auto"+ style="width: 100%;"></or-mwc-input>+ `}+ <or-mwc-input .type="${InputType.SWITCH}" style="margin: 0 -10px 0 0;" .value="${rightMin !== undefined}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onMinMaxValueToggle('right', 'min', ev)}"+ ></or-mwc-input>+ </div>+ </div>+ `+ })}</div></settings-panel>@@ -138,9 +207,9 @@ export class ChartSettings extends WidgetSettings {return html`<or-mwc-input .type="${InputType.SELECT}" style="width: 100%;" .options="${formulaOptions}".value="${intervalQuery.formula}" label="${i18next.t('algorithmMethod')}" @or-mwc-input-changed="${(event: OrInputChangedEvent) => {- intervalQuery.formula = event.detail.value;- this.notifyConfigUpdate();- }}"+ intervalQuery.formula = event.detail.value;+ this.notifyConfigUpdate();+ }}"></or-mwc-input>`;}@@ -149,12 +218,47 @@ export class ChartSettings extends WidgetSettings {}}+ // When a user clicks on ANY action in the attribute list, we want to switch between LEFT and RIGHT axis.+ // Since that is the only action, there is no need to check the ev.action variable.+ protected onAttributeAction(ev: AttributeActionEvent) {+ if(this.widgetConfig.attributeRefs.indexOf(ev.detail.attributeRef) >= 0) {+ if(this.widgetConfig.rightAxisAttributes.includes(ev.detail.attributeRef)) {+ this.removeFromRightAxis(ev.detail.attributeRef);+ } else {+ this.addToRightAxis(ev.detail.attributeRef);+ }+ this.notifyConfigUpdate();+ }+ }+ // When the list of attributeRefs is changed by the asset selector,+ // we should remove the "right axis" references for the attributes that got removed.+ // Also update the WidgetConfig attributeRefs field as usualprotected onAttributesSelect(ev: AttributesSelectEvent) {+ const removedAttributeRefs = this.widgetConfig.attributeRefs.filter(ar => !ev.detail.includes(ar));+ removedAttributeRefs.forEach(raf => this.removeFromRightAxis(raf));this.widgetConfig.attributeRefs = ev.detail as AttributeRef[];this.notifyConfigUpdate();}+ protected addToRightAxis(attributeRef: AttributeRef, notify = false) {+ if(!this.widgetConfig.rightAxisAttributes.includes(attributeRef)) {+ this.widgetConfig.rightAxisAttributes.push(attributeRef);+ if(notify) {+ this.notifyConfigUpdate();+ }+ }+ }++ protected removeFromRightAxis(attributeRef: AttributeRef, notify = false) {+ if(this.widgetConfig.rightAxisAttributes.includes(attributeRef)) {+ this.widgetConfig.rightAxisAttributes.splice(this.widgetConfig.rightAxisAttributes.indexOf(attributeRef), 1);+ if(notify) {+ this.notifyConfigUpdate();+ }+ }+ }+protected onTimePresetSelect(ev: OrInputChangedEvent) {this.widgetConfig.defaultTimePresetKey = ev.detail.value.toString();this.notifyConfigUpdate();@@ -170,24 +274,29 @@ export class ChartSettings extends WidgetSettings {this.notifyConfigUpdate();}- protected onMinMaxValueChange(type: 'min' | 'max', ev: OrInputChangedEvent) {- switch (type) {- case "max":- this.widgetConfig.chartOptions.options.scales.y.max = ev.detail.value; break;- case "min":- this.widgetConfig.chartOptions.options.scales.y.min = ev.detail.value; break;+ protected setAxisMinMaxValue(axis: 'left' | 'right', type: 'min' | 'max', value?: number) {+ if(axis === 'left') {+ if(type === 'min') {+ this.widgetConfig.chartOptions.options.scales.y.min = value;+ } else {+ this.widgetConfig.chartOptions.options.scales.y.max = value;+ }+ } else {+ if(type === 'min') {+ this.widgetConfig.chartOptions.options.scales.y1.min = value;+ } else {+ this.widgetConfig.chartOptions.options.scales.y1.max = value;+ }}this.notifyConfigUpdate();}- protected onMinMaxValueToggle(type: 'min' | 'max', ev: OrInputChangedEvent) {- switch (type) {- case "max":- this.widgetConfig.chartOptions.options.scales.y.max = (ev.detail.value ? 100 : undefined); break;- case "min":- this.widgetConfig.chartOptions.options.scales.y.min = (ev.detail.value ? 0 : undefined); break;- }- this.notifyConfigUpdate();+ protected onMinMaxValueChange(axis: 'left' | 'right', type: 'min' | 'max', ev: OrInputChangedEvent) {+ this.setAxisMinMaxValue(axis, type, ev.detail.value);+ }++ protected onMinMaxValueToggle(axis: 'left' | 'right', type: 'min' | 'max', ev: OrInputChangedEvent) {+ this.setAxisMinMaxValue(axis, type, (ev.detail.value ? (type === 'min' ? 0 : 100) : undefined));}protected onSamplingQueryChange(ev: OrInputChangedEvent) {diff --git a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts b/ui/component/or-dashboard-builder/src/widgets/chart-widget.tsindex afe23dc84..595f289f7 100644--- a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts+++ b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts@@ -13,6 +13,7 @@ import {WidgetSettings} from "../util/widget-settings";export interface ChartWidgetConfig extends WidgetConfig {attributeRefs: AttributeRef[];+ rightAxisAttributes: AttributeRef[];datapointQuery: AssetDatapointQueryUnion;chartOptions?: any; // ChartConfiguration<"line", ScatterDataPoint[]>showTimestampControls: boolean;@@ -52,6 +53,7 @@ function getDefaultWidgetConfig(): ChartWidgetConfig {const dates = dateFunc(new Date());return {attributeRefs: [],+ rightAxisAttributes: [],datapointQuery: {type: "lttb",fromTimestamp: dates[0].getTime(),@@ -64,6 +66,10 @@ function getDefaultWidgetConfig(): ChartWidgetConfig {y: {min: undefined,max: undefined+ },+ y1: {+ min: undefined,+ max: undefined}}},@@ -170,7 +176,7 @@ export class ChartWidget extends OrAssetWidget {return html`${when(this.loadedAssets && this.assetAttributes && this.loadedAssets.length > 0 && this.assetAttributes.length > 0, () => {return html`- <or-chart .assets="${this.loadedAssets}" .assetAttributes="${this.assetAttributes}"+ <or-chart .assets="${this.loadedAssets}" .assetAttributes="${this.assetAttributes}" .rightAxisAttributes="${this.widgetConfig.rightAxisAttributes}".showLegend="${(this.widgetConfig?.showLegend != null) ? this.widgetConfig?.showLegend : true}".attributeControls="${false}" .timestampControls="${!this.widgetConfig?.showTimestampControls}".timePresetOptions="${getDefaultTimePresetOptions()}" .timePresetKey="${this.widgetConfig?.defaultTimePresetKey}"