|
@@ -1,4 +1,5 @@
|
|
|
import { SPoint } from "./index";
|
|
|
+import {SStringBuilder} from "@saga-web/base/lib";
|
|
|
|
|
|
/**
|
|
|
* Path对象
|
|
@@ -8,6 +9,14 @@ import { SPoint } from "./index";
|
|
|
export class SPath2D {
|
|
|
/** 内部path对象 */
|
|
|
_path = new Path2D();
|
|
|
+ private svgBuilder = new SStringBuilder();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * svg数据值
|
|
|
+ */
|
|
|
+ svgPath(): string {
|
|
|
+ return this.svgBuilder.toString(" ");
|
|
|
+ } // Function svgPath()
|
|
|
|
|
|
/**
|
|
|
* 添加路径
|
|
@@ -16,6 +25,7 @@ export class SPath2D {
|
|
|
*/
|
|
|
addPath(path: SPath2D): void {
|
|
|
this._path.addPath(path._path);
|
|
|
+ this.svgBuilder.append(path.svgBuilder.toString(" "))
|
|
|
} // Function addPath()
|
|
|
|
|
|
/**
|
|
@@ -26,6 +36,7 @@ export class SPath2D {
|
|
|
*/
|
|
|
moveTo(x: number, y: number): void {
|
|
|
this._path.moveTo(x, y);
|
|
|
+ this.svgBuilder.append(`M ${x} ${y}`);
|
|
|
} // Function moveTo()
|
|
|
|
|
|
/**
|
|
@@ -36,6 +47,7 @@ export class SPath2D {
|
|
|
*/
|
|
|
lineTo(x: number, y: number): void {
|
|
|
this._path.lineTo(x, y);
|
|
|
+ this.svgBuilder.append(`L ${x} ${y}`);
|
|
|
} // Function moveTo()
|
|
|
|
|
|
/**
|
|
@@ -53,13 +65,16 @@ export class SPath2D {
|
|
|
this._path.lineTo(r, y);
|
|
|
this._path.lineTo(r, b);
|
|
|
this._path.lineTo(x, b);
|
|
|
- this._path.lineTo(x, y);
|
|
|
- // 逆时针
|
|
|
- this._path.moveTo(x, y);
|
|
|
- this._path.lineTo(r, y);
|
|
|
- this._path.lineTo(r, b);
|
|
|
- this._path.lineTo(x, b);
|
|
|
- this._path.lineTo(x, y);
|
|
|
+ this._path.closePath();
|
|
|
+ this.svgBuilder.append(`M ${x} ${y} L${r} ${y} L${r} ${b} L${x} ${b} Z`);
|
|
|
+ // // 逆时针
|
|
|
+ // this._path.moveTo(x, y);
|
|
|
+ // this._path.lineTo(r, y);
|
|
|
+ // this._path.lineTo(r, b);
|
|
|
+ // this._path.lineTo(x, b);
|
|
|
+ // this._path.closePath();
|
|
|
+ // this.svgBuilder.append(`M ${x} ${y} L${r} ${y} L${} ${} L${} ${} L${} ${}`);
|
|
|
+
|
|
|
} // Function rect()
|
|
|
|
|
|
/**
|
|
@@ -74,8 +89,10 @@ export class SPath2D {
|
|
|
points.map((it: SPoint, index: number): void => {
|
|
|
if (index == 0) {
|
|
|
this._path.moveTo(it.x, it.y);
|
|
|
+ this.svgBuilder.append(`M ${it.x} ${it.y}`);
|
|
|
} else {
|
|
|
this._path.lineTo(it.x, it.y);
|
|
|
+ this.svgBuilder.append(`L ${it.x} ${it.y}`);
|
|
|
}
|
|
|
});
|
|
|
} // Function drawPolyline()
|
|
@@ -92,11 +109,14 @@ export class SPath2D {
|
|
|
points.map((it: SPoint, index: number): void => {
|
|
|
if (index == 0) {
|
|
|
this._path.moveTo(it.x, it.y);
|
|
|
+ this.svgBuilder.append(`M ${it.x} ${it.y}`);
|
|
|
} else {
|
|
|
this._path.lineTo(it.x, it.y);
|
|
|
+ this.svgBuilder.append(`L ${it.x} ${it.y}`);
|
|
|
}
|
|
|
});
|
|
|
- this._path.lineTo(points[0].x, points[0].y);
|
|
|
+ this._path.closePath();
|
|
|
+ this.svgBuilder.append(`Z`);
|
|
|
} // Functin polygon()
|
|
|
|
|
|
/**
|