Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPortCoords(port: PortModel, element?: HTMLDivElement): Rectangle {
if (!this.canvas) {
throw new Error('Canvas needs to be set first');
}
if (!element) {
element = this.getNodePortElement(port);
}
const sourceRect = element.getBoundingClientRect();
const point = this.getRelativeMousePoint({
clientX: sourceRect.left,
clientY: sourceRect.top
});
const zoom = this.model.getZoomLevel() / 100.0;
return new Rectangle(point.x, point.y, sourceRect.width / zoom, sourceRect.height / zoom);
}
fireMouseMoved(event: AbstractDisplacementStateEvent) {
this.layer.setBox(this.getBoxDimensions(event));
const relative = this.engine.getRelativeMousePoint({
clientX: this.initialX,
clientY: this.initialY
});
if (event.virtualDisplacementX < 0) {
relative.x -= Math.abs(event.virtualDisplacementX);
}
if (event.virtualDisplacementY < 0) {
relative.y -= Math.abs(event.virtualDisplacementY);
}
const rect = new Rectangle(relative, Math.abs(event.virtualDisplacementX), Math.abs(event.virtualDisplacementY));
for (let model of this.engine.getModel().getSelectionEntities()) {
if (((model as unknown) as ModelGeometryInterface).getBoundingBox) {
const bounds = ((model as unknown) as ModelGeometryInterface).getBoundingBox();
if (rect.containsPoint(bounds.getTopLeft()) && rect.containsPoint(bounds.getBottomRight())) {
model.setSelected(true);
} else {
model.setSelected(false);
}
}
}
this.engine.repaintCanvas();
}
}