12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /**
- * 线条
- */
- import SGraphyItem from '../SGraphyItem'
- import SRect from './../types/SRect';
- export default class SGraphyLineItem extends SGraphyItem {
- /**
- * 构造函数
- *
- * @param startX 线的起始x坐标
- * @param startY 线的起始y坐标
- * @param endX 线的终止x坐标
- * @param endY 线的终止y坐标
- * @param width 线的宽度
- *
- * @param color 线的颜色
- * @param isVirtual 是否为虚线
- */
- constructor(startX, startY, endX, endY, color, width, isVirtual, parent = null) {
- super(parent)
- this.startX = startX
- this.startY = startY
- this.endX = endX
- this.endY = endY
- this.color = color
- this.width = width
- this.isVirtual = isVirtual
- }
- /**
- * Item对象边界区域
- *
- * @return SRect
- */
- boundingRect() {
- return new SRect(0, 0, this.width, this.height)
- }
- /**
- * 绘制线条
- *
- * @param canvas 画布
- * @param rect 绘制区域
- */
- onDraw(canvas, rect) {
- if (this.isVirtual) {
- canvas.setLineDash([15, 5])
- }
- canvas.lineWidth = this.width || 1
- canvas.strokeStyle = this.color || '#000'
- canvas.beginPath();
- canvas.moveTo(this.startX, this.startY)
- canvas.lineTo(this.endX, this.endY)
- canvas.stroke()
- }
- }
|