Skip to content

Commit

Permalink
Simplify arrow y computation
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Feb 23, 2024
1 parent 40b6019 commit 9ef560d
Showing 1 changed file with 6 additions and 39 deletions.
45 changes: 6 additions & 39 deletions src/single-line-diagram-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,37 +388,6 @@ export class SingleLineDiagramViewer {
return vlList?.indexOf(element.nextVId) === -1;
});

const highestY = new Map();
const lowestY = new Map();
let y;

navigable?.forEach((element) => {
const elementById: HTMLElement | null =
this.container.querySelector('#' + element.id);
if (elementById != null) {
const transform: string[] | undefined = elementById
?.getAttribute('transform')
?.split(',');

const ys = transform?.[1]?.match(/\d+/)?.[0];
if (ys !== undefined) {
y = parseInt(ys, 10);
if (
highestY.get(element.vid) === undefined ||
y > highestY.get(element.vid)
) {
highestY.set(element.vid, y);
}
if (
lowestY.get(element.vid) === undefined ||
y < lowestY.get(element.vid)
) {
lowestY.set(element.vid, y);
}
}
}
});

navigable?.forEach((element) => {
const elementById: HTMLElement | null =
this.container.querySelector('#' + element.id);
Expand All @@ -427,14 +396,15 @@ export class SingleLineDiagramViewer {
?.getAttribute('transform')
?.split(',');
const xs = transform?.[0]?.match(/\d+/)?.[0];
const ys = transform?.[1]?.match(/\d+/)?.[0] || 0;
const y = parseInt(ys, 10);
if (xs !== undefined) {
const x = parseInt(xs, 10);
this.createSvgArrow(
elementById,
element.direction,
x,
highestY.get(element.vid),
lowestY.get(element.vid)
y
);
}
}
Expand All @@ -461,20 +431,17 @@ export class SingleLineDiagramViewer {
element: HTMLElement,
position: string,
x: number,
highestY: number,
lowestY: number
y: number
) {
const svgInsert: HTMLElement | null = element?.parentElement;
if (svgInsert !== undefined && svgInsert !== null) {
const group = document.createElementNS(SVG_NS, 'g');
const svgMetadata = this.svgMetadata;
let y;

if (position === 'TOP') {
y = lowestY - 65;
y = y - 65;
x = x - 22;
} else {
y = highestY + 65;
y = y + 65;
x = x + 22;
}

Expand Down

0 comments on commit 9ef560d

Please sign in to comment.