jmgraph 3.2.19 → 3.2.20

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 (55) hide show
  1. package/README.md +174 -2
  2. package/dist/jmgraph.core.min.js +1 -1
  3. package/dist/jmgraph.core.min.js.map +1 -1
  4. package/dist/jmgraph.js +1640 -135
  5. package/dist/jmgraph.min.js +1 -1
  6. package/index.js +13 -2
  7. package/package.json +1 -1
  8. package/src/core/jmGraph.js +453 -4
  9. package/src/core/jmLayer.js +142 -0
  10. package/src/core/jmPath.js +55 -0
  11. package/src/shapes/jmEllipse.js +91 -0
  12. package/src/shapes/jmLabel.js +127 -15
  13. package/src/shapes/jmPolygon.js +129 -0
  14. package/src/shapes/jmStar.js +160 -0
  15. package/example/ball.html +0 -217
  16. package/example/base.html +0 -112
  17. package/example/canvas.html +0 -54
  18. package/example/cell.html +0 -284
  19. package/example/controls/arc.html +0 -129
  20. package/example/controls/arrowline.html +0 -78
  21. package/example/controls/bezier.html +0 -299
  22. package/example/controls/img.html +0 -97
  23. package/example/controls/label.html +0 -87
  24. package/example/controls/line.html +0 -173
  25. package/example/controls/prismatic.html +0 -63
  26. package/example/controls/rect.html +0 -64
  27. package/example/controls/resize.html +0 -112
  28. package/example/controls/test.html +0 -360
  29. package/example/es.html +0 -70
  30. package/example/es5module.html +0 -63
  31. package/example/heartarc.html +0 -116
  32. package/example/index.html +0 -47
  33. package/example/js/require.js +0 -5
  34. package/example/love/img/bling/bling.tps +0 -265
  35. package/example/love/img/bling.json +0 -87
  36. package/example/love/img/bling.tps +0 -295
  37. package/example/love/img/doc/bling.gif +0 -0
  38. package/example/love/img/love.json +0 -95
  39. package/example/love/img/love.tps +0 -315
  40. package/example/love/img/qq/qq.tps +0 -399
  41. package/example/love/img/qq.json +0 -242
  42. package/example/love/index.html +0 -40
  43. package/example/love/js/game.js +0 -558
  44. package/example/music.html +0 -211
  45. package/example/node/test.js +0 -138
  46. package/example/pdf.html +0 -187
  47. package/example/progress.html +0 -173
  48. package/example/pso.html +0 -148
  49. package/example/sort.html +0 -805
  50. package/example/tweenjs.html +0 -84
  51. package/example/webgl.html +0 -278
  52. package/example/xfj/img/dr_die.gif +0 -0
  53. package/example/xfj/index.html +0 -332
  54. package/example/xfj/shake.js +0 -49
  55. package/example/xfj/testori.html +0 -76
package/dist/jmgraph.js CHANGED
@@ -78,6 +78,24 @@ Object.defineProperty(exports, "jmResize", {
78
78
  return _jmResize.jmResize;
79
79
  }
80
80
  });
