jmgraph 3.2.27 → 3.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/jmgraph.core.min.js +1 -1
  2. package/dist/jmgraph.core.min.js.map +1 -1
  3. package/dist/jmgraph.js +2661 -415
  4. package/dist/jmgraph.min.js +1 -1
  5. package/package.json +1 -1
  6. package/src/core/jmControl.js +827 -127
  7. package/src/core/jmEvents.js +154 -0
  8. package/src/core/jmFilter.js +38 -1
  9. package/src/core/jmGradient.js +47 -2
  10. package/src/core/jmGraph.js +51 -7
  11. package/src/core/jmLayer.js +34 -2
  12. package/src/core/jmList.js +167 -0
  13. package/src/core/jmObject.js +128 -8
  14. package/src/core/jmPath.js +43 -5
  15. package/src/core/jmProperty.js +181 -2
  16. package/src/core/jmShadow.js +36 -7
  17. package/src/core/jmUtils.js +149 -12
  18. package/src/lib/webgl/base.js +211 -83
  19. package/src/lib/webgl/core/buffer.js +43 -12
  20. package/src/lib/webgl/core/mapSize.js +16 -7
  21. package/src/lib/webgl/core/mapType.js +41 -22
  22. package/src/lib/webgl/core/program.js +94 -54
  23. package/src/lib/webgl/core/shader.js +20 -8
  24. package/src/lib/webgl/core/texture.js +55 -32
  25. package/src/lib/webgl/gradient.js +49 -17
  26. package/src/lib/webgl/index.js +173 -24
  27. package/src/lib/webgl/path.js +61 -12
  28. package/src/shapes/jmArc.js +48 -2
  29. package/src/shapes/jmArrow.js +35 -2
  30. package/src/shapes/jmArrowLine.js +33 -2
  31. package/src/shapes/jmBezier.js +50 -4
  32. package/src/shapes/jmCircle.js +35 -2
  33. package/src/shapes/jmEllipse.js +29 -3
  34. package/src/shapes/jmHArc.js +39 -2
  35. package/src/shapes/jmImage.js +49 -3
  36. package/src/shapes/jmLabel.js +41 -2
  37. package/src/shapes/jmLine.js +42 -2
  38. package/src/shapes/jmPolygon.js +42 -3
  39. package/src/shapes/jmPrismatic.js +34 -2
  40. package/src/shapes/jmRect.js +45 -3
  41. package/src/shapes/jmResize.js +42 -4
  42. package/src/shapes/jmStar.js +38 -4
@@ -1,6 +1,33 @@
1
1
 
2
+ /**
3
+ * @fileoverview jmGraph 工具类
4
+ *
5
+ * jmUtils 是 jmGraph 库的核心工具类,提供了一系列静态工具方法:
6
+ * - 对象克隆与深拷贝
7
+ * - 事件绑定与解绑
8
+ * - DOM 元素位置计算
9
+ * - 几何计算(点在多边形内判断、旋转等)
10
+ * - 颜色解析与转换
11
+ * - 字符串处理
12
+ *
13
+ * 所有方法都是静态的,可以直接通过 jmUtils.methodName() 调用。
14
+ *
15
+ * @module jmUtils
16
+ * @author jmGraph Team
17
+ * @license MIT
18
+ */
19
+
2
20
  import { jmList } from './jmList.js';
3
21
 
