diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-07 15:35:41 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-07 15:35:41 +0100 |
commit | 7b02d60829d1151a9fd1e726a0a995b92b165328 (patch) | |
tree | 5a7c86988fedd7420d45336ee36edf98e109e8a1 /src/types | |
parent | 5161dfdb3a08490da0ae1c5c8b6515eb0ae0da30 (diff) | |
download | svg.js-7b02d60829d1151a9fd1e726a0a995b92b165328.tar.gz svg.js-7b02d60829d1151a9fd1e726a0a995b92b165328.zip |
Release 3.0.43.0.4
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/Box.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/types/Box.js b/src/types/Box.js index 3df1367..eb43d07 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -2,6 +2,7 @@ import { delimiter } from '../modules/core/regex.js' import { globals } from '../utils/window.js' import { register } from '../utils/adopter.js' import { registerMethods } from '../utils/methods.js' +import Matrix from './Matrix.js' import Point from './Point.js' import parser from '../modules/core/parser.js' @@ -150,6 +151,37 @@ registerMethods({ // act as setter return this.attr('viewBox', new Box(x, y, width, height)) + }, + + zoom (level, point) { + var style = window.getComputedStyle(this.node) + + var width = parseFloat(style.getPropertyValue('width')) + + var height = parseFloat(style.getPropertyValue('height')) + + var v = this.viewbox() + + var zoomX = width / v.width + + var zoomY = height / v.height + + var zoom = Math.min(zoomX, zoomY) + + if (level == null) { + return zoom + } + + var zoomAmount = zoom / level + if (zoomAmount === Infinity) zoomAmount = Number.MIN_VALUE + + point = point || new Point(width / 2 / zoomX + v.x, height / 2 / zoomY + v.y) + + var box = new Box(v).transform( + new Matrix({ scale: zoomAmount, origin: point }) + ) + + return this.viewbox(box) } } }) |