/* * ********************************************************************************************************************* * * !! * .F88X * X8888Y * .}888888N; * i888888N; .:! .I$WI: * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8& * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I * +888888N; .8888888Y "&&8Y.}8, * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$* * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~ * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi' * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/ * .:R888888I * .&888888I Copyright (c) 2009-2021. 博锐尚格科技股份有限公司 * ~8888' * .!88~ All rights reserved. * * ********************************************************************************************************************* */ import { SGraphItem, SGraphStyleItem, SLineStyle } from "@persagy-web/graph/lib"; import { SPoint, SPainter, SRect, SPath } from "@persagy-web/draw"; /** * 圆角折线 item * * @author 郝建龙 */ export default class SCircleCornerPolylineItem extends SGraphStyleItem { /** X 坐标最小值 */ private minX = Number.MAX_SAFE_INTEGER; /** X 坐标最大值 */ private maxX = Number.MIN_SAFE_INTEGER; /** Y 坐标最小值 */ private minY = Number.MAX_SAFE_INTEGER; /** Y 坐标最大值 */ private maxY = Number.MIN_SAFE_INTEGER; /** 折点信息 */ pointList: SPoint[] = []; /** 圆角半径 */ private _radius: number = 5; get radius(): number { return this._radius; } set radius(v: number) { if (v === this._radius) { return; } this._radius = v; this.update(); } /** 圆角半径是否需要转像素值 */ radiusIsPx: boolean = false; /** path 对象 */ path: SPath = new SPath(); /** * 构造函数 */ constructor(parent: SGraphItem | null, list: SPoint[]) { super(parent); this.pointList = list; } /** * Item 对象边界区域 * * @return 外接矩阵 */ boundingRect(): SRect { if (this.pointList.length) { this.minX = this.pointList[0].x; this.maxX = this.pointList[0].x; this.minY = this.pointList[0].y; this.maxY = this.pointList[0].y; this.pointList.forEach((it): void => { let x = it.x, y = it.y; // 如果数据 x 坐标小于 x 坐标最小值 if (x < this.minX) { this.minX = x; } // 如果数据 y 坐标小于 y 坐标最小值 if (y < this.minY) { this.minY = y; } // 如果数据 x 坐标大于 x 坐标最小值 if (x > this.maxX) { this.maxX = x; } // 如果数据 y 坐标大于 y 坐标最小值 if (y > this.maxY) { this.maxY = y; } }); } return new SRect( this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY ); } /** * 根据点集生成 path 对象 * * @param list 需要生成的点击 * @param r 拐点处圆角半径 */ generatePath(list: SPoint[], r: number = 0): void { const len = list.length; if (len) { this.path = new SPath(); this.path.moveTo(list[0].x, list[0].y); for (let i = 1; i < len - 1; i++) { const temp = list[i]; const next = list[i + 1]; this.path.arcTo(temp.x, temp.y, next.x, next.y, r); } const last = list[len - 1]; this.path.lineTo(last.x, last.y); } } /** * Item 绘制操作 * * @param painter 绘制对象 */ onDraw(painter: SPainter): void { // 绘制基本图形 painter.pen.color = this.strokeColor; // 线宽是否缩放 if (this.widthIsPx) { painter.pen.lineWidth = painter.toPx(this.lineWidth); } else { painter.pen.lineWidth = this.lineWidth; } // 虚线 if (this.lineStyle == SLineStyle.Dashed) { painter.pen.lineDash = [ painter.toPx(this.lineWidth * 3), painter.toPx(this.lineWidth * 7) ]; } else if (this.lineStyle == SLineStyle.Dotted) { // 点线 painter.pen.lineDash = [ painter.toPx(this.lineWidth), painter.toPx(this.lineWidth) ]; } const temp = JSON.parse(JSON.stringify(this.pointList)); // 折线点数2个以上 if (temp.length > 2) { let radius = this.radius; if (this.radiusIsPx) { radius = painter.toPx(this.radius); } this.generatePath(temp, radius); painter.drawPath(this.path); } else { // 否则 painter.drawPolyline(temp); } } }