MCPcopy
hub / github.com/markmap/markmap / fit

Method fit

packages/markmap-view/src/view.ts:618–641  ·  view source on GitHub ↗

* Fit the content to the viewport.

(maxScale = this.options.maxInitialScale)

Source from the content-addressed store, hash-verified

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:

Callers 5

renderDataMethod · 0.95
createMethod · 0.95
constructorMethod · 0.80
doRenderFunction · 0.80
checkDataFunction · 0.80

Calls 2

transitionMethod · 0.95
callMethod · 0.80

Tested by

no test coverage detected