Skip to content

Commit

Permalink
Move edge names when moving edges in network area diagram (#77)
Browse files Browse the repository at this point in the history
Signed-off-by: massimo.ferraro <massimo.ferraro@soft.it>
  • Loading branch information
massimo-ferraro committed Jun 19, 2024
1 parent 6e4df8e commit 8f32510
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
16 changes: 16 additions & 0 deletions demo/src/diagram-viewers/data/nad-eurostag-tutorial-example1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions 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.
7 changes: 7 additions & 0 deletions src/components/network-area-diagram-viewer/diagram-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<string, SVGGraphicsElement[]>,
Expand Down
5 changes: 5 additions & 0 deletions src/components/network-area-diagram-viewer/svg-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SvgParameters {
converterStationWidth = 70.0;
nodeHollowWidth = 15.0;
unknownBusNodeExtraRadius = 10.0;
edgeNameDisplayed = true;

public getVoltageLevelCircleRadius(): number {
return this.voltageLevelCircleRadius;
Expand Down Expand Up @@ -58,4 +59,8 @@ export class SvgParameters {
public getUnknownBusNodeExtraRadius(): number {
return this.unknownBusNodeExtraRadius;
}

public getEdgeNameDisplayed(): boolean {
return this.edgeNameDisplayed;
}
}

0 comments on commit 8f32510

Please sign in to comment.