MCPcopy
hub / github.com/markmap/markmap / rescale

Method rescale

packages/markmap-view/src/view.ts:739–756  ·  view source on GitHub ↗

* Scale content with it pinned at the center of the viewport.

(scale: number)

Source from the content-addressed store, hash-verified

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);

Callers 1

constructorMethod · 0.80

Calls 2

transitionMethod · 0.95
callMethod · 0.80

Tested by

no test coverage detected