jmgraph 3.2.27 → 3.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +2661 -415
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +827 -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
|
}, {
|
|
@@ -1639,6 +2299,10 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1639
2299
|
var events = this.getEvent(name);
|
|
1640
2300
|
|
|
1641
2301
|
if (events) {
|
|
2302
|
+
if (name === 'mousemove' && this.type == 'jmResize') {
|
|
2303
|
+
console.log('resize mousemove', args, events);
|
|
2304
|
+
}
|
|
2305
|
+
|
|
1642
2306
|
var self = this;
|
|
1643
2307
|
if (!Array.isArray(args)) args = [args];
|
|
1644
2308
|
events.each(function (i, handle) {
|
|
@@ -1652,12 +2316,25 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1652
2316
|
return args.cancel;
|
|
1653
2317
|
}
|
|
1654
2318
|
/**
|
|
1655
|
-
*
|
|
1656
|
-
*
|
|
2319
|
+
* 检查坐标是否落在当前控件区域中
|
|
2320
|
+
*
|
|
2321
|
+
* 用于点击测试和碰撞检测。
|
|
2322
|
+
* 支持旋转后的碰撞检测,以及自定义命中区域。
|
|
2323
|
+
*
|
|
1657
2324
|
* @method checkPoint
|
|
1658
|
-
* @param {
|
|
1659
|
-
* @param {number}
|
|
1660
|
-
* @
|
|
2325
|
+
* @param {Object} p - 要检测的点坐标
|
|
2326
|
+
* @param {number} p.x - X 坐标
|
|
2327
|
+
* @param {number} p.y - Y 坐标
|
|
2328
|
+
* @param {number} [pad] - 容差范围,默认使用 lineWidth 或 1
|
|
2329
|
+
* @returns {boolean} 点是否在控件区域内
|
|
2330
|
+
*
|
|
2331
|
+
* @example
|
|
2332
|
+
* // 检查点击位置
|
|
2333
|
+
* graph.bind('click', (evt) => {
|
|
2334
|
+
* if(control.checkPoint(evt.position)) {
|
|
2335
|
+
* console.log('点击了控件');
|
|
2336
|
+
* }
|
|
2337
|
+
* });
|
|
1661
2338
|
*/
|
|
1662
2339
|
|
|
1663
2340
|
}, {
|
|
@@ -1666,16 +2343,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1666
2343
|
//jmGraph 需要判断dom位置
|
|
1667
2344
|
if (this.type == 'jmGraph') {
|
|
1668
2345
|
//获取dom位置
|
|
1669
|
-
var position = this.getPosition();
|
|
1670
|
-
|
|
1671
|
-
var right = position.left + this.width;
|
|
1672
|
-
var bottom = position.top + this.height;
|
|
2346
|
+
var position = this.getPosition();
|
|
1673
2347
|
|
|
1674
|
-
if (p.
|
|
2348
|
+
if (p.pageX > position.right || p.pageX < position.left) {
|
|
1675
2349
|
return false;
|
|
1676
2350
|
}
|
|
1677
2351
|
|
|
1678
|
-
if (p.
|
|
2352
|
+
if (p.pageY > position.bottom || p.pageY < position.top) {
|
|
1679
2353
|
return false;
|
|
1680
2354
|
}
|
|
1681
2355
|
|
|
@@ -1793,12 +2467,19 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1793
2467
|
return true;
|
|
1794
2468
|
}
|
|
1795
2469
|
/**
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
2470
|
+
* 触发控件事件并执行事件冒泡
|
|
2471
|
+
*
|
|
2472
|
+
* 组合事件参数,按控件层级关系执行事件冒泡。
|
|
2473
|
+
* 事件从最上层的子控件开始触发,向上冒泡到父控件。
|
|
2474
|
+
*
|
|
1798
2475
|
* @method raiseEvent
|
|
1799
|
-
* @param {string} name 事件名称
|
|
1800
|
-
* @param {
|
|
1801
|
-
* @
|
|
2476
|
+
* @param {string} name - 事件名称
|
|
2477
|
+
* @param {Object} args - 原生事件对象
|
|
2478
|
+
* @returns {boolean} 如果事件被阻止冒泡则返回 false,否则返回 true
|
|
2479
|
+
*
|
|
2480
|
+
* @example
|
|
2481
|
+
* // 通常由框架内部调用,用户一般不需要直接调用
|
|
2482
|
+
* // 框架会自动处理鼠标/触摸事件
|
|
1802
2483
|
*/
|
|
1803
2484
|
|
|
1804
2485
|
}, {
|
|
@@ -1854,7 +2535,12 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1854
2535
|
args.position.x = args.position.offsetX - abounds.left;
|
|
1855
2536
|
args.position.y = args.position.offsetY - abounds.top; // 是否在当前控件内操作
|
|
1856
2537
|
|
|
1857
|
-
var inpos = this.interactive !== false && this.checkPoint(args.position);
|
|
2538
|
+
var inpos = this.interactive !== false && this.checkPoint(args.position);
|
|
2539
|
+
|
|
2540
|
+
if (name === 'mousemove' && this.type == 'jmGraph' && !inpos) {
|
|
2541
|
+
console.log('mousemove out', args.position, abounds);
|
|
2542
|
+
} //事件发生在边界内或健盘事件发生在画布中才触发
|
|
2543
|
+
|
|
1858
2544
|
|
|
1859
2545
|
if (inpos) {
|
|
1860
2546
|
//如果没有指定触发对象,则认为当前为第一触发对象
|
|
@@ -1881,9 +2567,14 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1881
2567
|
return args.cancel === false; //如果被阻止则返回false,否则返回true
|
|
1882
2568
|
}
|
|
1883
2569
|
/**
|
|
1884
|
-
*
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
2570
|
+
* 执行事件并进行冒泡
|
|
2571
|
+
*
|
|
2572
|
+
* 内部方法,用于执行事件处理并添加到事件路径。
|
|
2573
|
+
*
|
|
2574
|
+
* @method runEventAndPopEvent
|
|
2575
|
+
* @param {string} name - 事件名称
|
|
2576
|
+
* @param {Object} args - 事件参数
|
|
2577
|
+
* @protected
|
|
1887
2578
|
*/
|
|
1888
2579
|
|
|
1889
2580
|
}, {
|
|
@@ -1908,9 +2599,15 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1908
2599
|
}
|
|
1909
2600
|
/**
|
|
1910
2601
|
* 清空控件指定事件
|
|
1911
|
-
*
|
|
2602
|
+
*
|
|
2603
|
+
* 移除指定事件名称下的所有事件处理函数。
|
|
2604
|
+
*
|
|
1912
2605
|
* @method clearEvents
|
|
1913
|
-
* @param {string} name 需要清除的事件名称
|
|
2606
|
+
* @param {string} name - 需要清除的事件名称
|
|
2607
|
+
*
|
|
2608
|
+
* @example
|
|
2609
|
+
* // 清除所有点击事件
|
|
2610
|
+
* control.clearEvents('click');
|
|
1914
2611
|
*/
|
|
1915
2612
|
|
|
1916
2613
|
}, {
|
|
@@ -1919,15 +2616,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1919
2616
|
var eventCollection = this.getEvent(name);
|
|
1920
2617
|
|
|
1921
2618
|
if (eventCollection) {
|
|
1922
|
-
eventCollection.clear;
|
|
2619
|
+
eventCollection.clear();
|
|
1923
2620
|
}
|
|
1924
2621
|
}
|
|
1925
2622
|
/**
|
|
1926
|
-
*
|
|
1927
|
-
*
|
|
1928
|
-
*
|
|
1929
|
-
*
|
|
1930
|
-
* @
|
|
2623
|
+
* 查找指定类型的父级控件
|
|
2624
|
+
*
|
|
2625
|
+
* 沿着父级链向上查找,直到找到指定类型的控件或到达最顶级。
|
|
2626
|
+
*
|
|
2627
|
+
* @method findParent
|
|
2628
|
+
* @param {string|Function} type - 类型名称(字符串)或类构造函数
|
|
2629
|
+
* @returns {jmControl|null} 找到的父级控件实例,未找到返回 null
|
|
2630
|
+
*
|
|
2631
|
+
* @example
|
|
2632
|
+
* // 查找 jmGraph 实例
|
|
2633
|
+
* const graph = control.findParent('jmGraph');
|
|
2634
|
+
*
|
|
2635
|
+
* // 查找特定类的实例
|
|
2636
|
+
* const parent = control.findParent(MyCustomControl);
|
|
1931
2637
|
*/
|
|
1932
2638
|
|
|
1933
2639
|
}, {
|
|
@@ -1947,12 +2653,26 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1947
2653
|
return null;
|
|
1948
2654
|
}
|
|
1949
2655
|
/**
|
|
1950
|
-
*
|
|
1951
|
-
*
|
|
1952
|
-
*
|
|
2656
|
+
* 设置控件是否可拖动
|
|
2657
|
+
*
|
|
2658
|
+
* 启用或禁用控件的拖动功能。
|
|
2659
|
+
* 拖动时会触发 movestart、move、moveend 事件。
|
|
2660
|
+
*
|
|
1953
2661
|
* @method canMove
|
|
1954
|
-
* @param {boolean} m true
|
|
1955
|
-
* @param {jmGraph} [graph]
|
|
2662
|
+
* @param {boolean} m - true 启用拖动,false 禁用拖动
|
|
2663
|
+
* @param {jmGraph} [graph] - 画布实例,如果控件已添加到画布可省略
|
|
2664
|
+
* @returns {jmControl} 返回 this 以支持链式调用
|
|
2665
|
+
*
|
|
2666
|
+
* @example
|
|
2667
|
+
* // 启用拖动
|
|
2668
|
+
* control.canMove(true);
|
|
2669
|
+
*
|
|
2670
|
+
* // 禁用拖动
|
|
2671
|
+
* control.canMove(false);
|
|
2672
|
+
*
|
|
2673
|
+
* // 监听拖动事件
|
|
2674
|
+
* control.on('movestart', (evt) => console.log('开始拖动'));
|
|
2675
|
+
* control.on('moveend', (evt) => console.log('结束拖动'));
|
|
1956
2676
|
*/
|
|
1957
2677
|
|
|
1958
2678
|
}, {
|
|
@@ -2022,7 +2742,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
2022
2742
|
_this.offset(offsetx, offsety, true, evt);
|
|
2023
2743
|
|
|
2024
2744
|
if (offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
|
|
2025
|
-
if (offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY; //console.log(offsetx + '.' + offsety);
|
|
2745
|
+
if (offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY; //console.log('mouse move',offsetx + '.' + offsety);
|
|
2026
2746
|
}
|
|
2027
2747
|
|
|
2028
2748
|
return false;
|
|
@@ -2146,15 +2866,63 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
2146
2866
|
|
|
2147
2867
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2148
2868
|
|
|
2869
|
+
/**
|
|
2870
|
+
* jmEvents 事件处理类
|
|
2871
|
+
*
|
|
2872
|
+
* 统一管理画布上的所有交互事件,包括鼠标、触摸和键盘事件。
|
|
2873
|
+
* 支持事件冒泡机制,可以将事件传递给子控件处理。
|
|
2874
|
+
*
|
|
2875
|
+
* @class jmEvents
|
|
2876
|
+
*
|
|
2877
|
+
* @param {jmGraph} container jmGraph 实例
|
|
2878
|
+
* @param {HTMLElement} target 事件目标元素(通常是 canvas 元素)
|
|
2879
|
+
*
|
|
2880
|
+
* @example
|
|
2881
|
+
* // 通常由 jmGraph 内部创建,不需要手动实例化
|
|
2882
|
+
* const events = new jmEvents(graph, canvasElement);
|
|
2883
|
+
*/
|
|
2149
2884
|
var jmEvents = /*#__PURE__*/function () {
|
|
2885
|
+
/**
|
|
2886
|
+
* 构造函数
|
|
2887
|
+
*
|
|
2888
|
+
* @param {jmGraph} container jmGraph 实例
|
|
2889
|
+
* @param {HTMLElement} target 事件目标元素
|
|
2890
|
+
*/
|
|
2150
2891
|
function jmEvents(container, target) {
|
|
2151
2892
|
_classCallCheck(this, jmEvents);
|
|
2152
2893
|
|
|
2894
|
+
/**
|
|
2895
|
+
* jmGraph 实例
|
|
2896
|
+
* @type {jmGraph}
|
|
2897
|
+
*/
|
|
2153
2898
|
this.container = container;
|
|
2899
|
+
/**
|
|
2900
|
+
* 事件目标元素
|
|
2901
|
+
* @type {HTMLElement}
|
|
2902
|
+
*/
|
|
2903
|
+
|
|
2154
2904
|
this.target = target || container;
|
|
2905
|
+
/**
|
|
2906
|
+
* 鼠标事件处理器
|
|
2907
|
+
* @type {jmMouseEvent}
|
|
2908
|
+
*/
|
|
2909
|
+
|
|
2155
2910
|
this.mouseHandler = new jmMouseEvent(this, container, target);
|
|
2911
|
+
/**
|
|
2912
|
+
* 键盘事件处理器
|
|
2913
|
+
* @type {jmKeyEvent}
|
|
2914
|
+
*/
|
|
2915
|
+
|
|
2156
2916
|
this.keyHandler = new jmKeyEvent(this, container, target);
|
|
2157
2917
|
}
|
|
2918
|
+
/**
|
|
2919
|
+
* 触摸开始事件处理
|
|
2920
|
+
*
|
|
2921
|
+
* @method touchStart
|
|
2922
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2923
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2924
|
+
*/
|
|
2925
|
+
|
|
2158
2926
|
|
|
2159
2927
|
_createClass(jmEvents, [{
|
|
2160
2928
|
key: "touchStart",
|
|
@@ -2170,7 +2938,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2170
2938
|
}
|
|
2171
2939
|
}, {
|
|
2172
2940
|
key: "touchMove",
|
|
2173
|
-
value:
|
|
2941
|
+
value:
|
|
2942
|
+
/**
|
|
2943
|
+
* 触摸移动事件处理
|
|
2944
|
+
*
|
|
2945
|
+
* @method touchMove
|
|
2946
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2947
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2948
|
+
*/
|
|
2949
|
+
function touchMove(evt) {
|
|
2174
2950
|
evt = evt || window.event;
|
|
2175
2951
|
evt.eventName = 'touchmove';
|
|
2176
2952
|
this.container.raiseEvent('touchmove', evt);
|
|
@@ -2182,7 +2958,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2182
2958
|
}
|
|
2183
2959
|
}, {
|
|
2184
2960
|
key: "touchEnd",
|
|
2185
|
-
value:
|
|
2961
|
+
value:
|
|
2962
|
+
/**
|
|
2963
|
+
* 触摸结束事件处理
|
|
2964
|
+
*
|
|
2965
|
+
* @method touchEnd
|
|
2966
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2967
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2968
|
+
*/
|
|
2969
|
+
function touchEnd(evt) {
|
|
2186
2970
|
evt = evt || window.event;
|
|
2187
2971
|
evt.eventName = 'touchend';
|
|
2188
2972
|
this.container.raiseEvent('touchend', evt);
|
|
@@ -2194,7 +2978,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2194
2978
|
}
|
|
2195
2979
|
}, {
|
|
2196
2980
|
key: "touchCancel",
|
|
2197
|
-
value:
|
|
2981
|
+
value:
|
|
2982
|
+
/**
|
|
2983
|
+
* 触摸取消事件处理
|
|
2984
|
+
*
|
|
2985
|
+
* @method touchCancel
|
|
2986
|
+
* @param {TouchEvent} evt 触摸事件对象
|
|
2987
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
2988
|
+
*/
|
|
2989
|
+
function touchCancel(evt) {
|
|
2198
2990
|
evt = evt || window.event;
|
|
2199
2991
|
evt.eventName = 'touchcancel';
|
|
2200
2992
|
this.container.raiseEvent('touchcancel', evt);
|
|
@@ -2206,7 +2998,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2206
2998
|
}
|
|
2207
2999
|
}, {
|
|
2208
3000
|
key: "tap",
|
|
2209
|
-
value:
|
|
3001
|
+
value:
|
|
3002
|
+
/**
|
|
3003
|
+
* 轻触事件处理
|
|
3004
|
+
*
|
|
3005
|
+
* @method tap
|
|
3006
|
+
* @param {Event} evt 事件对象
|
|
3007
|
+
* @return {boolean} 如果事件目标为画布本身则返回 false
|
|
3008
|
+
*/
|
|
3009
|
+
function tap(evt) {
|
|
2210
3010
|
evt = evt || window.event;
|
|
2211
3011
|
evt.eventName = 'tap';
|
|
2212
3012
|
this.container.raiseEvent('tap', evt);
|
|
@@ -2218,7 +3018,15 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2218
3018
|
}
|
|
2219
3019
|
}, {
|
|
2220
3020
|
key: "destroy",
|
|
2221
|
-
value:
|
|
3021
|
+
value:
|
|
3022
|
+
/**
|
|
3023
|
+
* 销毁事件处理器
|
|
3024
|
+
*
|
|
3025
|
+
* 移除所有绑定的事件监听器,释放资源。
|
|
3026
|
+
*
|
|
3027
|
+
* @method destroy
|
|
3028
|
+
*/
|
|
3029
|
+
function destroy() {
|
|
2222
3030
|
this.mouseHandler.destroy();
|
|
2223
3031
|
this.keyHandler.destroy();
|
|
2224
3032
|
}
|
|
@@ -2226,19 +3034,48 @@ var jmEvents = /*#__PURE__*/function () {
|
|
|
2226
3034
|
|
|
2227
3035
|
return jmEvents;
|
|
2228
3036
|
}();
|
|
3037
|
+
/**
|
|
3038
|
+
* 鼠标事件处理器
|
|
3039
|
+
*
|
|
3040
|
+
* @class jmMouseEvent
|
|
3041
|
+
* @private
|
|
3042
|
+
*/
|
|
3043
|
+
|
|
2229
3044
|
|
|
2230
3045
|
exports.jmEvents = exports["default"] = jmEvents;
|
|
2231
3046
|
|
|
2232
3047
|
var jmMouseEvent = /*#__PURE__*/function () {
|
|
3048
|
+
/**
|
|
3049
|
+
* 构造函数
|
|
3050
|
+
*
|
|
3051
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3052
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3053
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3054
|
+
*/
|
|
2233
3055
|
function jmMouseEvent(instance, container, target) {
|
|
2234
3056
|
_classCallCheck(this, jmMouseEvent);
|
|
2235
3057
|
|
|
2236
3058
|
this.instance = instance;
|
|
2237
3059
|
this.container = container;
|
|
2238
3060
|
this.target = target || container;
|
|
3061
|
+
/**
|
|
3062
|
+
* 已绑定的事件映射表
|
|
3063
|
+
* @type {Object}
|
|
3064
|
+
*/
|
|
3065
|
+
|
|
2239
3066
|
this.eventEvents = {};
|
|
2240
3067
|
this.init(instance, container, target);
|
|
2241
3068
|
}
|
|
3069
|
+
/**
|
|
3070
|
+
* 初始化鼠标事件绑定
|
|
3071
|
+
*
|
|
3072
|
+
* @method init
|
|
3073
|
+
* @private
|
|
3074
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3075
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3076
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3077
|
+
*/
|
|
3078
|
+
|
|
2242
3079
|
|
|
2243
3080
|
_createClass(jmMouseEvent, [{
|
|
2244
3081
|
key: "init",
|
|
@@ -2326,6 +3163,14 @@ var jmMouseEvent = /*#__PURE__*/function () {
|
|
|
2326
3163
|
passive: false
|
|
2327
3164
|
}));
|
|
2328
3165
|
}
|
|
3166
|
+
/**
|
|
3167
|
+
* 销毁鼠标事件处理器
|
|
3168
|
+
*
|
|
3169
|
+
* 移除所有绑定的鼠标事件监听器。
|
|
3170
|
+
*
|
|
3171
|
+
* @method destroy
|
|
3172
|
+
*/
|
|
3173
|
+
|
|
2329
3174
|
}, {
|
|
2330
3175
|
key: "destroy",
|
|
2331
3176
|
value: function destroy() {
|
|
@@ -2340,17 +3185,45 @@ var jmMouseEvent = /*#__PURE__*/function () {
|
|
|
2340
3185
|
|
|
2341
3186
|
return jmMouseEvent;
|
|
2342
3187
|
}();
|
|
3188
|
+
/**
|
|
3189
|
+
* 键盘事件处理器
|
|
3190
|
+
*
|
|
3191
|
+
* @class jmKeyEvent
|
|
3192
|
+
* @private
|
|
3193
|
+
*/
|
|
3194
|
+
|
|
2343
3195
|
|
|
2344
3196
|
var jmKeyEvent = /*#__PURE__*/function () {
|
|
3197
|
+
/**
|
|
3198
|
+
* 构造函数
|
|
3199
|
+
*
|
|
3200
|
+
* @param {jmEvents} instance jmEvents 实例
|
|
3201
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3202
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3203
|
+
*/
|
|
2345
3204
|
function jmKeyEvent(instance, container, target) {
|
|
2346
3205
|
_classCallCheck(this, jmKeyEvent);
|
|
2347
3206
|
|
|
2348
3207
|
this.instance = instance;
|
|
2349
3208
|
this.container = container;
|
|
2350
3209
|
this.target = target || container;
|
|
3210
|
+
/**
|
|
3211
|
+
* 已绑定的事件映射表
|
|
3212
|
+
* @type {Object}
|
|
3213
|
+
*/
|
|
3214
|
+
|
|
2351
3215
|
this.eventEvents = {};
|
|
2352
3216
|
this.init(container, target);
|
|
2353
3217
|
}
|
|
3218
|
+
/**
|
|
3219
|
+
* 初始化键盘事件绑定
|
|
3220
|
+
*
|
|
3221
|
+
* @method init
|
|
3222
|
+
* @private
|
|
3223
|
+
* @param {jmGraph} container jmGraph 实例
|
|
3224
|
+
* @param {HTMLElement} target 事件目标元素
|
|
3225
|
+
*/
|
|
3226
|
+
|
|
2354
3227
|
|
|
2355
3228
|
_createClass(jmKeyEvent, [{
|
|
2356
3229
|
key: "init",
|
|
@@ -2423,13 +3296,28 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
2423
3296
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
2424
3297
|
|
|
2425
3298
|
/**
|
|
2426
|
-
* CSS滤镜效果类
|
|
3299
|
+
* CSS 滤镜效果类
|
|
3300
|
+
*
|
|
2427
3301
|
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
2428
3302
|
*
|
|
2429
3303
|
* @class jmFilter
|
|
2430
3304
|
* @param {string|object} opt 滤镜参数
|
|
2431
3305
|
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
2432
3306
|
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
3307
|
+
*
|
|
3308
|
+
* @example
|
|
3309
|
+
* // 从字符串创建
|
|
3310
|
+
* const filter = new jmFilter('blur(2px) grayscale(50%)');
|
|
3311
|
+
*
|
|
3312
|
+
* // 从对象创建
|
|
3313
|
+
* const filter = new jmFilter({
|
|
3314
|
+
* blur: 2,
|
|
3315
|
+
* grayscale: 0.5,
|
|
3316
|
+
* brightness: 1.2
|
|
3317
|
+
* });
|
|
3318
|
+
*
|
|
3319
|
+
* // 应用到图形
|
|
3320
|
+
* shape.style.filter = filter;
|
|
2433
3321
|
*/
|
|
2434
3322
|
var jmFilter = /*#__PURE__*/function () {
|
|
2435
3323
|
function jmFilter(opt) {
|
|
@@ -2641,9 +3529,36 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
2641
3529
|
|
|
2642
3530
|
/**
|
|
2643
3531
|
* 渐变类
|
|
2644
|
-
*
|
|
3532
|
+
*
|
|
3533
|
+
* 用于创建和管理线性渐变或径向渐变效果。
|
|
3534
|
+
* 支持 CSS 渐变字符串格式解析,可以转换为 Canvas 或 WebGL 兼容的渐变对象。
|
|
3535
|
+
*
|
|
2645
3536
|
* @class jmGradient
|
|
2646
|
-
*
|
|
3537
|
+
*
|
|
3538
|
+
* @param {Object|string} opt 渐变参数对象或 CSS 渐变字符串
|
|
3539
|
+
* @param {string} [opt.type='linear'] 渐变类型:'linear' 或 'radial'
|
|
3540
|
+
* @param {number|string} [opt.x1] 起点X坐标(支持百分比)
|
|
3541
|
+
* @param {number|string} [opt.y1] 起点Y坐标(支持百分比)
|
|
3542
|
+
* @param {number|string} [opt.x2] 终点X坐标(支持百分比)
|
|
3543
|
+
* @param {number|string} [opt.y2] 终点Y坐标(支持百分比)
|
|
3544
|
+
* @param {number|string} [opt.r1] 内圆半径(径向渐变)
|
|
3545
|
+
* @param {number|string} [opt.r2] 外圆半径(径向渐变)
|
|
3546
|
+
* @param {Array} [opt.stops] 颜色停止点数组 [{offset, color}, ...]
|
|
3547
|
+
*
|
|
3548
|
+
* @example
|
|
3549
|
+
* // 创建线性渐变
|
|
3550
|
+
* const gradient = new jmGradient({
|
|
3551
|
+
* type: 'linear',
|
|
3552
|
+
* x1: 0, y1: 0,
|
|
3553
|
+
* x2: '100%', y2: '100%',
|
|
3554
|
+
* stops: [
|
|
3555
|
+
* { offset: 0, color: '#ff0000' },
|
|
3556
|
+
* { offset: 1, color: '#0000ff' }
|
|
3557
|
+
* ]
|
|
3558
|
+
* });
|
|
3559
|
+
*
|
|
3560
|
+
* // 从 CSS 字符串创建
|
|
3561
|
+
* const gradient = new jmGradient('linear-gradient(180deg, #ff0000, #0000ff)');
|
|
2647
3562
|
*/
|
|
2648
3563
|
var jmGradient = /*#__PURE__*/function () {
|
|
2649
3564
|
function jmGradient(opt) {
|
|
@@ -3672,15 +4587,39 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
3672
4587
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
3673
4588
|
|
|
3674
4589
|
/**
|
|
3675
|
-
* jmGraph
|
|
3676
|
-
*
|
|
3677
|
-
*
|
|
3678
|
-
*
|
|
4590
|
+
* jmGraph 画图类
|
|
4591
|
+
*
|
|
4592
|
+
* 对 Canvas 画图 API 进行二次封装,使其更易调用,省去很多重复的工作。
|
|
4593
|
+
* 支持多种图形的创建、渲染、交互和导出。
|
|
4594
|
+
*
|
|
3679
4595
|
* @class jmGraph
|
|
3680
4596
|
* @extends jmControl
|
|
3681
|
-
*
|
|
3682
|
-
* @param {
|
|
3683
|
-
* @param {
|
|
4597
|
+
*
|
|
4598
|
+
* @param {HTMLElement|string} canvas Canvas 元素或元素 ID
|
|
4599
|
+
* @param {Object} [option] 配置选项
|
|
4600
|
+
* @param {number} [option.width] 画布宽度
|
|
4601
|
+
* @param {number} [option.height] 画布高度
|
|
4602
|
+
* @param {string} [option.mode='2d'] 渲染模式:'2d' 或 'webgl'
|
|
4603
|
+
* @param {boolean} [option.autoRefresh=false] 是否自动刷新
|
|
4604
|
+
* @param {Object} [option.shapes] 自定义图形类型映射
|
|
4605
|
+
* @param {function} [callback] 初始化完成后的回调函数
|
|
4606
|
+
*
|
|
4607
|
+
* @example
|
|
4608
|
+
* // 创建画布实例
|
|
4609
|
+
* const graph = new jmGraph('canvasId', {
|
|
4610
|
+
* width: 800,
|
|
4611
|
+
* height: 600,
|
|
4612
|
+
* mode: '2d'
|
|
4613
|
+
* });
|
|
4614
|
+
*
|
|
4615
|
+
* // 创建一个矩形
|
|
4616
|
+
* const rect = graph.createShape('rect', {
|
|
4617
|
+
* x: 100, y: 100,
|
|
4618
|
+
* width: 200, height: 150,
|
|
4619
|
+
* style: { fill: '#ff0000' }
|
|
4620
|
+
* });
|
|
4621
|
+
* graph.children.add(rect);
|
|
4622
|
+
* graph.refresh();
|
|
3684
4623
|
*/
|
|
3685
4624
|
var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
3686
4625
|
_inherits(jmGraph, _jmControl);
|
|
@@ -4580,11 +5519,61 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
|
|
|
4580
5519
|
|
|
4581
5520
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4582
5521
|
|
|
5522
|
+
/**
|
|
5523
|
+
* @fileoverview jmList 列表类
|
|
5524
|
+
*
|
|
5525
|
+
* jmList 是 jmGraph 库的集合类,继承自原生 Array。
|
|
5526
|
+
* 提供了增强的列表操作方法,包括去重添加、条件查找、遍历等。
|
|
5527
|
+
*
|
|
5528
|
+
* 主要功能:
|
|
5529
|
+
* - 去重添加元素(add)
|
|
5530
|
+
* - 条件查找(get)
|
|
5531
|
+
* - 正向/反向遍历(each)
|
|
5532
|
+
* - 元素计数(count)
|
|
5533
|
+
* - 移除回调支持
|
|
5534
|
+
*
|
|
5535
|
+
* @module jmList
|
|
5536
|
+
* @author jmGraph Team
|
|
5537
|
+
* @license MIT
|
|
5538
|
+
*/
|
|
5539
|
+
|
|
5540
|
+
/**
|
|
5541
|
+
* jmList 列表类
|
|
5542
|
+
*
|
|
5543
|
+
* 继承自 Array 的增强列表类,提供去重、遍历、查找等功能。
|
|
5544
|
+
* 主要用于管理图形对象的子元素集合。
|
|
5545
|
+
*
|
|
5546
|
+
* @class jmList
|
|
5547
|
+
* @extends Array
|
|
5548
|
+
*
|
|
5549
|
+
* @param {...*} arg 初始元素或数组
|
|
5550
|
+
*
|
|
5551
|
+
* @example
|
|
5552
|
+
* // 创建列表
|
|
5553
|
+
* const list = new jmList([1, 2, 3]);
|
|
5554
|
+
*
|
|
5555
|
+
* // 添加元素(自动去重)
|
|
5556
|
+
* list.add(4);
|
|
5557
|
+
* list.add([5, 6]);
|
|
5558
|
+
*
|
|
5559
|
+
* // 遍历
|
|
5560
|
+
* list.each((index, item) => {
|
|
5561
|
+
* console.log(index, item);
|
|
5562
|
+
* });
|
|
5563
|
+
*
|
|
5564
|
+
* // 条件查找
|
|
5565
|
+
* const found = list.get(item => item > 3);
|
|
5566
|
+
*/
|
|
4583
5567
|
var jmList = /*#__PURE__*/function (_Array) {
|
|
4584
5568
|
_inherits(jmList, _Array);
|
|
4585
5569
|
|
|
4586
5570
|
var _super = _createSuper(jmList);
|
|
4587
5571
|
|
|
5572
|
+
/**
|
|
5573
|
+
* 构造函数
|
|
5574
|
+
*
|
|
5575
|
+
* @param {...*} arg 初始元素或数组
|
|
5576
|
+
*/
|
|
4588
5577
|
function jmList() {
|
|
4589
5578
|
var _this;
|
|
4590
5579
|
|
|
@@ -4605,11 +5594,37 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4605
5594
|
} else {
|
|
4606
5595
|
_this = _super.call(this);
|
|
4607
5596
|
}
|
|
5597
|
+
/**
|
|
5598
|
+
* 配置选项
|
|
5599
|
+
* @type {Object}
|
|
5600
|
+
* @property {function} removeHandler 元素移除时的回调函数
|
|
5601
|
+
*/
|
|
5602
|
+
|
|
4608
5603
|
|
|
4609
5604
|
_this.option = {};
|
|
5605
|
+
/**
|
|
5606
|
+
* 类型标识
|
|
5607
|
+
* @type {string}
|
|
5608
|
+
*/
|
|
5609
|
+
|
|
4610
5610
|
_this.type = 'jmList';
|
|
4611
5611
|
return _possibleConstructorReturn(_this);
|
|
4612
5612
|
}
|
|
5613
|
+
/**
|
|
5614
|
+
* 添加元素到列表
|
|
5615
|
+
*
|
|
5616
|
+
* 自动去重,如果元素已存在则不会重复添加。
|
|
5617
|
+
* 支持添加单个元素或数组。
|
|
5618
|
+
*
|
|
5619
|
+
* @method add
|
|
5620
|
+
* @param {*} obj 要添加的元素或数组
|
|
5621
|
+
* @returns {*} 添加的元素
|
|
5622
|
+
*
|
|
5623
|
+
* @example
|
|
5624
|
+
* list.add(1); // 添加单个元素
|
|
5625
|
+
* list.add([2, 3, 4]); // 添加数组
|
|
5626
|
+
*/
|
|
5627
|
+
|
|
4613
5628
|
|
|
4614
5629
|
_createClass(jmList, [{
|
|
4615
5630
|
key: "add",
|
|
@@ -4626,6 +5641,18 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4626
5641
|
this.push(obj);
|
|
4627
5642
|
return obj;
|
|
4628
5643
|
}
|
|
5644
|
+
/**
|
|
5645
|
+
* 从列表中移除元素
|
|
5646
|
+
*
|
|
5647
|
+
* 移除所有匹配的元素,并触发移除回调。
|
|
5648
|
+
*
|
|
5649
|
+
* @method remove
|
|
5650
|
+
* @param {*} obj 要移除的元素
|
|
5651
|
+
*
|
|
5652
|
+
* @example
|
|
5653
|
+
* list.remove(item);
|
|
5654
|
+
*/
|
|
5655
|
+
|
|
4629
5656
|
}, {
|
|
4630
5657
|
key: "remove",
|
|
4631
5658
|
value: function remove(obj) {
|
|
@@ -4635,6 +5662,16 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4635
5662
|
}
|
|
4636
5663
|
}
|
|
4637
5664
|
}
|
|
5665
|
+
/**
|
|
5666
|
+
* 移除指定索引位置的元素
|
|
5667
|
+
*
|
|
5668
|
+
* @method removeAt
|
|
5669
|
+
* @param {number} index 要移除的元素索引
|
|
5670
|
+
*
|
|
5671
|
+
* @example
|
|
5672
|
+
* list.removeAt(0); // 移除第一个元素
|
|
5673
|
+
*/
|
|
5674
|
+
|
|
4638
5675
|
}, {
|
|
4639
5676
|
key: "removeAt",
|
|
4640
5677
|
value: function removeAt(index) {
|
|
@@ -4644,11 +5681,42 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4644
5681
|
if (this.option.removeHandler) this.option.removeHandler.call(this, obj, index);
|
|
4645
5682
|
}
|
|
4646
5683
|
}
|
|
5684
|
+
/**
|
|
5685
|
+
* 检查列表是否包含指定元素
|
|
5686
|
+
*
|
|
5687
|
+
* @method contain
|
|
5688
|
+
* @param {*} obj 要检查的元素
|
|
5689
|
+
* @returns {boolean} 如果包含返回 true,否则返回 false
|
|
5690
|
+
*
|
|
5691
|
+
* @example
|
|
5692
|
+
* if (list.contain(item)) {
|
|
5693
|
+
* console.log('元素存在');
|
|
5694
|
+
* }
|
|
5695
|
+
*/
|
|
5696
|
+
|
|
4647
5697
|
}, {
|
|
4648
5698
|
key: "contain",
|
|
4649
5699
|
value: function contain(obj) {
|
|
4650
5700
|
return this.includes(obj);
|
|
4651
5701
|
}
|
|
5702
|
+
/**
|
|
5703
|
+
* 获取元素
|
|
5704
|
+
*
|
|
5705
|
+
* 如果参数是函数,则返回第一个满足条件的元素;
|
|
5706
|
+
* 如果参数是数字,则返回指定索引的元素。
|
|
5707
|
+
*
|
|
5708
|
+
* @method get
|
|
5709
|
+
* @param {number|function} index 索引或条件函数
|
|
5710
|
+
* @returns {*} 找到的元素,如果未找到返回 undefined
|
|
5711
|
+
*
|
|
5712
|
+
* @example
|
|
5713
|
+
* // 按索引获取
|
|
5714
|
+
* const item = list.get(0);
|
|
5715
|
+
*
|
|
5716
|
+
* // 按条件查找
|
|
5717
|
+
* const found = list.get(item => item.id === 5);
|
|
5718
|
+
*/
|
|
5719
|
+
|
|
4652
5720
|
}, {
|
|
4653
5721
|
key: "get",
|
|
4654
5722
|
value: function get(index) {
|
|
@@ -4658,6 +5726,28 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4658
5726
|
return this[index];
|
|
4659
5727
|
}
|
|
4660
5728
|
}
|
|
5729
|
+
/**
|
|
5730
|
+
* 遍历列表
|
|
5731
|
+
*
|
|
5732
|
+
* 支持正向和反向遍历。在回调中返回 false 可以中断遍历。
|
|
5733
|
+
*
|
|
5734
|
+
* @method each
|
|
5735
|
+
* @param {function} cb 回调函数,参数为 (index, item)
|
|
5736
|
+
* @param {boolean} [inverse=false] 是否反向遍历
|
|
5737
|
+
*
|
|
5738
|
+
* @example
|
|
5739
|
+
* // 正向遍历
|
|
5740
|
+
* list.each((index, item) => {
|
|
5741
|
+
* console.log(index, item);
|
|
5742
|
+
* if (item.id === 3) return false; // 中断遍历
|
|
5743
|
+
* });
|
|
5744
|
+
*
|
|
5745
|
+
* // 反向遍历
|
|
5746
|
+
* list.each((index, item) => {
|
|
5747
|
+
* console.log(index, item);
|
|
5748
|
+
* }, true);
|
|
5749
|
+
*/
|
|
5750
|
+
|
|
4661
5751
|
}, {
|
|
4662
5752
|
key: "each",
|
|
4663
5753
|
value: function each(cb, inverse) {
|
|
@@ -4678,6 +5768,21 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4678
5768
|
}
|
|
4679
5769
|
}
|
|
4680
5770
|
}
|
|
5771
|
+
/**
|
|
5772
|
+
* 统计元素数量
|
|
5773
|
+
*
|
|
5774
|
+
* 如果提供了条件函数,返回满足条件的元素数量;
|
|
5775
|
+
* 否则返回列表总长度。
|
|
5776
|
+
*
|
|
5777
|
+
* @method count
|
|
5778
|
+
* @param {function} [handler] 条件函数
|
|
5779
|
+
* @returns {number} 元素数量
|
|
5780
|
+
*
|
|
5781
|
+
* @example
|
|
5782
|
+
* const total = list.count(); // 总数量
|
|
5783
|
+
* const matched = list.count(item => item.active); // 满足条件的数量
|
|
5784
|
+
*/
|
|
5785
|
+
|
|
4681
5786
|
}, {
|
|
4682
5787
|
key: "count",
|
|
4683
5788
|
value: function count(handler) {
|
|
@@ -4696,6 +5801,17 @@ var jmList = /*#__PURE__*/function (_Array) {
|
|
|
4696
5801
|
|
|
4697
5802
|
return this.length;
|
|
4698
5803
|
}
|
|
5804
|
+
/**
|
|
5805
|
+
* 清空列表
|
|
5806
|
+
*
|
|
5807
|
+
* 移除列表中的所有元素。
|
|
5808
|
+
*
|
|
5809
|
+
* @method clear
|
|
5810
|
+
*
|
|
5811
|
+
* @example
|
|
5812
|
+
* list.clear();
|
|
5813
|
+
*/
|
|
5814
|
+
|
|
4699
5815
|
}, {
|
|
4700
5816
|
key: "clear",
|
|
4701
5817
|
value: function clear() {
|
|
@@ -4724,91 +5840,197 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
4724
5840
|
|
|
4725
5841
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
4726
5842
|
|
|
5843
|
+
/**
|
|
5844
|
+
* 控件ID计数器
|
|
5845
|
+
* 用于为每个新创建的对象生成唯一标识符
|
|
5846
|
+
* @type {number}
|
|
5847
|
+
* @private
|
|
5848
|
+
*/
|
|
4727
5849
|
var control_id_counter = 0;
|
|
5850
|
+
/**
|
|
5851
|
+
* jmGraph 基础对象类
|
|
5852
|
+
*
|
|
5853
|
+
* 所有图形控件、属性对象、工具类的基类。
|
|
5854
|
+
* 提供了对象标识、类型检查和动画调度等核心功能。
|
|
5855
|
+
*
|
|
5856
|
+
* @class jmObject
|
|
5857
|
+
* @example
|
|
5858
|
+
* // 创建一个基础对象
|
|
5859
|
+
* const obj = new jmObject();
|
|
5860
|
+
* console.log(obj.id); // 输出唯一ID
|
|
5861
|
+
*
|
|
5862
|
+
* // 类型检查
|
|
5863
|
+
* obj.is('jmObject'); // true
|
|
5864
|
+
* obj.is(jmObject); // true
|
|
5865
|
+
*/
|
|
4728
5866
|
|
|
4729
5867
|
var jmObject = /*#__PURE__*/function () {
|
|
5868
|
+
/**
|
|
5869
|
+
* 构造函数
|
|
5870
|
+
*
|
|
5871
|
+
* 创建一个新的基础对象实例,自动分配唯一ID。
|
|
5872
|
+
* 如果传入的是 jmGraph 实例,则建立关联关系。
|
|
5873
|
+
*
|
|
5874
|
+
* @constructor
|
|
5875
|
+
* @param {jmGraph} [g] - 可选的 jmGraph 实例,用于建立对象与画布的关联
|
|
5876
|
+
*
|
|
5877
|
+
* @example
|
|
5878
|
+
* // 创建独立对象
|
|
5879
|
+
* const obj = new jmObject();
|
|
5880
|
+
*
|
|
5881
|
+
* // 创建关联画布的对象
|
|
5882
|
+
* const graph = new jmGraph(canvas);
|
|
5883
|
+
* const objWithGraph = new jmObject(graph);
|
|
5884
|
+
*/
|
|
4730
5885
|
function jmObject(g) {
|
|
4731
5886
|
_classCallCheck(this, jmObject);
|
|
4732
5887
|
|
|
5888
|
+
// 如果传入的是 jmGraph 实例,则建立引用关系
|
|
4733
5889
|
if (g && g.type == 'jmGraph') {
|
|
4734
5890
|
this.graph = g;
|
|
4735
|
-
}
|
|
5891
|
+
} // 生成唯一ID
|
|
5892
|
+
|
|
4736
5893
|
|
|
4737
5894
|
this.id = ++control_id_counter;
|
|
4738
5895
|
}
|
|
4739
5896
|
/**
|
|
4740
|
-
*
|
|
5897
|
+
* 检查对象是否为指定类型
|
|
5898
|
+
*
|
|
5899
|
+
* 支持两种类型检查方式:
|
|
5900
|
+
* 1. 字符串方式:检查对象的 type 属性是否匹配
|
|
5901
|
+
* 2. 类构造函数方式:使用 instanceof 检查原型链
|
|
4741
5902
|
*
|
|
4742
5903
|
* @method is
|
|
4743
|
-
* @param {
|
|
4744
|
-
* @
|
|
4745
|
-
*
|
|
5904
|
+
* @param {string|Function} type - 要检查的类型名称(字符串)或类构造函数
|
|
5905
|
+
* @returns {boolean} 如果对象是指定类型则返回 true,否则返回 false
|
|
5906
|
+
*
|
|
5907
|
+
* @example
|
|
5908
|
+
* // 使用字符串检查
|
|
5909
|
+
* control.is('jmRect'); // 检查是否为矩形
|
|
5910
|
+
*
|
|
5911
|
+
* // 使用类构造函数检查
|
|
5912
|
+
* control.is(jmControl); // 检查是否为 jmControl 实例
|
|
5913
|
+
* control.is(jmPath); // 检查是否继承自 jmPath
|
|
4746
5914
|
*/
|
|
4747
5915
|
|
|
4748
5916
|
|
|
4749
5917
|
_createClass(jmObject, [{
|
|
4750
5918
|
key: "is",
|
|
4751
5919
|
value: function is(type) {
|
|
5920
|
+
// 字符串类型:检查 type 属性
|
|
4752
5921
|
if (typeof type == 'string') {
|
|
4753
5922
|
return this.type == type;
|
|
4754
|
-
}
|
|
5923
|
+
} // 类构造函数:使用 instanceof 检查原型链
|
|
5924
|
+
|
|
4755
5925
|
|
|
4756
5926
|
return this instanceof type;
|
|
4757
5927
|
}
|
|
5928
|
+
/**
|
|
5929
|
+
* 注册并执行动画帧回调
|
|
5930
|
+
*
|
|
5931
|
+
* 提供动画帧调度功能,支持:
|
|
5932
|
+
* - 按指定时间间隔执行回调
|
|
5933
|
+
* - 多个动画句柄并行执行
|
|
5934
|
+
* - 自动清理返回 false 的动画
|
|
5935
|
+
* - 错误自动移除异常动画
|
|
5936
|
+
*
|
|
5937
|
+
* 此方法通常由 jmGraph 实例调用,子控件会委托给所属的 graph 处理。
|
|
5938
|
+
*
|
|
5939
|
+
* @method animate
|
|
5940
|
+
* @param {Function} handle - 动画回调函数,返回 false 时自动移除
|
|
5941
|
+
* @param {number} [millisec=20] - 执行间隔(毫秒),默认 20ms
|
|
5942
|
+
* @param {...*} [params] - 传递给回调函数的额外参数
|
|
5943
|
+
*
|
|
5944
|
+
* @example
|
|
5945
|
+
* // 创建一个简单的动画
|
|
5946
|
+
* let x = 0;
|
|
5947
|
+
* graph.animate(function() {
|
|
5948
|
+
* x += 1;
|
|
5949
|
+
* rect.position.x = x;
|
|
5950
|
+
* graph.redraw();
|
|
5951
|
+
*
|
|
5952
|
+
* // 动画结束条件
|
|
5953
|
+
* if(x > 100) return false;
|
|
5954
|
+
* }, 16); // 约60fps
|
|
5955
|
+
*
|
|
5956
|
+
* // 带参数的动画
|
|
5957
|
+
* graph.animate(function(speed) {
|
|
5958
|
+
* x += speed;
|
|
5959
|
+
* // ...
|
|
5960
|
+
* }, 16, 5); // speed = 5
|
|
5961
|
+
*/
|
|
5962
|
+
|
|
4758
5963
|
}, {
|
|
4759
5964
|
key: "animate",
|
|
4760
5965
|
value: function animate() {
|
|
5966
|
+
// 只有 jmGraph 实例才真正处理动画调度
|
|
4761
5967
|
if (this.is('jmGraph')) {
|
|
5968
|
+
// 注册新的动画句柄
|
|
4762
5969
|
if (arguments.length > 1) {
|
|
4763
|
-
if (!this.animateHandles) this.animateHandles = new _jmList.jmList();
|
|
5970
|
+
if (!this.animateHandles) this.animateHandles = new _jmList.jmList(); // 收集额外参数
|
|
5971
|
+
|
|
4764
5972
|
var params = [];
|
|
4765
5973
|
|
|
4766
5974
|
if (arguments.length > 2) {
|
|
4767
5975
|
for (var i = 2; i < arguments.length; i++) {
|
|
4768
5976
|
params.push(i < 0 || arguments.length <= i ? undefined : arguments[i]);
|
|
4769
5977
|
}
|
|
4770
|
-
}
|
|
5978
|
+
} // 添加动画句柄到列表
|
|
5979
|
+
|
|
4771
5980
|
|
|
4772
5981
|
this.animateHandles.add({
|
|
4773
5982
|
millisec: (arguments.length <= 1 ? undefined : arguments[1]) || 20,
|
|
5983
|
+
// 执行间隔
|
|
4774
5984
|
handle: arguments.length <= 0 ? undefined : arguments[0],
|
|
4775
|
-
|
|
5985
|
+
// 回调函数
|
|
5986
|
+
params: params // 额外参数
|
|
5987
|
+
|
|
4776
5988
|
});
|
|
4777
|
-
}
|
|
5989
|
+
} // 如果有动画句柄,启动调度循环
|
|
5990
|
+
|
|
4778
5991
|
|
|
4779
5992
|
if (this.animateHandles) {
|
|
4780
5993
|
if (this.animateHandles.count() > 0) {
|
|
4781
|
-
var self = this;
|
|
5994
|
+
var self = this; // 使用 setTimeout 进行调度(避免 requestAnimationFrame 的固定帧率限制)
|
|
5995
|
+
|
|
4782
5996
|
this.dispatcher = setTimeout(function (_this) {
|
|
4783
5997
|
_this = _this || self;
|
|
4784
|
-
var overduehandles = [];
|
|
4785
|
-
|
|
5998
|
+
var overduehandles = []; // 需要移除的句柄
|
|
5999
|
+
|
|
6000
|
+
var curTimes = Date.now(); // 遍历执行所有动画句柄
|
|
4786
6001
|
|
|
4787
6002
|
_this.animateHandles.each(function (i, ani) {
|
|
4788
6003
|
try {
|
|
6004
|
+
// 检查是否到达执行时间
|
|
4789
6005
|
if (ani && ani.handle && (!ani.times || curTimes - ani.times >= ani.millisec)) {
|
|
4790
|
-
|
|
6006
|
+
// 执行回调
|
|
6007
|
+
var r = ani.handle.apply(_this, ani.params); // 返回 false 表示动画结束
|
|
4791
6008
|
|
|
4792
6009
|
if (r === false) {
|
|
4793
6010
|
overduehandles.push(ani);
|
|
4794
|
-
}
|
|
6011
|
+
} // 更新最后执行时间
|
|
6012
|
+
|
|
4795
6013
|
|
|
4796
6014
|
ani.times = curTimes;
|
|
4797
6015
|
}
|
|
4798
6016
|
} catch (e) {
|
|
6017
|
+
// 出错的句柄自动移除
|
|
4799
6018
|
if (ani) overduehandles.push(ani);
|
|
4800
6019
|
}
|
|
4801
|
-
});
|
|
6020
|
+
}); // 移除已完成的动画句柄
|
|
6021
|
+
|
|
4802
6022
|
|
|
4803
6023
|
for (var _i in overduehandles) {
|
|
4804
6024
|
_this.animateHandles.remove(overduehandles[_i]);
|
|
4805
|
-
}
|
|
6025
|
+
} // 继续下一轮调度
|
|
6026
|
+
|
|
4806
6027
|
|
|
4807
6028
|
_this.animate();
|
|
4808
6029
|
}, 10, this);
|
|
4809
6030
|
}
|
|
4810
6031
|
}
|
|
4811
6032
|
} else {
|
|
6033
|
+
// 非 jmGraph 对象委托给所属的 graph 处理
|
|
4812
6034
|
var graph = this.graph;
|
|
4813
6035
|
|
|
4814
6036
|
if (graph) {
|
|
@@ -4856,12 +6078,33 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
4856
6078
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4857
6079
|
|
|
4858
6080
|
/**
|
|
4859
|
-
*
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
6081
|
+
* 基础路径类
|
|
6082
|
+
*
|
|
6083
|
+
* 大部分图形的基类,通过指定一系列点来画出图形。
|
|
6084
|
+
* 支持开放路径和闭合路径,支持 SVG 导出。
|
|
6085
|
+
*
|
|
4862
6086
|
* @class jmPath
|
|
4863
6087
|
* @extends jmControl
|
|
4864
|
-
*
|
|
6088
|
+
*
|
|
6089
|
+
* @param {Object} params 路径参数
|
|
6090
|
+
* @param {Array<Object>} [params.points] 点序列,每个点格式:{x:0, y:0, m:false}
|
|
6091
|
+
* @param {string} [t='jmPath'] 类型标识
|
|
6092
|
+
*
|
|
6093
|
+
* @example
|
|
6094
|
+
* // 创建自定义路径
|
|
6095
|
+
* const path = new jmPath({
|
|
6096
|
+
* points: [
|
|
6097
|
+
* {x: 0, y: 0},
|
|
6098
|
+
* {x: 100, y: 0},
|
|
6099
|
+
* {x: 100, y: 100},
|
|
6100
|
+
* {x: 0, y: 100}
|
|
6101
|
+
* ],
|
|
6102
|
+
* style: {
|
|
6103
|
+
* fill: '#ff0000',
|
|
6104
|
+
* stroke: '#000000',
|
|
6105
|
+
* close: true // 闭合路径
|
|
6106
|
+
* }
|
|
6107
|
+
* });
|
|
4865
6108
|
*/
|
|
4866
6109
|
var jmPath = /*#__PURE__*/function (_jmControl) {
|
|
4867
6110
|
_inherits(jmPath, _jmControl);
|
|
@@ -4995,23 +6238,94 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
4995
6238
|
|
|
4996
6239
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
4997
6240
|
|
|
6241
|
+
/**
|
|
6242
|
+
* 属性存储的 Symbol 键
|
|
6243
|
+
* 使用 Symbol 确保属性存储的私有性和唯一性
|
|
6244
|
+
* @type {Symbol}
|
|
6245
|
+
* @private
|
|
6246
|
+
*/
|
|
4998
6247
|
var PROPERTY_KEY = Symbol("properties");
|
|
6248
|
+
/**
|
|
6249
|
+
* jmGraph 属性管理基类
|
|
6250
|
+
*
|
|
6251
|
+
* jmProperty 是 jmControl 的父类,为所有图形控件提供属性管理功能。
|
|
6252
|
+
* 采用 Symbol + WeakMap 模式实现真正的私有属性存储,避免属性名冲突。
|
|
6253
|
+
*
|
|
6254
|
+
* 核心特性:
|
|
6255
|
+
* 1. **私有属性存储**:使用 Symbol 键确保属性不被外部直接访问
|
|
6256
|
+
* 2. **属性变更通知**:设置属性时自动触发 'propertyChange' 事件
|
|
6257
|
+
* 3. **渲染模式继承**:子控件自动继承所属 graph 的渲染模式
|
|
6258
|
+
* 4. **脏标记传播**:子控件 needUpdate 会自动传播到 graph
|
|
6259
|
+
*
|
|
6260
|
+
* @class jmProperty
|
|
6261
|
+
* @extends jmObject
|
|
6262
|
+
*
|
|
6263
|
+
* @example
|
|
6264
|
+
* // 创建属性对象
|
|
6265
|
+
* const prop = new jmProperty({ mode: 'webgl' });
|
|
6266
|
+
*
|
|
6267
|
+
* // 设置和获取属性
|
|
6268
|
+
* prop.property('customValue', 100);
|
|
6269
|
+
* console.log(prop.property('customValue')); // 100
|
|
6270
|
+
*
|
|
6271
|
+
* // 监听属性变更
|
|
6272
|
+
* prop.on('propertyChange', (name, args) => {
|
|
6273
|
+
* console.log(`${name} changed from ${args.oldValue} to ${args.newValue}`);
|
|
6274
|
+
* });
|
|
6275
|
+
*/
|
|
4999
6276
|
|
|
5000
6277
|
var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
5001
6278
|
_inherits(jmProperty, _jmObject);
|
|
5002
6279
|
|
|
5003
6280
|
var _super = _createSuper(jmProperty);
|
|
5004
6281
|
|
|
6282
|
+
/**
|
|
6283
|
+
* 构造函数
|
|
6284
|
+
*
|
|
6285
|
+
* 初始化属性存储对象,并设置初始渲染模式。
|
|
6286
|
+
*
|
|
6287
|
+
* @constructor
|
|
6288
|
+
* @param {Object} [params] - 初始化参数
|
|
6289
|
+
* @param {'2d'|'webgl'} [params.mode] - 渲染模式,默认 '2d'
|
|
6290
|
+
*
|
|
6291
|
+
* @example
|
|
6292
|
+
* // 创建使用 WebGL 渲染的属性对象
|
|
6293
|
+
* const prop = new jmProperty({ mode: 'webgl' });
|
|
6294
|
+
*/
|
|
5005
6295
|
function jmProperty(params) {
|
|
5006
6296
|
var _this;
|
|
5007
6297
|
|
|
5008
6298
|
_classCallCheck(this, jmProperty);
|
|
5009
6299
|
|
|
5010
|
-
_this = _super.call(this);
|
|
5011
|
-
|
|
6300
|
+
_this = _super.call(this); // 初始化私有属性存储对象
|
|
6301
|
+
|
|
6302
|
+
_this[PROPERTY_KEY] = {}; // 设置渲染模式
|
|
6303
|
+
|
|
5012
6304
|
if (params && params.mode) _this.mode = params.mode;
|
|
5013
6305
|
return _this;
|
|
5014
6306
|
}
|
|
6307
|
+
/**
|
|
6308
|
+
* 获取或设置属性值
|
|
6309
|
+
*
|
|
6310
|
+
* 这是属性系统的核心方法,所有属性的存取都通过此方法。
|
|
6311
|
+
* 设置属性时会自动触发 'propertyChange' 事件,便于实现响应式更新。
|
|
6312
|
+
*
|
|
6313
|
+
* @method property
|
|
6314
|
+
* @param {string} name - 属性名称
|
|
6315
|
+
* @param {*} [value] - 属性值(设置时提供)
|
|
6316
|
+
* @returns {*} 获取时返回属性值,设置时返回设置的值
|
|
6317
|
+
*
|
|
6318
|
+
* @example
|
|
6319
|
+
* // 获取属性
|
|
6320
|
+
* const value = obj.property('myProp');
|
|
6321
|
+
*
|
|
6322
|
+
* // 设置属性
|
|
6323
|
+
* obj.property('myProp', 'newValue');
|
|
6324
|
+
*
|
|
6325
|
+
* // 链式调用
|
|
6326
|
+
* obj.property('a', 1).property('b', 2);
|
|
6327
|
+
*/
|
|
6328
|
+
|
|
5015
6329
|
|
|
5016
6330
|
_createClass(jmProperty, [{
|
|
5017
6331
|
key: "property",
|
|
@@ -5022,7 +6336,7 @@ var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
|
5022
6336
|
|
|
5023
6337
|
if (pars) {
|
|
5024
6338
|
var pros = this[PROPERTY_KEY];
|
|
5025
|
-
var name = pars[0];
|
|
6339
|
+
var name = pars[0]; // 设置属性
|
|
5026
6340
|
|
|
5027
6341
|
if (pars.length > 1) {
|
|
5028
6342
|
var value = pars[1];
|
|
@@ -5030,51 +6344,149 @@ var jmProperty = /*#__PURE__*/function (_jmObject) {
|
|
|
5030
6344
|
oldValue: pros[name],
|
|
5031
6345
|
newValue: value
|
|
5032
6346
|
};
|
|
5033
|
-
pros[name] = pars[1];
|
|
6347
|
+
pros[name] = pars[1]; // 触发属性变更事件(如果对象支持事件)
|
|
6348
|
+
|
|
5034
6349
|
if (this.emit) this.emit('propertyChange', name, args);
|
|
5035
6350
|
return pars[1];
|
|
5036
|
-
}
|
|
6351
|
+
} // 获取属性
|
|
6352
|
+
else if (name) {
|
|
5037
6353
|
return pros[name];
|
|
5038
6354
|
}
|
|
5039
6355
|
}
|
|
5040
6356
|
}
|
|
6357
|
+
/**
|
|
6358
|
+
* 是否需要重绘标记
|
|
6359
|
+
*
|
|
6360
|
+
* 当属性变化导致需要重新渲染时设置此标记。
|
|
6361
|
+
* 设置为 true 时,会自动将所属 graph 的 needUpdate 设为 true,
|
|
6362
|
+
* 从而触发画布重绘。
|
|
6363
|
+
*
|
|
6364
|
+
* @type {boolean}
|
|
6365
|
+
*
|
|
6366
|
+
* @example
|
|
6367
|
+
* // 标记需要重绘
|
|
6368
|
+
* control.needUpdate = true;
|
|
6369
|
+
*
|
|
6370
|
+
* // 检查是否需要重绘
|
|
6371
|
+
* if(control.needUpdate) {
|
|
6372
|
+
* control.redraw();
|
|
6373
|
+
* }
|
|
6374
|
+
*/
|
|
6375
|
+
|
|
5041
6376
|
}, {
|
|
5042
6377
|
key: "needUpdate",
|
|
5043
6378
|
get: function get() {
|
|
5044
6379
|
return this.property('needUpdate');
|
|
5045
6380
|
},
|
|
5046
6381
|
set: function set(v) {
|
|
5047
|
-
this.property('needUpdate', v);
|
|
6382
|
+
this.property('needUpdate', v); // 传播脏标记到 graph(避免 jmGraph 自身循环)
|
|
5048
6383
|
|
|
5049
6384
|
if (v && !this.is('jmGraph') && this.graph) {
|
|
5050
6385
|
this.graph.needUpdate = true;
|
|
5051
6386
|
}
|
|
5052
6387
|
}
|
|
6388
|
+
/**
|
|
6389
|
+
* 所属的画布实例
|
|
6390
|
+
*
|
|
6391
|
+
* 获取或设置当前对象所属的 jmGraph 实例。
|
|
6392
|
+
* 如果未显式设置,会自动向上查找父级链中的 jmGraph。
|
|
6393
|
+
*
|
|
6394
|
+
* @type {jmGraph}
|
|
6395
|
+
*
|
|
6396
|
+
* @example
|
|
6397
|
+
* // 获取所属画布
|
|
6398
|
+
* const graph = control.graph;
|
|
6399
|
+
*
|
|
6400
|
+
* // 设置所属画布(通常由框架内部调用)
|
|
6401
|
+
* control.graph = myGraph;
|
|
6402
|
+
*/
|
|
6403
|
+
|
|
5053
6404
|
}, {
|
|
5054
6405
|
key: "graph",
|
|
5055
6406
|
get: function get() {
|
|
5056
|
-
var g = this.property('graph');
|
|
6407
|
+
var g = this.property('graph'); // 如果未设置,尝试从父级链查找
|
|
6408
|
+
|
|
5057
6409
|
g = g || this.property('graph', this.findParent('jmGraph'));
|
|
5058
6410
|
return g;
|
|
5059
6411
|
},
|
|
5060
6412
|
set: function set(v) {
|
|
5061
6413
|
return this.property('graph', v);
|
|
5062
6414
|
}
|
|
6415
|
+
/**
|
|
6416
|
+
* 渲染模式
|
|
6417
|
+
*
|
|
6418
|
+
* 获取当前渲染模式,支持 '2d' 和 'webgl' 两种模式。
|
|
6419
|
+
* 渲染模式的查找优先级:
|
|
6420
|
+
* 1. 当前对象设置的 mode
|
|
6421
|
+
* 2. 如果是 jmGraph,默认 '2d'
|
|
6422
|
+
* 3. 从所属 graph 继承 mode
|
|
6423
|
+
*
|
|
6424
|
+
* @type {'2d'|'webgl'}
|
|
6425
|
+
* @readonly
|
|
6426
|
+
*
|
|
6427
|
+
* @example
|
|
6428
|
+
* // 检查渲染模式
|
|
6429
|
+
* if(control.mode === 'webgl') {
|
|
6430
|
+
* // 使用 WebGL 特性
|
|
6431
|
+
* } else {
|
|
6432
|
+
* // 使用 Canvas 2D API
|
|
6433
|
+
* }
|
|
6434
|
+
*/
|
|
6435
|
+
|
|
5063
6436
|
}, {
|
|
5064
6437
|
key: "mode",
|
|
5065
6438
|
get: function get() {
|
|
6439
|
+
var _this$graph;
|
|
6440
|
+
|
|
5066
6441
|
var m = this.property('mode');
|
|
5067
|
-
if (m) return m;
|
|
5068
|
-
|
|
6442
|
+
if (m) return m; // 如果当前对象是jmGraph且没有设置mode,返回默认值
|
|
6443
|
+
|
|
6444
|
+
if (this.is('jmGraph')) return this.property('mode') || '2d'; // 否则从所属的graph获取mode
|
|
6445
|
+
|
|
6446
|
+
return ((_this$graph = this.graph) === null || _this$graph === void 0 ? void 0 : _this$graph.mode) || '2d';
|
|
5069
6447
|
},
|
|
5070
6448
|
set: function set(v) {
|
|
5071
6449
|
return this.property('mode', v);
|
|
5072
6450
|
}
|
|
6451
|
+
/**
|
|
6452
|
+
* 请求动画帧
|
|
6453
|
+
*
|
|
6454
|
+
* 封装 requestAnimationFrame,支持在不同环境下工作。
|
|
6455
|
+
* 如果当前对象关联了 canvas,会使用 canvas 的 requestAnimationFrame。
|
|
6456
|
+
*
|
|
6457
|
+
* @method requestAnimationFrame
|
|
6458
|
+
* @param {Function} handler - 动画帧回调函数
|
|
6459
|
+
* @returns {number} 动画帧请求ID,用于取消
|
|
6460
|
+
*
|
|
6461
|
+
* @example
|
|
6462
|
+
* // 请求下一帧动画
|
|
6463
|
+
* const frameId = control.requestAnimationFrame(() => {
|
|
6464
|
+
* // 更新动画状态
|
|
6465
|
+
* control.redraw();
|
|
6466
|
+
* });
|
|
6467
|
+
*
|
|
6468
|
+
* // 取消动画帧
|
|
6469
|
+
* control.cancelAnimationFrame(frameId);
|
|
6470
|
+
*/
|
|
6471
|
+
|
|
5073
6472
|
}, {
|
|
5074
6473
|
key: "requestAnimationFrame",
|
|
5075
6474
|
value: function requestAnimationFrame(handler) {
|
|
5076
6475
|
return _jmUtils.jmUtils.requestAnimationFrame(handler, this.graph ? this.graph.canvas : null);
|
|
5077
6476
|
}
|
|
6477
|
+
/**
|
|
6478
|
+
* 取消动画帧请求
|
|
6479
|
+
*
|
|
6480
|
+
* 取消之前通过 requestAnimationFrame 注册的回调。
|
|
6481
|
+
*
|
|
6482
|
+
* @method cancelAnimationFrame
|
|
6483
|
+
* @param {number} handler - 动画帧请求ID
|
|
6484
|
+
*
|
|
6485
|
+
* @example
|
|
6486
|
+
* // 取消动画帧
|
|
6487
|
+
* control.cancelAnimationFrame(frameId);
|
|
6488
|
+
*/
|
|
6489
|
+
|
|
5078
6490
|
}, {
|
|
5079
6491
|
key: "cancelAnimationFrame",
|
|
5080
6492
|
value: function cancelAnimationFrame(handler) {
|
|
@@ -5104,13 +6516,26 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5104
6516
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5105
6517
|
|
|
5106
6518
|
/**
|
|
5107
|
-
*
|
|
5108
|
-
*
|
|
6519
|
+
* 阴影类
|
|
6520
|
+
*
|
|
6521
|
+
* 用于创建图形的阴影效果。阴影可以应用于任何图形控件。
|
|
6522
|
+
*
|
|
5109
6523
|
* @class jmShadow
|
|
5110
|
-
*
|
|
5111
|
-
* @param {number} y
|
|
5112
|
-
* @param {number}
|
|
5113
|
-
* @param {
|
|
6524
|
+
*
|
|
6525
|
+
* @param {number|string} x 横坐标偏移量,或阴影字符串格式 'x,y,blur,color'
|
|
6526
|
+
* @param {number} [y] 纵坐标偏移量
|
|
6527
|
+
* @param {number} [blur] 模糊值
|
|
6528
|
+
* @param {string} [color] 阴影颜色
|
|
6529
|
+
*
|
|
6530
|
+
* @example
|
|
6531
|
+
* // 创建阴影
|
|
6532
|
+
* const shadow = new jmShadow(5, 5, 10, 'rgba(0,0,0,0.5)');
|
|
6533
|
+
*
|
|
6534
|
+
* // 从字符串创建
|
|
6535
|
+
* const shadow = new jmShadow('5, 5, 10, rgba(0,0,0,0.5)');
|
|
6536
|
+
*
|
|
6537
|
+
* // 应用到图形
|
|
6538
|
+
* rect.style.shadow = shadow;
|
|
5114
6539
|
*/
|
|
5115
6540
|
var jmShadow = /*#__PURE__*/function () {
|
|
5116
6541
|
function jmShadow(x, y, blur, color) {
|
|
@@ -5204,6 +6629,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
5204
6629
|
|
|
5205
6630
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5206
6631
|
|
|
6632
|
+
/**
|
|
6633
|
+
* CSS 颜色关键字映射表
|
|
6634
|
+
*
|
|
6635
|
+
* 包含所有 CSS 标准颜色名称到十六进制值的映射。
|
|
6636
|
+
* 支持 147 种命名颜色 + CSS 系统颜色。
|
|
6637
|
+
*
|
|
6638
|
+
* @constant {Object.<string, string>}
|
|
6639
|
+
* @private
|
|
6640
|
+
*/
|
|
5207
6641
|
var colorKeywords = {
|
|
5208
6642
|
aliceblue: "#f0f8ff",
|
|
5209
6643
|
antiquewhite: "#faebd7",
|
|
@@ -5384,11 +6818,22 @@ var colorKeywords = {
|
|
|
5384
6818
|
windowtext: "#000000"
|
|
5385
6819
|
};
|
|
5386
6820
|
/**
|
|
5387
|
-
*
|
|
5388
|
-
*
|
|
6821
|
+
* jmGraph 工具类
|
|
6822
|
+
*
|
|
6823
|
+
* 提供常用的静态工具方法,包括对象操作、事件处理、几何计算、颜色转换等。
|
|
5389
6824
|
*
|
|
5390
6825
|
* @class jmUtils
|
|
5391
6826
|
* @static
|
|
6827
|
+
*
|
|
6828
|
+
* @example
|
|
6829
|
+
* // 克隆对象
|
|
6830
|
+
* const newObj = jmUtils.clone({ a: 1, b: 2 });
|
|
6831
|
+
*
|
|
6832
|
+
* // 绑定事件
|
|
6833
|
+
* jmUtils.bindEvent(element, 'click', handler);
|
|
6834
|
+
*
|
|
6835
|
+
* // 检查点是否在多边形内
|
|
6836
|
+
* const inside = jmUtils.pointInPolygon({x: 10, y: 10}, polygonPoints);
|
|
5392
6837
|
*/
|
|
5393
6838
|
|
|
5394
6839
|
exports.colorKeywords = colorKeywords;
|
|
@@ -5582,7 +7027,7 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5582
7027
|
}
|
|
5583
7028
|
} else if (el.x) {
|
|
5584
7029
|
pos.left += el.x;
|
|
5585
|
-
} else if (el.
|
|
7030
|
+
} else if (el.y) {
|
|
5586
7031
|
pos.top += el.y;
|
|
5587
7032
|
}
|
|
5588
7033
|
|
|
@@ -5717,6 +7162,31 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5717
7162
|
|
|
5718
7163
|
return this.rayCasting(pt, polygon, offset);
|
|
5719
7164
|
}
|
|
7165
|
+
/**
|
|
7166
|
+
* 判断点是否在线段上
|
|
7167
|
+
*
|
|
7168
|
+
* 通过计算点到线段的垂直距离来判断点是否在线段上。
|
|
7169
|
+
* 同时检查点是否在线段的范围内(不仅仅是直线上)。
|
|
7170
|
+
*
|
|
7171
|
+
* @method pointOnLine
|
|
7172
|
+
* @static
|
|
7173
|
+
* @private
|
|
7174
|
+
* @param {Object} pt 待检测的点 {x, y}
|
|
7175
|
+
* @param {Object} p1 线段起点 {x, y}
|
|
7176
|
+
* @param {Object} p2 线段终点 {x, y}
|
|
7177
|
+
* @param {number} offset 允许的偏差值(像素)
|
|
7178
|
+
* @returns {number} 0=不在线段上, 1=在线段上
|
|
7179
|
+
*
|
|
7180
|
+
* @example
|
|
7181
|
+
* const onLine = jmUtils.pointOnLine(
|
|
7182
|
+
* {x: 5, y: 5}, // 待检测点
|
|
7183
|
+
* {x: 0, y: 0}, // 起点
|
|
7184
|
+
* {x: 10, y: 10}, // 终点
|
|
7185
|
+
* 2 // 允许偏差
|
|
7186
|
+
* );
|
|
7187
|
+
* // 返回 1,点在对角线上
|
|
7188
|
+
*/
|
|
7189
|
+
|
|
5720
7190
|
}, {
|
|
5721
7191
|
key: "pointOnLine",
|
|
5722
7192
|
value: function pointOnLine(pt, p1, p2, offset) {
|
|
@@ -5758,6 +7228,26 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
5758
7228
|
|
|
5759
7229
|
return 0;
|
|
5760
7230
|
}
|
|
7231
|
+
/**
|
|
7232
|
+
* 射线法判断点是否在多边形内部
|
|
7233
|
+
*
|
|
7234
|
+
* 从待测点向右发射一条水平射线,计算与多边形边界的交点数量。
|
|
7235
|
+
* - 交点数为奇数:点在多边形内部
|
|
7236
|
+
* - 交点数为偶数:点在多边形外部
|
|
7237
|
+
*
|
|
7238
|
+
* 这是判断点是否在任意多边形内的经典算法,时间复杂度 O(n)。
|
|
7239
|
+
*
|
|
7240
|
+
* @method rayCasting
|
|
7241
|
+
* @static
|
|
7242
|
+
* @private
|
|
7243
|
+
* @param {Object} pt 待检测的点 {x, y}
|
|
7244
|
+
* @param {Array<Object>} polygon 多边形顶点数组 [{x, y}, ...]
|
|
7245
|
+
* @param {number} offset 允许的偏差值(未使用)
|
|
7246
|
+
* @returns {number} 0=在多边形外部, 2=在多边形内部
|
|
7247
|
+
*
|
|
7248
|
+
* @see {@link https://en.wikipedia.org/wiki/Point_in_polygon Point in polygon - Wikipedia}
|
|
7249
|
+
*/
|
|
7250
|
+
|
|
5761
7251
|
}, {
|
|
5762
7252
|
key: "rayCasting",
|
|
5763
7253
|
value: function rayCasting(pt, polygon, offset) {
|
|
@@ -6166,8 +7656,19 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6166
7656
|
return this.__hexToRGBA_Cache[hex] = res;
|
|
6167
7657
|
}
|
|
6168
7658
|
/**
|
|
6169
|
-
*
|
|
6170
|
-
*
|
|
7659
|
+
* 将 RGB 颜色值从 0-255 范围转换为 0-1 范围
|
|
7660
|
+
*
|
|
7661
|
+
* WebGL 中的颜色值通常使用 0-1 的浮点数表示,
|
|
7662
|
+
* 此方法用于将标准 RGB 值转换为 WebGL 兼容格式。
|
|
7663
|
+
*
|
|
7664
|
+
* @method rgbToDecimal
|
|
7665
|
+
* @static
|
|
7666
|
+
* @param {Object} color 颜色对象 {r, g, b, a?}
|
|
7667
|
+
* @returns {Object} 转换后的颜色对象 {r, g, b, a?},其中 r/g/b 为 0-1 范围
|
|
7668
|
+
*
|
|
7669
|
+
* @example
|
|
7670
|
+
* const color = jmUtils.rgbToDecimal({ r: 255, g: 128, b: 64 });
|
|
7671
|
+
* // 返回 { r: 1, g: 0.502, b: 0.251 }
|
|
6171
7672
|
*/
|
|
6172
7673
|
|
|
6173
7674
|
}, {
|
|
@@ -6178,7 +7679,16 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6178
7679
|
color.g = this.byteToDecimal(color.g);
|
|
6179
7680
|
color.b = this.byteToDecimal(color.b);
|
|
6180
7681
|
return color;
|
|
6181
|
-
}
|
|
7682
|
+
}
|
|
7683
|
+
/**
|
|
7684
|
+
* 将字节值(0-255)转换为小数(0-1)
|
|
7685
|
+
*
|
|
7686
|
+
* @method byteToDecimal
|
|
7687
|
+
* @static
|
|
7688
|
+
* @private
|
|
7689
|
+
* @param {number} b 字节值(0-255)
|
|
7690
|
+
* @returns {number} 小数值(0-1)
|
|
7691
|
+
*/
|
|
6182
7692
|
|
|
6183
7693
|
}, {
|
|
6184
7694
|
key: "byteToDecimal",
|
|
@@ -6225,7 +7735,30 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6225
7735
|
}
|
|
6226
7736
|
|
|
6227
7737
|
return r;
|
|
6228
|
-
}
|
|
7738
|
+
}
|
|
7739
|
+
/**
|
|
7740
|
+
* 请求动画帧
|
|
7741
|
+
*
|
|
7742
|
+
* 封装浏览器原生的 requestAnimationFrame 方法,提供跨浏览器兼容性。
|
|
7743
|
+
* 在不支持 requestAnimationFrame 的环境中降级为 setTimeout。
|
|
7744
|
+
*
|
|
7745
|
+
* @method requestAnimationFrame
|
|
7746
|
+
* @static
|
|
7747
|
+
* @param {Function} callback 动画帧回调函数,接收时间戳参数
|
|
7748
|
+
* @param {Window} [win] 可选的窗口对象(用于多窗口环境)
|
|
7749
|
+
* @returns {number} 动画帧请求ID,用于取消
|
|
7750
|
+
*
|
|
7751
|
+
* @example
|
|
7752
|
+
* let animationId;
|
|
7753
|
+
* function animate(timestamp) {
|
|
7754
|
+
* // 更新动画
|
|
7755
|
+
* animationId = jmUtils.requestAnimationFrame(animate);
|
|
7756
|
+
* }
|
|
7757
|
+
* animationId = jmUtils.requestAnimationFrame(animate);
|
|
7758
|
+
*
|
|
7759
|
+
* // 取消动画
|
|
7760
|
+
* jmUtils.cancelAnimationFrame(animationId);
|
|
7761
|
+
*/
|
|
6229
7762
|
|
|
6230
7763
|
}, {
|
|
6231
7764
|
key: "requestAnimationFrame",
|
|
@@ -6233,6 +7766,22 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
6233
7766
|
var fun = win && win.requestAnimationFrame ? win.requestAnimationFrame : typeof window !== 'undefined' && window.requestAnimationFrame ? window.requestAnimationFrame : setTimeout;
|
|
6234
7767
|
return fun(callback, 20);
|
|
6235
7768
|
}
|
|
7769
|
+
/**
|
|
7770
|
+
* 取消动画帧请求
|
|
7771
|
+
*
|
|
7772
|
+
* 取消之前通过 requestAnimationFrame 注册的回调。
|
|
7773
|
+
* 在不支持 cancelAnimationFrame 的环境中降级为 clearTimeout。
|
|
7774
|
+
*
|
|
7775
|
+
* @method cancelAnimationFrame
|
|
7776
|
+
* @static
|
|
7777
|
+
* @param {number} handler requestAnimationFrame 返回的请求ID
|
|
7778
|
+
* @param {Window} [win] 可选的窗口对象(用于多窗口环境)
|
|
7779
|
+
*
|
|
7780
|
+
* @example
|
|
7781
|
+
* const animationId = jmUtils.requestAnimationFrame(animate);
|
|
7782
|
+
* jmUtils.cancelAnimationFrame(animationId);
|
|
7783
|
+
*/
|
|
7784
|
+
|
|
6236
7785
|
}, {
|
|
6237
7786
|
key: "cancelAnimationFrame",
|
|
6238
7787
|
value: function cancelAnimationFrame(handler, win) {
|
|
@@ -6982,9 +8531,24 @@ var pathVertexSource = "\n attribute vec4 a_position;\n attribute vec4 a_c
|
|
|
6982
8531
|
|
|
6983
8532
|
exports.pathVertexSource = pathVertexSource;
|
|
6984
8533
|
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");
|
|
8534
|
+
/**
|
|
8535
|
+
* WebGL 基础渲染类
|
|
8536
|
+
* 提供 WebGL 渲染的核心功能,包括着色器、缓冲区、纹理管理等
|
|
8537
|
+
*
|
|
8538
|
+
* @class WeblBase
|
|
8539
|
+
* @example
|
|
8540
|
+
* const base = new WeblBase(graph, { mode: 'webgl' });
|
|
8541
|
+
* base.setStyle({ fillStyle: '#ff0000' });
|
|
8542
|
+
*/
|
|
8543
|
+
|
|
6985
8544
|
exports.pathFragmentSource = pathFragmentSource;
|
|
6986
8545
|
|
|
6987
8546
|
var WeblBase = /*#__PURE__*/function () {
|
|
8547
|
+
/**
|
|
8548
|
+
* 构造函数
|
|
8549
|
+
* @param {jmGraph} graph jmGraph 实例
|
|
8550
|
+
* @param {Object} option 配置选项
|
|
8551
|
+
*/
|
|
6988
8552
|
function WeblBase(graph, option) {
|
|
6989
8553
|
_classCallCheck(this, WeblBase);
|
|
6990
8554
|
|
|
@@ -6994,14 +8558,19 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
6994
8558
|
globalAlpha: 1
|
|
6995
8559
|
};
|
|
6996
8560
|
this.stateStack = [];
|
|
6997
|
-
|
|
8561
|
+
/** @type {number[]} 2D 变换矩阵 [a, b, c, d, tx, ty] */
|
|
8562
|
+
|
|
8563
|
+
this.transformMatrix = [1, 0, 0, 1, 0, 0];
|
|
6998
8564
|
}
|
|
8565
|
+
/** @returns {WebGLRenderingContext} WebGL 渲染上下文 */
|
|
8566
|
+
|
|
6999
8567
|
|
|
7000
8568
|
_createClass(WeblBase, [{
|
|
7001
8569
|
key: "context",
|
|
7002
8570
|
get: function get() {
|
|
7003
8571
|
if (this.graph) return this.graph.context;
|
|
7004
|
-
}
|
|
8572
|
+
}
|
|
8573
|
+
/** 保存当前状态到状态栈 */
|
|
7005
8574
|
|
|
7006
8575
|
}, {
|
|
7007
8576
|
key: "save",
|
|
@@ -7010,7 +8579,8 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7010
8579
|
transformMatrix: _toConsumableArray(this.transformMatrix),
|
|
7011
8580
|
style: _objectSpread({}, this.style)
|
|
7012
8581
|
});
|
|
7013
|
-
}
|
|
8582
|
+
}
|
|
8583
|
+
/** 从状态栈恢复上一个状态 */
|
|
7014
8584
|
|
|
7015
8585
|
}, {
|
|
7016
8586
|
key: "restore",
|
|
@@ -7020,25 +8590,37 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7020
8590
|
this.transformMatrix = state.transformMatrix;
|
|
7021
8591
|
this.style = state.style;
|
|
7022
8592
|
}
|
|
7023
|
-
}
|
|
8593
|
+
}
|
|
8594
|
+
/**
|
|
8595
|
+
* 平移变换
|
|
8596
|
+
* @param {number} x X 轴平移量
|
|
8597
|
+
* @param {number} y Y 轴平移量
|
|
8598
|
+
*/
|
|
7024
8599
|
|
|
7025
8600
|
}, {
|
|
7026
8601
|
key: "translate",
|
|
7027
8602
|
value: function translate(x, y) {
|
|
7028
|
-
// 更新变换矩阵
|
|
7029
8603
|
this.transformMatrix[4] += x * this.transformMatrix[0] + y * this.transformMatrix[2];
|
|
7030
8604
|
this.transformMatrix[5] += x * this.transformMatrix[1] + y * this.transformMatrix[3];
|
|
7031
|
-
}
|
|
8605
|
+
}
|
|
8606
|
+
/**
|
|
8607
|
+
* 缩放变换
|
|
8608
|
+
* @param {number} sx X 轴缩放比例
|
|
8609
|
+
* @param {number} sy Y 轴缩放比例
|
|
8610
|
+
*/
|
|
7032
8611
|
|
|
7033
8612
|
}, {
|
|
7034
8613
|
key: "scale",
|
|
7035
8614
|
value: function scale(sx, sy) {
|
|
7036
|
-
// 更新变换矩阵
|
|
7037
8615
|
this.transformMatrix[0] *= sx;
|
|
7038
8616
|
this.transformMatrix[1] *= sx;
|
|
7039
8617
|
this.transformMatrix[2] *= sy;
|
|
7040
8618
|
this.transformMatrix[3] *= sy;
|
|
7041
|
-
}
|
|
8619
|
+
}
|
|
8620
|
+
/**
|
|
8621
|
+
* 旋转变换
|
|
8622
|
+
* @param {number} angle 旋转角度(弧度)
|
|
8623
|
+
*/
|
|
7042
8624
|
|
|
7043
8625
|
}, {
|
|
7044
8626
|
key: "rotate",
|
|
@@ -7050,14 +8632,22 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7050
8632
|
a = _this$transformMatrix[0],
|
|
7051
8633
|
b = _this$transformMatrix[1],
|
|
7052
8634
|
c = _this$transformMatrix[2],
|
|
7053
|
-
d = _this$transformMatrix[3];
|
|
7054
|
-
|
|
8635
|
+
d = _this$transformMatrix[3];
|
|
7055
8636
|
|
|
7056
8637
|
this.transformMatrix[0] = a * cos - b * sin;
|
|
7057
8638
|
this.transformMatrix[1] = a * sin + b * cos;
|
|
7058
8639
|
this.transformMatrix[2] = c * cos - d * sin;
|
|
7059
8640
|
this.transformMatrix[3] = c * sin + d * cos;
|
|
7060
|
-
}
|
|
8641
|
+
}
|
|
8642
|
+
/**
|
|
8643
|
+
* 矩阵变换
|
|
8644
|
+
* @param {number} a 水平缩放
|
|
8645
|
+
* @param {number} b 垂直倾斜
|
|
8646
|
+
* @param {number} c 水平倾斜
|
|
8647
|
+
* @param {number} d 垂直缩放
|
|
8648
|
+
* @param {number} e 水平移动
|
|
8649
|
+
* @param {number} f 垂直移动
|
|
8650
|
+
*/
|
|
7061
8651
|
|
|
7062
8652
|
}, {
|
|
7063
8653
|
key: "transform",
|
|
@@ -7068,8 +8658,7 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7068
8658
|
currentC = _this$transformMatrix2[2],
|
|
7069
8659
|
currentD = _this$transformMatrix2[3],
|
|
7070
8660
|
currentE = _this$transformMatrix2[4],
|
|
7071
|
-
currentF = _this$transformMatrix2[5];
|
|
7072
|
-
|
|
8661
|
+
currentF = _this$transformMatrix2[5];
|
|
7073
8662
|
|
|
7074
8663
|
this.transformMatrix[0] = a * currentA + b * currentC;
|
|
7075
8664
|
this.transformMatrix[1] = a * currentB + b * currentD;
|
|
@@ -7077,7 +8666,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7077
8666
|
this.transformMatrix[3] = c * currentB + d * currentD;
|
|
7078
8667
|
this.transformMatrix[4] = e * currentA + f * currentC + currentE;
|
|
7079
8668
|
this.transformMatrix[5] = e * currentB + f * currentD + currentF;
|
|
7080
|
-
}
|
|
8669
|
+
}
|
|
8670
|
+
/**
|
|
8671
|
+
* 应用变换到点
|
|
8672
|
+
* @param {Object} point 点坐标 {x, y}
|
|
8673
|
+
* @returns {Object} 变换后的点坐标 {x, y}
|
|
8674
|
+
*/
|
|
7081
8675
|
|
|
7082
8676
|
}, {
|
|
7083
8677
|
key: "applyTransform",
|
|
@@ -7094,7 +8688,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7094
8688
|
x: a * point.x + c * point.y + tx,
|
|
7095
8689
|
y: b * point.x + d * point.y + ty
|
|
7096
8690
|
};
|
|
7097
|
-
}
|
|
8691
|
+
}
|
|
8692
|
+
/**
|
|
8693
|
+
* 文本测量用的离屏 canvas context
|
|
8694
|
+
* @private
|
|
8695
|
+
* @returns {CanvasRenderingContext2D|null}
|
|
8696
|
+
*/
|
|
7098
8697
|
|
|
7099
8698
|
}, {
|
|
7100
8699
|
key: "_measureCtx",
|
|
@@ -7112,14 +8711,22 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7112
8711
|
}
|
|
7113
8712
|
|
|
7114
8713
|
return this.__measureCtx;
|
|
7115
|
-
}
|
|
8714
|
+
}
|
|
8715
|
+
/**
|
|
8716
|
+
* 获取当前着色器程序
|
|
8717
|
+
* @returns {Object} 着色器程序对象
|
|
8718
|
+
*/
|
|
7116
8719
|
|
|
7117
8720
|
}, {
|
|
7118
8721
|
key: "program",
|
|
7119
8722
|
get: function get() {
|
|
7120
|
-
// 默认所有path用同一个编译好的program
|
|
7121
8723
|
return this.graph.context.pathProgram || (this.graph.context.pathProgram = this.createProgram(pathVertexSource, pathFragmentSource));
|
|
7122
|
-
}
|
|
8724
|
+
}
|
|
8725
|
+
/**
|
|
8726
|
+
* 设置样式
|
|
8727
|
+
* @param {Object|string} style 样式对象或样式属性名
|
|
8728
|
+
* @param {string} [value] 样式值(当 style 为字符串时使用)
|
|
8729
|
+
*/
|
|
7123
8730
|
|
|
7124
8731
|
}, {
|
|
7125
8732
|
key: "setStyle",
|
|
@@ -7132,29 +8739,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7132
8739
|
obj[style] = value;
|
|
7133
8740
|
style = obj;
|
|
7134
8741
|
}
|
|
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
8742
|
|
|
7156
8743
|
this.style = _objectSpread(_objectSpread({}, this.style), style);
|
|
7157
|
-
}
|
|
8744
|
+
}
|
|
8745
|
+
/**
|
|
8746
|
+
* 将颜色转换为 WebGL 可识别的格式
|
|
8747
|
+
* @param {string|Object} color 颜色值
|
|
8748
|
+
* @returns {Object} RGBA 对象 {r, g, b, a},范围 0-1
|
|
8749
|
+
*/
|
|
7158
8750
|
|
|
7159
8751
|
}, {
|
|
7160
8752
|
key: "convertColor",
|
|
@@ -7162,9 +8754,7 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7162
8754
|
if (this.isGradient(color)) return color;
|
|
7163
8755
|
|
|
7164
8756
|
if (typeof color === 'string') {
|
|
7165
|
-
|
|
7166
|
-
color = this.graph.utils.hexToRGBA(color); // hexToRGBA 对无法识别的格式(如 hsl)会原样返回字符串
|
|
7167
|
-
// 利用离屏 canvas 将任意 CSS 颜色转为 rgba
|
|
8757
|
+
color = this.graph.utils.hexToRGBA(color);
|
|
7168
8758
|
|
|
7169
8759
|
if (typeof color === 'string') {
|
|
7170
8760
|
color = this.__parseCSSColor(color);
|
|
@@ -7176,7 +8766,13 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7176
8766
|
}
|
|
7177
8767
|
|
|
7178
8768
|
return color;
|
|
7179
|
-
}
|
|
8769
|
+
}
|
|
8770
|
+
/**
|
|
8771
|
+
* 利用离屏 canvas 解析任意 CSS 颜色
|
|
8772
|
+
* @private
|
|
8773
|
+
* @param {string} colorStr CSS 颜色字符串
|
|
8774
|
+
* @returns {Object} RGBA 对象 {r, g, b, a}
|
|
8775
|
+
*/
|
|
7180
8776
|
|
|
7181
8777
|
}, {
|
|
7182
8778
|
key: "__parseCSSColor",
|
|
@@ -7224,13 +8820,24 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7224
8820
|
a: 0
|
|
7225
8821
|
};
|
|
7226
8822
|
}
|
|
7227
|
-
}
|
|
8823
|
+
}
|
|
8824
|
+
/**
|
|
8825
|
+
* 创建着色器程序
|
|
8826
|
+
* @param {string} vertexSrc 顶点着色器源码
|
|
8827
|
+
* @param {string} fragmentSrc 片段着色器源码
|
|
8828
|
+
* @returns {Object} 着色器程序对象
|
|
8829
|
+
*/
|
|
7228
8830
|
|
|
7229
8831
|
}, {
|
|
7230
8832
|
key: "createProgram",
|
|
7231
8833
|
value: function createProgram(vertexSrc, fragmentSrc) {
|
|
7232
8834
|
return (0, _program.createProgram)(this.context, vertexSrc, fragmentSrc);
|
|
7233
|
-
}
|
|
8835
|
+
}
|
|
8836
|
+
/**
|
|
8837
|
+
* 使用指定的着色器程序
|
|
8838
|
+
* @param {Object} [program] 着色器程序,默认使用当前程序
|
|
8839
|
+
* @returns {Object} 着色器程序
|
|
8840
|
+
*/
|
|
7234
8841
|
|
|
7235
8842
|
}, {
|
|
7236
8843
|
key: "useProgram",
|
|
@@ -7242,21 +8849,38 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7242
8849
|
this.context.__curent_program = program;
|
|
7243
8850
|
return program;
|
|
7244
8851
|
}
|
|
8852
|
+
/**
|
|
8853
|
+
* 获取属性位置
|
|
8854
|
+
* @param {string} name 属性名
|
|
8855
|
+
* @returns {number} 属性位置
|
|
8856
|
+
*/
|
|
8857
|
+
|
|
7245
8858
|
}, {
|
|
7246
8859
|
key: "getAttribLocation",
|
|
7247
8860
|
value: function getAttribLocation(name) {
|
|
7248
8861
|
return this.context.getAttribLocation(this.program.program, name);
|
|
7249
8862
|
}
|
|
8863
|
+
/**
|
|
8864
|
+
* 获取 uniform 位置
|
|
8865
|
+
* @param {string} name uniform 变量名
|
|
8866
|
+
* @returns {WebGLUniformLocation} uniform 位置
|
|
8867
|
+
*/
|
|
8868
|
+
|
|
7250
8869
|
}, {
|
|
7251
8870
|
key: "getUniformLocation",
|
|
7252
8871
|
value: function getUniformLocation(name) {
|
|
7253
8872
|
return this.context.getUniformLocation(this.program.program, name);
|
|
7254
|
-
}
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
|
|
8873
|
+
}
|
|
8874
|
+
/**
|
|
8875
|
+
* 将缓冲区数据写入顶点属性
|
|
8876
|
+
* @param {Object} buffer 缓冲区对象
|
|
8877
|
+
* @param {Object} attr 属性对象
|
|
8878
|
+
* @param {number} [size=2] 每个顶点的分量数(1-4)
|
|
8879
|
+
* @param {number} [strip=0] 步长,0 表示紧密排列
|
|
8880
|
+
* @param {number} [offset=0] 字节偏移量
|
|
8881
|
+
* @param {number} [dataType=FLOAT] 数据类型
|
|
8882
|
+
* @returns {Object} 缓冲区对象
|
|
8883
|
+
*/
|
|
7260
8884
|
|
|
7261
8885
|
}, {
|
|
7262
8886
|
key: "writeVertexAttrib",
|
|
@@ -7267,7 +8891,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7267
8891
|
var dataType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this.context.FLOAT;
|
|
7268
8892
|
buffer.attr = attr;
|
|
7269
8893
|
return (0, _program.writeVertexAttrib)(this.context, buffer, attr, size, strip, offset, dataType);
|
|
7270
|
-
}
|
|
8894
|
+
}
|
|
8895
|
+
/**
|
|
8896
|
+
* 禁用顶点属性数组
|
|
8897
|
+
* @param {Object} attr 属性对象
|
|
8898
|
+
* @returns {Object} 属性对象
|
|
8899
|
+
*/
|
|
7271
8900
|
|
|
7272
8901
|
}, {
|
|
7273
8902
|
key: "disableVertexAttribArray",
|
|
@@ -7280,7 +8909,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7280
8909
|
}
|
|
7281
8910
|
|
|
7282
8911
|
return attr;
|
|
7283
|
-
}
|
|
8912
|
+
}
|
|
8913
|
+
/**
|
|
8914
|
+
* 创建 Float32 缓冲区
|
|
8915
|
+
* @param {Array} data 数据数组
|
|
8916
|
+
* @param {number} [type=ARRAY_BUFFER] 缓冲区类型
|
|
8917
|
+
* @param {number} [drawType=STATIC_DRAW] 绘制类型
|
|
8918
|
+
* @returns {Object} 缓冲区对象
|
|
8919
|
+
*/
|
|
7284
8920
|
|
|
7285
8921
|
}, {
|
|
7286
8922
|
key: "createFloat32Buffer",
|
|
@@ -7292,6 +8928,14 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7292
8928
|
data: data
|
|
7293
8929
|
}, buffer);
|
|
7294
8930
|
}
|
|
8931
|
+
/**
|
|
8932
|
+
* 创建 Uint16 缓冲区
|
|
8933
|
+
* @param {Array} data 数据数组
|
|
8934
|
+
* @param {number} [type=ARRAY_BUFFER] 缓冲区类型
|
|
8935
|
+
* @param {number} [drawType=STATIC_DRAW] 绘制类型
|
|
8936
|
+
* @returns {Object} 缓冲区对象
|
|
8937
|
+
*/
|
|
8938
|
+
|
|
7295
8939
|
}, {
|
|
7296
8940
|
key: "createUint16Buffer",
|
|
7297
8941
|
value: function createUint16Buffer(data) {
|
|
@@ -7301,7 +8945,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7301
8945
|
return _objectSpread({
|
|
7302
8946
|
data: data
|
|
7303
8947
|
}, buffer);
|
|
7304
|
-
}
|
|
8948
|
+
}
|
|
8949
|
+
/**
|
|
8950
|
+
* 删除缓冲区
|
|
8951
|
+
* @param {Object} buffer 缓冲区对象
|
|
8952
|
+
* @returns {Object} 缓冲区对象
|
|
8953
|
+
*/
|
|
7305
8954
|
|
|
7306
8955
|
}, {
|
|
7307
8956
|
key: "deleteBuffer",
|
|
@@ -7316,25 +8965,41 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7316
8965
|
}
|
|
7317
8966
|
|
|
7318
8967
|
return buffer;
|
|
7319
|
-
}
|
|
8968
|
+
}
|
|
8969
|
+
/** @returns {WebGLTexture} 2D 纹理对象 */
|
|
7320
8970
|
|
|
7321
8971
|
}, {
|
|
7322
8972
|
key: "create2DTexture",
|
|
7323
8973
|
value: function create2DTexture() {
|
|
7324
8974
|
return (0, _texture.create2DTexture)(this.context);
|
|
7325
|
-
}
|
|
8975
|
+
}
|
|
8976
|
+
/**
|
|
8977
|
+
* 创建图片纹理
|
|
8978
|
+
* @param {Image|HTMLImageElement} img 图像对象
|
|
8979
|
+
* @returns {Object} 纹理对象
|
|
8980
|
+
*/
|
|
7326
8981
|
|
|
7327
8982
|
}, {
|
|
7328
8983
|
key: "createImgTexture",
|
|
7329
8984
|
value: function createImgTexture(img) {
|
|
7330
8985
|
return (0, _texture.createImgTexture)(this.context, img);
|
|
7331
|
-
}
|
|
8986
|
+
}
|
|
8987
|
+
/**
|
|
8988
|
+
* 根据像素数据创建纹理
|
|
8989
|
+
* @param {ImageData|Uint8Array} data 像素数据
|
|
8990
|
+
* @returns {Object} 纹理对象
|
|
8991
|
+
*/
|
|
7332
8992
|
|
|
7333
8993
|
}, {
|
|
7334
8994
|
key: "createDataTexture",
|
|
7335
8995
|
value: function createDataTexture(data) {
|
|
7336
8996
|
return (0, _texture.createDataTexture)(this.context, data);
|
|
7337
|
-
}
|
|
8997
|
+
}
|
|
8998
|
+
/**
|
|
8999
|
+
* 删除纹理
|
|
9000
|
+
* @param {Object} texture 纹理对象
|
|
9001
|
+
* @returns {Object} 纹理对象
|
|
9002
|
+
*/
|
|
7338
9003
|
|
|
7339
9004
|
}, {
|
|
7340
9005
|
key: "deleteTexture",
|
|
@@ -7346,41 +9011,51 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7346
9011
|
}
|
|
7347
9012
|
|
|
7348
9013
|
return texture;
|
|
7349
|
-
}
|
|
7350
|
-
|
|
9014
|
+
}
|
|
9015
|
+
/**
|
|
9016
|
+
* 多边形三角化,得到三角形顶点索引数组
|
|
9017
|
+
* @param {Array<Object>} points 多边形顶点数组
|
|
9018
|
+
* @returns {Array<number>} 三角形顶点索引数组
|
|
9019
|
+
*/
|
|
7351
9020
|
|
|
7352
9021
|
}, {
|
|
7353
9022
|
key: "earCutPoints",
|
|
7354
9023
|
value: function earCutPoints(points) {
|
|
7355
9024
|
var arr = this.pointsToArray(points);
|
|
7356
|
-
var ps = (0, _earcut["default"])(arr);
|
|
7357
|
-
|
|
9025
|
+
var ps = (0, _earcut["default"])(arr);
|
|
7358
9026
|
return ps;
|
|
7359
|
-
}
|
|
7360
|
-
|
|
9027
|
+
}
|
|
9028
|
+
/**
|
|
9029
|
+
* 多边形三角化,得到三角形顶点数组
|
|
9030
|
+
* @param {Array<Object>} points 多边形顶点数组
|
|
9031
|
+
* @returns {Array<Array<Object>>} 三角形数组,每个三角形包含3个顶点
|
|
9032
|
+
*/
|
|
7361
9033
|
|
|
7362
9034
|
}, {
|
|
7363
9035
|
key: "earCutPointsToTriangles",
|
|
7364
9036
|
value: function earCutPointsToTriangles(points) {
|
|
7365
|
-
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
7366
|
-
|
|
9037
|
+
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
7367
9038
|
var len = points.length;
|
|
7368
9039
|
var key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len - 1].x + '_' + points[len - 1].y;
|
|
7369
9040
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
7370
|
-
var ps = this.earCutPoints(points);
|
|
7371
|
-
|
|
7372
|
-
var triangles = []; // 用顶点索引再组合成坐标数组
|
|
9041
|
+
var ps = this.earCutPoints(points);
|
|
9042
|
+
var triangles = [];
|
|
7373
9043
|
|
|
7374
9044
|
for (var i = 0; i < ps.length; i += 3) {
|
|
7375
9045
|
var p1 = points[ps[i]];
|
|
7376
9046
|
var p2 = points[ps[i + 1]];
|
|
7377
9047
|
var p3 = points[ps[i + 2]];
|
|
7378
|
-
triangles.push([p1, p2, p3]);
|
|
9048
|
+
triangles.push([p1, p2, p3]);
|
|
7379
9049
|
}
|
|
7380
9050
|
|
|
7381
9051
|
this.earCutCache[key] = triangles;
|
|
7382
9052
|
return triangles;
|
|
7383
|
-
}
|
|
9053
|
+
}
|
|
9054
|
+
/**
|
|
9055
|
+
* 点坐标数组转为一维数组
|
|
9056
|
+
* @param {Array<Object>} points 点数组 [{x, y}, ...]
|
|
9057
|
+
* @returns {Array<number>} 一维数组 [x1, y1, x2, y2, ...]
|
|
9058
|
+
*/
|
|
7384
9059
|
|
|
7385
9060
|
}, {
|
|
7386
9061
|
key: "pointsToArray",
|
|
@@ -7389,8 +9064,13 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7389
9064
|
|
|
7390
9065
|
return (_ref = []).concat.apply(_ref, _toConsumableArray(points.map(function (p) {
|
|
7391
9066
|
return [p.x, p.y];
|
|
7392
|
-
})));
|
|
7393
|
-
}
|
|
9067
|
+
})));
|
|
9068
|
+
}
|
|
9069
|
+
/**
|
|
9070
|
+
* 一维数组转为点坐标数组
|
|
9071
|
+
* @param {Array<number>} arr 一维数组 [x1, y1, x2, y2, ...]
|
|
9072
|
+
* @returns {Array<Object>} 点数组 [{x, y}, ...]
|
|
9073
|
+
*/
|
|
7394
9074
|
|
|
7395
9075
|
}, {
|
|
7396
9076
|
key: "arrayToPoints",
|
|
@@ -7405,7 +9085,16 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7405
9085
|
}
|
|
7406
9086
|
|
|
7407
9087
|
return points;
|
|
7408
|
-
}
|
|
9088
|
+
}
|
|
9089
|
+
/**
|
|
9090
|
+
* 创建线性渐变
|
|
9091
|
+
* @param {number} x1 起点X坐标
|
|
9092
|
+
* @param {number} y1 起点Y坐标
|
|
9093
|
+
* @param {number} x2 终点X坐标
|
|
9094
|
+
* @param {number} y2 终点Y坐标
|
|
9095
|
+
* @param {Object} bounds 渐变边界
|
|
9096
|
+
* @returns {WebglGradient} 渐变对象
|
|
9097
|
+
*/
|
|
7409
9098
|
|
|
7410
9099
|
}, {
|
|
7411
9100
|
key: "createLinearGradient",
|
|
@@ -7418,7 +9107,18 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7418
9107
|
bounds: bounds,
|
|
7419
9108
|
control: this
|
|
7420
9109
|
});
|
|
7421
|
-
}
|
|
9110
|
+
}
|
|
9111
|
+
/**
|
|
9112
|
+
* 创建径向渐变
|
|
9113
|
+
* @param {number} x1 内圆中心X坐标
|
|
9114
|
+
* @param {number} y1 内圆中心Y坐标
|
|
9115
|
+
* @param {number} r1 内圆半径
|
|
9116
|
+
* @param {number} x2 外圆中心X坐标
|
|
9117
|
+
* @param {number} y2 外圆中心Y坐标
|
|
9118
|
+
* @param {number} r2 外圆半径
|
|
9119
|
+
* @param {Object} bounds 渐变边界
|
|
9120
|
+
* @returns {WebglGradient} 渐变对象
|
|
9121
|
+
*/
|
|
7422
9122
|
|
|
7423
9123
|
}, {
|
|
7424
9124
|
key: "createRadialGradient",
|
|
@@ -7433,7 +9133,12 @@ var WeblBase = /*#__PURE__*/function () {
|
|
|
7433
9133
|
bounds: bounds,
|
|
7434
9134
|
control: this
|
|
7435
9135
|
});
|
|
7436
|
-
}
|
|
9136
|
+
}
|
|
9137
|
+
/**
|
|
9138
|
+
* 判断是否为渐变对象
|
|
9139
|
+
* @param {Object} obj 待检测对象
|
|
9140
|
+
* @returns {boolean} 是否为渐变对象
|
|
9141
|
+
*/
|
|
7437
9142
|
|
|
7438
9143
|
}, {
|
|
7439
9144
|
key: "isGradient",
|
|
@@ -7484,32 +9189,53 @@ exports.createUint16Buffer = createUint16Buffer;
|
|
|
7484
9189
|
exports.createFloat32Buffer = createFloat32Buffer;
|
|
7485
9190
|
exports.deleteBuffer = deleteBuffer;
|
|
7486
9191
|
|
|
7487
|
-
|
|
9192
|
+
/**
|
|
9193
|
+
* @fileoverview WebGL 缓冲区管理模块
|
|
9194
|
+
*
|
|
9195
|
+
* 本模块提供了 WebGL 缓冲区的创建和管理功能,包括:
|
|
9196
|
+
* - 创建通用缓冲区
|
|
9197
|
+
* - 创建 Float32 类型缓冲区
|
|
9198
|
+
* - 创建 Uint16 类型缓冲区
|
|
9199
|
+
* - 删除缓冲区
|
|
9200
|
+
*
|
|
9201
|
+
* @module lib/webgl/core/buffer
|
|
9202
|
+
* @author jmGraph Team
|
|
9203
|
+
*/
|
|
9204
|
+
|
|
9205
|
+
/**
|
|
9206
|
+
* 创建 WebGL 缓冲区
|
|
9207
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9208
|
+
* @param {Array|TypedArray} data 缓冲区数据
|
|
9209
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9210
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9211
|
+
* @returns {Object} 缓冲区对象 {type, drawType, buffer, unitSize}
|
|
9212
|
+
*/
|
|
7488
9213
|
function createBuffer(gl, data) {
|
|
7489
9214
|
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
|
|
7490
9215
|
var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
|
|
7491
|
-
//先创建一个缓存对象
|
|
7492
9216
|
var buffer = gl.createBuffer();
|
|
7493
9217
|
|
|
7494
9218
|
if (!buffer) {
|
|
7495
9219
|
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); // 表示缓冲区的内容不会经常更改
|
|
9220
|
+
}
|
|
7504
9221
|
|
|
9222
|
+
gl.bindBuffer(type, buffer);
|
|
9223
|
+
gl.bufferData(type, data.buffer || data, drawType);
|
|
7505
9224
|
return {
|
|
7506
9225
|
type: type,
|
|
7507
9226
|
drawType: drawType,
|
|
7508
9227
|
buffer: buffer,
|
|
7509
|
-
// 获取到数组中单个元素的字节数
|
|
7510
9228
|
unitSize: data.BYTES_PER_ELEMENT
|
|
7511
9229
|
};
|
|
7512
|
-
}
|
|
9230
|
+
}
|
|
9231
|
+
/**
|
|
9232
|
+
* 创建 Float32 类型缓冲区
|
|
9233
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9234
|
+
* @param {Array} data 数据数组
|
|
9235
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9236
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9237
|
+
* @returns {Object} 缓冲区对象
|
|
9238
|
+
*/
|
|
7513
9239
|
|
|
7514
9240
|
|
|
7515
9241
|
function createFloat32Buffer(gl, data) {
|
|
@@ -7518,7 +9244,15 @@ function createFloat32Buffer(gl, data) {
|
|
|
7518
9244
|
var vertices = new Float32Array(data);
|
|
7519
9245
|
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
7520
9246
|
return buffer;
|
|
7521
|
-
}
|
|
9247
|
+
}
|
|
9248
|
+
/**
|
|
9249
|
+
* 创建 Uint16 类型缓冲区
|
|
9250
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9251
|
+
* @param {Array} data 数据数组
|
|
9252
|
+
* @param {number} [type=gl.ARRAY_BUFFER] 缓冲区类型
|
|
9253
|
+
* @param {number} [drawType=gl.STATIC_DRAW] 绘制类型
|
|
9254
|
+
* @returns {Object} 缓冲区对象
|
|
9255
|
+
*/
|
|
7522
9256
|
|
|
7523
9257
|
|
|
7524
9258
|
function createUint16Buffer(gl, data) {
|
|
@@ -7527,7 +9261,12 @@ function createUint16Buffer(gl, data) {
|
|
|
7527
9261
|
var vertices = new Uint16Array(data);
|
|
7528
9262
|
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
7529
9263
|
return buffer;
|
|
7530
|
-
}
|
|
9264
|
+
}
|
|
9265
|
+
/**
|
|
9266
|
+
* 删除缓冲区
|
|
9267
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9268
|
+
* @param {Object|WebGLBuffer} buffer 缓冲区对象或 WebGL 缓冲区
|
|
9269
|
+
*/
|
|
7531
9270
|
|
|
7532
9271
|
|
|
7533
9272
|
function deleteBuffer(gl, buffer) {
|
|
@@ -7541,6 +9280,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7541
9280
|
value: true
|
|
7542
9281
|
});
|
|
7543
9282
|
exports.mapSize = void 0;
|
|
9283
|
+
|
|
9284
|
+
/**
|
|
9285
|
+
* @fileoverview GLSL 类型大小映射模块
|
|
9286
|
+
*
|
|
9287
|
+
* 本模块提供了 GLSL 类型到其元素数量的映射。
|
|
9288
|
+
*
|
|
9289
|
+
* @module lib/webgl/core/mapSize
|
|
9290
|
+
* @author jmGraph Team
|
|
9291
|
+
*/
|
|
9292
|
+
|
|
9293
|
+
/**
|
|
9294
|
+
* GLSL 类型到元素数量的映射表
|
|
9295
|
+
* @constant {Object.<string, number>}
|
|
9296
|
+
*/
|
|
7544
9297
|
var GLSL_TO_SIZE = {
|
|
7545
9298
|
'float': 1,
|
|
7546
9299
|
'vec2': 2,
|
|
@@ -7560,10 +9313,9 @@ var GLSL_TO_SIZE = {
|
|
|
7560
9313
|
'sampler2D': 1
|
|
7561
9314
|
};
|
|
7562
9315
|
/**
|
|
7563
|
-
*
|
|
7564
|
-
* @
|
|
7565
|
-
* @
|
|
7566
|
-
* @return {Number}
|
|
9316
|
+
* 根据 GLSL 类型名获取元素数量
|
|
9317
|
+
* @param {string} type GLSL 类型名
|
|
9318
|
+
* @returns {number} 元素数量
|
|
7567
9319
|
*/
|
|
7568
9320
|
|
|
7569
9321
|
var mapSize = function mapSize(type) {
|
|
@@ -7579,7 +9331,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7579
9331
|
value: true
|
|
7580
9332
|
});
|
|
7581
9333
|
exports.mapType = void 0;
|
|
9334
|
+
|
|
9335
|
+
/**
|
|
9336
|
+
* @fileoverview WebGL 类型到 GLSL 类型映射模块
|
|
9337
|
+
*
|
|
9338
|
+
* 本模块提供了 WebGL 常量类型到 GLSL 类型名的映射。
|
|
9339
|
+
*
|
|
9340
|
+
* @module lib/webgl/core/mapType
|
|
9341
|
+
* @author jmGraph Team
|
|
9342
|
+
*/
|
|
9343
|
+
|
|
9344
|
+
/** @type {Object.<number, string>|null} 缓存的类型映射表 */
|
|
7582
9345
|
var GL_TABLE = null;
|
|
9346
|
+
/**
|
|
9347
|
+
* WebGL 常量到 GLSL 类型的映射表
|
|
9348
|
+
* @constant {Object.<string, string>}
|
|
9349
|
+
*/
|
|
9350
|
+
|
|
7583
9351
|
var GL_TO_GLSL_TYPES = {
|
|
7584
9352
|
'FLOAT': 'float',
|
|
7585
9353
|
'FLOAT_VEC2': 'vec2',
|
|
@@ -7598,6 +9366,12 @@ var GL_TO_GLSL_TYPES = {
|
|
|
7598
9366
|
'FLOAT_MAT4': 'mat4',
|
|
7599
9367
|
'SAMPLER_2D': 'sampler2D'
|
|
7600
9368
|
};
|
|
9369
|
+
/**
|
|
9370
|
+
* 将 WebGL 类型常量映射为 GLSL 类型名
|
|
9371
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9372
|
+
* @param {number} type WebGL 类型常量
|
|
9373
|
+
* @returns {string} GLSL 类型名
|
|
9374
|
+
*/
|
|
7601
9375
|
|
|
7602
9376
|
var mapType = function mapType(gl, type) {
|
|
7603
9377
|
if (!GL_TABLE) {
|
|
@@ -7636,25 +9410,37 @@ var _mapSize = require("./mapSize.js");
|
|
|
7636
9410
|
|
|
7637
9411
|
var _mapType = require("./mapType.js");
|
|
7638
9412
|
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
9413
|
+
/**
|
|
9414
|
+
* @fileoverview WebGL 着色器程序管理模块
|
|
9415
|
+
*
|
|
9416
|
+
* 本模块提供了 WebGL 着色器程序的创建和管理功能,包括:
|
|
9417
|
+
* - 创建着色器程序
|
|
9418
|
+
* - 提取属性和 uniform 变量
|
|
9419
|
+
* - 顶点属性绑定
|
|
9420
|
+
*
|
|
9421
|
+
* @module lib/webgl/core/program
|
|
9422
|
+
* @author jmGraph Team
|
|
9423
|
+
*/
|
|
7643
9424
|
|
|
9425
|
+
/**
|
|
9426
|
+
* 创建着色器程序
|
|
9427
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9428
|
+
* @param {string} vertexSrc 顶点着色器源码
|
|
9429
|
+
* @param {string} fragmentSrc 片段着色器源码
|
|
9430
|
+
* @returns {Object} 程序对象 {program, attrs, uniforms}
|
|
9431
|
+
*/
|
|
9432
|
+
function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
9433
|
+
var vertexShader = (0, _shader.createShader)(gl, gl.VERTEX_SHADER, vertexSrc);
|
|
7644
9434
|
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
|
-
// 检查程序链接状态
|
|
9435
|
+
var program = gl.createProgram();
|
|
9436
|
+
gl.attachShader(program, vertexShader);
|
|
9437
|
+
gl.attachShader(program, fragmentShader);
|
|
9438
|
+
gl.linkProgram(program);
|
|
7653
9439
|
|
|
7654
9440
|
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
7655
9441
|
console.error('PError: Could not initialize shader.');
|
|
7656
9442
|
console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS));
|
|
7657
|
-
console.error('gl.getError()', gl.getError());
|
|
9443
|
+
console.error('gl.getError()', gl.getError());
|
|
7658
9444
|
|
|
7659
9445
|
if (gl.getProgramInfoLog(program) !== '') {
|
|
7660
9446
|
console.warn('Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
|
|
@@ -7663,8 +9449,7 @@ function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
|
7663
9449
|
gl.deleteProgram(program);
|
|
7664
9450
|
}
|
|
7665
9451
|
|
|
7666
|
-
useProgram(gl, program);
|
|
7667
|
-
|
|
9452
|
+
useProgram(gl, program);
|
|
7668
9453
|
gl.deleteShader(vertexShader);
|
|
7669
9454
|
gl.deleteShader(fragmentShader);
|
|
7670
9455
|
var attrs = extractAttributes(gl, program);
|
|
@@ -7674,12 +9459,24 @@ function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
|
7674
9459
|
attrs: attrs,
|
|
7675
9460
|
uniforms: uniforms
|
|
7676
9461
|
};
|
|
7677
|
-
}
|
|
9462
|
+
}
|
|
9463
|
+
/**
|
|
9464
|
+
* 使用指定的着色器程序
|
|
9465
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9466
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9467
|
+
*/
|
|
7678
9468
|
|
|
7679
9469
|
|
|
7680
9470
|
function useProgram(gl, program) {
|
|
7681
|
-
return gl.useProgram(program);
|
|
9471
|
+
return gl.useProgram(program);
|
|
7682
9472
|
}
|
|
9473
|
+
/**
|
|
9474
|
+
* 提取着色器程序中的所有属性
|
|
9475
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9476
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9477
|
+
* @returns {Object} 属性对象字典
|
|
9478
|
+
*/
|
|
9479
|
+
|
|
7683
9480
|
|
|
7684
9481
|
function extractAttributes(gl, program) {
|
|
7685
9482
|
var attributes = {};
|
|
@@ -7698,6 +9495,13 @@ function extractAttributes(gl, program) {
|
|
|
7698
9495
|
|
|
7699
9496
|
return attributes;
|
|
7700
9497
|
}
|
|
9498
|
+
/**
|
|
9499
|
+
* 提取着色器程序中的所有 uniform 变量
|
|
9500
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9501
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9502
|
+
* @returns {Object} uniform 变量对象字典
|
|
9503
|
+
*/
|
|
9504
|
+
|
|
7701
9505
|
|
|
7702
9506
|
function extractUniforms(gl, program) {
|
|
7703
9507
|
var uniforms = {};
|
|
@@ -7717,12 +9521,18 @@ function extractUniforms(gl, program) {
|
|
|
7717
9521
|
|
|
7718
9522
|
return uniforms;
|
|
7719
9523
|
}
|
|
9524
|
+
/**
|
|
9525
|
+
* 将缓冲区数据写入顶点属性
|
|
9526
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9527
|
+
* @param {Object} buffer 缓冲区对象
|
|
9528
|
+
* @param {Object} attr 属性对象
|
|
9529
|
+
* @param {number} [size=2] 每个顶点的分量数(1-4)
|
|
9530
|
+
* @param {number} [strip=0] 步长,0 表示紧密排列
|
|
9531
|
+
* @param {number} [offset=0] 字节偏移量
|
|
9532
|
+
* @param {number} [dataType=gl.FLOAT] 数据类型
|
|
9533
|
+
* @returns {Object} 缓冲区对象
|
|
9534
|
+
*/
|
|
7720
9535
|
|
|
7721
|
-
; // 把缓冲区的值写入变量
|
|
7722
|
-
// size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
|
|
7723
|
-
// strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
|
|
7724
|
-
// offset: 字节偏移量,必须是类型的字节长度的倍数。
|
|
7725
|
-
// dataType: 每个元素的数据类型
|
|
7726
9536
|
|
|
7727
9537
|
function writeVertexAttrib(gl, buffer, attr) {
|
|
7728
9538
|
var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
|
|
@@ -7730,22 +9540,40 @@ function writeVertexAttrib(gl, buffer, attr) {
|
|
|
7730
9540
|
var offset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
7731
9541
|
var dataType = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : gl.FLOAT;
|
|
7732
9542
|
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);
|
|
9543
|
+
gl.vertexAttribPointer(attr.location, size, dataType, false, strip * buffer.unitSize, offset);
|
|
7738
9544
|
gl.enableVertexAttribArray(attr.location);
|
|
7739
9545
|
return buffer;
|
|
7740
9546
|
}
|
|
9547
|
+
/**
|
|
9548
|
+
* 禁用顶点属性数组
|
|
9549
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9550
|
+
* @param {Object} attr 属性对象
|
|
9551
|
+
*/
|
|
9552
|
+
|
|
7741
9553
|
|
|
7742
9554
|
function disableVertexAttribArray(gl, attr) {
|
|
7743
9555
|
return gl.disableVertexAttribArray(attr.location);
|
|
7744
9556
|
}
|
|
9557
|
+
/**
|
|
9558
|
+
* 获取属性位置
|
|
9559
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9560
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9561
|
+
* @param {string} name 属性名
|
|
9562
|
+
* @returns {number} 属性位置
|
|
9563
|
+
*/
|
|
9564
|
+
|
|
7745
9565
|
|
|
7746
9566
|
function getAttribLocation(gl, program, name) {
|
|
7747
9567
|
return gl.getAttribLocation(program, name);
|
|
7748
9568
|
}
|
|
9569
|
+
/**
|
|
9570
|
+
* 获取 uniform 位置
|
|
9571
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9572
|
+
* @param {WebGLProgram} program 着色器程序
|
|
9573
|
+
* @param {string} name uniform 变量名
|
|
9574
|
+
* @returns {WebGLUniformLocation} uniform 位置
|
|
9575
|
+
*/
|
|
9576
|
+
|
|
7749
9577
|
|
|
7750
9578
|
function getUniformLocation(gl, program, name) {
|
|
7751
9579
|
return gl.getUniformLocation(program, name);
|
|
@@ -7759,16 +9587,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7759
9587
|
});
|
|
7760
9588
|
exports.createShader = createShader;
|
|
7761
9589
|
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
gl.compileShader(shader); // 编译着色器
|
|
9590
|
+
/**
|
|
9591
|
+
* @fileoverview WebGL 着色器管理模块
|
|
9592
|
+
*
|
|
9593
|
+
* 本模块提供了 WebGL 着色器的创建功能。
|
|
9594
|
+
*
|
|
9595
|
+
* @module lib/webgl/core/shader
|
|
9596
|
+
* @author jmGraph Team
|
|
9597
|
+
*/
|
|
7771
9598
|
|
|
9599
|
+
/**
|
|
9600
|
+
* 创建 WebGL 着色器
|
|
9601
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9602
|
+
* @param {number} type 着色器类型:gl.VERTEX_SHADER 或 gl.FRAGMENT_SHADER
|
|
9603
|
+
* @param {string} src 着色器源码
|
|
9604
|
+
* @returns {WebGLShader} 编译后的着色器对象
|
|
9605
|
+
*/
|
|
9606
|
+
function createShader(gl, type, src) {
|
|
9607
|
+
var shader = gl.createShader(type);
|
|
9608
|
+
gl.shaderSource(shader, src);
|
|
9609
|
+
gl.compileShader(shader);
|
|
7772
9610
|
return shader;
|
|
7773
9611
|
}
|
|
7774
9612
|
|
|
@@ -7783,55 +9621,71 @@ exports.createImgTexture = createImgTexture;
|
|
|
7783
9621
|
exports.createDataTexture = createDataTexture;
|
|
7784
9622
|
exports.deleteTexture = deleteTexture;
|
|
7785
9623
|
|
|
7786
|
-
|
|
9624
|
+
/**
|
|
9625
|
+
* @fileoverview WebGL 纹理管理模块
|
|
9626
|
+
*
|
|
9627
|
+
* 本模块提供了 WebGL 纹理的创建和管理功能,包括:
|
|
9628
|
+
* - 创建 2D 纹理
|
|
9629
|
+
* - 创建图片纹理
|
|
9630
|
+
* - 创建数据纹理
|
|
9631
|
+
* - 删除纹理
|
|
9632
|
+
*
|
|
9633
|
+
* @module lib/webgl/core/texture
|
|
9634
|
+
* @author jmGraph Team
|
|
9635
|
+
*/
|
|
9636
|
+
|
|
9637
|
+
/**
|
|
9638
|
+
* 创建 2D 纹理
|
|
9639
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9640
|
+
* @returns {WebGLTexture} 纹理对象
|
|
9641
|
+
*/
|
|
7787
9642
|
function create2DTexture(gl) {
|
|
7788
9643
|
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
|
-
|
|
9644
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
|
|
9645
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
9646
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
9647
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
9648
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
9649
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
9650
|
+
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
7804
9651
|
return texture;
|
|
7805
|
-
}
|
|
9652
|
+
}
|
|
9653
|
+
/**
|
|
9654
|
+
* 创建图片纹理
|
|
9655
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9656
|
+
* @param {Image|HTMLImageElement} img 图像对象
|
|
9657
|
+
* @returns {Object} 纹理对象 {texture}
|
|
9658
|
+
*/
|
|
7806
9659
|
|
|
7807
9660
|
|
|
7808
9661
|
function createImgTexture(gl, img) {
|
|
7809
9662
|
var texture = create2DTexture(gl);
|
|
7810
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
7811
|
-
|
|
9663
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
7812
9664
|
return {
|
|
7813
9665
|
texture: texture
|
|
7814
9666
|
};
|
|
7815
|
-
}
|
|
9667
|
+
}
|
|
9668
|
+
/**
|
|
9669
|
+
* 根据像素数据创建纹理
|
|
9670
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9671
|
+
* @param {ImageData|Object} pixels 像素数据 {data, width, height}
|
|
9672
|
+
* @returns {Object} 纹理对象 {texture}
|
|
9673
|
+
*/
|
|
7816
9674
|
|
|
7817
9675
|
|
|
7818
9676
|
function createDataTexture(gl, pixels) {
|
|
7819
9677
|
var data = new Uint8Array(pixels.data || pixels);
|
|
7820
9678
|
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
|
-
);
|
|
9679
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, pixels.width || 1, pixels.height || 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
7831
9680
|
return {
|
|
7832
9681
|
texture: texture
|
|
7833
9682
|
};
|
|
7834
|
-
}
|
|
9683
|
+
}
|
|
9684
|
+
/**
|
|
9685
|
+
* 删除纹理
|
|
9686
|
+
* @param {WebGLRenderingContext} gl WebGL 渲染上下文
|
|
9687
|
+
* @param {WebGLTexture} texture 纹理对象
|
|
9688
|
+
*/
|
|
7835
9689
|
|
|
7836
9690
|
|
|
7837
9691
|
function deleteTexture(gl, texture) {
|
|
@@ -7854,21 +9708,56 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
7854
9708
|
|
|
7855
9709
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
7856
9710
|
|
|
9711
|
+
/**
|
|
9712
|
+
* @fileoverview WebGL 渐变对象
|
|
9713
|
+
*
|
|
9714
|
+
* 本模块提供了 WebGL 渐变功能,支持 GLSL 着色器直接计算渐变色,
|
|
9715
|
+
* 无需 textureCanvas,性能更优。
|
|
9716
|
+
*
|
|
9717
|
+
* 支持的渐变类型:
|
|
9718
|
+
* - 线性渐变 (linear)
|
|
9719
|
+
* - 径向渐变 (radial)
|
|
9720
|
+
*
|
|
9721
|
+
* @module lib/webgl/gradient
|
|
9722
|
+
* @author jmGraph Team
|
|
9723
|
+
*/
|
|
9724
|
+
|
|
9725
|
+
/** @constant {number} 最大颜色断点数量 */
|
|
7857
9726
|
var MAX_STOPS = 16;
|
|
7858
9727
|
/**
|
|
7859
|
-
* WebGL
|
|
7860
|
-
* 支持 GLSL
|
|
9728
|
+
* WebGL 渐变类
|
|
9729
|
+
* 支持 GLSL 着色器直接计算渐变色
|
|
9730
|
+
*
|
|
9731
|
+
* @class WebglGradient
|
|
9732
|
+
* @example
|
|
9733
|
+
* const gradient = new WebglGradient('linear', { x1: 0, y1: 0, x2: 100, y2: 0 });
|
|
9734
|
+
* gradient.addColorStop(0, '#ff0000');
|
|
9735
|
+
* gradient.addColorStop(1, '#0000ff');
|
|
7861
9736
|
*/
|
|
7862
9737
|
|
|
7863
9738
|
exports.MAX_STOPS = MAX_STOPS;
|
|
7864
9739
|
|
|
7865
9740
|
var WebglGradient = /*#__PURE__*/function () {
|
|
9741
|
+
/**
|
|
9742
|
+
* 构造函数
|
|
9743
|
+
* @param {string} [type='linear'] 渐变类型:'linear' 或 'radial'
|
|
9744
|
+
* @param {Object} params 渐变参数
|
|
9745
|
+
* @param {number} [params.x1=0] 起点/内圆中心X坐标
|
|
9746
|
+
* @param {number} [params.y1=0] 起点/内圆中心Y坐标
|
|
9747
|
+
* @param {number} [params.r1=0] 内圆半径(径向渐变)
|
|
9748
|
+
* @param {number} [params.x2=0] 终点/外圆中心X坐标
|
|
9749
|
+
* @param {number} [params.y2=0] 终点/外圆中心Y坐标
|
|
9750
|
+
* @param {number} [params.r2=0] 外圆半径(径向渐变)
|
|
9751
|
+
* @param {Object} [params.bounds] 渐变边界
|
|
9752
|
+
* @param {Object} [params.control] 控制器对象
|
|
9753
|
+
*/
|
|
7866
9754
|
function WebglGradient() {
|
|
7867
9755
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'linear';
|
|
7868
9756
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7869
9757
|
|
|
7870
9758
|
_classCallCheck(this, WebglGradient);
|
|
7871
9759
|
|
|
9760
|
+
/** @type {string} 渐变类型 */
|
|
7872
9761
|
this.type = type || 'linear';
|
|
7873
9762
|
this.x1 = params.x1 || 0;
|
|
7874
9763
|
this.y1 = params.y1 || 0;
|
|
@@ -7876,6 +9765,8 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7876
9765
|
this.x2 = params.x2 || 0;
|
|
7877
9766
|
this.y2 = params.y2 || 0;
|
|
7878
9767
|
this.r2 = params.r2 || 0;
|
|
9768
|
+
/** @type {Object} 渐变边界 */
|
|
9769
|
+
|
|
7879
9770
|
this.bounds = params.bounds || {
|
|
7880
9771
|
left: 0,
|
|
7881
9772
|
top: 0,
|
|
@@ -7883,12 +9774,16 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7883
9774
|
height: 0
|
|
7884
9775
|
};
|
|
7885
9776
|
this.control = params.control;
|
|
9777
|
+
/** @type {Array<{offset: number, color: string}>} 颜色断点数组 */
|
|
9778
|
+
|
|
7886
9779
|
this.stops = [];
|
|
7887
9780
|
this._sortedStops = null;
|
|
7888
9781
|
this._paramsHash = null;
|
|
7889
9782
|
}
|
|
7890
9783
|
/**
|
|
7891
9784
|
* 添加颜色断点
|
|
9785
|
+
* @param {number} offset 断点位置 (0-1)
|
|
9786
|
+
* @param {string} color 颜色值
|
|
7892
9787
|
*/
|
|
7893
9788
|
|
|
7894
9789
|
|
|
@@ -7903,7 +9798,9 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7903
9798
|
this._paramsHash = null;
|
|
7904
9799
|
}
|
|
7905
9800
|
/**
|
|
7906
|
-
*
|
|
9801
|
+
* 获取排序后的断点数组(带解析后的颜色)
|
|
9802
|
+
* @private
|
|
9803
|
+
* @returns {Array<{offset: number, r: number, g: number, b: number, a: number}>}
|
|
7907
9804
|
*/
|
|
7908
9805
|
|
|
7909
9806
|
}, {
|
|
@@ -7919,8 +9816,6 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7919
9816
|
}
|
|
7920
9817
|
|
|
7921
9818
|
if (_typeof(c) === 'object' && c !== null) {
|
|
7922
|
-
// hexToRGBA 返回 r/g/b 为 0~255,a 为 0~1
|
|
7923
|
-
// 但如果已经是 0~1 范围(由 rgbToDecimal 处理过),需要检测
|
|
7924
9819
|
var needNormalize = c.r > 1 || c.g > 1 || c.b > 1 ? 255 : 1;
|
|
7925
9820
|
return {
|
|
7926
9821
|
offset: s.offset,
|
|
@@ -7944,8 +9839,8 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7944
9839
|
return this._sortedStops;
|
|
7945
9840
|
}
|
|
7946
9841
|
/**
|
|
7947
|
-
*
|
|
7948
|
-
*
|
|
9842
|
+
* 将渐变参数转换为 uniform 格式,传递给着色器
|
|
9843
|
+
* @returns {Object} uniform 参数对象
|
|
7949
9844
|
*/
|
|
7950
9845
|
|
|
7951
9846
|
}, {
|
|
@@ -7953,8 +9848,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7953
9848
|
value: function toUniformParams() {
|
|
7954
9849
|
var stops = this._getSortedStops();
|
|
7955
9850
|
|
|
7956
|
-
var count = Math.min(stops.length, MAX_STOPS);
|
|
7957
|
-
|
|
9851
|
+
var count = Math.min(stops.length, MAX_STOPS);
|
|
7958
9852
|
var flatStops = new Float32Array(count * 5);
|
|
7959
9853
|
|
|
7960
9854
|
for (var i = 0; i < count; i++) {
|
|
@@ -7974,9 +9868,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7974
9868
|
stops: flatStops
|
|
7975
9869
|
};
|
|
7976
9870
|
}
|
|
7977
|
-
/**
|
|
7978
|
-
* 使缓存失效
|
|
7979
|
-
*/
|
|
9871
|
+
/** 使缓存失效 */
|
|
7980
9872
|
|
|
7981
9873
|
}, {
|
|
7982
9874
|
key: "invalidateCache",
|
|
@@ -7986,6 +9878,7 @@ var WebglGradient = /*#__PURE__*/function () {
|
|
|
7986
9878
|
}
|
|
7987
9879
|
/**
|
|
7988
9880
|
* 转换为渐变的字符串表达
|
|
9881
|
+
* @returns {string} 渐变字符串
|
|
7989
9882
|
*/
|
|
7990
9883
|
|
|
7991
9884
|
}, {
|
|
@@ -8078,29 +9971,58 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
8078
9971
|
|
|
8079
9972
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
8080
9973
|
|
|
8081
|
-
|
|
9974
|
+
/**
|
|
9975
|
+
* WebGL 路径绘制类
|
|
9976
|
+
* 继承自 WeblBase,提供路径绘制功能
|
|
9977
|
+
*
|
|
9978
|
+
* @class WebglPath
|
|
9979
|
+
* @extends WeblBase
|
|
9980
|
+
* @example
|
|
9981
|
+
* const path = new WebglPath(graph, { isRegular: false, needCut: true });
|
|
9982
|
+
* path.draw(points);
|
|
9983
|
+
* path.stroke(points, '#ff0000', 2);
|
|
9984
|
+
*/
|
|
8082
9985
|
var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
8083
9986
|
_inherits(WebglPath, _WebglBase);
|
|
8084
9987
|
|
|
8085
9988
|
var _super = _createSuper(WebglPath);
|
|
8086
9989
|
|
|
9990
|
+
/**
|
|
9991
|
+
* 构造函数
|
|
9992
|
+
* @param {jmGraph} graph jmGraph 实例
|
|
9993
|
+
* @param {Object} option 配置选项
|
|
9994
|
+
* @param {boolean} [option.isRegular=false] 是否为规则图形(凸多边形)
|
|
9995
|
+
* @param {boolean} [option.needCut=false] 是否需要切割处理
|
|
9996
|
+
* @param {Object} [option.control] 控制器对象
|
|
9997
|
+
*/
|
|
8087
9998
|
function WebglPath(graph, option) {
|
|
8088
9999
|
var _this;
|
|
8089
10000
|
|
|
8090
10001
|
_classCallCheck(this, WebglPath);
|
|
8091
10002
|
|
|
8092
|
-
_this = _super.call(this, graph, option);
|
|
10003
|
+
_this = _super.call(this, graph, option);
|
|
10004
|
+
/** @type {boolean} 是否为规则图形(凸多边形),规则图形处理更高效 */
|
|
8093
10005
|
|
|
8094
10006
|
_this.isRegular = option.isRegular || false;
|
|
10007
|
+
/** @type {boolean} 是否需要切割处理 */
|
|
10008
|
+
|
|
8095
10009
|
_this.needCut = option.needCut || false;
|
|
8096
10010
|
_this.control = option.control;
|
|
8097
|
-
|
|
10011
|
+
/** @type {Array<Object>} 路径点数组 */
|
|
10012
|
+
|
|
10013
|
+
_this.points = [];
|
|
10014
|
+
/** @type {Array} 缓存的缓冲区,避免每帧创建/销毁 */
|
|
8098
10015
|
|
|
8099
10016
|
_this.__cachedBuffers = [];
|
|
10017
|
+
/** @type {Object} 缓存的纹理 */
|
|
10018
|
+
|
|
8100
10019
|
_this.__cachedTexture = null;
|
|
10020
|
+
/** @type {string} 缓存纹理的 key */
|
|
10021
|
+
|
|
8101
10022
|
_this.__cachedTextureKey = null;
|
|
8102
10023
|
return _this;
|
|
8103
|
-
}
|
|
10024
|
+
}
|
|
10025
|
+
/** 释放缓存的 WebGL 资源 */
|
|
8104
10026
|
|
|
8105
10027
|
|
|
8106
10028
|
_createClass(WebglPath, [{
|
|
@@ -8127,7 +10049,13 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8127
10049
|
this.__cachedTexture = null;
|
|
8128
10050
|
this.__cachedTextureKey = null;
|
|
8129
10051
|
}
|
|
8130
|
-
}
|
|
10052
|
+
}
|
|
10053
|
+
/**
|
|
10054
|
+
* 获取或创建缓冲区,优先复用缓存
|
|
10055
|
+
* @param {Array} data 数据数组
|
|
10056
|
+
* @param {Object} attr 属性对象
|
|
10057
|
+
* @returns {Object} 缓冲区对象
|
|
10058
|
+
*/
|
|
8131
10059
|
|
|
8132
10060
|
}, {
|
|
8133
10061
|
key: "getOrCreateBuffer",
|
|
@@ -8151,13 +10079,23 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8151
10079
|
this.__cachedBuffers.push(buffer);
|
|
8152
10080
|
|
|
8153
10081
|
return buffer;
|
|
8154
|
-
}
|
|
10082
|
+
}
|
|
10083
|
+
/**
|
|
10084
|
+
* 应用变换到点
|
|
10085
|
+
* @param {Object} point 点坐标 {x, y}
|
|
10086
|
+
* @returns {Object} 变换后的点坐标
|
|
10087
|
+
*/
|
|
8155
10088
|
|
|
8156
10089
|
}, {
|
|
8157
10090
|
key: "applyTransform",
|
|
8158
10091
|
value: function applyTransform(point) {
|
|
8159
10092
|
return _get(_getPrototypeOf(WebglPath.prototype), "applyTransform", this).call(this, point);
|
|
8160
10093
|
}
|
|
10094
|
+
/**
|
|
10095
|
+
* 设置父级边界
|
|
10096
|
+
* @param {Object} [parentBounds] 父级边界 {left, top, width, height}
|
|
10097
|
+
*/
|
|
10098
|
+
|
|
8161
10099
|
}, {
|
|
8162
10100
|
key: "setParentBounds",
|
|
8163
10101
|
value: function setParentBounds() {
|
|
@@ -8225,17 +10163,18 @@ var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
|
8225
10163
|
key: "endDraw",
|
|
8226
10164
|
value: function endDraw() {
|
|
8227
10165
|
if (this.points) delete this.points;
|
|
8228
|
-
if (this.pathPoints) delete this.pathPoints;
|
|
8229
|
-
|
|
10166
|
+
if (this.pathPoints) delete this.pathPoints;
|
|
10167
|
+
this.needClose = false; // 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
10168
|
+
}
|
|
10169
|
+
/**
|
|
10170
|
+
* 标记路径需要闭合(不修改原始 points 数组)
|
|
10171
|
+
* 闭合逻辑由 stroke/fill 绘制方法自行处理
|
|
10172
|
+
*/
|
|
8230
10173
|
|
|
8231
10174
|
}, {
|
|
8232
10175
|
key: "closePath",
|
|
8233
10176
|
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
|
-
}
|
|
10177
|
+
this.needClose = true;
|
|
8239
10178
|
} // 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
8240
10179
|
|
|
8241
10180
|
}, {
|
|
@@ -9333,11 +11272,40 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9333
11272
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9334
11273
|
|
|
9335
11274
|
/**
|
|
9336
|
-
*
|
|
11275
|
+
* 圆弧类
|
|
11276
|
+
*
|
|
11277
|
+
* 绘制圆弧或扇形图形,继承自 jmPath。
|
|
11278
|
+
* 支持设置圆心、半径、起始角度和结束角度。
|
|
9337
11279
|
*
|
|
9338
11280
|
* @class jmArc
|
|
9339
11281
|
* @extends jmPath
|
|
9340
|
-
* @param {object} params
|
|
11282
|
+
* @param {object} params 圆弧参数
|
|
11283
|
+
* @param {object} [params.center] 圆弧中心点 {x, y}
|
|
11284
|
+
* @param {number} [params.radius] 圆弧半径
|
|
11285
|
+
* @param {number} [params.start=0] 圆弧起始角度(弧度)
|
|
11286
|
+
* @param {number} [params.end=Math.PI*2] 圆弧结束角度(弧度)
|
|
11287
|
+
* @param {boolean} [params.anticlockwise=false] 绘制方向:false=顺时针,true=逆时针
|
|
11288
|
+
* @param {boolean} [params.isFan=false] 是否绘制为扇形
|
|
11289
|
+
*
|
|
11290
|
+
* @example
|
|
11291
|
+
* // 创建圆弧
|
|
11292
|
+
* const arc = graph.createShape('arc', {
|
|
11293
|
+
* center: {x: 200, y: 200},
|
|
11294
|
+
* radius: 50,
|
|
11295
|
+
* start: 0,
|
|
11296
|
+
* end: Math.PI,
|
|
11297
|
+
* style: { stroke: '#000' }
|
|
11298
|
+
* });
|
|
11299
|
+
*
|
|
11300
|
+
* // 创建扇形
|
|
11301
|
+
* const fan = graph.createShape('arc', {
|
|
11302
|
+
* center: {x: 200, y: 200},
|
|
11303
|
+
* radius: 50,
|
|
11304
|
+
* start: 0,
|
|
11305
|
+
* end: Math.PI / 2,
|
|
11306
|
+
* isFan: true,
|
|
11307
|
+
* style: { fill: '#ff0000' }
|
|
11308
|
+
* });
|
|
9341
11309
|
*/
|
|
9342
11310
|
var jmArc = /*#__PURE__*/function (_jmPath) {
|
|
9343
11311
|
_inherits(jmArc, _jmPath);
|
|
@@ -9560,11 +11528,27 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9560
11528
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9561
11529
|
|
|
9562
11530
|
/**
|
|
9563
|
-
*
|
|
11531
|
+
* 箭头类
|
|
11532
|
+
*
|
|
11533
|
+
* 绘制箭头图形,支持空心和实心两种样式。
|
|
11534
|
+
* 箭头方向由起点和终点决定。
|
|
9564
11535
|
*
|
|
9565
11536
|
* @class jmArrow
|
|
9566
11537
|
* @extends jmPath
|
|
9567
|
-
* @param {object}
|
|
11538
|
+
* @param {object} params 箭头参数
|
|
11539
|
+
* @param {object} [params.start] 箭头起始点 {x, y}
|
|
11540
|
+
* @param {object} [params.end] 箭头终点(箭头尖端){x, y}
|
|
11541
|
+
* @param {number} [params.angle] 箭头角度(弧度),不指定则自动计算
|
|
11542
|
+
* @param {number} [params.offsetX=5] 箭头X方向偏移量
|
|
11543
|
+
* @param {number} [params.offsetY=8] 箭头Y方向偏移量
|
|
11544
|
+
*
|
|
11545
|
+
* @example
|
|
11546
|
+
* // 创建箭头
|
|
11547
|
+
* const arrow = graph.createShape('arrow', {
|
|
11548
|
+
* start: {x: 100, y: 100},
|
|
11549
|
+
* end: {x: 200, y: 100},
|
|
11550
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
11551
|
+
* });
|
|
9568
11552
|
*/
|
|
9569
11553
|
var jmArrow = /*#__PURE__*/function (_jmPath) {
|
|
9570
11554
|
_inherits(jmArrow, _jmPath);
|
|
@@ -9788,11 +11772,25 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9788
11772
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9789
11773
|
|
|
9790
11774
|
/**
|
|
9791
|
-
*
|
|
11775
|
+
* 带箭头的直线类
|
|
11776
|
+
*
|
|
11777
|
+
* 绘制带箭头的直线,继承自 jmLine。
|
|
11778
|
+
* 箭头位于直线的末端。
|
|
9792
11779
|
*
|
|
9793
11780
|
* @class jmArrowLine
|
|
9794
11781
|
* @extends jmLine
|
|
9795
|
-
* @param {object} params
|
|
11782
|
+
* @param {object} params 直线参数
|
|
11783
|
+
* @param {object} [params.start] 直线起始点 {x, y}
|
|
11784
|
+
* @param {object} [params.end] 直线终结点 {x, y}
|
|
11785
|
+
* @param {boolean} [params.arrowVisible=true] 是否显示箭头
|
|
11786
|
+
*
|
|
11787
|
+
* @example
|
|
11788
|
+
* // 创建带箭头的直线
|
|
11789
|
+
* const arrowLine = graph.createShape('arrowLine', {
|
|
11790
|
+
* start: {x: 100, y: 100},
|
|
11791
|
+
* end: {x: 200, y: 100},
|
|
11792
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
11793
|
+
* });
|
|
9796
11794
|
*/
|
|
9797
11795
|
var jmArrowLine = /*#__PURE__*/function (_jmLine) {
|
|
9798
11796
|
_inherits(jmArrowLine, _jmLine);
|
|
@@ -9876,12 +11874,37 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
9876
11874
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
9877
11875
|
|
|
9878
11876
|
/**
|
|
9879
|
-
*
|
|
9880
|
-
*
|
|
11877
|
+
* 贝塞尔曲线类
|
|
11878
|
+
*
|
|
11879
|
+
* 绘制 N 阶贝塞尔曲线,参数 points 中为控制点。
|
|
11880
|
+
* 支持 2 阶(二次贝塞尔)、3 阶(三次贝塞尔)及更高阶曲线。
|
|
9881
11881
|
*
|
|
9882
11882
|
* @class jmBezier
|
|
9883
11883
|
* @extends jmPath
|
|
9884
11884
|
* @param {object} params 参数
|
|
11885
|
+
* @param {array} [params.points] 控制点数组 [{x, y}, ...]
|
|
11886
|
+
*
|
|
11887
|
+
* @example
|
|
11888
|
+
* // 创建二次贝塞尔曲线(3个控制点)
|
|
11889
|
+
* const quadBezier = graph.createShape('bezier', {
|
|
11890
|
+
* points: [
|
|
11891
|
+
* {x: 100, y: 100}, // 起点
|
|
11892
|
+
* {x: 200, y: 50}, // 控制点
|
|
11893
|
+
* {x: 300, y: 100} // 终点
|
|
11894
|
+
* ],
|
|
11895
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
11896
|
+
* });
|
|
11897
|
+
*
|
|
11898
|
+
* // 创建三次贝塞尔曲线(4个控制点)
|
|
11899
|
+
* const cubicBezier = graph.createShape('bezier', {
|
|
11900
|
+
* points: [
|
|
11901
|
+
* {x: 100, y: 100}, // 起点
|
|
11902
|
+
* {x: 150, y: 50}, // 控制点1
|
|
11903
|
+
* {x: 250, y: 50}, // 控制点2
|
|
11904
|
+
* {x: 300, y: 100} // 终点
|
|
11905
|
+
* ],
|
|
11906
|
+
* style: { stroke: '#ff0000' }
|
|
11907
|
+
* });
|
|
9885
11908
|
*/
|
|
9886
11909
|
var jmBezier = /*#__PURE__*/function (_jmPath) {
|
|
9887
11910
|
_inherits(jmBezier, _jmPath);
|
|
@@ -9895,8 +11918,12 @@ var jmBezier = /*#__PURE__*/function (_jmPath) {
|
|
|
9895
11918
|
|
|
9896
11919
|
_classCallCheck(this, jmBezier);
|
|
9897
11920
|
|
|
9898
|
-
//
|
|
9899
|
-
|
|
11921
|
+
// 参数初始化
|
|
11922
|
+
params = params || {}; // 曲线默认不封闭
|
|
11923
|
+
|
|
11924
|
+
if (!params.style) params.style = {};
|
|
11925
|
+
|
|
11926
|
+
if (typeof params.style.close !== true) {
|
|
9900
11927
|
params.style.close = false;
|
|
9901
11928
|
}
|
|
9902
11929
|
|
|
@@ -10052,11 +12079,27 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10052
12079
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10053
12080
|
|
|
10054
12081
|
/**
|
|
10055
|
-
*
|
|
12082
|
+
* 圆形类
|
|
12083
|
+
*
|
|
12084
|
+
* 绘制圆形图形,继承自 jmArc。
|
|
12085
|
+
* 可以通过 center 和 radius 指定圆心和半径,
|
|
12086
|
+
* 也可以通过 width 和 height 指定圆的尺寸。
|
|
10056
12087
|
*
|
|
10057
12088
|
* @class jmCircle
|
|
10058
12089
|
* @extends jmArc
|
|
10059
|
-
* @param {object} params
|
|
12090
|
+
* @param {object} params 圆的参数
|
|
12091
|
+
* @param {object} [params.center] 圆心坐标 {x, y}
|
|
12092
|
+
* @param {number} [params.radius] 圆半径(优先使用)
|
|
12093
|
+
* @param {number} [params.width] 圆宽度(无 radius 时使用)
|
|
12094
|
+
* @param {number} [params.height] 圆高度(无 radius 时使用)
|
|
12095
|
+
*
|
|
12096
|
+
* @example
|
|
12097
|
+
* // 创建圆形
|
|
12098
|
+
* const circle = graph.createShape('circle', {
|
|
12099
|
+
* center: {x: 200, y: 200},
|
|
12100
|
+
* radius: 50,
|
|
12101
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
12102
|
+
* });
|
|
10060
12103
|
*/
|
|
10061
12104
|
var jmCircle = /*#__PURE__*/function (_jmArc) {
|
|
10062
12105
|
_inherits(jmCircle, _jmArc);
|
|
@@ -10182,9 +12225,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10182
12225
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10183
12226
|
|
|
10184
12227
|
/**
|
|
10185
|
-
*
|
|
10186
|
-
*
|
|
10187
|
-
*
|
|
12228
|
+
* 椭圆类
|
|
12229
|
+
*
|
|
12230
|
+
* 绘制椭圆图形,继承自 jmArc。
|
|
12231
|
+
* 可以指定起始角度和结束角度来绘制椭圆弧。
|
|
10188
12232
|
*
|
|
10189
12233
|
* @class jmEllipse
|
|
10190
12234
|
* @extends jmArc
|
|
@@ -10195,6 +12239,15 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
10195
12239
|
* @param {number} [params.startAngle=0] 起始角度(弧度)
|
|
10196
12240
|
* @param {number} [params.endAngle=Math.PI*2] 结束角度(弧度)
|
|
10197
12241
|
* @param {boolean} [params.anticlockwise=false] 是否逆时针绘制
|
|
12242
|
+
*
|
|
12243
|
+
* @example
|
|
12244
|
+
* // 创建椭圆
|
|
12245
|
+
* const ellipse = graph.createShape('ellipse', {
|
|
12246
|
+
* center: {x: 200, y: 200},
|
|
12247
|
+
* width: 200,
|
|
12248
|
+
* height: 100,
|
|
12249
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
12250
|
+
* });
|
|
10198
12251
|
*/
|
|
10199
12252
|
var jmEllipse = /*#__PURE__*/function (_jmArc) {
|
|
10200
12253
|
_inherits(jmEllipse, _jmArc);
|
|
@@ -10328,11 +12381,31 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10328
12381
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10329
12382
|
|
|
10330
12383
|
/**
|
|
10331
|
-
*
|
|
12384
|
+
* 空心圆弧类
|
|
12385
|
+
*
|
|
12386
|
+
* 绘制空心圆弧(圆环弧),继承自 jmArc。
|
|
12387
|
+
* 由内圆半径和外圆半径定义环形区域。
|
|
10332
12388
|
*
|
|
10333
12389
|
* @class jmHArc
|
|
10334
12390
|
* @extends jmArc
|
|
10335
|
-
* @param {object} params
|
|
12391
|
+
* @param {object} params 空心圆弧参数
|
|
12392
|
+
* @param {object} [params.center] 圆弧中心点 {x, y}
|
|
12393
|
+
* @param {number} [params.minRadius] 内圆半径
|
|
12394
|
+
* @param {number} [params.maxRadius] 外圆半径
|
|
12395
|
+
* @param {number} [params.start=0] 起始角度(弧度)
|
|
12396
|
+
* @param {number} [params.end=Math.PI*2] 结束角度(弧度)
|
|
12397
|
+
* @param {boolean} [params.anticlockwise=false] 是否逆时针绘制
|
|
12398
|
+
*
|
|
12399
|
+
* @example
|
|
12400
|
+
* // 创建空心圆弧
|
|
12401
|
+
* const hArc = graph.createShape('hArc', {
|
|
12402
|
+
* center: {x: 200, y: 200},
|
|
12403
|
+
* minRadius: 30,
|
|
12404
|
+
* maxRadius: 50,
|
|
12405
|
+
* start: 0,
|
|
12406
|
+
* end: Math.PI,
|
|
12407
|
+
* style: { fill: '#ff0000' }
|
|
12408
|
+
* });
|
|
10336
12409
|
*/
|
|
10337
12410
|
var jmHArc = /*#__PURE__*/function (_jmArc) {
|
|
10338
12411
|
_inherits(jmHArc, _jmArc);
|
|
@@ -10492,13 +12565,41 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10492
12565
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10493
12566
|
|
|
10494
12567
|
/**
|
|
10495
|
-
*
|
|
10496
|
-
* params参数中image为指定的图片源地址或图片img对象,
|
|
10497
|
-
* postion=当前控件的位置,width=其宽度,height=高度,sourcePosition=从当前图片中展示的位置,sourceWidth=从图片中截取的宽度,sourceHeight=从图片中截取的高度。
|
|
12568
|
+
* 图片类
|
|
10498
12569
|
*
|
|
12570
|
+
* 显示图片控件,支持从 URL 或 Image 对象加载图片。
|
|
12571
|
+
* 支持图片裁剪和缩放功能。
|
|
12572
|
+
*
|
|
10499
12573
|
* @class jmImage
|
|
10500
12574
|
* @extends jmControl
|
|
10501
12575
|
* @param {object} params 控件参数
|
|
12576
|
+
* @param {string|HTMLImageElement} [params.image] 图片源地址或图片对象
|
|
12577
|
+
* @param {object} [params.position] 图片位置 {x, y}
|
|
12578
|
+
* @param {number} [params.width] 图片显示宽度
|
|
12579
|
+
* @param {number} [params.height] 图片显示高度
|
|
12580
|
+
* @param {object} [params.sourcePosition] 图片裁剪起始位置 {x, y}
|
|
12581
|
+
* @param {number} [params.sourceWidth] 图片裁剪宽度
|
|
12582
|
+
* @param {number} [params.sourceHeight] 图片裁剪高度
|
|
12583
|
+
*
|
|
12584
|
+
* @example
|
|
12585
|
+
* // 从 URL 加载图片
|
|
12586
|
+
* const img = graph.createShape('image', {
|
|
12587
|
+
* image: 'path/to/image.png',
|
|
12588
|
+
* position: {x: 100, y: 100},
|
|
12589
|
+
* width: 200,
|
|
12590
|
+
* height: 150
|
|
12591
|
+
* });
|
|
12592
|
+
*
|
|
12593
|
+
* // 裁剪图片
|
|
12594
|
+
* const croppedImg = graph.createShape('image', {
|
|
12595
|
+
* image: 'path/to/sprite.png',
|
|
12596
|
+
* position: {x: 100, y: 100},
|
|
12597
|
+
* sourcePosition: {x: 0, y: 0},
|
|
12598
|
+
* sourceWidth: 50,
|
|
12599
|
+
* sourceHeight: 50,
|
|
12600
|
+
* width: 100,
|
|
12601
|
+
* height: 100
|
|
12602
|
+
* });
|
|
10502
12603
|
*/
|
|
10503
12604
|
var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
10504
12605
|
_inherits(jmImage, _jmControl);
|
|
@@ -10800,11 +12901,32 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10800
12901
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10801
12902
|
|
|
10802
12903
|
/**
|
|
10803
|
-
*
|
|
12904
|
+
* 文本标签类
|
|
12905
|
+
*
|
|
12906
|
+
* 显示文字控件,支持多种文本样式和对齐方式。
|
|
10804
12907
|
*
|
|
10805
12908
|
* @class jmLabel
|
|
10806
12909
|
* @extends jmControl
|
|
10807
|
-
* @param {object} params
|
|
12910
|
+
* @param {object} params 参数
|
|
12911
|
+
* @param {string} [params.text=''] 显示的文字内容
|
|
12912
|
+
* @param {object} [params.center] 文本中心点坐标
|
|
12913
|
+
* @param {object} [params.style] 样式对象
|
|
12914
|
+
* @param {string} [params.style.font] 字体样式
|
|
12915
|
+
* @param {string} [params.style.textAlign='left'] 水平对齐方式
|
|
12916
|
+
* @param {string} [params.style.textBaseline='middle'] 垂直对齐方式
|
|
12917
|
+
* @param {number} [params.style.maxWidth] 最大宽度(用于自动换行)
|
|
12918
|
+
*
|
|
12919
|
+
* @example
|
|
12920
|
+
* // 创建文本标签
|
|
12921
|
+
* const label = graph.createShape('label', {
|
|
12922
|
+
* position: {x: 100, y: 100},
|
|
12923
|
+
* text: 'Hello World',
|
|
12924
|
+
* style: {
|
|
12925
|
+
* fill: '#000',
|
|
12926
|
+
* font: '20px Arial',
|
|
12927
|
+
* textAlign: 'center'
|
|
12928
|
+
* }
|
|
12929
|
+
* });
|
|
10808
12930
|
*/
|
|
10809
12931
|
var jmLabel = /*#__PURE__*/function (_jmControl) {
|
|
10810
12932
|
_inherits(jmLabel, _jmControl);
|
|
@@ -11210,11 +13332,34 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11210
13332
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11211
13333
|
|
|
11212
13334
|
/**
|
|
11213
|
-
*
|
|
13335
|
+
* 直线类
|
|
13336
|
+
*
|
|
13337
|
+
* 绘制从起点到终点的直线,支持实线和虚线两种模式。
|
|
11214
13338
|
*
|
|
11215
13339
|
* @class jmLine
|
|
11216
13340
|
* @extends jmPath
|
|
11217
|
-
* @param {object} params
|
|
13341
|
+
* @param {object} params 直线参数
|
|
13342
|
+
* @param {object} [params.start] 起始点 {x, y}
|
|
13343
|
+
* @param {object} [params.end] 结束点 {x, y}
|
|
13344
|
+
* @param {string} [params.lineType='solid'] 线类型:'solid'=实线,'dotted'=虚线
|
|
13345
|
+
* @param {number} [params.dashLength=4] 虚线间隔长度
|
|
13346
|
+
*
|
|
13347
|
+
* @example
|
|
13348
|
+
* // 创建实线
|
|
13349
|
+
* const line = graph.createShape('line', {
|
|
13350
|
+
* start: {x: 0, y: 0},
|
|
13351
|
+
* end: {x: 100, y: 100},
|
|
13352
|
+
* style: { stroke: '#000', lineWidth: 2 }
|
|
13353
|
+
* });
|
|
13354
|
+
*
|
|
13355
|
+
* // 创建虚线
|
|
13356
|
+
* const dottedLine = graph.createShape('line', {
|
|
13357
|
+
* start: {x: 0, y: 0},
|
|
13358
|
+
* end: {x: 100, y: 100},
|
|
13359
|
+
* lineType: 'dotted',
|
|
13360
|
+
* dashLength: 5,
|
|
13361
|
+
* style: { stroke: '#000' }
|
|
13362
|
+
* });
|
|
11218
13363
|
*/
|
|
11219
13364
|
var jmLine = /*#__PURE__*/function (_jmPath) {
|
|
11220
13365
|
_inherits(jmLine, _jmPath);
|
|
@@ -11365,9 +13510,11 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11365
13510
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11366
13511
|
|
|
11367
13512
|
/**
|
|
11368
|
-
*
|
|
11369
|
-
*
|
|
11370
|
-
*
|
|
13513
|
+
* 多边形类
|
|
13514
|
+
*
|
|
13515
|
+
* 绘制多边形图形,支持规则多边形和自定义多边形。
|
|
13516
|
+
* 规则多边形通过边数和半径自动计算顶点,
|
|
13517
|
+
* 自定义多边形通过顶点数组定义。
|
|
11371
13518
|
*
|
|
11372
13519
|
* @class jmPolygon
|
|
11373
13520
|
* @extends jmPath
|
|
@@ -11376,6 +13523,27 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
11376
13523
|
* @param {number} [params.sides=3] 多边形边数(3-100)
|
|
11377
13524
|
* @param {number} [params.radius=50] 多边形半径(像素)
|
|
11378
13525
|
* @param {object} [params.center={x:0,y:0}] 多边形中心点坐标
|
|
13526
|
+
*
|
|
13527
|
+
* @example
|
|
13528
|
+
* // 创建正六边形
|
|
13529
|
+
* const hexagon = graph.createShape('polygon', {
|
|
13530
|
+
* center: {x: 200, y: 200},
|
|
13531
|
+
* sides: 6,
|
|
13532
|
+
* radius: 50,
|
|
13533
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13534
|
+
* });
|
|
13535
|
+
*
|
|
13536
|
+
* // 创建自定义多边形
|
|
13537
|
+
* const polygon = graph.createShape('polygon', {
|
|
13538
|
+
* points: [
|
|
13539
|
+
* {x: 100, y: 100},
|
|
13540
|
+
* {x: 200, y: 50},
|
|
13541
|
+
* {x: 300, y: 100},
|
|
13542
|
+
* {x: 250, y: 200},
|
|
13543
|
+
* {x: 150, y: 200}
|
|
13544
|
+
* ],
|
|
13545
|
+
* style: { fill: '#00ff00' }
|
|
13546
|
+
* });
|
|
11379
13547
|
*/
|
|
11380
13548
|
var jmPolygon = /*#__PURE__*/function (_jmPath) {
|
|
11381
13549
|
_inherits(jmPolygon, _jmPath);
|
|
@@ -11561,11 +13729,26 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11561
13729
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11562
13730
|
|
|
11563
13731
|
/**
|
|
11564
|
-
*
|
|
13732
|
+
* 棱形类
|
|
13733
|
+
*
|
|
13734
|
+
* 绘制棱形(菱形)图形,继承自 jmPath。
|
|
13735
|
+
* 棱形由中心点、宽度和高度定义。
|
|
11565
13736
|
*
|
|
11566
13737
|
* @class jmPrismatic
|
|
11567
13738
|
* @extends jmPath
|
|
11568
|
-
* @param {object} params 参数
|
|
13739
|
+
* @param {object} params 参数
|
|
13740
|
+
* @param {object} [params.center] 棱形中心点 {x, y}
|
|
13741
|
+
* @param {number} [params.width] 棱形宽度
|
|
13742
|
+
* @param {number} [params.height] 棱形高度
|
|
13743
|
+
*
|
|
13744
|
+
* @example
|
|
13745
|
+
* // 创建棱形
|
|
13746
|
+
* const prismatic = graph.createShape('prismatic', {
|
|
13747
|
+
* center: {x: 200, y: 200},
|
|
13748
|
+
* width: 100,
|
|
13749
|
+
* height: 80,
|
|
13750
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13751
|
+
* });
|
|
11569
13752
|
*/
|
|
11570
13753
|
var jmPrismatic = /*#__PURE__*/function (_jmPath) {
|
|
11571
13754
|
_inherits(jmPrismatic, _jmPath);
|
|
@@ -11685,12 +13868,37 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11685
13868
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
11686
13869
|
|
|
11687
13870
|
/**
|
|
11688
|
-
*
|
|
13871
|
+
* 矩形类
|
|
13872
|
+
*
|
|
13873
|
+
* 绘制矩形图形,支持圆角和虚线边框。
|
|
13874
|
+
* 圆角可以统一设置或四角独立设置。
|
|
11689
13875
|
*
|
|
11690
13876
|
* @class jmRect
|
|
11691
13877
|
* @extends jmPath
|
|
11692
|
-
* @param {object} params 参数
|
|
11693
|
-
*
|
|
13878
|
+
* @param {object} params 参数
|
|
13879
|
+
* @param {object} [params.position] 矩形左上角顶点坐标 {x, y}
|
|
13880
|
+
* @param {number} [params.width] 矩形宽度
|
|
13881
|
+
* @param {number} [params.height] 矩形高度
|
|
13882
|
+
* @param {number|object} [params.radius] 边角弧度,支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
13883
|
+
*
|
|
13884
|
+
* @example
|
|
13885
|
+
* // 创建普通矩形
|
|
13886
|
+
* const rect = graph.createShape('rect', {
|
|
13887
|
+
* position: {x: 100, y: 100},
|
|
13888
|
+
* width: 200,
|
|
13889
|
+
* height: 150,
|
|
13890
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
13891
|
+
* });
|
|
13892
|
+
*
|
|
13893
|
+
* // 创建圆角矩形
|
|
13894
|
+
* const roundedRect = graph.createShape('rect', {
|
|
13895
|
+
* position: {x: 100, y: 100},
|
|
13896
|
+
* width: 200,
|
|
13897
|
+
* height: 150,
|
|
13898
|
+
* radius: 10, // 四角统一圆角
|
|
13899
|
+
* // 或 radius: { topLeft: 5, topRight: 10, bottomRight: 15, bottomLeft: 20 }
|
|
13900
|
+
* style: { fill: '#00ff00' }
|
|
13901
|
+
* });
|
|
11694
13902
|
*/
|
|
11695
13903
|
var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
11696
13904
|
_inherits(jmRect, _jmPath);
|
|
@@ -12046,12 +14254,32 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
12046
14254
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12047
14255
|
|
|
12048
14256
|
/**
|
|
12049
|
-
*
|
|
12050
|
-
*
|
|
12051
|
-
*
|
|
14257
|
+
* 可缩放控件类
|
|
14258
|
+
*
|
|
14259
|
+
* 继承自 jmRect,在矩形四边和四角添加可拖拽的控制点。
|
|
14260
|
+
* 用于实现图形的缩放和调整功能。
|
|
12052
14261
|
*
|
|
12053
14262
|
* @class jmResize
|
|
12054
14263
|
* @extends jmRect
|
|
14264
|
+
* @param {object} params 控件参数
|
|
14265
|
+
* @param {boolean} [params.resizable=true] 是否可缩放
|
|
14266
|
+
* @param {boolean} [params.movable] 是否可移动
|
|
14267
|
+
* @param {number} [params.rectSize=8] 控制点大小
|
|
14268
|
+
*
|
|
14269
|
+
* @example
|
|
14270
|
+
* // 创建可缩放矩形
|
|
14271
|
+
* const resize = graph.createShape('resize', {
|
|
14272
|
+
* position: {x: 100, y: 100},
|
|
14273
|
+
* width: 200,
|
|
14274
|
+
* height: 150,
|
|
14275
|
+
* resizable: true,
|
|
14276
|
+
* movable: true
|
|
14277
|
+
* });
|
|
14278
|
+
*
|
|
14279
|
+
* // 监听缩放事件
|
|
14280
|
+
* resize.on('resize', (px, py, dx, dy) => {
|
|
14281
|
+
* console.log('缩放中', px, py, dx, dy);
|
|
14282
|
+
* });
|
|
12055
14283
|
*/
|
|
12056
14284
|
var jmResize = /*#__PURE__*/function (_jmRect) {
|
|
12057
14285
|
_inherits(jmResize, _jmRect);
|
|
@@ -12390,7 +14618,7 @@ var jmResize = /*#__PURE__*/function (_jmRect) {
|
|
|
12390
14618
|
|
|
12391
14619
|
case 6:
|
|
12392
14620
|
{
|
|
12393
|
-
r.position.x = (newLocation.width - r.
|
|
14621
|
+
r.position.x = (newLocation.width - r.width) / 2;
|
|
12394
14622
|
r.position.y = newLocation.height - r.height / 2;
|
|
12395
14623
|
break;
|
|
12396
14624
|
}
|
|
@@ -12446,18 +14674,36 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
12446
14674
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
12447
14675
|
|
|
12448
14676
|
/**
|
|
12449
|
-
*
|
|
12450
|
-
*
|
|
12451
|
-
*
|
|
14677
|
+
* 星形类
|
|
14678
|
+
*
|
|
14679
|
+
* 绘制星形图形,支持自定义顶点数和内外半径。
|
|
14680
|
+
* 星形由交替的外半径和内半径顶点组成。
|
|
12452
14681
|
*
|
|
12453
14682
|
* @class jmStar
|
|
12454
14683
|
* @extends jmPath
|
|
12455
14684
|
* @param {object} params 星形的参数
|
|
12456
|
-
* @param {array} [params.points] 自定义顶点数组,如果提供则忽略其他参数
|
|
12457
14685
|
* @param {number} [params.points=5] 星形顶点数(角数,3-50)
|
|
12458
14686
|
* @param {number} [params.radius=50] 星形外半径(从中心到尖角的距离)
|
|
12459
14687
|
* @param {number} [params.innerRadius=25] 星形内半径(从中心到凹陷处的距离)
|
|
12460
14688
|
* @param {object} [params.center={x:0,y:0}] 星形中心点坐标
|
|
14689
|
+
*
|
|
14690
|
+
* @example
|
|
14691
|
+
* // 创建五角星
|
|
14692
|
+
* const star = graph.createShape('star', {
|
|
14693
|
+
* center: {x: 200, y: 200},
|
|
14694
|
+
* points: 5,
|
|
14695
|
+
* radius: 50,
|
|
14696
|
+
* innerRadius: 25,
|
|
14697
|
+
* style: { fill: '#ff0000', stroke: '#000' }
|
|
14698
|
+
* });
|
|
14699
|
+
*
|
|
14700
|
+
* // 创建六角星
|
|
14701
|
+
* const hexStar = graph.createShape('star', {
|
|
14702
|
+
* center: {x: 200, y: 200},
|
|
14703
|
+
* points: 6,
|
|
14704
|
+
* radius: 60,
|
|
14705
|
+
* innerRadius: 30
|
|
14706
|
+
* });
|
|
12461
14707
|
*/
|
|
12462
14708
|
var jmStar = /*#__PURE__*/function (_jmPath) {
|
|
12463
14709
|
_inherits(jmStar, _jmPath);
|