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

[sld-viewer] Simplify computations for navigation arrow #34

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -392,47 +392,13 @@ export class SingleLineDiagramViewer {
private addNavigationArrow() {
if (this.onNextVoltageCallback !== null) {
let navigable = this.svgMetadata?.nodes.filter((el) => el.nextVId);
let vlList = this.svgMetadata?.nodes.map((element) => element.vid);
vlList = vlList?.filter(
(element, index) =>
element !== '' && vlList?.indexOf(element) === index
);
const vlList = navigable?.map((element) => element.vid);
const vlSet = new Set(vlList);

//remove arrows if the arrow points to the current svg
navigable = navigable?.filter((element) => {
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 = navigable?.filter(
(element) => !vlSet.has(element.nextVId)
);

navigable?.forEach((element) => {
const elementById: HTMLElement | null =
Expand All @@ -442,6 +408,8 @@ export class SingleLineDiagramViewer {
?.getAttribute('transform')
?.split(',');
const xs = transform?.[0]?.match(/\d+/)?.[0];
const ys = transform?.[1]?.match(/\d+/)?.[0] || '';
const y = parseInt(ys, 10);
if (xs !== undefined) {
const x = parseInt(xs, 10);
const feederWidth =
Expand All @@ -452,8 +420,7 @@ export class SingleLineDiagramViewer {
elementById,
element.direction,
x + feederWidth / 2,
highestY.get(element.vid),
lowestY.get(element.vid)
y
);
}
}
Expand All @@ -480,20 +447,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
Loading