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

Split mouse events methods in network area diagram viewer #107

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 21 additions & 3 deletions src/components/network-area-diagram-viewer/diagram-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function getConverterStationPolyline(
return getFormattedPolyline(points[0], null, points[1]);
}

// get the drabbable element, if present,
// get the draggable element, if present,
// from the element selected using the mouse
export function getDraggableFrom(element: SVGElement): SVGElement | undefined {
if (isDraggable(element)) {
Expand All @@ -214,12 +214,30 @@ export function getDraggableFrom(element: SVGElement): SVGElement | undefined {
}
}

// get the selectable element, if present,
// from the element selected using the mouse
export function getSelectableFrom(element: SVGElement): SVGElement | undefined {
if (isSelectable(element)) {
return element;
} else if (element.parentElement) {
return getSelectableFrom(element.parentNode as SVGElement);
}
}

function isDraggable(element: SVGElement): boolean {
return (
hasId(element) && element.parentNode != null && classIsContainerOfDraggables(element.parentNode as SVGElement)
);
}

function isSelectable(element: SVGElement): boolean {
return (
hasId(element) &&
element.parentNode != null &&
(element.parentNode as SVGElement).classList.contains('nad-vl-nodes')
);
}

function hasId(element: SVGElement): boolean {
return typeof element.id != 'undefined' && element.id != '';
}
Expand Down Expand Up @@ -398,9 +416,9 @@ export function getEdgeNameAngle(point1: Point, point2: Point): number {
}

// check if a DOM element is a text node
export function isTextNode(element: SVGGraphicsElement | null): boolean | undefined {
export function isTextNode(element: SVGGraphicsElement | null): boolean {
return (
element != null && element.parentElement != null && element.parentElement?.classList.contains('nad-text-nodes')
element != null && element.parentElement != null && element.parentElement.classList.contains('nad-text-nodes')
);
}

Expand Down
Loading
Loading