2018-12-08 16:05:19 +08:00
|
|
|
export function drawLine (ctx, lineBegin, lineEnd, lineWidth = 2, lineColor = '#000', dashArray = [10, 10]) {
|
2018-12-07 15:50:10 +08:00
|
|
|
if (!ctx || !lineBegin || !lineEnd) return
|
|
|
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
|
|
|
ctx.moveTo(...lineBegin)
|
|
|
|
ctx.lineTo(...lineEnd)
|
|
|
|
|
|
|
|
ctx.closePath()
|
|
|
|
|
|
|
|
ctx.lineWidth = lineWidth
|
|
|
|
ctx.strokeStyle = lineColor
|
2018-12-08 16:05:19 +08:00
|
|
|
ctx.setLineDash(dashArray)
|
|
|
|
|
|
|
|
ctx.stroke()
|
|
|
|
}
|
|
|
|
|
2018-12-09 19:48:46 +08:00
|
|
|
export function drawPolyline (ctx, points, lineWidth = 2, lineColor = '#000', close = false, dashArray = [10, 0]) {
|
2018-12-08 16:05:19 +08:00
|
|
|
if (!ctx || !points.length) return
|
|
|
|
|
|
|
|
ctx.beginPath()
|
|
|
|
|
2018-12-09 19:48:46 +08:00
|
|
|
points.forEach((point, i) => i === 0 ? ctx.moveTo(...point) : ctx.lineTo(...point))
|
2018-12-08 16:05:19 +08:00
|
|
|
|
|
|
|
close && ctx.lineTo(...points[0])
|
|
|
|
|
|
|
|
ctx.lineWidth = lineWidth
|
|
|
|
ctx.strokeStyle = lineColor
|
|
|
|
ctx.setLineDash(dashArray)
|
2018-12-07 15:50:10 +08:00
|
|
|
|
|
|
|
ctx.stroke()
|
|
|
|
}
|
|
|
|
|
|
|
|
const canvas = {
|
2018-12-08 16:05:19 +08:00
|
|
|
drawLine,
|
|
|
|
drawPolyline
|
2018-12-07 15:50:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function (Vue) {
|
|
|
|
Vue.prototype.canvas = canvas
|
|
|
|
}
|