-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
64 lines (47 loc) · 1.51 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
const panzoom = require('./')
const regl = require('regl')({ extensions: ['OES_element_index_uint'] })
const scatter = require('regl-scatter2d')(regl)
let range = [-10, -10, 10, 10]
let canvas = scatter.canvas
let inner = document.createElement('div')
document.body.appendChild(inner)
inner.setAttribute('style', 'background: rgba(200,200,210,.2); width: 20px; height: 20px; top: 30%; left: 40%; position: absolute;')
scatter({ points: [0,0, 1,1, 2,2], colors: ['red', 'green', 'blue'], range })
let destroy = panzoom(document.body, e => {
console.log(e)
let w = canvas.offsetWidth
let h = canvas.offsetHeight
let rx = e.x / w
let ry = e.y / h
let xrange = range[2] - range[0],
yrange = range[3] - range[1]
if (e.dz) {
let dz = e.dz / w
range[0] -= rx * xrange * dz
range[2] += (1 - rx) * xrange * dz
range[1] -= (1 - ry) * yrange * dz
range[3] += ry * yrange * dz
}
range[0] -= xrange * e.dx / w
range[2] -= xrange * e.dx / w
range[1] += yrange * e.dy / h
range[3] += yrange * e.dy / h
scatter({ range })
})
// test double init
// dest disabling interactions
let off = document.body.appendChild(document.createElement('button'))
Object.assign(off.style, {
position: 'absolute',
left: '50%',
width: '8rem',
lineHeight: '1.6rem',
marginLeft: '-4rem',
bottom: '2rem'
})
off.innerHTML = 'remove panzoom'
off.addEventListener('click', () => {
document.body.removeChild(off)
destroy()
})