0

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);
        }
    }
};
  • That depends on the implementation of the class "Point". Can you post the code of the class? – cdold Jul 21 '22 at 17:43
  • https://docs.yworks.com/yfileshtml/#/api/Point – Cameron Bogucki Jul 21 '22 at 17:54
  • its kinda lengthy in the code itself. however i can provide the documentation – Cameron Bogucki Jul 21 '22 at 17:57
  • I don't know exactly what you want to do, but doesn't applying a different `y` value not work? Additionally, it looks like you might be able to use [toYVector](https://docs.yworks.com/yfileshtml/#/api/Point#Point-defaultmethod-toYVector), but I'm not familiar with this yworks library. – paddotk Jul 21 '22 at 17:58
  • let me explain a little deeper i apologize. so im trying to create a button that will move 'ports' to a specific location. when i click the button with the code above it stacks all the ports on top of eachother. so im trying to increment the y value so it separates the other ports. – Cameron Bogucki Jul 21 '22 at 18:11

2 Answers2

1

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);
        }
    })
Sebastian
  • 7,729
  • 2
  • 37
  • 69
1

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)