jmgraph 3.2.27 → 3.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/jmgraph.core.min.js +1 -1
  2. package/dist/jmgraph.core.min.js.map +1 -1
  3. package/dist/jmgraph.js +2661 -415
  4. package/dist/jmgraph.min.js +1 -1
  5. package/package.json +1 -1
  6. package/src/core/jmControl.js +827 -127
  7. package/src/core/jmEvents.js +154 -0
  8. package/src/core/jmFilter.js +38 -1
  9. package/src/core/jmGradient.js +47 -2
  10. package/src/core/jmGraph.js +51 -7
  11. package/src/core/jmLayer.js +34 -2
  12. package/src/core/jmList.js +167 -0
  13. package/src/core/jmObject.js +128 -8
  14. package/src/core/jmPath.js +43 -5
  15. package/src/core/jmProperty.js +181 -2
  16. package/src/core/jmShadow.js +36 -7
  17. package/src/core/jmUtils.js +149 -12
  18. package/src/lib/webgl/base.js +211 -83
  19. package/src/lib/webgl/core/buffer.js +43 -12
  20. package/src/lib/webgl/core/mapSize.js +16 -7
  21. package/src/lib/webgl/core/mapType.js +41 -22
  22. package/src/lib/webgl/core/program.js +94 -54
  23. package/src/lib/webgl/core/shader.js +20 -8
  24. package/src/lib/webgl/core/texture.js +55 -32
  25. package/src/lib/webgl/gradient.js +49 -17
  26. package/src/lib/webgl/index.js +173 -24
  27. package/src/lib/webgl/path.js +61 -12
  28. package/src/shapes/jmArc.js +48 -2
  29. package/src/shapes/jmArrow.js +35 -2
  30. package/src/shapes/jmArrowLine.js +33 -2
  31. package/src/shapes/jmBezier.js +50 -4
  32. package/src/shapes/jmCircle.js +35 -2
  33. package/src/shapes/jmEllipse.js +29 -3
  34. package/src/shapes/jmHArc.js +39 -2
  35. package/src/shapes/jmImage.js +49 -3
  36. package/src/shapes/jmLabel.js +41 -2
  37. package/src/shapes/jmLine.js +42 -2
  38. package/src/shapes/jmPolygon.js +42 -3
  39. package/src/shapes/jmPrismatic.js +34 -2
  40. package/src/shapes/jmRect.js +45 -3
  41. package/src/shapes/jmResize.js +42 -4
  42. package/src/shapes/jmStar.js +38 -4
@@ -1,12 +1,39 @@
1
1
 
2
2
 
3
3
  /**
4
- * 采用webgl基础绘图
4
+ * @fileoverview WebGL 渲染上下文适配器
5
+ *
6
+ * 本模块提供了与 Canvas 2D API 兼容的 WebGL 接口,
7
+ * 使 jmGraph 能够无缝切换使用 Canvas 2D 或 WebGL 进行渲染。
8
+ *
9
+ * 主要功能:
10
+ * - 提供与 Canvas 2D Context 兼容的方法签名
11
+ * - 管理变换矩阵(平移、缩放、旋转)
12
+ * - 支持渐变创建
13
+ * - 文本测量支持
14
+ *
15
+ * @module lib/webgl
16
+ * @author jmGraph Team
5
17
  */
6
18
  import WebglBase from './base.js';
7
19
  import WebglPath from './path.js';
8
20
 
