Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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];
}
} else {
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 });
// 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]));
}
export default (options: CanvasEngineOptions = {}): DiagramEngine => {
const engine = new DiagramEngine(options);
// register model factories
engine.getLayerFactories().registerFactory(new NodeLayerFactory());
engine.getLayerFactories().registerFactory(new LinkLayerFactory());
engine.getLayerFactories().registerFactory(new SelectionBoxLayerFactory());
engine.getLabelFactories().registerFactory(new DefaultLabelFactory());
engine.getNodeFactories().registerFactory(new DefaultNodeFactory()); // i cant figure out why
engine.getLinkFactories().registerFactory(new DefaultLinkFactory());
engine.getLinkFactories().registerFactory(new PathFindingLinkFactory());
engine.getPortFactories().registerFactory(new DefaultPortFactory());
// register the default interaction behaviours
engine.getStateMachine().pushState(new DefaultDiagramState());
return engine;
};
export default (options: CanvasEngineOptions = {}): DiagramEngine => {
const engine = new DiagramEngine(options);
// register model factories
engine.getLayerFactories().registerFactory(new NodeLayerFactory());
engine.getLayerFactories().registerFactory(new LinkLayerFactory());
engine.getLayerFactories().registerFactory(new SelectionBoxLayerFactory());
engine.getLabelFactories().registerFactory(new DefaultLabelFactory());
engine.getNodeFactories().registerFactory(new DefaultNodeFactory()); // i cant figure out why
engine.getLinkFactories().registerFactory(new DefaultLinkFactory());
engine.getLinkFactories().registerFactory(new PathFindingLinkFactory());
engine.getPortFactories().registerFactory(new DefaultPortFactory());
// register the default interaction behaviours
engine.getStateMachine().pushState(new DefaultDiagramState());
return engine;
};
constructor() {
super({ name: 'starting-state' });
this.childStates = [new SelectingState()];
this.dragCanvas = new DragCanvasState();
this.createLink = new CreateLinkState();
this.dragItems = new DragDiagramItemsState();
// determine what was clicked on
this.registerAction(
new Action({
type: InputType.MOUSE_DOWN,
fire: (event: ActionEvent) => {
const element = this.engine.getActionEventBus().getModelForEvent(event);
// the canvas was clicked on, transition to the dragging canvas state
if (!element) {
this.transitionWithEvent(this.dragCanvas, event);
}
// initiate dragging a new link
else if (element instanceof PortModel) {
return;
}
export default (options: CanvasEngineOptions = {}): DiagramEngine => {
const engine = new DiagramEngine(options);
// register model factories
engine.getLayerFactories().registerFactory(new NodeLayerFactory());
engine.getLayerFactories().registerFactory(new LinkLayerFactory());
engine.getLayerFactories().registerFactory(new SelectionBoxLayerFactory());
engine.getLabelFactories().registerFactory(new DefaultLabelFactory());
engine.getNodeFactories().registerFactory(new DefaultNodeFactory()); // i cant figure out why
engine.getLinkFactories().registerFactory(new DefaultLinkFactory());
engine.getLinkFactories().registerFactory(new PathFindingLinkFactory());
engine.getPortFactories().registerFactory(new DefaultPortFactory());
// register the default interaction behaviours
engine.getStateMachine().pushState(new DefaultDiagramState());
return engine;
};
export default (options: CanvasEngineOptions = {}): DiagramEngine => {
const engine = new DiagramEngine(options);
// register model factories
engine.getLayerFactories().registerFactory(new NodeLayerFactory());
engine.getLayerFactories().registerFactory(new LinkLayerFactory());
engine.getLayerFactories().registerFactory(new SelectionBoxLayerFactory());
engine.getLabelFactories().registerFactory(new DefaultLabelFactory());
engine.getNodeFactories().registerFactory(new DefaultNodeFactory()); // i cant figure out why
engine.getLinkFactories().registerFactory(new DefaultLinkFactory());
engine.getLinkFactories().registerFactory(new PathFindingLinkFactory());
engine.getPortFactories().registerFactory(new DefaultPortFactory());
// register the default interaction behaviours
engine.getStateMachine().pushState(new DefaultDiagramState());
return engine;
};