From 4b68c0bd01b44b40dba94a72139593d496256736 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Fri, 20 Dec 2024 13:08:25 +0100 Subject: [PATCH] Rename BranchLabel to BranchState Signed-off-by: Geoffroy Jamgotchian --- demo/src/diagram-viewers/add-diagrams.ts | 12 ++--- .../network-area-diagram-viewer.ts | 50 +++++++++---------- src/index.ts | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/demo/src/diagram-viewers/add-diagrams.ts b/demo/src/diagram-viewers/add-diagrams.ts index 3e68151..8c322f2 100644 --- a/demo/src/diagram-viewers/add-diagrams.ts +++ b/demo/src/diagram-viewers/add-diagrams.ts @@ -34,7 +34,7 @@ import { OnMoveTextNodeCallbackType, OnSelectNodeCallbackType, OnToggleNadHoverCallbackType, - BranchLabel, + BranchState, } from '../../../src'; export const addNadToDemo = () => { @@ -75,7 +75,7 @@ export const addNadToDemo = () => { branchLabelsSlider.style.justifyContent = 'space-between'; branchLabelsSlider.style.padding = '0 5px'; branchLabelsSlider.addEventListener('input', () => { - const branchLabels = + const branchStates = '[{"branchId": "NGEN_NHV1", "value1": ' + (627 - +branchLabelsSlider.value * 20) + ', "value2": ' + @@ -97,8 +97,8 @@ export const addNadToDemo = () => { ', "value2": ' + (621 - +branchLabelsSlider.value * 20) + '}]'; - console.log(branchLabels); - nadViewer.setJsonBranchLabels(branchLabels); + console.log(branchStates); + nadViewer.setJsonBranchStates(branchStates); }); document.getElementById('svg-container-nad')?.appendChild(branchLabelsSlider); @@ -165,8 +165,8 @@ export const addNadToDemo = () => { const updateFlowsButton = document.createElement('button'); updateFlowsButton.innerHTML = 'Update Branch Labels'; updateFlowsButton.addEventListener('click', () => { - const branchLabelsArray: BranchLabel[] = JSON.parse(updateFlowsTextArea.value); - nadViewer.setBranchLabels(branchLabelsArray); + const branchStatesArray: BranchState[] = JSON.parse(updateFlowsTextArea.value); + nadViewer.setBranchStates(branchStatesArray); }); const updateFlowsDiv = document.createElement('div'); updateFlowsDiv.appendChild(updateFlowsTextArea); diff --git a/src/components/network-area-diagram-viewer/network-area-diagram-viewer.ts b/src/components/network-area-diagram-viewer/network-area-diagram-viewer.ts index 919bb81..5c6e6df 100644 --- a/src/components/network-area-diagram-viewer/network-area-diagram-viewer.ts +++ b/src/components/network-area-diagram-viewer/network-area-diagram-viewer.ts @@ -16,7 +16,7 @@ import { debounce } from '@mui/material'; type DIMENSIONS = { width: number; height: number; viewbox: VIEWBOX }; type VIEWBOX = { x: number; y: number; width: number; height: number }; -export type BranchLabel = { branchId: string; value1: number | string; value2: number | string; connected1: boolean; connected2: boolean }; +export type BranchState = { branchId: string; value1: number | string; value2: number | string; connected1: boolean; connected2: boolean }; export type OnMoveNodeCallbackType = ( equipmentId: string, @@ -1392,46 +1392,46 @@ export class NetworkAreaDiagramViewer { }); } - public setJsonBranchLabels(branchLabels: string) { - const branchLabelsArray: BranchLabel[] = JSON.parse(branchLabels); - this.setBranchLabels(branchLabelsArray); + public setJsonBranchStates(branchStates: string) { + const branchStatesArray: BranchState[] = JSON.parse(branchStates); + this.setBranchStates(branchStatesArray); } - public setBranchLabels(branchLabels: BranchLabel[]) { - branchLabels.forEach((branchLabel) => { - if (!this.edgesMap.has(branchLabel.branchId)) { + public setBranchStates(branchStates: BranchState[]) { + branchStates.forEach((branchState) => { + if (!this.edgesMap.has(branchState.branchId)) { const edge: EdgeMetadata | undefined = this.diagramMetadata?.edges.find( - (edge) => edge.equipmentId == branchLabel.branchId + (edge) => edge.equipmentId == branchState.branchId ); if (edge === undefined) { - console.warn('Skipping updating branch ' + branchLabel.branchId + ' labels: branch not found'); + console.warn('Skipping updating branch ' + branchState.branchId + ' labels: branch not found'); return; } - this.edgesMap.set(branchLabel.branchId, edge); + this.edgesMap.set(branchState.branchId, edge); } this.setBranchSideLabel( - branchLabel.branchId, + branchState.branchId, '1', - this.edgesMap.get(branchLabel.branchId)?.svgId ?? '-1', - branchLabel.value1 + this.edgesMap.get(branchState.branchId)?.svgId ?? '-1', + branchState.value1 ); this.setBranchSideLabel( - branchLabel.branchId, + branchState.branchId, '2', - this.edgesMap.get(branchLabel.branchId)?.svgId ?? '-1', - branchLabel.value2 + this.edgesMap.get(branchState.branchId)?.svgId ?? '-1', + branchState.value2 ); - this.setBranchConnection( - branchLabel.branchId, + this.setBranchSideConnection( + branchState.branchId, '1', - this.edgesMap.get(branchLabel.branchId)?.svgId ?? '-1', - branchLabel.connected1 + this.edgesMap.get(branchState.branchId)?.svgId ?? '-1', + branchState.connected1 ); - this.setBranchConnection( - branchLabel.branchId, + this.setBranchSideConnection( + branchState.branchId, '2', - this.edgesMap.get(branchLabel.branchId)?.svgId ?? '-1', - branchLabel.connected2 + this.edgesMap.get(branchState.branchId)?.svgId ?? '-1', + branchState.connected2 ); }); } @@ -1455,7 +1455,7 @@ export class NetworkAreaDiagramViewer { } } - private setBranchConnection(branchId: string, side: string, edgeId: string, connected: boolean) { + private setBranchSideConnection(branchId: string, side: string, edgeId: string, connected: boolean) { const halfEdge: SVGGraphicsElement | null = this.container.querySelector("[id='" + edgeId + '.' + side + "']"); if (halfEdge !== null && halfEdge != undefined) { if (connected == undefined || connected) { diff --git a/src/index.ts b/src/index.ts index 9379f63..2f6b55f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ export type { OnMoveTextNodeCallbackType, OnSelectNodeCallbackType, OnToggleNadHoverCallbackType, - BranchLabel, + BranchState, } from './components/network-area-diagram-viewer/network-area-diagram-viewer'; export type { DiagramMetadata } from './components/network-area-diagram-viewer/diagram-metadata'; export { THRESHOLD_STATUS } from './components/network-area-diagram-viewer/dynamic-css-utils';