22
+ /**
23
+ * CSS 颜色关键字映射表
24
+ *
25
+ * 包含所有 CSS 标准颜色名称到十六进制值的映射。
26
+ * 支持 147 种命名颜色 + CSS 系统颜色。
27
+ *
28
+ * @constant {Object.<string, string>}
29
+ * @private
30
+ */
4
31
  const colorKeywords = {
5
32
  aliceblue: "#f0f8ff",
6
33
  antiquewhite: "#faebd7",
@@ -182,11 +209,22 @@ const colorKeywords = {
182
209
  };
183
210
 
184
211
  /**
185
- * 画图基础对象
186
- * 当前库的工具类
212
+ * jmGraph 工具类
213
+ *
214
+ * 提供常用的静态工具方法,包括对象操作、事件处理、几何计算、颜色转换等。
187
215
  *
188
216
  * @class jmUtils
189
217
  * @static
218
+ *
219
+ * @example
220
+ * // 克隆对象
221
+ * const newObj = jmUtils.clone({ a: 1, b: 2 });
222
+ *
223
+ * // 绑定事件
224
+ * jmUtils.bindEvent(element, 'click', handler);
225
+ *
226
+ * // 检查点是否在多边形内
227
+ * const inside = jmUtils.pointInPolygon({x: 10, y: 10}, polygonPoints);
190
228
  */
191
229
  export default class jmUtils {
192
230
  /**
@@ -342,12 +380,12 @@ export default class jmUtils {
342
380
  el = el.offsetParent;
343
381
  }
344
382
  }
345
- else if(el.x) {
346
- pos.left += el.x;
347
- }
348
- else if(el.x){
349
- pos.top += el.y;
350
- }
383
+ else if(el.x) {
384
+ pos.left += el.x;
385
+ }
386
+ else if(el.y){
387
+ pos.top += el.y;
388
+ }
351
389
  return pos;
352
390
  }
353
391
  /**
@@ -471,6 +509,30 @@ export default class jmUtils {
471
509
  return this.rayCasting(pt, polygon, offset);
472
510
  }
473
511
 
512
+ /**
513
+ * 判断点是否在线段上
514
+ *
515
+ * 通过计算点到线段的垂直距离来判断点是否在线段上。
516
+ * 同时检查点是否在线段的范围内(不仅仅是直线上)。
517
+ *
518
+ * @method pointOnLine
519
+ * @static
520
+ * @private
521
+ * @param {Object} pt 待检测的点 {x, y}
522
+ * @param {Object} p1 线段起点 {x, y}
523
+ * @param {Object} p2 线段终点 {x, y}
524
+ * @param {number} offset 允许的偏差值(像素)
525
+ * @returns {number} 0=不在线段上, 1=在线段上
526
+ *
527
+ * @example
528
+ * const onLine = jmUtils.pointOnLine(
529
+ * {x: 5, y: 5}, // 待检测点
530
+ * {x: 0, y: 0}, // 起点
531
+ * {x: 10, y: 10}, // 终点
532
+ * 2 // 允许偏差
533
+ * );
534
+ * // 返回 1,点在对角线上
535
+ */
474
536
  static pointOnLine(pt, p1, p2, offset) {
475
537
  const minX = Math.min(p1.x, p2.x);
476
538
  const maxX = Math.max(p1.x, p2.x);
@@ -511,6 +573,25 @@ export default class jmUtils {
511
573
  return 0;
512
574
  }
513
575
 
576
+ /**
577
+ * 射线法判断点是否在多边形内部
578
+ *
579
+ * 从待测点向右发射一条水平射线,计算与多边形边界的交点数量。
580
+ * - 交点数为奇数:点在多边形内部
581
+ * - 交点数为偶数:点在多边形外部
582
+ *
583
+ * 这是判断点是否在任意多边形内的经典算法,时间复杂度 O(n)。
584
+ *
585
+ * @method rayCasting
586
+ * @static
587
+ * @private
588
+ * @param {Object} pt 待检测的点 {x, y}
589
+ * @param {Array<Object>} polygon 多边形顶点数组 [{x, y}, ...]
590
+ * @param {number} offset 允许的偏差值(未使用)
591
+ * @returns {number} 0=在多边形外部, 2=在多边形内部
592
+ *
593
+ * @see {@link https://en.wikipedia.org/wiki/Point_in_polygon Point in polygon - Wikipedia}
594
+ */
514
595
  static rayCasting(pt, polygon, offset) {
515
596
  const n = polygon.length;
516
597
  let inside = false;
@@ -884,8 +965,19 @@ export default class jmUtils {
884
965
  }
885
966
 
886
967
  /**
887
- * 255的rgb值转为0-1的值
888
- * @param {rgba} color 颜色
968
+ * 将 RGB 颜色值从 0-255 范围转换为 0-1 范围
969
+ *
970
+ * WebGL 中的颜色值通常使用 0-1 的浮点数表示,
971
+ * 此方法用于将标准 RGB 值转换为 WebGL 兼容格式。
972
+ *
973
+ * @method rgbToDecimal
974
+ * @static
975
+ * @param {Object} color 颜色对象 {r, g, b, a?}
976
+ * @returns {Object} 转换后的颜色对象 {r, g, b, a?},其中 r/g/b 为 0-1 范围
977
+ *
978
+ * @example
979
+ * const color = jmUtils.rgbToDecimal({ r: 255, g: 128, b: 64 });
980
+ * // 返回 { r: 1, g: 0.502, b: 0.251 }
889
981
  */
890
982
  static rgbToDecimal(color) {
891
983
  color = this.clone(color);
@@ -895,7 +987,15 @@ export default class jmUtils {
895
987
  return color;
896
988
  }
897
989
 
898
- //255值转为0-1的小数
990
+ /**
991
+ * 将字节值(0-255)转换为小数(0-1)
992
+ *
993
+ * @method byteToDecimal
994
+ * @static
995
+ * @private
996
+ * @param {number} b 字节值(0-255)
997
+ * @returns {number} 小数值(0-1)
998
+ */
899
999
  static byteToDecimal(b) {
900
1000
  return b / 255;
901
1001
  }
@@ -938,11 +1038,48 @@ export default class jmUtils {
938
1038
  }
939
1039
  return r;
940
1040
  }
941
- // window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
1041
+ /**
1042
+ * 请求动画帧
1043
+ *
1044
+ * 封装浏览器原生的 requestAnimationFrame 方法,提供跨浏览器兼容性。
1045
+ * 在不支持 requestAnimationFrame 的环境中降级为 setTimeout。
1046
+ *
1047
+ * @method requestAnimationFrame
1048
+ * @static
1049
+ * @param {Function} callback 动画帧回调函数,接收时间戳参数
1050
+ * @param {Window} [win] 可选的窗口对象(用于多窗口环境)
1051
+ * @returns {number} 动画帧请求ID,用于取消
1052
+ *
1053
+ * @example
1054
+ * let animationId;
1055
+ * function animate(timestamp) {
1056
+ * // 更新动画
1057
+ * animationId = jmUtils.requestAnimationFrame(animate);
1058
+ * }
1059
+ * animationId = jmUtils.requestAnimationFrame(animate);
1060
+ *
1061
+ * // 取消动画
1062
+ * jmUtils.cancelAnimationFrame(animationId);
1063
+ */
942
1064
  static requestAnimationFrame(callback, win) {
943
1065
  let fun = win && win.requestAnimationFrame? win.requestAnimationFrame: (typeof window !== 'undefined' && window.requestAnimationFrame? window.requestAnimationFrame: setTimeout);
944
1066
  return fun(callback, 20);
945
1067
  }
1068
+ /**
1069
+ * 取消动画帧请求
1070
+ *
1071
+ * 取消之前通过 requestAnimationFrame 注册的回调。
1072
+ * 在不支持 cancelAnimationFrame 的环境中降级为 clearTimeout。
1073
+ *
1074
+ * @method cancelAnimationFrame
1075
+ * @static
1076
+ * @param {number} handler requestAnimationFrame 返回的请求ID
1077
+ * @param {Window} [win] 可选的窗口对象(用于多窗口环境)
1078
+ *
1079
+ * @example
1080
+ * const animationId = jmUtils.requestAnimationFrame(animate);
1081
+ * jmUtils.cancelAnimationFrame(animationId);
1082
+ */
946
1083
  static cancelAnimationFrame(handler, win) {
947
1084
  let fun = win && win.cancelAnimationFrame? win.cancelAnimationFrame: (typeof window !== 'undefined' && window.cancelAnimationFrame? window.cancelAnimationFrame: clearTimeout);
948
1085
  return fun(handler);