-
Notifications
You must be signed in to change notification settings - Fork 0
/
testPenPath.js
134 lines (116 loc) · 2.72 KB
/
testPenPath.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//#!py
/**
* @import eventer SvgNodes
* @include setNodeChild
*/
const root = new SvgNodes.root({
width: '100%',
height: '100%',
})
setNodeChild(document.body, root.dom)
/**
* @include rotatePoint
*/
function getReverseCtrlPoint(p, ctrlPoint)
const offset = p.map((v, i)=> v - ctrlPoint[i])
return rotatePoint(offset, 180).map((v, i)=> p[i] + v)
/**
* @include addEvent createSvgNode setSvgNodeStyle
*/
const pathNode = new SvgNodes.path({
stroke: '#142bc1',
strokeWidth: 2,
})
root.append(pathNode)
const pathShodow = new SvgNodes.path({
stroke: '#788aff',
})
root.append(pathShodow)
const path = []
let lastCtrlPoint
eventer.on('tap', (e)=>{
let ctrlPoint
const lastPoint = getArrayValueByIndex(path, -1)
if lastPoint
if lastPoint.length > 2
ctrlPoint = getReverseCtrlPoint(lastPoint.slice(0, 2), lastPoint.slice(-2))
lastCtrlPoint = ctrlPoint
/**
* @include xyKeys
*/
const p = xyKeys.map(key=> e[key])
path.push(p)
if ctrlPoint
p.push(...ctrlPoint)
pathNode.path = path
pathNode.updateAttr('path', path)
console.log(path)
})
eventer.on('over', (e)=>{
/**
* @include xyKeys
*/
const p = xyKeys.map(key=> e[key])
if path.length
const lastPoint = getArrayValueByIndex(path, -1).slice(0, 2)
if lastCtrlPoint
p.push(...lastCtrlPoint)
pathShodow.path = [lastPoint.slice(0, 2), p]
console.log('over')
})
eventer.on('drag', {
dragstart(e, op){
/**
* @include xyKeys
*/
const p = xyKeys.map(key=> e[key])
// pathShodow.path.push(p)
// pathShodow.updateAttr('path', pathShodow.path)
// pathShodow.path = path.slice(-1).concat([p])
op.starts = getArrayValueByIndex(path, -1)
op.ends = p
ctrlPoint = null
// if path.length
// pathShodow.path = [path.slice(-1).concat([p])]
return true
},
drag(e, op){
/**
* @include xyKeys dragOffsetKeys rotatePoint getArrayValueByIndex
*/
if !pathShodow.path || pathShodow.path.length < 2
return
const {starts, ends} = op
const ctrlPoint1 = xyKeys.map(key=> e[key])
const ctrlPoint2 = rotatePoint(dragOffsetKeys.map(key=> e[key]), 180).map((v, i)=> ends[i] + v)
// const point = getArrayValueByIndex(path, -1)
// const point = ends.concat(p)
ends.splice(2, 2, ...ctrlPoint2)
pathShodow.ctrlPoint = ctrlPoint1
pathShodow.path = [
[
starts,
ends,
],
[
ctrlPoint1,
ctrlPoint2,
],
generateShapePath('circle', {
r: 2
}, true)
]
// console.log(point)
// pathShodow.path = [path.slice(-1).concat([p])]
// pathShodow.path = path.slice(-2)
// if path.length
// pathShodow.path = [path.slice(-1).concat([p])]
return true
},
dragend(e, op){
const {ends} = op
path.push(ends)
console.log('dragend', path)
pathNode.updateAttr('path', path)
},
})