jmgraph 3.2.27 → 3.2.29
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.
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +2657 -415
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +824 -127
- package/src/core/jmEvents.js +154 -0
- package/src/core/jmFilter.js +38 -1
- package/src/core/jmGradient.js +47 -2
- package/src/core/jmGraph.js +51 -7
- package/src/core/jmLayer.js +34 -2
- package/src/core/jmList.js +167 -0
- package/src/core/jmObject.js +128 -8
- package/src/core/jmPath.js +43 -5
- package/src/core/jmProperty.js +181 -2
- package/src/core/jmShadow.js +36 -7
- package/src/core/jmUtils.js +149 -12
- package/src/lib/webgl/base.js +211 -83
- package/src/lib/webgl/core/buffer.js +43 -12
- package/src/lib/webgl/core/mapSize.js +16 -7
- package/src/lib/webgl/core/mapType.js +41 -22
- package/src/lib/webgl/core/program.js +94 -54
- package/src/lib/webgl/core/shader.js +20 -8
- package/src/lib/webgl/core/texture.js +55 -32
- package/src/lib/webgl/gradient.js +49 -17
- package/src/lib/webgl/index.js +173 -24
- package/src/lib/webgl/path.js +61 -12
- package/src/shapes/jmArc.js +48 -2
- package/src/shapes/jmArrow.js +35 -2
- package/src/shapes/jmArrowLine.js +33 -2
- package/src/shapes/jmBezier.js +50 -4
- package/src/shapes/jmCircle.js +35 -2
- package/src/shapes/jmEllipse.js +29 -3
- package/src/shapes/jmHArc.js +39 -2
- package/src/shapes/jmImage.js +49 -3
- package/src/shapes/jmLabel.js +41 -2
- package/src/shapes/jmLine.js +42 -2
- package/src/shapes/jmPolygon.js +42 -3
- package/src/shapes/jmPrismatic.js +34 -2
- package/src/shapes/jmRect.js +45 -3
- package/src/shapes/jmResize.js +42 -4
- package/src/shapes/jmStar.js +38 -4
package/dist/jmgraph.js
CHANGED
|
@@ -320,59 +320,192 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
320
320
|
|
|
321
321
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
322
322
|
|
|
323
|
+
/**
|
|
324
|
+
* 样式名称映射表
|
|
325
|
+
*
|
|
326
|
+
* 将简化的样式名称映射到 Canvas API 的标准属性名。
|
|
327
|
+
* 例如:'fill' -> 'fillStyle', 'stroke' -> 'strokeStyle'
|
|
328
|
+
*
|
|
329
|
+
* @constant {Object.<string, string>}
|
|
330
|
+
* @private
|
|
331
|
+
*/
|
|
323
332
|
var jmStyleMap = {
|
|
324
333
|
'fill': 'fillStyle',
|
|
334
|
+
// 填充颜色
|
|
325
335
|
'fillImage': 'fillImage',
|
|
336
|
+
// 填充图片
|
|
326
337
|
'stroke': 'strokeStyle',
|
|
338
|
+
// 描边颜色
|
|
327
339
|
'shadow.blur': 'shadowBlur',
|
|
340
|
+
// 阴影模糊度
|
|
328
341
|
'shadow.x': 'shadowOffsetX',
|
|
342
|
+
// 阴影X偏移
|
|
329
343
|
'shadow.y': 'shadowOffsetY',
|
|
344
|
+
// 阴影Y偏移
|
|
330
345
|
'shadow.color': 'shadowColor',
|
|
346
|
+
// 阴影颜色
|
|
331
347
|
'lineWidth': 'lineWidth',
|
|
348
|
+
// 线宽
|
|
332
349
|
'miterLimit': 'miterLimit',
|
|
350
|
+
// 斜接限制
|
|
333
351
|
'fillStyle': 'fillStyle',
|
|
352
|
+
// 填充样式
|
|
334
353
|
'strokeStyle': 'strokeStyle',
|
|
354
|
+
// 描边样式
|
|
335
355
|
'font': 'font',
|
|
356
|
+
// 字体
|
|
336
357
|
'opacity': 'globalAlpha',
|
|
358
|
+
// 透明度
|
|
337
359
|
'textAlign': 'textAlign',
|
|
360
|
+
// 文本对齐
|
|
338
361
|
'textBaseline': 'textBaseline',
|
|
362
|
+
// 文本基线
|
|
339
363
|
'shadowBlur': 'shadowBlur',
|
|
364
|
+
// 阴影模糊
|
|
340
365
|
'shadowOffsetX': 'shadowOffsetX',
|
|
366
|
+
// 阴影X偏移
|
|
341
367
|
'shadowOffsetY': 'shadowOffsetY',
|
|
368
|
+
// 阴影Y偏移
|
|
342
369
|
'shadowColor': 'shadowColor',
|
|
370
|
+
// 阴影颜色
|
|
343
371
|
'lineJoin': 'lineJoin',
|
|
372
|
+
// 线条连接样式
|
|
344
373
|
'lineCap': 'lineCap',
|
|
374
|
+
// 线条端点样式
|
|
345
375
|
'lineDashOffset': 'lineDashOffset',
|
|
346
|
-
|
|
376
|
+
// 虚线偏移
|
|
377
|
+
'globalCompositeOperation': 'globalCompositeOperation' // 合成操作
|
|
378
|
+
|
|
347
379
|
};
|
|
380
|
+
/**
|
|
381
|
+
* jmGraph 控件基类
|
|
382
|
+
*
|
|
383
|
+
* jmControl 是所有可视化图形控件的基类,提供了完整的图形渲染和交互能力。
|
|
384
|
+
*
|
|
385
|
+
* **核心功能:**
|
|
386
|
+
*
|
|
387
|
+
* 1. **样式系统**
|
|
388
|
+
* - 支持填充色、描边色、渐变、图片填充
|
|
389
|
+
* - 支持阴影、滤镜、混合模式
|
|
390
|
+
* - 支持虚线、线宽、线帽等线条样式
|
|
391
|
+
*
|
|
392
|
+
* 2. **变换系统**
|
|
393
|
+
* - 支持 translate(平移)
|
|
394
|
+
* - 支持 rotation(旋转)
|
|
395
|
+
* - 支持 transform(矩阵变换)
|
|
396
|
+
*
|
|
397
|
+
* 3. **事件系统**
|
|
398
|
+
* - 鼠标事件:mousedown, mouseup, mousemove, click, dblclick
|
|
399
|
+
* - 触摸事件:touchstart, touchmove, touchend
|
|
400
|
+
* - 焦点事件:mouseover, mouseleave, touchover, touchleave
|
|
401
|
+
* - 自定义事件:支持任意事件类型
|
|
402
|
+
*
|
|
403
|
+
* 4. **渲染系统**
|
|
404
|
+
* - 自动选择 Canvas 2D 或 WebGL 渲染器
|
|
405
|
+
* - 支持脏矩形优化
|
|
406
|
+
* - 支持层级排序(zIndex)
|
|
407
|
+
*
|
|
408
|
+
* 5. **碰撞检测**
|
|
409
|
+
* - 支持点在多边形内判断
|
|
410
|
+
* - 支持自定义命中区域
|
|
411
|
+
* - 支持旋转后的碰撞检测
|
|
412
|
+
*
|
|
413
|
+
* @class jmControl
|
|
414
|
+
* @extends jmProperty
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* // 创建自定义控件
|
|
418
|
+
* class MyShape extends jmControl {
|
|
419
|
+
* constructor(params) {
|
|
420
|
+
* super(params, 'myShape');
|
|
421
|
+
* }
|
|
422
|
+
*
|
|
423
|
+
* // 重写绘制方法
|
|
424
|
+
* draw() {
|
|
425
|
+
* // 自定义绘制逻辑
|
|
426
|
+
* }
|
|
427
|
+
* }
|
|
428
|
+
*
|
|
429
|
+
* // 使用控件
|
|
430
|
+
* const shape = new MyShape({
|
|
431
|
+
* position: { x: 100, y: 100 },
|
|
432
|
+
* width: 50,
|
|
433
|
+
* height: 50,
|
|
434
|
+
* style: {
|
|
435
|
+
* fill: 'red',
|
|
436
|
+
* stroke: 'black',
|
|
437
|
+
* lineWidth: 2
|
|
438
|
+
* }
|
|
439
|
+
* });
|
|
440
|
+
* graph.children.add(shape);
|
|
441
|
+
*/
|
|
348
442
|
|
|
349
443
|
var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
350
444
|
_inherits(jmControl, _jmProperty);
|
|
351
445
|
|
|
352
446
|
var _super = _createSuper(jmControl);
|
|
353
447
|
|
|
448
|
+
/**
|
|
449
|
+
* 构造函数
|
|
450
|
+
*
|
|
451
|
+
* 创建一个新的控件实例。子类应该调用 super(params, 'typeName') 来设置类型名称。
|
|
452
|
+
*
|
|
453
|
+
* @constructor
|
|
454
|
+
* @param {Object} [params] - 控件初始化参数
|
|
455
|
+
* @param {Object} [params.style] - 样式对象,包含填充、描边等属性
|
|
456
|
+
* @param {number} [params.width=0] - 控件宽度
|
|
457
|
+
* @param {number} [params.height=0] - 控件高度
|
|
458
|
+
* @param {Object} [params.position] - 控件位置 {x, y}
|
|
459
|
+
* @param {jmGraph} [params.graph] - 所属画布实例
|
|
460
|
+
* @param {number} [params.zIndex=0] - 层级顺序
|
|
461
|
+
* @param {boolean} [params.interactive=false] - 是否响应交互事件
|
|
462
|
+
* @param {Object} [params.hitArea] - 自定义命中区域 {x, y, width, height}
|
|
463
|
+
* @param {boolean} [params.isRegular] - 是否为规则图形(WebGL优化)
|
|
464
|
+
* @param {boolean} [params.needCut] - 是否需要裁剪(WebGL)
|
|
465
|
+
* @param {string} [t] - 控件类型名称,默认使用类名
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* // 创建矩形控件
|
|
469
|
+
* const rect = new jmControl({
|
|
470
|
+
* position: { x: 10, y: 10 },
|
|
471
|
+
* width: 100,
|
|
472
|
+
* height: 50,
|
|
473
|
+
* style: {
|
|
474
|
+
* fill: '#ff0000',
|
|
475
|
+
* stroke: '#000000',
|
|
476
|
+
* lineWidth: 2
|
|
477
|
+
* },
|
|
478
|
+
* interactive: true
|
|
479
|
+
* }, 'jmRect');
|
|
480
|
+
*/
|
|
354
481
|
function jmControl(params, t) {
|
|
355
482
|
var _this2;
|
|
356
483
|
|
|
357
484
|
_classCallCheck(this, jmControl);
|
|
358
485
|
|
|
359
486
|
params = params || {};
|
|
360
|
-
_this2 = _super.call(this, params);
|
|
487
|
+
_this2 = _super.call(this, params); // 设置控件类型标识
|
|
488
|
+
|
|
489
|
+
_this2.property('type', t || (this instanceof jmControl ? this.constructor : void 0).name); // 初始化样式对象
|
|
361
490
|
|
|
362
|
-
_this2.property('type', t || (this instanceof jmControl ? this.constructor : void 0).name);
|
|
363
491
|
|
|
364
|
-
_this2.style = params && params.style ? params.style : {};
|
|
492
|
+
_this2.style = params && params.style ? params.style : {}; // 设置尺寸
|
|
493
|
+
|
|
365
494
|
_this2.width = params.width || 0;
|
|
366
|
-
_this2.height = params.height || 0;
|
|
367
|
-
|
|
495
|
+
_this2.height = params.height || 0; // 自定义命中区域(用于点击测试)
|
|
496
|
+
|
|
497
|
+
_this2.hitArea = params.hitArea || null; // 设置位置
|
|
368
498
|
|
|
369
499
|
if (params.position) {
|
|
370
500
|
_this2.position = params.position;
|
|
371
|
-
}
|
|
501
|
+
} // 关联画布
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
_this2.graph = params.graph || null; // 层级顺序(用于排序)
|
|
505
|
+
|
|
506
|
+
_this2.zIndex = params.zIndex || 0; // 是否响应交互事件
|
|
372
507
|
|
|
373
|
-
_this2.
|
|
374
|
-
_this2.zIndex = params.zIndex || 0;
|
|
375
|
-
_this2.interactive = typeof params.interactive == 'undefined' ? false : params.interactive;
|
|
508
|
+
_this2.interactive = typeof params.interactive == 'undefined' ? false : params.interactive; // WebGL 模式下创建对应的渲染控制器
|
|
376
509
|
|
|
377
510
|
if (_this2.mode === 'webgl') {
|
|
378
511
|
_this2.webglControl = new _path["default"](_this2.graph, {
|
|
@@ -381,20 +514,52 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
381
514
|
isRegular: params.isRegular,
|
|
382
515
|
needCut: params.needCut
|
|
383
516
|
});
|
|
384
|
-
}
|
|
517
|
+
} // 执行初始化
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
_this2.initializing(); // 别名:on 等同于 bind
|
|
385
521
|
|
|
386
|
-
_this2.initializing();
|
|
387
522
|
|
|
388
|
-
_this2.on = _this2.bind;
|
|
523
|
+
_this2.on = _this2.bind; // 保存原始参数
|
|
524
|
+
|
|
389
525
|
_this2.option = params;
|
|
390
526
|
return _this2;
|
|
391
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* 控件类型标识
|
|
530
|
+
*
|
|
531
|
+
* 用于类型检查和调试,由构造函数自动设置。
|
|
532
|
+
*
|
|
533
|
+
* @type {string}
|
|
534
|
+
* @readonly
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* console.log(rect.type); // 'jmRect'
|
|
538
|
+
* if(control.type === 'jmCircle') { ... }
|
|
539
|
+
*/
|
|
540
|
+
|
|
392
541
|
|
|
393
542
|
_createClass(jmControl, [{
|
|
394
543
|
key: "type",
|
|
395
544
|
get: function get() {
|
|
396
545
|
return this.property('type');
|
|
397
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* 绘图上下文
|
|
549
|
+
*
|
|
550
|
+
* 获取当前控件的 Canvas 2D 或 WebGL 渲染上下文。
|
|
551
|
+
* 如果控件本身不是 jmGraph,会返回所属 graph 的上下文。
|
|
552
|
+
*
|
|
553
|
+
* @type {CanvasRenderingContext2D|WebGLRenderingContext}
|
|
554
|
+
* @readonly
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* // 获取上下文并绘制
|
|
558
|
+
* const ctx = control.context;
|
|
559
|
+
* ctx.fillStyle = 'red';
|
|
560
|
+
* ctx.fillRect(0, 0, 100, 100);
|
|
561
|
+
*/
|
|
562
|
+
|
|
398
563
|
}, {
|
|
399
564
|
key: "context",
|
|
400
565
|
get: function get() {
|
|
@@ -409,6 +574,36 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
409
574
|
set: function set(v) {
|
|
410
575
|
return this.property('context', v);
|
|
411
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* 样式对象
|
|
579
|
+
*
|
|
580
|
+
* 控件的视觉样式配置,包括:
|
|
581
|
+
* - fill: 填充颜色或渐变
|
|
582
|
+
* - stroke: 描边颜色
|
|
583
|
+
* - lineWidth: 线宽
|
|
584
|
+
* - shadow: 阴影配置
|
|
585
|
+
* - font: 字体(文本控件)
|
|
586
|
+
* - opacity: 透明度
|
|
587
|
+
*
|
|
588
|
+
* 设置新样式会触发 needUpdate。
|
|
589
|
+
*
|
|
590
|
+
* @type {Object}
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* // 设置样式
|
|
594
|
+
* control.style = {
|
|
595
|
+
* fill: '#ff0000',
|
|
596
|
+
* stroke: '#000000',
|
|
597
|
+
* lineWidth: 2,
|
|
598
|
+
* shadow: {
|
|
599
|
+
* blur: 10,
|
|
600
|
+
* x: 5,
|
|
601
|
+
* y: 5,
|
|
602
|
+
* color: 'rgba(0,0,0,0.5)'
|
|
603
|
+
* }
|
|
604
|
+
* };
|
|
605
|
+
*/
|
|
606
|
+
|
|
412
607
|
}, {
|
|
413
608
|
key: "style",
|
|
414
609
|
get: function get() {
|
|
@@ -420,6 +615,23 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
420
615
|
this.needUpdate = true;
|
|
421
616
|
return this.property('style', v);
|
|
422
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* 是否可见
|
|
620
|
+
*
|
|
621
|
+
* 控制控件是否参与渲染和事件响应。
|
|
622
|
+
* 不可见的控件不会被绘制,也不会响应鼠标/触摸事件。
|
|
623
|
+
*
|
|
624
|
+
* @type {boolean}
|
|
625
|
+
* @default true
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* // 隐藏控件
|
|
629
|
+
* control.visible = false;
|
|
630
|
+
*
|
|
631
|
+
* // 显示控件
|
|
632
|
+
* control.visible = true;
|
|
633
|
+
*/
|
|
634
|
+
|
|
423
635
|
}, {
|
|
424
636
|
key: "visible",
|
|
425
637
|
get: function get() {
|
|
@@ -431,6 +643,23 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
431
643
|
this.needUpdate = true;
|
|
432
644
|
return this.property('visible', v);
|
|
433
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* 是否响应交互事件
|
|
648
|
+
*
|
|
649
|
+
* 设置为 true 时,控件会响应鼠标和触摸事件。
|
|
650
|
+
* 设置为 false 时,事件会穿透到下层控件。
|
|
651
|
+
*
|
|
652
|
+
* @type {boolean}
|
|
653
|
+
* @default false
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* // 启用交互
|
|
657
|
+
* control.interactive = true;
|
|
658
|
+
* control.bind('click', (evt) => {
|
|
659
|
+
* console.log('clicked!');
|
|
660
|
+
* });
|
|
661
|
+
*/
|
|
662
|
+
|
|
434
663
|
}, {
|
|
435
664
|
key: "interactive",
|
|
436
665
|
get: function get() {
|
|
@@ -440,6 +669,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
440
669
|
set: function set(v) {
|
|
441
670
|
return this.property('interactive', v);
|
|
442
671
|
}
|
|
672
|
+
/**
|
|
673
|
+
* 自定义命中区域
|
|
674
|
+
*
|
|
675
|
+
* 用于点击测试的自定义区域,格式为 {x, y, width, height}。
|
|
676
|
+
* 如果设置,点击测试会使用此区域而非实际图形边界。
|
|
677
|
+
*
|
|
678
|
+
* @type {Object|null}
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* // 设置更大的点击区域
|
|
682
|
+
* control.hitArea = {
|
|
683
|
+
* x: -10,
|
|
684
|
+
* y: -10,
|
|
685
|
+
* width: control.width + 20,
|
|
686
|
+
* height: control.height + 20
|
|
687
|
+
* };
|
|
688
|
+
*/
|
|
689
|
+
|
|
443
690
|
}, {
|
|
444
691
|
key: "hitArea",
|
|
445
692
|
get: function get() {
|
|
@@ -449,6 +696,27 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
449
696
|
set: function set(v) {
|
|
450
697
|
return this.property('hitArea', v);
|
|
451
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* 子控件列表
|
|
701
|
+
*
|
|
702
|
+
* 当前控件的所有子控件。子控件会按 zIndex 排序后绘制。
|
|
703
|
+
* 添加子控件时会自动建立父子关系。
|
|
704
|
+
*
|
|
705
|
+
* @type {jmList}
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* // 添加子控件
|
|
709
|
+
* parent.children.add(child);
|
|
710
|
+
*
|
|
711
|
+
* // 移除子控件
|
|
712
|
+
* parent.children.remove(child);
|
|
713
|
+
*
|
|
714
|
+
* // 遍历子控件
|
|
715
|
+
* parent.children.each((i, child) => {
|
|
716
|
+
* console.log(child);
|
|
717
|
+
* });
|
|
718
|
+
*/
|
|
719
|
+
|
|
452
720
|
}, {
|
|
453
721
|
key: "children",
|
|
454
722
|
get: function get() {
|
|
@@ -460,6 +728,22 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
460
728
|
this.needUpdate = true;
|
|
461
729
|
return this.property('children', v);
|
|
462
730
|
}
|
|
731
|
+
/**
|
|
732
|
+
* 控件宽度
|
|
733
|
+
*
|
|
734
|
+
* 可以是具体数值或百分比字符串(如 '50%')。
|
|
735
|
+
* 百分比会相对于父容器宽度计算。
|
|
736
|
+
*
|
|
737
|
+
* @type {number|string}
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* // 设置固定宽度
|
|
741
|
+
* control.width = 100;
|
|
742
|
+
*
|
|
743
|
+
* // 设置百分比宽度
|
|
744
|
+
* control.width = '50%';
|
|
745
|
+
*/
|
|
746
|
+
|
|
463
747
|
}, {
|
|
464
748
|
key: "width",
|
|
465
749
|
get: function get() {
|
|
@@ -471,6 +755,22 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
471
755
|
this.needUpdate = true;
|
|
472
756
|
return this.property('width', v);
|
|
473
757
|
}
|
|
758
|
+
/**
|
|
759
|
+
* 控件高度
|
|
760
|
+
*
|
|
761
|
+
* 可以是具体数值或百分比字符串(如 '50%')。
|
|
762
|
+
* 百分比会相对于父容器高度计算。
|
|
763
|
+
*
|
|
764
|
+
* @type {number|string}
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* // 设置固定高度
|
|
768
|
+
* control.height = 100;
|
|
769
|
+
*
|
|
770
|
+
* // 设置百分比高度
|
|
771
|
+
* control.height = '50%';
|
|
772
|
+
*/
|
|
773
|
+
|
|
474
774
|
}, {
|
|
475
775
|
key: "height",
|
|
476
776
|
get: function get() {
|
|
@@ -482,6 +782,23 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
482
782
|
this.needUpdate = true;
|
|
483
783
|
return this.property('height', v);
|
|
484
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* 层级顺序
|
|
787
|
+
*
|
|
788
|
+
* 控制控件的绘制顺序,值越大越靠上。
|
|
789
|
+
* 设置 zIndex 会触发子控件重新排序。
|
|
790
|
+
*
|
|
791
|
+
* @type {number}
|
|
792
|
+
* @default 0
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* // 将控件置于最上层
|
|
796
|
+
* control.zIndex = 100;
|
|
797
|
+
*
|
|
798
|
+
* // 将控件置于最下层
|
|
799
|
+
* control.zIndex = -1;
|
|
800
|
+
*/
|
|
801
|
+
|
|
485
802
|
}, {
|
|
486
803
|
key: "zIndex",
|
|
487
804
|
get: function get() {
|
|
@@ -495,6 +812,22 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
495
812
|
this.needUpdate = true;
|
|
496
813
|
return v;
|
|
497
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* 鼠标样式
|
|
817
|
+
*
|
|
818
|
+
* 鼠标悬停在控件上时显示的光标样式。
|
|
819
|
+
* 常用值:'default', 'pointer', 'move', 'text', 'crosshair'
|
|
820
|
+
*
|
|
821
|
+
* @type {string}
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* // 设置为手型指针
|
|
825
|
+
* control.cursor = 'pointer';
|
|
826
|
+
*
|
|
827
|
+
* // 设置为移动样式
|
|
828
|
+
* control.cursor = 'move';
|
|
829
|
+
*/
|
|
830
|
+
|
|
498
831
|
}, {
|
|
499
832
|
key: "cursor",
|
|
500
833
|
get: function get() {
|
|
@@ -503,7 +836,18 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
503
836
|
if (graph) {
|
|
504
837
|
return graph.css('cursor');
|
|
505
838
|
}
|
|
506
|
-
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* 初始化控件
|
|
842
|
+
*
|
|
843
|
+
* 在构造函数末尾调用,用于设置子控件管理逻辑。
|
|
844
|
+
* 重写了 children 的 add、remove、sort、clear 方法,
|
|
845
|
+
* 实现自动的父子关系维护和脏标记传播。
|
|
846
|
+
*
|
|
847
|
+
* @method initializing
|
|
848
|
+
* @protected
|
|
849
|
+
*/
|
|
850
|
+
,
|
|
507
851
|
set: function set(cur) {
|
|
508
852
|
var graph = this.graph;
|
|
509
853
|
|
|
@@ -517,14 +861,20 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
517
861
|
var self = this;
|
|
518
862
|
this.children = this.children || new _jmList.jmList();
|
|
519
863
|
var oadd = this.children.add;
|
|
864
|
+
/**
|
|
865
|
+
* 重写 add 方法,自动建立父子关系
|
|
866
|
+
* @param {jmControl} obj - 要添加的子控件
|
|
867
|
+
* @returns {jmControl} 添加的子控件
|
|
868
|
+
*/
|
|
520
869
|
|
|
521
870
|
this.children.add = function (obj) {
|
|
522
871
|
if (_typeof(obj) === 'object') {
|
|
872
|
+
// 如果对象已有父级,先从原父级移除
|
|
523
873
|
if (obj.parent && obj.parent != self && obj.parent.children) {
|
|
524
874
|
obj.parent.children.remove(obj);
|
|
525
875
|
}
|
|
526
876
|
|
|
527
|
-
obj.parent = self;
|
|
877
|
+
obj.parent = self; // 如果已存在,先移除再添加
|
|
528
878
|
|
|
529
879
|
if (this.contain(obj)) {
|
|
530
880
|
this.oremove(obj);
|
|
@@ -532,7 +882,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
532
882
|
|
|
533
883
|
oadd.call(this, obj);
|
|
534
884
|
obj.emit('add', obj);
|
|
535
|
-
self.needUpdate = true;
|
|
885
|
+
self.needUpdate = true; // 传播 graph 引用
|
|
886
|
+
|
|
536
887
|
if (self.graph) obj.graph = self.graph;
|
|
537
888
|
this.sort();
|
|
538
889
|
return obj;
|
|
@@ -540,6 +891,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
540
891
|
};
|
|
541
892
|
|
|
542
893
|
this.children.oremove = this.children.remove;
|
|
894
|
+
/**
|
|
895
|
+
* 重写 remove 方法,清理父子关系
|
|
896
|
+
* @param {jmControl} obj - 要移除的子控件
|
|
897
|
+
*/
|
|
543
898
|
|
|
544
899
|
this.children.remove = function (obj) {
|
|
545
900
|
if (_typeof(obj) === 'object') {
|
|
@@ -550,6 +905,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
550
905
|
self.needUpdate = true;
|
|
551
906
|
}
|
|
552
907
|
};
|
|
908
|
+
/**
|
|
909
|
+
* 按 zIndex 排序子控件
|
|
910
|
+
*/
|
|
911
|
+
|
|
553
912
|
|
|
554
913
|
this.children.sort = function () {
|
|
555
914
|
var levelItems = {};
|
|
@@ -571,6 +930,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
571
930
|
oadd.call(this, levelItems[index]);
|
|
572
931
|
}
|
|
573
932
|
};
|
|
933
|
+
/**
|
|
934
|
+
* 清空所有子控件
|
|
935
|
+
*/
|
|
936
|
+
|
|
574
937
|
|
|
575
938
|
this.children.clear = function () {
|
|
576
939
|
this.each(function (i, obj) {
|
|
@@ -580,6 +943,39 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
580
943
|
|
|
581
944
|
this.needUpdate = true;
|
|
582
945
|
}
|
|
946
|
+
/**
|
|
947
|
+
* 设置控件样式到绘图上下文
|
|
948
|
+
*
|
|
949
|
+
* 将样式对象应用到 Canvas 上下文,支持:
|
|
950
|
+
* - 基础样式:fill, stroke, lineWidth, opacity 等
|
|
951
|
+
* - 阴影效果:shadow.blur, shadow.x, shadow.y, shadow.color
|
|
952
|
+
* - 渐变填充:支持线性渐变和径向渐变
|
|
953
|
+
* - 变换效果:rotation(旋转)、translate(平移)、transform(矩阵变换)
|
|
954
|
+
* - 高级效果:lineDash(虚线)、filter(滤镜)、clipPath(裁剪)、mask(遮罩)
|
|
955
|
+
*
|
|
956
|
+
* @method setStyle
|
|
957
|
+
* @param {Object} [style] - 要应用的样式对象,默认使用 this.style
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* // 应用样式
|
|
961
|
+
* control.setStyle({
|
|
962
|
+
* fill: '#ff0000',
|
|
963
|
+
* stroke: '#000000',
|
|
964
|
+
* lineWidth: 2,
|
|
965
|
+
* shadow: {
|
|
966
|
+
* blur: 10,
|
|
967
|
+
* x: 5,
|
|
968
|
+
* y: 5,
|
|
969
|
+
* color: 'rgba(0,0,0,0.5)'
|
|
970
|
+
* }
|
|
971
|
+
* });
|
|
972
|
+
*
|
|
973
|
+
* // 使用渐变
|
|
974
|
+
* control.setStyle({
|
|
975
|
+
* fill: 'linear-gradient(0,0,100,0,#ff0000,#0000ff)'
|
|
976
|
+
* });
|
|
977
|
+
*/
|
|
978
|
+
|
|
583
979
|
}, {
|
|
584
980
|
key: "setStyle",
|
|
585
981
|
value: function setStyle(style) {
|
|
@@ -590,10 +986,17 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
590
986
|
}
|
|
591
987
|
|
|
592
988
|
if (!style) return;
|
|
989
|
+
/**
|
|
990
|
+
* 内部样式设置函数
|
|
991
|
+
* @param {*} styleValue - 样式值
|
|
992
|
+
* @param {string} name - 样式名称
|
|
993
|
+
* @param {string} [mpkey] - 映射键名
|
|
994
|
+
* @private
|
|
995
|
+
*/
|
|
593
996
|
|
|
594
997
|
var __setStyle = function __setStyle(style, name, mpkey) {
|
|
595
998
|
if (style) {
|
|
596
|
-
var styleValue = style;
|
|
999
|
+
var styleValue = style; // 支持函数形式的样式值
|
|
597
1000
|
|
|
598
1001
|
if (typeof styleValue === 'function') {
|
|
599
1002
|
try {
|
|
@@ -606,7 +1009,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
606
1009
|
|
|
607
1010
|
var t = _typeof(styleValue);
|
|
608
1011
|
|
|
609
|
-
var mpname = jmStyleMap[mpkey || name];
|
|
1012
|
+
var mpname = jmStyleMap[mpkey || name]; // 处理渐变
|
|
610
1013
|
|
|
611
1014
|
if (styleValue instanceof _jmGradient.jmGradient || t == 'string' && styleValue.indexOf('-gradient') > -1) {
|
|
612
1015
|
if (t == 'string' && styleValue.indexOf('-gradient') > -1) {
|
|
@@ -614,7 +1017,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
614
1017
|
}
|
|
615
1018
|
|
|
616
1019
|
__setStyle(styleValue.toGradient(_this3), mpname || name);
|
|
617
|
-
}
|
|
1020
|
+
} // 处理标准样式映射
|
|
1021
|
+
else if (mpname) {
|
|
618
1022
|
if (_this3.webglControl) {
|
|
619
1023
|
_this3.webglControl.setStyle(mpname, styleValue);
|
|
620
1024
|
} else {
|
|
@@ -624,8 +1028,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
624
1028
|
|
|
625
1029
|
_this3.context[mpname] = styleValue;
|
|
626
1030
|
}
|
|
627
|
-
}
|
|
1031
|
+
} // 处理特殊样式
|
|
1032
|
+
else {
|
|
628
1033
|
switch (name) {
|
|
1034
|
+
// 阴影样式
|
|
629
1035
|
case 'shadow':
|
|
630
1036
|
{
|
|
631
1037
|
if (t == 'string') {
|
|
@@ -640,11 +1046,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
640
1046
|
|
|
641
1047
|
break;
|
|
642
1048
|
}
|
|
1049
|
+
// 平移变换
|
|
643
1050
|
|
|
644
1051
|
case 'translate':
|
|
645
1052
|
{
|
|
646
1053
|
break;
|
|
647
1054
|
}
|
|
1055
|
+
// 旋转变换
|
|
648
1056
|
|
|
649
1057
|
case 'rotation':
|
|
650
1058
|
{
|
|
@@ -659,6 +1067,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
659
1067
|
_this3.context.translate && _this3.context.translate(-_this3.__translateAbsolutePosition.x, -_this3.__translateAbsolutePosition.y);
|
|
660
1068
|
break;
|
|
661
1069
|
}
|
|
1070
|
+
// 矩阵变换
|
|
662
1071
|
|
|
663
1072
|
case 'transform':
|
|
664
1073
|
{
|
|
@@ -672,6 +1081,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
672
1081
|
|
|
673
1082
|
break;
|
|
674
1083
|
}
|
|
1084
|
+
// 鼠标样式
|
|
675
1085
|
|
|
676
1086
|
case 'cursor':
|
|
677
1087
|
{
|
|
@@ -679,7 +1089,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
679
1089
|
break;
|
|
680
1090
|
}
|
|
681
1091
|
// ===== 新增样式特性 =====
|
|
682
|
-
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* 虚线样式
|
|
1095
|
+
* 支持数组格式 [5, 3, 2] 或字符串格式 "5,3,2"
|
|
1096
|
+
* @example
|
|
1097
|
+
* style: { lineDash: [5, 3] } // 5px实线,3px空白
|
|
1098
|
+
*/
|
|
683
1099
|
|
|
684
1100
|
case 'lineDash':
|
|
685
1101
|
{
|
|
@@ -716,7 +1132,15 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
716
1132
|
_this3.context.lineDashOffset = Number(styleValue) || 0;
|
|
717
1133
|
break;
|
|
718
1134
|
}
|
|
719
|
-
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* CSS滤镜效果
|
|
1138
|
+
* 支持 blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
1139
|
+
* @example
|
|
1140
|
+
* style: { filter: 'blur(5px) grayscale(50%)' }
|
|
1141
|
+
* // 或使用对象
|
|
1142
|
+
* style: { filter: { blur: 5, grayscale: 0.5 } }
|
|
1143
|
+
*/
|
|
720
1144
|
|
|
721
1145
|
case 'filter':
|
|
722
1146
|
{
|
|
@@ -732,7 +1156,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
732
1156
|
|
|
733
1157
|
break;
|
|
734
1158
|
}
|
|
735
|
-
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* 混合模式
|
|
1162
|
+
* 常用值:source-over, multiply, screen, overlay, darken, lighten
|
|
1163
|
+
* @example
|
|
1164
|
+
* style: { globalCompositeOperation: 'multiply' }
|
|
1165
|
+
*/
|
|
736
1166
|
|
|
737
1167
|
case 'globalCompositeOperation':
|
|
738
1168
|
{
|
|
@@ -740,7 +1170,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
740
1170
|
_this3.context.globalCompositeOperation = styleValue;
|
|
741
1171
|
break;
|
|
742
1172
|
}
|
|
743
|
-
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* 裁剪路径
|
|
1176
|
+
* 通过 canvas clip 实现裁剪效果
|
|
1177
|
+
* @example
|
|
1178
|
+
* style: { clipPath: clipShape } // clipShape 是一个图形控件
|
|
1179
|
+
*/
|
|
744
1180
|
|
|
745
1181
|
case 'clipPath':
|
|
746
1182
|
{
|
|
@@ -770,7 +1206,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
770
1206
|
|
|
771
1207
|
break;
|
|
772
1208
|
}
|
|
773
|
-
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* 遮罩效果
|
|
1212
|
+
* 通过 globalCompositeOperation + destination-in 实现
|
|
1213
|
+
* @example
|
|
1214
|
+
* style: { mask: maskShape } // maskShape 是一个图形控件
|
|
1215
|
+
*/
|
|
774
1216
|
|
|
775
1217
|
case 'mask':
|
|
776
1218
|
{
|
|
@@ -780,7 +1222,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
780
1222
|
_this3.__mask = styleValue;
|
|
781
1223
|
break;
|
|
782
1224
|
}
|
|
783
|
-
//
|
|
1225
|
+
// 阴影相关样式(WebGL兼容)
|
|
784
1226
|
|
|
785
1227
|
case 'shadowColor':
|
|
786
1228
|
{
|
|
@@ -828,26 +1270,32 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
828
1270
|
}
|
|
829
1271
|
}
|
|
830
1272
|
}
|
|
831
|
-
};
|
|
1273
|
+
}; // 应用平移变换
|
|
1274
|
+
|
|
832
1275
|
|
|
833
1276
|
if (this.translate) {
|
|
834
1277
|
__setStyle(this.translate, 'translate');
|
|
835
|
-
}
|
|
1278
|
+
} // 应用矩阵变换
|
|
1279
|
+
|
|
836
1280
|
|
|
837
1281
|
if (this.transform) {
|
|
838
1282
|
__setStyle(this.transform, 'transform');
|
|
839
|
-
}
|
|
1283
|
+
} // 遍历应用所有样式
|
|
1284
|
+
|
|
840
1285
|
|
|
841
1286
|
for (var k in style) {
|
|
842
1287
|
if (k === 'constructor') continue;
|
|
843
1288
|
|
|
844
|
-
var t = _typeof(style[k]);
|
|
1289
|
+
var t = _typeof(style[k]); // 自动转换渐变字符串
|
|
1290
|
+
|
|
845
1291
|
|
|
846
1292
|
if (t == 'string' && style[k].indexOf('-gradient') > -1) {
|
|
847
1293
|
style[k] = new _jmGradient.jmGradient(style[k]);
|
|
848
|
-
}
|
|
1294
|
+
} // 自动转换阴影字符串
|
|
1295
|
+
else if (t == 'string' && k == 'shadow') {
|
|
849
1296
|
style[k] = new _jmShadow.jmShadow(style[k]);
|
|
850
|
-
}
|
|
1297
|
+
} // 自动转换滤镜字符串
|
|
1298
|
+
else if (t == 'string' && k == 'filter') {
|
|
851
1299
|
style[k] = new _jmFilter.jmFilter(style[k]);
|
|
852
1300
|
}
|
|
853
1301
|
|
|
@@ -855,13 +1303,29 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
855
1303
|
}
|
|
856
1304
|
}
|
|
857
1305
|
/**
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
*
|
|
1306
|
+
* 获取当前控件的边界矩形
|
|
1307
|
+
*
|
|
1308
|
+
* 通过分析控件的描点或位置加宽高得到边界矩形。
|
|
1309
|
+
* 对于 jmGraph,边界为画布尺寸。
|
|
1310
|
+
* 对于有 points 的控件,边界为所有点的最小包围矩形。
|
|
1311
|
+
*
|
|
861
1312
|
* @method getBounds
|
|
862
|
-
* @
|
|
863
|
-
* @
|
|
864
|
-
* @
|
|
1313
|
+
* @param {boolean} [isReset=false] - 是否强制重新计算(忽略缓存)
|
|
1314
|
+
* @returns {Object} 边界对象
|
|
1315
|
+
* @returns {number} returns.left - 左边界 X 坐标
|
|
1316
|
+
* @returns {number} returns.top - 上边界 Y 坐标
|
|
1317
|
+
* @returns {number} returns.right - 右边界 X 坐标
|
|
1318
|
+
* @returns {number} returns.bottom - 下边界 Y 坐标
|
|
1319
|
+
* @returns {number} returns.width - 宽度
|
|
1320
|
+
* @returns {number} returns.height - 高度
|
|
1321
|
+
*
|
|
1322
|
+
* @example
|
|
1323
|
+
* // 获取边界
|
|
1324
|
+
* const bounds = control.getBounds();
|
|
1325
|
+
* console.log(`宽: ${bounds.width}, 高: ${bounds.height}`);
|
|
1326
|
+
*
|
|
1327
|
+
* // 强制重新计算
|
|
1328
|
+
* const newBounds = control.getBounds(true);
|
|
865
1329
|
*/
|
|
866
1330
|
|
|
867
1331
|
}, {
|
|
@@ -884,7 +1348,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
884
1348
|
} else if (this.height) {
|
|
885
1349
|
rect.bottom = this.height;
|
|
886
1350
|
}
|
|
887
|
-
}
|
|
1351
|
+
} // 根据 points 计算边界
|
|
1352
|
+
else if (this.points && this.points.length > 0) {
|
|
888
1353
|
var _iterator = _createForOfIteratorHelper(this.points),
|
|
889
1354
|
_step;
|
|
890
1355
|
|
|
@@ -913,7 +1378,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
913
1378
|
} finally {
|
|
914
1379
|
_iterator.f();
|
|
915
1380
|
}
|
|
916
|
-
}
|
|
1381
|
+
} // 根据位置和尺寸计算边界
|
|
1382
|
+
else if (this.getLocation) {
|
|
917
1383
|
var _p = this.getLocation();
|
|
918
1384
|
|
|
919
1385
|
if (_p) {
|
|
@@ -924,16 +1390,32 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
924
1390
|
}
|
|
925
1391
|
}
|
|
926
1392
|
|
|
927
|
-
if (
|
|
928
|
-
if (
|
|
929
|
-
if (
|
|
930
|
-
if (
|
|
1393
|
+
if (rect.left === undefined) rect.left = 0;
|
|
1394
|
+
if (rect.top === undefined) rect.top = 0;
|
|
1395
|
+
if (rect.right === undefined) rect.right = 0;
|
|
1396
|
+
if (rect.bottom === undefined) rect.bottom = 0;
|
|
931
1397
|
rect.width = rect.right - rect.left;
|
|
932
1398
|
rect.height = rect.bottom - rect.top;
|
|
933
1399
|
return this.bounds = rect;
|
|
934
1400
|
}
|
|
935
1401
|
/**
|
|
936
|
-
*
|
|
1402
|
+
* 获取旋转后的边界矩形
|
|
1403
|
+
*
|
|
1404
|
+
* 计算控件旋转后的最小包围矩形。
|
|
1405
|
+
* 当控件有旋转变换时,实际占据的空间会发生变化。
|
|
1406
|
+
*
|
|
1407
|
+
* @method getRotationBounds
|
|
1408
|
+
* @param {Object} [rotation] - 旋转参数,默认使用 style.rotation
|
|
1409
|
+
* @param {number} rotation.x - 旋转中心 X(相对于控件)
|
|
1410
|
+
* @param {number} rotation.y - 旋转中心 Y(相对于控件)
|
|
1411
|
+
* @param {number} rotation.angle - 旋转角度(弧度)
|
|
1412
|
+
* @param {Object} [bounds] - 基础边界,默认使用 getBounds()
|
|
1413
|
+
* @returns {Object} 旋转后的边界对象
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* // 获取旋转后的边界
|
|
1417
|
+
* const bounds = control.getRotationBounds();
|
|
1418
|
+
* console.log(`旋转后宽度: ${bounds.width}`);
|
|
937
1419
|
*/
|
|
938
1420
|
|
|
939
1421
|
}, {
|
|
@@ -1016,11 +1498,26 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1016
1498
|
return rect;
|
|
1017
1499
|
}
|
|
1018
1500
|
/**
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1501
|
+
* 获取当前控件的位置参数
|
|
1502
|
+
*
|
|
1503
|
+
* 解析百分比和 margin 参数,返回标准化的位置信息。
|
|
1504
|
+
* 支持百分比定位(如 '50%')和 margin 偏移。
|
|
1505
|
+
*
|
|
1022
1506
|
* @method getLocation
|
|
1023
|
-
* @
|
|
1507
|
+
* @returns {Object} 位置参数对象
|
|
1508
|
+
* @returns {number} returns.left - 左边距
|
|
1509
|
+
* @returns {number} returns.top - 上边距
|
|
1510
|
+
* @returns {number} returns.width - 宽度
|
|
1511
|
+
* @returns {number} returns.height - 高度
|
|
1512
|
+
* @returns {Object} [returns.position] - 位置对象 {x, y}
|
|
1513
|
+
* @returns {Object} [returns.center] - 中心点
|
|
1514
|
+
* @returns {Object} [returns.start] - 起点(线条类)
|
|
1515
|
+
* @returns {Object} [returns.end] - 终点(线条类)
|
|
1516
|
+
* @returns {number} [returns.radius] - 半径(圆形类)
|
|
1517
|
+
*
|
|
1518
|
+
* @example
|
|
1519
|
+
* const loc = control.getLocation();
|
|
1520
|
+
* console.log(`位置: (${loc.left}, ${loc.top})`);
|
|
1024
1521
|
*/
|
|
1025
1522
|
|
|
1026
1523
|
}, {
|
|
@@ -1107,8 +1604,26 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1107
1604
|
return local;
|
|
1108
1605
|
}
|
|
1109
1606
|
/**
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1607
|
+
* 获取当前控件的旋转信息
|
|
1608
|
+
*
|
|
1609
|
+
* 解析旋转参数,支持百分比形式的旋转中心。
|
|
1610
|
+
* 如果控件本身没有旋转,会继承父级的旋转。
|
|
1611
|
+
*
|
|
1612
|
+
* @method getRotation
|
|
1613
|
+
* @param {Object} [rotation] - 旋转参数,默认使用 style.rotation
|
|
1614
|
+
* @param {Object} [bounds] - 基础边界
|
|
1615
|
+
* @returns {Object} 旋转信息
|
|
1616
|
+
* @returns {number} returns.x - 旋转中心 X(相对于控件)
|
|
1617
|
+
* @returns {number} returns.y - 旋转中心 Y(相对于控件)
|
|
1618
|
+
* @returns {number} returns.angle - 旋转角度(弧度)
|
|
1619
|
+
* @returns {Object} returns.bounds - 控件边界
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* // 获取旋转信息
|
|
1623
|
+
* const rot = control.getRotation();
|
|
1624
|
+
* if(rot.angle) {
|
|
1625
|
+
* console.log(`旋转角度: ${rot.angle} 弧度`);
|
|
1626
|
+
* }
|
|
1112
1627
|
*/
|
|
1113
1628
|
|
|
1114
1629
|
}, {
|
|
@@ -1143,7 +1658,21 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1143
1658
|
return _objectSpread(_objectSpread({}, rotation), {}, {
|
|
1144
1659
|
bounds: bounds
|
|
1145
1660
|
});
|
|
1146
|
-
}
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* 计算位移偏移量
|
|
1664
|
+
*
|
|
1665
|
+
* 解析 translate 样式,支持百分比形式。
|
|
1666
|
+
*
|
|
1667
|
+
* @method getTranslate
|
|
1668
|
+
* @param {Object} [translate] - 平移参数,默认使用 style.translate
|
|
1669
|
+
* @param {Object} [bounds] - 参考边界
|
|
1670
|
+
* @returns {Object} 平移信息 {x, y}
|
|
1671
|
+
*
|
|
1672
|
+
* @example
|
|
1673
|
+
* const trans = control.getTranslate();
|
|
1674
|
+
* console.log(`平移: (${trans.x}, ${trans.y})`);
|
|
1675
|
+
*/
|
|
1147
1676
|
|
|
1148
1677
|
}, {
|
|
1149
1678
|
key: "getTranslate",
|
|
@@ -1173,9 +1702,15 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1173
1702
|
}
|
|
1174
1703
|
/**
|
|
1175
1704
|
* 移除当前控件
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1705
|
+
*
|
|
1706
|
+
* 从父控件的子控件列表中移除当前控件。
|
|
1707
|
+
* 移除后会触发 needUpdate 重绘。
|
|
1708
|
+
*
|
|
1709
|
+
* @method remove
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* // 移除控件
|
|
1713
|
+
* control.remove();
|
|
1179
1714
|
*/
|
|
1180
1715
|
|
|
1181
1716
|
}, {
|
|
@@ -1187,13 +1722,19 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1187
1722
|
}
|
|
1188
1723
|
/**
|
|
1189
1724
|
* 对控件进行平移
|
|
1725
|
+
*
|
|
1190
1726
|
* 遍历控件所有描点或位置,设置其偏移量。
|
|
1191
|
-
*
|
|
1727
|
+
* 支持移动 position、center、start、end、points 等属性。
|
|
1728
|
+
*
|
|
1192
1729
|
* @method offset
|
|
1193
|
-
* @param {number} x
|
|
1194
|
-
* @param {number} y
|
|
1195
|
-
* @param {boolean} [trans]
|
|
1196
|
-
* @param {
|
|
1730
|
+
* @param {number} x - X 轴偏移量
|
|
1731
|
+
* @param {number} y - Y 轴偏移量
|
|
1732
|
+
* @param {boolean} [trans=true] - 是否传递给监听者
|
|
1733
|
+
* @param {Object} [evt] - 如果是事件触发,传递 move 事件参数
|
|
1734
|
+
*
|
|
1735
|
+
* @example
|
|
1736
|
+
* // 向右移动 10px,向下移动 5px
|
|
1737
|
+
* control.offset(10, 5);
|
|
1197
1738
|
*/
|
|
1198
1739
|
|
|
1199
1740
|
}, {
|
|
@@ -1266,11 +1807,17 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1266
1807
|
this.needUpdate = true;
|
|
1267
1808
|
}
|
|
1268
1809
|
/**
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1810
|
+
* 获取控件相对于画布的绝对边界
|
|
1811
|
+
*
|
|
1812
|
+
* 与 getBounds 不同的是:getBounds 获取的是相对于父容器的边界,
|
|
1813
|
+
* 而 getAbsoluteBounds 获取的是相对于画布的边界。
|
|
1814
|
+
*
|
|
1272
1815
|
* @method getAbsoluteBounds
|
|
1273
|
-
* @
|
|
1816
|
+
* @returns {Object} 绝对边界对象
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* const absBounds = control.getAbsoluteBounds();
|
|
1820
|
+
* console.log(`画布上的位置: (${absBounds.left}, ${absBounds.top})`);
|
|
1274
1821
|
*/
|
|
1275
1822
|
|
|
1276
1823
|
}, {
|
|
@@ -1295,10 +1842,14 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1295
1842
|
return rec;
|
|
1296
1843
|
}
|
|
1297
1844
|
/**
|
|
1298
|
-
*
|
|
1845
|
+
* 把当前控件内部坐标转为画布绝对坐标
|
|
1299
1846
|
*
|
|
1300
1847
|
* @method toAbsolutePoint
|
|
1301
|
-
* @param {x
|
|
1848
|
+
* @param {Object} point - 内部坐标 {x, y}
|
|
1849
|
+
* @returns {Object} 绝对坐标
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* const absPoint = control.toAbsolutePoint({x: 10, y: 10});
|
|
1302
1853
|
*/
|
|
1303
1854
|
|
|
1304
1855
|
}, {
|
|
@@ -1313,8 +1864,14 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1313
1864
|
return point;
|
|
1314
1865
|
}
|
|
1315
1866
|
/**
|
|
1316
|
-
*
|
|
1317
|
-
*
|
|
1867
|
+
* 把画布绝对坐标转为当前控件坐标系内
|
|
1868
|
+
*
|
|
1869
|
+
* @method toLocalPosition
|
|
1870
|
+
* @param {Object} point - 绝对坐标
|
|
1871
|
+
* @returns {Object|false} 相对坐标,如果无法转换返回 false
|
|
1872
|
+
*
|
|
1873
|
+
* @example
|
|
1874
|
+
* const localPoint = control.toLocalPosition({x: 100, y: 100});
|
|
1318
1875
|
*/
|
|
1319
1876
|
|
|
1320
1877
|
}, {
|
|
@@ -1329,9 +1886,21 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1329
1886
|
}
|
|
1330
1887
|
/**
|
|
1331
1888
|
* 画控件前初始化
|
|
1332
|
-
*
|
|
1889
|
+
*
|
|
1890
|
+
* 执行 beginPath 开始控件的绘制路径。
|
|
1891
|
+
* 重置位置信息缓存,确保使用最新的位置数据。
|
|
1333
1892
|
*
|
|
1334
1893
|
* @method beginDraw
|
|
1894
|
+
* @protected
|
|
1895
|
+
*
|
|
1896
|
+
* @example
|
|
1897
|
+
* // 子类重写时需要调用父类方法
|
|
1898
|
+
* class MyShape extends jmControl {
|
|
1899
|
+
* beginDraw() {
|
|
1900
|
+
* super.beginDraw();
|
|
1901
|
+
* // 自定义初始化逻辑
|
|
1902
|
+
* }
|
|
1903
|
+
* }
|
|
1335
1904
|
*/
|
|
1336
1905
|
|
|
1337
1906
|
}, {
|
|
@@ -1344,8 +1913,18 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1344
1913
|
}
|
|
1345
1914
|
/**
|
|
1346
1915
|
* 结束控件绘制
|
|
1347
|
-
*
|
|
1916
|
+
*
|
|
1917
|
+
* 根据样式执行 fill 或 stroke 操作。
|
|
1918
|
+
* 如果设置了 close 样式,会先闭合路径。
|
|
1919
|
+
*
|
|
1348
1920
|
* @method endDraw
|
|
1921
|
+
* @protected
|
|
1922
|
+
*
|
|
1923
|
+
* @example
|
|
1924
|
+
* // 绘制流程
|
|
1925
|
+
* control.beginDraw();
|
|
1926
|
+
* control.draw();
|
|
1927
|
+
* control.endDraw();
|
|
1349
1928
|
*/
|
|
1350
1929
|
|
|
1351
1930
|
}, {
|
|
@@ -1388,10 +1967,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1388
1967
|
this.needUpdate = false;
|
|
1389
1968
|
}
|
|
1390
1969
|
/**
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1970
|
+
* 绘制控件路径
|
|
1971
|
+
*
|
|
1972
|
+
* 在画布上绘制控件的路径点。
|
|
1973
|
+
* 子类应该重写此方法实现自定义绘制逻辑。
|
|
1393
1974
|
*
|
|
1394
1975
|
* @method draw
|
|
1976
|
+
* @protected
|
|
1977
|
+
*
|
|
1978
|
+
* @example
|
|
1979
|
+
* // 子类重写绘制方法
|
|
1980
|
+
* class MyShape extends jmControl {
|
|
1981
|
+
* draw() {
|
|
1982
|
+
* const ctx = this.context;
|
|
1983
|
+
* ctx.moveTo(0, 0);
|
|
1984
|
+
* ctx.lineTo(100, 100);
|
|
1985
|
+
* // ... 更多绘制逻辑
|
|
1986
|
+
* }
|
|
1987
|
+
* }
|
|
1395
1988
|
*/
|
|
1396
1989
|
|
|
1397
1990
|
}, {
|
|
@@ -1421,10 +2014,23 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1421
2014
|
}
|
|
1422
2015
|
}
|
|
1423
2016
|
/**
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
2017
|
+
* 绘制当前控件及其子控件
|
|
2018
|
+
*
|
|
2019
|
+
* 协调控件的绘制流程:
|
|
2020
|
+
* 1. 检查可见性
|
|
2021
|
+
* 2. 初始化点数据
|
|
2022
|
+
* 3. 计算边界
|
|
2023
|
+
* 4. 应用样式
|
|
2024
|
+
* 5. 绘制自身
|
|
2025
|
+
* 6. 绘制子控件
|
|
2026
|
+
* 7. 触发事件
|
|
2027
|
+
*
|
|
1427
2028
|
* @method paint
|
|
2029
|
+
* @param {boolean} [v] - 是否可见,false 时跳过绘制
|
|
2030
|
+
*
|
|
2031
|
+
* @example
|
|
2032
|
+
* // 手动触发重绘
|
|
2033
|
+
* control.paint();
|
|
1428
2034
|
*/
|
|
1429
2035
|
|
|
1430
2036
|
}, {
|
|
@@ -1498,12 +2104,19 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1498
2104
|
}
|
|
1499
2105
|
}
|
|
1500
2106
|
/**
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
2107
|
+
* 获取指定事件的监听器集合
|
|
2108
|
+
*
|
|
2109
|
+
* 返回绑定到指定事件名称的所有事件处理函数。
|
|
2110
|
+
*
|
|
1504
2111
|
* @method getEvent
|
|
1505
|
-
* @param {string} name
|
|
1506
|
-
* @
|
|
2112
|
+
* @param {string} name - 事件名称(如 'click', 'mousedown')
|
|
2113
|
+
* @returns {jmList|null} 事件处理函数集合,不存在则返回 null
|
|
2114
|
+
*
|
|
2115
|
+
* @example
|
|
2116
|
+
* const handlers = control.getEvent('click');
|
|
2117
|
+
* if(handlers) {
|
|
2118
|
+
* console.log(`有 ${handlers.count()} 个点击事件处理器`);
|
|
2119
|
+
* }
|
|
1507
2120
|
*/
|
|
1508
2121
|
|
|
1509
2122
|
}, {
|
|
@@ -1512,11 +2125,31 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1512
2125
|
return this.__events ? this.__events[name] : null;
|
|
1513
2126
|
}
|
|
1514
2127
|
/**
|
|
1515
|
-
*
|
|
1516
|
-
*
|
|
2128
|
+
* 绑定控件事件
|
|
2129
|
+
*
|
|
2130
|
+
* 为控件添加事件监听器。支持同时绑定多个事件(用空格分隔)。
|
|
2131
|
+
* 同一个处理函数不会被重复添加。
|
|
2132
|
+
*
|
|
1517
2133
|
* @method bind
|
|
1518
|
-
* @param {string} name
|
|
1519
|
-
* @param {
|
|
2134
|
+
* @param {string} name - 事件名称,多个事件用空格分隔
|
|
2135
|
+
* @param {Function} handle - 事件处理函数
|
|
2136
|
+
* @returns {void}
|
|
2137
|
+
*
|
|
2138
|
+
* @example
|
|
2139
|
+
* // 绑定单个事件
|
|
2140
|
+
* control.bind('click', (evt) => {
|
|
2141
|
+
* console.log('被点击了', evt);
|
|
2142
|
+
* });
|
|
2143
|
+
*
|
|
2144
|
+
* // 绑定多个事件
|
|
2145
|
+
* control.bind('mousedown mouseup', (evt) => {
|
|
2146
|
+
* console.log('鼠标事件', evt);
|
|
2147
|
+
* });
|
|
2148
|
+
*
|
|
2149
|
+
* // 使用 on 别名
|
|
2150
|
+
* control.on('mousemove', (evt) => {
|
|
2151
|
+
* console.log('鼠标移动', evt.position);
|
|
2152
|
+
* });
|
|
1520
2153
|
*/
|
|
1521
2154
|
|
|
1522
2155
|
}, {
|
|
@@ -1561,11 +2194,23 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1561
2194
|
}
|
|
1562
2195
|
}
|
|
1563
2196
|
/**
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1568
|
-
* @
|
|
2197
|
+
* 移除控件事件
|
|
2198
|
+
*
|
|
2199
|
+
* 移除已绑定的事件处理函数。如果不指定处理函数,则移除该事件的所有处理函数。
|
|
2200
|
+
*
|
|
2201
|
+
* @method unbind
|
|
2202
|
+
* @param {string} name - 事件名称,多个事件用空格分隔
|
|
2203
|
+
* @param {Function} [handle] - 要移除的事件处理函数,不指定则移除所有
|
|
2204
|
+
*
|
|
2205
|
+
* @example
|
|
2206
|
+
* // 移除特定处理函数
|
|
2207
|
+
* control.unbind('click', myHandler);
|
|
2208
|
+
*
|
|
2209
|
+
* // 移除所有点击事件
|
|
2210
|
+
* control.unbind('click');
|
|
2211
|
+
*
|
|
2212
|
+
* // 移除多个事件
|
|
2213
|
+
* control.unbind('mousedown mouseup');
|
|
1569
2214
|
*/
|
|
1570
2215
|
|
|
1571
2216
|
}, {
|
|
@@ -1598,12 +2243,22 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1598
2243
|
}
|
|
1599
2244
|
}
|
|
1600
2245
|
/**
|
|
1601
|
-
*
|
|
2246
|
+
* 触发事件
|
|
2247
|
+
*
|
|
2248
|
+
* 执行指定事件的所有监听器。
|
|
2249
|
+
* 支持传递多个参数给事件处理函数。
|
|
1602
2250
|
*
|
|
1603
2251
|
* @method emit
|
|
1604
|
-
* @
|
|
1605
|
-
* @param {
|
|
1606
|
-
* @
|
|
2252
|
+
* @param {string} name - 事件名称
|
|
2253
|
+
* @param {...*} args - 传递给事件处理函数的参数
|
|
2254
|
+
* @returns {jmControl} 返回 this 以支持链式调用
|
|
2255
|
+
*
|
|
2256
|
+
* @example
|
|
2257
|
+
* // 触发自定义事件
|
|
2258
|
+
* control.emit('customEvent', { data: 'value' });
|
|
2259
|
+
*
|
|
2260
|
+
* // 触发带多个参数的事件
|
|
2261
|
+
* control.emit('dataChange', oldValue, newValue);
|
|
1607
2262
|
*/
|
|
1608
2263
|
|
|
1609
2264
|
}, {
|
|
@@ -1626,11 +2281,16 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1626
2281
|
return this;
|
|
1627
2282
|
}
|
|
1628
2283
|
/**
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
2284
|
+
* 执行事件处理函数
|
|
2285
|
+
*
|
|
2286
|
+
* 内部方法,用于执行指定事件的所有监听器。
|
|
2287
|
+
* 如果任一处理函数返回 false,会设置 args.cancel = true。
|
|
2288
|
+
*
|
|
1631
2289
|
* @method runEventHandle
|
|
1632
|
-
* @param {string}
|
|
1633
|
-
* @param {
|
|
2290
|
+
* @param {string} name - 事件名称
|
|
2291
|
+
* @param {Array|Object} args - 事件参数
|
|
2292
|
+
* @returns {boolean} 是否被取消
|
|
2293
|
+
* @protected
|
|
1634
2294
|
*/
|
|
1635
2295
|
|
|
1636
2296
|
}, {
|
|
@@ -1652,12 +2312,25 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1652
2312
|
return args.cancel;
|
|
1653
2313
|
}
|
|
1654
2314
|
/**
|
|
1655
|
-
*
|
|
1656
|
-
*
|
|
2315
|
+
* 检查坐标是否落在当前控件区域中
|
|
2316
|
+
*
|
|
2317
|
+
* 用于点击测试和碰撞检测。
|
|
2318
|
+
* 支持旋转后的碰撞检测,以及自定义命中区域。
|
|
2319
|
+
*
|
|
1657
2320
|
* @method checkPoint
|
|
1658
|
-
* @param {
|
|
1659
|
-
* @param {number}
|
|
1660
|
-
* @
|
|
2321
|
+
* @param {Object} p - 要检测的点坐标
|
|
2322
|
+
* @param {number} p.x - X 坐标
|
|
2323
|
+
* @param {number} p.y - Y 坐标
|
|
2324
|
+
* @param {number} [pad] - 容差范围,默认使用 lineWidth 或 1
|
|
2325
|
+
* @returns {boolean} 点是否在控件区域内
|
|
2326
|
+
*
|
|
2327
|
+
* @example
|
|
2328
|
+
* // 检查点击位置
|
|
2329
|
+
* graph.bind('click', (evt) => {
|
|
2330
|
+
* if(control.checkPoint(evt.position)) {
|
|
2331
|
+
* console.log('点击了控件');
|
|
2332
|
+
* }
|
|
2333
|
+
* });
|
|
1661
2334
|
*/
|
|
1662
2335
|
|
|
1663
2336
|
}, {
|
|
@@ -1666,16 +2339,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1666
2339
|
//jmGraph 需要判断dom位置
|
|
1667
2340
|
if (this.type == 'jmGraph') {
|
|
1668
2341
|
//获取dom位置
|
|
1669
|
-
var position = this.getPosition();
|
|
1670
|
-
|
|
1671
|
-
var right = position.left + this.width;
|
|
1672
|
-
var bottom = position.top + this.height;
|
|
2342
|
+
var position = this.getPosition();
|
|
1673
2343
|
|
|
1674
|
-
if (p.
|
|
2344
|
+
if (p.pageX > position.right || p.pageX < position.left) {
|
|
1675
2345
|
return false;
|
|
1676
2346
|
}
|
|
1677
2347
|
|
|
1678
|
-
if (p.
|
|
2348
|
+
if (p.pageY > position.bottom || p.pageY < position.top) {
|
|
1679
2349
|
return false;
|
|
1680
2350
|
}
|
|
1681
2351
|
|
|
@@ -1793,12 +2463,19 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1793
2463
|
return true;
|
|
1794
2464
|
}
|
|
1795
2465
|
/**
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
2466
|
+
* 触发控件事件并执行事件冒泡
|
|
2467
|
+
*
|
|
2468
|
+
* 组合事件参数,按控件层级关系执行事件冒泡。
|
|
2469
|
+
* 事件从最上层的子控件开始触发,向上冒泡到父控件。
|
|
2470
|
+
*
|
|
1798
2471
|
* @method raiseEvent
|
|
1799
|
-
* @param {string} name 事件名称
|
|
1800
|
-
* @param {
|
|
1801
|
-
* @
|
|
2472
|
+
* @param {string} name - 事件名称
|
|
2473
|
+
* @param {Object} args - 原生事件对象
|
|
2474
|
+
* @returns {boolean} 如果事件被阻止冒泡则返回 false,否则返回 true
|
|
2475
|
+
*
|
|
2476
|
+
* @example
|
|
2477
|
+
* // 通常由框架内部调用,用户一般不需要直接调用
|
|
2478
|
+
* // 框架会自动处理鼠标/触摸事件
|
|
1802
2479
|
*/
|
|
1803
2480
|
|
|
1804
2481
|
}, {
|
|
@@ -1854,7 +2531,12 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1854
2531
|
args.position.x = args.position.offsetX - abounds.left;
|
|
1855
2532
|
args.position.y = args.position.offsetY - abounds.top; // 是否在当前控件内操作
|
|
1856
2533
|
|
|
1857
|
-
var inpos = this.interactive !== false && this.checkPoint(args.position);
|
|
2534
|
+
var inpos = this.interactive !== false && this.checkPoint(args.position);
|
|
2535
|
+
|
|
2536
|
+
if (name === 'mousemove' && this.type == 'jmGraph' && !inpos) {
|
|
2537
|
+
console.log('mousemove out', args.position, abounds);
|
|
2538
|
+
} //事件发生在边界内或健盘事件发生在画布中才触发
|
|
2539
|
+
|
|
1858
2540
|
|
|
1859
2541
|
if (inpos) {
|
|
1860
2542
|
//如果没有指定触发对象,则认为当前为第一触发对象
|
|
@@ -1881,9 +2563,14 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1881
2563
|
return args.cancel === false; //如果被阻止则返回false,否则返回true
|
|
1882
2564
|
}
|
|
1883
2565
|
/**
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
2566
|
+
* 执行事件并进行冒泡
|
|
2567
|
+
*
|
|
2568
|
+
* 内部方法,用于执行事件处理并添加到事件路径。
|
|
2569
|
+
*
|
|
2570
|
+
* @method runEventAndPopEvent
|
|
2571
|
+
* @param {string} name - 事件名称
|
|
2572
|
+
* @param {Object} args - 事件参数
|
|
2573
|
+
* @protected
|
|
1887
2574
|
*/
|
|
1888
2575
|
|
|
1889
2576
|
}, {
|
|
@@ -1908,9 +2595,15 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1908
2595
|
}
|
|
1909
2596
|
/**
|
|
1910
2597
|
* 清空控件指定事件
|
|
1911
|
-
*
|
|
2598
|
+
*
|
|
2599
|
+
* 移除指定事件名称下的所有事件处理函数。
|
|
2600
|
+
*
|
|
1912
2601
|
* @method clearEvents
|
|
1913
|
-
* @param {string} name 需要清除的事件名称
|
|
2602
|
+
* @param {string} name - 需要清除的事件名称
|
|
2603
|
+
*
|
|
2604
|
+
* @example
|
|
2605
|
+
* // 清除所有点击事件
|
|
2606
|
+
* control.clearEvents('click');
|
|
1914
2607
|
*/
|
|
1915
2608
|
|
|
1916
2609
|
}, {
|
|
@@ -1919,15 +2612,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1919
2612
|
var eventCollection = this.getEvent(name);
|
|
1920
2613
|
|
|
1921
2614
|
if (eventCollection) {
|
|
1922
|
-
eventCollection.clear;
|
|
2615
|
+
eventCollection.clear();
|
|
1923
2616
|
}
|
|
1924
2617
|
}
|
|
1925
2618
|
/**
|
|
1926
|
-
*
|
|
1927
|
-
*
|
|
1928
|
-
*
|
|
1929
|
-
*
|
|
1930
|
-
* @
|
|
2619
|
+
* 查找指定类型的父级控件
|
|
2620
|
+
*
|
|
2621
|
+
* 沿着父级链向上查找,直到找到指定类型的控件或到达最顶级。
|
|
2622
|
+
*
|
|
2623
|
+
* @method findParent
|
|
2624
|
+
* @param {string|Function} type - 类型名称(字符串)或类构造函数
|
|
2625
|
+
* @returns {jmControl|null} 找到的父级控件实例,未找到返回 null
|
|
2626
|
+
*
|
|
2627
|
+
* @example
|
|
2628
|
+
* // 查找 jmGraph 实例
|
|
2629
|
+
* const graph = control.findParent('jmGraph');
|
|
2630
|
+
*
|
|
2631
|
+
* // 查找特定类的实例
|
|
2632
|
+
* const parent = control.findParent(MyCustomControl);
|
|
1931
2633
|
*/
|
|
1932
2634
|
|
|
1933
2635
|
}, {
|
|
@@ -1947,12 +2649,26 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1947
2649
|
return null;
|
|
1948
2650
|
}
|
|
1949
2651
|
/**
|
|
1950
|
-
*
|
|
1951
|
-
*
|
|
1952
|
-
*
|
|
2652
|
+
* 设置控件是否可拖动
|
|
2653
|
+
*
|
|
2654
|
+
* 启用或禁用控件的拖动功能。
|
|
2655
|
+
* 拖动时会触发 movestart、move、moveend 事件。
|
|
2656
|
+
*
|
|
1953
2657
|
* @method canMove
|
|
1954
|
-
* @param {boolean} m true
|
|
1955
|
-
* @param {jmGraph} [graph]
|
|
2658
|
+
* @param {boolean} m - true 启用拖动,false 禁用拖动
|
|
2659
|
+
* @param {jmGraph} [graph] - 画布实例,如果控件已添加到画布可省略
|
|
2660
|
+
* @returns {jmControl} 返回 this 以支持链式调用
|
|
2661
|
+
*
|
|
2662
|
+
* @example
|
|
2663
|
+
* // 启用拖动
|
|
2664
|
+
* control.canMove(true);
|
|
2665
|
+
*
|
|
2666
|
+
* // 禁用拖动
|
|
2667
|
+
* control.canMove(false);
|
|
2668
|
+
*
|
|
2669
|
+
* // 监听拖动事件
|
|
2670
|
+
* control.on('movestart', (evt) => console.log('开始拖动'));
|
|
2671
|
+
* control.on('moveend', (evt) => console.log('结束拖动'));
|
|
1956
2672
|
*/
|
|
1957
2673
|
|
|
1958
2674
|
}, {
|
|
@@ -2022,7 +2738,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
2022
2738
|
_this.offset(offsetx, offsety, true, evt);
|
|
2023
2739
|
|
|
2024
2740
|
if (offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
|
|
2025
|
-
if (offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY; //console.log(offsetx + '.' + offsety);
|
|
2741
|
+
if (offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY; //console.log('mouse move',offsetx + '.' + offsety);
|
|
2026
2742
|
}
|
|
2027
2743
|
|
|
2028
2744
|
return false;
|
|
@@ -2146,15 +2862,63 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
2146
2862
|
|
|
2147
2863
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2148
2864
|
|
|
2865
|
+
/**
|
|
2866
|
+
* jmEvents 事件处理类
|
|
2867
|
+
*
|
|
2868
|
+
* 统一管理画布上的所有交互事件,包括鼠标、触摸和键盘事件。
|
|
2869
|
+
* 支持事件冒泡机制,可以将事件传递给子控件处理。
|
|
2870
|
+
*
|
|
2871
|
+
* @class jmEvents
|
|
2872
|
+
*
|
|
2873
|
+
* @param {jmGraph} container jmGraph 实例
|
|
2874
|
+
* @param {HTMLElement} target 事件目标元素(通常是 canvas 元素)
|
|
2875
|
+
*
|
|
2876
|
+
* @example
|
|
2877
|
+
* // 通常由 jmGraph 内部创建,不需要手动实例化
|
|
2878
|
+
* const events = new jmEvents(graph, canvasElement);
|
|
2879
|
+
*/
|
|
2149
2880
|
var jmEvents = /*#__PURE__*/function () {
|
|
2881
|
+
/**
|
|
2882
|
+
* 构造函数
|
|
2883
|
+
*
|
|
2884
|
+
* @param {jmGraph} container jmGraph 实例
|
|
2885
|
+
* @param {HTMLElement} target 事件目标元素
|
|
2886
|
+
*/
|
|
2150
2887
|
function jmEvents(container, target) {
|
|
2151
2888
|
_classCallCheck(this, jmEvents);
|
|
2152
2889
|
|
|
2890
|
+
/**
|
|
2891
|
+
* jmGraph 实例
|
|
2892
|
+
* @type {jmGraph}
|
|
2893
|
+
*/
|
|
2153
2894
|
this.container = container;
|
|
2895
|
+
/**
|
|
2896
|
+
* 事件目标元素
|
|
2897
|
+
* @type {HTMLElement}
|
|
2898
|
+
*/
|
|
2899
|
+
|
|
2154
2900
|
this.target = target || container;
|
|
2901
|
+
/**
|
|
2902
|
+
* 鼠标事件处理器
|
|
2903
|
+
* @type {jmMouseEvent}
|
|
2904
|
+
*/
|
|
2905
|
+
|
|
2155
2906
|
this.mouseHandler = new jmMouseEvent(this, container, target);
|
|
2907
|
+
/**
|
|
2908
|
+
* 键盘事件处理器
|
|
2909
|
+
* @type {jmKeyEvent}
|
|
2910
|
+
*/
|
|
2911
|
+
|
|
2156
2912
|
this.keyHandler = new jmKeyEvent(this, container, target);
|
|
2157
2913
|
}
|
|
2914
|
+
/**
|
|
2915
|
+
* 触摸开始事件处理
|
|
2916
|
+
*
|
|
2917
|
+
* @method touchStart
|
|
2918
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2919
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2920
|
+
*/
|
|
2921
|
+
|
|
2158
2922
|
|
|
2159
2923
|
_createClass(jmEvents, [{
|
|
2160
2924
|
key: "touchStart",
|
|
@@ -2170,7 +2934,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2170
2934
|
}
|
|
2171
2935
|
}, {
|
|
2172
2936
|
key: "touchMove",
|
|
2173
|
-
value:
|
|
2937
|
+
value:
|
|
2938
|
+
/**
|
|
2939
|
+
* 触摸移动事件处理
|
|
2940
|
+
*
|
|
2941
|
+
* @method touchMove
|
|
2942
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2943
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2944
|
+
*/
|
|
2945
|
+
function touchMove(evt) {
|
|
2174
2946
|
evt = evt || window.event;
|
|
2175
2947
|
evt.eventName = 'touchmove';
|
|
2176
2948
|
this.container.raiseEvent('touchmove', evt);
|
|
@@ -2182,7 +2954,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2182
2954
|
}
|
|
2183
2955
|
}, {
|
|
2184
2956
|
key: "touchEnd",
|
|
2185
|
-
value:
|
|
2957
|
+
value:
|
|
2958
|
+
/**
|
|
2959
|
+
* 触摸结束事件处理
|
|
2960
|
+
*
|
|
2961
|
+
* @method touchEnd
|
|
2962
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2963
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2964
|
+
*/
|
|
2965
|
+
function touchEnd(evt) {
|
|
2186
2966
|
evt = evt || window.event;
|
|
2187
2967
|
evt.eventName = 'touchend';
|
|
2188
2968
|
this.container.raiseEvent('touchend', evt);
|
|
@@ -2194,7 +2974,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2194
2974
|
}
|
|
2195
2975
|
}, {
|
|
2196
2976
|
key: "touchCancel",
|
|
2197
|
-
value:
|
|
2977
|
+
value:
|
|
2978
|
+
/**
|
|
2979
|
+
* 触摸取消事件处理
|
|
2980
|
+
*
|
|
2981
|
+
* @method touchCancel
|
|
2982
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2983
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2984
|
+
*/
|
|
2985
|
+
function touchCancel(evt) {
|
|
2198
2986
|
evt = evt || window.event;
|
|
2199
2987
|
evt.eventName = 'touchcancel';
|
|
2200
2988
|
this.container.raiseEvent('touchcancel', evt);
|
|
@@ -2206,7 +2994,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2206
2994
|
}
|
|
2207
2995
|
}, {
|
|
2208
2996
|
key: "tap",
|
|
2209
|
-
value:
|
|
2997
|
+
value:
|
|
2998
|
+
/**
|
|
2999
|
+
* 轻触事件处理
|
|
3000
|
+
*
|
|
3001
|
+
* @method tap
|
|
3002
|
+
* @param {Event} evt 事件对象
|
|
3003
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
3004
|
+
*/
|
|
3005
|
+
function tap(evt) {
|
|
2210
3006
|
evt = evt || window.event;
|
|
2211
3007
|
evt.eventName = 'tap';
|
|
2212
3008
|
this.container.raiseEvent('tap', evt);
|
|
@@ -2218,7 +3014,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2218
3014
|
}
|
|
2219
3015
|
}, {
|
|
2220
3016
|
key: "destroy",
|
|
2221
|
-
value:
|
|
3017
|
+
value:
|
|
3018
|
+
/**
|
|
3019
|
+
* 销毁事件处理器
|
|
3020
|
+
*
|
|
3021
|
+
* 移除所有绑定的事件监听器,释放资源。
|
|
3022
|
+
*
|
|
3023
|
+
* @method destroy
|
|
3024
|
+
*/
|
|
3025
|
+
function destroy() {
|
|
2222
3026
|
this.mouseHandler.destroy();
|
|
2223
3027
|
this.keyHandler.destroy();
|
|
2224
3028
|
}
|
|
@@ -2226,19 +3030,48 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2226
3030
|
|
|
2227
3031
|
return jmEvents;
|
|
2228
3032
|
}();
|
|
3033
|
+
/**
|
|
3034
|
+
* 鼠标事件处理器
|
|
3035
|
+
*
|
|
3036
|
+
* @class jmMouseEvent
|
|
3037
|
+
* @private
|
|
3038
|
+
*/
|
|
3039
|
+
|
|
2229
3040
|
|
|
2230
3041
|
exports.jmEvents = exports["default"] = jmEvents;
|
|
2231
3042
|
|
|
2232
3043
|
var jmMouseEvent = /*#__PURE__*/function () {
|
|
3044
|
+
/**
|
|
3045
|
+
* 构造函数
|
|
3046
|
+
*
|
|
3047
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3048
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3049
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3050
|
+
*/
|
|
2233
3051
|
function jmMouseEvent(instance, container, target) {
|
|
2234
3052
|
_classCallCheck(this, jmMouseEvent);
|
|
2235
3053
|
|
|
2236
3054
|
this.instance = instance;
|
|
2237
3055
|
this.container = container;
|
|
2238
3056
|
this.target = target || container;
|
|
3057
|
+
/**
|
|
3058
|
+
* 已绑定的事件映射表
|
|
3059
|
+
* @type {Object}
|
|
3060
|
+
*/
|
|
3061
|
+
|
|
2239
3062
|
this.eventEvents = {};
|
|
2240
3063
|
this.init(instance, container, target);
|
|
2241
3064
|
}
|
|
3065
|
+
/**
|
|
3066
|
+
* 初始化鼠标事件绑定
|
|
3067
|
+
*
|
|
3068
|
+
* @method init
|
|
3069
|
+
* @private
|
|
3070
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3071
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3072
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3073
|
+
*/
|
|
3074
|
+
|
|
2242
3075
|
|
|
2243
3076
|
_createClass(jmMouseEvent, [{
|
|
2244
3077
|
key: "init",
|
|
@@ -2326,6 +3159,14 @@ var jmMouseEvent = /*#__PURE__*/function () {
|
|
|
2326
3159
|
passive: false
|
|
2327
3160
|
}));
|
|
2328
3161
|
}
|
|
3162
|
+
/**
|
|
3163
|
+
* 销毁鼠标事件处理器
|
|
3164
|
+
*
|
|
3165
|
+
* 移除所有绑定的鼠标事件监听器。
|
|
3166
|
+
*
|
|
3167
|
+
* @method destroy
|
|
3168
|
+
*/
|
|
3169
|
+
|
|
2329
3170
|
}, {
|
|
2330
3171
|
key: "destroy",
|
|
2331
3172
|
value: function destroy() {
|
|
@@ -2340,17 +3181,45 @@ var jmMouseEvent = /*#__PURE__*/function () {
|
|
|
2340
3181
|
|
|
2341
3182
|
return jmMouseEvent;
|
|
2342
3183
|
}();
|
|
3184
|
+
/**
|
|
3185
|
+
* 键盘事件处理器
|
|
3186
|
+
*
|
|
3187
|
+
* @class jmKeyEvent
|
|
3188
|
+
* @private
|
|
3189
|
+
*/
|
|
3190
|
+
|
|
2343
3191
|
|
|
2344
3192
|
var jmKeyEvent = /*#__PURE__*/function () {
|
|
3193
|
+
/**
|
|
3194
|
+
* 构造函数
|
|
3195
|
+
*
|
|
3196
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3197
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3198
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3199
|
+
*/
|
|
2345
3200
|
function jmKeyEvent(instance, container, target) {
|
|
2346
3201
|
_classCallCheck(this, jmKeyEvent);
|
|
2347
3202
|
|
|
2348
3203
|
this.instance = instance;
|
|
2349
3204
|
this.container = container;
|
|
2350
3205
|
this.target = target || container;
|
|
3206
|
+
/**
|
|
3207
|
+
* 已绑定的事件映射表
|
|
3208
|
+
* @type {Object}
|
|
3209
|
+
*/
|
|
3210
|
+
|
|
2351
3211
|
this.eventEvents = {};
|
|
2352
3212
|
this.init(container, target);
|
|
2353
3213
|
}
|
|
3214
|
+
/**
|
|
3215
|
+
* 初始化键盘事件绑定
|
|
3216
|
+
*
|
|
3217
|
+
* @method init
|
|
3218
|
+
* @private
|
|
3219
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3220
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3221
|
+
*/
|
|
3222
|
+
|
|
2354
3223
|
|
|
2355
3224
|
_createClass(jmKeyEvent, [{
|
|
2356
3225
|
key: "init",
|
|
@@ -2423,13 +3292,28 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
2423
3292
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2424
3293
|
|
|
2425
3294
|
/**
|
|
2426
|
-
* CSS滤镜效果类
|
|
3295
|
+
* CSS 滤镜效果类
|
|
3296
|
+
*
|
|
2427
3297
|
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
2428
3298
|
*
|
|
2429
3299
|
* @class jmFilter
|
|
2430
3300
|
* @param {string|object} opt 滤镜参数
|
|
2431
3301
|
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
2432
3302
|
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
3303
|
+
*
|
|
3304
|
+
* @example
|
|
3305
|
+
* // 从字符串创建
|
|
3306
|
+
* const filter = new jmFilter('blur(2px) grayscale(50%)');
|
|
3307
|
+
*
|
|
3308
|
+
* // 从对象创建
|
|
3309
|
+
* const filter = new jmFilter({
|
|
3310
|
+
* blur: 2,
|
|
3311
|
+
* grayscale: 0.5,
|
|
3312
|
+
* brightness: 1.2
|
|
3313
|
+
* });
|
|
3314
|
+
*
|
|
3315
|
+
* // 应用到图形
|
|
3316
|
+
* shape.style.filter = filter;
|
|
2433
3317
|
*/
|
|
2434
3318
|
var jmFilter = /*#__PURE__*/function () {
|
|
2435
3319
|
function jmFilter(opt) {
|
|
@@ -2641,9 +3525,36 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
2641
3525
|
|
|
2642
3526
|
/**
|
|
2643
3527
|
* 渐变类
|
|
2644
|
-
*
|
|
3528
|
+
*
|
|
3529
|
+
* 用于创建和管理线性渐变或径向渐变效果。
|
|
3530
|
+
* 支持 CSS 渐变字符串格式解析,可以转换为 Canvas 或 WebGL 兼容的渐变对象。
|
|
3531
|
+
*
|
|
2645
3532
|
* @class jmGradient
|
|
2646
|
-
*
|
|
3533
|
+
*
|
|
3534
|
+
* @param {Object|string} opt 渐变参数对象或 CSS 渐变字符串
|
|
3535
|
+
* @param {string} [opt.type='linear'] 渐变类型:'linear' 或 'radial'
|
|
3536
|
+
* @param {number|string} [opt.x1] 起点X坐标(支持百分比)
|
|
3537
|
+
* @param {number|string} [opt.y1] 起点Y坐标(支持百分比)
|
|
3538
|
+
* @param {number|string} [opt.x2] 终点X坐标(支持百分比)
|
|
3539
|
+
* @param {number|string} [opt.y2] 终点Y坐标(支持百分比)
|
|
3540
|
+
* @param {number|string} [opt.r1] 内圆半径(径向渐变)
|
|
3541
|
+
* @param {number|string} [opt.r2] 外圆半径(径向渐变)
|
|
3542
|
+
* @param {Array} [opt.stops] 颜色停止点数组 [{offset, color}, ...]
|
|
3543
|
+
*
|
|
3544
|
+
* @example
|
|
3545
|
+
* // 创建线性渐变
|
|
3546
|
+
* const gradient = new jmGradient({
|
|
3547
|
+
* type: 'linear',
|
|
3548
|
+
* x1: 0, y1: 0,
|
|
3549
|
+
* x2: '100%', y2: '100%',
|
|
3550
|
+
* stops: [
|
|
3551
|
+
* { offset: 0, color: '#ff0000' },
|
|
3552
|
+
* { offset: 1, color: '#0000ff' }
|
|
3553
|
+
* ]
|
|
3554
|
+
* });
|
|
3555
|
+
*
|
|
3556
|
+
* // 从 CSS 字符串创建
|
|
3557
|
+
* const gradient = new jmGradient('linear-gradient(180deg, #ff0000, #0000ff)');
|
|
2647
3558
|
*/
|
|
2648
3559
|
var jmGradient = /*#__PURE__*/function () {
|
|
2649
3560
|
function jmGradient(opt) {
|
|
@@ -3672,15 +4583,39 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
3672
4583
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
3673
4584
|
|
|
3674
4585
|
/**
|
|
3675
|
-
* jmGraph
|
|
3676
|
-
*
|
|
3677
|
-
*
|
|
3678
|
-
*
|
|
4586
|
+
* jmGraph 画图类
|
|
4587
|
+
*
|
|
4588
|
+
* 对 Canvas 画图 API 进行二次封装,使其更易调用,省去很多重复的工作。
|
|
4589
|
+
* 支持多种图形的创建、渲染、交互和导出。
|
|
4590
|
+
*
|
|
3679
4591
|
* @class jmGraph
|
|
3680
4592
|
* @extends jmControl
|
|
3681
|
-
*
|
|
3682
|
-
* @param {
|
|
3683
|
-
* @param {
|
|
4593
|
+
*
|
|
4594
|
+
* @param {HTMLElement|string} canvas Canvas 元素或元素 ID
|
|
4595
|
+
* @param {Object} [option] 配置选项
|
|
4596
|
+
* @param {number} [option.width] 画布宽度
|
|
4597
|
+
* @param {number} [option.height] 画布高度
|
|
4598
|
+
* @param {string} [option.mode='2d'] 渲染模式:'2d' 或 'webgl'
|
|
4599
|
+
* @param {boolean} [option.autoRefresh=false] 是否自动刷新
|
|
4600
|
+
* @param {Object} [option.shapes] 自定义图形类型映射
|
|
4601
|
+
* @param {function} [callback] 初始化完成后的回调函数
|
|
4602
|
+
*
|
|
4603
|
+
* @example
|
|
4604
|
+
* // 创建画布实例
|
|
4605
|
+
* const graph = new jmGraph('canvasId', {
|
|
4606
|
+
* width: 800,
|
|
4607
|
+
* height: 600,
|
|
4608
|
+
* mode: '2d'
|
|
4609
|
+
* });
|
|
4610
|
+
*
|
|
4611
|
+
* // 创建一个矩形
|
|
4612
|
+
* const rect = graph.createShape('rect', {
|
|
4613
|
+
* x: 100, y: 100,
|
|
4614
|
+
* width: 200, height: 150,
|
|
4615
|
+
* style: { fill: '#ff0000' }
|
|
4616
|
+
* });
|
|
4617
|
+
* graph.children.add(rect);
|
|
4618
|
+
* graph.refresh();
|
|
3684
4619
|
*/
|
|
3685
4620
|
var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
3686
4621
|
_inherits(jmGraph, _jmControl);
|
|
@@ -4580,11 +5515,61 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
4580
5515
|
|
|
4581
5516
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4582
5517
|
|
|
5518
|
+
/**
|
|
5519
|
+
* @fileoverview jmList 列表类
|
|
5520
|
+
*
|
|
5521
|
+
* jmList 是 jmGraph 库的集合类,继承自原生 Array。
|
|
5522
|
+
* 提供了增强的列表操作方法,包括去重添加、条件查找、遍历等。
|
|
5523
|
+
*
|
|
5524
|
+
* 主要功能:
|
|
5525
|
+
* - 去重添加元素(add)
|
|
5526
|
+
* - 条件查找(get)
|
|
5527
|
+
* - 正向/反向遍历(each)
|
|
5528
|
+
* - 元素计数(count)
|
|
5529
|
+
* - 移除回调支持
|
|
5530
|
+
*
|
|
5531
|
+
* @module jmList
|
|
5532
|
+
* @author jmGraph Team
|
|
5533
|
+
* @license MIT
|
|
5534
|
+
*/
|
|
5535
|
+
|
|
5536
|
+
/**
|
|
5537
|
+
* jmList 列表类
|
|
5538
|
+
*
|
|
5539
|
+
* 继承自 Array 的增强列表类,提供去重、遍历、查找等功能。
|
|
5540
|
+
* 主要用于管理图形对象的子元素集合。
|
|
5541
|
+
*
|
|
5542
|
+
* @class jmList
|
|
5543
|
+
* @extends Array
|
|
5544
|
+
*
|
|
5545
|
+
* @param {...*} arg 初始元素或数组
|
|
5546
|
+
*
|
|
5547
|
+
* @example
|
|
5548
|
+
* // 创建列表
|
|
5549
|
+
* const list = new jmList([1, 2, 3]);
|
|
5550
|
+
*
|
|
5551
|
+
* // 添加元素(自动去重)
|
|
5552
|
+
* list.add(4);
|
|
5553
|
+
* list.add([5, 6]);
|
|
5554
|
+
*
|
|
5555
|
+
* // 遍历
|
|
5556
|
+
* list.each((index, item) => {
|
|
5557
|
+
* console.log(index, item);
|
|
5558
|
+
* });
|
|
5559
|
+
*
|
|
5560
|
+
* // 条件查找
|
|
5561
|
+
* const found = list.get(item => item > 3);
|
|
5562
|
+
*/
|
|
4583
5563
|
var jmList = /*#__PURE__*/function (_Array) {
|
|
4584
5564
|
_inherits(jmList, _Array);
|
|
4585
5565
|
|
|
4586
5566
|
var _super = _createSuper(jmList);
|
|
4587
5567
|
|
|
5568
|
+
/**
|
|
5569
|
+
* 构造函数
|
|
5570
|
+
*
|
|
5571
|
+
* @param {...*} arg 初始元素或数组
|
|
5572
|
+
*/
|
|
4588
5573
|
function jmList() {
|
|
4589
5574
|
var _this;
|
|
4590
5575
|
|
|
@@ -4605,11 +5590,37 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4605
5590
|
} else {
|
|
4606
5591
|
_this = _super.call(this);
|
|
4607
5592
|
}
|
|
5593
|
+
/**
|
|
5594
|
+
* 配置选项
|
|
5595
|
+
* @type {Object}
|
|
5596
|
+
* @property {function} removeHandler 元素移除时的回调函数
|
|
5597
|
+
*/
|
|
5598
|
+
|
|
4608
5599
|
|
|
4609
5600
|
_this.option = {};
|
|
5601
|
+
/**
|
|
5602
|
+
* 类型标识
|
|
5603
|
+
* @type {string}
|
|
5604
|
+
*/
|
|
5605
|
+
|
|
4610
5606
|
_this.type = 'jmList';
|
|
4611
5607
|
return _possibleConstructorReturn(_this);
|
|
4612
5608
|
}
|
|
5609
|
+
/**
|
|
5610
|
+
* 添加元素到列表
|
|
5611
|
+
*
|
|
5612
|
+
* 自动去重,如果元素已存在则不会重复添加。
|
|
5613
|
+
* 支持添加单个元素或数组。
|
|
5614
|
+
*
|
|
5615
|
+
* @method add
|
|
5616
|
+
* @param {*} obj 要添加的元素或数组
|
|
5617
|
+
* @returns {*} 添加的元素
|
|
5618
|
+
*
|
|
5619
|
+
* @example
|
|
5620
|
+
* list.add(1); // 添加单个元素
|
|
5621
|
+
* list.add([2, 3, 4]); // 添加数组
|
|
5622
|
+
*/
|
|
5623
|
+
|
|
4613
5624
|
|
|
4614
5625
|
_createClass(jmList, [{
|
|
4615
5626
|
key: "add",
|
|
@@ -4626,6 +5637,18 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4626
5637
|
this.push(obj);
|
|
4627
5638
|
return obj;
|
|
4628
5639
|
}
|
|
5640
|
+
/**
|
|
5641
|
+
* 从列表中移除元素
|
|
5642
|
+
*
|
|
5643
|
+
* 移除所有匹配的元素,并触发移除回调。
|
|
5644
|
+
*
|
|
5645
|
+
* @method remove
|
|
5646
|
+
* @param {*} obj 要移除的元素
|
|
5647
|
+
*
|
|
5648
|
+
* @example
|
|
5649
|
+
* list.remove(item);
|
|
5650
|
+
*/
|
|
5651
|
+
|
|
4629
5652
|
}, {
|
|
4630
5653
|
key: "remove",
|
|
4631
5654
|
value: function remove(obj) {
|
|
@@ -4635,6 +5658,16 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4635
5658
|
}
|
|
4636
5659
|
}
|
|
4637
5660
|
}
|
|
5661
|
+
/**
|
|
5662
|
+
* 移除指定索引位置的元素
|
|
5663
|
+
*
|
|
5664
|
+
* @method removeAt
|
|
5665
|
+
* @param {number} index 要移除的元素索引
|
|
5666
|
+
*
|
|
5667
|
+
* @example
|
|
5668
|
+
* list.removeAt(0); // 移除第一个元素
|
|
5669
|
+
*/
|
|
5670
|
+
|
|
4638
5671
|
}, {
|
|
4639
5672
|
key: "removeAt",
|
|
4640
5673
|
value: function removeAt(index) {
|
|
@@ -4644,11 +5677,42 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4644
5677
|
if (this.option.removeHandler) this.option.removeHandler.call(this, obj, index);
|
|
4645
5678
|
}
|
|
4646
5679
|
}
|
|
5680
|
+
/**
|
|
5681
|
+
* 检查列表是否包含指定元素
|
|
5682
|
+
*
|
|
5683
|
+
* @method contain
|
|
5684
|
+
* @param {*} obj 要检查的元素
|
|
5685
|
+
* @returns {boolean} 如果包含返回 true,否则返回 false
|
|
5686
|
+
*
|
|
5687
|
+
* @example
|
|
5688
|
+
* if (list.contain(item)) {
|
|
5689
|
+
* console.log('元素存在');
|
|
5690
|
+
* }
|
|
5691
|
+
*/
|
|
5692
|
+
|
|
4647
5693
|
}, {
|
|
4648
5694
|
key: "contain",
|
|
4649
5695
|
value: function contain(obj) {
|
|
4650
5696
|
return this.includes(obj);
|
|
4651
5697
|
}
|
|
5698
|
+
/**
|
|
5699
|
+
* 获取元素
|
|
5700
|
+
*
|
|
5701
|
+
* 如果参数是函数,则返回第一个满足条件的元素;
|
|
5702
|
+
* 如果参数是数字,则返回指定索引的元素。
|
|
5703
|
+
*
|
|
5704
|
+
* @method get
|
|
5705
|
+
* @param {number|function} index 索引或条件函数
|
|
5706
|
+
* @returns {*} 找到的元素,如果未找到返回 undefined
|
|
5707
|
+
*
|
|
5708
|
+
* @example
|
|
5709
|
+
* // 按索引获取
|
|
5710
|
+
* const item = list.get(0);
|
|
5711
|
+
*
|
|
5712
|
+
* // 按条件查找
|
|
5713
|
+
* const found = list.get(item => item.id === 5);
|
|
5714
|
+
*/
|
|
5715
|
+
|
|
4652
5716
|
}, {
|
|
4653
5717
|
key: "get",
|
|
4654
5718
|
value: function get(index) {
|
|
@@ -4658,6 +5722,28 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4658
5722
|
return this[index];
|
|
4659
5723
|
}
|
|
4660
5724
|
}
|
|
5725
|
+
/**
|
|
5726
|
+
* 遍历列表
|
|
5727
|
+
*
|
|
5728
|
+
* 支持正向和反向遍历。在回调中返回 false 可以中断遍历。
|
|
5729
|
+
*
|
|
5730
|
+
* @method each
|
|
5731
|
+
* @param {function} cb 回调函数,参数为 (index, item)
|
|
5732
|
+
* @param {boolean} [inverse=false] 是否反向遍历
|
|
5733
|
+
*
|
|
5734
|
+
* @example
|
|
5735
|
+
* // 正向遍历
|
|
5736
|
+
* list.each((index, item) => {
|
|
5737
|
+
* console.log(index, item);
|
|
5738
|
+
* if (item.id === 3) return false; // 中断遍历
|
|
5739
|
+
* });
|
|
5740
|
+
*
|
|
5741
|
+
* // 反向遍历
|
|
5742
|
+
* list.each((index, item) => {
|
|
5743
|
+
* console.log(index, item);
|
|
5744
|
+
* }, true);
|
|
5745
|
+
*/
|
|
5746
|
+
|
|
4661
5747
|
}, {
|
|
4662
5748
|
key: "each",
|
|
4663
5749
|
value: function each(cb, inverse) {
|
|
@@ -4678,6 +5764,21 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4678
5764
|
}
|
|
4679
5765
|
}
|
|
4680
5766
|
}
|
|
5767
|
+
/**
|
|
5768
|
+
* 统计元素数量
|
|
5769
|
+
*
|
|
5770
|
+
* 如果提供了条件函数,返回满足条件的元素数量;
|
|
5771
|
+
* 否则返回列表总长度。
|
|
5772
|
+
*
|
|
5773
|
+
* @method count
|
|
5774
|
+
* @param {function} [handler] 条件函数
|
|
5775
|
+
* @returns {number} 元素数量
|
|
5776
|
+
*
|
|
5777
|
+
* @example
|
|
5778
|
+
* const total = list.count(); // 总数量
|
|
5779
|
+
* const matched = list.count(item => item.active); // 满足条件的数量
|
|
5780
|
+
*/
|
|
5781
|
+
|
|
4681
5782
|
}, {
|
|
4682
5783
|
key: "count",
|
|
4683
5784
|
value: function count(handler) {
|
|
@@ -4696,6 +5797,17 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4696
5797
|
|
|
4697
5798
|
return this.length;
|
|
4698
5799
|
}
|
|
5800
|
+
/**
|
|
5801
|
+
* 清空列表
|
|
5802
|
+
*
|
|
5803
|
+
* 移除列表中的所有元素。
|
|
5804
|
+
*
|
|
5805
|
+
* @method clear
|
|
5806
|
+
*
|
|
5807
|
+
* @example
|
|
5808
|
+
* list.clear();
|
|
5809
|
+
*/
|
|
5810
|
+
|
|
4699
5811
|
}, {
|
|
4700
5812
|
key: "clear",
|
|
4701
5813
|
value: function clear() {
|
|
@@ -4724,91 +5836,197 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
4724
5836
|
|
|
4725
5837
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
4726
5838
|
|
|
5839
|
+
/**
|
|
5840
|
+
* 控件ID计数器
|
|
5841
|
+
* 用于为每个新创建的对象生成唯一标识符
|
|
5842
|
+
* @type {number}
|
|
5843
|
+
* @private
|
|
5844
|
+
*/
|
|
4727
5845
|
var control_id_counter = 0;
|
|
5846
|
+
/**
|
|
5847
|
+
* jmGraph 基础对象类
|
|
5848
|
+
*
|
|
5849
|
+
* 所有图形控件、属性对象、工具类的基类。
|
|
5850
|
+
* 提供了对象标识、类型检查和动画调度等核心功能。
|
|
5851
|
+
*
|
|
5852
|
+
* @class jmObject
|
|
5853
|
+
* @example
|
|
5854
|
+
* // 创建一个基础对象
|
|
5855
|
+
* const obj = new jmObject();
|
|
5856
|
+
* console.log(obj.id); // 输出唯一ID
|
|
5857
|
+
*
|
|
5858
|
+
* // 类型检查
|
|
5859
|
+
* obj.is('jmObject'); // true
|
|
5860
|
+
* obj.is(jmObject); // true
|
|
5861
|
+
*/
|
|
4728
5862
|
|
|
4729
5863
|
var jmObject = /*#__PURE__*/function () {
|
|
5864
|
+
/**
|
|
5865
|
+
* 构造函数
|
|
5866
|
+
*
|
|
5867
|
+
* 创建一个新的基础对象实例,自动分配唯一ID。
|
|
5868
|
+
* 如果传入的是 jmGraph 实例,则建立关联关系。
|
|
5869
|
+
*
|
|
5870
|
+
* @constructor
|
|
5871
|
+
* @param {jmGraph} [g] - 可选的 jmGraph 实例,用于建立对象与画布的关联
|
|
5872
|
+
*
|
|
5873
|
+
* @example
|
|
5874
|
+
* // 创建独立对象
|
|
5875
|
+
* const obj = new jmObject();
|
|
5876
|
+
*
|
|
5877
|
+
* // 创建关联画布的对象
|
|
5878
|
+
* const graph = new jmGraph(canvas);
|
|
5879
|
+
* const objWithGraph = new jmObject(graph);
|
|
5880
|
+
*/
|
|
4730
5881
|
function jmObject(g) {
|
|
4731
5882
|
_classCallCheck(this, jmObject);
|
|
4732
5883
|
|
|
5884
|
+
// 如果传入的是 jmGraph 实例,则建立引用关系
|
|
4733
5885
|
if (g && g.type == 'jmGraph') {
|
|
4734
5886
|
this.graph = g;
|
|
4735
|
-
}
|
|
5887
|
+
} // 生成唯一ID
|
|
5888
|
+
|
|
4736
5889
|
|
|
4737
5890
|
this.id = ++control_id_counter;
|
|
4738
5891
|
}
|
|
4739
5892
|
/**
|
|
4740
|
-
*
|
|
5893
|
+
* 检查对象是否为指定类型
|
|
5894
|
+
*
|
|
5895
|
+
* 支持两种类型检查方式:
|
|
5896
|
+
* 1. 字符串方式:检查对象的 type 属性是否匹配
|
|
5897
|
+
* 2. 类构造函数方式:使用 instanceof 检查原型链
|
|
4741
5898
|
*
|
|
4742
5899
|
* @method is
|
|
4743
|
-
* @param {
|
|
4744
|
-
* @
|
|
4745
|
-
*
|
|
5900
|
+
* @param {string|Function} type - 要检查的类型名称(字符串)或类构造函数
|
|
5901
|
+
* @returns {boolean} 如果对象是指定类型则返回 true,否则返回 false
|
|
5902
|
+
*
|
|
5903
|
+
* @example
|
|
5904
|
+
* // 使用字符串检查
|
|
5905
|
+
* control.is('jmRect'); // 检查是否为矩形
|
|
5906
|
+
*
|
|
5907
|
+
* // 使用类构造函数检查
|
|
5908
|
+
* control.is(jmControl); // 检查是否为 jmControl 实例
|
|
5909
|
+
* control.is(jmPath); // 检查是否继承自 jmPath
|
|
4746
5910
|
*/
|
|
4747
5911
|
|
|
4748
5912
|
|
|
4749
5913
|
_createClass(jmObject, [{
|
|
4750
5914
|
key: "is",
|
|
4751
5915
|
value: function is(type) {
|
|
5916
|
+
// 字符串类型:检查 type 属性
|
|
4752
5917
|
if (typeof type == 'string') {
|
|
4753
5918
|
return this.type == type;
|
|
4754
|
-
}
|
|
5919
|
+
} // 类构造函数:使用 instanceof 检查原型链
|
|
5920
|
+
|
|
4755
5921
|
|
|
4756
5922
|
return this instanceof type;
|
|
4757
5923
|
}
|
|
5924
|
+
/**
|
|
5925
|
+
* 注册并执行动画帧回调
|
|
5926
|
+
*
|
|
5927
|
+
* 提供动画帧调度功能,支持:
|
|
5928
|
+
* - 按指定时间间隔执行回调
|
|
5929
|
+
* - 多个动画句柄并行执行
|
|
5930
|
+
* - 自动清理返回 false 的动画
|
|
5931
|
+
* - 错误自动移除异常动画
|
|
5932
|
+
*
|
|
5933
|
+
* 此方法通常由 jmGraph 实例调用,子控件会委托给所属的 graph 处理。
|
|
5934
|
+
*
|
|
5935
|
+
* @method animate
|
|
5936
|
+
* @param {Function} handle - 动画回调函数,返回 false 时自动移除
|
|
5937
|
+
* @param {number} [millisec=20] - 执行间隔(毫秒),默认 20ms
|
|
5938
|
+
* @param {...*} [params] - 传递给回调函数的额外参数
|
|
5939
|
+
*
|
|
5940
|
+
* @example
|
|
5941
|
+
* // 创建一个简单的动画
|
|
5942
|
+
* let x = 0;
|
|
5943
|
+
* graph.animate(function() {
|
|
5944
|
+
* x += 1;
|
|
5945
|
+
* rect.position.x = x;
|
|
5946
|
+
* graph.redraw();
|
|
5947
|
+
*
|
|
5948
|
+
* // 动画结束条件
|
|
5949
|
+
* if(x > 100) return false;
|
|
5950
|
+
* }, 16); // 约60fps
|
|
5951
|
+
*
|
|
5952
|
+
* // 带参数的动画
|
|
5953
|
+
* graph.animate(function(speed) {
|
|
5954
|
+
* x += speed;
|
|
5955
|
+
* // ...
|
|
5956
|
+
* }, 16, 5); // speed = 5
|
|
5957
|
+
*/
|
|
5958
|
+
|
|
4758
5959
|
}, {
|
|
4759
5960
|
key: "animate",
|
|
4760
5961
|
value: function animate() {
|
|
5962
|
+
// 只有 jmGraph 实例才真正处理动画调度
|
|
4761
5963
|
if (this.is('jmGraph')) {
|
|
5964
|
+
// 注册新的动画句柄
|
|
4762
5965
|
if (arguments.length > 1) {
|
|
4763
|
-
if (!this.animateHandles) this.animateHandles = new _jmList.jmList();
|
|
5966
|
+
if (!this.animateHandles) this.animateHandles = new _jmList.jmList(); // 收集额外参数
|
|
5967
|
+
|
|
4764
5968
|
var params = [];
|
|
4765
5969
|
|
|
4766
5970
|
if (arguments.length > 2) {
|
|
4767
5971
|
for (var i = 2; i < arguments.length; i++) {
|
|
4768
5972
|
params.push(i < 0 || arguments.length <= i ? undefined : arguments[i]);
|
|
4769
5973
|
}
|
|
4770
|
-
}
|
|
5974
|
+
} // 添加动画句柄到列表
|
|
5975
|
+
|
|
4771
5976
|
|
|
4772
5977
|
this.animateHandles.add({
|
|
4773
5978
|
millisec: (arguments.length <= 1 ? undefined : arguments[1]) || 20,
|
|
5979
|
+
// 执行间隔
|
|
4774
5980
|
handle: arguments.length <= 0 ? undefined : arguments[0],
|
|
4775
|
-
|
|
5981
|
+
// 回调函数
|
|
5982
|
+
params: params // 额外参数
|
|
5983
|
+
|
|
4776
5984
|
});
|
|
4777
|
-
}
|
|
5985
|
+
} // 如果有动画句柄,启动调度循环
|
|
5986
|
+
|
|
4778
5987
|
|
|
4779
5988
|
if (this.animateHandles) {
|
|
4780
5989
|
if (this.animateHandles.count() > 0) {
|
|
4781
|
-
var self = this;
|
|
5990
|
+
var self = this; // 使用 setTimeout 进行调度(避免 requestAnimationFrame 的固定帧率限制)
|
|
5991
|
+
|
|
4782
5992
|
this.dispatcher = setTimeout(function (_this) {
|
|
4783
5993
|
_this = _this || self;
|
|
4784
|
-
var overduehandles = [];
|
|
4785
|
-
|
|
5994
|
+
var overduehandles = []; // 需要移除的句柄
|
|
5995
|
+
|
|
5996
|
+
var curTimes = Date.now(); // 遍历执行所有动画句柄
|
|
4786
5997
|
|
|
4787
5998
|
_this.animateHandles.each(function (i, ani) {
|
|
4788
5999
|
try {
|
|
6000
|
+
// 检查是否到达执行时间
|
|
4789
6001
|
if (ani && ani.handle && (!ani.times || curTimes - ani.times >= ani.millisec)) {
|
|
4790
|
-
|
|
6002
|
+
// 执行回调
|
|
6003
|
+
var r = ani.handle.apply(_this, ani.params); // 返回 false 表示动画结束
|
|
4791
6004
|
|
|
4792
6005
|
if (r === false) {
|
|
4793
6006
|
overduehandles.push(ani);
|
|
4794
|
-
}
|
|
6007
|
+
} // 更新最后执行时间
|
|
6008
|
+
|
|
4795
6009
|
|
|
4796
6010
|
ani.times = curTimes;
|
|
4797
6011
|
}
|
|
4798
6012
|
} catch (e) {
|
|
6013
|
+
// 出错的句柄自动移除
|
|
4799
6014
|
if (ani) overduehandles.push(ani);
|
|
4800
6015
|
}
|
|
4801
|
-
});
|
|
6016
|
+
}); // 移除已完成的动画句柄
|
|
6017
|
+
|
|
4802
6018
|
|
|
4803
6019
|
for (var _i in overduehandles) {
|
|
4804
6020
|
_this.animateHandles.remove(overduehandles[_i]);
|
|
4805
|
-
}
|
|
6021
|
+
} // 继续下一轮调度
|
|
6022
|
+
|
|
4806
6023
|
|
|
4807
6024
|
_this.animate();
|
|
4808
6025
|
}, 10, this);
|
|
4809
6026
|
}
|
|
4810
6027
|
}
|
|
4811
6028
|
} else {
|
|
6029
|
+
// 非 jmGraph 对象委托给所属的 graph 处理
|
|
4812
6030
|
var graph = this.graph;
|
|
4813
6031
|
|
|
4814
6032
|
if (graph) {
|
|
@@ -4856,12 +6074,33 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
4856
6074
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4857
6075
|
|
|
4858
6076
|
/**
|
|
4859
|
-
*
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
6077
|
+
* 基础路径类
|
|
6078
|
+
*
|
|
6079
|
+
* 大部分图形的基类,通过指定一系列点来画出图形。
|
|
6080
|
+
* 支持开放路径和闭合路径,支持 SVG 导出。
|
|
6081
|
+
*
|
|
4862
6082
|
* @class jmPath
|
|
4863
6083
|
* @extends jmControl
|
|
4864
|
-
*
|
|
6084
|
+
*
|
|
6085
|
+
* @param {Object} params 路径参数
|
|
6086
|
+
* @param {Array<Object>} [params.points] 点序列,每个点格式:{x:0, y:0, m:false}
|
|
6087
|
+
* @param {string} [t='jmPath'] 类型标识
|
|
6088
|
+
*
|
|
6089
|
+
* @example
|
|
6090
|
+
* // 创建自定义路径
|
|
6091
|
+
* const path = new jmPath({
|
|
6092
|
+
* points: [
|
|
6093
|
+
* {x: 0, y: 0},
|
|
6094
|
+
* {x: 100, y: 0},
|
|
6095
|
+
* {x: 100, y: 100},
|
|
6096
|
+
* {x: 0, y: 100}
|
|
6097
|
+
* ],
|
|
6098
|
+
* style: {
|
|
6099
|
+
* fill: '#ff0000',
|
|
6100
|
+
* stroke: '#000000',
|
|
6101
|
+
* close: true // 闭合路径
|
|
6102
|
+
* }
|
|
6103
|
+
* });
|
|
4865
6104
|
*/
|
|
4866
6105
|
var jmPath = /*#__PURE__*/function (_jmControl) {
|
|
4867
6106
|
_inherits(jmPath, _jmControl);
|
|
@@ -4995,23 +6234,94 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
4995
6234
|
|
|
4996
6235
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4997
6236
|
|
|
6237
|
+
/**
|
|
6238
|
+
* 属性存储的 Symbol 键
|
|
6239
|
+
* 使用 Symbol 确保属性存储的私有性和唯一性
|
|
6240
|
+
* @type {Symbol}
|
|
6241
|
+
* @private
|
|
6242
|
+
*/
|
|
4998
6243
|
var PROPERTY_KEY = Symbol("properties");
|
|
6244
|
+
/**
|
|
6245
|
+
* jmGraph 属性管理基类
|
|
6246
|
+
*
|
|
6247
|
+
* jmProperty 是 jmControl 的父类,为所有图形控件提供属性管理功能。
|
|
6248
|
+
* 采用 Symbol + WeakMap 模式实现真正的私有属性存储,避免属性名冲突。
|
|
6249
|
+
*
|
|
6250
|
+
* 核心特性:
|
|
6251
|
+
* 1. **私有属性存储**:使用 Symbol 键确保属性不被外部直接访问
|
|
6252
|
+
* 2. **属性变更通知**:设置属性时自动触发 'propertyChange' 事件
|
|
6253
|
+
* 3. **渲染模式继承**:子控件自动继承所属 graph 的渲染模式
|
|
6254
|
+
* 4. **脏标记传播**:子控件 needUpdate 会自动传播到 graph
|
|
6255
|
+
*
|
|
6256
|
+
* @class jmProperty
|
|
6257
|
+
* @extends jmObject
|
|
6258
|
+
*
|
|
6259
|
+
* @example
|
|
6260
|
+
* // 创建属性对象
|
|
6261
|
+
* const prop = new jmProperty({ mode: 'webgl' });
|
|
6262
|
+
*
|
|
6263
|
+
* // 设置和获取属性
|
|
6264
|
+
* prop.property('customValue', 100);
|
|
6265
|
+
* console.log(prop.property('customValue')); // 100
|
|
6266
|
+
*
|
|
6267
|
+
* // 监听属性变更
|
|
6268
|
+
* prop.on('propertyChange', (name, args) => {
|
|
6269
|
+
* console.log(`${name} changed from ${args.oldValue} to ${args.newValue}`);
|
|
6270
|
+
* });
|
|
6271
|
+
*/
|
|
4999
6272
|
|
|
5000
6273
|
var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
5001
6274
|
_inherits(jmProperty, _jmObject);
|
|
5002
6275
|
|
|
5003
6276
|
var _super = _createSuper(jmProperty);
|
|
5004
6277
|
|
|
6278
|
+
/**
|
|
6279
|
+
* 构造函数
|
|
6280
|
+
*
|
|
6281
|
+
* 初始化属性存储对象,并设置初始渲染模式。
|
|
6282
|
+
*
|
|
6283
|
+
* @constructor
|
|
6284
|
+
* @param {Object} [params] - 初始化参数
|
|
6285
|
+
* @param {'2d'|'webgl'} [params.mode] - 渲染模式,默认 '2d'
|
|
6286
|
+
*
|
|
6287
|
+
* @example
|
|
6288
|
+
* // 创建使用 WebGL 渲染的属性对象
|
|
6289
|
+
* const prop = new jmProperty({ mode: 'webgl' });
|
|
6290
|
+
*/
|
|
5005
6291
|
function jmProperty(params) {
|
|
5006
6292
|
var _this;
|
|
5007
6293
|
|
|
5008
6294
|
_classCallCheck(this, jmProperty);
|
|
5009
6295
|
|
|
5010
|
-
_this = _super.call(this);
|
|
5011
|
-
|
|
6296
|
+
_this = _super.call(this); // 初始化私有属性存储对象
|
|
6297
|
+
|
|
6298
|
+
_this[PROPERTY_KEY] = {}; // 设置渲染模式
|
|
6299
|
+
|
|
5012
6300
|
if (params && params.mode) _this.mode = params.mode;
|
|
5013
6301
|
return _this;
|
|
5014
6302
|
}
|
|
6303
|
+
/**
|
|
6304
|
+
* 获取或设置属性值
|
|
6305
|
+
*
|
|
6306
|
+
* 这是属性系统的核心方法,所有属性的存取都通过此方法。
|
|
6307
|
+
* 设置属性时会自动触发 'propertyChange' 事件,便于实现响应式更新。
|
|
6308
|
+
*
|
|
6309
|
+
* @method property
|
|
6310
|
+
* @param {string} name - 属性名称
|
|
6311
|
+
* @param {*} [value] - 属性值(设置时提供)
|
|
6312
|
+
* @returns {*} 获取时返回属性值,设置时返回设置的值
|
|
6313
|
+
*
|
|
6314
|
+
* @example
|
|
6315
|
+
* // 获取属性
|
|
6316
|
+
* const value = obj.property('myProp');
|
|
6317
|
+
*
|
|
6318
|
+
* // 设置属性
|
|
6319
|
+
* obj.property('myProp', 'newValue');
|
|
6320
|
+
*
|
|
6321
|
+
* // 链式调用
|
|
6322
|
+
* obj.property('a', 1).property('b', 2);
|
|
6323
|
+
*/
|
|
6324
|
+
|
|
5015
6325
|
|
|
5016
6326
|
_createClass(jmProperty, [{
|
|
5017
6327
|
key: "property",
|
|
@@ -5022,7 +6332,7 @@ var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
|
5022
6332
|
|
|
5023
6333
|
if (pars) {
|
|
5024
6334
|
var pros = this[PROPERTY_KEY];
|
|
5025
|
-
var name = pars[0];
|
|
6335
|
+
var name = pars[0]; // 设置属性
|
|
5026
6336
|
|
|
5027
6337
|
if (pars.length > 1) {
|
|
5028
6338
|
var value = pars[1];
|
|
@@ -5030,51 +6340,149 @@ var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
|
5030
6340
|
oldValue: pros[name],
|
|
5031
6341
|
newValue: value
|
|
5032
6342
|
};
|
|
5033
|
-
pros[name] = pars[1];
|
|
6343
|
+
pros[name] = pars[1]; // 触发属性变更事件(如果对象支持事件)
|
|
6344
|
+
|
|
5034
6345
|
if (this.emit) this.emit('propertyChange', name, args);
|
|
5035
6346
|
return pars[1];
|
|
5036
|
-
}
|
|
6347
|
+
} // 获取属性
|
|
6348
|
+
else if (name) {
|
|
5037
6349
|
return pros[name];
|
|
5038
6350
|
}
|
|
5039
6351
|
}
|
|
5040
6352
|
}
|
|
6353
|
+
/**
|
|
6354
|
+
* 是否需要重绘标记
|
|
6355
|
+
*
|
|
6356
|
+
* 当属性变化导致需要重新渲染时设置此标记。
|
|
6357
|
+
* 设置为 true 时,会自动将所属 graph 的 needUpdate 设为 true,
|
|
6358
|
+
* 从而触发画布重绘。
|
|
6359
|
+
*
|
|
6360
|
+
* @type {boolean}
|
|
6361
|
+
*
|
|
6362
|
+
* @example
|
|
6363
|
+
* // 标记需要重绘
|
|
6364
|
+
* control.needUpdate = true;
|
|
6365
|
+
*
|
|
6366
|
+
* // 检查是否需要重绘
|
|
6367
|
+
* if(control.needUpdate) {
|
|
6368
|
+
* control.redraw();
|
|
6369
|
+
* }
|
|
6370
|
+
*/
|
|
6371
|
+
|
|
5041
6372
|
}, {
|
|
5042
6373
|
key: "needUpdate",
|
|
5043
6374
|
get: function get() {
|
|
5044
6375
|
return this.property('needUpdate');
|
|
5045
6376
|
},
|
|
5046
6377
|
set: function set(v) {
|
|
5047
|
-
this.property('needUpdate', v);
|
|
6378
|
+
this.property('needUpdate', v); // 传播脏标记到 graph(避免 jmGraph 自身循环)
|
|
5048
6379
|
|
|
5049
6380
|
if (v && !this.is('jmGraph') && this.graph) {
|
|
5050
6381
|
this.graph.needUpdate = true;
|
|
5051
6382
|
}
|
|
5052
6383
|
}
|
|
6384
|
+
/**
|
|
6385
|
+
* 所属的画布实例
|
|
6386
|
+
*
|
|
6387
|
+
* 获取或设置当前对象所属的 jmGraph 实例。
|
|
6388
|
+
* 如果未显式设置,会自动向上查找父级链中的 jmGraph。
|
|
6389
|
+
*
|
|
6390
|
+
* @type {jmGraph}
|
|
6391
|
+
*
|
|
6392
|
+
* @example
|
|
6393
|
+
* // 获取所属画布
|
|
6394
|
+
* const graph = control.graph;
|
|
6395
|
+
*
|
|
6396
|
+
* // 设置所属画布(通常由框架内部调用)
|
|
6397
|
+
* control.graph = myGraph;
|
|
6398
|
+
*/
|
|
6399
|
+
|
|
5053
6400
|
}, {
|
|
5054
6401
|
key: "graph",
|
|
5055
6402
|
get: function get() {
|
|
5056
|
-
var g = this.property('graph');
|
|
6403
|
+
var g = this.property('graph'); // 如果未设置,尝试从父级链查找
|
|
6404
|
+
|
|
5057
6405
|
g = g || this.property('graph', this.findParent('jmGraph'));
|
|
5058
6406
|
return g;
|
|
5059
6407
|
},
|
|
5060
6408
|
set: function set(v) {
|
|
5061
6409
|
return this.property('graph', v);
|
|
5062
6410
|
}
|
|
6411
|
+
/**
|
|
6412
|
+
* 渲染模式
|
|
6413
|
+
*
|
|
6414
|
+
* 获取当前渲染模式,支持 '2d' 和 'webgl' 两种模式。
|
|
6415
|
+
* 渲染模式的查找优先级:
|
|
6416
|
+
* 1. 当前对象设置的 mode
|
|
6417
|
+
* 2. 如果是 jmGraph,默认 '2d'
|
|
6418
|
+
* 3. 从所属 graph 继承 mode
|
|
6419
|
+
*
|
|
6420
|
+
* @type {'2d'|'webgl'}
|
|
6421
|
+
* @readonly
|
|
6422
|
+
*
|
|
6423
|
+
* @example
|
|
6424
|
+
* // 检查渲染模式
|
|
6425
|
+
* if(control.mode === 'webgl') {
|
|
6426
|
+
* // 使用 WebGL 特性
|
|
6427
|
+
* } else {
|
|
6428
|
+
* // 使用 Canvas 2D API
|
|
6429
|
+
* }
|
|
6430
|
+
*/
|
|
6431
|
+
|
|
5063
6432
|
}, {
|
|
5064
6433
|
key: "mode",
|
|
5065
6434
|
get: function get() {
|
|
6435
|
+
var _this$graph;
|
|
6436
|
+
|
|
5066
6437
|
var m = this.property('mode');
|
|
5067
|
-
if (m) return m;
|
|
5068
|
-
|
|
6438
|
+
if (m) return m; // 如果当前对象是jmGraph且没有设置mode,返回默认值
|
|
6439
|
+
|
|
6440
|
+
if (this.is('jmGraph')) return this.property('mode') || '2d'; // 否则从所属的graph获取mode
|
|
6441
|
+
|
|
6442
|
+
return ((_this$graph = this.graph) === null || _this$graph === void 0 ? void 0 : _this$graph.mode) || '2d';
|
|
5069
6443
|
},
|
|
5070
6444
|
set: function set(v) {
|
|
5071
6445
|
return this.property('mode', v);
|
|
5072
6446
|
}
|
|
6447
|
+
/**
|
|
6448
|
+
* 请求动画帧
|
|
6449
|
+
*
|
|
6450
|
+
* 封装 requestAnimationFrame,支持在不同环境下工作。
|
|
6451
|
+
* 如果当前对象关联了 canvas,会使用 canvas 的 requestAnimationFrame。
|
|
6452
|
+
*
|
|
6453
|
+
* @method requestAnimationFrame
|
|
6454
|
+
* @param {Function} handler - 动画帧回调函数
|
|
6455
|
+
* @returns {number} 动画帧请求ID,用于取消
|
|
6456
|
+
*
|
|
6457
|
+
* @example
|
|
6458
|
+
* // 请求下一帧动画
|
|
6459
|
+
* const frameId = control.requestAnimationFrame(() => {
|
|
6460
|
+
* // 更新动画状态
|
|
6461
|
+
* control.redraw();
|
|
6462
|
+
* });
|
|
6463
|
+
*
|
|
6464
|
+
* // 取消动画帧
|
|
6465
|
+
* control.cancelAnimationFrame(frameId);
|
|
6466
|
+
*/
|
|
6467
|
+
|
|
5073
6468
|
}, {
|
|
5074
6469
|
key: "requestAnimationFrame",
|
|
5075
6470
|
value: function requestAnimationFrame(handler) {
|
|
5076
6471
|
return _jmUtils.jmUtils.requestAnimationFrame(handler, this.graph ? this.graph.canvas : null);
|
|
5077
6472
|
}
|
|
6473
|
+
/**
|
|
6474
|
+
* 取消动画帧请求
|
|
6475
|
+
*
|
|
6476
|
+
* 取消之前通过 requestAnimationFrame 注册的回调。
|
|
6477
|
+
*
|
|
6478
|
+
* @method cancelAnimationFrame
|
|
6479
|
+
* @param {number} handler - 动画帧请求ID
|
|
6480
|
+
*
|
|
6481
|
+
* @example
|
|
6482
|
+
* // 取消动画帧
|
|
6483
|
+
* control.cancelAnimationFrame(frameId);
|
|
6484
|
+
*/
|
|
6485
|
+
|
|
5078
6486
|
}, {
|
|
5079
6487
|
key: "cancelAnimationFrame",
|
|
5080
6488
|
value: function cancelAnimationFrame(handler) {
|
|
@@ -5104,13 +6512,26 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5104
6512
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5105
6513
|
|
|
5106
6514
|
/**
|
|
5107
|
-
*
|
|
5108
|
-
*
|
|
6515
|
+
* 阴影类
|
|
6516
|
+
*
|
|
6517
|
+
* 用于创建图形的阴影效果。阴影可以应用于任何图形控件。
|
|
6518
|
+
*
|
|
5109
6519
|
* @class jmShadow
|
|
5110
|
-
*
|
|
5111
|
-
* @param {number} y
|
|
5112
|
-
* @param {number}
|
|
5113
|
-
* @param {
|
|
6520
|
+
*
|
|
6521
|
+
* @param {number|string} x 横坐标偏移量,或阴影字符串格式 'x,y,blur,color'
|
|
6522
|
+
* @param {number} [y] 纵坐标偏移量
|
|
6523
|
+
* @param {number} [blur] 模糊值
|
|
6524
|
+
* @param {string} [color] 阴影颜色
|
|
6525
|
+
*
|
|
6526
|
+
* @example
|
|
6527
|
+
* // 创建阴影
|
|
6528
|
+
* const shadow = new jmShadow(5, 5, 10, 'rgba(0,0,0,0.5)');
|
|
6529
|
+
*
|
|
6530
|
+
* // 从字符串创建
|
|
6531
|
+
* const shadow = new jmShadow('5, 5, 10, rgba(0,0,0,0.5)');
|
|
6532
|
+
*
|
|
6533
|
+
* // 应用到图形
|
|
6534
|
+
* rect.style.shadow = shadow;
|
|
5114
6535
|
*/
|
|
5115
6536
|
var jmShadow = /*#__PURE__*/function () {
|
|
5116
6537
|
function jmShadow(x, y, blur, color) {
|
|
@@ -5204,6 +6625,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5204
6625
|
|
|
5205
6626
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5206
6627
|
|
|
6628
|
+
/**
|
|
6629
|
+
* CSS 颜色关键字映射表
|
|
6630
|
+
*
|
|
6631
|
+
* 包含所有 CSS 标准颜色名称到十六进制值的映射。
|
|
6632
|
+
* 支持 147 种命名颜色 + CSS 系统颜色。
|
|
6633
|
+
*
|
|
6634
|
+
* @constant {Object.<string, string>}
|
|
6635
|
+
* @private
|
|
6636
|
+
*/
|
|
5207
6637
|
var colorKeywords = {
|
|
5208
6638
|
aliceblue: "#f0f8ff",
|
|
5209
6639
|
antiquewhite: "#faebd7",
|
|
@@ -5384,11 +6814,22 @@ var colorKeywords = {
|
|
|
5384
6814
|
windowtext: "#000000"
|
|
5385
6815
|
};
|
|
5386
6816
|
/**
|
|
5387
|
-
*
|
|
5388
|
-
*
|
|
6817
|
+
* jmGraph 工具类
|
|
6818
|
+
*
|
|
6819
|
+
* 提供常用的静态工具方法,包括对象操作、事件处理、几何计算、颜色转换等。
|
|
5389
6820
|
*
|
|
5390
6821
|
* @class jmUtils
|
|
5391
6822
|
* @static
|
|
6823
|
+
*
|
|
6824
|
+
* @example
|
|
6825
|
+
* // 克隆对象
|
|
6826
|
+
* const newObj = jmUtils.clone({ a: 1, b: 2 });
|
|
6827
|
+
*
|
|
6828
|
+
* // 绑定事件
|
|
6829
|
+
* jmUtils.bindEvent(element, 'click', handler);
|
|
6830
|
+
*
|
|
6831
|
+
* // 检查点是否在多边形内
|
|
6832
|
+
* const inside = jmUtils.pointInPolygon({x: 10, y: 10}, polygonPoints);
|
|
5392
6833
|
*/
|
|
5393
6834
|
|
|
5394
6835
|
exports.colorKeywords = colorKeywords;
|
|
@@ -5582,7 +7023,7 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5582
7023
|
}
|
|
5583
7024
|
} else if (el.x) {
|
|
5584
7025
|
pos.left += el.x;
|
|
5585
|
-
} else if (el.
|
|
7026
|
+
} else if (el.y) {
|
|
5586
7027
|
pos.top += el.y;
|
|
5587
7028
|
}
|
|
5588
7029
|
|
|
@@ -5717,6 +7158,31 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5717
7158
|
|
|
5718
7159
|
return this.rayCasting(pt, polygon, offset);
|
|
5719
7160
|
}
|
|
7161
|
+
/**
|
|
7162
|
+
* 判断点是否在线段上
|
|
7163
|
+
*
|
|
7164
|
+
* 通过计算点到线段的垂直距离来判断点是否在线段上。
|
|
7165
|
+
* 同时检查点是否在线段的范围内(不仅仅是直线上)。
|
|
7166
|
+
*
|
|
7167
|
+
* @method pointOnLine
|
|
7168
|
+
* @static
|
|
7169
|
+
* @private
|
|
7170
|
+
* @param {Object} pt 待检测的点 {x, y}
|
|
7171
|
+
* @param {Object} p1 线段起点 {x, y}
|
|
7172
|
+
* @param {Object} p2 线段终点 {x, y}
|
|
7173
|
+
* @param {number} offset 允许的偏差值(像素)
|
|
7174
|
+
* @returns {number} 0=不在线段上, 1=在线段上
|
|
7175
|
+
*
|
|
7176
|
+
* @example
|
|
7177
|
+
* const onLine = jmUtils.pointOnLine(
|
|
7178
|
+
* {x: 5, y: 5}, // 待检测点
|
|
7179
|
+
* {x: 0, y: 0}, // 起点
|
|
7180
|
+
* {x: 10, y: 10}, // 终点
|
|
7181
|
+
* 2 // 允许偏差
|
|
7182
|
+
* );
|
|
7183
|
+
* // 返回 1,点在对角线上
|
|
7184
|
+
*/
|
|
7185
|
+
|
|
5720
7186
|
}, {
|
|
5721
7187
|
key: "pointOnLine",
|
|
5722
7188
|
value: function pointOnLine(pt, p1, p2, offset) {
|
|
@@ -5758,6 +7224,26 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5758
7224
|
|
|
5759
7225
|
return 0;
|
|
5760
7226
|
}
|
|
7227
|
+
/**
|
|
7228
|
+
* 射线法判断点是否在多边形内部
|
|
7229
|
+
*
|
|
7230
|
+
* 从待测点向右发射一条水平射线,计算与多边形边界的交点数量。
|
|
7231
|
+
* - 交点数为奇数:点在多边形内部
|
|
7232
|
+
* - 交点数为偶数:点在多边形外部
|
|
7233
|
+
*
|
|
7234
|
+
* 这是判断点是否在任意多边形内的经典算法,时间复杂度 O(n)。
|
|
7235
|
+
*
|
|
7236
|
+
* @method rayCasting
|
|
7237
|
+
* @static
|
|
7238
|
+
* @private
|
|
7239
|
+
* @param {Object} pt 待检测的点 {x, y}
|
|
7240
|
+
* @param {Array<Object>} polygon 多边形顶点数组 [{x, y}, ...]
|
|
7241
|
+
* @param {number} offset 允许的偏差值(未使用)
|
|
7242
|
+
* @returns {number} 0=在多边形外部, 2=在多边形内部
|
|
7243
|
+
*
|
|
7244
|
+
* @see {@link https://en.wikipedia.org/wiki/Point_in_polygon Point in polygon - Wikipedia}
|
|
7245
|
+
*/
|
|
7246
|
+
|
|
5761
7247
|
}, {
|
|
5762
7248
|
key: "rayCasting",
|
|
5763
7249
|
value: function rayCasting(pt, polygon, offset) {
|
|
@@ -6166,8 +7652,19 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6166
7652
|
return this.__hexToRGBA_Cache[hex] = res;
|
|
6167
7653
|
}
|
|
6168
7654
|
/**
|
|
6169
|
-
*
|
|
6170
|
-
*
|
|
7655
|
+
* 将 RGB 颜色值从 0-255 范围转换为 0-1 范围
|
|
7656
|
+
*
|
|
7657
|
+
* WebGL 中的颜色值通常使用 0-1 的浮点数表示,
|
|
7658
|
+
* 此方法用于将标准 RGB 值转换为 WebGL 兼容格式。
|
|
7659
|
+
*
|
|
7660
|
+
* @method rgbToDecimal
|
|
7661
|
+
* @static
|
|
7662
|
+
* @param {Object} color 颜色对象 {r, g, b, a?}
|
|
7663
|
+
* @returns {Object} 转换后的颜色对象 {r, g, b, a?},其中 r/g/b 为 0-1 范围
|
|
7664
|
+
*
|
|
7665
|
+
* @example
|
|
7666
|
+
* const color = jmUtils.rgbToDecimal({ r: 255, g: 128, b: 64 });
|
|
7667
|
+
* // 返回 { r: 1, g: 0.502, b: 0.251 }
|
|
6171
7668
|
*/
|
|
6172
7669
|
|
|
6173
7670
|
}, {
|
|
@@ -6178,7 +7675,16 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6178
7675
|
color.g = this.byteToDecimal(color.g);
|
|
6179
7676
|
color.b = this.byteToDecimal(color.b);
|
|
6180
7677
|
return color;
|
|
6181
|
-
}
|
|
7678
|
+
}
|
|
7679
|
+
/**
|
|
7680
|
+
* 将字节值(0-255)转换为小数(0-1)
|
|
7681
|
+
*
|
|
7682
|
+
* @method byteToDecimal
|
|
7683
|
+
* @static
|
|
7684
|
+
* @private
|
|
7685
|
+
* @param {number} b 字节值(0-255)
|
|
7686
|
+
* @returns {number} 小数值(0-1)
|
|
7687
|
+
*/
|
|
6182
7688
|
|
|
6183
7689
|
}, {
|
|
6184
7690
|
key: "byteToDecimal",
|
|
@@ -6225,7 +7731,30 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6225
7731
|
}
|
|
6226
7732
|
|
|
6227
7733
|
return r;
|
|
6228
|
-
}
|
|
7734
|
+
}
|
|
7735
|
+
/**
|
|
7736
|
+
* 请求动画帧
|
|
7737
|
+
*
|
|
7738
|
+
* 封装浏览器原生的 requestAnimationFrame 方法,提供跨浏览器兼容性。
|
|
7739
|
+
* 在不支持 requestAnimationFrame 的环境中降级为 setTimeout。
|
|
7740
|
+
*
|
|
7741
|
+
* @method requestAnimationFrame
|
|
7742
|
+
* @static
|
|
7743
|
+
* @param {Function} callback 动画帧回调函数,接收时间戳参数
|
|
7744
|
+
* @param {Window} [win] 可选的窗口对象(用于多窗口环境)
|
|
7745
|
+
* @returns {number} 动画帧请求ID,用于取消
|
|
7746
|
+
*
|
|
7747
|
+
* @example
|
|
7748
|
+
* let animationId;
|
|
7749
|
+
* function animate(timestamp) {
|
|
7750
|
+
* // 更新动画
|
|
7751
|
+
* animationId = jmUtils.requestAnimationFrame(animate);
|
|
7752
|
+
* }
|
|
7753
|
+
* animationId = jmUtils.requestAnimationFrame(animate);
|
|
7754
|
+
*
|
|
7755
|
+
* // 取消动画
|
|
7756
|
+
* jmUtils.cancelAnimationFrame(animationId);
|
|
7757
|
+
*/
|
|
6229
7758
|
|
|
6230
7759
|
}, {
|
|
6231
7760
|
key: "requestAnimationFrame",
|
|
@@ -6233,6 +7762,22 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6233
7762
|
var fun = win && win.requestAnimationFrame ? win.requestAnimationFrame : typeof window !== 'undefined' && window.requestAnimationFrame ? window.requestAnimationFrame : setTimeout;
|
|
6234
7763
|
return fun(callback, 20);
|
|
6235
7764
|
}
|
|
7765
|
+
/**
|
|
7766
|
+
* 取消动画帧请求
|
|
7767
|
+
*
|
|
7768
|
+
* 取消之前通过 requestAnimationFrame 注册的回调。
|
|
7769
|
+
* 在不支持 cancelAnimationFrame 的环境中降级为 clearTimeout。
|
|
7770
|
+
*
|
|
7771
|
+
* @method cancelAnimationFrame
|
|
7772
|
+
* @static
|
|
7773
|
+
* @param {number} handler requestAnimationFrame 返回的请求ID
|
|
7774
|
+
* @param {Window} [win] 可选的窗口对象(用于多窗口环境)
|
|
7775
|
+
*
|
|
7776
|
+
* @example
|
|
7777
|
+
* const animationId = jmUtils.requestAnimationFrame(animate);
|
|
7778
|
+
* jmUtils.cancelAnimationFrame(animationId);
|
|
7779
|
+
*/
|
|
7780
|
+
|
|
6236
7781
|
}, {
|
|
6237
7782
|
key: "cancelAnimationFrame",
|
|
6238
7783
|
value: function cancelAnimationFrame(handler, win) {
|
|
@@ -6982,9 +8527,24 @@ var pathVertexSource = "\n attribute vec4 a_position;\n attribute vec4 a_c
|
|
|
6982
8527
|
|
|
6983
8528
|
exports.pathVertexSource = pathVertexSource;
|
|
6984
8529
|
var pathFragmentSource = "\n precision mediump float;\n uniform sampler2D u_sample;\n uniform vec4 v_texture_bounds; // \u7EB9\u7406\u7684\u5DE6\u4E0A\u5750\u6807\u548C\u5927\u5C0F x,y,z,w\n uniform vec4 v_single_color;\n // GLSL \u6E10\u53D8 uniforms\n uniform int u_gradient_type; // 0=\u65E0 1=\u7EBF\u6027 2=\u5F84\u5411\n uniform vec4 u_gradient_start; // \u7EBF\u6027:{x1,y1,0,0} \u5F84\u5411:{cx,cy,r1,0}\n uniform vec4 u_gradient_end; // \u7EBF\u6027:{x2,y2,0,0} \u5F84\u5411:{cx,cy,r2,0}\n uniform int u_gradient_stop_count;\n uniform float u_gradient_offsets[".concat(_gradient.MAX_STOPS, "];\n uniform vec4 u_gradient_colors[").concat(_gradient.MAX_STOPS, "]; // {r, g, b, a} 0~1 \u8303\u56F4\n varying float v_type;\n varying vec4 v_color;\n varying vec2 v_text_coord;\n\n ").concat(convertTexturePosition, "\n\n // \u5728 sorted stops \u4E2D\u6309 t \u503C\u91C7\u6837\u989C\u8272\n // \u517C\u5BB9 GLSL ES 1.0\uFF1A\u5FAA\u73AF\u4EC5\u4E0E\u5E38\u91CF\u6BD4\u8F83\uFF0C\u65E0 break/continue\n vec4 sampleGradient(float t) {\n t = clamp(t, 0.0, 1.0);\n // \u6B63\u5411\u626B\u63CF\uFF1A\u59CB\u7EC8\u904D\u5386 MAX_STOPS-1 \u6B21\uFF0C\u627E\u5230 t \u6240\u5728\u6BB5\u5E76\u8986\u76D6\u7ED3\u679C\n float localT = 0.0;\n vec4 c0 = u_gradient_colors[0];\n vec4 c1 = u_gradient_colors[0];\n for(int i = 0; i < ").concat(_gradient.MAX_STOPS - 1, "; i++) {\n float s0 = u_gradient_offsets[i];\n float s1 = u_gradient_offsets[i + 1];\n if(t >= s0) {\n float range = s1 - s0;\n localT = range > 0.0001 ? clamp((t - s0) / range, 0.0, 1.0) : 0.0;\n c0 = u_gradient_colors[i];\n c1 = u_gradient_colors[i + 1];\n }\n }\n return mix(c0, c1, localT);\n }\n\n void main() {\n // \u5982\u679C\u662Ffill\uFF0C\u5219\u76F4\u63A5\u586B\u5145\u989C\u8272\n if(v_type == 1.0) {\n gl_FragColor = v_single_color;\n }\n // \u6E10\u53D8\u8272 (\u65E7\u65B9\u5F0F\uFF0C\u9876\u70B9\u989C\u8272\u63D2\u503C)\n else if(v_type == 3.0) {\n gl_FragColor = v_color;\n }\n // GLSL \u6E10\u53D8\u586B\u5145 (type=5)\n else if(v_type == 5.0) {\n float t;\n if(u_gradient_type == 2) {\n // \u5F84\u5411\u6E10\u53D8\n vec2 d = v_text_coord - u_gradient_start.xy;\n float dist = length(d);\n float r1 = u_gradient_start.z;\n float r2 = u_gradient_end.z;\n float range = r2 - r1;\n t = range > 0.001 ? (dist - r1) / range : 0.0;\n } else {\n // \u7EBF\u6027\u6E10\u53D8\n vec2 dir = u_gradient_end.xy - u_gradient_start.xy;\n float lenSq = dot(dir, dir);\n if(lenSq > 0.001) {\n vec2 pos = v_text_coord - u_gradient_start.xy;\n t = dot(pos, dir) / lenSq;\n } else {\n t = 0.0;\n }\n }\n gl_FragColor = sampleGradient(t) * v_single_color.a;\n }\n else if(v_type == 2.0) {\n vec2 pos = translateTexturePosition(v_text_coord, v_texture_bounds);\n gl_FragColor = texture2D(u_sample, pos);\n }\n else {\n float r = distance(gl_PointCoord, vec2(0.5, 0.5));\n //\u6839\u636E\u8DDD\u79BB\u8BBE\u7F6E\u7247\u5143\n if(r <= 0.5){\n // \u65B9\u5F62\u533A\u57DF\u7247\u5143\u8DDD\u79BB\u51E0\u4F55\u4E2D\u5FC3\u534A\u5F84\u5C0F\u4E8E0.5\uFF0C\u50CF\u7D20\u989C\u8272\u8BBE\u7F6E\u7EA2\u8272\n gl_FragColor = v_single_color;\n }else {\n // \u65B9\u5F62\u533A\u57DF\u8DDD\u79BB\u51E0\u4F55\u4E2D\u5FC3\u534A\u5F84\u4E0D\u5C0F\u4E8E0.5\u7684\u7247\u5143\u526A\u88C1\u820D\u5F03\u6389\uFF1A\n discard;\n }\n }\n }\n");
|
|
8530
|
+
/**
|
|
8531
|
+
* WebGL 基础渲染类
|
|
8532
|
+
* 提供 WebGL 渲染的核心功能,包括着色器、缓冲区、纹理管理等
|
|
8533
|
+
*
|
|
8534
|
+
* @class WeblBase
|
|
8535
|
+
* @example
|
|
8536
|
+
* const base = new WeblBase(graph, { mode: 'webgl' });
|
|
8537
|
+
* base.setStyle({ fillStyle: '#ff0000' });
|
|
8538
|
+
*/
|
|
8539
|
+
|
|
6985
8540
|
exports.pathFragmentSource = pathFragmentSource;
|
|
6986
8541
|
|
|
6987
8542
|
var WeblBase = /*#__PURE__*/function () {
|
|
8543
|
+
/**
|
|
8544
|
+
* 构造函数
|
|
8545
|
+
* @param {jmGraph} graph jmGraph 实例
|
|
8546
|
+
* @param {Object} option 配置选项
|
|
8547
|
+
*/
|
|
6988
8548
|
function WeblBase(graph, option) {
|
|
6989
8549
|
_classCallCheck(this, WeblBase);
|
|
6990
8550
|
|
|
@@ -6994,14 +8554,19 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6994
8554
|
globalAlpha: 1
|
|
6995
8555
|
};
|
|
6996
8556
|
this.stateStack = [];
|
|
6997
|
-
|
|
8557
|
+
/** @type {number[]} 2D 变换矩阵 [a, b, c, d, tx, ty] */
|
|
8558
|
+
|
|
8559
|
+
this.transformMatrix = [1, 0, 0, 1, 0, 0];
|
|
6998
8560
|
}
|
|
8561
|
+
/** @returns {WebGLRenderingContext} WebGL 渲染上下文 */
|
|
8562
|
+
|
|
6999
8563
|
|
|
7000
8564
|
_createClass(WeblBase, [{
|
|
7001
8565
|
key: "context",
|
|
7002
8566
|
get: function get() {
|
|
7003
8567
|
if (this.graph) return this.graph.context;
|
|
7004
|
-
}
|
|
8568
|
+
}
|
|
8569
|
+
/** 保存当前状态到状态栈 */
|
|
7005
8570
|
|
|
7006
8571
|
}, {
|
|
7007
8572
|
key: "save",
|
|
@@ -7010,7 +8575,8 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7010
8575
|
transformMatrix: _toConsumableArray(this.transformMatrix),
|
|
7011
8576
|
style: _objectSpread({}, this.style)
|
|
7012
8577
|
});
|
|
7013
|
-
}
|
|
8578
|
+
}
|
|
8579
|
+
/** 从状态栈恢复上一个状态 */
|
|
7014
8580
|
|
|
7015
8581
|
}, {
|
|
7016
8582
|
key: "restore",
|
|
@@ -7020,25 +8586,37 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7020
8586
|
this.transformMatrix = state.transformMatrix;
|
|
7021
8587
|
this.style = state.style;
|
|
7022
8588
|
}
|
|
7023
|
-
}
|
|
8589
|
+
}
|
|
8590
|
+
/**
|
|
8591
|
+
* 平移变换
|
|
8592
|
+
* @param {number} x X 轴平移量
|
|
8593
|
+
* @param {number} y Y 轴平移量
|
|
8594
|
+
*/
|
|
7024
8595
|
|
|
7025
8596
|
}, {
|
|
7026
8597
|
key: "translate",
|
|
7027
8598
|
value: function translate(x, y) {
|
|
7028
|
-
// 更新变换矩阵
|
|
7029
8599
|
this.transformMatrix[4] += x * this.transformMatrix[0] + y * this.transformMatrix[2];
|
|
7030
8600
|
this.transformMatrix[5] += x * this.transformMatrix[1] + y * this.transformMatrix[3];
|
|
7031
|
-
}
|
|
8601
|
+
}
|
|
8602
|
+
/**
|
|
8603
|
+
* 缩放变换
|
|
8604
|
+
* @param {number} sx X 轴缩放比例
|
|
8605
|
+
* @param {number} sy Y 轴缩放比例
|
|
8606
|
+
*/
|
|
7032
8607
|
|
|
7033
8608
|
}, {
|
|
7034
8609
|
key: "scale",
|
|
7035
8610
|
value: function scale(sx, sy) {
|
|
7036
|
-
// 更新变换矩阵
|
|
7037
8611
|
this.transformMatrix[0] *= sx;
|
|
7038
8612
|
this.transformMatrix[1] *= sx;
|
|
7039
8613
|
this.transformMatrix[2] *= sy;
|
|
7040
8614
|
this.transformMatrix[3] *= sy;
|
|
7041
|
-
}
|
|
8615
|
+
}
|
|
8616
|
+
/**
|
|
8617
|
+
* 旋转变换
|
|
8618
|
+
* @param {number} angle 旋转角度(弧度)
|
|
8619
|
+
*/
|
|
7042
8620
|
|
|
7043
8621
|
}, {
|
|
7044
8622
|
key: "rotate",
|
|
@@ -7050,14 +8628,22 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7050
8628
|
a = _this$transformMatrix[0],
|
|
7051
8629
|
b = _this$transformMatrix[1],
|
|
7052
8630
|
c = _this$transformMatrix[2],
|
|
7053
|
-
d = _this$transformMatrix[3];
|
|
7054
|
-
|
|
8631
|
+
d = _this$transformMatrix[3];
|
|
7055
8632
|
|
|
7056
8633
|
this.transformMatrix[0] = a * cos - b * sin;
|
|
7057
8634
|
this.transformMatrix[1] = a * sin + b * cos;
|
|
7058
8635
|
this.transformMatrix[2] = c * cos - d * sin;
|
|
7059
8636
|
this.transformMatrix[3] = c * sin + d * cos;
|
|
7060
|
-
}
|
|
8637
|
+
}
|
|
8638
|
+
/**
|
|
8639
|
+
* 矩阵变换
|
|
8640
|
+
* @param {number} a 水平缩放
|
|
8641
|
+
* @param {number} b 垂直倾斜
|
|
8642
|
+
* @param {number} c 水平倾斜
|
|
8643
|
+
* @param {number} d 垂直缩放
|
|
8644
|
+
* @param {number} e 水平移动
|
|
8645
|
+
* @param {number} f 垂直移动
|
|
8646
|
+
*/
|
|
7061
8647
|
|
|
7062
8648
|
}, {
|
|
7063
8649
|
key: "transform",
|
|
@@ -7068,8 +8654,7 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7068
8654
|
currentC = _this$transformMatrix2[2],
|
|
7069
8655
|
currentD = _this$transformMatrix2[3],
|
|
7070
8656
|
currentE = _this$transformMatrix2[4],
|
|
7071
|
-
currentF = _this$transformMatrix2[5];
|
|
7072
|
-
|
|
8657
|
+
currentF = _this$transformMatrix2[5];
|
|
7073
8658
|
|
|
7074
8659
|
this.transformMatrix[0] = a * currentA + b * currentC;
|
|
7075
8660
|
this.transformMatrix[1] = a * currentB + b * currentD;
|
|
@@ -7077,7 +8662,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7077
8662
|
this.transformMatrix[3] = c * currentB + d * currentD;
|
|
7078
8663
|
this.transformMatrix[4] = e * currentA + f * currentC + currentE;
|
|
7079
8664
|
this.transformMatrix[5] = e * currentB + f * currentD + currentF;
|
|
7080
|
-
}
|
|
8665
|
+
}
|
|
8666
|
+
/**
|
|
8667
|
+
* 应用变换到点
|
|
8668
|
+
* @param {Object} point 点坐标 {x, y}
|
|
8669
|
+
* @returns {Object} 变换后的点坐标 {x, y}
|
|
8670
|
+
*/
|
|
7081
8671
|
|
|
7082
8672
|
}, {
|
|
7083
8673
|
key: "applyTransform",
|
|
@@ -7094,7 +8684,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7094
8684
|
x: a * point.x + c * point.y + tx,
|
|
7095
8685
|
y: b * point.x + d * point.y + ty
|
|
7096
8686
|
};
|
|
7097
|
-
}
|
|
8687
|
+
}
|
|
8688
|
+
/**
|
|
8689
|
+
* 文本测量用的离屏 canvas context
|
|
8690
|
+
* @private
|
|
8691
|
+
* @returns {CanvasRenderingContext2D|null}
|
|
8692
|
+
*/
|
|
7098
8693
|
|
|
7099
8694
|
}, {
|
|
7100
8695
|
key: "_measureCtx",
|
|
@@ -7112,14 +8707,22 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7112
8707
|
}
|
|
7113
8708
|
|
|
7114
8709
|
return this.__measureCtx;
|
|
7115
|
-
}
|
|
8710
|
+
}
|
|
8711
|
+
/**
|
|
8712
|
+
* 获取当前着色器程序
|
|
8713
|
+
* @returns {Object} 着色器程序对象
|
|
8714
|
+
*/
|
|
7116
8715
|
|
|
7117
8716
|
}, {
|
|
7118
8717
|
key: "program",
|
|
7119
8718
|
get: function get() {
|
|
7120
|
-
// 默认所有path用同一个编译好的program
|
|
7121
8719
|
return this.graph.context.pathProgram || (this.graph.context.pathProgram = this.createProgram(pathVertexSource, pathFragmentSource));
|
|
7122
|
-
}
|
|
8720
|
+
}
|
|
8721
|
+
/**
|
|
8722
|
+
* 设置样式
|
|
8723
|
+
* @param {Object|string} style 样式对象或样式属性名
|
|
8724
|
+
* @param {string} [value] 样式值(当 style 为字符串时使用)
|
|
8725
|
+
*/
|
|
7123
8726
|
|
|
7124
8727
|
}, {
|
|
7125
8728
|
key: "setStyle",
|
|
@@ -7132,29 +8735,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7132
8735
|
obj[style] = value;
|
|
7133
8736
|
style = obj;
|
|
7134
8737
|
}
|
|
7135
|
-
/*
|
|
7136
|
-
// 设置线条颜色或填充色
|
|
7137
|
-
if(style.strokeStyle) {
|
|
7138
|
-
let color = style.strokeStyle;
|
|
7139
|
-
if(typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
|
|
7140
|
-
this.style.strokeStyle = this.graph.utils.rgbToDecimal(color);
|
|
7141
|
-
delete style.strokeStyle;
|
|
7142
|
-
}
|
|
7143
|
-
else if(style.fillStyle) {
|
|
7144
|
-
let color = style.fillStyle;
|
|
7145
|
-
if(this.isGradient(color)) {
|
|
7146
|
-
this.style.fillStyle = color;
|
|
7147
|
-
}
|
|
7148
|
-
else {
|
|
7149
|
-
if(typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
|
|
7150
|
-
this.style.fillStyle = this.graph.utils.rgbToDecimal(color);
|
|
7151
|
-
}
|
|
7152
|
-
delete style.fillStyle;
|
|
7153
|
-
} */
|
|
7154
|
-
|
|
7155
8738
|
|
|
7156
8739
|
this.style = _objectSpread(_objectSpread({}, this.style), style);
|
|
7157
|
-
}
|
|
8740
|
+
}
|
|
8741
|
+
/**
|
|
8742
|
+
* 将颜色转换为 WebGL 可识别的格式
|
|
8743
|
+
* @param {string|Object} color 颜色值
|
|
8744
|
+
* @returns {Object} RGBA 对象 {r, g, b, a},范围 0-1
|
|
8745
|
+
*/
|
|
7158
8746
|
|
|
7159
8747
|
}, {
|
|
7160
8748
|
key: "convertColor",
|
|
@@ -7162,9 +8750,7 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7162
8750
|
if (this.isGradient(color)) return color;
|
|
7163
8751
|
|
|
7164
8752
|
if (typeof color === 'string') {
|
|
7165
|
-
|
|
7166
|
-
color = this.graph.utils.hexToRGBA(color); // hexToRGBA 对无法识别的格式(如 hsl)会原样返回字符串
|
|
7167
|
-
// 利用离屏 canvas 将任意 CSS 颜色转为 rgba
|
|
8753
|
+
color = this.graph.utils.hexToRGBA(color);
|
|
7168
8754
|
|
|
7169
8755
|
if (typeof color === 'string') {
|
|
7170
8756
|
color = this.__parseCSSColor(color);
|
|
@@ -7176,7 +8762,13 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7176
8762
|
}
|
|
7177
8763
|
|
|
7178
8764
|
return color;
|
|
7179
|
-
}
|
|
8765
|
+
}
|
|
8766
|
+
/**
|
|
8767
|
+
* 利用离屏 canvas 解析任意 CSS 颜色
|
|
8768
|
+
* @private
|
|
8769
|
+
* @param {string} colorStr CSS 颜色字符串
|
|
8770
|
+
* @returns {Object} RGBA 对象 {r, g, b, a}
|
|
8771
|
+
*/
|
|
7180
8772
|
|
|
7181
8773
|
}, {
|
|
7182
8774
|
key: "__parseCSSColor",
|
|
@@ -7224,13 +8816,24 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7224
8816
|
a: 0
|
|
7225
8817
|
};
|
|
7226
8818
|
}
|
|
7227
|
-
}
|
|
8819
|
+
}
|
|
8820
|
+
/**
|
|
8821
|
+
* 创建着色器程序
|
|
8822
|
+
* @param {string} vertexSrc 顶点着色器源码
|
|
8823
|
+
* @param {string} fragmentSrc 片段着色器源码
|
|
8824
|
+
* @returns {Object} 着色器程序对象
|
|
8825
|
+
*/
|
|
7228
8826
|
|
|
7229
8827
|
}, {
|
|
7230
8828
|
key: "createProgram",
|
|
7231
8829
|
value: function createProgram(vertexSrc, fragmentSrc) {
|
|
7232
8830
|
return (0, _program.createProgram)(this.context, vertexSrc, fragmentSrc);
|
|
7233
|
-
}
|
|
8831
|
+
}
|
|
8832
|
+
/**
|
|
8833
|
+
* 使用指定的着色器程序
|
|
8834
|
+
* @param {Object} [program] 着色器程序,默认使用当前程序
|
|
8835
|
+
* @returns {Object} 着色器程序
|
|
8836
|
+
*/
|
|
7234
8837
|
|
|
7235
8838
|
}, {
|
|
7236
8839
|
key: "useProgram",
|
|
@@ -7242,21 +8845,38 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7242
8845
|
this.context.__curent_program = program;
|
|
7243
8846
|
return program;
|
|
7244
8847
|
}
|
|
8848
|
+
/**
|
|
8849
|
+
* 获取属性位置
|
|
8850
|
+
* @param {string} name 属性名
|
|
8851
|
+
* @returns {number} 属性位置
|
|
8852
|
+
*/
|
|
8853
|
+
|
|
7245
8854
|
}, {
|
|
7246
8855
|
key: "getAttribLocation",
|
|
7247
8856
|
value: function getAttribLocation(name) {
|
|
7248
8857
|
return this.context.getAttribLocation(this.program.program, name);
|
|
7249
8858
|
}
|
|
8859
|
+
/**
|
|
8860
|
+
* 获取 uniform 位置
|
|
8861
|
+
* @param {string} name uniform 变量名
|
|
8862
|
+
* @returns {WebGLUniformLocation} uniform 位置
|
|
8863
|
+
*/
|
|
8864
|
+
|
|
7250
8865
|
}, {
|
|
7251
8866
|
key: "getUniformLocation",
|
|
7252
8867
|
value: function getUniformLocation(name) {
|
|
7253
8868
|
return this.context.getUniformLocation(this.program.program, name);
|
|
7254
|
-
}
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
|
|
8869
|
+
}
|
|
8870
|
+
/**
|
|
8871
|
+
* 将缓冲区数据写入顶点属性
|
|
8872
|
+
* @param {Object} buffer 缓冲区对象
|
|
8873
|
+
* @param {Object} attr 属性对象
|
|
8874
|
+
* @param {number} [size=2] 每个顶点的分量数(1-4)
|
|
8875
|
+
* @param {number} [strip=0] 步长,0 表示紧密排列
|
|
8876
|
+
* @param {number} [offset=0] 字节偏移量
|
|
8877
|
+
* @param {number} [dataType=FLOAT] 数据类型
|
|
8878
|
+
* @returns {Object} 缓冲区对象
|
|
8879
|
+
*/
|
|
7260
8880
|
|
|
7261
8881
|
}, {
|
|
7262
8882
|
key: "writeVertexAttrib",
|
|
@@ -7267,7 +8887,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7267
8887
|
var dataType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this.context.FLOAT;
|
|
7268
8888
|
buffer.attr = attr;
|
|
7269
8889
|
return (0, _program.writeVertexAttrib)(this.context, buffer, attr, size, strip, offset, dataType);
|
|
7270
|
-
}
|
|
8890
|
+
}
|
|
8891
|
+
/**
|
|
8892
|
+
* 禁用顶点属性数组
|
|
8893
|
+
* @param {Object} attr 属性对象
|
|
8894
|
+
* @returns {Object} 属性对象
|
|
8895
|
+
*/
|
|
7271
8896
|
|
|
7272
8897
|
}, {
|
|
7273
8898
|
key: "disableVertexAttribArray",
|
|
@@ -7280,7 +8905,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7280
8905
|
}
|
|
7281
8906
|
|
|
7282
8907
|
return attr;
|
|
7283
|
-
}
|
|
8908
|
+
}
|
|
8909
|
+
/**
|
|
8910
|
+
* 创建 Float32 缓冲区
|
|
8911
|
+
* @param {Array} data 数据数组
|
|
8912
|
+
* @param {number} [type=ARRAY_BUFFER] 缓冲区类型
|
|
8913
|
+
* @param {number} [drawType=STATIC_DRAW] 绘制类型
|
|
8914
|
+
* @returns {Object} 缓冲区对象
|
|
8915
|
+
*/
|
|
7284
8916
|
|
|
7285
8917
|
}, {
|
|
7286
8918
|
key: "createFloat32Buffer",
|
|
@@ -7292,6 +8924,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7292
8924
|
data: data
|
|
7293
8925
|
}, buffer);
|
|
7294
8926
|
}
|
|
8927
|
+
/**
|
|
8928
|
+
* 创建 Uint16 缓冲区
|
|
8929
|
+
* @param {Array} data 数据数组
|
|
8930
|
+
* @param {number} [type=ARRAY_BUFFER] 缓冲区类型
|
|
8931
|
+
* @param {number} [drawType=STATIC_DRAW] 绘制类型
|
|
8932
|
+
* @returns {Object} 缓冲区对象
|
|
8933
|
+
*/
|
|
8934
|
+
|
|
7295
8935
|
}, {
|
|
7296
8936
|
key: "createUint16Buffer",
|
|
7297
8937
|
value: function createUint16Buffer(data) {
|
|
@@ -7301,7 +8941,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7301
8941
|
return _objectSpread({
|
|
7302
8942
|
data: data
|
|
7303
8943
|
}, buffer);
|
|
7304
|
-
}
|
|
8944
|
+
}
|
|
8945
|
+
/**
|
|
8946
|
+
* 删除缓冲区
|
|
8947
|
+
* @param {Object} buffer 缓冲区对象
|
|
8948
|
+
* @returns {Object} 缓冲区对象
|
|
8949
|
+
*/
|
|
7305
8950
|
|
|
7306
8951
|
}, {
|
|
7307
8952
|
key: "deleteBuffer",
|
|
@@ -7316,25 +8961,41 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7316
8961
|
}
|
|
7317
8962
|
|
|
7318
8963
|
return buffer;
|
|
7319
|
-
}
|
|
8964
|
+
}
|
|
8965
|
+
/** @returns {WebGLTexture} 2D 纹理对象 */
|
|
7320
8966
|
|
|
7321
8967
|
}, {
|
|
7322
8968
|
key: "create2DTexture",
|
|
7323
8969
|
value: function create2DTexture() {
|
|
7324
8970
|
return (0, _texture.create2DTexture)(this.context);
|
|
7325
|
-
}
|
|
8971
|
+
}
|
|
8972
|
+
/**
|
|
8973
|
+
* 创建图片纹理
|
|
8974
|
+
* @param {Image|HTMLImageElement} img 图像对象
|
|
8975
|
+
* @returns {Object} 纹理对象
|
|
8976
|
+
*/
|
|
7326
8977
|
|
|
7327
8978
|
}, {
|
|
7328
8979
|
key: "createImgTexture",
|
|
7329
8980
|
value: function createImgTexture(img) {
|
|
7330
8981
|
return (0, _texture.createImgTexture)(this.context, img);
|
|
7331
|
-
}
|
|
8982
|
+
}
|
|
8983
|
+
/**
|
|
8984
|
+
* 根据像素数据创建纹理
|
|
8985
|
+
* @param {ImageData|Uint8Array} data 像素数据
|
|
8986
|
+
* @returns {Object} 纹理对象
|
|
8987
|
+
*/
|
|
7332
8988
|
|
|
7333
8989
|
}, {
|
|
7334
8990
|
key: "createDataTexture",
|
|
7335
8991
|
value: function createDataTexture(data) {
|
|
7336
8992
|
return (0, _texture.createDataTexture)(this.context, data);
|
|
7337
|
-
}
|
|
8993
|
+
}
|
|
8994
|
+
/**
|
|
8995
|
+
* 删除纹理
|
|
8996
|
+
* @param {Object} texture 纹理对象
|
|
8997
|
+
* @returns {Object} 纹理对象
|
|
8998
|
+
*/
|
|
7338
8999
|
|
|
7339
9000
|
}, {
|
|
7340
9001
|
key: "deleteTexture",
|
|
@@ -7346,41 +9007,51 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7346
9007
|
}
|
|
7347
9008
|
|
|
7348
9009
|
return texture;
|
|
7349
|
-
}
|
|
7350
|
-
|
|
9010
|
+
}
|
|
9011
|
+
/**
|
|
9012
|
+
* 多边形三角化,得到三角形顶点索引数组
|
|
9013
|
+
* @param {Array<Object>} points 多边形顶点数组
|
|
9014
|
+
* @returns {Array<number>} 三角形顶点索引数组
|
|
9015
|
+
*/
|
|
7351
9016
|
|
|
7352
9017
|
}, {
|
|
7353
9018
|
key: "earCutPoints",
|
|
7354
9019
|
value: function earCutPoints(points) {
|
|
7355
9020
|
var arr = this.pointsToArray(points);
|
|
7356
|
-
var ps = (0, _earcut["default"])(arr);
|
|
7357
|
-
|
|
9021
|
+
var ps = (0, _earcut["default"])(arr);
|
|
7358
9022
|
return ps;
|
|
7359
|
-
}
|
|
7360
|
-
|
|
9023
|
+
}
|
|
9024
|
+
/**
|
|
9025
|
+
* 多边形三角化,得到三角形顶点数组
|
|
9026
|
+
* @param {Array<Object>} points 多边形顶点数组
|
|
9027
|
+
* @returns {Array<Array<Object>>} 三角形数组,每个三角形包含3个顶点
|
|
9028
|
+
*/
|
|
7361
9029
|
|
|
7362
9030
|
}, {
|
|
7363
9031
|
key: "earCutPointsToTriangles",
|
|
7364
9032
|
value: function earCutPointsToTriangles(points) {
|
|
7365
|
-
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
7366
|
-
|
|
9033
|
+
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
7367
9034
|
var len = points.length;
|
|
7368
9035
|
var key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len - 1].x + '_' + points[len - 1].y;
|
|
7369
9036
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
7370
|
-
var ps = this.earCutPoints(points);
|
|
7371
|
-
|
|
7372
|
-
var triangles = []; // 用顶点索引再组合成坐标数组
|
|
9037
|
+
var ps = this.earCutPoints(points);
|
|
9038
|
+
var triangles = [];
|
|
7373
9039
|
|
|
7374
9040
|
for (var i = 0; i < ps.length; i += 3) {
|
|
7375
9041
|
var p1 = points[ps[i]];
|
|
7376
9042
|
var p2 = points[ps[i + 1]];
|
|
7377
9043
|
var p3 = points[ps[i + 2]];
|
|
7378
|
-
triangles.push([p1, p2, p3]);
|
|
9044
|
+
triangles.push([p1, p2, p3]);
|
|
7379
9045
|
}
|
|
7380
9046
|
|
|
7381
9047
|
this.earCutCache[key] = triangles;
|
|
7382
9048
|
return triangles;
|
|
7383
|
-
}
|
|
9049
|
+
}
|
|
9050
|
+
/**
|
|
9051
|
+
* 点坐标数组转为一维数组
|
|
9052
|
+
* @param {Array<Object>} points 点数组 [{x, y}, ...]
|
|
9053
|
+
* @returns {Array<number>} 一维数组 [x1, y1, x2, y2, ...]
|
|
9054
|
+
*/
|
|
7384
9055
|
|
|
7385
9056
|
}, {
|
|
7386
9057
|
key: "pointsToArray",
|
|
@@ -7389,8 +9060,13 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7389
9060
|
|
|
7390
9061
|
return (_ref = []).concat.apply(_ref, _toConsumableArray(points.map(function (p) {
|
|
7391
9062
|
return [p.x, p.y];
|
|
7392
|
-
})));
|
|
7393
|
-
}
|
|
9063
|
+
})));
|
|
9064
|
+
}
|
|
9065
|
+
/**
|
|
9066
|
+
* 一维数组转为点坐标数组
|
|
9067
|
+
* @param {Array<number>} arr 一维数组 [x1, y1, x2, y2, ...]
|
|
9068
|
+
* @returns {Array<Object>} 点数组 [{x, y}, ...]
|
|
9069
|
+
*/
|
|
7394
9070
|
|
|
7395
9071
|
}, {
|
|
7396
9072
|
key: "arrayToPoints",
|
|
@@ -7405,7 +9081,16 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7405
9081
|
}
|
|
7406
9082
|
|
|
7407
9083
|
return points;
|
|
7408
|
-
}
|
|
9084
|
+
}
|
|
9085
|
+
/**
|
|
9086
|
+
* 创建线性渐变
|
|
9087
|
+
* @param {number} x1 起点X坐标
|
|
9088
|
+
* @param {number} y1 起点Y坐标
|
|
9089
|
+
* @param {number} x2 终点X坐标
|
|
9090
|
+
* @param {number} y2 终点Y坐标
|
|
9091
|
+
* @param {Object} bounds 渐变边界
|
|
9092
|
+
* @returns {WebglGradient} 渐变对象
|
|
9093
|
+
*/
|
|
7409
9094
|
|
|
7410
9095
|
}, {
|
|
7411
9096
|
key: "createLinearGradient",
|
|
@@ -7418,7 +9103,18 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7418
9103
|
bounds: bounds,
|
|
7419
9104
|
control: this
|
|
7420
9105
|
});
|
|
7421
|
-
}
|
|
9106
|
+
}
|
|
9107
|
+
/**
|
|
9108
|
+
* 创建径向渐变
|
|
9109
|
+
* @param {number} x1 内圆中心X坐标
|
|
9110
|
+
* @param {number} y1 内圆中心Y坐标
|
|
9111
|
+
* @param {number} r1 内圆半径
|
|
9112
|
+
* @param {number} x2 外圆中心X坐标
|
|
9113
|
+
* @param {number} y2 外圆中心Y坐标
|
|
9114
|
+
* @param {number} r2 外圆半径
|
|
9115
|
+
* @param {Object} bounds 渐变边界
|
|
9116
|
+
* @returns {WebglGradient} 渐变对象
|
|
9117
|
+
*/
|
|
7422
9118
|
|
|
7423
9119
|
}, {
|
|
7424
9120
|
key: "createRadialGradient",
|
|
@@ -7433,7 +9129,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7433
9129
|
bounds: bounds,
|
|
7434
9130
|
control: this
|
|
7435
9131
|
});
|
|
7436
|
-
}
|
|
9132
|
+
}
|
|
9133
|
+
/**
|
|
9134
|
+
* 判断是否为渐变对象
|
|
9135
|
+
* @param {Object} obj 待检测对象
|
|
9136
|
+
* @returns {boolean} 是否为渐变对象
|
|
9137
|
+
*/
|
|
7437
9138
|
|
|
7438
9139
|
}, {
|
|
7439
9140
|
key: "isGradient",
|
|
@@ -7484,32 +9185,53 @@ exports.createUint16Buffer = createUint16Buffer;
|
|
|
7484
9185
|
exports.createFloat32Buffer = createFloat32Buffer;
|
|
7485
9186
|
exports.deleteBuffer = deleteBuffer;
|
|
7486
9187
|
|
|
7487
|
-
|
|
9188
|
+
/**
|
|
9189
|
+
* @fileoverview WebGL 缓冲区管理模块
|
|
9190
|
+
*
|
|
9191
|
+
* 本模块提供了 WebGL 缓冲区的创建和管理功能,包括:
|
|
9192
|
+
* - 创建通用缓冲区
|
|
9193
|
+
* - 创建 Float32 类型缓冲区
|
|
9194
|
+
* - 创建 Uint16 类型缓冲区
|
|
9195
|
+
* - 删除缓冲区
|
|
9196
|
+
*
|
|
9197
|
+
* @module lib/webgl/core/buffer
|
|
9198
|
+
* @author jmGraph Team
|
|
9199
|
+
*/
|
|
9200
|
+
|
|
9201
|
+
/**
|
|
9202
|
+
* 创建 WebGL 缓冲区
|
|
9203
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9204
|
+
* @param {Array|TypedArray} data 缓冲区数据
|
|
9205
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9206
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9207
|
+
* @returns {Object} 缓冲区对象 {type, drawType, buffer, unitSize}
|
|
9208
|
+
*/
|
|
7488
9209
|
function createBuffer(gl, data) {
|
|
7489
9210
|
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
|
|
7490
9211
|
var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
|
|
7491
|
-
//先创建一个缓存对象
|
|
7492
9212
|
var buffer = gl.createBuffer();
|
|
7493
9213
|
|
|
7494
9214
|
if (!buffer) {
|
|
7495
9215
|
throw Error('创建缓冲区对象失败');
|
|
7496
|
-
}
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
gl.bindBuffer(type, buffer); //写入坐标数据
|
|
7500
|
-
// 因为会将数据发送到 GPU,为了省去数据解析,这里使用 Float32Array 直接传送数据
|
|
7501
|
-
// data.buffer这里要使用data.buffer,否则在edge下可能导至数据发生较大的改变
|
|
7502
|
-
|
|
7503
|
-
gl.bufferData(type, data.buffer || data, drawType); // 表示缓冲区的内容不会经常更改
|
|
9216
|
+
}
|
|
7504
9217
|
|
|
9218
|
+
gl.bindBuffer(type, buffer);
|
|
9219
|
+
gl.bufferData(type, data.buffer || data, drawType);
|
|
7505
9220
|
return {
|
|
7506
9221
|
type: type,
|
|
7507
9222
|
drawType: drawType,
|
|
7508
9223
|
buffer: buffer,
|
|
7509
|
-
// 获取到数组中单个元素的字节数
|
|
7510
9224
|
unitSize: data.BYTES_PER_ELEMENT
|
|
7511
9225
|
};
|
|
7512
|
-
}
|
|
9226
|
+
}
|
|
9227
|
+
/**
|
|
9228
|
+
* 创建 Float32 类型缓冲区
|
|
9229
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9230
|
+
* @param {Array} data 数据数组
|
|
9231
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9232
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9233
|
+
* @returns {Object} 缓冲区对象
|
|
9234
|
+
*/
|
|
7513
9235
|
|
|
7514
9236
|
|
|
7515
9237
|
function createFloat32Buffer(gl, data) {
|
|
@@ -7518,7 +9240,15 @@ function createFloat32Buffer(gl, data) {
|
|
|
7518
9240
|
var vertices = new Float32Array(data);
|
|
7519
9241
|
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
7520
9242
|
return buffer;
|
|
7521
|
-
}
|
|
9243
|
+
}
|
|
9244
|
+
/**
|
|
9245
|
+
* 创建 Uint16 类型缓冲区
|
|
9246
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9247
|
+
* @param {Array} data 数据数组
|
|
9248
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9249
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9250
|
+
* @returns {Object} 缓冲区对象
|
|
9251
|
+
*/
|
|
7522
9252
|
|
|
7523
9253
|
|
|
7524
9254
|
function createUint16Buffer(gl, data) {
|
|
@@ -7527,7 +9257,12 @@ function createUint16Buffer(gl, data) {
|
|
|
7527
9257
|
var vertices = new Uint16Array(data);
|
|
7528
9258
|
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
7529
9259
|
return buffer;
|
|
7530
|
-
}
|
|
9260
|
+
}
|
|
9261
|
+
/**
|
|
9262
|
+
* 删除缓冲区
|
|
9263
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9264
|
+
* @param {Object|WebGLBuffer} buffer 缓冲区对象或 WebGL 缓冲区
|
|
9265
|
+
*/
|
|
7531
9266
|
|
|
7532
9267
|
|
|
7533
9268
|
function deleteBuffer(gl, buffer) {
|
|
@@ -7541,6 +9276,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7541
9276
|
value: true
|
|
7542
9277
|
});
|
|
7543
9278
|
exports.mapSize = void 0;
|
|
9279
|
+
|
|
9280
|
+
/**
|
|
9281
|
+
* @fileoverview GLSL 类型大小映射模块
|
|
9282
|
+
*
|
|
9283
|
+
* 本模块提供了 GLSL 类型到其元素数量的映射。
|
|
9284
|
+
*
|
|
9285
|
+
* @module lib/webgl/core/mapSize
|
|
9286
|
+
* @author jmGraph Team
|
|
9287
|
+
*/
|
|
9288
|
+
|
|
9289
|
+
/**
|
|
9290
|
+
* GLSL 类型到元素数量的映射表
|
|
9291
|
+
* @constant {Object.<string, number>}
|
|
9292
|
+
*/
|
|
7544
9293
|
var GLSL_TO_SIZE = {
|
|
7545
9294
|
'float': 1,
|
|
7546
9295
|
'vec2': 2,
|
|
@@ -7560,10 +9309,9 @@ var GLSL_TO_SIZE = {
|
|
|
7560
9309
|
'sampler2D': 1
|
|
7561
9310
|
};
|
|
7562
9311
|
/**
|
|
7563
|
-
*
|
|
7564
|
-
* @
|
|
7565
|
-
* @
|
|
7566
|
-
* @return {Number}
|
|
9312
|
+
* 根据 GLSL 类型名获取元素数量
|
|
9313
|
+
* @param {string} type GLSL 类型名
|
|
9314
|
+
* @returns {number} 元素数量
|
|
7567
9315
|
*/
|
|
7568
9316
|
|
|
7569
9317
|
var mapSize = function mapSize(type) {
|
|
@@ -7579,7 +9327,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7579
9327
|
value: true
|
|
7580
9328
|
});
|
|
7581
9329
|
exports.mapType = void 0;
|
|
9330
|
+
|
|
9331
|
+
/**
|
|
9332
|
+
* @fileoverview WebGL 类型到 GLSL 类型映射模块
|
|
9333
|
+
*
|
|
9334
|
+
* 本模块提供了 WebGL 常量类型到 GLSL 类型名的映射。
|
|
9335
|
+
*
|
|
9336
|
+
* @module lib/webgl/core/mapType
|
|
9337
|
+
* @author jmGraph Team
|
|
9338
|
+
*/
|
|
9339
|
+
|
|
9340
|
+
/** @type {Object.<number, string>|null} 缓存的类型映射表 */
|
|
7582
9341
|
var GL_TABLE = null;
|
|
9342
|
+
/**
|
|
9343
|
+
* WebGL 常量到 GLSL 类型的映射表
|
|
9344
|
+
* @constant {Object.<string, string>}
|
|
9345
|
+
*/
|
|
9346
|
+
|
|
7583
9347
|
var GL_TO_GLSL_TYPES = {
|
|
7584
9348
|
'FLOAT': 'float',
|
|
7585
9349
|
'FLOAT_VEC2': 'vec2',
|
|
@@ -7598,6 +9362,12 @@ var GL_TO_GLSL_TYPES = {
|
|
|
7598
9362
|
'FLOAT_MAT4': 'mat4',
|
|
7599
9363
|
'SAMPLER_2D': 'sampler2D'
|
|
7600
9364
|
};
|
|
9365
|
+
/**
|
|
9366
|
+
* 将 WebGL 类型常量映射为 GLSL 类型名
|
|
9367
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9368
|
+
* @param {number} type WebGL 类型常量
|
|
9369
|
+
* @returns {string} GLSL 类型名
|
|
9370
|
+
*/
|
|
7601
9371
|
|
|
7602
9372
|
var mapType = function mapType(gl, type) {
|
|
7603
9373
|
if (!GL_TABLE) {
|
|
@@ -7636,25 +9406,37 @@ var _mapSize = require("./mapSize.js");
|
|
|
7636
9406
|
|
|
7637
9407
|
var _mapType = require("./mapType.js");
|
|
7638
9408
|
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
9409
|
+
/**
|
|
9410
|
+
* @fileoverview WebGL 着色器程序管理模块
|
|
9411
|
+
*
|
|
9412
|
+
* 本模块提供了 WebGL 着色器程序的创建和管理功能,包括:
|
|
9413
|
+
* - 创建着色器程序
|
|
9414
|
+
* - 提取属性和 uniform 变量
|
|
9415
|
+
* - 顶点属性绑定
|
|
9416
|
+
*
|
|
9417
|
+
* @module lib/webgl/core/program
|
|
9418
|
+
* @author jmGraph Team
|
|
9419
|
+
*/
|
|
7643
9420
|
|
|
9421
|
+
/**
|
|
9422
|
+
* 创建着色器程序
|
|
9423
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9424
|
+
* @param {string} vertexSrc 顶点着色器源码
|
|
9425
|
+
* @param {string} fragmentSrc 片段着色器源码
|
|
9426
|
+
* @returns {Object} 程序对象 {program, attrs, uniforms}
|
|
9427
|
+
*/
|
|
9428
|
+
function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
9429
|
+
var vertexShader = (0, _shader.createShader)(gl, gl.VERTEX_SHADER, vertexSrc);
|
|
7644
9430
|
var fragmentShader = (0, _shader.createShader)(gl, gl.FRAGMENT_SHADER, fragmentSrc);
|
|
7645
|
-
var program = gl.createProgram();
|
|
7646
|
-
|
|
7647
|
-
gl.attachShader(program,
|
|
7648
|
-
|
|
7649
|
-
gl.attachShader(program, fragmentShader); // 添加片元着色器
|
|
7650
|
-
|
|
7651
|
-
gl.linkProgram(program); // 连接 program 中的着色器
|
|
7652
|
-
// 检查程序链接状态
|
|
9431
|
+
var program = gl.createProgram();
|
|
9432
|
+
gl.attachShader(program, vertexShader);
|
|
9433
|
+
gl.attachShader(program, fragmentShader);
|
|
9434
|
+
gl.linkProgram(program);
|
|
7653
9435
|
|
|
7654
9436
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
7655
9437
|
console.error('PError: Could not initialize shader.');
|
|
7656
9438
|
console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS));
|
|
7657
|
-
console.error('gl.getError()', gl.getError());
|
|
9439
|
+
console.error('gl.getError()', gl.getError());
|
|
7658
9440
|
|
|
7659
9441
|
if (gl.getProgramInfoLog(program) !== '') {
|
|
7660
9442
|
console.warn('Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
|
|
@@ -7663,8 +9445,7 @@ function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
|
7663
9445
|
gl.deleteProgram(program);
|
|
7664
9446
|
}
|
|
7665
9447
|
|
|
7666
|
-
useProgram(gl, program);
|
|
7667
|
-
|
|
9448
|
+
useProgram(gl, program);
|
|
7668
9449
|
gl.deleteShader(vertexShader);
|
|
7669
9450
|
gl.deleteShader(fragmentShader);
|
|
7670
9451
|
var attrs = extractAttributes(gl, program);
|
|
@@ -7674,12 +9455,24 @@ function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
|
7674
9455
|
attrs: attrs,
|
|
7675
9456
|
uniforms: uniforms
|
|
7676
9457
|
};
|
|
7677
|
-
}
|
|
9458
|
+
}
|
|
9459
|
+
/**
|
|
9460
|
+
* 使用指定的着色器程序
|
|
9461
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9462
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9463
|
+
*/
|
|
7678
9464
|
|
|
7679
9465
|
|
|
7680
9466
|
function useProgram(gl, program) {
|
|
7681
|
-
return gl.useProgram(program);
|
|
9467
|
+
return gl.useProgram(program);
|
|
7682
9468
|
}
|
|
9469
|
+
/**
|
|
9470
|
+
* 提取着色器程序中的所有属性
|
|
9471
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9472
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9473
|
+
* @returns {Object} 属性对象字典
|
|
9474
|
+
*/
|
|
9475
|
+
|
|
7683
9476
|
|
|
7684
9477
|
function extractAttributes(gl, program) {
|
|
7685
9478
|
var attributes = {};
|
|
@@ -7698,6 +9491,13 @@ function extractAttributes(gl, program) {
|
|
|
7698
9491
|
|
|
7699
9492
|
return attributes;
|
|
7700
9493
|
}
|
|
9494
|
+
/**
|
|
9495
|
+
* 提取着色器程序中的所有 uniform 变量
|
|
9496
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9497
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9498
|
+
* @returns {Object} uniform 变量对象字典
|
|
9499
|
+
*/
|
|
9500
|
+
|
|
7701
9501
|
|
|
7702
9502
|
function extractUniforms(gl, program) {
|
|
7703
9503
|
var uniforms = {};
|
|
@@ -7717,12 +9517,18 @@ function extractUniforms(gl, program) {
|
|
|
7717
9517
|
|
|
7718
9518
|
return uniforms;
|
|
7719
9519
|
}
|
|
9520
|
+
/**
|
|
9521
|
+
* 将缓冲区数据写入顶点属性
|
|
9522
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9523
|
+
* @param {Object} buffer 缓冲区对象
|
|
9524
|
+
* @param {Object} attr 属性对象
|
|
9525
|
+
* @param {number} [size=2] 每个顶点的分量数(1-4)
|
|
9526
|
+
* @param {number} [strip=0] 步长,0 表示紧密排列
|
|
9527
|
+
* @param {number} [offset=0] 字节偏移量
|
|
9528
|
+
* @param {number} [dataType=gl.FLOAT] 数据类型
|
|
9529
|
+
* @returns {Object} 缓冲区对象
|
|
9530
|
+
*/
|
|
7720
9531
|
|
|
7721
|
-
; // 把缓冲区的值写入变量
|
|
7722
|
-
// size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
|
|
7723
|
-
// strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
|
|
7724
|
-
// offset: 字节偏移量,必须是类型的字节长度的倍数。
|
|
7725
|
-
// dataType: 每个元素的数据类型
|
|
7726
9532
|
|
|
7727
9533
|
function writeVertexAttrib(gl, buffer, attr) {
|
|
7728
9534
|
var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
|
|
@@ -7730,22 +9536,40 @@ function writeVertexAttrib(gl, buffer, attr) {
|
|
|
7730
9536
|
var offset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
7731
9537
|
var dataType = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : gl.FLOAT;
|
|
7732
9538
|
gl.bindBuffer(buffer.type, buffer.buffer);
|
|
7733
|
-
gl.vertexAttribPointer(
|
|
7734
|
-
attr.location, // 顶点属性的索引
|
|
7735
|
-
size, // 组成数量,必须是1,2,3或4。我们只提供了 x 和 y
|
|
7736
|
-
dataType, false, // 是否归一化到特定的范围,对 FLOAT 类型数据设置无效
|
|
7737
|
-
strip * buffer.unitSize, offset);
|
|
9539
|
+
gl.vertexAttribPointer(attr.location, size, dataType, false, strip * buffer.unitSize, offset);
|
|
7738
9540
|
gl.enableVertexAttribArray(attr.location);
|
|
7739
9541
|
return buffer;
|
|
7740
9542
|
}
|
|
9543
|
+
/**
|
|
9544
|
+
* 禁用顶点属性数组
|
|
9545
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9546
|
+
* @param {Object} attr 属性对象
|
|
9547
|
+
*/
|
|
9548
|
+
|
|
7741
9549
|
|
|
7742
9550
|
function disableVertexAttribArray(gl, attr) {
|
|
7743
9551
|
return gl.disableVertexAttribArray(attr.location);
|
|
7744
9552
|
}
|
|
9553
|
+
/**
|
|
9554
|
+
* 获取属性位置
|
|
9555
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9556
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9557
|
+
* @param {string} name 属性名
|
|
9558
|
+
* @returns {number} 属性位置
|
|
9559
|
+
*/
|
|
9560
|
+
|
|
7745
9561
|
|
|
7746
9562
|
function getAttribLocation(gl, program, name) {
|
|
7747
9563
|
return gl.getAttribLocation(program, name);
|
|
7748
9564
|
}
|
|
9565
|
+
/**
|
|
9566
|
+
* 获取 uniform 位置
|
|
9567
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9568
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9569
|
+
* @param {string} name uniform 变量名
|
|
9570
|
+
* @returns {WebGLUniformLocation} uniform 位置
|
|
9571
|
+
*/
|
|
9572
|
+
|
|
7749
9573
|
|
|
7750
9574
|
function getUniformLocation(gl, program, name) {
|
|
7751
9575
|
return gl.getUniformLocation(program, name);
|
|
@@ -7759,16 +9583,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7759
9583
|
});
|
|
7760
9584
|
exports.createShader = createShader;
|
|
7761
9585
|
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
gl.compileShader(shader); // 编译着色器
|
|
9586
|
+
/**
|
|
9587
|
+
* @fileoverview WebGL 着色器管理模块
|
|
9588
|
+
*
|
|
9589
|
+
* 本模块提供了 WebGL 着色器的创建功能。
|
|
9590
|
+
*
|
|
9591
|
+
* @module lib/webgl/core/shader
|
|
9592
|
+
* @author jmGraph Team
|
|
9593
|
+
*/
|
|
7771
9594
|
|
|
9595
|
+
/**
|
|
9596
|
+
* 创建 WebGL 着色器
|
|
9597
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9598
|
+
* @param {number} type 着色器类型:gl.VERTEX_SHADER 或 gl.FRAGMENT_SHADER
|
|
9599
|
+
* @param {string} src 着色器源码
|
|
9600
|
+
* @returns {WebGLShader} 编译后的着色器对象
|
|
9601
|
+
*/
|
|
9602
|
+
function createShader(gl, type, src) {
|
|
9603
|
+
var shader = gl.createShader(type);
|
|
9604
|
+
gl.shaderSource(shader, src);
|
|
9605
|
+
gl.compileShader(shader);
|
|
7772
9606
|
return shader;
|
|
7773
9607
|
}
|
|
7774
9608
|
|
|
@@ -7783,55 +9617,71 @@ exports.createImgTexture = createImgTexture;
|
|
|
7783
9617
|
exports.createDataTexture = createDataTexture;
|
|
7784
9618
|
exports.deleteTexture = deleteTexture;
|
|
7785
9619
|
|
|
7786
|
-
|
|
9620
|
+
/**
|
|
9621
|
+
* @fileoverview WebGL 纹理管理模块
|
|
9622
|
+
*
|
|
9623
|
+
* 本模块提供了 WebGL 纹理的创建和管理功能,包括:
|
|
9624
|
+
* - 创建 2D 纹理
|
|
9625
|
+
* - 创建图片纹理
|
|
9626
|
+
* - 创建数据纹理
|
|
9627
|
+
* - 删除纹理
|
|
9628
|
+
*
|
|
9629
|
+
* @module lib/webgl/core/texture
|
|
9630
|
+
* @author jmGraph Team
|
|
9631
|
+
*/
|
|
9632
|
+
|
|
9633
|
+
/**
|
|
9634
|
+
* 创建 2D 纹理
|
|
9635
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9636
|
+
* @returns {WebGLTexture} 纹理对象
|
|
9637
|
+
*/
|
|
7787
9638
|
function create2DTexture(gl) {
|
|
7788
9639
|
var texture = gl.createTexture();
|
|
7789
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
|
|
7790
|
-
|
|
7791
|
-
gl.
|
|
7792
|
-
|
|
7793
|
-
gl.
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // 放大处理方式 // LINEAR / NEAREST
|
|
7797
|
-
|
|
7798
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // 缩小处理方式
|
|
7799
|
-
|
|
7800
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // 水平平铺方式
|
|
7801
|
-
|
|
7802
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // 竖直平铺方式
|
|
7803
|
-
|
|
9640
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
|
|
9641
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
9642
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
9643
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
9644
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
9645
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
9646
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
7804
9647
|
return texture;
|
|
7805
|
-
}
|
|
9648
|
+
}
|
|
9649
|
+
/**
|
|
9650
|
+
* 创建图片纹理
|
|
9651
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9652
|
+
* @param {Image|HTMLImageElement} img 图像对象
|
|
9653
|
+
* @returns {Object} 纹理对象 {texture}
|
|
9654
|
+
*/
|
|
7806
9655
|
|
|
7807
9656
|
|
|
7808
9657
|
function createImgTexture(gl, img) {
|
|
7809
9658
|
var texture = create2DTexture(gl);
|
|
7810
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
7811
|
-
|
|
9659
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
7812
9660
|
return {
|
|
7813
9661
|
texture: texture
|
|
7814
9662
|
};
|
|
7815
|
-
}
|
|
9663
|
+
}
|
|
9664
|
+
/**
|
|
9665
|
+
* 根据像素数据创建纹理
|
|
9666
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9667
|
+
* @param {ImageData|Object} pixels 像素数据 {data, width, height}
|
|
9668
|
+
* @returns {Object} 纹理对象 {texture}
|
|
9669
|
+
*/
|
|
7816
9670
|
|
|
7817
9671
|
|
|
7818
9672
|
function createDataTexture(gl, pixels) {
|
|
7819
9673
|
var data = new Uint8Array(pixels.data || pixels);
|
|
7820
9674
|
var texture = create2DTexture(gl);
|
|
7821
|
-
gl.texImage2D(gl.TEXTURE_2D,
|
|
7822
|
-
0, // 细节级别,指定详细级别。0 级是基本图像等级,n 级是第 n 个金字塔简化级。
|
|
7823
|
-
gl.RGBA, // 纹理内部格式
|
|
7824
|
-
pixels.width || 1, // 指定纹理的宽度
|
|
7825
|
-
pixels.height || 1, // 指定纹理的高度
|
|
7826
|
-
0, // 指定纹理的边框宽度。必须为 0。
|
|
7827
|
-
gl.RGBA, // 源图像数据格式
|
|
7828
|
-
gl.UNSIGNED_BYTE, // 纹理数据类型
|
|
7829
|
-
data // 数据
|
|
7830
|
-
);
|
|
9675
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, pixels.width || 1, pixels.height || 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
7831
9676
|
return {
|
|
7832
9677
|
texture: texture
|
|
7833
9678
|
};
|
|
7834
|
-
}
|
|
9679
|
+
}
|
|
9680
|
+
/**
|
|
9681
|
+
* 删除纹理
|
|
9682
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9683
|
+
* @param {WebGLTexture} texture 纹理对象
|
|
9684
|
+
*/
|
|
7835
9685
|
|
|
7836
9686
|
|
|
7837
9687
|
function deleteTexture(gl, texture) {
|
|
@@ -7854,21 +9704,56 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
7854
9704
|
|
|
7855
9705
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
7856
9706
|
|
|
9707
|
+
/**
|
|
9708
|
+
* @fileoverview WebGL 渐变对象
|
|
9709
|
+
*
|
|
9710
|
+
* 本模块提供了 WebGL 渐变功能,支持 GLSL 着色器直接计算渐变色,
|
|
9711
|
+
* 无需 textureCanvas,性能更优。
|
|
9712
|
+
*
|
|
9713
|
+
* 支持的渐变类型:
|
|
9714
|
+
* - 线性渐变 (linear)
|
|
9715
|
+
* - 径向渐变 (radial)
|
|
9716
|
+
*
|
|
9717
|
+
* @module lib/webgl/gradient
|
|
9718
|
+
* @author jmGraph Team
|
|
9719
|
+
*/
|
|
9720
|
+
|
|
9721
|
+
/** @constant {number} 最大颜色断点数量 */
|
|
7857
9722
|
var MAX_STOPS = 16;
|
|
7858
9723
|
/**
|
|
7859
|
-
* WebGL
|
|
7860
|
-
* 支持 GLSL
|
|
9724
|
+
* WebGL 渐变类
|
|
9725
|
+
* 支持 GLSL 着色器直接计算渐变色
|
|
9726
|
+
*
|
|
9727
|
+
* @class WebglGradient
|
|
9728
|
+
* @example
|
|
9729
|
+
* const gradient = new WebglGradient('linear', { x1: 0, y1: 0, x2: 100, y2: 0 });
|
|
9730
|
+
* gradient.addColorStop(0, '#ff0000');
|
|
9731
|
+
* gradient.addColorStop(1, '#0000ff');
|
|
7861
9732
|
*/
|
|
7862
9733
|
|
|
7863
9734
|
exports.MAX_STOPS = MAX_STOPS;
|
|
7864
9735
|
|
|
7865
9736
|
var WebglGradient = /*#__PURE__*/function () {
|
|
9737
|
+
/**
|
|
9738
|
+
* 构造函数
|
|
9739
|
+
* @param {string} [type='linear'] 渐变类型:'linear' 或 'radial'
|
|
9740
|
+
* @param {Object} params 渐变参数
|
|
9741
|
+
* @param {number} [params.x1=0] 起点/内圆中心X坐标
|
|
9742
|
+
* @param {number} [params.y1=0] 起点/内圆中心Y坐标
|
|
9743
|
+
* @param {number} [params.r1=0] 内圆半径(径向渐变)
|
|
9744
|
+
* @param {number} [params.x2=0] 终点/外圆中心X坐标
|
|
9745
|
+
* @param {number} [params.y2=0] 终点/外圆中心Y坐标
|
|
9746
|
+
* @param {number} [params.r2=0] 外圆半径(径向渐变)
|
|
9747
|
+
* @param {Object} [params.bounds] 渐变边界
|
|
9748
|
+
* @param {Object} [params.control] 控制器对象
|
|
9749
|
+
*/
|
|
7866
9750
|
function WebglGradient() {
|
|
7867
9751
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'linear';
|
|
7868
9752
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7869
9753
|
|
|
7870
9754
|
_classCallCheck(this, WebglGradient);
|
|
7871
9755
|
|
|
9756
|
+
/** @type {string} 渐变类型 */
|
|
7872
9757
|
this.type = type || 'linear';
|
|
7873
9758
|
this.x1 = params.x1 || 0;
|
|
7874
9759
|
this.y1 = params.y1 || 0;
|
|
@@ -7876,6 +9761,8 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7876
9761
|
this.x2 = params.x2 || 0;
|
|
7877
9762
|
this.y2 = params.y2 || 0;
|
|
7878
9763
|
this.r2 = params.r2 || 0;
|
|
9764
|
+
/** @type {Object} 渐变边界 */
|
|
9765
|
+
|
|
7879
9766
|
this.bounds = params.bounds || {
|
|
7880
9767
|
left: 0,
|
|
7881
9768
|
top: 0,
|
|
@@ -7883,12 +9770,16 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7883
9770
|
height: 0
|
|
7884
9771
|
};
|
|
7885
9772
|
this.control = params.control;
|
|
9773
|
+
/** @type {Array<{offset: number, color: string}>} 颜色断点数组 */
|
|
9774
|
+
|
|
7886
9775
|
this.stops = [];
|
|
7887
9776
|
this._sortedStops = null;
|
|
7888
9777
|
this._paramsHash = null;
|
|
7889
9778
|
}
|
|
7890
9779
|
/**
|
|
7891
9780
|
* 添加颜色断点
|
|
9781
|
+
* @param {number} offset 断点位置 (0-1)
|
|
9782
|
+
* @param {string} color 颜色值
|
|
7892
9783
|
*/
|
|
7893
9784
|
|
|
7894
9785
|
|
|
@@ -7903,7 +9794,9 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7903
9794
|
this._paramsHash = null;
|
|
7904
9795
|
}
|
|
7905
9796
|
/**
|
|
7906
|
-
*
|
|
9797
|
+
* 获取排序后的断点数组(带解析后的颜色)
|
|
9798
|
+
* @private
|
|
9799
|
+
* @returns {Array<{offset: number, r: number, g: number, b: number, a: number}>}
|
|
7907
9800
|
*/
|
|
7908
9801
|
|
|
7909
9802
|
}, {
|
|
@@ -7919,8 +9812,6 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7919
9812
|
}
|
|
7920
9813
|
|
|
7921
9814
|
if (_typeof(c) === 'object' && c !== null) {
|
|
7922
|
-
// hexToRGBA 返回 r/g/b 为 0~255,a 为 0~1
|
|
7923
|
-
// 但如果已经是 0~1 范围(由 rgbToDecimal 处理过),需要检测
|
|
7924
9815
|
var needNormalize = c.r > 1 || c.g > 1 || c.b > 1 ? 255 : 1;
|
|
7925
9816
|
return {
|
|
7926
9817
|
offset: s.offset,
|
|
@@ -7944,8 +9835,8 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7944
9835
|
return this._sortedStops;
|
|
7945
9836
|
}
|
|
7946
9837
|
/**
|
|
7947
|
-
*
|
|
7948
|
-
*
|
|
9838
|
+
* 将渐变参数转换为 uniform 格式,传递给着色器
|
|
9839
|
+
* @returns {Object} uniform 参数对象
|
|
7949
9840
|
*/
|
|
7950
9841
|
|
|
7951
9842
|
}, {
|
|
@@ -7953,8 +9844,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7953
9844
|
value: function toUniformParams() {
|
|
7954
9845
|
var stops = this._getSortedStops();
|
|
7955
9846
|
|
|
7956
|
-
var count = Math.min(stops.length, MAX_STOPS);
|
|
7957
|
-
|
|
9847
|
+
var count = Math.min(stops.length, MAX_STOPS);
|
|
7958
9848
|
var flatStops = new Float32Array(count * 5);
|
|
7959
9849
|
|
|
7960
9850
|
for (var i = 0; i < count; i++) {
|
|
@@ -7974,9 +9864,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7974
9864
|
stops: flatStops
|
|
7975
9865
|
};
|
|
7976
9866
|
}
|
|
7977
|
-
/**
|
|
7978
|
-
* 使缓存失效
|
|
7979
|
-
*/
|
|
9867
|
+
/** 使缓存失效 */
|
|
7980
9868
|
|
|
7981
9869
|
}, {
|
|
7982
9870
|
key: "invalidateCache",
|
|
@@ -7986,6 +9874,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7986
9874
|
}
|
|
7987
9875
|
/**
|
|
7988
9876
|
* 转换为渐变的字符串表达
|
|
9877
|
+
* @returns {string} 渐变字符串
|
|
7989
9878
|
*/
|
|
7990
9879
|
|
|
7991
9880
|
}, {
|
|
@@ -8078,29 +9967,58 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
8078
9967
|
|
|
8079
9968
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
8080
9969
|
|
|
8081
|
-
|
|
9970
|
+
/**
|
|
9971
|
+
* WebGL 路径绘制类
|
|
9972
|
+
* 继承自 WeblBase,提供路径绘制功能
|
|
9973
|
+
*
|
|
9974
|
+
* @class WebglPath
|
|
9975
|
+
* @extends WeblBase
|
|
9976
|
+
* @example
|
|
9977
|
+
* const path = new WebglPath(graph, { isRegular: false, needCut: true });
|
|
9978
|
+
* path.draw(points);
|
|
9979
|
+
* path.stroke(points, '#ff0000', 2);
|
|
9980
|
+
*/
|
|
8082
9981
|
var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
8083
9982
|
_inherits(WebglPath, _WebglBase);
|
|
8084
9983
|
|
|
8085
9984
|
var _super = _createSuper(WebglPath);
|
|
8086
9985
|
|
|
9986
|
+
/**
|
|
9987
|
+
* 构造函数
|
|
9988
|
+
* @param {jmGraph} graph jmGraph 实例
|
|
9989
|
+
* @param {Object} option 配置选项
|
|
9990
|
+
* @param {boolean} [option.isRegular=false] 是否为规则图形(凸多边形)
|
|
9991
|
+
* @param {boolean} [option.needCut=false] 是否需要切割处理
|
|
9992
|
+
* @param {Object} [option.control] 控制器对象
|
|
9993
|
+
*/
|
|
8087
9994
|
function WebglPath(graph, option) {
|
|
8088
9995
|
var _this;
|
|
8089
9996
|
|
|
8090
9997
|
_classCallCheck(this, WebglPath);
|
|
8091
9998
|
|
|
8092
|
-
_this = _super.call(this, graph, option);
|
|
9999
|
+
_this = _super.call(this, graph, option);
|
|
10000
|
+
/** @type {boolean} 是否为规则图形(凸多边形),规则图形处理更高效 */
|
|
8093
10001
|
|
|
8094
10002
|
_this.isRegular = option.isRegular || false;
|
|
10003
|
+
/** @type {boolean} 是否需要切割处理 */
|
|
10004
|
+
|
|
8095
10005
|
_this.needCut = option.needCut || false;
|
|
8096
10006
|
_this.control = option.control;
|
|
8097
|
-
|
|
10007
|
+
/** @type {Array<Object>} 路径点数组 */
|
|
10008
|
+
|
|
10009
|
+
_this.points = [];
|
|
10010
|
+
/** @type {Array} 缓存的缓冲区,避免每帧创建/销毁 */
|
|
8098
10011
|
|
|
8099
10012
|
_this.__cachedBuffers = [];
|
|
10013
|
+
/** @type {Object} 缓存的纹理 */
|
|
10014
|
+
|
|
8100
10015
|
_this.__cachedTexture = null;
|
|
10016
|
+
/** @type {string} 缓存纹理的 key */
|
|
10017
|
+
|
|
8101
10018
|
_this.__cachedTextureKey = null;
|
|
8102
10019
|
return _this;
|
|
8103
|
-
}
|
|
10020
|
+
}
|
|
10021
|
+
/** 释放缓存的 WebGL 资源 */
|
|
8104
10022
|
|
|
8105
10023
|
|
|
8106
10024
|
_createClass(WebglPath, [{
|
|
@@ -8127,7 +10045,13 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8127
10045
|
this.__cachedTexture = null;
|
|
8128
10046
|
this.__cachedTextureKey = null;
|
|
8129
10047
|
}
|
|
8130
|
-
}
|
|
10048
|
+
}
|
|
10049
|
+
/**
|
|
10050
|
+
* 获取或创建缓冲区,优先复用缓存
|
|
10051
|
+
* @param {Array} data 数据数组
|
|
10052
|
+
* @param {Object} attr 属性对象
|
|
10053
|
+
* @returns {Object} 缓冲区对象
|
|
10054
|
+
*/
|
|
8131
10055
|
|
|
8132
10056
|
}, {
|
|
8133
10057
|
key: "getOrCreateBuffer",
|
|
@@ -8151,13 +10075,23 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8151
10075
|
this.__cachedBuffers.push(buffer);
|
|
8152
10076
|
|
|
8153
10077
|
return buffer;
|
|
8154
|
-
}
|
|
10078
|
+
}
|
|
10079
|
+
/**
|
|
10080
|
+
* 应用变换到点
|
|
10081
|
+
* @param {Object} point 点坐标 {x, y}
|
|
10082
|
+
* @returns {Object} 变换后的点坐标
|
|
10083
|
+
*/
|
|
8155
10084
|
|
|
8156
10085
|
}, {
|
|
8157
10086
|
key: "applyTransform",
|
|
8158
10087
|
value: function applyTransform(point) {
|
|
8159
10088
|
return _get(_getPrototypeOf(WebglPath.prototype), "applyTransform", this).call(this, point);
|
|
8160
10089
|
}
|
|
10090
|
+
/**
|
|
10091
|
+
* 设置父级边界
|
|
10092
|
+
* @param {Object} [parentBounds] 父级边界 {left, top, width, height}
|
|
10093
|
+
*/
|
|
10094
|
+
|
|
8161
10095
|
}, {
|
|
8162
10096
|
key: "setParentBounds",
|
|
8163
10097
|
value: function setParentBounds() {
|
|
@@ -8225,17 +10159,18 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8225
10159
|
key: "endDraw",
|
|
8226
10160
|
value: function endDraw() {
|
|
8227
10161
|
if (this.points) delete this.points;
|
|
8228
|
-
if (this.pathPoints) delete this.pathPoints;
|
|
8229
|
-
|
|
10162
|
+
if (this.pathPoints) delete this.pathPoints;
|
|
10163
|
+
this.needClose = false; // 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
10164
|
+
}
|
|
10165
|
+
/**
|
|
10166
|
+
* 标记路径需要闭合(不修改原始 points 数组)
|
|
10167
|
+
* 闭合逻辑由 stroke/fill 绘制方法自行处理
|
|
10168
|
+
*/
|
|
8230
10169
|
|
|
8231
10170
|
}, {
|
|
8232
10171
|
key: "closePath",
|
|
8233
10172
|
value: function closePath() {
|
|
8234
|
-
|
|
8235
|
-
var start = this.points[0];
|
|
8236
|
-
var end = this.points[this.points.length - 1];
|
|
8237
|
-
if (start != end && !(start.x === end.x && start.y === end.y)) this.points.push(start);
|
|
8238
|
-
}
|
|
10173
|
+
this.needClose = true;
|
|
8239
10174
|
} // 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
8240
10175
|
|
|
8241
10176
|
}, {
|
|
@@ -9333,11 +11268,40 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9333
11268
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9334
11269
|
|
|
9335
11270
|
/**
|
|
9336
|
-
*
|
|
11271
|
+
* 圆弧类
|
|
11272
|
+
*
|
|
11273
|
+
* 绘制圆弧或扇形图形,继承自 jmPath。
|
|
11274
|
+
* 支持设置圆心、半径、起始角度和结束角度。
|
|
9337
11275
|
*
|
|
9338
11276
|
* @class jmArc
|
|
9339
11277
|
* @extends jmPath
|
|
9340
|
-
* @param {object} params
|
|
11278
|
+
* @param {object} params 圆弧参数
|
|
11279
|
+
* @param {object} [params.center] 圆弧中心点 {x, y}
|
|
11280
|
+
* @param {number} [params.radius] 圆弧半径
|
|
11281
|
+
* @param {number} [params.start=0] 圆弧起始角度(弧度)
|
|
11282
|
+
* @param {number} [params.end=Math.PI*2] 圆弧结束角度(弧度)
|
|
11283
|
+
* @param {boolean} [params.anticlockwise=false] 绘制方向:false=顺时针,true=逆时针
|
|
11284
|
+
* @param {boolean} [params.isFan=false] 是否绘制为扇形
|
|
11285
|
+
*
|
|
11286
|
+
* @example
|
|
11287
|
+
* // 创建圆弧
|
|
11288
|
+
* const arc = graph.createShape('arc', {
|
|
11289
|
+
* center: {x: 200, y: 200},
|
|
11290
|
+
* radius: 50,
|
|
11291
|
+
* start: 0,
|
|
11292
|
+
* end: Math.PI,
|
|
11293
|
+
* style: { stroke: '#000' }
|
|
11294
|
+
* });
|
|
11295
|
+
*
|
|
11296
|
+
* // 创建扇形
|
|
11297
|
+
* const fan = graph.createShape('arc', {
|
|
11298
|
+
* center: {x: 200, y: 200},
|
|
11299
|
+
* radius: 50,
|
|
11300
|
+
* start: 0,
|
|
11301
|
+
* end: Math.PI / 2,
|
|
11302
|
+
* isFan: true,
|
|
11303
|
+
* style: { fill: '#ff0000' }
|
|
11304
|
+
* });
|
|
9341
11305
|
*/
|
|
9342
11306
|
var jmArc = /*#__PURE__*/function (_jmPath) {
|
|
9343
11307
|
_inherits(jmArc, _jmPath);
|
|
@@ -9560,11 +11524,27 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9560
11524
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9561
11525
|
|
|
9562
11526
|
/**
|
|
9563
|
-
*
|
|
11527
|
+
* 箭头类
|
|
11528
|
+
*
|
|
11529
|
+
* 绘制箭头图形,支持空心和实心两种样式。
|
|
11530
|
+
* 箭头方向由起点和终点决定。
|
|
9564
11531
|
*
|
|
9565
11532
|
* @class jmArrow
|
|
9566
11533
|
* @extends jmPath
|
|
9567
|
-
* @param {object}
|
|
11534
|
+
* @param {object} params 箭头参数
|
|
11535
|
+
* @param {object} [params.start] 箭头起始点 {x, y}
|
|
11536
|
+
* @param {object} [params.end] 箭头终点(箭头尖端){x, y}
|
|
11537
|
+
* @param {number} [params.angle] 箭头角度(弧度),不指定则自动计算
|
|
11538
|
+
* @param {number} [params.offsetX=5] 箭头X方向偏移量
|
|
11539
|
+
* @param {number} [params.offsetY=8] 箭头Y方向偏移量
|
|
11540
|
+
*
|
|
11541
|
+
* @example
|
|
11542
|
+
* // 创建箭头
|
|
11543
|
+
* const arrow = graph.createShape('arrow', {
|
|
11544
|
+
* start: {x: 100, y: 100},
|
|
11545
|
+
* end: {x: 200, y: 100},
|
|
11546
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
11547
|
+
* });
|
|
9568
11548
|
*/
|
|
9569
11549
|
var jmArrow = /*#__PURE__*/function (_jmPath) {
|
|
9570
11550
|
_inherits(jmArrow, _jmPath);
|
|
@@ -9788,11 +11768,25 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9788
11768
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9789
11769
|
|
|
9790
11770
|
/**
|
|
9791
|
-
*
|
|
11771
|
+
* 带箭头的直线类
|
|
11772
|
+
*
|
|
11773
|
+
* 绘制带箭头的直线,继承自 jmLine。
|
|
11774
|
+
* 箭头位于直线的末端。
|
|
9792
11775
|
*
|
|
9793
11776
|
* @class jmArrowLine
|
|
9794
11777
|
* @extends jmLine
|
|
9795
|
-
* @param {object} params
|
|
11778
|
+
* @param {object} params 直线参数
|
|
11779
|
+
* @param {object} [params.start] 直线起始点 {x, y}
|
|
11780
|
+
* @param {object} [params.end] 直线终结点 {x, y}
|
|
11781
|
+
* @param {boolean} [params.arrowVisible=true] 是否显示箭头
|
|
11782
|
+
*
|
|
11783
|
+
* @example
|
|
11784
|
+
* // 创建带箭头的直线
|
|
11785
|
+
* const arrowLine = graph.createShape('arrowLine', {
|
|
11786
|
+
* start: {x: 100, y: 100},
|
|
11787
|
+
* end: {x: 200, y: 100},
|
|
11788
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
11789
|
+
* });
|
|
9796
11790
|
*/
|
|
9797
11791
|
var jmArrowLine = /*#__PURE__*/function (_jmLine) {
|
|
9798
11792
|
_inherits(jmArrowLine, _jmLine);
|
|
@@ -9876,12 +11870,37 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9876
11870
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9877
11871
|
|
|
9878
11872
|
/**
|
|
9879
|
-
*
|
|
9880
|
-
*
|
|
11873
|
+
* 贝塞尔曲线类
|
|
11874
|
+
*
|
|
11875
|
+
* 绘制 N 阶贝塞尔曲线,参数 points 中为控制点。
|
|
11876
|
+
* 支持 2 阶(二次贝塞尔)、3 阶(三次贝塞尔)及更高阶曲线。
|
|
9881
11877
|
*
|
|
9882
11878
|
* @class jmBezier
|
|
9883
11879
|
* @extends jmPath
|
|
9884
11880
|
* @param {object} params 参数
|
|
11881
|
+
* @param {array} [params.points] 控制点数组 [{x, y}, ...]
|
|
11882
|
+
*
|
|
11883
|
+
* @example
|
|
11884
|
+
* // 创建二次贝塞尔曲线(3个控制点)
|
|
11885
|
+
* const quadBezier = graph.createShape('bezier', {
|
|
11886
|
+
* points: [
|
|
11887
|
+
* {x: 100, y: 100}, // 起点
|
|
11888
|
+
* {x: 200, y: 50}, // 控制点
|
|
11889
|
+
* {x: 300, y: 100} // 终点
|
|
11890
|
+
* ],
|
|
11891
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
11892
|
+
* });
|
|
11893
|
+
*
|
|
11894
|
+
* // 创建三次贝塞尔曲线(4个控制点)
|
|
11895
|
+
* const cubicBezier = graph.createShape('bezier', {
|
|
11896
|
+
* points: [
|
|
11897
|
+
* {x: 100, y: 100}, // 起点
|
|
11898
|
+
* {x: 150, y: 50}, // 控制点1
|
|
11899
|
+
* {x: 250, y: 50}, // 控制点2
|
|
11900
|
+
* {x: 300, y: 100} // 终点
|
|
11901
|
+
* ],
|
|
11902
|
+
* style: { stroke: '#ff0000' }
|
|
11903
|
+
* });
|
|
9885
11904
|
*/
|
|
9886
11905
|
var jmBezier = /*#__PURE__*/function (_jmPath) {
|
|
9887
11906
|
_inherits(jmBezier, _jmPath);
|
|
@@ -9895,8 +11914,12 @@ var jmBezier = /*#__PURE__*/function (_jmPath) {
|
|
|
9895
11914
|
|
|
9896
11915
|
_classCallCheck(this, jmBezier);
|
|
9897
11916
|
|
|
9898
|
-
//
|
|
9899
|
-
|
|
11917
|
+
// 参数初始化
|
|
11918
|
+
params = params || {}; // 曲线默认不封闭
|
|
11919
|
+
|
|
11920
|
+
if (!params.style) params.style = {};
|
|
11921
|
+
|
|
11922
|
+
if (typeof params.style.close !== true) {
|
|
9900
11923
|
params.style.close = false;
|
|
9901
11924
|
}
|
|
9902
11925
|
|
|
@@ -10052,11 +12075,27 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10052
12075
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10053
12076
|
|
|
10054
12077
|
/**
|
|
10055
|
-
*
|
|
12078
|
+
* 圆形类
|
|
12079
|
+
*
|
|
12080
|
+
* 绘制圆形图形,继承自 jmArc。
|
|
12081
|
+
* 可以通过 center 和 radius 指定圆心和半径,
|
|
12082
|
+
* 也可以通过 width 和 height 指定圆的尺寸。
|
|
10056
12083
|
*
|
|
10057
12084
|
* @class jmCircle
|
|
10058
12085
|
* @extends jmArc
|
|
10059
|
-
* @param {object} params
|
|
12086
|
+
* @param {object} params 圆的参数
|
|
12087
|
+
* @param {object} [params.center] 圆心坐标 {x, y}
|
|
12088
|
+
* @param {number} [params.radius] 圆半径(优先使用)
|
|
12089
|
+
* @param {number} [params.width] 圆宽度(无 radius 时使用)
|
|
12090
|
+
* @param {number} [params.height] 圆高度(无 radius 时使用)
|
|
12091
|
+
*
|
|
12092
|
+
* @example
|
|
12093
|
+
* // 创建圆形
|
|
12094
|
+
* const circle = graph.createShape('circle', {
|
|
12095
|
+
* center: {x: 200, y: 200},
|
|
12096
|
+
* radius: 50,
|
|
12097
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
12098
|
+
* });
|
|
10060
12099
|
*/
|
|
10061
12100
|
var jmCircle = /*#__PURE__*/function (_jmArc) {
|
|
10062
12101
|
_inherits(jmCircle, _jmArc);
|
|
@@ -10182,9 +12221,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10182
12221
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10183
12222
|
|
|
10184
12223
|
/**
|
|
10185
|
-
*
|
|
10186
|
-
*
|
|
10187
|
-
*
|
|
12224
|
+
* 椭圆类
|
|
12225
|
+
*
|
|
12226
|
+
* 绘制椭圆图形,继承自 jmArc。
|
|
12227
|
+
* 可以指定起始角度和结束角度来绘制椭圆弧。
|
|
10188
12228
|
*
|
|
10189
12229
|
* @class jmEllipse
|
|
10190
12230
|
* @extends jmArc
|
|
@@ -10195,6 +12235,15 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
10195
12235
|
* @param {number} [params.startAngle=0] 起始角度(弧度)
|
|
10196
12236
|
* @param {number} [params.endAngle=Math.PI*2] 结束角度(弧度)
|
|
10197
12237
|
* @param {boolean} [params.anticlockwise=false] 是否逆时针绘制
|
|
12238
|
+
*
|
|
12239
|
+
* @example
|
|
12240
|
+
* // 创建椭圆
|
|
12241
|
+
* const ellipse = graph.createShape('ellipse', {
|
|
12242
|
+
* center: {x: 200, y: 200},
|
|
12243
|
+
* width: 200,
|
|
12244
|
+
* height: 100,
|
|
12245
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
12246
|
+
* });
|
|
10198
12247
|
*/
|
|
10199
12248
|
var jmEllipse = /*#__PURE__*/function (_jmArc) {
|
|
10200
12249
|
_inherits(jmEllipse, _jmArc);
|
|
@@ -10328,11 +12377,31 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10328
12377
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10329
12378
|
|
|
10330
12379
|
/**
|
|
10331
|
-
*
|
|
12380
|
+
* 空心圆弧类
|
|
12381
|
+
*
|
|
12382
|
+
* 绘制空心圆弧(圆环弧),继承自 jmArc。
|
|
12383
|
+
* 由内圆半径和外圆半径定义环形区域。
|
|
10332
12384
|
*
|
|
10333
12385
|
* @class jmHArc
|
|
10334
12386
|
* @extends jmArc
|
|
10335
|
-
* @param {object} params
|
|
12387
|
+
* @param {object} params 空心圆弧参数
|
|
12388
|
+
* @param {object} [params.center] 圆弧中心点 {x, y}
|
|
12389
|
+
* @param {number} [params.minRadius] 内圆半径
|
|
12390
|
+
* @param {number} [params.maxRadius] 外圆半径
|
|
12391
|
+
* @param {number} [params.start=0] 起始角度(弧度)
|
|
12392
|
+
* @param {number} [params.end=Math.PI*2] 结束角度(弧度)
|
|
12393
|
+
* @param {boolean} [params.anticlockwise=false] 是否逆时针绘制
|
|
12394
|
+
*
|
|
12395
|
+
* @example
|
|
12396
|
+
* // 创建空心圆弧
|
|
12397
|
+
* const hArc = graph.createShape('hArc', {
|
|
12398
|
+
* center: {x: 200, y: 200},
|
|
12399
|
+
* minRadius: 30,
|
|
12400
|
+
* maxRadius: 50,
|
|
12401
|
+
* start: 0,
|
|
12402
|
+
* end: Math.PI,
|
|
12403
|
+
* style: { fill: '#ff0000' }
|
|
12404
|
+
* });
|
|
10336
12405
|
*/
|
|
10337
12406
|
var jmHArc = /*#__PURE__*/function (_jmArc) {
|
|
10338
12407
|
_inherits(jmHArc, _jmArc);
|
|
@@ -10492,13 +12561,41 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10492
12561
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10493
12562
|
|
|
10494
12563
|
/**
|
|
10495
|
-
*
|
|
10496
|
-
* params参数中image为指定的图片源地址或图片img对象,
|
|
10497
|
-
* postion=当前控件的位置,width=其宽度,height=高度,sourcePosition=从当前图片中展示的位置,sourceWidth=从图片中截取的宽度,sourceHeight=从图片中截取的高度。
|
|
12564
|
+
* 图片类
|
|
10498
12565
|
*
|
|
12566
|
+
* 显示图片控件,支持从 URL 或 Image 对象加载图片。
|
|
12567
|
+
* 支持图片裁剪和缩放功能。
|
|
12568
|
+
*
|
|
10499
12569
|
* @class jmImage
|
|
10500
12570
|
* @extends jmControl
|
|
10501
12571
|
* @param {object} params 控件参数
|
|
12572
|
+
* @param {string|HTMLImageElement} [params.image] 图片源地址或图片对象
|
|
12573
|
+
* @param {object} [params.position] 图片位置 {x, y}
|
|
12574
|
+
* @param {number} [params.width] 图片显示宽度
|
|
12575
|
+
* @param {number} [params.height] 图片显示高度
|
|
12576
|
+
* @param {object} [params.sourcePosition] 图片裁剪起始位置 {x, y}
|
|
12577
|
+
* @param {number} [params.sourceWidth] 图片裁剪宽度
|
|
12578
|
+
* @param {number} [params.sourceHeight] 图片裁剪高度
|
|
12579
|
+
*
|
|
12580
|
+
* @example
|
|
12581
|
+
* // 从 URL 加载图片
|
|
12582
|
+
* const img = graph.createShape('image', {
|
|
12583
|
+
* image: 'path/to/image.png',
|
|
12584
|
+
* position: {x: 100, y: 100},
|
|
12585
|
+
* width: 200,
|
|
12586
|
+
* height: 150
|
|
12587
|
+
* });
|
|
12588
|
+
*
|
|
12589
|
+
* // 裁剪图片
|
|
12590
|
+
* const croppedImg = graph.createShape('image', {
|
|
12591
|
+
* image: 'path/to/sprite.png',
|
|
12592
|
+
* position: {x: 100, y: 100},
|
|
12593
|
+
* sourcePosition: {x: 0, y: 0},
|
|
12594
|
+
* sourceWidth: 50,
|
|
12595
|
+
* sourceHeight: 50,
|
|
12596
|
+
* width: 100,
|
|
12597
|
+
* height: 100
|
|
12598
|
+
* });
|
|
10502
12599
|
*/
|
|
10503
12600
|
var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
10504
12601
|
_inherits(jmImage, _jmControl);
|
|
@@ -10800,11 +12897,32 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10800
12897
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10801
12898
|
|
|
10802
12899
|
/**
|
|
10803
|
-
*
|
|
12900
|
+
* 文本标签类
|
|
12901
|
+
*
|
|
12902
|
+
* 显示文字控件,支持多种文本样式和对齐方式。
|
|
10804
12903
|
*
|
|
10805
12904
|
* @class jmLabel
|
|
10806
12905
|
* @extends jmControl
|
|
10807
|
-
* @param {object} params
|
|
12906
|
+
* @param {object} params 参数
|
|
12907
|
+
* @param {string} [params.text=''] 显示的文字内容
|
|
12908
|
+
* @param {object} [params.center] 文本中心点坐标
|
|
12909
|
+
* @param {object} [params.style] 样式对象
|
|
12910
|
+
* @param {string} [params.style.font] 字体样式
|
|
12911
|
+
* @param {string} [params.style.textAlign='left'] 水平对齐方式
|
|
12912
|
+
* @param {string} [params.style.textBaseline='middle'] 垂直对齐方式
|
|
12913
|
+
* @param {number} [params.style.maxWidth] 最大宽度(用于自动换行)
|
|
12914
|
+
*
|
|
12915
|
+
* @example
|
|
12916
|
+
* // 创建文本标签
|
|
12917
|
+
* const label = graph.createShape('label', {
|
|
12918
|
+
* position: {x: 100, y: 100},
|
|
12919
|
+
* text: 'Hello World',
|
|
12920
|
+
* style: {
|
|
12921
|
+
* fill: '#000',
|
|
12922
|
+
* font: '20px Arial',
|
|
12923
|
+
* textAlign: 'center'
|
|
12924
|
+
* }
|
|
12925
|
+
* });
|
|
10808
12926
|
*/
|
|
10809
12927
|
var jmLabel = /*#__PURE__*/function (_jmControl) {
|
|
10810
12928
|
_inherits(jmLabel, _jmControl);
|
|
@@ -11210,11 +13328,34 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11210
13328
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11211
13329
|
|
|
11212
13330
|
/**
|
|
11213
|
-
*
|
|
13331
|
+
* 直线类
|
|
13332
|
+
*
|
|
13333
|
+
* 绘制从起点到终点的直线,支持实线和虚线两种模式。
|
|
11214
13334
|
*
|
|
11215
13335
|
* @class jmLine
|
|
11216
13336
|
* @extends jmPath
|
|
11217
|
-
* @param {object} params
|
|
13337
|
+
* @param {object} params 直线参数
|
|
13338
|
+
* @param {object} [params.start] 起始点 {x, y}
|
|
13339
|
+
* @param {object} [params.end] 结束点 {x, y}
|
|
13340
|
+
* @param {string} [params.lineType='solid'] 线类型:'solid'=实线,'dotted'=虚线
|
|
13341
|
+
* @param {number} [params.dashLength=4] 虚线间隔长度
|
|
13342
|
+
*
|
|
13343
|
+
* @example
|
|
13344
|
+
* // 创建实线
|
|
13345
|
+
* const line = graph.createShape('line', {
|
|
13346
|
+
* start: {x: 0, y: 0},
|
|
13347
|
+
* end: {x: 100, y: 100},
|
|
13348
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
13349
|
+
* });
|
|
13350
|
+
*
|
|
13351
|
+
* // 创建虚线
|
|
13352
|
+
* const dottedLine = graph.createShape('line', {
|
|
13353
|
+
* start: {x: 0, y: 0},
|
|
13354
|
+
* end: {x: 100, y: 100},
|
|
13355
|
+
* lineType: 'dotted',
|
|
13356
|
+
* dashLength: 5,
|
|
13357
|
+
* style: { stroke: '#000' }
|
|
13358
|
+
* });
|
|
11218
13359
|
*/
|
|
11219
13360
|
var jmLine = /*#__PURE__*/function (_jmPath) {
|
|
11220
13361
|
_inherits(jmLine, _jmPath);
|
|
@@ -11365,9 +13506,11 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11365
13506
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11366
13507
|
|
|
11367
13508
|
/**
|
|
11368
|
-
*
|
|
11369
|
-
*
|
|
11370
|
-
*
|
|
13509
|
+
* 多边形类
|
|
13510
|
+
*
|
|
13511
|
+
* 绘制多边形图形,支持规则多边形和自定义多边形。
|
|
13512
|
+
* 规则多边形通过边数和半径自动计算顶点,
|
|
13513
|
+
* 自定义多边形通过顶点数组定义。
|
|
11371
13514
|
*
|
|
11372
13515
|
* @class jmPolygon
|
|
11373
13516
|
* @extends jmPath
|
|
@@ -11376,6 +13519,27 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
11376
13519
|
* @param {number} [params.sides=3] 多边形边数(3-100)
|
|
11377
13520
|
* @param {number} [params.radius=50] 多边形半径(像素)
|
|
11378
13521
|
* @param {object} [params.center={x:0,y:0}] 多边形中心点坐标
|
|
13522
|
+
*
|
|
13523
|
+
* @example
|
|
13524
|
+
* // 创建正六边形
|
|
13525
|
+
* const hexagon = graph.createShape('polygon', {
|
|
13526
|
+
* center: {x: 200, y: 200},
|
|
13527
|
+
* sides: 6,
|
|
13528
|
+
* radius: 50,
|
|
13529
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13530
|
+
* });
|
|
13531
|
+
*
|
|
13532
|
+
* // 创建自定义多边形
|
|
13533
|
+
* const polygon = graph.createShape('polygon', {
|
|
13534
|
+
* points: [
|
|
13535
|
+
* {x: 100, y: 100},
|
|
13536
|
+
* {x: 200, y: 50},
|
|
13537
|
+
* {x: 300, y: 100},
|
|
13538
|
+
* {x: 250, y: 200},
|
|
13539
|
+
* {x: 150, y: 200}
|
|
13540
|
+
* ],
|
|
13541
|
+
* style: { fill: '#00ff00' }
|
|
13542
|
+
* });
|
|
11379
13543
|
*/
|
|
11380
13544
|
var jmPolygon = /*#__PURE__*/function (_jmPath) {
|
|
11381
13545
|
_inherits(jmPolygon, _jmPath);
|
|
@@ -11561,11 +13725,26 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11561
13725
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11562
13726
|
|
|
11563
13727
|
/**
|
|
11564
|
-
*
|
|
13728
|
+
* 棱形类
|
|
13729
|
+
*
|
|
13730
|
+
* 绘制棱形(菱形)图形,继承自 jmPath。
|
|
13731
|
+
* 棱形由中心点、宽度和高度定义。
|
|
11565
13732
|
*
|
|
11566
13733
|
* @class jmPrismatic
|
|
11567
13734
|
* @extends jmPath
|
|
11568
|
-
* @param {object} params 参数
|
|
13735
|
+
* @param {object} params 参数
|
|
13736
|
+
* @param {object} [params.center] 棱形中心点 {x, y}
|
|
13737
|
+
* @param {number} [params.width] 棱形宽度
|
|
13738
|
+
* @param {number} [params.height] 棱形高度
|
|
13739
|
+
*
|
|
13740
|
+
* @example
|
|
13741
|
+
* // 创建棱形
|
|
13742
|
+
* const prismatic = graph.createShape('prismatic', {
|
|
13743
|
+
* center: {x: 200, y: 200},
|
|
13744
|
+
* width: 100,
|
|
13745
|
+
* height: 80,
|
|
13746
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13747
|
+
* });
|
|
11569
13748
|
*/
|
|
11570
13749
|
var jmPrismatic = /*#__PURE__*/function (_jmPath) {
|
|
11571
13750
|
_inherits(jmPrismatic, _jmPath);
|
|
@@ -11685,12 +13864,37 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11685
13864
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11686
13865
|
|
|
11687
13866
|
/**
|
|
11688
|
-
*
|
|
13867
|
+
* 矩形类
|
|
13868
|
+
*
|
|
13869
|
+
* 绘制矩形图形,支持圆角和虚线边框。
|
|
13870
|
+
* 圆角可以统一设置或四角独立设置。
|
|
11689
13871
|
*
|
|
11690
13872
|
* @class jmRect
|
|
11691
13873
|
* @extends jmPath
|
|
11692
|
-
* @param {object} params 参数
|
|
11693
|
-
*
|
|
13874
|
+
* @param {object} params 参数
|
|
13875
|
+
* @param {object} [params.position] 矩形左上角顶点坐标 {x, y}
|
|
13876
|
+
* @param {number} [params.width] 矩形宽度
|
|
13877
|
+
* @param {number} [params.height] 矩形高度
|
|
13878
|
+
* @param {number|object} [params.radius] 边角弧度,支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
13879
|
+
*
|
|
13880
|
+
* @example
|
|
13881
|
+
* // 创建普通矩形
|
|
13882
|
+
* const rect = graph.createShape('rect', {
|
|
13883
|
+
* position: {x: 100, y: 100},
|
|
13884
|
+
* width: 200,
|
|
13885
|
+
* height: 150,
|
|
13886
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13887
|
+
* });
|
|
13888
|
+
*
|
|
13889
|
+
* // 创建圆角矩形
|
|
13890
|
+
* const roundedRect = graph.createShape('rect', {
|
|
13891
|
+
* position: {x: 100, y: 100},
|
|
13892
|
+
* width: 200,
|
|
13893
|
+
* height: 150,
|
|
13894
|
+
* radius: 10, // 四角统一圆角
|
|
13895
|
+
* // 或 radius: { topLeft: 5, topRight: 10, bottomRight: 15, bottomLeft: 20 }
|
|
13896
|
+
* style: { fill: '#00ff00' }
|
|
13897
|
+
* });
|
|
11694
13898
|
*/
|
|
11695
13899
|
var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
11696
13900
|
_inherits(jmRect, _jmPath);
|
|
@@ -12046,12 +14250,32 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
12046
14250
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12047
14251
|
|
|
12048
14252
|
/**
|
|
12049
|
-
*
|
|
12050
|
-
*
|
|
12051
|
-
*
|
|
14253
|
+
* 可缩放控件类
|
|
14254
|
+
*
|
|
14255
|
+
* 继承自 jmRect,在矩形四边和四角添加可拖拽的控制点。
|
|
14256
|
+
* 用于实现图形的缩放和调整功能。
|
|
12052
14257
|
*
|
|
12053
14258
|
* @class jmResize
|
|
12054
14259
|
* @extends jmRect
|
|
14260
|
+
* @param {object} params 控件参数
|
|
14261
|
+
* @param {boolean} [params.resizable=true] 是否可缩放
|
|
14262
|
+
* @param {boolean} [params.movable] 是否可移动
|
|
14263
|
+
* @param {number} [params.rectSize=8] 控制点大小
|
|
14264
|
+
*
|
|
14265
|
+
* @example
|
|
14266
|
+
* // 创建可缩放矩形
|
|
14267
|
+
* const resize = graph.createShape('resize', {
|
|
14268
|
+
* position: {x: 100, y: 100},
|
|
14269
|
+
* width: 200,
|
|
14270
|
+
* height: 150,
|
|
14271
|
+
* resizable: true,
|
|
14272
|
+
* movable: true
|
|
14273
|
+
* });
|
|
14274
|
+
*
|
|
14275
|
+
* // 监听缩放事件
|
|
14276
|
+
* resize.on('resize', (px, py, dx, dy) => {
|
|
14277
|
+
* console.log('缩放中', px, py, dx, dy);
|
|
14278
|
+
* });
|
|
12055
14279
|
*/
|
|
12056
14280
|
var jmResize = /*#__PURE__*/function (_jmRect) {
|
|
12057
14281
|
_inherits(jmResize, _jmRect);
|
|
@@ -12390,7 +14614,7 @@ var jmResize = /*#__PURE__*/function (_jmRect) {
|
|
|
12390
14614
|
|
|
12391
14615
|
case 6:
|
|
12392
14616
|
{
|
|
12393
|
-
r.position.x = (newLocation.width - r.
|
|
14617
|
+
r.position.x = (newLocation.width - r.width) / 2;
|
|
12394
14618
|
r.position.y = newLocation.height - r.height / 2;
|
|
12395
14619
|
break;
|
|
12396
14620
|
}
|
|
@@ -12446,18 +14670,36 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
12446
14670
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12447
14671
|
|
|
12448
14672
|
/**
|
|
12449
|
-
*
|
|
12450
|
-
*
|
|
12451
|
-
*
|
|
14673
|
+
* 星形类
|
|
14674
|
+
*
|
|
14675
|
+
* 绘制星形图形,支持自定义顶点数和内外半径。
|
|
14676
|
+
* 星形由交替的外半径和内半径顶点组成。
|
|
12452
14677
|
*
|
|
12453
14678
|
* @class jmStar
|
|
12454
14679
|
* @extends jmPath
|
|
12455
14680
|
* @param {object} params 星形的参数
|
|
12456
|
-
* @param {array} [params.points] 自定义顶点数组,如果提供则忽略其他参数
|
|
12457
14681
|
* @param {number} [params.points=5] 星形顶点数(角数,3-50)
|
|
12458
14682
|
* @param {number} [params.radius=50] 星形外半径(从中心到尖角的距离)
|
|
12459
14683
|
* @param {number} [params.innerRadius=25] 星形内半径(从中心到凹陷处的距离)
|
|
12460
14684
|
* @param {object} [params.center={x:0,y:0}] 星形中心点坐标
|
|
14685
|
+
*
|
|
14686
|
+
* @example
|
|
14687
|
+
* // 创建五角星
|
|
14688
|
+
* const star = graph.createShape('star', {
|
|
14689
|
+
* center: {x: 200, y: 200},
|
|
14690
|
+
* points: 5,
|
|
14691
|
+
* radius: 50,
|
|
14692
|
+
* innerRadius: 25,
|
|
14693
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
14694
|
+
* });
|
|
14695
|
+
*
|
|
14696
|
+
* // 创建六角星
|
|
14697
|
+
* const hexStar = graph.createShape('star', {
|
|
14698
|
+
* center: {x: 200, y: 200},
|
|
14699
|
+
* points: 6,
|
|
14700
|
+
* radius: 60,
|
|
14701
|
+
* innerRadius: 30
|
|
14702
|
+
* });
|
|
12461
14703
|
*/
|
|
12462
14704
|
var jmStar = /*#__PURE__*/function (_jmPath) {
|
|
12463
14705
|
_inherits(jmStar, _jmPath);
|