81
+ Object.defineProperty(exports, "jmEllipse", {
82
+ enumerable: true,
83
+ get: function get() {
84
+ return _jmEllipse.jmEllipse;
85
+ }
86
+ });
87
+ Object.defineProperty(exports, "jmPolygon", {
88
+ enumerable: true,
89
+ get: function get() {
90
+ return _jmPolygon.jmPolygon;
91
+ }
92
+ });
93
+ Object.defineProperty(exports, "jmStar", {
94
+ enumerable: true,
95
+ get: function get() {
96
+ return _jmStar.jmStar;
97
+ }
98
+ });
81
99
  Object.defineProperty(exports, "jmUtils", {
82
100
  enumerable: true,
83
101
  get: function get() {
@@ -114,6 +132,12 @@ Object.defineProperty(exports, "jmPath", {
114
132
  return _jmGraph.jmPath;
115
133
  }
116
134
  });
135
+ Object.defineProperty(exports, "jmLayer", {
136
+ enumerable: true,
137
+ get: function get() {
138
+ return _jmGraph.jmLayer;
139
+ }
140
+ });
117
141
  exports.create = exports.jmGraph = exports["default"] = void 0;
118
142
 
119
143
  var _jmArc = require("./src/shapes/jmArc.js");
@@ -140,6 +164,12 @@ var _jmLabel = require("./src/shapes/jmLabel.js");
140
164
 
141
165
  var _jmResize = require("./src/shapes/jmResize.js");
142
166
 
167
+ var _jmEllipse = require("./src/shapes/jmEllipse.js");
168
+
169
+ var _jmPolygon = require("./src/shapes/jmPolygon.js");
170
+
171
+ var _jmStar = require("./src/shapes/jmStar.js");
172
+
143
173
  var _jmGraph = require("./src/core/jmGraph.js");
144
174
 
145
175
  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
@@ -177,7 +207,10 @@ var shapes = {
177
207
  "image": _jmImage.jmImage,
178
208
  "img": _jmImage.jmImage,
179
209
  "label": _jmLabel.jmLabel,
180
- "resize": _jmResize.jmResize
210
+ "resize": _jmResize.jmResize,
211
+ "ellipse": _jmEllipse.jmEllipse,
212
+ "polygon": _jmPolygon.jmPolygon,
213
+ "star": _jmStar.jmStar
181
214
  };
182
215
 
183
216
  var jmGraph = /*#__PURE__*/function (_jmGraphCore) {
@@ -233,7 +266,7 @@ var createJmGraph = function createJmGraph() {
233
266
 
234
267
  exports.create = createJmGraph;
235
268
 
236
- },{"./src/core/jmGraph.js":5,"./src/shapes/jmArc.js":22,"./src/shapes/jmArrow.js":23,"./src/shapes/jmArrowLine.js":24,"./src/shapes/jmBezier.js":25,"./src/shapes/jmCircle.js":26,"./src/shapes/jmHArc.js":27,"./src/shapes/jmImage.js":28,"./src/shapes/jmLabel.js":29,"./src/shapes/jmLine.js":30,"./src/shapes/jmPrismatic.js":31,"./src/shapes/jmRect.js":32,"./src/shapes/jmResize.js":33}],2:[function(require,module,exports){
269
+ },{"./src/core/jmGraph.js":5,"./src/shapes/jmArc.js":23,"./src/shapes/jmArrow.js":24,"./src/shapes/jmArrowLine.js":25,"./src/shapes/jmBezier.js":26,"./src/shapes/jmCircle.js":27,"./src/shapes/jmEllipse.js":28,"./src/shapes/jmHArc.js":29,"./src/shapes/jmImage.js":30,"./src/shapes/jmLabel.js":31,"./src/shapes/jmLine.js":32,"./src/shapes/jmPolygon.js":33,"./src/shapes/jmPrismatic.js":34,"./src/shapes/jmRect.js":35,"./src/shapes/jmResize.js":36,"./src/shapes/jmStar.js":37}],2:[function(require,module,exports){
237
270
  "use strict";
238
271
 
239
272
  Object.defineProperty(exports, "__esModule", {
@@ -1895,7 +1928,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1895
1928
  exports.jmControl = exports["default"] = jmControl;
1896
1929
  ;
1897
1930
 
1898
- },{"../lib/webgl/path.js":21,"./jmGradient.js":4,"./jmList.js":6,"./jmProperty.js":9,"./jmShadow.js":10,"./jmUtils.js":11}],3:[function(require,module,exports){
1931
+ },{"../lib/webgl/path.js":22,"./jmGradient.js":4,"./jmList.js":7,"./jmProperty.js":10,"./jmShadow.js":11,"./jmUtils.js":12}],3:[function(require,module,exports){
1899
1932
  "use strict";
1900
1933
 
1901
1934
  Object.defineProperty(exports, "__esModule", {
@@ -2169,7 +2202,7 @@ var jmKeyEvent = /*#__PURE__*/function () {
2169
2202
  return jmKeyEvent;
2170
2203
  }();
2171
2204
 
2172
- },{"./jmUtils.js":11}],4:[function(require,module,exports){
2205
+ },{"./jmUtils.js":12}],4:[function(require,module,exports){
2173
2206
  "use strict";
2174
2207
 
2175
2208
  Object.defineProperty(exports, "__esModule", {
@@ -2452,7 +2485,7 @@ var jmGradient = /*#__PURE__*/function () {
2452
2485
 
2453
2486
  exports.jmGradient = exports["default"] = jmGradient;
2454
2487
 
2455
- },{"./jmList.js":6,"./jmUtils.js":11}],5:[function(require,module,exports){
2488
+ },{"./jmList.js":7,"./jmUtils.js":12}],5:[function(require,module,exports){
2456
2489
  "use strict";
2457
2490
 
2458
2491
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -2508,6 +2541,12 @@ Object.defineProperty(exports, "jmPath", {
2508
2541
  return _jmPath.jmPath;
2509
2542
  }
2510
2543
  });
2544
+ Object.defineProperty(exports, "jmLayer", {
2545
+ enumerable: true,
2546
+ get: function get() {
2547
+ return _jmLayer.jmLayer;
2548
+ }
2549
+ });
2511
2550
  exports.jmGraph = exports["default"] = void 0;
2512
2551
 
2513
2552
  var _jmUtils = require("./jmUtils.js");
@@ -2526,6 +2565,8 @@ var _jmControl2 = require("./jmControl.js");
2526
2565
 
2527
2566
  var _jmPath = require("./jmPath.js");
2528
2567
 
2568
+ var _jmLayer = require("./jmLayer.js");
2569
+
2529
2570
  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
2530
2571
 
2531
2572
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
@@ -2597,7 +2638,13 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2597
2638
 
2598
2639
  _this.util = _this.utils = _jmUtils.jmUtils; // 模式 webgl | 2d
2599
2640
 
2600
- _this.mode = option.mode || '2d'; //如果是小程序
2641
+ _this.mode = option.mode || '2d'; // 缩放和平移相关
2642
+
2643
+ _this.scaleFactor = 1;
2644
+ _this.translation = {
2645
+ x: 0,
2646
+ y: 0
2647
+ }; //如果是小程序
2601
2648
 
2602
2649
  if (typeof wx != 'undefined' && wx.canIUse && wx.canIUse('canvas')) {
2603
2650
  if (typeof canvas === 'string') canvas = wx.createSelectorQuery().select('#' + canvas);
@@ -2683,14 +2730,24 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2683
2730
  */
2684
2731
 
2685
2732
  this.on('beginDraw', function () {
2686
- this.context.translate && this.context.translate(0.5, 0.5);
2733
+ this.context.translate && this.context.translate(0.5, 0.5); // 应用缩放和平移变换
2734
+
2735
+ if (this.context.translate && this.context.scale) {
2736
+ this.context.translate(this.translation.x, this.translation.y);
2737
+ this.context.scale(this.scaleFactor, this.scaleFactor);
2738
+ }
2687
2739
  });
2688
2740
  /**
2689
2741
  * 结束控件绘制 为了解决一像素线条问题
2690
2742
  */
2691
2743
 
2692
2744
  this.on('endDraw', function () {
2693
- this.context.translate && this.context.translate(-0.5, -0.5);
2745
+ this.context.translate && this.context.translate(-0.5, -0.5); // 恢复缩放和平移变换
2746
+
2747
+ if (this.context.translate && this.context.scale) {
2748
+ this.context.scale(1 / this.scaleFactor, 1 / this.scaleFactor);
2749
+ this.context.translate(-this.translation.x, -this.translation.y);
2750
+ }
2694
2751
  }); // devicePixelRatio初始化
2695
2752
 
2696
2753
  var dpr = typeof window != 'undefined' && window.devicePixelRatio > 1 ? window.devicePixelRatio : 1;
@@ -2845,7 +2902,9 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2845
2902
  if (shape) {
2846
2903
  if (!args) args = {};
2847
2904
  args.graph = this;
2848
- var obj = new shape(args);
2905
+ var obj = new shape(args); // 添加到活动图层
2906
+
2907
+ this.addShapeToLayer(obj);
2849
2908
  return obj;
2850
2909
  }
2851
2910
  }
@@ -3128,6 +3187,334 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3128
3187
 
3129
3188
  this.canvas.style && (this.canvas.style.transform = "scale(".concat(this.scaleSize.x, ", ").concat(this.scaleSize.y, ")"));
3130
3189
  }
3190
+ /**
3191
+ * 设置缩放因子
3192
+ * 支持以指定点为中心进行缩放,保持该点在屏幕上的位置不变
3193
+ *
3194
+ * @method setZoom
3195
+ * @param {number} zoom 缩放因子(建议范围:0.1 - 10)
3196
+ * @param {number} [x] 缩放中心X坐标(画布坐标)
3197
+ * @param {number} [y] 缩放中心Y坐标(画布坐标)
3198
+ * @return {jmGraph} 返回当前实例,支持链式调用
3199
+ */
3200
+
3201
+ }, {
3202
+ key: "setZoom",
3203
+ value: function setZoom(zoom, x, y) {
3204
+ // 参数验证
3205
+ if (typeof zoom !== 'number' || isNaN(zoom)) {
3206
+ console.warn('jmGraph: setZoom - 无效的缩放因子');
3207
+ return this;
3208
+ } // 限制缩放范围,防止过度缩放导致性能问题或显示异常
3209
+
3210
+
3211
+ var minZoom = 0.1; // 最小缩放到10%
3212
+
3213
+ var maxZoom = 10; // 最大放大到10倍
3214
+
3215
+ zoom = Math.max(minZoom, Math.min(maxZoom, zoom));
3216
+
3217
+ if (x !== undefined && y !== undefined) {
3218
+ // 计算缩放前后的坐标偏移
3219
+ // 保持缩放中心点在屏幕上的位置不变
3220
+ var oldZoom = this.scaleFactor;
3221
+ var newZoom = zoom; // 调整平移量以保持缩放中心位置不变
3222
+
3223
+ this.translation.x = x - (x - this.translation.x) * (newZoom / oldZoom);
3224
+ this.translation.y = y - (y - this.translation.y) * (newZoom / oldZoom);
3225
+ }
3226
+
3227
+ this.scaleFactor = zoom;
3228
+ this.needUpdate = true;
3229
+ this.redraw();
3230
+ return this; // 支持链式调用
3231
+ }
3232
+ /**
3233
+ * 平移画布
3234
+ * 移动画布视图,改变可视区域
3235
+ *
3236
+ * @method pan
3237
+ * @param {number} dx X轴平移量(像素)
3238
+ * @param {number} dy Y轴平移量(像素)
3239
+ * @return {jmGraph} 返回当前实例,支持链式调用
3240
+ */
3241
+
3242
+ }, {
3243
+ key: "pan",
3244
+ value: function pan(dx, dy) {
3245
+ // 参数验证
3246
+ if (typeof dx !== 'number' || typeof dy !== 'number' || isNaN(dx) || isNaN(dy)) {
3247
+ console.warn('jmGraph: pan - 无效的平移参数');
3248
+ return this;
3249
+ }
3250
+
3251
+ this.translation.x += dx;
3252
+ this.translation.y += dy;
3253
+ this.needUpdate = true;
3254
+ this.redraw();
3255
+ return this; // 支持链式调用
3256
+ }
3257
+ /**
3258
+ * 重置缩放和平移
3259
+ * 恢复画布到初始状态(缩放为1,平移为0)
3260
+ *
3261
+ * @method resetTransform
3262
+ * @return {jmGraph} 返回当前实例,支持链式调用
3263
+ */
3264
+
3265
+ }, {
3266
+ key: "resetTransform",
3267
+ value: function resetTransform() {
3268
+ this.scaleFactor = 1;
3269
+ this.translation = {
3270
+ x: 0,
3271
+ y: 0
3272
+ };
3273
+ this.needUpdate = true;
3274
+ this.redraw();
3275
+ return this; // 支持链式调用
3276
+ }
3277
+ /**
3278
+ * 初始化图层系统
3279
+ * 创建图层管理的基础结构,包括默认图层
3280
+ *
3281
+ * @method initLayers
3282
+ * @private
3283
+ */
3284
+
3285
+ }, {
3286
+ key: "initLayers",
3287
+ value: function initLayers() {
3288
+ if (!this.layers) {
3289
+ this.layers = new _jmList.jmList(); // 创建默认图层
3290
+
3291
+ var defaultLayer = this.createLayer('Default Layer');
3292
+ this.activeLayer = defaultLayer;
3293
+ }
3294
+ }
3295
+ /**
3296
+ * 创建新图层
3297
+ * 图层用于组织和管理图形对象,支持可见性和锁定控制
3298
+ *
3299
+ * @method createLayer
3300
+ * @param {string} name 图层名称(必须唯一)
3301
+ * @param {object} [options] 图层选项
3302
+ * @param {boolean} [options.visible=true] 图层是否可见
3303
+ * @param {boolean} [options.locked=false] 图层是否锁定(锁定后不可交互)
3304
+ * @return {jmLayer} 新创建的图层
3305
+ */
3306
+
3307
+ }, {
3308
+ key: "createLayer",
3309
+ value: function createLayer(name) {
3310
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3311
+
3312
+ // 参数验证
3313
+ if (!name || typeof name !== 'string') {
3314
+ console.warn('jmGraph: createLayer - 图层名称必须是非空字符串');
3315
+ name = "Layer_".concat(Date.now());
3316
+ }
3317
+
3318
+ this.initLayers(); // 检查图层名称是否已存在
3319
+
3320
+ var existingLayer = this.getLayer(name);
3321
+
3322
+ if (existingLayer) {
3323
+ console.warn("jmGraph: \u56FE\u5C42 \"".concat(name, "\" \u5DF2\u5B58\u5728\uFF0C\u5C06\u8FD4\u56DE\u73B0\u6709\u56FE\u5C42"));
3324
+ return existingLayer;
3325
+ }
3326
+
3327
+ var layer = new _jmLayer.jmLayer(_objectSpread({
3328
+ name: name,
3329
+ graph: this
3330
+ }, options));
3331
+ this.layers.add(layer);
3332
+ this.children.add(layer);
3333
+ this.needUpdate = true;
3334
+ return layer;
3335
+ }
3336
+ /**
3337
+ * 获取所有图层
3338
+ *
3339
+ * @method getLayers
3340
+ * @return {jmList} 图层列表
3341
+ */
3342
+
3343
+ }, {
3344
+ key: "getLayers",
3345
+ value: function getLayers() {
3346
+ this.initLayers();
3347
+ return this.layers;
3348
+ }
3349
+ /**
3350
+ * 根据名称获取图层
3351
+ *
3352
+ * @method getLayer
3353
+ * @param {string} name 图层名称
3354
+ * @return {jmLayer|null} 图层对象,如果不存在则返回null
3355
+ */
3356
+
3357
+ }, {
3358
+ key: "getLayer",
3359
+ value: function getLayer(name) {
3360
+ this.initLayers();
3361
+ if (!name) return null;
3362
+ var result = null;
3363
+ this.layers.each(function (i, layer) {
3364
+ if (layer.name === name) {
3365
+ result = layer;
3366
+ return false; // 找到后停止遍历
3367
+ }
3368
+ });
3369
+ return result;
3370
+ }
3371
+ /**
3372
+ * 设置活动图层
3373
+ * 新创建的图形将自动添加到活动图层
3374
+ *
3375
+ * @method setActiveLayer
3376
+ * @param {string|jmLayer} layer 图层名称或图层对象
3377
+ * @return {jmGraph} 返回当前实例,支持链式调用
3378
+ */
3379
+
3380
+ }, {
3381
+ key: "setActiveLayer",
3382
+ value: function setActiveLayer(layer) {
3383
+ this.initLayers(); // 支持传入图层名称或图层对象
3384
+
3385
+ if (typeof layer === 'string') {
3386
+ layer = this.getLayer(layer);
3387
+ }
3388
+
3389
+ if (!layer || !(layer instanceof _jmLayer.jmLayer)) {
3390
+ console.warn('jmGraph: setActiveLayer - 无效的图层');
3391
+ return this;
3392
+ }
3393
+
3394
+ this.activeLayer = layer;
3395
+ return this;
3396
+ }
3397
+ /**
3398
+ * 获取当前活动图层
3399
+ * 活动图层是新创建图形的默认容器
3400
+ *
3401
+ * @method getActiveLayer
3402
+ * @return {jmLayer} 当前活动图层
3403
+ */
3404
+
3405
+ }, {
3406
+ key: "getActiveLayer",
3407
+ value: function getActiveLayer() {
3408
+ this.initLayers();
3409
+ return this.activeLayer;
3410
+ }
3411
+ /**
3412
+ * 移除图层
3413
+ * 删除指定图层及其包含的所有图形
3414
+ * 注意:默认图层不可删除
3415
+ *
3416
+ * @method removeLayer
3417
+ * @param {string|jmLayer} layer 图层名称或图层对象
3418
+ * @return {boolean} 是否成功删除
3419
+ */
3420
+
3421
+ }, {
3422
+ key: "removeLayer",
3423
+ value: function removeLayer(layer) {
3424
+ this.initLayers(); // 支持传入图层名称或图层对象
3425
+
3426
+ if (typeof layer === 'string') {
3427
+ layer = this.getLayer(layer);
3428
+ }
3429
+
3430
+ if (!layer) {
3431
+ console.warn('jmGraph: removeLayer - 图层不存在');
3432
+ return false;
3433
+ } // 禁止删除默认图层
3434
+
3435
+
3436
+ if (layer.name === 'Default Layer') {
3437
+ console.warn('jmGraph: 不能删除默认图层');
3438
+ return false;
3439
+ } // 如果删除的是当前活动图层,切换到默认图层
3440
+
3441
+
3442
+ if (this.activeLayer === layer) {
3443
+ this.activeLayer = this.getLayer('Default Layer');
3444
+ }
3445
+
3446
+ this.layers.remove(layer);
3447
+ this.children.remove(layer);
3448
+ this.needUpdate = true;
3449
+ return true;
3450
+ }
3451
+ /**
3452
+ * 将形状添加到指定图层
3453
+ * 如果未指定图层,则添加到当前活动图层
3454
+ *
3455
+ * @method addShapeToLayer
3456
+ * @param {jmControl} shape 要添加的形状对象
3457
+ * @param {string|jmLayer} [layer] 图层名称或图层对象,默认为当前活动图层
3458
+ * @return {jmGraph} 返回当前实例,支持链式调用
3459
+ */
3460
+
3461
+ }, {
3462
+ key: "addShapeToLayer",
3463
+ value: function addShapeToLayer(shape, layer) {
3464
+ this.initLayers(); // 参数验证
3465
+
3466
+ if (!shape) {
3467
+ console.warn('jmGraph: addShapeToLayer - 无效的形状对象');
3468
+ return this;
3469
+ } // 确定目标图层
3470
+
3471
+
3472
+ if (!layer) {
3473
+ layer = this.activeLayer;
3474
+ } else if (typeof layer === 'string') {
3475
+ layer = this.getLayer(layer);
3476
+ }
3477
+
3478
+ if (!layer) {
3479
+ console.warn('jmGraph: addShapeToLayer - 图层不存在');
3480
+ return this;
3481
+ }
3482
+
3483
+ layer.children.add(shape);
3484
+ this.needUpdate = true;
3485
+ return this;
3486
+ }
3487
+ /**
3488
+ * 从图层中移除形状
3489
+ *
3490
+ * @method removeShapeFromLayer
3491
+ * @param {jmControl} shape 要移除的形状对象
3492
+ * @return {jmGraph} 返回当前实例,支持链式调用
3493
+ */
3494
+
3495
+ }, {
3496
+ key: "removeShapeFromLayer",
3497
+ value: function removeShapeFromLayer(shape) {
3498
+ var _this2 = this;
3499
+
3500
+ if (!shape) {
3501
+ console.warn('jmGraph: removeShapeFromLayer - 无效的形状对象');
3502
+ return this;
3503
+ } // 从所有图层中查找并移除
3504
+
3505
+
3506
+ if (this.layers) {
3507
+ this.layers.each(function (i, layer) {
3508
+ if (layer.children.contains(shape)) {
3509
+ layer.children.remove(shape);
3510
+ _this2.needUpdate = true;
3511
+ return false; // 找到后停止遍历
3512
+ }
3513
+ });
3514
+ }
3515
+
3516
+ return this;
3517
+ }
3131
3518
  /**
3132
3519
  * 保存为base64图形数据
3133
3520
  *
@@ -3141,6 +3528,145 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3141
3528
  var data = this.canvas.toDataURL ? this.canvas.toDataURL() : '';
3142
3529
  return data;
3143
3530
  }
3531
+ /**
3532
+ * 导出为PNG图片
3533
+ * 使用Canvas的toDataURL方法导出当前画布内容
3534
+ *
3535
+ * @method exportToPNG
3536
+ * @param {string} [fileName='jmgraph-export'] 文件名(不含扩展名)
3537
+ * @param {string} [format='image/png'] 图片格式,支持image/png和image/jpeg
3538
+ * @param {number} [quality=0.9] 图片质量(0-1之间,仅对JPEG格式有效)
3539
+ */
3540
+
3541
+ }, {
3542
+ key: "exportToPNG",
3543
+ value: function exportToPNG() {
3544
+ var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'jmgraph-export';
3545
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/png';
3546
+ var quality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.9;
3547
+
3548
+ try {
3549
+ // 确保画布已渲染
3550
+ this.redraw();
3551
+ var dataURL = this.canvas.toDataURL(format, quality);
3552
+ this.downloadFile(dataURL, fileName, 'png');
3553
+ } catch (error) {
3554
+ console.error('jmGraph: exportToPNG - 导出失败', error);
3555
+ }
3556
+ }
3557
+ /**
3558
+ * 导出为JPEG图片
3559
+ *
3560
+ * @method exportToJPEG
3561
+ * @param {string} [fileName='jmgraph-export'] 文件名(不含扩展名)
3562
+ * @param {number} [quality=0.9] 图片质量(0-1之间)
3563
+ */
3564
+
3565
+ }, {
3566
+ key: "exportToJPEG",
3567
+ value: function exportToJPEG() {
3568
+ var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'jmgraph-export';
3569
+ var quality = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.9;
3570
+ this.exportToPNG(fileName, 'image/jpeg', quality);
3571
+ }
3572
+ /**
3573
+ * 导出为SVG文件
3574
+ * 将当前画布内容转换为SVG格式
3575
+ * 注意:只有实现了toSVG方法的形状才能被导出
3576
+ *
3577
+ * @method exportToSVG
3578
+ * @param {string} [fileName='jmgraph-export'] 文件名(不含扩展名)
3579
+ */
3580
+
3581
+ }, {
3582
+ key: "exportToSVG",
3583
+ value: function exportToSVG() {
3584
+ var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'jmgraph-export';
3585
+
3586
+ try {
3587
+ var svg = this.toSVG();
3588
+ var blob = new Blob([svg], {
3589
+ type: 'image/svg+xml;charset=utf-8'
3590
+ });
3591
+ var url = URL.createObjectURL(blob);
3592
+ this.downloadFile(url, fileName, 'svg'); // 释放URL对象,避免内存泄漏
3593
+
3594
+ setTimeout(function () {
3595
+ return URL.revokeObjectURL(url);
3596
+ }, 100);
3597
+ } catch (error) {
3598
+ console.error('jmGraph: exportToSVG - 导出失败', error);
3599
+ }
3600
+ }
3601
+ /**
3602
+ * 转换为SVG字符串
3603
+ * 遍历所有图层和形状,生成SVG标记
3604
+ *
3605
+ * @method toSVG
3606
+ * @return {string} SVG字符串
3607
+ */
3608
+
3609
+ }, {
3610
+ key: "toSVG",
3611
+ value: function toSVG() {
3612
+ // SVG头部,包含命名空间和画布尺寸
3613
+ var svg = "<svg width=\"".concat(this.width, "\" height=\"").concat(this.height, "\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ").concat(this.width, " ").concat(this.height, "\">"); // 添加背景色(如果有)
3614
+
3615
+ if (this.style && this.style.fill) {
3616
+ svg += "<rect width=\"100%\" height=\"100%\" fill=\"".concat(this.style.fill, "\"/>");
3617
+ } // 遍历所有图层
3618
+
3619
+
3620
+ if (this.layers) {
3621
+ this.layers.each(function (i, layer) {
3622
+ if (layer.visible) {
3623
+ // 添加图层组,方便管理
3624
+ svg += "<g id=\"".concat(layer.name, "\" opacity=\"").concat(layer.opacity || 1, "\">"); // 遍历图层中的所有形状
3625
+
3626
+ layer.children.each(function (j, shape) {
3627
+ if (shape.toSVG) {
3628
+ svg += shape.toSVG();
3629
+ }
3630
+ });
3631
+ svg += '</g>';
3632
+ }
3633
+ });
3634
+ } else {
3635
+ // 遍历直接添加的形状(兼容没有图层系统的情况)
3636
+ this.children.each(function (i, shape) {
3637
+ if (shape.toSVG) {
3638
+ svg += shape.toSVG();
3639
+ }
3640
+ });
3641
+ }
3642
+
3643
+ svg += '</svg>';
3644
+ return svg;
3645
+ }
3646
+ /**
3647
+ * 下载文件
3648
+ * 创建临时链接元素触发浏览器下载
3649
+ *
3650
+ * @method downloadFile
3651
+ * @private
3652
+ * @param {string} url 文件URL或Data URL
3653
+ * @param {string} fileName 文件名(不含扩展名)
3654
+ * @param {string} extension 文件扩展名
3655
+ */
3656
+
3657
+ }, {
3658
+ key: "downloadFile",
3659
+ value: function downloadFile(url, fileName, extension) {
3660
+ // 创建临时链接元素
3661
+ var link = document.createElement('a');
3662
+ link.href = url;
3663
+ link.download = "".concat(fileName, ".").concat(extension); // 添加到DOM并触发点击
3664
+
3665
+ document.body.appendChild(link);
3666
+ link.click(); // 清理DOM
3667
+
3668
+ document.body.removeChild(link);
3669
+ }
3144
3670
  /**
3145
3671
  * 自动刷新画版
3146
3672
  * @param {function} callback 执行回调
@@ -3196,15 +3722,17 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3196
3722
 
3197
3723
  exports.jmGraph = exports["default"] = jmGraph;
3198
3724
 
3199
- },{"./jmControl.js":2,"./jmEvents.js":3,"./jmGradient.js":4,"./jmList.js":6,"./jmPath.js":8,"./jmProperty.js":9,"./jmShadow.js":10,"./jmUtils.js":11}],6:[function(require,module,exports){
3725
+ },{"./jmControl.js":2,"./jmEvents.js":3,"./jmGradient.js":4,"./jmLayer.js":6,"./jmList.js":7,"./jmPath.js":9,"./jmProperty.js":10,"./jmShadow.js":11,"./jmUtils.js":12}],6:[function(require,module,exports){
3200
3726
  "use strict";
3201
3727
 
3728
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3729
+
3202
3730
  Object.defineProperty(exports, "__esModule", {
3203
3731
  value: true
3204
3732
  });
3205
- exports.jmList = exports["default"] = void 0;
3733
+ exports.jmLayer = exports["default"] = void 0;
3206
3734
 
3207
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3735
+ var _jmControl2 = require("./jmControl.js");
3208
3736
 
3209
3737
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3210
3738
 
@@ -3212,28 +3740,234 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
3212
3740
 
3213
3741
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
3214
3742
 
3743
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
3744
+
3745
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
3746
+
3215
3747
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
3216
3748
 
3749
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3750
+
3217
3751
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
3218
3752
 
3219
3753
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
3220
3754
 
3221
3755
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
3222
3756
 
3223
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
3224
-
3225
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
3226
-
3227
3757
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
3228
3758
 
3229
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
3230
-
3231
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3232
-
3233
3759
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
3234
3760
 
3235
- var jmList = /*#__PURE__*/function (_Array) {
3236
- _inherits(jmList, _Array);
3761
+ /**
3762
+ * 图层类
3763
+ * 用于组织和管理图形对象,支持可见性和锁定控制
3764
+ * 图层可以包含多个图形对象,并控制它们的显示和交互
3765
+ *
3766
+ * @class jmLayer
3767
+ * @extends jmControl
3768
+ * @param {object} params 图层参数
3769
+ * @param {string} [params.name] 图层名称,默认为 'Layer_${timestamp}'
3770
+ * @param {boolean} [params.visible=true] 图层是否可见
3771
+ * @param {boolean} [params.locked=false] 图层是否锁定(锁定后不可交互)
3772
+ * @param {jmGraph} [params.graph] 所属的画布对象
3773
+ */
3774
+ var jmLayer = /*#__PURE__*/function (_jmControl) {
3775
+ _inherits(jmLayer, _jmControl);
3776
+
3777
+ var _super = _createSuper(jmLayer);
3778
+
3779
+ function jmLayer(params) {
3780
+ var _this;
3781
+
3782
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmLayer';
3783
+
3784
+ _classCallCheck(this, jmLayer);
3785
+
3786
+ params = params || {};
3787
+ params.interactive = false; // 图层本身不响应交互事件
3788
+
3789
+ _this = _super.call(this, params, t);
3790
+ _this.name = params.name || "Layer_".concat(Date.now());
3791
+ _this.visible = params.visible !== false;
3792
+ _this.locked = params.locked || false;
3793
+ return _this;
3794
+ }
3795
+ /**
3796
+ * 图层名称
3797
+ * 图层的唯一标识符,用于查找和管理图层
3798
+ *
3799
+ * @property name
3800
+ * @type {string}
3801
+ */
3802
+
3803
+
3804
+ _createClass(jmLayer, [{
3805
+ key: "name",
3806
+ get: function get() {
3807
+ return this.property('name');
3808
+ },
3809
+ set: function set(v) {
3810
+ if (!v || typeof v !== 'string') {
3811
+ console.warn('jmLayer: name must be a non-empty string');
3812
+ return;
3813
+ }
3814
+
3815
+ return this.property('name', v);
3816
+ }
3817
+ /**
3818
+ * 图层是否可见
3819
+ * 不可见的图层不会被渲染,但仍然存在于图层列表中
3820
+ *
3821
+ * @property visible
3822
+ * @type {boolean}
3823
+ */
3824
+
3825
+ }, {
3826
+ key: "visible",
3827
+ get: function get() {
3828
+ return this.property('visible');
3829
+ },
3830
+ set: function set(v) {
3831
+ this.needUpdate = true;
3832
+ return this.property('visible', v);
3833
+ }
3834
+ /**
3835
+ * 图层是否锁定
3836
+ * 锁定的图层中的图形不可被选中或移动,但仍然可见
3837
+ * 适用于背景图层或参考图层
3838
+ *
3839
+ * @property locked
3840
+ * @type {boolean}
3841
+ */
3842
+
3843
+ }, {
3844
+ key: "locked",
3845
+ get: function get() {
3846
+ return this.property('locked');
3847
+ },
3848
+ set: function set(v) {
3849
+ return this.property('locked', v);
3850
+ }
3851
+ /**
3852
+ * 绘制图层
3853
+ * 只有可见的图层才会被绘制
3854
+ *
3855
+ * @method paint
3856
+ * @param {boolean} v 是否需要重绘
3857
+ */
3858
+
3859
+ }, {
3860
+ key: "paint",
3861
+ value: function paint(v) {
3862
+ if (this.visible !== false) {
3863
+ _get(_getPrototypeOf(jmLayer.prototype), "paint", this).call(this, v);
3864
+ }
3865
+ }
3866
+ /**
3867
+ * 检查点是否在图层内
3868
+ * 锁定的图层不会响应鼠标事件
3869
+ *
3870
+ * @method checkPoint
3871
+ * @param {object} p 坐标点 {x, y}
3872
+ * @param {number} [pad] padding,额外的检测范围
3873
+ * @return {boolean} 是否在图层内
3874
+ */
3875
+
3876
+ }, {
3877
+ key: "checkPoint",
3878
+ value: function checkPoint(p, pad) {
3879
+ // 锁定的图层不响应交互
3880
+ if (this.locked) return false;
3881
+ return _get(_getPrototypeOf(jmLayer.prototype), "checkPoint", this).call(this, p, pad);
3882
+ }
3883
+ /**
3884
+ * 清空图层
3885
+ * 移除图层中的所有图形对象
3886
+ *
3887
+ * @method clear
3888
+ */
3889
+
3890
+ }, {
3891
+ key: "clear",
3892
+ value: function clear() {
3893
+ this.children.clear();
3894
+ this.needUpdate = true;
3895
+ }
3896
+ /**
3897
+ * 获取图层中的图形数量
3898
+ *
3899
+ * @method getShapeCount
3900
+ * @return {number} 图形数量
3901
+ */
3902
+
3903
+ }, {
3904
+ key: "getShapeCount",
3905
+ value: function getShapeCount() {
3906
+ return this.children.length;
3907
+ }
3908
+ /**
3909
+ * 获取图层信息
3910
+ * 返回图层的基本信息,用于调试和日志
3911
+ *
3912
+ * @method getInfo
3913
+ * @return {object} 图层信息对象
3914
+ */
3915
+
3916
+ }, {
3917
+ key: "getInfo",
3918
+ value: function getInfo() {
3919
+ return {
3920
+ name: this.name,
3921
+ visible: this.visible,
3922
+ locked: this.locked,
3923
+ shapeCount: this.getShapeCount()
3924
+ };
3925
+ }
3926
+ }]);
3927
+
3928
+ return jmLayer;
3929
+ }(_jmControl2.jmControl);
3930
+
3931
+ exports.jmLayer = exports["default"] = jmLayer;
3932
+
3933
+ },{"./jmControl.js":2}],7:[function(require,module,exports){
3934
+ "use strict";
3935
+
3936
+ Object.defineProperty(exports, "__esModule", {
3937
+ value: true
3938
+ });
3939
+ exports.jmList = exports["default"] = void 0;
3940
+
3941
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3942
+
3943
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3944
+
3945
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3946
+
3947
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
3948
+
3949
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
3950
+
3951
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
3952
+
3953
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
3954
+
3955
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
3956
+
3957
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
3958
+
3959
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
3960
+
3961
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
3962
+
3963
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
3964
+
3965
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3966
+
3967
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
3968
+
3969
+ var jmList = /*#__PURE__*/function (_Array) {
3970
+ _inherits(jmList, _Array);
3237
3971
 
3238
3972
  var _super = _createSuper(jmList);
3239
3973
 
@@ -3360,7 +4094,7 @@ var jmList = /*#__PURE__*/function (_Array) {
3360
4094
 
3361
4095
  exports.jmList = exports["default"] = jmList;
3362
4096
 
3363
- },{}],7:[function(require,module,exports){
4097
+ },{}],8:[function(require,module,exports){
3364
4098
  "use strict";
3365
4099
 
3366
4100
  Object.defineProperty(exports, "__esModule", {
@@ -3475,7 +4209,7 @@ var jmObject = /*#__PURE__*/function () {
3475
4209
 
3476
4210
  exports.jmObject = exports["default"] = jmObject;
3477
4211
 
3478
- },{"./jmList.js":6}],8:[function(require,module,exports){
4212
+ },{"./jmList.js":7}],9:[function(require,module,exports){
3479
4213
  "use strict";
3480
4214
 
3481
4215
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -3549,6 +4283,63 @@ var jmPath = /*#__PURE__*/function (_jmControl) {
3549
4283
  this.needUpdate = true;
3550
4284
  return this.property('points', v);
3551
4285
  }
4286
+ /**
4287
+ * 转换为SVG路径
4288
+ *
4289
+ * @method toSVG
4290
+ * @return {string} SVG路径字符串
4291
+ */
4292
+
4293
+ }, {
4294
+ key: "toSVG",
4295
+ value: function toSVG() {
4296
+ if (!this.points || this.points.length === 0) return '';
4297
+ var pathData = '';
4298
+ var points = this.points; // 移动到起点
4299
+
4300
+ pathData += "M ".concat(points[0].x, " ").concat(points[0].y); // 绘制路径
4301
+
4302
+ for (var i = 1; i < points.length; i++) {
4303
+ var p = points[i];
4304
+
4305
+ if (p.m) {
4306
+ // 移动到新位置
4307
+ pathData += " M ".concat(p.x, " ").concat(p.y);
4308
+ } else {
4309
+ // 直线到
4310
+ pathData += " L ".concat(p.x, " ").concat(p.y);
4311
+ }
4312
+ } // 如果是封闭路径
4313
+
4314
+
4315
+ if (this.style && this.style.close) {
4316
+ pathData += ' Z';
4317
+ } // 构建SVG元素
4318
+
4319
+
4320
+ var svg = '<path d="' + pathData + '"'; // 添加样式
4321
+
4322
+ if (this.style) {
4323
+ if (this.style.fill) {
4324
+ svg += ' fill="' + this.style.fill + '"';
4325
+ }
4326
+
4327
+ if (this.style.stroke) {
4328
+ svg += ' stroke="' + this.style.stroke + '"';
4329
+ }
4330
+
4331
+ if (this.style.lineWidth) {
4332
+ svg += ' stroke-width="' + this.style.lineWidth + '"';
4333
+ }
4334
+
4335
+ if (this.style.opacity) {
4336
+ svg += ' opacity="' + this.style.opacity + '"';
4337
+ }
4338
+ }
4339
+
4340
+ svg += '/>';
4341
+ return svg;
4342
+ }
3552
4343
  }]);
3553
4344
 
3554
4345
  return jmPath;
@@ -3556,7 +4347,7 @@ var jmPath = /*#__PURE__*/function (_jmControl) {
3556
4347
 
3557
4348
  exports.jmPath = exports["default"] = jmPath;
3558
4349
 
3559
- },{"./jmControl.js":2}],9:[function(require,module,exports){
4350
+ },{"./jmControl.js":2}],10:[function(require,module,exports){
3560
4351
  "use strict";
3561
4352
 
3562
4353
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -3682,7 +4473,7 @@ var jmProperty = /*#__PURE__*/function (_jmObject) {
3682
4473
 
3683
4474
  exports.jmProperty = exports["default"] = jmProperty;
3684
4475
 
3685
- },{"./jmObject.js":7,"./jmUtils.js":11}],10:[function(require,module,exports){
4476
+ },{"./jmObject.js":8,"./jmUtils.js":12}],11:[function(require,module,exports){
3686
4477
  "use strict";
3687
4478
 
3688
4479
  Object.defineProperty(exports, "__esModule", {
@@ -3775,7 +4566,7 @@ var jmShadow = /*#__PURE__*/function () {
3775
4566
 
3776
4567
  exports.jmShadow = exports["default"] = jmShadow;
3777
4568
 
3778
- },{"./jmUtils.js":11}],11:[function(require,module,exports){
4569
+ },{"./jmUtils.js":12}],12:[function(require,module,exports){
3779
4570
  "use strict";
3780
4571
 
3781
4572
  Object.defineProperty(exports, "__esModule", {
@@ -4777,7 +5568,7 @@ var jmUtils = /*#__PURE__*/function () {
4777
5568
 
4778
5569
  exports.jmUtils = exports["default"] = jmUtils;
4779
5570
 
4780
- },{"./jmList.js":6}],12:[function(require,module,exports){
5571
+ },{"./jmList.js":7}],13:[function(require,module,exports){
4781
5572
  'use strict';
4782
5573
 
4783
5574
  Object.defineProperty(exports, "__esModule", {
@@ -5440,7 +6231,7 @@ earcut.flatten = function (data) {
5440
6231
  return result;
5441
6232
  };
5442
6233
 
5443
- },{}],13:[function(require,module,exports){
6234
+ },{}],14:[function(require,module,exports){
5444
6235
  "use strict";
5445
6236
 
5446
6237
  Object.defineProperty(exports, "__esModule", {
@@ -6034,7 +6825,7 @@ var WeblBase = /*#__PURE__*/function () {
6034
6825
  var _default = WeblBase;
6035
6826
  exports["default"] = _default;
6036
6827
 
6037
- },{"../earcut.js":12,"./core/buffer.js":14,"./core/program.js":17,"./core/texture.js":19,"./gradient.js":20}],14:[function(require,module,exports){
6828
+ },{"../earcut.js":13,"./core/buffer.js":15,"./core/program.js":18,"./core/texture.js":20,"./gradient.js":21}],15:[function(require,module,exports){
6038
6829
  "use strict";
6039
6830
 
6040
6831
  Object.defineProperty(exports, "__esModule", {
@@ -6095,7 +6886,7 @@ function deleteBuffer(gl, buffer) {
6095
6886
  gl.deleteBuffer(buffer.buffer || buffer);
6096
6887
  }
6097
6888
 
6098
- },{}],15:[function(require,module,exports){
6889
+ },{}],16:[function(require,module,exports){
6099
6890
  "use strict";
6100
6891
 
6101
6892
  Object.defineProperty(exports, "__esModule", {
@@ -6133,7 +6924,7 @@ var mapSize = function mapSize(type) {
6133
6924
 
6134
6925
  exports.mapSize = mapSize;
6135
6926
 
6136
- },{}],16:[function(require,module,exports){
6927
+ },{}],17:[function(require,module,exports){
6137
6928
  "use strict";
6138
6929
 
6139
6930
  Object.defineProperty(exports, "__esModule", {
@@ -6176,7 +6967,7 @@ var mapType = function mapType(gl, type) {
6176
6967
 
6177
6968
  exports.mapType = mapType;
6178
6969
 
6179
- },{}],17:[function(require,module,exports){
6970
+ },{}],18:[function(require,module,exports){
6180
6971
  "use strict";
6181
6972
 
6182
6973
  Object.defineProperty(exports, "__esModule", {
@@ -6312,7 +7103,7 @@ function getUniformLocation(gl, program, name) {
6312
7103
  return gl.getUniformLocation(program, name);
6313
7104
  }
6314
7105
 
6315
- },{"./mapSize.js":15,"./mapType.js":16,"./shader.js":18}],18:[function(require,module,exports){
7106
+ },{"./mapSize.js":16,"./mapType.js":17,"./shader.js":19}],19:[function(require,module,exports){
6316
7107
  "use strict";
6317
7108
 
6318
7109
  Object.defineProperty(exports, "__esModule", {
@@ -6333,7 +7124,7 @@ function createShader(gl, type, src) {
6333
7124
  return shader;
6334
7125
  }
6335
7126
 
6336
- },{}],19:[function(require,module,exports){
7127
+ },{}],20:[function(require,module,exports){
6337
7128
  "use strict";
6338
7129
 
6339
7130
  Object.defineProperty(exports, "__esModule", {
@@ -6399,7 +7190,7 @@ function deleteTexture(gl, texture) {
6399
7190
  return gl.deleteTexture(texture);
6400
7191
  }
6401
7192
 
6402
- },{}],20:[function(require,module,exports){
7193
+ },{}],21:[function(require,module,exports){
6403
7194
  "use strict";
6404
7195
 
6405
7196
  Object.defineProperty(exports, "__esModule", {
@@ -6595,7 +7386,7 @@ var WebglGradient = /*#__PURE__*/function () {
6595
7386
  var _default = WebglGradient;
6596
7387
  exports["default"] = _default;
6597
7388
 
6598
- },{}],21:[function(require,module,exports){
7389
+ },{}],22:[function(require,module,exports){
6599
7390
  "use strict";
6600
7391
 
6601
7392
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -7319,7 +8110,7 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
7319
8110
  var _default = WebglPath;
7320
8111
  exports["default"] = _default;
7321
8112
 
7322
- },{"./base.js":13}],22:[function(require,module,exports){
8113
+ },{"./base.js":14}],23:[function(require,module,exports){
7323
8114
  "use strict";
7324
8115
 
7325
8116
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -7526,7 +8317,7 @@ var jmArc = /*#__PURE__*/function (_jmPath) {
7526
8317
 
7527
8318
  exports.jmArc = exports["default"] = jmArc;
7528
8319
 
7529
- },{"../core/jmPath.js":8}],23:[function(require,module,exports){
8320
+ },{"../core/jmPath.js":9}],24:[function(require,module,exports){
7530
8321
  "use strict";
7531
8322
 
7532
8323
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -7750,7 +8541,7 @@ var jmArrow = /*#__PURE__*/function (_jmPath) {
7750
8541
 
7751
8542
  exports.jmArrow = exports["default"] = jmArrow;
7752
8543
 
7753
- },{"../core/jmPath.js":8,"../core/jmUtils.js":11}],24:[function(require,module,exports){
8544
+ },{"../core/jmPath.js":9,"../core/jmUtils.js":12}],25:[function(require,module,exports){
7754
8545
  "use strict";
7755
8546
 
7756
8547
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -7844,7 +8635,7 @@ var jmArrowLine = /*#__PURE__*/function (_jmLine) {
7844
8635
 
7845
8636
  exports.jmArrowLine = exports["default"] = jmArrowLine;
7846
8637
 
7847
- },{"./jmArrow.js":23,"./jmLine.js":30}],25:[function(require,module,exports){
8638
+ },{"./jmArrow.js":24,"./jmLine.js":32}],26:[function(require,module,exports){
7848
8639
  "use strict";
7849
8640
 
7850
8641
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -8016,7 +8807,7 @@ var jmBezier = /*#__PURE__*/function (_jmPath) {
8016
8807
 
8017
8808
  exports.jmBezier = exports["default"] = jmBezier;
8018
8809
 
8019
- },{"../core/jmPath.js":8}],26:[function(require,module,exports){
8810
+ },{"../core/jmPath.js":9}],27:[function(require,module,exports){
8020
8811
  "use strict";
8021
8812
 
8022
8813
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -8146,7 +8937,7 @@ var jmCircle = /*#__PURE__*/function (_jmArc) {
8146
8937
 
8147
8938
  exports.jmCircle = exports["default"] = jmCircle;
8148
8939
 
8149
- },{"./jmArc.js":22}],27:[function(require,module,exports){
8940
+ },{"./jmArc.js":23}],28:[function(require,module,exports){
8150
8941
  "use strict";
8151
8942
 
8152
8943
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -8154,7 +8945,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
8154
8945
  Object.defineProperty(exports, "__esModule", {
8155
8946
  value: true
8156
8947
  });
8157
- exports.jmHArc = exports["default"] = void 0;
8948
+ exports.jmEllipse = exports["default"] = void 0;
8158
8949
 
8159
8950
  var _jmArc2 = require("./jmArc.js");
8160
8951
 
@@ -8164,6 +8955,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
8164
8955
 
8165
8956
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8166
8957
 
8958
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
8959
+
8960
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
8961
+
8167
8962
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
8168
8963
 
8169
8964
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
@@ -8178,91 +8973,237 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
8178
8973
 
8179
8974
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
8180
8975
 
8181
- /**
8182
- * 画空心圆弧,继承自jmPath
8183
- *
8184
- * @class jmHArc
8185
- * @extends jmArc
8186
- * @param {object} params 空心圆参数:minRadius=中心小圆半径,maxRadius=大圆半径,start=起始角度,end=结束角度,anticlockwise=false 顺时针,true 逆时针
8976
+ /**
8977
+ * 画椭圆
8978
+ * 椭圆是通过缩放圆形来实现的,支持完整的椭圆和椭圆弧
8979
+ * 可以指定起始角度和结束角度来绘制椭圆弧
8980
+ *
8981
+ * @class jmEllipse
8982
+ * @extends jmArc
8983
+ * @param {object} params 椭圆的参数
8984
+ * @param {object} [params.center={x:0,y:0}] 椭圆中心点坐标
8985
+ * @param {number} [params.width=100] 椭圆宽度(长轴直径)
8986
+ * @param {number} [params.height=60] 椭圆高度(短轴直径)
8987
+ * @param {number} [params.startAngle=0] 起始角度(弧度)
8988
+ * @param {number} [params.endAngle=Math.PI*2] 结束角度(弧度)
8989
+ * @param {boolean} [params.anticlockwise=false] 是否逆时针绘制
8187
8990
  */
8188
- var jmHArc = /*#__PURE__*/function (_jmArc) {
8189
- _inherits(jmHArc, _jmArc);
8190
-
8191
- var _super = _createSuper(jmHArc);
8991
+ var jmEllipse = /*#__PURE__*/function (_jmArc) {
8992
+ _inherits(jmEllipse, _jmArc);
8192
8993
 
8193
- function jmHArc(params) {
8194
- var _this;
8994
+ var _super = _createSuper(jmEllipse);
8195
8995
 
8196
- var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmHArc';
8996
+ function jmEllipse(params) {
8997
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmEllipse';
8197
8998
 
8198
- _classCallCheck(this, jmHArc);
8999
+ _classCallCheck(this, jmEllipse);
8199
9000
 
8200
- params.isRegular = true; // 规则的
9001
+ params = params || {};
9002
+ params.isRegular = true; // 标记为规则图形
8201
9003
 
8202
- params.needCut = true;
8203
- _this = _super.call(this, params, t);
8204
- _this.minRadius = params.minRadius || _this.style.minRadius || 0;
8205
- _this.maxRadius = params.maxRadius || _this.style.maxRadius || 0;
8206
- return _this;
9004
+ return _super.call(this, params, t);
8207
9005
  }
8208
- /**
8209
- * 设定或获取内空心圆半径
8210
- *
8211
- * @property minRadius
8212
- * @for jmHArc
8213
- * @type {number}
9006
+ /**
9007
+ * 初始化图形点
9008
+ * 为WebGL模式生成控制点,2D模式使用draw方法直接绘制
9009
+ *
9010
+ * @method initPoints
9011
+ * @private
9012
+ * @for jmEllipse
8214
9013
  */
8215
9014
 
8216
9015
 
8217
- _createClass(jmHArc, [{
8218
- key: "minRadius",
8219
- get: function get() {
8220
- return this.property('minRadius');
8221
- },
8222
- set: function set(v) {
8223
- this.needUpdate = true;
8224
- return this.property('minRadius', v);
8225
- }
8226
- /**
8227
- * 设定或获取外空心圆半径
8228
- *
8229
- * @property maxRadius
8230
- * @for jmHArc
8231
- * @type {number}
8232
- */
8233
-
8234
- }, {
8235
- key: "maxRadius",
8236
- get: function get() {
8237
- return this.property('maxRadius');
8238
- },
8239
- set: function set(v) {
8240
- this.needUpdate = true;
8241
- return this.property('maxRadius', v);
8242
- }
8243
- /**
8244
- * 初始化图形点
8245
- *
8246
- * @method initPoints
8247
- * @private
8248
- */
8249
-
8250
- }, {
9016
+ _createClass(jmEllipse, [{
8251
9017
  key: "initPoints",
8252
9018
  value: function initPoints() {
8253
- var location = this.getLocation(); //如果设定了半径。则以半径为主
8254
-
8255
- var minr = this.minRadius;
8256
- var maxr = this.maxRadius;
8257
- var start = this.startAngle;
8258
- var end = this.endAngle;
8259
- var anticlockwise = this.anticlockwise; //如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
9019
+ // WebGL模式使用父类的点生成方法
9020
+ if (this.graph.mode === 'webgl') {
9021
+ return _get(_getPrototypeOf(jmEllipse.prototype), "initPoints", this).call(this);
9022
+ } // 2D模式:生成4个控制点用于边界计算
9023
+ // 这些点不是实际的绘制点,而是用于碰撞检测和边界计算
8260
9024
 
8261
- if (anticlockwise) {
8262
- var p2 = Math.PI * 2;
8263
- start = p2 - start;
8264
- end = p2 - end;
8265
- }
9025
+
9026
+ var location = this.getLocation();
9027
+ this.points = [];
9028
+ this.points.push({
9029
+ x: location.center.x - location.width / 2,
9030
+ y: location.center.y
9031
+ }); // 左
9032
+
9033
+ this.points.push({
9034
+ x: location.center.x,
9035
+ y: location.center.y - location.height / 2
9036
+ }); // 上
9037
+
9038
+ this.points.push({
9039
+ x: location.center.x + location.width / 2,
9040
+ y: location.center.y
9041
+ }); // 右
9042
+
9043
+ this.points.push({
9044
+ x: location.center.x,
9045
+ y: location.center.y + location.height / 2
9046
+ }); // 下
9047
+ }
9048
+ /**
9049
+ * 重写基类画图,此处为画一个椭圆
9050
+ * 使用Canvas的变换功能(平移和缩放)来绘制椭圆
9051
+ *
9052
+ * @method draw
9053
+ */
9054
+
9055
+ }, {
9056
+ key: "draw",
9057
+ value: function draw() {
9058
+ // WebGL模式使用父类的绘制方法
9059
+ if (this.graph.mode === 'webgl') {
9060
+ return _get(_getPrototypeOf(jmEllipse.prototype), "draw", this).call(this);
9061
+ } // 获取边界和位置信息
9062
+
9063
+
9064
+ var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
9065
+ var location = this.getLocation(); // 获取椭圆弧参数
9066
+
9067
+ var start = this.startAngle || 0;
9068
+ var end = this.endAngle || Math.PI * 2;
9069
+ var anticlockwise = this.anticlockwise || false; // 椭圆绘制:通过变换圆形来实现
9070
+ // 1. 保存当前绘图状态
9071
+
9072
+ this.context.save(); // 2. 平移到椭圆中心
9073
+
9074
+ this.context.translate(location.center.x + bounds.left, location.center.y + bounds.top); // 3. 缩放坐标系,使圆形变为椭圆
9075
+ // 将X轴缩放width/2,Y轴缩放height/2,这样单位圆就变成了椭圆
9076
+
9077
+ this.context.scale(location.width / 2, location.height / 2); // 4. 绘制单位圆(会被缩放成椭圆)
9078
+
9079
+ this.context.arc(0, 0, 1, start, end, anticlockwise); // 5. 恢复绘图状态
9080
+
9081
+ this.context.restore();
9082
+ }
9083
+ }]);
9084
+
9085
+ return jmEllipse;
9086
+ }(_jmArc2.jmArc);
9087
+
9088
+ exports.jmEllipse = exports["default"] = jmEllipse;
9089
+
9090
+ },{"./jmArc.js":23}],29:[function(require,module,exports){
9091
+ "use strict";
9092
+
9093
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9094
+
9095
+ Object.defineProperty(exports, "__esModule", {
9096
+ value: true
9097
+ });
9098
+ exports.jmHArc = exports["default"] = void 0;
9099
+
9100
+ var _jmArc2 = require("./jmArc.js");
9101
+
9102
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9103
+
9104
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
9105
+
9106
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
9107
+
9108
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
9109
+
9110
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9111
+
9112
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9113
+
9114
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
9115
+
9116
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9117
+
9118
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
9119
+
9120
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
9121
+
9122
+ /**
9123
+ * 画空心圆弧,继承自jmPath
9124
+ *
9125
+ * @class jmHArc
9126
+ * @extends jmArc
9127
+ * @param {object} params 空心圆参数:minRadius=中心小圆半径,maxRadius=大圆半径,start=起始角度,end=结束角度,anticlockwise=false 顺时针,true 逆时针
9128
+ */
9129
+ var jmHArc = /*#__PURE__*/function (_jmArc) {
9130
+ _inherits(jmHArc, _jmArc);
9131
+
9132
+ var _super = _createSuper(jmHArc);
9133
+
9134
+ function jmHArc(params) {
9135
+ var _this;
9136
+
9137
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmHArc';
9138
+
9139
+ _classCallCheck(this, jmHArc);
9140
+
9141
+ params.isRegular = true; // 规则的
9142
+
9143
+ params.needCut = true;
9144
+ _this = _super.call(this, params, t);
9145
+ _this.minRadius = params.minRadius || _this.style.minRadius || 0;
9146
+ _this.maxRadius = params.maxRadius || _this.style.maxRadius || 0;
9147
+ return _this;
9148
+ }
9149
+ /**
9150
+ * 设定或获取内空心圆半径
9151
+ *
9152
+ * @property minRadius
9153
+ * @for jmHArc
9154
+ * @type {number}
9155
+ */
9156
+
9157
+
9158
+ _createClass(jmHArc, [{
9159
+ key: "minRadius",
9160
+ get: function get() {
9161
+ return this.property('minRadius');
9162
+ },
9163
+ set: function set(v) {
9164
+ this.needUpdate = true;
9165
+ return this.property('minRadius', v);
9166
+ }
9167
+ /**
9168
+ * 设定或获取外空心圆半径
9169
+ *
9170
+ * @property maxRadius
9171
+ * @for jmHArc
9172
+ * @type {number}
9173
+ */
9174
+
9175
+ }, {
9176
+ key: "maxRadius",
9177
+ get: function get() {
9178
+ return this.property('maxRadius');
9179
+ },
9180
+ set: function set(v) {
9181
+ this.needUpdate = true;
9182
+ return this.property('maxRadius', v);
9183
+ }
9184
+ /**
9185
+ * 初始化图形点
9186
+ *
9187
+ * @method initPoints
9188
+ * @private
9189
+ */
9190
+
9191
+ }, {
9192
+ key: "initPoints",
9193
+ value: function initPoints() {
9194
+ var location = this.getLocation(); //如果设定了半径。则以半径为主
9195
+
9196
+ var minr = this.minRadius;
9197
+ var maxr = this.maxRadius;
9198
+ var start = this.startAngle;
9199
+ var end = this.endAngle;
9200
+ var anticlockwise = this.anticlockwise; //如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
9201
+
9202
+ if (anticlockwise) {
9203
+ var p2 = Math.PI * 2;
9204
+ start = p2 - start;
9205
+ end = p2 - end;
9206
+ }
8266
9207
 
8267
9208
  var step = 0.1;
8268
9209
  if (start > end) step = -step;
@@ -8306,7 +9247,7 @@ var jmHArc = /*#__PURE__*/function (_jmArc) {
8306
9247
 
8307
9248
  exports.jmHArc = exports["default"] = jmHArc;
8308
9249
 
8309
- },{"./jmArc.js":22}],28:[function(require,module,exports){
9250
+ },{"./jmArc.js":23}],30:[function(require,module,exports){
8310
9251
  "use strict";
8311
9252
 
8312
9253
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -8608,7 +9549,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
8608
9549
 
8609
9550
  exports.jmImage = exports["default"] = jmImage;
8610
9551
 
8611
- },{"../core/jmControl.js":2}],29:[function(require,module,exports){
9552
+ },{"../core/jmControl.js":2}],31:[function(require,module,exports){
8612
9553
  "use strict";
8613
9554
 
8614
9555
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -8626,6 +9567,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
8626
9567
 
8627
9568
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8628
9569
 
9570
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
9571
+
9572
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9573
+
9574
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
9575
+
8629
9576
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8630
9577
 
8631
9578
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -8786,32 +9733,145 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
8786
9733
  }
8787
9734
  /**
8788
9735
  * 测试获取文本所占大小
8789
- *
9736
+ * 计算文本渲染所需的宽度和高度,支持自动换行
9737
+ *
8790
9738
  * @method testSize
8791
- * @return {object} 含文本大小的对象
9739
+ * @return {object} 含文本大小的对象 {width, height}
8792
9740
  */
8793
9741
 
8794
9742
  }, {
8795
9743
  key: "testSize",
8796
9744
  value: function testSize() {
9745
+ // 使用缓存提高性能,避免重复计算
8797
9746
  if (this.__size) return this.__size;
8798
- if (this.webglControl) this.__size = this.webglControl.testSize(this.text, this.style);else {
8799
- this.context.save && this.context.save(); // 修改字体,用来计算
9747
+
9748
+ if (this.webglControl) {
9749
+ this.__size = this.webglControl.testSize(this.text, this.style);
9750
+ } else {
9751
+ this.context.save && this.context.save(); // 设置字体样式用于测量
8800
9752
 
8801
9753
  this.setStyle({
8802
9754
  font: this.style.font || this.style.fontSize + 'px ' + this.style.fontFamily
8803
- }); //计算宽度
9755
+ }); // 计算文本尺寸
9756
+
9757
+ if (this.style.maxWidth && this.text) {
9758
+ // 文本换行处理
9759
+ var lines = this.wrapText(this.text, this.style.maxWidth);
9760
+ var maxWidth = 0; // 找出最宽的一行
9761
+
9762
+ var _iterator = _createForOfIteratorHelper(lines),
9763
+ _step;
9764
+
9765
+ try {
9766
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
9767
+ var line = _step.value;
9768
+ var width = this.context.measureText(line).width;
9769
+ if (width > maxWidth) maxWidth = width;
9770
+ } // 计算总高度(行数 × 行高)
9771
+
9772
+ } catch (err) {
9773
+ _iterator.e(err);
9774
+ } finally {
9775
+ _iterator.f();
9776
+ }
9777
+
9778
+ var lineHeight = this.style.lineHeight || this.style.fontSize * 1.2;
9779
+ this.__size = {
9780
+ width: maxWidth,
9781
+ height: lineHeight * lines.length
9782
+ };
9783
+ } else {
9784
+ // 单行文本
9785
+ this.__size = this.context.measureText ? this.context.measureText(this.text) : {
9786
+ width: 15
9787
+ };
9788
+ this.__size.height = this.style.fontSize ? this.style.fontSize : 15;
9789
+ }
8804
9790
 
8805
- this.__size = this.context.measureText ? this.context.measureText(this.text) : {
8806
- width: 15
8807
- };
8808
9791
  this.context.restore && this.context.restore();
8809
- this.__size.height = this.style.fontSize ? this.style.fontSize : 15;
8810
- }
9792
+ } // 设置默认宽高
9793
+
9794
+
8811
9795
  if (!this.width) this.width = this.__size.width;
8812
9796
  if (!this.height) this.height = this.__size.height;
8813
9797
  return this.__size;
8814
9798
  }
9799
+ /**
9800
+ * 文本换行处理
9801
+ * 根据最大宽度将文本分割成多行
9802
+ * 支持中英文混合文本,优先在空格处换行
9803
+ *
9804
+ * @method wrapText
9805
+ * @param {string} text 文本内容
9806
+ * @param {number} maxWidth 最大宽度(像素)
9807
+ * @return {array} 换行后的文本数组
9808
+ */
9809
+
9810
+ }, {
9811
+ key: "wrapText",
9812
+ value: function wrapText(text, maxWidth) {
9813
+ // 参数验证
9814
+ if (!text || !maxWidth) return [text || '']; // 检查缓存,避免重复计算
9815
+
9816
+ var cacheKey = "".concat(text, "_").concat(maxWidth);
9817
+
9818
+ if (this.__wrapTextCache && this.__wrapTextCache.key === cacheKey) {
9819
+ return this.__wrapTextCache.lines;
9820
+ }
9821
+
9822
+ var lines = []; // 先按换行符分割
9823
+
9824
+ var paragraphs = text.split('\n');
9825
+
9826
+ var _iterator2 = _createForOfIteratorHelper(paragraphs),
9827
+ _step2;
9828
+
9829
+ try {
9830
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
9831
+ var paragraph = _step2.value;
9832
+
9833
+ // 如果段落为空,添加空行
9834
+ if (!paragraph) {
9835
+ lines.push('');
9836
+ continue;
9837
+ } // 按空格分割单词
9838
+
9839
+
9840
+ var words = paragraph.split(' ');
9841
+ var currentLine = words[0];
9842
+
9843
+ for (var i = 1; i < words.length; i++) {
9844
+ var word = words[i];
9845
+ var testLine = currentLine + ' ' + word;
9846
+ var metrics = this.context.measureText(testLine);
9847
+ var testWidth = metrics.width;
9848
+
9849
+ if (testWidth <= maxWidth) {
9850
+ // 当前行还能容纳这个单词
9851
+ currentLine = testLine;
9852
+ } else {
9853
+ // 当前行已满,保存当前行并开始新行
9854
+ if (currentLine) lines.push(currentLine);
9855
+ currentLine = word;
9856
+ }
9857
+ } // 添加最后一行
9858
+
9859
+
9860
+ if (currentLine) lines.push(currentLine);
9861
+ } // 缓存结果
9862
+
9863
+ } catch (err) {
9864
+ _iterator2.e(err);
9865
+ } finally {
9866
+ _iterator2.f();
9867
+ }
9868
+
9869
+ this.__wrapTextCache = {
9870
+ key: cacheKey,
9871
+ lines: lines
9872
+ };
9873
+ return lines;
9874
+ }
8815
9875
  /**
8816
9876
  * 根据位置偏移画字符串
8817
9877
  *
@@ -8868,13 +9928,33 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
8868
9928
  this.webglControl.drawText(txt, x, y, location);
8869
9929
  } else if (this.style.fill && this.context.fillText) {
8870
9930
  if (this.style.maxWidth) {
8871
- this.context.fillText(txt, x, y, this.style.maxWidth);
9931
+ // 绘制换行文本
9932
+ var lines = this.wrapText(txt, this.style.maxWidth);
9933
+ var lineHeight = this.style.fontSize; // 调整起始Y位置以支持垂直对齐
9934
+
9935
+ var startY = y - (lines.length - 1) * lineHeight / 2;
9936
+
9937
+ for (var i = 0; i < lines.length; i++) {
9938
+ var lineY = startY + i * lineHeight;
9939
+ this.context.fillText(lines[i], x, lineY);
9940
+ }
8872
9941
  } else {
8873
9942
  this.context.fillText(txt, x, y);
8874
9943
  }
8875
9944
  } else if (this.context.strokeText) {
8876
9945
  if (this.style.maxWidth) {
8877
- this.context.strokeText(txt, x, y, this.style.maxWidth);
9946
+ // 绘制换行文本
9947
+ var _lines = this.wrapText(txt, this.style.maxWidth);
9948
+
9949
+ var _lineHeight = this.style.fontSize; // 调整起始Y位置以支持垂直对齐
9950
+
9951
+ var _startY = y - (_lines.length - 1) * _lineHeight / 2;
9952
+
9953
+ for (var _i = 0; _i < _lines.length; _i++) {
9954
+ var _lineY = _startY + _i * _lineHeight;
9955
+
9956
+ this.context.strokeText(_lines[_i], x, _lineY);
9957
+ }
8878
9958
  } else {
8879
9959
  this.context.strokeText(txt, x, y);
8880
9960
  }
@@ -8957,7 +10037,7 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
8957
10037
 
8958
10038
  exports.jmLabel = exports["default"] = jmLabel;
8959
10039
 
8960
- },{"../core/jmControl.js":2}],30:[function(require,module,exports){
10040
+ },{"../core/jmControl.js":2}],32:[function(require,module,exports){
8961
10041
  "use strict";
8962
10042
 
8963
10043
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -9112,7 +10192,203 @@ var jmLine = /*#__PURE__*/function (_jmPath) {
9112
10192
 
9113
10193
  exports.jmLine = exports["default"] = jmLine;
9114
10194
 
9115
- },{"../core/jmPath.js":8}],31:[function(require,module,exports){
10195
+ },{"../core/jmPath.js":9}],33:[function(require,module,exports){
10196
+ "use strict";
10197
+
10198
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
10199
+
10200
+ Object.defineProperty(exports, "__esModule", {
10201
+ value: true
10202
+ });
10203
+ exports.jmPolygon = exports["default"] = void 0;
10204
+
10205
+ var _jmPath2 = require("../core/jmPath.js");
10206
+
10207
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10208
+
10209
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
10210
+
10211
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
10212
+
10213
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10214
+
10215
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10216
+
10217
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10218
+
10219
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
10220
+
10221
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10222
+
10223
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10224
+
10225
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
10226
+
10227
+ /**
10228
+ * 画多边形
10229
+ * 支持规则多边形(正多边形)和自定义多边形
10230
+ * 规则多边形通过边数和半径自动计算顶点,自定义多边形通过顶点数组定义
10231
+ *
10232
+ * @class jmPolygon
10233
+ * @extends jmPath
10234
+ * @param {object} params 多边形的参数
10235
+ * @param {array} [params.points] 自定义顶点数组,如果提供则忽略sides和radius
10236
+ * @param {number} [params.sides=3] 多边形边数(3-100)
10237
+ * @param {number} [params.radius=50] 多边形半径(像素)
10238
+ * @param {object} [params.center={x:0,y:0}] 多边形中心点坐标
10239
+ */
10240
+ var jmPolygon = /*#__PURE__*/function (_jmPath) {
10241
+ _inherits(jmPolygon, _jmPath);
10242
+
10243
+ var _super = _createSuper(jmPolygon);
10244
+
10245
+ function jmPolygon(params) {
10246
+ var _params$points;
10247
+
10248
+ var _this;
10249
+
10250
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmPolygon';
10251
+
10252
+ _classCallCheck(this, jmPolygon);
10253
+
10254
+ params = params || {};
10255
+ params.isRegular = true; // 标记为规则图形,便于优化渲染
10256
+
10257
+ _this = _super.call(this, params, t); // 参数验证和初始化
10258
+
10259
+ _this.sides = params.sides || ((_params$points = params.points) === null || _params$points === void 0 ? void 0 : _params$points.length) || 3;
10260
+ _this.radius = params.radius || 50;
10261
+ _this.center = params.center || {
10262
+ x: 0,
10263
+ y: 0
10264
+ };
10265
+ return _this;
10266
+ }
10267
+ /**
10268
+ * 设定或获取多边形边数
10269
+ * 边数决定了多边形的形状,最小为3(三角形)
10270
+ *
10271
+ * @property sides
10272
+ * @for jmPolygon
10273
+ * @type {number}
10274
+ */
10275
+
10276
+
10277
+ _createClass(jmPolygon, [{
10278
+ key: "sides",
10279
+ get: function get() {
10280
+ return this.property('sides');
10281
+ },
10282
+ set: function set(v) {
10283
+ // 参数验证:边数必须在3-100之间
10284
+ if (typeof v !== 'number' || isNaN(v) || v < 3) {
10285
+ console.warn('jmPolygon: sides must be a number >= 3');
10286
+ v = 3;
10287
+ }
10288
+
10289
+ if (v > 100) {
10290
+ console.warn('jmPolygon: sides should not exceed 100 for performance reasons');
10291
+ v = 100;
10292
+ }
10293
+
10294
+ this.needUpdate = true;
10295
+ return this.property('sides', Math.floor(v)); // 确保是整数
10296
+ }
10297
+ /**
10298
+ * 设定或获取多边形半径
10299
+ * 半径是从中心点到顶点的距离
10300
+ *
10301
+ * @property radius
10302
+ * @for jmPolygon
10303
+ * @type {number}
10304
+ */
10305
+
10306
+ }, {
10307
+ key: "radius",
10308
+ get: function get() {
10309
+ return this.property('radius');
10310
+ },
10311
+ set: function set(v) {
10312
+ // 参数验证:半径必须为正数
10313
+ if (typeof v !== 'number' || isNaN(v) || v <= 0) {
10314
+ console.warn('jmPolygon: radius must be a positive number');
10315
+ v = 1;
10316
+ }
10317
+
10318
+ this.needUpdate = true;
10319
+ return this.property('radius', v);
10320
+ }
10321
+ /**
10322
+ * 设定或获取多边形中心
10323
+ * 中心点是多边形的几何中心
10324
+ *
10325
+ * @property center
10326
+ * @for jmPolygon
10327
+ * @type {object}
10328
+ */
10329
+
10330
+ }, {
10331
+ key: "center",
10332
+ get: function get() {
10333
+ return this.property('center');
10334
+ },
10335
+ set: function set(v) {
10336
+ // 参数验证:中心点必须包含x和y属性
10337
+ if (!v || typeof v.x !== 'number' || typeof v.y !== 'number') {
10338
+ console.warn('jmPolygon: center must be an object with x and y properties');
10339
+ v = {
10340
+ x: 0,
10341
+ y: 0
10342
+ };
10343
+ }
10344
+
10345
+ this.needUpdate = true;
10346
+ return this.property('center', v);
10347
+ }
10348
+ /**
10349
+ * 初始化图形点
10350
+ * 如果提供了自定义顶点,则使用自定义顶点
10351
+ * 否则根据边数和半径自动计算规则多边形的顶点
10352
+ *
10353
+ * @method initPoints
10354
+ * @private
10355
+ * @for jmPolygon
10356
+ */
10357
+
10358
+ }, {
10359
+ key: "initPoints",
10360
+ value: function initPoints() {
10361
+ // 如果提供了自定义顶点,直接使用
10362
+ if (this.points && this.points.length > 0) {
10363
+ return;
10364
+ } // 计算规则多边形的顶点
10365
+
10366
+
10367
+ var points = [];
10368
+ var sides = this.sides;
10369
+ var radius = this.radius;
10370
+ var center = this.center; // 从顶部开始绘制(-90度),顺时针方向
10371
+
10372
+ for (var i = 0; i < sides; i++) {
10373
+ var angle = i / sides * Math.PI * 2 - Math.PI / 2;
10374
+ var x = center.x + Math.cos(angle) * radius;
10375
+ var y = center.y + Math.sin(angle) * radius;
10376
+ points.push({
10377
+ x: x,
10378
+ y: y
10379
+ });
10380
+ }
10381
+
10382
+ this.points = points;
10383
+ }
10384
+ }]);
10385
+
10386
+ return jmPolygon;
10387
+ }(_jmPath2.jmPath);
10388
+
10389
+ exports.jmPolygon = exports["default"] = jmPolygon;
10390
+
10391
+ },{"../core/jmPath.js":9}],34:[function(require,module,exports){
9116
10392
  "use strict";
9117
10393
 
9118
10394
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -9232,7 +10508,7 @@ var jmPrismatic = /*#__PURE__*/function (_jmPath) {
9232
10508
 
9233
10509
  exports.jmPrismatic = exports["default"] = jmPrismatic;
9234
10510
 
9235
- },{"../core/jmPath.js":8}],32:[function(require,module,exports){
10511
+ },{"../core/jmPath.js":9}],35:[function(require,module,exports){
9236
10512
  "use strict";
9237
10513
 
9238
10514
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -9498,7 +10774,7 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
9498
10774
 
9499
10775
  exports.jmRect = exports["default"] = jmRect;
9500
10776
 
9501
- },{"../core/jmPath.js":8,"./jmArc.js":22,"./jmLine.js":30}],33:[function(require,module,exports){
10777
+ },{"../core/jmPath.js":9,"./jmArc.js":23,"./jmLine.js":32}],36:[function(require,module,exports){
9502
10778
  "use strict";
9503
10779
 
9504
10780
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -9898,5 +11174,234 @@ var jmResize = /*#__PURE__*/function (_jmRect) {
9898
11174
 
9899
11175
  exports.jmResize = exports["default"] = jmResize;
9900
11176
 
9901
- },{"./jmRect.js":32}]},{},[1]);
11177
+ },{"./jmRect.js":35}],37:[function(require,module,exports){
11178
+ "use strict";
11179
+
11180
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
11181
+
11182
+ Object.defineProperty(exports, "__esModule", {
11183
+ value: true
11184
+ });
11185
+ exports.jmStar = exports["default"] = void 0;
11186
+
11187
+ var _jmPath2 = require("../core/jmPath.js");
11188
+
11189
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11190
+
11191
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11192
+
11193
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
11194
+
11195
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
11196
+
11197
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11198
+
11199
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11200
+
11201
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
11202
+
11203
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
11204
+
11205
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11206
+
11207
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
11208
+
11209
+ /**
11210
+ * 画星形
11211
+ * 支持自定义顶点数和内外半径,创建各种星形图案
11212
+ * 星形由交替的外半径和内半径顶点组成
11213
+ *
11214
+ * @class jmStar
11215
+ * @extends jmPath
11216
+ * @param {object} params 星形的参数
11217
+ * @param {array} [params.points] 自定义顶点数组,如果提供则忽略其他参数
11218
+ * @param {number} [params.points=5] 星形顶点数(角数,3-50)
11219
+ * @param {number} [params.radius=50] 星形外半径(从中心到尖角的距离)
11220
+ * @param {number} [params.innerRadius=25] 星形内半径(从中心到凹陷处的距离)
11221
+ * @param {object} [params.center={x:0,y:0}] 星形中心点坐标
11222
+ */
11223
+ var jmStar = /*#__PURE__*/function (_jmPath) {
11224
+ _inherits(jmStar, _jmPath);
11225
+
11226
+ var _super = _createSuper(jmStar);
11227
+
11228
+ function jmStar(params) {
11229
+ var _this;
11230
+
11231
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmStar';
11232
+
11233
+ _classCallCheck(this, jmStar);
11234
+
11235
+ params = params || {};
11236
+ params.isRegular = true; // 标记为规则图形
11237
+
11238
+ _this = _super.call(this, params, t); // 参数验证和初始化
11239
+
11240
+ _this.pointsCount = params.points || 5;
11241
+ _this.radius = params.radius || 50;
11242
+ _this.innerRadius = params.innerRadius || 25;
11243
+ _this.center = params.center || {
11244
+ x: 0,
11245
+ y: 0
11246
+ };
11247
+ return _this;
11248
+ }
11249
+ /**
11250
+ * 设定或获取星形顶点数(角数)
11251
+ * 顶点数决定了星形的角数,例如5表示五角星
11252
+ *
11253
+ * @property pointsCount
11254
+ * @for jmStar
11255
+ * @type {number}
11256
+ */
11257
+
11258
+
11259
+ _createClass(jmStar, [{
11260
+ key: "pointsCount",
11261
+ get: function get() {
11262
+ return this.property('pointsCount');
11263
+ },
11264
+ set: function set(v) {
11265
+ // 参数验证:顶点数必须在3-50之间
11266
+ if (typeof v !== 'number' || isNaN(v) || v < 3) {
11267
+ console.warn('jmStar: pointsCount must be a number >= 3');
11268
+ v = 3;
11269
+ }
11270
+
11271
+ if (v > 50) {
11272
+ console.warn('jmStar: pointsCount should not exceed 50 for performance reasons');
11273
+ v = 50;
11274
+ }
11275
+
11276
+ this.needUpdate = true;
11277
+ return this.property('pointsCount', Math.floor(v)); // 确保是整数
11278
+ }
11279
+ /**
11280
+ * 设定或获取星形外半径
11281
+ * 外半径是从中心到尖角的距离
11282
+ *
11283
+ * @property radius
11284
+ * @for jmStar
11285
+ * @type {number}
11286
+ */
11287
+
11288
+ }, {
11289
+ key: "radius",
11290
+ get: function get() {
11291
+ return this.property('radius');
11292
+ },
11293
+ set: function set(v) {
11294
+ // 参数验证:半径必须为正数
11295
+ if (typeof v !== 'number' || isNaN(v) || v <= 0) {
11296
+ console.warn('jmStar: radius must be a positive number');
11297
+ v = 1;
11298
+ }
11299
+
11300
+ this.needUpdate = true;
11301
+ return this.property('radius', v);
11302
+ }
11303
+ /**
11304
+ * 设定或获取星形内半径
11305
+ * 内半径是从中心到凹陷处的距离
11306
+ * 内半径应该小于外半径,否则会产生奇怪的形状
11307
+ *
11308
+ * @property innerRadius
11309
+ * @for jmStar
11310
+ * @type {number}
11311
+ */
11312
+
11313
+ }, {
11314
+ key: "innerRadius",
11315
+ get: function get() {
11316
+ return this.property('innerRadius');
11317
+ },
11318
+ set: function set(v) {
11319
+ // 参数验证:内半径必须为正数
11320
+ if (typeof v !== 'number' || isNaN(v) || v <= 0) {
11321
+ console.warn('jmStar: innerRadius must be a positive number');
11322
+ v = 1;
11323
+ } // 警告:内半径不应大于外半径
11324
+
11325
+
11326
+ if (v >= this.radius) {
11327
+ console.warn('jmStar: innerRadius should be less than radius for proper star shape');
11328
+ }
11329
+
11330
+ this.needUpdate = true;
11331
+ return this.property('innerRadius', v);
11332
+ }
11333
+ /**
11334
+ * 设定或获取星形中心
11335
+ * 中心点是星形的几何中心
11336
+ *
11337
+ * @property center
11338
+ * @for jmStar
11339
+ * @type {object}
11340
+ */
11341
+
11342
+ }, {
11343
+ key: "center",
11344
+ get: function get() {
11345
+ return this.property('center');
11346
+ },
11347
+ set: function set(v) {
11348
+ // 参数验证:中心点必须包含x和y属性
11349
+ if (!v || typeof v.x !== 'number' || typeof v.y !== 'number') {
11350
+ console.warn('jmStar: center must be an object with x and y properties');
11351
+ v = {
11352
+ x: 0,
11353
+ y: 0
11354
+ };
11355
+ }
11356
+
11357
+ this.needUpdate = true;
11358
+ return this.property('center', v);
11359
+ }
11360
+ /**
11361
+ * 初始化图形点
11362
+ * 计算星形的顶点坐标,交替使用外半径和内半径
11363
+ *
11364
+ * @method initPoints
11365
+ * @private
11366
+ * @for jmStar
11367
+ */
11368
+
11369
+ }, {
11370
+ key: "initPoints",
11371
+ value: function initPoints() {
11372
+ // 如果提供了自定义顶点,直接使用
11373
+ if (this.points && this.points.length > 0) {
11374
+ return;
11375
+ } // 计算星形顶点
11376
+
11377
+
11378
+ var points = [];
11379
+ var pointsCount = this.pointsCount;
11380
+ var radius = this.radius;
11381
+ var innerRadius = this.innerRadius;
11382
+ var center = this.center; // 星形有2倍顶点数的点(外半径和内半径交替)
11383
+ // 从顶部开始绘制(-90度),顺时针方向
11384
+
11385
+ for (var i = 0; i < pointsCount * 2; i++) {
11386
+ var angle = i / pointsCount * Math.PI - Math.PI / 2; // 偶数索引使用外半径,奇数索引使用内半径
11387
+
11388
+ var r = i % 2 === 0 ? radius : innerRadius;
11389
+ var x = center.x + Math.cos(angle) * r;
11390
+ var y = center.y + Math.sin(angle) * r;
11391
+ points.push({
11392
+ x: x,
11393
+ y: y
11394
+ });
11395
+ }
11396
+
11397
+ this.points = points;
11398
+ }
11399
+ }]);
11400
+
11401
+ return jmStar;
11402
+ }(_jmPath2.jmPath);
11403
+
11404
+ exports.jmStar = exports["default"] = jmStar;
11405
+
11406
+ },{"../core/jmPath.js":9}]},{},[1]);
9902
11407
  var _r=_m(1);_g.jmGraph=_r;return _r;})})(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:(typeof self!=='undefined'?self:this)));