Skip to content

Commit

Permalink
Use same variables for updating metadata and calling callback
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 3, 2024
1 parent cca7bb4 commit 71b10d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
5 changes: 0 additions & 5 deletions src/components/network-area-diagram-viewer/diagram-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ const EdgeTypeMapping: { [key: string]: EdgeType } = {
ThreeWtEdge: EdgeType.THREE_WINDINGS_TRANSFORMER,
};

// round a number w.r.t a precision
export function round(value: number, precision: number): number {
return +value.toFixed(precision);
}

// format number to string
export function getFormattedValue(value: number): string {
return value.toFixed(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1211,30 +1211,27 @@ export class NetworkAreaDiagramViewer {
}

private updateMetadataCallCallback(mousePosition: Point) {
// get move node in metadata
// get moved node in metadata
const node: SVGGraphicsElement | null = this.container.querySelector(
'nad\\:node[svgid="' + this.selectedElement?.id + '"]'
);
if (node != null) {
// get new position
const xNew = DiagramUtils.getFormattedValue(mousePosition.x);
const yNew = DiagramUtils.getFormattedValue(mousePosition.y);
// save original position, for the callback
const xOrig = node.getAttribute('x') ?? 0;
const yOrig = node.getAttribute('y') ?? 0;
const xOrig = node.getAttribute('x') ?? '0';
const yOrig = node.getAttribute('y') ?? '0';
// update node position in metadata
node.setAttribute(
'x',
DiagramUtils.getFormattedValue(mousePosition.x)
);
node.setAttribute(
'y',
DiagramUtils.getFormattedValue(mousePosition.y)
);
node.setAttribute('x', xNew);
node.setAttribute('y', yNew);
// call the callback, if defined
if (this.onNodeCallback != null) {
this.onNodeCallback(
node.getAttribute('equipmentid') ?? '',
node.getAttribute('svgid') ?? '',
DiagramUtils.round(mousePosition.x, 2),
DiagramUtils.round(mousePosition.y, 2),
+xNew,
+yNew,
+xOrig,
+yOrig
);
Expand Down

0 comments on commit 71b10d1

Please sign in to comment.