(node: INode, padding?: Partial<IPadding>)
| 702 | ensureView = this.ensureVisible; |
| 703 | |
| 704 | async centerNode(node: INode, padding?: Partial<IPadding>) { |
| 705 | const itemData = this.findElement(node)?.data; |
| 706 | if (!itemData) return; |
| 707 | const svgNode = this.svg.node()!; |
| 708 | const relRect = svgNode.getBoundingClientRect(); |
| 709 | const transform = zoomTransform(svgNode); |
| 710 | const x = |
| 711 | (itemData.state.rect.x + itemData.state.rect.width / 2) * transform.k + |
| 712 | transform.x; |
| 713 | const y = |
| 714 | (itemData.state.rect.y + itemData.state.rect.height / 2) * transform.k + |
| 715 | transform.y; |
| 716 | const pd: IPadding = { |
| 717 | left: 0, |
| 718 | right: 0, |
| 719 | top: 0, |
| 720 | bottom: 0, |
| 721 | ...padding, |
| 722 | }; |
| 723 | const cx = (pd.left + relRect.width - pd.right) / 2; |
| 724 | const cy = (pd.top + relRect.height - pd.bottom) / 2; |
| 725 | const dx = (cx - x) / transform.k; |
| 726 | const dy = (cy - y) / transform.k; |
| 727 | if (dx || dy) { |
| 728 | const newTransform = transform.translate(dx, dy); |
| 729 | return this.transition(this.svg) |
| 730 | .call(this.zoom.transform, newTransform) |
| 731 | .end() |
| 732 | .catch(noop); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Scale content with it pinned at the center of the viewport. |
nothing calls this directly
no test coverage detected