Skip to content

Commit

Permalink
Rename BranchLabel to BranchState
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg committed Dec 20, 2024
1 parent def0119 commit 4b68c0b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
12 changes: 6 additions & 6 deletions demo/src/diagram-viewers/add-diagrams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
OnMoveTextNodeCallbackType,
OnSelectNodeCallbackType,
OnToggleNadHoverCallbackType,
BranchLabel,
BranchState,
} from '../../../src';

export const addNadToDemo = () => {
Expand Down Expand Up @@ -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": ' +
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
});
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 4b68c0b

Please sign in to comment.