how can i increment an (x,y) value for a graph location

58 Views Asked by At

im trying to increment the y value inside of this class "Point" which can only take an x value and a y value. is there a way that i can increment the y

for (const port of node.ports) {
        const p = new Point(-10, 0);
        const j = new Point(8,0);
        if (port.tag.portConnector.charAt(0) === "P") {
            graph.setRelativePortLocation(port, p);
        } else {
            graph.setRelativePortLocation(port, j);
        }
    }
};
2

There are 2 best solutions below

0
Sebastian On

Either increment an external variable or use the foreach method, which provides an optional index:

node.ports.forEach((port, i) => {
        const p = new Point(-10, i * 42);
        const j = new Point(8, i + 1337 / 42);
        if (port.tag.portConnector.charAt(0) === "P") {
            graph.setRelativePortLocation(port, p);
        } else {
            graph.setRelativePortLocation(port, j);
        }
    })
0
Morteza Gholami On

From the documentation, you might wanna try:

const additionalY = 10 //Or any amount you wanna increase
const addition = new Point(0, additionalY )
const newPoint = p.add(addition)