( tool, x, y, insertIndex = -1 )
| 555 | } |
| 556 | |
| 557 | addNode( tool, x, y, insertIndex = -1 ){ |
| 558 | let pt = this.graph.convertScreenToPath( x, y ); |
| 559 | if (this.config.snap) this.graph.snapToGrid( pt ); |
| 560 | const node = { tool, x: pt.x, y: pt.y }; |
| 561 | this.activeNode = node; |
| 562 | if (insertIndex != -1){ |
| 563 | this.nodes.splice( insertIndex, 0, node ); |
| 564 | }else{ |
| 565 | this.nodes.push( node ); |
| 566 | } |
| 567 | const prevNode = ( insertIndex == -1 ) ? this.nodes[ this.nodes.length - 2 ] : this.nodes[ insertIndex - 1 ]; |
| 568 | |
| 569 | let ptB; |
| 570 | |
| 571 | switch ( tool ){ |
| 572 | case 'quadraticCurveTo': |
| 573 | pt = Geometry.calcLineMidPoint( prevNode, node ); |
| 574 | node.options = { ctrlA: pt }; |
| 575 | break; |
| 576 | case 'bezierCurveTo': |
| 577 | pt = Geometry.calcPointAlongLine( prevNode, node, 0.66 ); |
| 578 | ptB = Geometry.calcPointAlongLine( prevNode, node, 0.33 ); |
| 579 | node.options = { ctrlA: pt, ctrlB: ptB }; |
| 580 | break; |
| 581 | case 'arc': |
| 582 | const radius = ( prevNode ) ? Geometry.calcDistanceBetweenTwoPoints( prevNode, node ) : 0.5; |
| 583 | node.options = { radius, start: 0, end: Math.PI*2, clockwise: false }; |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | this.render(true); |
| 588 | } |
| 589 | |
| 590 | resize(){ |
| 591 | this.canvas.width = window.innerWidth; |
no test coverage detected