123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /**
- * 不规则多边形,元空间
- */
- import SGraphyItem from '../SGraphyItem'
- import SRect from './../types/SRect';
- export default class SGraphyPolygonItem extends SGraphyItem {
- /**
- *
- * 构造函数
- *
- * @param jsonArr 空间线条数组
- * @param lineWidth 空间线条的宽度
- * @param color 空间线条的颜色
- * @param fillColor 空间的填充颜色
- *
- */
- constructor(jsonArr, lineWidth, color, fillColor, parent = null) {
- super(parent)
- this.jsonArr = jsonArr
- this.lineWidth = lineWidth
- this.color = color
- this.fillColor = fillColor
- } //constructor
- /**
- * Item的边界区域
- *
- * @return SRect
- */
- boundingRect() {
- return new SRect(0, 0, this.width, this.height)
- }
- /**
- * 绘制不规则多边形
- *
- * @param canvas 画布
- * @param rect 绘制区域
- */
- onDraw(canvas, rect) {
- if (this.jsonArr && this.jsonArr.length) {
- canvas.beginPath();
- canvas.lineWidth = this.lineWidth || 1
- canvas.strokeStyle = this.color || '#000'
- canvas.fillStyle = this.fillColor || '#fff'
- canvas.moveTo(this.jsonArr[0].X / 120 * -1, this.jsonArr[0].Y / 120)
- for (let i = 1; i < this.jsonArr.length - 1; i++) {
- canvas.lineTo(this.jsonArr[i].X / 120 * -1, this.jsonArr[i].Y / 120)
- }
- canvas.lineTo(this.jsonArr[0].X / 120 * -1, this.jsonArr[0].Y / 120)
- canvas.closePath()
- canvas.fill()
- canvas.stroke()
- }
- }
- }
|