Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If there is existing link which has two points add one
// NOTE: It doesn't matter if check is for dy or dx
if (points.length === 2 && dy !== 0 && !this.state.canDrag) {
this.props.link.addPoint(
new PointModel({
link: this.props.link,
position: new Point(pointLeft.getX(), pointRight.getY())
})
);
}
for (let j = 0; j < points.length - 1; j++) {
paths.push(
this.generateLink(
LinkWidget.generateLinePath(points[j], points[j + 1]),
{
'data-linkid': this.props.link.getID(),
'data-point': j,
onMouseDown: (event: MouseEvent) => {
if (event.button === 0) {
this.setState({ canDrag: true });
this.dragging_index = j;
// Register mouse move event to track mouse position
// On mouse up these events are unregistered check "this.handleUp"
window.addEventListener('mousemove', this.handleMove);
window.addEventListener('mouseup', this.handleUp);
}
},
onMouseEnter: (event: MouseEvent) => {
this.setState({ selected: true });
this.props.link.lastHoverIndexOfPath = j;
}
},
'0'
)
);
// draw the link as dangeling
if (this.props.link.getTargetPort() == null) {
paths.push(this.generatePoint(points[1]));
}
} else {
//draw the multiple anchors and complex line instead
for (let j = 0; j < points.length - 1; j++) {
paths.push(
this.generateLink(
LinkWidget.generateLinePath(points[j], points[j + 1]),
{
'data-linkid': this.props.link.getID(),
'data-point': j,
onMouseDown: (event: MouseEvent) => {
this.addPointToLink(event, j + 1);
}
},
j
)
);
}
//render the circles
for (let i = 1; i < points.length - 1; i++) {
paths.push(this.generatePoint(points[i]));
}