Skip to content

Commit

Permalink
Merge pull request #76 from Jont828/zoom-limit
Browse files Browse the repository at this point in the history
Set zoom out limit to 10% to prevent 0 or negative zoom
  • Loading branch information
Jont828 authored Dec 4, 2024
2 parents 2db962b + f588236 commit 41c4f2e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions web/src/components/VueTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const DEFAULT_HEIGHT_DECREMENT = 100;
const ANIMATION_DURATION = 800;
const ZOOM_INCREMENT = 0.1;
function rotatePoint({ x, y }) {
return {
x: y,
Expand Down Expand Up @@ -164,25 +166,28 @@ export default {
zoomIn() {
const originTransformStr = this.$refs.domContainer.style.transform;
// 如果已有scale属性, 在原基础上修改
let targetScale = 1.2;
let targetScale = 1;
// let targetScale = 1 * 1.2;
const scaleMatchResult = originTransformStr.match(MATCH_SCALE_REGEX);
if (scaleMatchResult && scaleMatchResult.length > 0) {
const originScale = parseFloat(scaleMatchResult[1]);
targetScale = originScale + 0.1;
targetScale = originScale + ZOOM_INCREMENT;
// targetScale *= originScale;
}
this.setScale(targetScale);
},
zoomOut() {
const originTransformStr = this.$refs.domContainer.style.transform;
// 如果已有scale属性, 在原基础上修改
let targetScale = 0.8;
let targetScale = 1;
// let targetScale = 1 / 1.2;
const scaleMatchResult = originTransformStr.match(MATCH_SCALE_REGEX);
if (scaleMatchResult && scaleMatchResult.length > 0) {
const originScale = parseFloat(scaleMatchResult[1]);
targetScale = originScale - 0.1;
if (originScale > ZOOM_INCREMENT)
targetScale = originScale - 0.1;
else
targetScale = originScale;
// targetScale = originScale / 1.2;
}
this.setScale(targetScale);
Expand Down

0 comments on commit 41c4f2e

Please sign in to comment.