* Pan the content to make the provided node visible in the viewport.
(node: INode, padding?: Partial<IPadding>)
| 664 | * Pan the content to make the provided node visible in the viewport. |
| 665 | */ |
| 666 | async ensureVisible(node: INode, padding?: Partial<IPadding>) { |
| 667 | const itemData = this.findElement(node)?.data; |
| 668 | if (!itemData) return; |
| 669 | const svgNode = this.svg.node()!; |
| 670 | const relRect = svgNode.getBoundingClientRect(); |
| 671 | const transform = zoomTransform(svgNode); |
| 672 | const [left, right] = [ |
| 673 | itemData.state.rect.x, |
| 674 | itemData.state.rect.x + itemData.state.rect.width + 2, |
| 675 | ].map((x) => x * transform.k + transform.x); |
| 676 | const [top, bottom] = [ |
| 677 | itemData.state.rect.y, |
| 678 | itemData.state.rect.y + itemData.state.rect.height, |
| 679 | ].map((y) => y * transform.k + transform.y); |
| 680 | // Skip if the node includes or is included in the container. |
| 681 | const pd: IPadding = { |
| 682 | left: 0, |
| 683 | right: 0, |
| 684 | top: 0, |
| 685 | bottom: 0, |
| 686 | ...padding, |
| 687 | }; |
| 688 | const dxs = [pd.left - left, relRect.width - pd.right - right]; |
| 689 | const dys = [pd.top - top, relRect.height - pd.bottom - bottom]; |
| 690 | const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0; |
| 691 | const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0; |
| 692 | if (dx || dy) { |
| 693 | const newTransform = transform.translate(dx, dy); |
| 694 | return this.transition(this.svg) |
| 695 | .call(this.zoom.transform, newTransform) |
| 696 | .end() |
| 697 | .catch(noop); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | /** @deprecated Use `ensureVisible` instead */ |
| 702 | ensureView = this.ensureVisible; |
nothing calls this directly
no test coverage detected