* Scale content with it pinned at the center of the viewport.
(scale: number)
| 737 | * Scale content with it pinned at the center of the viewport. |
| 738 | */ |
| 739 | async rescale(scale: number): Promise<void> { |
| 740 | const svgNode = this.svg.node()!; |
| 741 | const { width: offsetWidth, height: offsetHeight } = |
| 742 | svgNode.getBoundingClientRect(); |
| 743 | const halfWidth = offsetWidth / 2; |
| 744 | const halfHeight = offsetHeight / 2; |
| 745 | const transform = zoomTransform(svgNode); |
| 746 | const newTransform = transform |
| 747 | .translate( |
| 748 | ((halfWidth - transform.x) * (1 - scale)) / transform.k, |
| 749 | ((halfHeight - transform.y) * (1 - scale)) / transform.k, |
| 750 | ) |
| 751 | .scale(scale); |
| 752 | return this.transition(this.svg) |
| 753 | .call(this.zoom.transform, newTransform) |
| 754 | .end() |
| 755 | .catch(noop); |
| 756 | } |
| 757 | |
| 758 | destroy() { |
| 759 | this.svg.on('.zoom', null); |
no test coverage detected