|
@@ -24,41 +24,32 @@
|
|
* *********************************************************************************************************************
|
|
* *********************************************************************************************************************
|
|
*/
|
|
*/
|
|
|
|
|
|
-import { SGraphShape } from "./SGraphShape";
|
|
|
|
import { SGraphItem } from "../SGraphItem";
|
|
import { SGraphItem } from "../SGraphItem";
|
|
-import { SPainter, SRect,SColor } from "@persagy-web/draw";
|
|
|
|
-import { SGraphRect,SLineStyle } from "..";
|
|
|
|
|
|
+import { SPainter, SRect } from "@persagy-web/draw";
|
|
|
|
+import { SGraphStyleItem, SLineStyle } from "..";
|
|
|
|
+import { SPoint } from "@persagy-web/draw/lib";
|
|
|
|
|
|
/**
|
|
/**
|
|
* 矩形(包含圆角矩形) item
|
|
* 矩形(包含圆角矩形) item
|
|
*
|
|
*
|
|
* @author 郝洁 <haojie@persagy.com>
|
|
* @author 郝洁 <haojie@persagy.com>
|
|
*/
|
|
*/
|
|
-export class SGraphRectItem extends SGraphShape {
|
|
|
|
- /** item 宽 */
|
|
|
|
- private _width: number = 0;
|
|
|
|
- get width(): number {
|
|
|
|
- return this._width;
|
|
|
|
- }
|
|
|
|
- set width(v: number) {
|
|
|
|
- if (v == this._width) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- this._width = v;
|
|
|
|
- this.update();
|
|
|
|
- }
|
|
|
|
- /** item 高 */
|
|
|
|
- private _height: number = 0;
|
|
|
|
- get height(): number {
|
|
|
|
- return this._height;
|
|
|
|
- }
|
|
|
|
- set height(v: number) {
|
|
|
|
- if (v == this._height) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- this._height = v;
|
|
|
|
|
|
+export class SGraphRectItem extends SGraphStyleItem {
|
|
|
|
+ /** 矩形两个对角 */
|
|
|
|
+ private _line: SPoint[] = [];
|
|
|
|
+ get line(): SPoint[] {
|
|
|
|
+ return this._line;
|
|
|
|
+ }
|
|
|
|
+ set line(arr: SPoint[]) {
|
|
|
|
+ this._line = arr;
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /** 矩形左上角 */
|
|
|
|
+ private _leftTop: SPoint = new SPoint();
|
|
|
|
+ /** 矩形右下角 */
|
|
|
|
+ private _rightBottom: SPoint = new SPoint();
|
|
|
|
+
|
|
/** 绘制矩形的圆角半径 */
|
|
/** 绘制矩形的圆角半径 */
|
|
private _radius: number = 0;
|
|
private _radius: number = 0;
|
|
get radius(): number {
|
|
get radius(): number {
|
|
@@ -71,60 +62,21 @@ export class SGraphRectItem extends SGraphShape {
|
|
this._radius = v;
|
|
this._radius = v;
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
- /** 线条颜色 */
|
|
|
|
- _strokeColor: SColor = SColor.Black;
|
|
|
|
- get strokeColor(): SColor {
|
|
|
|
- return this._strokeColor;
|
|
|
|
- }
|
|
|
|
- set strokeColor(v: SColor) {
|
|
|
|
- this._strokeColor = v;
|
|
|
|
- this.update();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /** 填充色 */
|
|
|
|
- _fillColor: SColor = new SColor("#2196f3");
|
|
|
|
- get fillColor(): SColor {
|
|
|
|
- return this._fillColor;
|
|
|
|
- }
|
|
|
|
- set fillColor(v: SColor) {
|
|
|
|
- this._fillColor = v;
|
|
|
|
- this.update();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /** 边框样式 */
|
|
|
|
- _lineStyle: SLineStyle = SLineStyle.Solid;
|
|
|
|
- get lineStyle(): SLineStyle {
|
|
|
|
- return this._lineStyle;
|
|
|
|
- }
|
|
|
|
- set lineStyle(v: SLineStyle) {
|
|
|
|
- this._lineStyle = v;
|
|
|
|
- this.update();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /** 线条宽度 */
|
|
|
|
- _lineWidth: number = 1;
|
|
|
|
- get lineWidth(): number {
|
|
|
|
- return this._lineWidth;
|
|
|
|
- }
|
|
|
|
- set lineWidth(v: number) {
|
|
|
|
- this._lineWidth = v;
|
|
|
|
- this.update();
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 构造函数
|
|
* 构造函数
|
|
*
|
|
*
|
|
* @param parent 指向父对象
|
|
* @param parent 指向父对象
|
|
* @param data 矩形数据
|
|
* @param data 矩形数据
|
|
|
|
+ * @param radius 圆角半径
|
|
*/
|
|
*/
|
|
- constructor(parent: SGraphItem | null, data: SGraphRect) {
|
|
|
|
- super(parent, data.style);
|
|
|
|
- this.width = data.width;
|
|
|
|
- this.height = data.height;
|
|
|
|
- this.moveTo(data.x, data.y);
|
|
|
|
- if (data.radius && !isNaN(data.radius)) {
|
|
|
|
- this.radius = Number(data.radius);
|
|
|
|
|
|
+ constructor(parent: SGraphItem | null, data: SPoint[], radius: number = 0) {
|
|
|
|
+ super(parent);
|
|
|
|
+ if (data.length) {
|
|
|
|
+ this.line = data;
|
|
|
|
+ this.calRect();
|
|
}
|
|
}
|
|
|
|
+ this.radius = radius;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -133,20 +85,73 @@ export class SGraphRectItem extends SGraphShape {
|
|
* @return 边界区域
|
|
* @return 边界区域
|
|
*/
|
|
*/
|
|
boundingRect(): SRect {
|
|
boundingRect(): SRect {
|
|
- return new SRect(0, 0, this.width, this.height);
|
|
|
|
|
|
+ if (this.line.length > 1) {
|
|
|
|
+ return new SRect(this._leftTop, this._rightBottom);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new SRect();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 计算矩形的左上角和右下角
|
|
|
|
+ */
|
|
|
|
+ private calRect(): void {
|
|
|
|
+ if (this.line.length > 1) {
|
|
|
|
+ const fi = this.line[0];
|
|
|
|
+ const se = this.line[1];
|
|
|
|
+ let minx, maxx, miny, maxy;
|
|
|
|
+ if (fi.x < se.x) {
|
|
|
|
+ minx = fi.x;
|
|
|
|
+ maxx = se.x;
|
|
|
|
+ } else {
|
|
|
|
+ minx = se.x;
|
|
|
|
+ maxx = fi.x;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (fi.y < se.y) {
|
|
|
|
+ miny = fi.y;
|
|
|
|
+ maxy = se.y;
|
|
|
|
+ } else {
|
|
|
|
+ miny = se.y;
|
|
|
|
+ maxy = fi.y;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this._leftTop = new SPoint(minx, miny);
|
|
|
|
+ this._rightBottom = new SPoint(maxx, maxy);
|
|
|
|
+ }
|
|
|
|
+ } // Function calRect()
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 绘制
|
|
* 绘制
|
|
*
|
|
*
|
|
* @param painter 绘制对象
|
|
* @param painter 绘制对象
|
|
*/
|
|
*/
|
|
onDraw(painter: SPainter): void {
|
|
onDraw(painter: SPainter): void {
|
|
- super.onDraw(painter);
|
|
|
|
- if (this.radius != 0) {
|
|
|
|
- painter.drawRoundRect(0, 0, this.width, this.height, this.radius);
|
|
|
|
- } else {
|
|
|
|
- painter.drawRect(0, 0, this.width, this.height);
|
|
|
|
|
|
+ if (this.line.length == 2) {
|
|
|
|
+ painter.pen.color = this.strokeColor;
|
|
|
|
+ painter.brush.color = this.fillColor;
|
|
|
|
+ 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 * 2),
|
|
|
|
+ painter.toPx(this.lineWidth * 2)
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.radius != 0) {
|
|
|
|
+ painter.drawRoundRect(
|
|
|
|
+ this._leftTop,
|
|
|
|
+ this._rightBottom,
|
|
|
|
+ this.radius
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ painter.drawRect(this._leftTop, this._rightBottom);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|