Skip to content

Commit 2c6094e

Browse files
authored
Merge pull request #241 from JunoLab/sp/fixcanopyresize
fix pannable initial scale
2 parents b7679d9 + d71a3fd commit 2c6094e

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/plots/canopy.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,21 @@ export class Pannable extends Etch {
9696
}
9797

9898
readAfterUpdate () {
99-
this.containerRect =
100-
this.element.getElementsByClassName('ink-pannable')[0].getBoundingClientRect()
99+
this.innerContainerRect = this.refs.innerContainer.getBoundingClientRect()
100+
this.outerContainerRect = this.refs.outerContainer.getBoundingClientRect()
101+
101102
this.setInitialScale(this.item)
103+
102104
etch.update(this)
103105
}
104106

105107
setInitialScale (item) {
106108
this.initialScale = 1
107-
if (item.naturalHeight && item.naturalWidth && this.containerRect) {
109+
if (item.naturalHeight && item.naturalWidth && this.outerContainerRect) {
108110
// only scale down, not up:
109111
this.initialScale = Math.min(
110-
this.containerRect.width/item.naturalWidth,
111-
this.containerRect.height/item.naturalHeight,
112+
this.outerContainerRect.width/item.naturalWidth,
113+
this.outerContainerRect.height/item.naturalHeight,
112114
1
113115
)
114116
}
@@ -136,14 +138,14 @@ export class Pannable extends Etch {
136138

137139
this.scale *= zoom
138140

139-
if (this.containerRect) {
141+
if (this.innerContainerRect) {
140142
let x, y
141143
if (amount) {
142-
x = this.containerRect.width/2
143-
y = this.containerRect.height/2
144+
x = this.innerContainerRect.width/2
145+
y = this.innerContainerRect.height/2
144146
} else {
145-
x = clamp(e.clientX - this.containerRect.left, 0, this.containerRect.width)
146-
y = clamp(e.clientY - this.containerRect.top, 0, this.containerRect.height)
147+
x = clamp(e.clientX - this.innerContainerRect.left, 0, this.innerContainerRect.width)
148+
y = clamp(e.clientY - this.innerContainerRect.top, 0, this.innerContainerRect.height)
147149
}
148150

149151
this.left -= x*zoom - x
@@ -191,8 +193,9 @@ export class Pannable extends Etch {
191193
onmouseleave={e=>this.dragging=false}
192194
onmousemove={e=>this.ondrag(e)}
193195
onmousewheel={e=>this.zoom(e)}
194-
ondblclick={e=>this.resetAll()}>
195-
<div style={style} className='ink-pannable'>
196+
ondblclick={e=>this.resetAll()}
197+
ref='outerContainer'>
198+
<div style={style} className='ink-pannable' ref='innerContainer'>
196199
{toView(this.item)}
197200
</div>
198201
</div>;

0 commit comments

Comments
 (0)