Skip to content

Commit b41feb5

Browse files
committed
feat: add scaleFit function
1 parent c36a267 commit b41feb5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/interact.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ export const scale = function (this: MindElixirInstance, scaleVal: number) {
167167
this.map.style.transform = 'scale(' + scaleVal + ')'
168168
this.bus.fire('scale', scaleVal)
169169
}
170+
171+
/**
172+
* Better to use with option `alignment: 'nodes'`.
173+
*/
174+
export const scaleFit = function (this: MindElixirInstance) {
175+
const heightPercent = this.nodes.offsetHeight / this.container.offsetHeight
176+
const widthPercent = this.nodes.offsetWidth / this.container.offsetWidth
177+
const scale = 1 / Math.max(1, Math.max(heightPercent, widthPercent))
178+
this.scaleVal = scale
179+
this.map.style.transform = 'scale(' + scale + ')'
180+
this.bus.fire('scale', scale)
181+
}
182+
170183
/**
171184
* @function
172185
* @instance

0 commit comments

Comments
 (0)