21
+ /**
22
+ * WebGL 渲染上下文适配器类
23
+ * 提供与 Canvas 2D Context 兼容的 API 接口
24
+ *
25
+ * @class webgl
26
+ * @example
27
+ * // 在 jmGraph 中使用
28
+ * const graph = new jmGraph(canvas, { mode: 'webgl' });
29
+ * // 内部会自动创建 webgl 实例作为 context
30
+ */
9
31
  class webgl {
32
+ /**
33
+ * 构造函数
34
+ * @param {WebGLRenderingContext} context WebGL 渲染上下文
35
+ * @param {Object} option 配置选项
36
+ */
10
37
  constructor(context, option) {
11
38
  this.option = option || {};
12
39
  this.context = context;
@@ -14,98 +41,187 @@ class webgl {
14
41
  this.base.context = context;
15
42
  }
16
43
 
17
- // 保存当前状态
44
+ /**
45
+ * 保存当前状态到状态栈
46
+ * @method save
47
+ */
18
48
  save() {
19
49
  this.base.save();
20
50
  }
21
51
 
22
- // 恢复上一个状态
52
+ /**
53
+ * 从状态栈恢复上一个状态
54
+ * @method restore
55
+ */
23
56
  restore() {
24
57
  this.base.restore();
25
58
  }
26
59
 
27
- // 平移变换
60
+ /**
61
+ * 平移变换
62
+ * @method translate
63
+ * @param {number} x X 轴平移量
64
+ * @param {number} y Y 轴平移量
65
+ */
28
66
  translate(x, y) {
29
67
  this.base.translate(x, y);
30
68
  }
31
69
 
32
- // 缩放变换
70
+ /**
71
+ * 缩放变换
72
+ * @method scale
73
+ * @param {number} sx X 轴缩放比例
74
+ * @param {number} sy Y 轴缩放比例
75
+ */
33
76
  scale(sx, sy) {
34
77
  this.base.scale(sx, sy);
35
78
  }
36
79
 
37
- // 旋转变换
80
+ /**
81
+ * 旋转变换
82
+ * @method rotate
83
+ * @param {number} angle 旋转角度(弧度)
84
+ */
38
85
  rotate(angle) {
39
86
  this.base.rotate(angle);
40
87
  }
41
88
 
42
- // 矩阵变换
89
+ /**
90
+ * 矩阵变换
91
+ * @method transform
92
+ * @param {number} a 水平缩放
93
+ * @param {number} b 垂直倾斜
94
+ * @param {number} c 水平倾斜
95
+ * @param {number} d 垂直缩放
96
+ * @param {number} e 水平移动
97
+ * @param {number} f 垂直移动
98
+ */
43
99
  transform(a, b, c, d, e, f) {
44
100
  this.base.transform(a, b, c, d, e, f);
45
101
  }
46
102
 
47
- // 开始路径
103
+ /**
104
+ * 开始路径(WebGL 中由具体绘制方法处理,此方法为空实现)
105
+ * @method beginPath
106
+ */
48
107
  beginPath() {
49
108
  // WebGL 中不需要 beginPath,由具体的绘制方法处理
50
109
  }
51
110
 
52
- // 关闭路径
111
+ /**
112
+ * 关闭路径(WebGL 中由具体绘制方法处理,此方法为空实现)
113
+ * @method closePath
114
+ */
53
115
  closePath() {
54
116
  // WebGL 中不需要 closePath,由具体的绘制方法处理
55
117
  }
56
118
 
57
- // 移动到指定点
119
+ /**
120
+ * 移动到指定点(WebGL 中由具体绘制方法处理,此方法为空实现)
121
+ * @method moveTo
122
+ * @param {number} x 目标点 X 坐标
123
+ * @param {number} y 目标点 Y 坐标
124
+ */
58
125
  moveTo(x, y) {
59
126
  // WebGL 中不需要 moveTo,由具体的绘制方法处理
60
127
  }
61
128
 
62
- // 绘制直线
129
+ /**
130
+ * 绘制直线到指定点(WebGL 中由具体绘制方法处理,此方法为空实现)
131
+ * @method lineTo
132
+ * @param {number} x 目标点 X 坐标
133
+ * @param {number} y 目标点 Y 坐标
134
+ */
63
135
  lineTo(x, y) {
64
136
  // WebGL 中不需要 lineTo,由具体的绘制方法处理
65
137
  }
66
138
 
67
- // 填充路径
139
+ /**
140
+ * 填充路径(WebGL 中由具体绘制方法处理,此方法为空实现)
141
+ * @method fill
142
+ */
68
143
  fill() {
69
144
  // WebGL 中不需要 fill,由具体的绘制方法处理
70
145
  }
71
146
 
72
- // 描边路径
147
+ /**
148
+ * 描边路径(WebGL 中由具体绘制方法处理,此方法为空实现)
149
+ * @method stroke
150
+ */
73
151
  stroke() {
74
152
  // WebGL 中不需要 stroke,由具体的绘制方法处理
75
153
  }
76
154
 
77
- // 清除矩形区域
155
+ /**
156
+ * 清除矩形区域
157
+ * @method clearRect
158
+ * @param {number} x 矩形左上角 X 坐标
159
+ * @param {number} y 矩形左上角 Y 坐标
160
+ * @param {number} width 矩形宽度
161
+ * @param {number} height 矩形高度
162
+ */
78
163
  clearRect(x, y, width, height) {
79
164
  this.context.clearColor(0, 0, 0, 0);
80
165
  this.context.clear(this.context.COLOR_BUFFER_BIT);
81
166
  }
82
167
 
83
- // 设置线条宽度
168
+ /**
169
+ * 设置线条宽度(由具体绘制方法处理)
170
+ * @method lineWidth
171
+ * @param {number} width 线条宽度
172
+ */
84
173
  lineWidth(width) {
85
174
  // 由具体的绘制方法处理
86
175
  }
87
176
 
88
- // 设置填充样式
177
+ /**
178
+ * 设置填充样式(由具体绘制方法处理)
179
+ * @method fillStyle
180
+ * @param {string|Object} style 填充样式
181
+ */
89
182
  fillStyle(style) {
90
183
  // 由具体的绘制方法处理
91
184
  }
92
185
 
93
- // 设置描边样式
186
+ /**
187
+ * 设置描边样式(由具体绘制方法处理)
188
+ * @method strokeStyle
189
+ * @param {string|Object} style 描边样式
190
+ */
94
191
  strokeStyle(style) {
95
192
  // 由具体的绘制方法处理
96
193
  }
97
194
 
98
- // 绘制文本
195
+ /**
196
+ * 绘制填充文本(由具体绘制方法处理)
197
+ * @method fillText
198
+ * @param {string} text 要绘制的文本
199
+ * @param {number} x 文本起始 X 坐标
200
+ * @param {number} y 文本起始 Y 坐标
201
+ * @param {number} [maxWidth] 最大宽度
202
+ */
99
203
  fillText(text, x, y, maxWidth) {
100
204
  // 由具体的绘制方法处理
101
205
  }
102
206
 
103
- // 描边文本
207
+ /**
208
+ * 绘制描边文本(由具体绘制方法处理)
209
+ * @method strokeText
210
+ * @param {string} text 要绘制的文本
211
+ * @param {number} x 文本起始 X 坐标
212
+ * @param {number} y 文本起始 Y 坐标
213
+ * @param {number} [maxWidth] 最大宽度
214
+ */
104
215
  strokeText(text, x, y, maxWidth) {
105
216
  // 由具体的绘制方法处理
106
217
  }
107
218
 
108
- // 测量文本宽度
219
+ /**
220
+ * 测量文本宽度
221
+ * @method measureText
222
+ * @param {string} text 要测量的文本
223
+ * @returns {TextMetrics} 文本测量结果,包含 width 属性
224
+ */
109
225
  measureText(text) {
110
226
  if(this.base && this.base._measureCtx) {
111
227
  return this.base._measureCtx.measureText(text);
@@ -113,22 +229,55 @@ class webgl {
113
229
  return { width: 15 };
114
230
  }
115
231
 
116
- // 创建线性渐变
232
+ /**
233
+ * 创建线性渐变
234
+ * @method createLinearGradient
235
+ * @param {number} x1 起点X坐标
236
+ * @param {number} y1 起点Y坐标
237
+ * @param {number} x2 终点X坐标
238
+ * @param {number} y2 终点Y坐标
239
+ * @param {Object} bounds 渐变边界 {left, top, width, height}
240
+ * @returns {WebglGradient} WebGL 渐变对象
241
+ */
117
242
  createLinearGradient(x1, y1, x2, y2, bounds) {
118
243
  return this.base.createLinearGradient(x1, y1, x2, y2, bounds);
119
244
  }
120
245
 
121
- // 创建径向渐变
246
+ /**
247
+ * 创建径向渐变
248
+ * @method createRadialGradient
249
+ * @param {number} x1 内圆中心X坐标
250
+ * @param {number} y1 内圆中心Y坐标
251
+ * @param {number} r1 内圆半径
252
+ * @param {number} x2 外圆中心X坐标
253
+ * @param {number} y2 外圆中心Y坐标
254
+ * @param {number} r2 外圆半径
255
+ * @param {Object} bounds 渐变边界 {left, top, width, height}
256
+ * @returns {WebglGradient} WebGL 渐变对象
257
+ */
122
258
  createRadialGradient(x1, y1, r1, x2, y2, r2, bounds) {
123
259
  return this.base.createRadialGradient(x1, y1, r1, x2, y2, r2, bounds);
124
260
  }
125
261
 
126
- // 绘制图像
262
+ /**
263
+ * 绘制图像(由具体绘制方法处理)
264
+ * @method drawImage
265
+ * @param {Image|HTMLImageElement} img 图像对象
266
+ * @param {number} dx 目标 X 坐标
267
+ * @param {number} dy 目标 Y 坐标
268
+ * @param {number} [dWidth] 目标宽度
269
+ * @param {number} [dHeight] 目标高度
270
+ */
127
271
  drawImage(img, dx, dy, dWidth, dHeight) {
128
272
  // 由具体的绘制方法处理
129
273
  }
130
274
 
131
- // 创建 WebglPath 实例
275
+ /**
276
+ * 创建 WebglPath 实例
277
+ * @method createPath
278
+ * @param {Object} option 路径配置选项
279
+ * @returns {WebglPath} WebGL 路径对象
280
+ */
132
281
  createPath(option) {
133
282
  return new WebglPath(null, option);
134
283
  }
@@ -1,22 +1,58 @@
1
+ /**
2
+ * @fileoverview WebGL 路径绘制类
3
+ *
4
+ * 本模块提供了 WebGL 路径绘制功能,包括:
5
+ * - 线条绘制(stroke)
6
+ * - 填充绘制(fill)
7
+ * - 纹理填充
8
+ * - 渐变填充
9
+ * - 文本绘制
10
+ * - 多边形三角化
11
+ *
12
+ * @module lib/webgl/path
13
+ * @author jmGraph Team
14
+ */
1
15
  import WebglBase, { MAX_STOPS } from './base.js';
2
16
  import earcut from '../earcut.js';
3
17
 
4
- // path 绘制类
18
+ /**
19
+ * WebGL 路径绘制类
20
+ * 继承自 WeblBase,提供路径绘制功能
21
+ *
22
+ * @class WebglPath
23
+ * @extends WeblBase
24
+ * @example
25
+ * const path = new WebglPath(graph, { isRegular: false, needCut: true });
26
+ * path.draw(points);
27
+ * path.stroke(points, '#ff0000', 2);
28
+ */
5
29
  class WebglPath extends WebglBase {
30
+ /**
31
+ * 构造函数
32
+ * @param {jmGraph} graph jmGraph 实例
33
+ * @param {Object} option 配置选项
34
+ * @param {boolean} [option.isRegular=false] 是否为规则图形(凸多边形)
35
+ * @param {boolean} [option.needCut=false] 是否需要切割处理
36
+ * @param {Object} [option.control] 控制器对象
37
+ */
6
38
  constructor(graph, option) {
7
39
  super(graph, option);
8
- // 是否是规则的,不规则的处理方式更为复杂和耗性能
40
+ /** @type {boolean} 是否为规则图形(凸多边形),规则图形处理更高效 */
9
41
  this.isRegular = option.isRegular || false;
42
+ /** @type {boolean} 是否需要切割处理 */
10
43
  this.needCut = option.needCut || false;
11
44
  this.control = option.control;
45
+ /** @type {Array<Object>} 路径点数组 */
12
46
  this.points = [];
13
- // 缓存 buffer 和纹理,避免每帧创建/销毁
47
+ /** @type {Array} 缓存的缓冲区,避免每帧创建/销毁 */
14
48
  this.__cachedBuffers = [];
49
+ /** @type {Object} 缓存的纹理 */
15
50
  this.__cachedTexture = null;
51
+ /** @type {string} 缓存纹理的 key */
16
52
  this.__cachedTextureKey = null;
17
53
  }
18
54
 
19
- // 释放缓存的 WebGL 资源
55
+ /** 释放缓存的 WebGL 资源 */
20
56
  dispose() {
21
57
  for(const buf of this.__cachedBuffers) {
22
58
  this.deleteBuffer(buf);
@@ -29,7 +65,12 @@ class WebglPath extends WebglBase {
29
65
  }
30
66
  }
31
67
 
32
- // 获取或创建 buffer,优先复用缓存
68
+ /**
69
+ * 获取或创建缓冲区,优先复用缓存
70
+ * @param {Array} data 数据数组
71
+ * @param {Object} attr 属性对象
72
+ * @returns {Object} 缓冲区对象
73
+ */
33
74
  getOrCreateBuffer(data, attr) {
34
75
  let buffer = this.__cachedBuffers.find(b => b.attr === attr);
35
76
  if(buffer) {
@@ -46,11 +87,19 @@ class WebglPath extends WebglBase {
46
87
  return buffer;
47
88
  }
48
89
 
49
- // 应用变换到点
90
+ /**
91
+ * 应用变换到点
92
+ * @param {Object} point 点坐标 {x, y}
93
+ * @returns {Object} 变换后的点坐标
94
+ */
50
95
  applyTransform(point) {
51
96
  return super.applyTransform(point);
52
97
  }
53
98
 
99
+ /**
100
+ * 设置父级边界
101
+ * @param {Object} [parentBounds] 父级边界 {left, top, width, height}
102
+ */
54
103
  setParentBounds(parentBounds = this.parentAbsoluteBounds) {
55
104
 
56
105
  //this.useProgram();
@@ -104,16 +153,16 @@ class WebglPath extends WebglBase {
104
153
  endDraw() {
105
154
  if(this.points) delete this.points;
106
155
  if(this.pathPoints) delete this.pathPoints;
156
+ this.needClose = false;
107
157
  // 缓存的纹理保留到下次绘制(渐变可能不变)
108
158
  }
109
159
 
110
- // 图形封闭
160
+ /**
161
+ * 标记路径需要闭合(不修改原始 points 数组)
162
+ * 闭合逻辑由 stroke/fill 绘制方法自行处理
163
+ */
111
164
  closePath() {
112
- if(this.points && this.points.length > 2 && this.points[0] !== this.points[this.points.length-1]) {
113
- const start = this.points[0];
114
- const end = this.points[this.points.length-1];
115
- if(start != end && !(start.x === end.x && start.y === end.y)) this.points.push(start);
116
- }
165
+ this.needClose = true;
117
166
  }
118
167
 
119
168
  // 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
@@ -1,11 +1,57 @@
1
+ /**
2
+ * @fileoverview jmArc 圆弧类
3
+ *
4
+ * jmArc 提供了圆弧图形的绘制功能。
5
+ * 可以绘制完整的圆、部分圆弧或扇形。
6
+ *
7
+ * 主要功能:
8
+ * - 圆弧绘制
9
+ * - 扇形绘制(isFan=true)
10
+ * - 顺时针/逆时针绘制
11
+ * - 支持 WebGL 和 Canvas 2D 模式
12
+ *
13
+ * @module jmArc
14
+ * @author jmGraph Team
15
+ * @license MIT
16
+ */
17
+
1
18
  import {jmPath} from "../core/jmPath.js";
2
19
 
3
20
  /**
4
- * 圆弧图型 继承自jmPath
21
+ * 圆弧类
22
+ *
23
+ * 绘制圆弧或扇形图形,继承自 jmPath。
24
+ * 支持设置圆心、半径、起始角度和结束角度。
5
25
  *
6
26
  * @class jmArc
7
27
  * @extends jmPath
8
- * @param {object} params center=当前圆弧中心,radius=圆弧半径,start=圆弧起始角度,end=圆弧结束角度,anticlockwise= false 顺时针,true 逆时针
28
+ * @param {object} params 圆弧参数
29
+ * @param {object} [params.center] 圆弧中心点 {x, y}
30
+ * @param {number} [params.radius] 圆弧半径
31
+ * @param {number} [params.start=0] 圆弧起始角度(弧度)
32
+ * @param {number} [params.end=Math.PI*2] 圆弧结束角度(弧度)
33
+ * @param {boolean} [params.anticlockwise=false] 绘制方向:false=顺时针,true=逆时针
34
+ * @param {boolean} [params.isFan=false] 是否绘制为扇形
35
+ *
36
+ * @example
37
+ * // 创建圆弧
38
+ * const arc = graph.createShape('arc', {
39
+ * center: {x: 200, y: 200},
40
+ * radius: 50,
41
+ * start: 0,
42
+ * end: Math.PI,
43
+ * style: { stroke: '#000' }
44
+ * });
45
+ *
46
+ * // 创建扇形
47
+ * const fan = graph.createShape('arc', {
48
+ * center: {x: 200, y: 200},
49
+ * radius: 50,
50
+ * start: 0,
51
+ * end: Math.PI / 2,
52
+ * isFan: true,
53
+ * style: { fill: '#ff0000' }
54
+ * });
9
55
  */
10
56
  export default class jmArc extends jmPath {
11
57
 
@@ -1,11 +1,44 @@
1
+ /**
2
+ * @fileoverview jmArrow 箭头类
3
+ *
4
+ * jmArrow 提供了箭头图形的绘制功能。
5
+ * 可以单独使用,也可以与直线组合使用。
6
+ *
7
+ * 主要功能:
8
+ * - 箭头绘制
9
+ * - 支持空心和实心箭头
10
+ * - 自定义箭头大小和角度
11
+ *
12
+ * @module jmArrow
13
+ * @author jmGraph Team
14
+ * @license MIT
15
+ */
16
+
1
17
  import {jmPath} from "../core/jmPath.js";
2
18
  import {jmUtils} from "../core/jmUtils.js";
19
+
3
20
  /**
4
- * 画箭头,继承自jmPath
21
+ * 箭头类
22
+ *
23
+ * 绘制箭头图形,支持空心和实心两种样式。
24
+ * 箭头方向由起点和终点决定。
5
25
  *
6
26
  * @class jmArrow
7
27
  * @extends jmPath
8
- * @param {object} 生成箭头所需的参数
28
+ * @param {object} params 箭头参数
29
+ * @param {object} [params.start] 箭头起始点 {x, y}
30
+ * @param {object} [params.end] 箭头终点(箭头尖端){x, y}
31
+ * @param {number} [params.angle] 箭头角度(弧度),不指定则自动计算
32
+ * @param {number} [params.offsetX=5] 箭头X方向偏移量
33
+ * @param {number} [params.offsetY=8] 箭头Y方向偏移量
34
+ *
35
+ * @example
36
+ * // 创建箭头
37
+ * const arrow = graph.createShape('arrow', {
38
+ * start: {x: 100, y: 100},
39
+ * end: {x: 200, y: 100},
40
+ * style: { fill: '#ff0000', stroke: '#000' }
41
+ * });
9
42
  */
10
43
  export default class jmArrow extends jmPath {
11
44
 
@@ -1,11 +1,42 @@
1
+ /**
2
+ * @fileoverview jmArrowLine 带箭头的直线类
3
+ *
4
+ * jmArrowLine 提供了带箭头直线的绘制功能。
5
+ * 继承自 jmLine,在直线末端添加箭头。
6
+ *
7
+ * 主要功能:
8
+ * - 带箭头的直线绘制
9
+ * - 支持虚线模式
10
+ * - 可控制箭头显示
11
+ *
12
+ * @module jmArrowLine
13
+ * @author jmGraph Team
14
+ * @license MIT
15
+ */
16
+
1
17
  import {jmLine} from "./jmLine.js";
2
18
  import {jmArrow} from "./jmArrow.js";
19
+
3
20
  /**
4
- * 带箭头的直线,继承jmPath
21
+ * 带箭头的直线类
22
+ *
23
+ * 绘制带箭头的直线,继承自 jmLine。
24
+ * 箭头位于直线的末端。
5
25
  *
6
26
  * @class jmArrowLine
7
27
  * @extends jmLine
8
- * @param {object} params 生成当前直线的参数对象,(style=当前线条样式,start=直线起始点,end=直线终结点)
28
+ * @param {object} params 直线参数
29
+ * @param {object} [params.start] 直线起始点 {x, y}
30
+ * @param {object} [params.end] 直线终结点 {x, y}
31
+ * @param {boolean} [params.arrowVisible=true] 是否显示箭头
32
+ *
33
+ * @example
34
+ * // 创建带箭头的直线
35
+ * const arrowLine = graph.createShape('arrowLine', {
36
+ * start: {x: 100, y: 100},
37
+ * end: {x: 200, y: 100},
38
+ * style: { stroke: '#000', lineWidth: 2 }
39
+ * });
9
40
  */
10
41
  export default class jmArrowLine extends jmLine {
11
42
 
@@ -1,17 +1,63 @@
1
+ /**
2
+ * @fileoverview jmBezier 贝塞尔曲线类
3
+ *
4
+ * jmBezier 提供了 N 阶贝塞尔曲线的绘制功能。
5
+ * 通过控制点定义曲线形状,支持任意阶数的贝塞尔曲线。
6
+ *
7
+ * 主要功能:
8
+ * - N 阶贝塞尔曲线
9
+ * - 控制点管理
10
+ * - 曲线平移
11
+ *
12
+ * @module jmBezier
13
+ * @author jmGraph Team
14
+ * @license MIT
15
+ */
16
+
1
17
  import {jmPath} from "../core/jmPath.js";
18
+
2
19
  /**
3
- * 贝塞尔曲线,继承jmPath
4
- * N阶,参数points中为控制点
20
+ * 贝塞尔曲线类
21
+ *
22
+ * 绘制 N 阶贝塞尔曲线,参数 points 中为控制点。
23
+ * 支持 2 阶(二次贝塞尔)、3 阶(三次贝塞尔)及更高阶曲线。
5
24
  *
6
25
  * @class jmBezier
7
26
  * @extends jmPath
8
27
  * @param {object} params 参数
28
+ * @param {array} [params.points] 控制点数组 [{x, y}, ...]
29
+ *
30
+ * @example
31
+ * // 创建二次贝塞尔曲线(3个控制点)
32
+ * const quadBezier = graph.createShape('bezier', {
33
+ * points: [
34
+ * {x: 100, y: 100}, // 起点
35
+ * {x: 200, y: 50}, // 控制点
36
+ * {x: 300, y: 100} // 终点
37
+ * ],
38
+ * style: { stroke: '#000', lineWidth: 2 }
39
+ * });
40
+ *
41
+ * // 创建三次贝塞尔曲线(4个控制点)
42
+ * const cubicBezier = graph.createShape('bezier', {
43
+ * points: [
44
+ * {x: 100, y: 100}, // 起点
45
+ * {x: 150, y: 50}, // 控制点1
46
+ * {x: 250, y: 50}, // 控制点2
47
+ * {x: 300, y: 100} // 终点
48
+ * ],
49
+ * style: { stroke: '#ff0000' }
50
+ * });
9
51
  */
10
52
  export default class jmBezier extends jmPath {
11
53
 
12
54
  constructor(params, t='jmBezier') {
13
- // 典线默认不封闭
14
- if(params.style && typeof params.style.close !== true) {
55
+ // 参数初始化
56
+ params = params || {};
57
+
58
+ // 曲线默认不封闭
59
+ if(!params.style) params.style = {};
60
+ if(typeof params.style.close !== true) {
15
61
  params.style.close = false;
16
62
  }
17
63
 
@@ -1,10 +1,43 @@
1
+ /**
2
+ * @fileoverview jmCircle 圆形类
3
+ *
4
+ * jmCircle 提供了圆形图形的绘制功能。
5
+ * 继承自 jmArc,可以绘制完整的圆或部分圆弧。
6
+ *
7
+ * 主要功能:
8
+ * - 圆形绘制
9
+ * - 支持填充和描边
10
+ * - 支持 WebGL 和 Canvas 2D 模式
11
+ *
12
+ * @module jmCircle
13
+ * @author jmGraph Team
14
+ * @license MIT
15
+ */
16
+
1
17
  import {jmArc} from "./jmArc.js";
18
+
2
19
  /**
3
- * 画规则的圆弧
20
+ * 圆形类
21
+ *
22
+ * 绘制圆形图形,继承自 jmArc。
23
+ * 可以通过 center 和 radius 指定圆心和半径,
24
+ * 也可以通过 width 和 height 指定圆的尺寸。
4
25
  *
5
26
  * @class jmCircle
6
27
  * @extends jmArc
7
- * @param {object} params 圆的参数:center=圆中心,radius=圆半径,优先取此属性,如果没有则取宽和高,width=圆宽,height=圆高
28
+ * @param {object} params 圆的参数
29
+ * @param {object} [params.center] 圆心坐标 {x, y}
30
+ * @param {number} [params.radius] 圆半径(优先使用)
31
+ * @param {number} [params.width] 圆宽度(无 radius 时使用)
32
+ * @param {number} [params.height] 圆高度(无 radius 时使用)
33
+ *
34
+ * @example
35
+ * // 创建圆形
36
+ * const circle = graph.createShape('circle', {
37
+ * center: {x: 200, y: 200},
38
+ * radius: 50,
39
+ * style: { fill: '#ff0000', stroke: '#000' }
40
+ * });
8
41
  */
9
42
  export default class jmCircle extends jmArc {
10
43