From 8f32510f31bb152090184bb47f6528294721774f Mon Sep 17 00:00:00 2001 From: Massimo Ferraro Date: Wed, 19 Jun 2024 10:31:06 +0200 Subject: [PATCH] Move edge names when moving edges in network area diagram (#77) Signed-off-by: massimo.ferraro --- .../data/nad-eurostag-tutorial-example1.svg | 16 ++++++++ demo/src/diagram-viewers/data/nad-scada.svg | 11 ++++++ .../diagram-utils.ts | 7 ++++ .../network-area-diagram-viewer.ts | 39 +++++++++++++++++++ .../svg-parameters.ts | 5 +++ 5 files changed, 78 insertions(+) diff --git a/demo/src/diagram-viewers/data/nad-eurostag-tutorial-example1.svg b/demo/src/diagram-viewers/data/nad-eurostag-tutorial-example1.svg index 31a3365..0974390 100644 --- a/demo/src/diagram-viewers/data/nad-eurostag-tutorial-example1.svg +++ b/demo/src/diagram-viewers/data/nad-eurostag-tutorial-example1.svg @@ -176,6 +176,9 @@ + + NGEN_NHV1 + @@ -203,6 +206,11 @@ + + + NHV1_NHV2_1 + + @@ -229,6 +237,11 @@ + + + NHV1_NHV2_2 + + @@ -258,6 +271,9 @@ + + NHV2_NLOAD + diff --git a/demo/src/diagram-viewers/data/nad-scada.svg b/demo/src/diagram-viewers/data/nad-scada.svg index 1121929..3ebf30a 100644 --- a/demo/src/diagram-viewers/data/nad-scada.svg +++ b/demo/src/diagram-viewers/data/nad-scada.svg @@ -176,6 +176,11 @@ + + + line + + @@ -206,6 +211,9 @@ + + tw2t + @@ -252,6 +260,9 @@ + + hvdcline + diff --git a/src/components/network-area-diagram-viewer/diagram-utils.ts b/src/components/network-area-diagram-viewer/diagram-utils.ts index 138b02a..c4e3aa8 100644 --- a/src/components/network-area-diagram-viewer/diagram-utils.ts +++ b/src/components/network-area-diagram-viewer/diagram-utils.ts @@ -436,3 +436,10 @@ export function getBoundarySemicircle( getCirclePath(busOuterRadius, startAngle, startAngle + Math.PI, true) ); } + +// get the angle of a edge name between two points +export function getEdgeNameAngle(point1: Point, point2: Point): number { + const angle = getAngle(point1, point2); + const textFlipped = Math.cos(angle) < 0; + return radToDeg(textFlipped ? angle - Math.PI : angle); +} 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 b46c58f..69e112e 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 @@ -731,6 +731,14 @@ export class NetworkAreaDiagramViewer { edgeMiddle ); } + // if present, move edge name + if (this.svgParameters.getEdgeNameDisplayed()) { + this.moveEdgeName( + edgeNode, + edgeMiddle, + edgeFork1 == null ? edgeStart1 : edgeFork1 + ); + } // store edge angles, to use them for bus node redrawing this.edgeAngles.set( edgeNode.id + '.1', @@ -960,6 +968,37 @@ export class NetworkAreaDiagramViewer { }); } + moveEdgeName( + edgeNode: SVGGraphicsElement, + anchorPoint: Point, + edgeStart: Point + ) { + const positionElement: SVGGraphicsElement | null = + edgeNode.querySelector('.nad-edge-label') as SVGGraphicsElement; + if (positionElement != null) { + // move edge name position + positionElement.setAttribute( + 'transform', + 'translate(' + DiagramUtils.getFormattedPoint(anchorPoint) + ')' + ); + const angleElement: SVGGraphicsElement | null = + positionElement.querySelector('text') as SVGGraphicsElement; + if (angleElement != null) { + // change edge name angle + const edgeNameAngle = DiagramUtils.getEdgeNameAngle( + edgeStart, + anchorPoint + ); + angleElement.setAttribute( + 'transform', + 'rotate(' + + DiagramUtils.getFormattedValue(edgeNameAngle) + + ')' + ); + } + } + } + private redrawVoltageLevelNode( node: SVGGraphicsElement | null, busNodeEdges: Map, diff --git a/src/components/network-area-diagram-viewer/svg-parameters.ts b/src/components/network-area-diagram-viewer/svg-parameters.ts index 03d005a..a1102be 100644 --- a/src/components/network-area-diagram-viewer/svg-parameters.ts +++ b/src/components/network-area-diagram-viewer/svg-parameters.ts @@ -18,6 +18,7 @@ export class SvgParameters { converterStationWidth = 70.0; nodeHollowWidth = 15.0; unknownBusNodeExtraRadius = 10.0; + edgeNameDisplayed = true; public getVoltageLevelCircleRadius(): number { return this.voltageLevelCircleRadius; @@ -58,4 +59,8 @@ export class SvgParameters { public getUnknownBusNodeExtraRadius(): number { return this.unknownBusNodeExtraRadius; } + + public getEdgeNameDisplayed(): boolean { + return this.edgeNameDisplayed; + } }