* Fit the content to the viewport.
(maxScale = this.options.maxInitialScale)
| 616 | * Fit the content to the viewport. |
| 617 | */ |
| 618 | async fit(maxScale = this.options.maxInitialScale): Promise<void> { |
| 619 | const svgNode = this.svg.node()!; |
| 620 | const { width: offsetWidth, height: offsetHeight } = |
| 621 | svgNode.getBoundingClientRect(); |
| 622 | const { fitRatio } = this.options; |
| 623 | const { x1, y1, x2, y2 } = this.state.rect; |
| 624 | const naturalWidth = x2 - x1; |
| 625 | const naturalHeight = y2 - y1; |
| 626 | const scale = Math.min( |
| 627 | (offsetWidth / naturalWidth) * fitRatio, |
| 628 | (offsetHeight / naturalHeight) * fitRatio, |
| 629 | maxScale, |
| 630 | ); |
| 631 | const initialZoom = zoomIdentity |
| 632 | .translate( |
| 633 | (offsetWidth - naturalWidth * scale) / 2 - x1 * scale, |
| 634 | (offsetHeight - naturalHeight * scale) / 2 - y1 * scale, |
| 635 | ) |
| 636 | .scale(scale); |
| 637 | return this.transition(this.svg) |
| 638 | .call(this.zoom.transform, initialZoom) |
| 639 | .end() |
| 640 | .catch(noop); |
| 641 | } |
| 642 | |
| 643 | findElement(node: INode) { |
| 644 | let result: |
no test coverage detected