Skip to content

Commit

Permalink
Read layout parameters from metadata in network area diagram viewer
Browse files Browse the repository at this point in the history
Signed-off-by: massimo.ferraro <[email protected]>
  • Loading branch information
massimo-ferraro authored and flo-dup committed Aug 7, 2024
1 parent 5f528a5 commit e48d754
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 45 deletions.
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

0 comments on commit e48d754

Please sign in to comment.