Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read layout parameters from metadata in network area diagram viewer #95

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion demo/src/diagram-viewers/data/nad-four-substations.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion demo/src/diagram-viewers/data/nad-ieee14cdf-solved.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demo/src/diagram-viewers/data/nad-ieee300cdf-VL9006.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion demo/src/diagram-viewers/data/nad-scada.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/components/network-area-diagram-viewer/diagram-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,23 @@ export function getTextNodeMoves(
{ xOrig: connXOrig, yOrig: connYOrig, xNew: connXNew, yNew: connYNew },
];
}

// get number parameter from metadata element
export function getNumberParameter(
parametersMetadataElement: SVGGraphicsElement | null,
parameterName: string,
parameterDefault: number
): number {
const parameter = parametersMetadataElement?.getAttribute(parameterName);
return parameter !== undefined && parameter !== null ? +parameter : parameterDefault;
}

// get boolean parameter from metadata element
export function getBooleanParameter(
parametersMetadataElement: SVGGraphicsElement | null,
parameterName: string,
parameterDefault: boolean
): boolean {
const parameter = parametersMetadataElement?.getAttribute(parameterName);
return parameter !== undefined && parameter !== null ? parameter === 'true' : parameterDefault;
}
28 changes: 28 additions & 0 deletions src/components/network-area-diagram-viewer/layout-parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { getNumberParameter } from './diagram-utils';

export class LayoutParameters {
static readonly TEXT_NODE_EDGE_CONNECTION_Y_SHIFT_PARAMETER_NAME = 'textnodeedgeconnectionyshift';

static readonly TEXT_NODE_EDGE_CONNECTION_Y_SHIFT_DEFAULT = 25.0;

textNodeEdgeConnectionYShift: number;

constructor(layoutParametersElement: SVGGraphicsElement | null) {
this.textNodeEdgeConnectionYShift = getNumberParameter(
layoutParametersElement,
LayoutParameters.TEXT_NODE_EDGE_CONNECTION_Y_SHIFT_PARAMETER_NAME,
LayoutParameters.TEXT_NODE_EDGE_CONNECTION_Y_SHIFT_DEFAULT
);
}

public getTextNodeEdgeConnectionYShift(): number {
return this.textNodeEdgeConnectionYShift;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Point, SVG, ViewBoxLike, Svg } from '@svgdotjs/svg.js';
import '@svgdotjs/svg.panzoom.js';
import * as DiagramUtils from './diagram-utils';
import { SvgParameters } from './svg-parameters';
import { LayoutParameters } from './layout-parameters';

type DIMENSIONS = { width: number; height: number; viewbox: VIEWBOX };
type VIEWBOX = { x: number; y: number; width: number; height: number };
Expand Down Expand Up @@ -52,6 +53,7 @@ export class NetworkAreaDiagramViewer {
ctm: DOMMatrix | null | undefined = null;
initialPosition: Point = new Point(0, 0);
svgParameters: SvgParameters;
layoutParameters: LayoutParameters;
edgeAngles: Map<string, number> = new Map<string, number>();
textNodeSelected: boolean = false;
endTextEdge: Point = new Point(0, 0);
Expand Down Expand Up @@ -80,6 +82,7 @@ export class NetworkAreaDiagramViewer {
this.originalHeight = 0;
this.init(minWidth, minHeight, maxWidth, maxHeight, enableNodeMoving);
this.svgParameters = this.getSvgParameters();
this.layoutParameters = this.getLayoutParameters();
this.onMoveNodeCallback = onMoveNodeCallback;
this.onMoveTextNodeCallback = onMoveTextNodeCallback;
this.onSelectNodeCallback = onSelectNodeCallback;
Expand Down Expand Up @@ -262,6 +265,12 @@ export class NetworkAreaDiagramViewer {
return new SvgParameters(svgParametersElement);
}

private getLayoutParameters(): LayoutParameters {
const layoutParametersElement: SVGGraphicsElement | null =
this.container.querySelector('nad\\:layoutparameters');
return new LayoutParameters(layoutParametersElement);
}

private startDrag(event: Event) {
const draggableElem = DiagramUtils.getDraggableFrom(event.target as SVGElement);
if (!draggableElem) {
Expand Down Expand Up @@ -429,7 +438,7 @@ export class NetworkAreaDiagramViewer {
this.endTextEdge = DiagramUtils.getTextEdgeEnd(
textNodePosition,
vlNodePosition,
this.svgParameters.getDetailedTextNodeYShift(),
this.layoutParameters.getTextNodeEdgeConnectionYShift(),
textHeight,
textWidth
);
Expand Down
Loading
Loading