Skip to content

Commit 7272603

Browse files
authored
Merge pull request #325 from kaustubhxd/scale-sensitivity
Add scaleSensitivity prop to adjust scale sensitivity
2 parents 7651b6e + d9002b7 commit 7272603

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

src/dev.dist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const options: Options = {
3939
return true
4040
},
4141
},
42+
scaleSensitivity: 0.2,
4243
}
4344
const mind = new MindElixir(options)
4445
mind.init(example)

src/dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const options: Options = {
7373
return true
7474
},
7575
},
76+
scaleSensitivity: 0.2,
7677
}
7778

7879
let mind = new MindElixir(options)

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function MindElixir(
3737
overflowHidden,
3838
theme,
3939
alignment,
40+
scaleSensitivity,
4041
}: Options
4142
): void {
4243
let ele: HTMLElement | null = null
@@ -64,6 +65,7 @@ function MindElixir(
6465
this.newTopicName = newTopicName || 'new node'
6566
this.editable = editable === undefined ? true : editable
6667
this.allowUndo = allowUndo === undefined ? false : allowUndo
68+
this.scaleSensitivity = typeof scaleSensitivity === 'number' ? scaleSensitivity : 0.2
6769
// this.parentMap = {} // deal with large amount of nodes
6870
this.currentNode = null // the selected <tpc/> element
6971
this.currentArrow = null // the selected link svg element

src/plugin/keypress.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ const handleZoom = function (mei: MindElixirInstance, direction: 'in' | 'out') {
5959
switch (direction) {
6060
case 'in':
6161
if (mei.scaleVal > 1.6) return
62-
mei.scale((mei.scaleVal += 0.2))
62+
mei.scale((mei.scaleVal += mei.scaleSensitivity))
6363
break
6464
case 'out':
6565
if (mei.scaleVal < 0.6) return
66-
mei.scale((mei.scaleVal -= 0.2))
66+
mei.scale((mei.scaleVal -= mei.scaleSensitivity))
6767
}
6868
}
6969

@@ -190,7 +190,7 @@ export default function (mind: MindElixirInstance, options: boolean | KeypressOp
190190
if (e.ctrlKey || e.metaKey) {
191191
e.preventDefault()
192192
if (e.deltaY < 0) handleZoom(mind, 'in')
193-
else if (mind.scaleVal - 0.2 > 0) handleZoom(mind, 'out')
193+
else if (mind.scaleVal - mind.scaleSensitivity > 0) handleZoom(mind, 'out')
194194
e.stopPropagation()
195195
}
196196
}

src/plugin/toolBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ function createToolBarRBContainer(mind: MindElixirInstance) {
3636
}
3737
zo.onclick = () => {
3838
if (mind.scaleVal < 0.6) return
39-
mind.scale(mind.scaleVal - 0.2)
39+
mind.scale(mind.scaleVal - mind.scaleSensitivity)
4040
}
4141
zi.onclick = () => {
4242
if (mind.scaleVal > 1.6) return
43-
mind.scale(mind.scaleVal + 0.2)
43+
mind.scale(mind.scaleVal + mind.scaleSensitivity)
4444
}
4545
return toolBarRBContainer
4646
}

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export interface Options {
137137
theme?: Theme
138138
selectionContainer?: string | HTMLElement
139139
alignment?: Alignment
140+
scaleSensitivity?: number
140141
}
141142

142143
export type Uid = string

0 commit comments

Comments
 (0)