Skip to content

Commit

Permalink
Separating selectedElement and draggedElement, some renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Nov 4, 2024
1 parent e10b9e3 commit adcde8f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 112 deletions.
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

0 comments on commit adcde8f

Please sign in to comment.