How to use the @projectstorm/geometry.Point function in @projectstorm/geometry

To help you get started, we’ve selected a few @projectstorm/geometry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectstorm / react-diagrams / packages / react-diagrams-routing / src / link / RightAngleLinkWidget.tsx View on Github external
calculatePositions(points: PointModel[], event: MouseEvent, index: number, coordinate: string) {
		// If path is first or last add another point to keep node port on its position
		if (index === 0) {
			let point = new PointModel({
				link: this.props.link,
				position: new Point(points[index].getX(), points[index].getY())
			});
			this.props.link.addPoint(point, index);
			this.dragging_index++;
			return;
		} else if (index === points.length - 2) {
			let point = new PointModel({
				link: this.props.link,
				position: new Point(points[index + 1].getX(), points[index + 1].getY())
			});
			this.props.link.addPoint(point, index + 1);
			return;
		}

		// Merge two points if it is not close to node port and close to each other
		if (index - 2 > 0) {
			let _points = {
github projectstorm / react-diagrams / packages / react-diagrams-routing / src / link / RightAngleLinkWidget.tsx View on Github external
if (this.props.link.getLastPathXdirection()) {
						points[i - 1].setPosition(points[i - 1].getX(), points[i].getY());
					} else {
						points[i - 1].setPosition(points[i].getX(), points[i - 1].getY());
					}
				}
			}
		}

		// 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
github projectstorm / react-diagrams / packages / react-diagrams-routing / src / link / RightAngleLinkWidget.tsx View on Github external
calculatePositions(points: PointModel[], event: MouseEvent, index: number, coordinate: string) {
		// If path is first or last add another point to keep node port on its position
		if (index === 0) {
			let point = new PointModel({
				link: this.props.link,
				position: new Point(points[index].getX(), points[index].getY())
			});
			this.props.link.addPoint(point, index);
			this.dragging_index++;
			return;
		} else if (index === points.length - 2) {
			let point = new PointModel({
				link: this.props.link,
				position: new Point(points[index + 1].getX(), points[index + 1].getY())
			});
			this.props.link.addPoint(point, index + 1);
			return;
		}

		// Merge two points if it is not close to node port and close to each other
		if (index - 2 > 0) {
			let _points = {
				[index - 2]: points[index - 2].getPosition(),
				[index + 1]: points[index + 1].getPosition(),
				[index - 1]: points[index - 1].getPosition()
			};
			if (Math.abs(_points[index - 1][coordinate] - _points[index + 1][coordinate]) < 5) {
				_points[index - 2][coordinate] = this.props.diagramEngine.getRelativeMousePoint(event)[coordinate];
				_points[index + 1][coordinate] = this.props.diagramEngine.getRelativeMousePoint(event)[coordinate];
				points[index - 2].setPosition(_points[index - 2]);
github projectstorm / react-diagrams / packages / react-diagrams-routing / src / dagre / DagreEngine.ts View on Github external
g.edges().forEach(e => {
				const edge = g.edge(e);
				const link = model.getLink(e.name);

				const points = [link.getFirstPoint()];
				for (let i = 1; i < edge.points.length - 2; i++) {
					points.push(new PointModel({ link: link, position: new Point(edge.points[i].x, edge.points[i].y) }));
				}
				link.setPoints(points.concat(link.getLastPoint()));
			});
		}
github projectstorm / react-diagrams / packages / react-canvas-core / src / CanvasEngine.ts View on Github external
getRelativePoint(x, y): Point {
		const canvasRect = this.canvas.getBoundingClientRect();
		return new Point(x - canvasRect.left, y - canvasRect.top);
	}
github projectstorm / react-diagrams / packages / react-diagrams-core / src / entities / port / PortModel.ts View on Github external
updateCoords(cords: { x: number; y: number; width: number; height: number }) {
		const { x, y, width, height } = cords;
		this.width = width;
		this.height = height;
		this.setPosition(x, y);
		const center = new Point(x + width / 2, y + height / 2);
		_.forEach(this.getLinks(), link => {
			link.getPointForPort(this).setPosition(center.clone());
		});
		this.reportedPosition = true;
		this.fireEvent(
			{
				entity: this
			},
			'reportInitialPosition'
		);
	}
github projectstorm / react-diagrams / packages / react-canvas-core / src / CanvasEngine.ts View on Github external
getRelativeMousePoint(event: { clientX: number; clientY: number }): Point {
		const point = this.getRelativePoint(event.clientX, event.clientY);
		return new Point(
			(point.x - this.model.getOffsetX()) / (this.model.getZoomLevel() / 100.0),
			(point.y - this.model.getOffsetY()) / (this.model.getZoomLevel() / 100.0)
		);
	}
github projectstorm / react-diagrams / packages / react-diagrams-core / src / entities / link / LinkModel.ts View on Github external
this.points = _.map(event.data.points || [], point => {
			var p = new PointModel({
				link: this,
				position: new Point(point.x, point.y)
			});
			p.deserialize({
				...event,
				data: point
			});
			return p;
		});
github projectstorm / react-diagrams / packages / react-diagrams-core / src / entities / link / LinkModel.ts View on Github external
generatePoint(x: number = 0, y: number = 0): PointModel {
		return new PointModel({
			link: this,
			position: new Point(x, y)
		});
	}
}