refactoring
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
<path
|
<path
|
||||||
v-if="item.id !== currentId"
|
v-if="item.id !== currentId"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:d="item.d"
|
:d="item.path"
|
||||||
:id="`id-${item.id}`"
|
:id="`id-${item.id}`"
|
||||||
:stroke="item.color"
|
:stroke="item.color"
|
||||||
:stroke-width="item.size"
|
:stroke-width="item.size"
|
||||||
@@ -47,13 +47,10 @@ export default {
|
|||||||
color: '#000000',
|
color: '#000000',
|
||||||
size: 2,
|
size: 2,
|
||||||
currentId: uuid(),
|
currentId: uuid(),
|
||||||
ptdata: [],
|
points: [],
|
||||||
path: null,
|
path: null,
|
||||||
drawing: false,
|
drawing: false,
|
||||||
svg: null,
|
svg: null,
|
||||||
line: d3.line()
|
|
||||||
.x(d => d.x)
|
|
||||||
.y(d => d.y),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -66,7 +63,7 @@ export default {
|
|||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
this.path.attr('d', points => {
|
this.path.attr('d', points => {
|
||||||
const d = this.line(points)
|
const path = d3.line()(points)
|
||||||
const lines = this.node.attrs.lines.filter(item => item.id !== this.currentId)
|
const lines = this.node.attrs.lines.filter(item => item.id !== this.currentId)
|
||||||
|
|
||||||
this.updateAttributes({
|
this.updateAttributes({
|
||||||
@@ -76,24 +73,22 @@ export default {
|
|||||||
id: this.currentId,
|
id: this.currentId,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
size: this.size,
|
size: this.size,
|
||||||
d,
|
path,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
return d
|
return path
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
listen(event) {
|
listen(event) {
|
||||||
this.drawing = true
|
this.drawing = true
|
||||||
this.ptdata = []
|
this.points = []
|
||||||
|
|
||||||
this.path = this.svg
|
this.path = this.svg
|
||||||
.append('path')
|
.append('path')
|
||||||
.data([this.ptdata])
|
.data([this.points])
|
||||||
.attr('id', `id-${this.currentId}`)
|
.attr('id', `id-${this.currentId}`)
|
||||||
.attr('d', this.line)
|
|
||||||
.attr('stroke', this.color)
|
.attr('stroke', this.color)
|
||||||
.attr('stroke-width', this.size)
|
.attr('stroke-width', this.size)
|
||||||
|
|
||||||
@@ -113,20 +108,13 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.drawing = false
|
this.drawing = false
|
||||||
|
this.svg.select(`#id-${this.currentId}`).remove()
|
||||||
d3.select(this.$refs.canvas)
|
|
||||||
.select(`#id-${this.currentId}`)
|
|
||||||
.remove()
|
|
||||||
|
|
||||||
this.currentId = uuid()
|
this.currentId = uuid()
|
||||||
},
|
},
|
||||||
|
|
||||||
onmove(event) {
|
onmove(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
this.points.push(d3.pointers(event)[0])
|
||||||
const point = d3.pointers(event)[0]
|
|
||||||
|
|
||||||
this.ptdata.push({ x: point[0], y: point[1] })
|
|
||||||
this.tick()
|
this.tick()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user