jmgraph 3.2.7 → 3.2.8

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 (51) hide show
  1. package/README.md +0 -1
  2. package/dist/jmgraph.core.min.js +1 -1
  3. package/dist/jmgraph.core.min.js.map +1 -1
  4. package/dist/jmgraph.js +2834 -325
  5. package/dist/jmgraph.min.js +1 -1
  6. package/example/ball.html +8 -14
  7. package/example/cell.html +1 -1
  8. package/example/controls/arc.html +10 -7
  9. package/example/controls/arrowline.html +1 -0
  10. package/example/controls/img.html +30 -23
  11. package/example/controls/label.html +6 -4
  12. package/example/controls/line.html +54 -51
  13. package/example/controls/resize.html +45 -8
  14. package/example/index.html +2 -1
  15. package/example/music.html +101 -82
  16. package/example/webgl.html +48 -25
  17. package/package.json +56 -56
  18. package/src/core/jmControl.js +124 -95
  19. package/src/core/jmEvents.js +2 -2
  20. package/src/core/jmGradient.js +5 -3
  21. package/src/core/jmGraph.js +10 -20
  22. package/src/core/jmPath.js +1 -17
  23. package/src/core/jmUtils.js +6 -0
  24. package/src/lib/webgl/base.js +253 -1
  25. package/src/lib/webgl/core/buffer.js +2 -1
  26. package/src/lib/webgl/core/program.js +2 -2
  27. package/src/lib/webgl/core/texture.js +8 -8
  28. package/src/lib/webgl/gradient.js +11 -38
  29. package/src/lib/webgl/path.js +118 -235
  30. package/src/shapes/jmImage.js +18 -3
  31. package/src/shapes/jmLabel.js +84 -38
  32. package/src/shapes/jmRect.js +5 -2
  33. package/docs/_config.yml +0 -1
  34. package/docs/about.html +0 -41
  35. package/docs/api/jmGraph.md +0 -2302
  36. package/docs/css/index.css +0 -131
  37. package/docs/images/ball.gif +0 -0
  38. package/docs/images/bezier.gif +0 -0
  39. package/docs/images/cell.gif +0 -0
  40. package/docs/images/chart.gif +0 -0
  41. package/docs/images/editor.gif +0 -0
  42. package/docs/images/sort.gif +0 -0
  43. package/docs/index.html +0 -80
  44. package/docs/js/helper.js +0 -89
  45. package/docs/js/jquery.min.js +0 -6
  46. package/example/love/img/music/bg.mp3 +0 -0
  47. package/example/love/img/music/bg_2019130144035.mp3 +0 -0
  48. package/example/love/img/music/f.mp3 +0 -0
  49. package/example/love/img/music/fail.mp3 +0 -0
  50. package/example/love/img/music/s.mp3 +0 -0
  51. package/example/love/img/music/s_201913014415.mp3 +0 -0
package/dist/jmgraph.js CHANGED
@@ -233,7 +233,7 @@ var createJmGraph = function createJmGraph() {
233
233
 
234
234
  exports.create = createJmGraph;
235
235
 
236
- },{"./src/core/jmGraph.js":5,"./src/shapes/jmArc.js":12,"./src/shapes/jmArrow.js":13,"./src/shapes/jmArrowLine.js":14,"./src/shapes/jmBezier.js":15,"./src/shapes/jmCircle.js":16,"./src/shapes/jmHArc.js":17,"./src/shapes/jmImage.js":18,"./src/shapes/jmLabel.js":19,"./src/shapes/jmLine.js":20,"./src/shapes/jmPrismatic.js":21,"./src/shapes/jmRect.js":22,"./src/shapes/jmResize.js":23}],2:[function(require,module,exports){
236
+ },{"./src/core/jmGraph.js":5,"./src/shapes/jmArc.js":22,"./src/shapes/jmArrow.js":23,"./src/shapes/jmArrowLine.js":24,"./src/shapes/jmBezier.js":25,"./src/shapes/jmCircle.js":26,"./src/shapes/jmHArc.js":27,"./src/shapes/jmImage.js":28,"./src/shapes/jmLabel.js":29,"./src/shapes/jmLine.js":30,"./src/shapes/jmPrismatic.js":31,"./src/shapes/jmRect.js":32,"./src/shapes/jmResize.js":33}],2:[function(require,module,exports){
237
237
  "use strict";
238
238
 
239
239
  Object.defineProperty(exports, "__esModule", {
@@ -251,6 +251,18 @@ var _jmShadow = require("./jmShadow.js");
251
251
 
252
252
  var _jmProperty2 = require("./jmProperty.js");
253
253
 
254
+ var _path = _interopRequireDefault(require("../lib/webgl/path.js"));
255
+
256
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
257
+
258
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
259
+
260
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
261
+
262
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
263
+
264
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
265
+
254
266
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
255
267
 
256
268
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -279,7 +291,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
279
291
 
280
292
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
281
293
 
282
- //import WebglPath from "../lib/webgl/path.js";
283
294
  //样式名称,也当做白名单使用
284
295
  var jmStyleMap = {
285
296
  'fill': 'fillStyle',
@@ -340,15 +351,16 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
340
351
 
341
352
  _this2.graph = params.graph || null;
342
353
  _this2.zIndex = params.zIndex || 0;
343
- _this2.interactive = typeof params.interactive == 'undefined' ? true : params.interactive; // webgl模式
344
-
345
- /*if(this.mode === 'webgl') {
346
- this.webglControl = new WebglPath(this.graph, {
347
- style: this.style,
348
- isRegular: params.isRegular,
349
- needCut: params.needCut
350
- });
351
- }*/
354
+ _this2.interactive = typeof params.interactive == 'undefined' ? false : params.interactive; // webgl模式
355
+
356
+ if (_this2.mode === 'webgl') {
357
+ _this2.webglControl = new _path["default"](_this2.graph, {
358
+ style: _this2.style,
359
+ control: _assertThisInitialized(_this2),
360
+ isRegular: params.isRegular,
361
+ needCut: params.needCut
362
+ });
363
+ }
352
364
 
353
365
  _this2.initializing();
354
366
 
@@ -507,7 +519,6 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
507
519
  return s;
508
520
  },
509
521
  set: function set(v) {
510
- this.needUpdate = true;
511
522
  this.property('zIndex', v);
512
523
  this.children.sort(); //层级发生改变,需要重新排序
513
524
 
@@ -707,12 +718,6 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
707
718
  __setStyle(styleValue.toGradient(_this3), mpname || name);
708
719
  } else if (mpname) {
709
720
  if (_this3.webglControl) {
710
- //只有存在白名单中才处理
711
- //颜色转换
712
- if (t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
713
- styleValue = _jmUtils.jmUtils.hexToRGBA(styleValue);
714
- }
715
-
716
721
  _this3.webglControl.setStyle(mpname, styleValue);
717
722
  } else {
718
723
  //只有存在白名单中才处理
@@ -744,46 +749,37 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
744
749
 
745
750
  case 'translate':
746
751
  {
747
- _this3.context.translate && _this3.context.translate(styleValue.x, styleValue.y);
748
752
  break;
749
753
  }
750
754
  //旋转
751
755
 
752
756
  case 'rotation':
753
757
  {
754
- if (!styleValue.angle) break; //旋 转先移位偏移量
755
-
756
- var tranX = 0;
757
- var tranY = 0; //旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
758
+ if (typeof styleValue.angle === 'undefined' || isNaN(styleValue.angle)) break;
759
+ styleValue = _this3.getRotation(styleValue); //旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
758
760
  //这里只有style中的旋转才能生效,不然会导至子控件多次旋转
759
761
 
760
- if (styleValue.point) {
761
- var bounds = _this3.absoluteBounds ? _this3.absoluteBounds : _this3.getAbsoluteBounds();
762
- styleValue = _this3.getRotation(styleValue);
763
- tranX = styleValue.rotateX + bounds.left;
764
- tranY = styleValue.rotateY + bounds.top;
765
- }
766
-
767
- if (tranX != 0 || tranY != 0) _this3.context.translate && _this3.context.translate(tranX, tranY);
768
-
769
- _this3.context.rotate(styleValue.angle);
770
-
771
- if (tranX != 0 || tranY != 0) _this3.context.translate && _this3.context.translate(-tranX, -tranY);
762
+ styleValue = _this3.toAbsolutePoint(styleValue);
763
+ _this3.context.translate && _this3.context.translate(styleValue.x, styleValue.y);
764
+ _this3.context.rotate && _this3.context.rotate(styleValue.angle);
765
+ _this3.context.translate && _this3.context.translate(-styleValue.x, -styleValue.y);
772
766
  break;
773
767
  }
774
768
 
775
769
  case 'transform':
776
770
  {
771
+ if (!_this3.context.transform) break;
772
+
777
773
  if (Array.isArray(styleValue)) {
778
774
  _this3.context.transform.apply(_this3.context, styleValue);
779
775
  } else if (_typeof(styleValue) == 'object') {
780
- _this3.context.transform(styleValue.scaleX, //水平缩放
781
- styleValue.skewX, //水平倾斜
782
- styleValue.skewY, //垂直倾斜
783
- styleValue.scaleY, //垂直缩放
784
- styleValue.offsetX, //水平位移
785
- styleValue.offsetY); //垂直位移
786
-
776
+ _this3.context.transform(styleValue.scaleX || 1, //水平缩放
777
+ styleValue.skewX || 0, //水平倾斜
778
+ styleValue.skewY || 0, //垂直倾斜
779
+ styleValue.scaleY || 1, //垂直缩放
780
+ styleValue.offsetX || 0, //水平位移
781
+ styleValue.offsetY || 0 //垂直位移
782
+ );
787
783
  }
788
784
 
789
785
  break;
@@ -856,24 +852,33 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
856
852
  rect.bottom = this.height;
857
853
  }
858
854
  } else if (this.points && this.points.length > 0) {
859
- for (var i in this.points) {
860
- var p = this.points[i];
855
+ var _iterator = _createForOfIteratorHelper(this.points),
856
+ _step;
861
857
 
862
- if (typeof rect.left === 'undefined' || rect.left > p.x) {
863
- rect.left = p.x;
864
- }
858
+ try {
859
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
860
+ var p = _step.value;
865
861
 
866
- if (typeof rect.top === 'undefined' || rect.top > p.y) {
867
- rect.top = p.y;
868
- }
862
+ if (typeof rect.left === 'undefined' || rect.left > p.x) {
863
+ rect.left = p.x;
864
+ }
869
865
 
870
- if (typeof rect.right === 'undefined' || rect.right < p.x) {
871
- rect.right = p.x;
872
- }
866
+ if (typeof rect.top === 'undefined' || rect.top > p.y) {
867
+ rect.top = p.y;
868
+ }
873
869
 
874
- if (typeof rect.bottom === 'undefined' || rect.bottom < p.y) {
875
- rect.bottom = p.y;
870
+ if (typeof rect.right === 'undefined' || rect.right < p.x) {
871
+ rect.right = p.x;
872
+ }
873
+
874
+ if (typeof rect.bottom === 'undefined' || rect.bottom < p.y) {
875
+ rect.bottom = p.y;
876
+ }
876
877
  }
878
+ } catch (err) {
879
+ _iterator.e(err);
880
+ } finally {
881
+ _iterator.f();
877
882
  }
878
883
  } else if (this.getLocation) {
879
884
  var _p = this.getLocation();
@@ -942,43 +947,43 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
942
947
  local.top = margin.top;
943
948
  }
944
949
 
945
- if (!this.parent) return local; //没有父节点则直接返回
946
-
947
- var parentBounds = this.parent.getBounds(); //处理百分比参数
950
+ if (this.parent) {
951
+ var parentBounds = this.parent.getBounds(); //处理百分比参数
948
952
 
949
- if (_jmUtils.jmUtils.checkPercent(local.left)) {
950
- local.left = _jmUtils.jmUtils.percentToNumber(local.left) * parentBounds.width;
951
- }
953
+ if (_jmUtils.jmUtils.checkPercent(local.left)) {
954
+ local.left = _jmUtils.jmUtils.percentToNumber(local.left) * parentBounds.width;
955
+ }
952
956
 
953
- if (_jmUtils.jmUtils.checkPercent(local.top)) {
954
- local.top = _jmUtils.jmUtils.percentToNumber(local.top) * parentBounds.height;
955
- } //如果没有指定宽度或高度,则按百分之百计算其父宽度或高度
957
+ if (_jmUtils.jmUtils.checkPercent(local.top)) {
958
+ local.top = _jmUtils.jmUtils.percentToNumber(local.top) * parentBounds.height;
959
+ } //如果没有指定宽度或高度,则按百分之百计算其父宽度或高度
956
960
 
957
961
 
958
- if (_jmUtils.jmUtils.checkPercent(local.width)) {
959
- local.width = _jmUtils.jmUtils.percentToNumber(local.width) * parentBounds.width;
960
- }
962
+ if (_jmUtils.jmUtils.checkPercent(local.width)) {
963
+ local.width = _jmUtils.jmUtils.percentToNumber(local.width) * parentBounds.width;
964
+ }
961
965
 
962
- if (_jmUtils.jmUtils.checkPercent(local.height)) {
963
- local.height = _jmUtils.jmUtils.percentToNumber(local.height) * parentBounds.height;
964
- } //处理中心点
966
+ if (_jmUtils.jmUtils.checkPercent(local.height)) {
967
+ local.height = _jmUtils.jmUtils.percentToNumber(local.height) * parentBounds.height;
968
+ } //处理中心点
965
969
 
966
970
 
967
- if (local.center) {
968
- //处理百分比参数
969
- if (_jmUtils.jmUtils.checkPercent(local.center.x)) {
970
- local.center.x = _jmUtils.jmUtils.percentToNumber(local.center.x) * parentBounds.width;
971
- }
971
+ if (local.center) {
972
+ //处理百分比参数
973
+ if (_jmUtils.jmUtils.checkPercent(local.center.x)) {
974
+ local.center.x = _jmUtils.jmUtils.percentToNumber(local.center.x) * parentBounds.width;
975
+ }
972
976
 
973
- if (_jmUtils.jmUtils.checkPercent(local.center.y)) {
974
- local.center.y = _jmUtils.jmUtils.percentToNumber(local.center.y) * parentBounds.height;
977
+ if (_jmUtils.jmUtils.checkPercent(local.center.y)) {
978
+ local.center.y = _jmUtils.jmUtils.percentToNumber(local.center.y) * parentBounds.height;
979
+ }
975
980
  }
976
- }
977
981
 
978
- if (local.radius) {
979
- //处理百分比参数
980
- if (_jmUtils.jmUtils.checkPercent(local.radius)) {
981
- local.radius = _jmUtils.jmUtils.percentToNumber(local.radius) * Math.min(parentBounds.width, parentBounds.height);
982
+ if (local.radius) {
983
+ //处理百分比参数
984
+ if (_jmUtils.jmUtils.checkPercent(local.radius)) {
985
+ local.radius = _jmUtils.jmUtils.percentToNumber(local.radius) * Math.min(parentBounds.width, parentBounds.height);
986
+ }
982
987
  }
983
988
  }
984
989
 
@@ -992,34 +997,60 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
992
997
  }, {
993
998
  key: "getRotation",
994
999
  value: function getRotation(rotation) {
995
- rotation = rotation || this.style.rotation;
1000
+ var bounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1001
+ rotation = rotation || _jmUtils.jmUtils.clone(this.style.rotation);
996
1002
 
997
1003
  if (!rotation) {
998
1004
  //如果本身没有,则可以继承父级的
999
1005
  rotation = this.parent && this.parent.getRotation ? this.parent.getRotation() : null; //如果父级有旋转,则把坐标转换为当前控件区域
1000
1006
 
1001
1007
  if (rotation) {
1002
- var bounds = this.getBounds();
1003
- rotation.rotateX -= bounds.left;
1004
- rotation.rotateY -= bounds.top;
1008
+ bounds = bounds || this.getBounds();
1009
+ rotation.x -= bounds.left;
1010
+ rotation.y -= bounds.top;
1005
1011
  }
1006
1012
  } else {
1007
- var _bounds = this.getBounds();
1013
+ bounds = bounds || this.getBounds();
1014
+ if (typeof rotation.x === 'undefined') rotation.x = '50%';
1015
+ if (typeof rotation.y === 'undefined') rotation.y = '50%';
1008
1016
 
1009
- rotation.rotateX = rotation.point.x;
1010
-
1011
- if (_jmUtils.jmUtils.checkPercent(rotation.rotateX)) {
1012
- rotation.rotateX = _jmUtils.jmUtils.percentToNumber(rotation.rotateX) * _bounds.width;
1017
+ if (_jmUtils.jmUtils.checkPercent(rotation.x)) {
1018
+ rotation.x = _jmUtils.jmUtils.percentToNumber(rotation.x) * bounds.width;
1013
1019
  }
1014
1020
 
1015
- rotation.rotateY = rotation.point.y;
1016
-
1017
- if (_jmUtils.jmUtils.checkPercent(rotation.rotateY)) {
1018
- rotation.rotateY = _jmUtils.jmUtils.percentToNumber(rotation.rotateY) * _bounds.height;
1021
+ if (_jmUtils.jmUtils.checkPercent(rotation.y)) {
1022
+ rotation.y = _jmUtils.jmUtils.percentToNumber(rotation.y) * bounds.height;
1019
1023
  }
1020
1024
  }
1021
1025
 
1022
1026
  return rotation;
1027
+ } // 计算位移偏移量
1028
+
1029
+ }, {
1030
+ key: "getTranslate",
1031
+ value: function getTranslate(translate) {
1032
+ var bounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1033
+ translate = translate || this.style.translate;
1034
+ if (!translate) return {
1035
+ x: 0,
1036
+ y: 0
1037
+ };
1038
+ var result = {
1039
+ x: translate.x || 0,
1040
+ y: translate.y || 0
1041
+ };
1042
+
1043
+ if (_jmUtils.jmUtils.checkPercent(result.x)) {
1044
+ if (!bounds && this.parent) bounds = this.parent.getBounds();
1045
+ result.x = _jmUtils.jmUtils.percentToNumber(result.x) * bounds.width;
1046
+ }
1047
+
1048
+ if (_jmUtils.jmUtils.checkPercent(result.y)) {
1049
+ if (!bounds && this.parent) bounds = this.parent.getBounds();
1050
+ result.y = _jmUtils.jmUtils.percentToNumber(result.y) * bounds.height;
1051
+ }
1052
+
1053
+ return result;
1023
1054
  }
1024
1055
  /**
1025
1056
  * 移除当前控件
@@ -1162,6 +1193,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1162
1193
 
1163
1194
  return rec;
1164
1195
  }
1196
+ /**
1197
+ * 把当前控制内部坐标转为canvas绝对定位坐标
1198
+ *
1199
+ * @method toAbsolutePoint
1200
+ * @param {x: number, y: number} 内部坐标
1201
+ */
1202
+
1203
+ }, {
1204
+ key: "toAbsolutePoint",
1205
+ value: function toAbsolutePoint(point) {
1206
+ if (point.x || point.y) {
1207
+ var bounds = this.absoluteBounds ? this.absoluteBounds : this.getAbsoluteBounds();
1208
+ point.x = (point.x || 0) + bounds.left;
1209
+ point.y = (point.y || 0) + bounds.top;
1210
+ }
1211
+
1212
+ return point;
1213
+ }
1165
1214
  /**
1166
1215
  * 画控件前初始化
1167
1216
  * 执行beginPath开始控件的绘制
@@ -1174,7 +1223,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1174
1223
  value: function beginDraw() {
1175
1224
  this.getLocation(true); //重置位置信息
1176
1225
 
1177
- this.context.beginPath && this.context.beginPath(); //if(this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
1226
+ this.context.beginPath && this.context.beginPath();
1227
+ if (this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
1178
1228
  }
1179
1229
  /**
1180
1230
  * 结束控件绘制
@@ -1187,26 +1237,27 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1187
1237
  value: function endDraw() {
1188
1238
  //如果当前为封闭路径
1189
1239
  if (this.style.close) {
1190
- //if(this.webglControl) this.webglControl.closePath();
1240
+ if (this.webglControl) this.webglControl.closePath();
1191
1241
  this.context.closePath && this.context.closePath();
1192
1242
  }
1193
1243
 
1194
1244
  var fill = this.style['fill'] || this.style['fillStyle'];
1195
1245
 
1196
1246
  if (fill) {
1197
- /*if(this.webglControl) {
1198
- const bounds = this.getBounds();
1199
- this.webglControl.fill(bounds);
1200
- }*/
1247
+ if (this.webglControl) {
1248
+ var bounds = this.getBounds();
1249
+ this.webglControl.fill(bounds);
1250
+ }
1251
+
1201
1252
  this.context.fill && this.context.fill();
1202
1253
  }
1203
1254
 
1204
1255
  if (this.style['stroke'] || !fill && !this.is('jmGraph')) {
1205
- //if(this.webglControl) this.webglControl.stroke();
1256
+ if (this.webglControl) this.webglControl.stroke();
1206
1257
  this.context.stroke && this.context.stroke();
1207
- } //if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
1208
-
1258
+ }
1209
1259
 
1260
+ if (this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
1210
1261
  this.needUpdate = false;
1211
1262
  }
1212
1263
  /**
@@ -1222,14 +1273,11 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1222
1273
  if (this.points && this.points.length > 0) {
1223
1274
  //获取当前控件的绝对位置
1224
1275
  var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
1225
- /*if(this.webglControl) {
1226
- this.webglControl.setParentBounds(bounds);
1227
- this.webglControl.draw([
1228
- ...this.points
1229
- ]);
1230
- }*/
1231
1276
 
1232
- if (this.context && this.context.moveTo) {
1277
+ if (this.webglControl) {
1278
+ this.webglControl.setParentBounds(bounds);
1279
+ this.webglControl.draw(_toConsumableArray(this.points));
1280
+ } else if (this.context && this.context.moveTo) {
1233
1281
  this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
1234
1282
  var len = this.points.length;
1235
1283
 
@@ -1313,18 +1361,18 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1313
1361
  if (name && name.indexOf(' ') > -1) {
1314
1362
  name = name.split(' ');
1315
1363
 
1316
- var _iterator = _createForOfIteratorHelper(name),
1317
- _step;
1364
+ var _iterator2 = _createForOfIteratorHelper(name),
1365
+ _step2;
1318
1366
 
1319
1367
  try {
1320
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1321
- var n = _step.value;
1368
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1369
+ var n = _step2.value;
1322
1370
  n && this.bind(n, handle);
1323
1371
  }
1324
1372
  } catch (err) {
1325
- _iterator.e(err);
1373
+ _iterator2.e(err);
1326
1374
  } finally {
1327
- _iterator.f();
1375
+ _iterator2.f();
1328
1376
  }
1329
1377
 
1330
1378
  return;
@@ -1362,18 +1410,18 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1362
1410
  if (name && name.indexOf(' ') > -1) {
1363
1411
  name = name.split(' ');
1364
1412
 
1365
- var _iterator2 = _createForOfIteratorHelper(name),
1366
- _step2;
1413
+ var _iterator3 = _createForOfIteratorHelper(name),
1414
+ _step3;
1367
1415
 
1368
1416
  try {
1369
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1370
- var n = _step2.value;
1417
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1418
+ var n = _step3.value;
1371
1419
  n && this.unbind(n, handle);
1372
1420
  }
1373
1421
  } catch (err) {
1374
- _iterator2.e(err);
1422
+ _iterator3.e(err);
1375
1423
  } finally {
1376
- _iterator2.f();
1424
+ _iterator3.f();
1377
1425
  }
1378
1426
 
1379
1427
  return;
@@ -1462,7 +1510,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1462
1510
  }
1463
1511
 
1464
1512
  var bounds = this.getBounds();
1465
- var rotation = this.getRotation(); //获取当前旋转参数
1513
+ var rotation = this.getRotation(null, bounds); //获取当前旋转参数
1466
1514
 
1467
1515
  var ps = this.points; //如果不是路径组成,则采用边界做为顶点
1468
1516
 
@@ -1504,8 +1552,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1504
1552
  //rotateX ,rotateY 是相对当前控件的位置
1505
1553
 
1506
1554
  ps = _jmUtils.jmUtils.rotatePoints(ps, {
1507
- x: rotation.rotateX + bounds.left,
1508
- y: rotation.rotateY + bounds.top
1555
+ x: rotation.x + bounds.left,
1556
+ y: rotation.y + bounds.top
1509
1557
  }, rotation.angle);
1510
1558
  } //如果当前路径不是实心的
1511
1559
  //就只用判断点是否在边上即可
@@ -1569,7 +1617,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1569
1617
  var graph = this.graph;
1570
1618
  var srcElement = args.srcElement || args.target;
1571
1619
 
1572
- var position = _jmUtils.jmUtils.getEventPosition(args, graph.scaleSize); //初始化事件位置
1620
+ var position = _jmUtils.jmUtils.getEventPosition(args); //初始化事件位置
1573
1621
 
1574
1622
 
1575
1623
  args = {
@@ -1873,6 +1921,8 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1873
1921
  this.unbind('touchstart', this.__mvMonitor.md);
1874
1922
  }
1875
1923
 
1924
+ this.interactive = true; // 如果可以移动,则响应事件
1925
+
1876
1926
  return this;
1877
1927
  }
1878
1928
  }]);
@@ -1883,7 +1933,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
1883
1933
  exports.jmControl = exports["default"] = jmControl;
1884
1934
  ;
1885
1935
 
1886
- },{"./jmGradient.js":4,"./jmList.js":6,"./jmProperty.js":9,"./jmShadow.js":10,"./jmUtils.js":11}],3:[function(require,module,exports){
1936
+ },{"../lib/webgl/path.js":21,"./jmGradient.js":4,"./jmList.js":6,"./jmProperty.js":9,"./jmShadow.js":10,"./jmUtils.js":11}],3:[function(require,module,exports){
1887
1937
  "use strict";
1888
1938
 
1889
1939
  Object.defineProperty(exports, "__esModule", {
@@ -2014,7 +2064,7 @@ var jmMouseEvent = /*#__PURE__*/function () {
2014
2064
  //return false;
2015
2065
  //}
2016
2066
  });
2017
- this.eventEvents['mousedown'] = _jmUtils.jmUtils.bindEvent(this.target, 'mousemove', function (evt) {
2067
+ this.eventEvents['mousemove'] = _jmUtils.jmUtils.bindEvent(this.target, 'mousemove', function (evt) {
2018
2068
  evt = evt || window.event;
2019
2069
  evt.eventName = 'mousemove';
2020
2070
  var target = evt.target || evt.srcElement;
@@ -2026,7 +2076,7 @@ var jmMouseEvent = /*#__PURE__*/function () {
2026
2076
  return false; //}
2027
2077
  }
2028
2078
  });
2029
- this.eventEvents['mousedown'] = _jmUtils.jmUtils.bindEvent(this.target, 'mouseover', function (evt) {
2079
+ this.eventEvents['mouseover'] = _jmUtils.jmUtils.bindEvent(this.target, 'mouseover', function (evt) {
2030
2080
  evt = evt || window.event;
2031
2081
  evt.eventName = 'mouseover';
2032
2082
  container.raiseEvent('mouseover', evt);
@@ -2329,6 +2379,7 @@ var jmGradient = /*#__PURE__*/function () {
2329
2379
  if (this.type === 'linear') {
2330
2380
  if (control.mode === 'webgl' && control.webglControl) {
2331
2381
  gradient = control.webglControl.createLinearGradient(x1, y1, x2, y2, bounds);
2382
+ gradient.key = this.toString();
2332
2383
  } else {
2333
2384
  context.createLinearGradient && (gradient = context.createLinearGradient(sx1, sy1, sx2, sy2));
2334
2385
  }
@@ -2348,6 +2399,7 @@ var jmGradient = /*#__PURE__*/function () {
2348
2399
 
2349
2400
  if (control.mode === 'webgl' && control.webglControl) {
2350
2401
  gradient = control.webglControl.createRadialGradient(x1, y1, r1, x2, y2, r2, bounds);
2402
+ gradient.key = this.toString();
2351
2403
  } //offsetLine = Math.abs(r2 - r1);//二圆半径差
2352
2404
  else if (context.createRadialGradient) {
2353
2405
  gradient = context.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2);
@@ -2456,14 +2508,14 @@ var jmGradient = /*#__PURE__*/function () {
2456
2508
  var str = this.type + '-gradient(';
2457
2509
 
2458
2510
  if (this.type == 'linear') {
2459
- str += this.x1.toFixed(2) + ' ' + this.y1.toFixed(2) + ' ' + this.x2.toFixed(2) + ' ' + this.y2.toFixed(2);
2511
+ str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
2460
2512
  } else {
2461
- str += this.x1.toFixed(2) + ' ' + this.y1.toFixed(2) + ' ' + this.r1.toFixed(2) + ' ' + this.x2.toFixed(2) + ' ' + this.y2.toFixed(2) + ' ' + this.r2.toFixed(2);
2513
+ str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
2462
2514
  } //颜色渐变
2463
2515
 
2464
2516
 
2465
2517
  this.stops.each(function (i, s) {
2466
- str += ',' + s.color + ' ' + s.offset.toFixed(2);
2518
+ str += ',' + s.color + ' ' + s.offset;
2467
2519
  });
2468
2520
  return str + ')';
2469
2521
  }
@@ -2602,8 +2654,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2602
2654
  option = {};
2603
2655
  }
2604
2656
 
2605
- option = option || {};
2606
- option.mode = '2d'; // webgl | 2d 暂不支持webgl
2657
+ option = option || {}; //option.mode = '2d'; // webgl | 2d 暂不支持webgl
2607
2658
 
2608
2659
  option.interactive = true;
2609
2660
  option.isRegular = true; // 规则的
@@ -2754,23 +2805,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
2754
2805
  }
2755
2806
 
2756
2807
  this.context.viewport && this.context.viewport(0, 0, w, h);
2757
- }
2758
- /**
2759
- * 内部坐标转为页面坐标,这里主要是有devicePixelRatio倍数问题
2760
- * @param {x, y} point 内部坐标
2761
- */
2762
-
2763
- }, {
2764
- key: "pointToPixes",
2765
- value: function pointToPixes(point) {
2766
- if (this.dprScaleSize && this.dprScaleSize !== 1) {
2767
- point = Object.assign({}, point, {
2768
- x: point.x / this.dprScaleSize,
2769
- y: point.y / this.dprScaleSize
2770
- });
2771
- }
2772
-
2773
- return point;
2808
+ this.needUpdate = true;
2774
2809
  }
2775
2810
  /**
2776
2811
  * 宽度
@@ -3140,14 +3175,13 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3140
3175
  width: this.canvas.width,
3141
3176
  height: this.canvas.height
3142
3177
  };
3143
- }
3178
+ } //this.context.scale && this.context.scale(dx,dy);
3144
3179
 
3145
- this.context.scale(dx, dy);
3146
3180
 
3147
3181
  if (!this.scaleSize) {
3148
3182
  this.scaleSize = {
3149
- x: dx,
3150
- y: dy
3183
+ x: 1,
3184
+ y: 1
3151
3185
  };
3152
3186
  } else {
3153
3187
  this.scaleSize = {
@@ -3156,7 +3190,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3156
3190
  };
3157
3191
  }
3158
3192
 
3159
- this.refresh();
3193
+ this.canvas.style && (this.canvas.style.transform = "scale(".concat(this.scaleSize.x, ", ").concat(this.scaleSize.y, ")"));
3160
3194
  }
3161
3195
  /**
3162
3196
  * 保存为base64图形数据
@@ -3182,6 +3216,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3182
3216
  if (this.___isAutoRefreshing) return;
3183
3217
  var self = this;
3184
3218
  this.___isAutoRefreshing = true;
3219
+ var refreshStartTime = Date.now();
3185
3220
 
3186
3221
  function update() {
3187
3222
  if (self.destroyed) {
@@ -3189,9 +3224,10 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
3189
3224
  return; // 已销毁
3190
3225
  }
3191
3226
 
3192
- if (self.needUpdate) self.redraw(); // 触发刷新事件
3227
+ if (self.needUpdate) self.redraw();
3228
+ var time = Date.now() - refreshStartTime; // 触发刷新事件
3193
3229
 
3194
- self.emit('update');
3230
+ self.emit('update', time);
3195
3231
  self.__requestAnimationFrameFunHandler && self.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
3196
3232
  self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
3197
3233
  if (callback) callback();
@@ -3655,7 +3691,6 @@ var jmPath = /*#__PURE__*/function (_jmControl) {
3655
3691
 
3656
3692
  _this = _super.call(this, params, t);
3657
3693
  _this.points = params && params.points ? params.points : [];
3658
- _this.polygonIndices = params && params.polygonIndices ? params.polygonIndices : [];
3659
3694
  return _this;
3660
3695
  }
3661
3696
  /**
@@ -3676,22 +3711,6 @@ var jmPath = /*#__PURE__*/function (_jmControl) {
3676
3711
  this.needUpdate = true;
3677
3712
  return this.property('points', v);
3678
3713
  }
3679
- /**
3680
- * 顶点数组索引,对应points中的顶点
3681
- * @property polygonIndices
3682
- * @type {array}
3683
- */
3684
-
3685
- }, {
3686
- key: "polygonIndices",
3687
- get: function get() {
3688
- var s = this.property('polygonIndices');
3689
- return s;
3690
- },
3691
- set: function set(v) {
3692
- this.needUpdate = true;
3693
- return this.property('polygonIndices', v);
3694
- }
3695
3714
  }]);
3696
3715
 
3697
3716
  return jmPath;
@@ -4932,6 +4951,13 @@ var jmUtils = /*#__PURE__*/function () {
4932
4951
  a = typeof color.a !== 'undefined' ? color.a : a;
4933
4952
  }
4934
4953
 
4954
+ if (r && _typeof(r) === 'object') {
4955
+ g = r.g;
4956
+ b = r.b;
4957
+ a = r.a || 1;
4958
+ r = r.r;
4959
+ }
4960
+
4935
4961
  if (typeof r != 'undefined' && typeof g != 'undefined' && typeof b != 'undefined') {
4936
4962
  if (typeof a != 'undefined') {
4937
4963
  return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
@@ -4963,143 +4989,2556 @@ var jmUtils = /*#__PURE__*/function () {
4963
4989
  exports.jmUtils = exports["default"] = jmUtils;
4964
4990
 
4965
4991
  },{"./jmList.js":6}],12:[function(require,module,exports){
4966
- "use strict";
4967
-
4968
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4992
+ 'use strict';
4969
4993
 
4970
4994
  Object.defineProperty(exports, "__esModule", {
4971
4995
  value: true
4972
4996
  });
4973
- exports.jmArc = exports["default"] = void 0;
4997
+ exports["default"] = void 0;
4998
+ var _default = earcut;
4999
+ exports["default"] = _default;
5000
+
5001
+ function earcut(data, holeIndices, dim) {
5002
+ dim = dim || 2;
5003
+ var hasHoles = holeIndices && holeIndices.length,
5004
+ outerLen = hasHoles ? holeIndices[0] * dim : data.length,
5005
+ outerNode = linkedList(data, 0, outerLen, dim, true),
5006
+ triangles = [];
5007
+ if (!outerNode || outerNode.next === outerNode.prev) return triangles;
5008
+ var minX, minY, maxX, maxY, x, y, invSize;
5009
+ if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
5010
+
5011
+ if (data.length > 80 * dim) {
5012
+ minX = maxX = data[0];
5013
+ minY = maxY = data[1];
5014
+
5015
+ for (var i = dim; i < outerLen; i += dim) {
5016
+ x = data[i];
5017
+ y = data[i + 1];
5018
+ if (x < minX) minX = x;
5019
+ if (y < minY) minY = y;
5020
+ if (x > maxX) maxX = x;
5021
+ if (y > maxY) maxY = y;
5022
+ } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
5023
+
5024
+
5025
+ invSize = Math.max(maxX - minX, maxY - minY);
5026
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
5027
+ }
4974
5028
 
4975
- var _jmPath2 = require("../core/jmPath.js");
5029
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
5030
+ return triangles;
5031
+ } // create a circular doubly linked list from polygon points in the specified winding order
4976
5032
 
4977
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4978
5033
 
4979
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
5034
+ function linkedList(data, start, end, dim, clockwise) {
5035
+ var i, last;
4980
5036
 
4981
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
5037
+ if (clockwise === signedArea(data, start, end, dim) > 0) {
5038
+ for (i = start; i < end; i += dim) {
5039
+ last = insertNode(i, data[i], data[i + 1], last);
5040
+ }
5041
+ } else {
5042
+ for (i = end - dim; i >= start; i -= dim) {
5043
+ last = insertNode(i, data[i], data[i + 1], last);
5044
+ }
5045
+ }
4982
5046
 
4983
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
5047
+ if (last && equals(last, last.next)) {
5048
+ removeNode(last);
5049
+ last = last.next;
5050
+ }
4984
5051
 
4985
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
5052
+ return last;
5053
+ } // eliminate colinear or duplicate points
4986
5054
 
4987
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
4988
5055
 
4989
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
5056
+ function filterPoints(start, end) {
5057
+ if (!start) return start;
5058
+ if (!end) end = start;
5059
+ var p = start,
5060
+ again;
4990
5061
 
4991
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
5062
+ do {
5063
+ again = false;
4992
5064
 
4993
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
5065
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
5066
+ removeNode(p);
5067
+ p = end = p.prev;
5068
+ if (p === p.next) break;
5069
+ again = true;
5070
+ } else {
5071
+ p = p.next;
5072
+ }
5073
+ } while (again || p !== end);
4994
5074
 
4995
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
5075
+ return end;
5076
+ } // main ear slicing loop which triangulates a polygon (given as a linked list)
4996
5077
 
4997
- /**
4998
- * 圆弧图型 继承自jmPath
4999
- *
5000
- * @class jmArc
5001
- * @extends jmPath
5002
- * @param {object} params center=当前圆弧中心,radius=圆弧半径,start=圆弧起始角度,end=圆弧结束角度,anticlockwise= false 顺时针,true 逆时针
5003
- */
5004
- var jmArc = /*#__PURE__*/function (_jmPath) {
5005
- _inherits(jmArc, _jmPath);
5006
5078
 
5007
- var _super = _createSuper(jmArc);
5079
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
5080
+ if (!ear) return; // interlink polygon nodes in z-order
5008
5081
 
5009
- function jmArc(params) {
5010
- var _this;
5082
+ if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
5083
+ var stop = ear,
5084
+ prev,
5085
+ next; // iterate through ears, slicing them one by one
5011
5086
 
5012
- var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmArc';
5087
+ while (ear.prev !== ear.next) {
5088
+ prev = ear.prev;
5089
+ next = ear.next;
5013
5090
 
5014
- _classCallCheck(this, jmArc);
5091
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
5092
+ // cut off the triangle
5093
+ triangles.push(prev.i / dim | 0);
5094
+ triangles.push(ear.i / dim | 0);
5095
+ triangles.push(next.i / dim | 0);
5096
+ removeNode(ear); // skipping the next vertex leads to less sliver triangles
5015
5097
 
5016
- if (!params) params = {};
5017
- params.isRegular = params.isRegular === false ? false : true; // 规则的
5098
+ ear = next.next;
5099
+ stop = next.next;
5100
+ continue;
5101
+ }
5018
5102
 
5019
- params.needCut = params.needCut === true ? true : false; // 规则的
5103
+ ear = next; // if we looped through the whole remaining polygon and can't find any more ears
5020
5104
 
5021
- _this = _super.call(this, params, t);
5022
- _this.center = params.center || {
5023
- x: 0,
5024
- y: 0
5025
- };
5026
- _this.radius = params.radius || 0;
5027
- _this.startAngle = params.start || params.startAngle || 0;
5028
- _this.endAngle = params.end || params.endAngle || Math.PI * 2;
5029
- _this.anticlockwise = params.anticlockwise || 0;
5030
- _this.isFan = !!params.isFan;
5031
- return _this;
5105
+ if (ear === stop) {
5106
+ // try filtering points and slicing again
5107
+ if (!pass) {
5108
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
5109
+ } else if (pass === 1) {
5110
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
5111
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
5112
+ } else if (pass === 2) {
5113
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
5114
+ }
5115
+
5116
+ break;
5117
+ }
5118
+ }
5119
+ } // check whether a polygon node forms a valid ear with adjacent nodes
5120
+
5121
+
5122
+ function isEar(ear) {
5123
+ var a = ear.prev,
5124
+ b = ear,
5125
+ c = ear.next;
5126
+ if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
5127
+ // now make sure we don't have other points inside the potential ear
5128
+
5129
+ var ax = a.x,
5130
+ bx = b.x,
5131
+ cx = c.x,
5132
+ ay = a.y,
5133
+ by = b.y,
5134
+ cy = c.y; // triangle bbox; min & max are calculated like this for speed
5135
+
5136
+ var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
5137
+ y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
5138
+ x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
5139
+ y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
5140
+ var p = c.next;
5141
+
5142
+ while (p !== a) {
5143
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
5144
+ p = p.next;
5032
5145
  }
5033
- /**
5034
- * 中心点
5035
- * point格式:{x:0,y:0,m:true}
5036
- * @property center
5037
- * @type {point}
5038
- */
5039
5146
 
5147
+ return true;
5148
+ }
5149
+
5150
+ function isEarHashed(ear, minX, minY, invSize) {
5151
+ var a = ear.prev,
5152
+ b = ear,
5153
+ c = ear.next;
5154
+ if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
5155
+
5156
+ var ax = a.x,
5157
+ bx = b.x,
5158
+ cx = c.x,
5159
+ ay = a.y,
5160
+ by = b.y,
5161
+ cy = c.y; // triangle bbox; min & max are calculated like this for speed
5162
+
5163
+ var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
5164
+ y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
5165
+ x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
5166
+ y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy; // z-order range for the current triangle bbox;
5167
+
5168
+ var minZ = zOrder(x0, y0, minX, minY, invSize),
5169
+ maxZ = zOrder(x1, y1, minX, minY, invSize);
5170
+ var p = ear.prevZ,
5171
+ n = ear.nextZ; // look for points inside the triangle in both directions
5172
+
5173
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
5174
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
5175
+ p = p.prevZ;
5176
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
5177
+ n = n.nextZ;
5178
+ } // look for remaining points in decreasing z-order
5179
+
5180
+
5181
+ while (p && p.z >= minZ) {
5182
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
5183
+ p = p.prevZ;
5184
+ } // look for remaining points in increasing z-order
5185
+
5186
+
5187
+ while (n && n.z <= maxZ) {
5188
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
5189
+ n = n.nextZ;
5190
+ }
5040
5191
 
5041
- _createClass(jmArc, [{
5042
- key: "center",
5043
- get: function get() {
5044
- return this.property('center');
5045
- },
5046
- set: function set(v) {
5047
- this.needUpdate = true;
5048
- return this.property('center', v);
5049
- }
5050
- /**
5051
- * 半径
5052
- * @property radius
5053
- * @type {number}
5054
- */
5192
+ return true;
5193
+ } // go through all polygon nodes and cure small local self-intersections
5055
5194
 
5056
- }, {
5057
- key: "radius",
5058
- get: function get() {
5059
- return this.property('radius');
5060
- },
5061
- set: function set(v) {
5062
- this.needUpdate = true;
5063
- return this.property('radius', v);
5064
- }
5065
- /**
5066
- * 扇形起始角度
5067
- * @property startAngle
5068
- * @type {number}
5069
- */
5070
5195
 
5071
- }, {
5072
- key: "startAngle",
5073
- get: function get() {
5074
- return this.property('startAngle');
5075
- },
5076
- set: function set(v) {
5077
- this.needUpdate = true;
5078
- return this.property('startAngle', v);
5196
+ function cureLocalIntersections(start, triangles, dim) {
5197
+ var p = start;
5198
+
5199
+ do {
5200
+ var a = p.prev,
5201
+ b = p.next.next;
5202
+
5203
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
5204
+ triangles.push(a.i / dim | 0);
5205
+ triangles.push(p.i / dim | 0);
5206
+ triangles.push(b.i / dim | 0); // remove two nodes involved
5207
+
5208
+ removeNode(p);
5209
+ removeNode(p.next);
5210
+ p = start = b;
5079
5211
  }
5080
- /**
5081
- * 扇形结束角度
5082
- * @property endAngle
5083
- * @type {number}
5084
- */
5085
5212
 
5086
- }, {
5087
- key: "endAngle",
5088
- get: function get() {
5089
- return this.property('endAngle');
5090
- },
5091
- set: function set(v) {
5092
- this.needUpdate = true;
5093
- return this.property('endAngle', v);
5213
+ p = p.next;
5214
+ } while (p !== start);
5215
+
5216
+ return filterPoints(p);
5217
+ } // try splitting polygon into two and triangulate them independently
5218
+
5219
+
5220
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
5221
+ // look for a valid diagonal that divides the polygon into two
5222
+ var a = start;
5223
+
5224
+ do {
5225
+ var b = a.next.next;
5226
+
5227
+ while (b !== a.prev) {
5228
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
5229
+ // split the polygon in two by the diagonal
5230
+ var c = splitPolygon(a, b); // filter colinear points around the cuts
5231
+
5232
+ a = filterPoints(a, a.next);
5233
+ c = filterPoints(c, c.next); // run earcut on each half
5234
+
5235
+ earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
5236
+ earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
5237
+ return;
5238
+ }
5239
+
5240
+ b = b.next;
5094
5241
  }
5095
- /**
5096
- * 可选。规定应该逆时针还是顺时针绘图
5097
- * false 顺时针,true 逆时针
5098
- * @property anticlockwise
5099
- * @type {boolean}
5100
- */
5101
5242
 
5102
- }, {
5243
+ a = a.next;
5244
+ } while (a !== start);
5245
+ } // link every hole into the outer loop, producing a single-ring polygon without holes
5246
+
5247
+
5248
+ function eliminateHoles(data, holeIndices, outerNode, dim) {
5249
+ var queue = [],
5250
+ i,
5251
+ len,
5252
+ start,
5253
+ end,
5254
+ list;
5255
+
5256
+ for (i = 0, len = holeIndices.length; i < len; i++) {
5257
+ start = holeIndices[i] * dim;
5258
+ end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
5259
+ list = linkedList(data, start, end, dim, false);
5260
+ if (list === list.next) list.steiner = true;
5261
+ queue.push(getLeftmost(list));
5262
+ }
5263
+
5264
+ queue.sort(compareX); // process holes from left to right
5265
+
5266
+ for (i = 0; i < queue.length; i++) {
5267
+ outerNode = eliminateHole(queue[i], outerNode);
5268
+ }
5269
+
5270
+ return outerNode;
5271
+ }
5272
+
5273
+ function compareX(a, b) {
5274
+ return a.x - b.x;
5275
+ } // find a bridge between vertices that connects hole with an outer ring and and link it
5276
+
5277
+
5278
+ function eliminateHole(hole, outerNode) {
5279
+ var bridge = findHoleBridge(hole, outerNode);
5280
+
5281
+ if (!bridge) {
5282
+ return outerNode;
5283
+ }
5284
+
5285
+ var bridgeReverse = splitPolygon(bridge, hole); // filter collinear points around the cuts
5286
+
5287
+ filterPoints(bridgeReverse, bridgeReverse.next);
5288
+ return filterPoints(bridge, bridge.next);
5289
+ } // David Eberly's algorithm for finding a bridge between hole and outer polygon
5290
+
5291
+
5292
+ function findHoleBridge(hole, outerNode) {
5293
+ var p = outerNode,
5294
+ hx = hole.x,
5295
+ hy = hole.y,
5296
+ qx = -Infinity,
5297
+ m; // find a segment intersected by a ray from the hole's leftmost point to the left;
5298
+ // segment's endpoint with lesser x will be potential connection point
5299
+
5300
+ do {
5301
+ if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
5302
+ var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
5303
+
5304
+ if (x <= hx && x > qx) {
5305
+ qx = x;
5306
+ m = p.x < p.next.x ? p : p.next;
5307
+ if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint
5308
+ }
5309
+ }
5310
+
5311
+ p = p.next;
5312
+ } while (p !== outerNode);
5313
+
5314
+ if (!m) return null; // look for points inside the triangle of hole point, segment intersection and endpoint;
5315
+ // if there are no points found, we have a valid connection;
5316
+ // otherwise choose the point of the minimum angle with the ray as connection point
5317
+
5318
+ var stop = m,
5319
+ mx = m.x,
5320
+ my = m.y,
5321
+ tanMin = Infinity,
5322
+ tan;
5323
+ p = m;
5324
+
5325
+ do {
5326
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
5327
+ tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
5328
+
5329
+ if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
5330
+ m = p;
5331
+ tanMin = tan;
5332
+ }
5333
+ }
5334
+
5335
+ p = p.next;
5336
+ } while (p !== stop);
5337
+
5338
+ return m;
5339
+ } // whether sector in vertex m contains sector in vertex p in the same coordinates
5340
+
5341
+
5342
+ function sectorContainsSector(m, p) {
5343
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
5344
+ } // interlink polygon nodes in z-order
5345
+
5346
+
5347
+ function indexCurve(start, minX, minY, invSize) {
5348
+ var p = start;
5349
+
5350
+ do {
5351
+ if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);
5352
+ p.prevZ = p.prev;
5353
+ p.nextZ = p.next;
5354
+ p = p.next;
5355
+ } while (p !== start);
5356
+
5357
+ p.prevZ.nextZ = null;
5358
+ p.prevZ = null;
5359
+ sortLinked(p);
5360
+ } // Simon Tatham's linked list merge sort algorithm
5361
+ // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
5362
+
5363
+
5364
+ function sortLinked(list) {
5365
+ var i,
5366
+ p,
5367
+ q,
5368
+ e,
5369
+ tail,
5370
+ numMerges,
5371
+ pSize,
5372
+ qSize,
5373
+ inSize = 1;
5374
+
5375
+ do {
5376
+ p = list;
5377
+ list = null;
5378
+ tail = null;
5379
+ numMerges = 0;
5380
+
5381
+ while (p) {
5382
+ numMerges++;
5383
+ q = p;
5384
+ pSize = 0;
5385
+
5386
+ for (i = 0; i < inSize; i++) {
5387
+ pSize++;
5388
+ q = q.nextZ;
5389
+ if (!q) break;
5390
+ }
5391
+
5392
+ qSize = inSize;
5393
+
5394
+ while (pSize > 0 || qSize > 0 && q) {
5395
+ if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
5396
+ e = p;
5397
+ p = p.nextZ;
5398
+ pSize--;
5399
+ } else {
5400
+ e = q;
5401
+ q = q.nextZ;
5402
+ qSize--;
5403
+ }
5404
+
5405
+ if (tail) tail.nextZ = e;else list = e;
5406
+ e.prevZ = tail;
5407
+ tail = e;
5408
+ }
5409
+
5410
+ p = q;
5411
+ }
5412
+
5413
+ tail.nextZ = null;
5414
+ inSize *= 2;
5415
+ } while (numMerges > 1);
5416
+
5417
+ return list;
5418
+ } // z-order of a point given coords and inverse of the longer side of data bbox
5419
+
5420
+
5421
+ function zOrder(x, y, minX, minY, invSize) {
5422
+ // coords are transformed into non-negative 15-bit integer range
5423
+ x = (x - minX) * invSize | 0;
5424
+ y = (y - minY) * invSize | 0;
5425
+ x = (x | x << 8) & 0x00FF00FF;
5426
+ x = (x | x << 4) & 0x0F0F0F0F;
5427
+ x = (x | x << 2) & 0x33333333;
5428
+ x = (x | x << 1) & 0x55555555;
5429
+ y = (y | y << 8) & 0x00FF00FF;
5430
+ y = (y | y << 4) & 0x0F0F0F0F;
5431
+ y = (y | y << 2) & 0x33333333;
5432
+ y = (y | y << 1) & 0x55555555;
5433
+ return x | y << 1;
5434
+ } // find the leftmost node of a polygon ring
5435
+
5436
+
5437
+ function getLeftmost(start) {
5438
+ var p = start,
5439
+ leftmost = start;
5440
+
5441
+ do {
5442
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
5443
+ p = p.next;
5444
+ } while (p !== start);
5445
+
5446
+ return leftmost;
5447
+ } // check if a point lies within a convex triangle
5448
+
5449
+
5450
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
5451
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
5452
+ } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
5453
+
5454
+
5455
+ function isValidDiagonal(a, b) {
5456
+ return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
5457
+ equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
5458
+ } // signed area of a triangle
5459
+
5460
+
5461
+ function area(p, q, r) {
5462
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
5463
+ } // check if two points are equal
5464
+
5465
+
5466
+ function equals(p1, p2) {
5467
+ return p1.x === p2.x && p1.y === p2.y;
5468
+ } // check if two segments intersect
5469
+
5470
+
5471
+ function intersects(p1, q1, p2, q2) {
5472
+ var o1 = sign(area(p1, q1, p2));
5473
+ var o2 = sign(area(p1, q1, q2));
5474
+ var o3 = sign(area(p2, q2, p1));
5475
+ var o4 = sign(area(p2, q2, q1));
5476
+ if (o1 !== o2 && o3 !== o4) return true; // general case
5477
+
5478
+ if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
5479
+
5480
+ if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
5481
+
5482
+ if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
5483
+
5484
+ if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
5485
+
5486
+ return false;
5487
+ } // for collinear points p, q, r, check if point q lies on segment pr
5488
+
5489
+
5490
+ function onSegment(p, q, r) {
5491
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
5492
+ }
5493
+
5494
+ function sign(num) {
5495
+ return num > 0 ? 1 : num < 0 ? -1 : 0;
5496
+ } // check if a polygon diagonal intersects any polygon segments
5497
+
5498
+
5499
+ function intersectsPolygon(a, b) {
5500
+ var p = a;
5501
+
5502
+ do {
5503
+ if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) return true;
5504
+ p = p.next;
5505
+ } while (p !== a);
5506
+
5507
+ return false;
5508
+ } // check if a polygon diagonal is locally inside the polygon
5509
+
5510
+
5511
+ function locallyInside(a, b) {
5512
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
5513
+ } // check if the middle point of a polygon diagonal is inside the polygon
5514
+
5515
+
5516
+ function middleInside(a, b) {
5517
+ var p = a,
5518
+ inside = false,
5519
+ px = (a.x + b.x) / 2,
5520
+ py = (a.y + b.y) / 2;
5521
+
5522
+ do {
5523
+ if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) inside = !inside;
5524
+ p = p.next;
5525
+ } while (p !== a);
5526
+
5527
+ return inside;
5528
+ } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
5529
+ // if one belongs to the outer ring and another to a hole, it merges it into a single ring
5530
+
5531
+
5532
+ function splitPolygon(a, b) {
5533
+ var a2 = new Node(a.i, a.x, a.y),
5534
+ b2 = new Node(b.i, b.x, b.y),
5535
+ an = a.next,
5536
+ bp = b.prev;
5537
+ a.next = b;
5538
+ b.prev = a;
5539
+ a2.next = an;
5540
+ an.prev = a2;
5541
+ b2.next = a2;
5542
+ a2.prev = b2;
5543
+ bp.next = b2;
5544
+ b2.prev = bp;
5545
+ return b2;
5546
+ } // create a node and optionally link it with previous one (in a circular doubly linked list)
5547
+
5548
+
5549
+ function insertNode(i, x, y, last) {
5550
+ var p = new Node(i, x, y);
5551
+
5552
+ if (!last) {
5553
+ p.prev = p;
5554
+ p.next = p;
5555
+ } else {
5556
+ p.next = last.next;
5557
+ p.prev = last;
5558
+ last.next.prev = p;
5559
+ last.next = p;
5560
+ }
5561
+
5562
+ return p;
5563
+ }
5564
+
5565
+ function removeNode(p) {
5566
+ p.next.prev = p.prev;
5567
+ p.prev.next = p.next;
5568
+ if (p.prevZ) p.prevZ.nextZ = p.nextZ;
5569
+ if (p.nextZ) p.nextZ.prevZ = p.prevZ;
5570
+ }
5571
+
5572
+ function Node(i, x, y) {
5573
+ // vertex index in coordinates array
5574
+ this.i = i; // vertex coordinates
5575
+
5576
+ this.x = x;
5577
+ this.y = y; // previous and next vertex nodes in a polygon ring
5578
+
5579
+ this.prev = null;
5580
+ this.next = null; // z-order curve value
5581
+
5582
+ this.z = 0; // previous and next nodes in z-order
5583
+
5584
+ this.prevZ = null;
5585
+ this.nextZ = null; // indicates whether this is a steiner point
5586
+
5587
+ this.steiner = false;
5588
+ } // return a percentage difference between the polygon area and its triangulation area;
5589
+ // used to verify correctness of triangulation
5590
+
5591
+
5592
+ earcut.deviation = function (data, holeIndices, dim, triangles) {
5593
+ var hasHoles = holeIndices && holeIndices.length;
5594
+ var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
5595
+ var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
5596
+
5597
+ if (hasHoles) {
5598
+ for (var i = 0, len = holeIndices.length; i < len; i++) {
5599
+ var start = holeIndices[i] * dim;
5600
+ var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
5601
+ polygonArea -= Math.abs(signedArea(data, start, end, dim));
5602
+ }
5603
+ }
5604
+
5605
+ var trianglesArea = 0;
5606
+
5607
+ for (i = 0; i < triangles.length; i += 3) {
5608
+ var a = triangles[i] * dim;
5609
+ var b = triangles[i + 1] * dim;
5610
+ var c = triangles[i + 2] * dim;
5611
+ trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
5612
+ }
5613
+
5614
+ return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
5615
+ };
5616
+
5617
+ function signedArea(data, start, end, dim) {
5618
+ var sum = 0;
5619
+
5620
+ for (var i = start, j = end - dim; i < end; i += dim) {
5621
+ sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
5622
+ j = i;
5623
+ }
5624
+
5625
+ return sum;
5626
+ } // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
5627
+
5628
+
5629
+ earcut.flatten = function (data) {
5630
+ var dim = data[0][0].length,
5631
+ result = {
5632
+ vertices: [],
5633
+ holes: [],
5634
+ dimensions: dim
5635
+ },
5636
+ holeIndex = 0;
5637
+
5638
+ for (var i = 0; i < data.length; i++) {
5639
+ for (var j = 0; j < data[i].length; j++) {
5640
+ for (var d = 0; d < dim; d++) {
5641
+ result.vertices.push(data[i][j][d]);
5642
+ }
5643
+ }
5644
+
5645
+ if (i > 0) {
5646
+ holeIndex += data[i - 1].length;
5647
+ result.holes.push(holeIndex);
5648
+ }
5649
+ }
5650
+
5651
+ return result;
5652
+ };
5653
+
5654
+ },{}],13:[function(require,module,exports){
5655
+ "use strict";
5656
+
5657
+ Object.defineProperty(exports, "__esModule", {
5658
+ value: true
5659
+ });
5660
+ exports["default"] = void 0;
5661
+
5662
+ var _earcut = _interopRequireDefault(require("../earcut.js"));
5663
+
5664
+ var _gradient = _interopRequireDefault(require("./gradient.js"));
5665
+
5666
+ var _program = require("./core/program.js");
5667
+
5668
+ var _buffer = require("./core/buffer.js");
5669
+
5670
+ var _texture = require("./core/texture.js");
5671
+
5672
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
5673
+
5674
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
5675
+
5676
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5677
+
5678
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5679
+
5680
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5681
+
5682
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5683
+
5684
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5685
+
5686
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5687
+
5688
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5689
+
5690
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5691
+
5692
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5693
+
5694
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5695
+
5696
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
5697
+
5698
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
5699
+
5700
+ // 把canvas坐标转为webgl坐标系
5701
+ var convertPointSource = "\n vec4 translatePosition(vec4 point, float x, float y) {\n point.x = (point.x-x)/x;\n point.y = (y-point.y)/y;\n return point;\n }"; // 把纹理的canvas坐标转为纹理的坐标系
5702
+
5703
+ var convertTexturePosition = "\n vec2 translateTexturePosition(in vec2 point, vec4 bounds) {\n point.x = (point.x-bounds.x)/bounds.z; // \u79BB\u5DE6\u4E0A\u89D2\u4F4D\u7F6E\u7684X\u957F\u6BD4\u4E0A\u7EB9\u7406\u5BBD 0-1\n point.y = 1.0-(point.y-bounds.y)/bounds.w; // \u79BB\u5DE6\u4E0A\u89D2\u4F4D\u7F6E\u7684Y\u957F\u6BD4\u4E0A\u9AD8\uFF0C\u56E0\u4E3A\u7EB9\u7406\u5750\u6807\u662F\u5DE6\u4E0B\u89D2\u8D77\uFF0C\u6240\u4EE5\u8981\u75281-\n return point;\n }"; // path顶点着色器源码
5704
+
5705
+ var pathVertexSource = "\n attribute vec4 a_position;\n attribute vec4 a_color;\n attribute vec2 a_text_coord;\n uniform vec2 a_center_point; // \u5F53\u524Dcanvas\u7684\u4E2D\u5FC3\u4F4D\u7F6E\n uniform float a_point_size; // \u70B9\u7684\u5927\u5C0F\n uniform int a_type;\n varying vec4 v_color;\n varying vec2 v_text_coord;\n varying float v_type;\n\n ".concat(convertPointSource, "\n\n void main() {\n gl_PointSize = a_point_size == 0.0? 1.0 : a_point_size;\n v_type = float(a_type);\n vec4 pos = translatePosition(a_position, a_center_point.x, a_center_point.y);\n gl_Position = pos;\n v_color = a_color;\n if(a_type == 2) {\n v_text_coord = a_text_coord;\n }\n }\n"); // path 片段着色器源码
5706
+
5707
+ 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 varying float v_type;\n varying vec4 v_color;\n varying vec2 v_text_coord;\n\n ".concat(convertTexturePosition, "\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\n else if(v_type == 3.0) {\n gl_FragColor = v_color;\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");
5708
+
5709
+ var WeblBase = /*#__PURE__*/function () {
5710
+ function WeblBase(graph, option) {
5711
+ _classCallCheck(this, WeblBase);
5712
+
5713
+ this.graph = graph;
5714
+ this.option = option || {};
5715
+ this.style = {
5716
+ globalAlpha: 1
5717
+ };
5718
+ }
5719
+
5720
+ _createClass(WeblBase, [{
5721
+ key: "context",
5722
+ get: function get() {
5723
+ if (this.graph) return this.graph.context;
5724
+ } // 纹理绘制canvas
5725
+
5726
+ }, {
5727
+ key: "textureCanvas",
5728
+ get: function get() {
5729
+ var canvas = this.graph.textureCanvas;
5730
+
5731
+ if (!canvas) {
5732
+ if (typeof document === 'undefined') return null;
5733
+ canvas = this.graph.textureCanvas = document.createElement('canvas');
5734
+ }
5735
+
5736
+ return canvas;
5737
+ } // 纹理绘制canvas ctx
5738
+
5739
+ }, {
5740
+ key: "textureContext",
5741
+ get: function get() {
5742
+ var ctx = this.textureCanvas.ctx || (this.textureCanvas.ctx = this.textureCanvas.getContext('2d', {
5743
+ willReadFrequently: true
5744
+ }));
5745
+ return ctx;
5746
+ } // i当前程序
5747
+
5748
+ }, {
5749
+ key: "program",
5750
+ get: function get() {
5751
+ // 默认所有path用同一个编译好的program
5752
+ return this.graph.context.pathProgram || (this.graph.context.pathProgram = this.createProgram(pathVertexSource, pathFragmentSource));
5753
+ } // 设置样式
5754
+
5755
+ }, {
5756
+ key: "setStyle",
5757
+ value: function setStyle() {
5758
+ var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.style;
5759
+ var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
5760
+
5761
+ if (typeof style === 'string') {
5762
+ var obj = {};
5763
+ obj[style] = value;
5764
+ style = obj;
5765
+ }
5766
+ /*
5767
+ // 设置线条颜色或填充色
5768
+ if(style.strokeStyle) {
5769
+ let color = style.strokeStyle;
5770
+ if(typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
5771
+ this.style.strokeStyle = this.graph.utils.rgbToDecimal(color);
5772
+ delete style.strokeStyle;
5773
+ }
5774
+ else if(style.fillStyle) {
5775
+ let color = style.fillStyle;
5776
+ if(this.isGradient(color)) {
5777
+ this.style.fillStyle = color;
5778
+ }
5779
+ else {
5780
+ if(typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
5781
+ this.style.fillStyle = this.graph.utils.rgbToDecimal(color);
5782
+ }
5783
+ delete style.fillStyle;
5784
+ } */
5785
+
5786
+
5787
+ this.style = _objectSpread(_objectSpread({}, this.style), style);
5788
+ } // 把传统颜色转为webgl识别的
5789
+
5790
+ }, {
5791
+ key: "convertColor",
5792
+ value: function convertColor(color) {
5793
+ if (this.isGradient(color)) return color;
5794
+ if (typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
5795
+ return this.graph.utils.rgbToDecimal(color);
5796
+ }
5797
+ }, {
5798
+ key: "setTextureStyle",
5799
+ value: function setTextureStyle(style) {
5800
+ var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
5801
+
5802
+ if (typeof style === 'string') {
5803
+ if (['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(style) > -1) {
5804
+ value = this.graph.utils.toColor(value);
5805
+ }
5806
+
5807
+ this.textureContext[style] = value;
5808
+ } else {
5809
+ for (var name in style) {
5810
+ if (name === 'constructor') continue;
5811
+ this.setTextureStyle(name, style[name]);
5812
+ }
5813
+ }
5814
+ } // 创建程序
5815
+
5816
+ }, {
5817
+ key: "createProgram",
5818
+ value: function createProgram(vertexSrc, fragmentSrc) {
5819
+ this.context.lineWidth(1);
5820
+ return (0, _program.createProgram)(this.context, vertexSrc, fragmentSrc);
5821
+ } // 指定使用某个程序
5822
+
5823
+ }, {
5824
+ key: "useProgram",
5825
+ value: function useProgram() {
5826
+ var program = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.program;
5827
+ program = program.program || program;
5828
+ if (this.context.__curent_program === program) return program;
5829
+ (0, _program.useProgram)(this.context, program.program || program);
5830
+ this.context.__curent_program = program;
5831
+ return program;
5832
+ }
5833
+ }, {
5834
+ key: "getAttribLocation",
5835
+ value: function getAttribLocation(name) {
5836
+ return this.context.getAttribLocation(this.program.program, name);
5837
+ }
5838
+ }, {
5839
+ key: "getUniformLocation",
5840
+ value: function getUniformLocation(name) {
5841
+ return this.context.getUniformLocation(this.program.program, name);
5842
+ } // 把缓冲区的值写入变量
5843
+ // buffer: 缓冲区
5844
+ // size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
5845
+ // strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
5846
+ // offset: 字节偏移量,必须是类型的字节长度的倍数。
5847
+ // dataType: 每个元素的数据类型
5848
+
5849
+ }, {
5850
+ key: "writeVertexAttrib",
5851
+ value: function writeVertexAttrib(buffer, attr) {
5852
+ var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
5853
+ var strip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
5854
+ var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
5855
+ var dataType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this.context.FLOAT;
5856
+ buffer.attr = attr;
5857
+ return (0, _program.writeVertexAttrib)(this.context, buffer, attr, size, strip, offset, dataType);
5858
+ } // 禁用attri
5859
+
5860
+ }, {
5861
+ key: "disableVertexAttribArray",
5862
+ value: function disableVertexAttribArray(attr) {
5863
+ try {
5864
+ if (!attr) return attr;
5865
+ return (0, _program.disableVertexAttribArray)(this.context, attr);
5866
+ } catch (e) {
5867
+ console.error(e);
5868
+ }
5869
+
5870
+ return attr;
5871
+ } // 创建float32的buffer
5872
+
5873
+ }, {
5874
+ key: "createFloat32Buffer",
5875
+ value: function createFloat32Buffer(data) {
5876
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.context.ARRAY_BUFFER;
5877
+ var drawType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.context.STATIC_DRAW;
5878
+ var buffer = (0, _buffer.createFloat32Buffer)(this.context, data, type, drawType);
5879
+ return _objectSpread({
5880
+ data: data
5881
+ }, buffer);
5882
+ }
5883
+ }, {
5884
+ key: "createUint16Buffer",
5885
+ value: function createUint16Buffer(data) {
5886
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.context.ARRAY_BUFFER;
5887
+ var drawType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.context.STATIC_DRAW;
5888
+ var buffer = (0, _buffer.createUint16Buffer)(this.context, data, type, drawType);
5889
+ return _objectSpread({
5890
+ data: data
5891
+ }, buffer);
5892
+ } // 释放
5893
+
5894
+ }, {
5895
+ key: "deleteBuffer",
5896
+ value: function deleteBuffer(buffer) {
5897
+ try {
5898
+ if (!buffer) return;
5899
+ var bufferHandler = buffer.buffer || buffer;
5900
+ if (bufferHandler) return (0, _buffer.deleteBuffer)(this.context, bufferHandler);
5901
+ } catch (e) {
5902
+ console.log(buffer);
5903
+ console.error(e);
5904
+ }
5905
+
5906
+ return buffer;
5907
+ } // 生成纹理
5908
+
5909
+ }, {
5910
+ key: "create2DTexture",
5911
+ value: function create2DTexture() {
5912
+ return (0, _texture.create2DTexture)(this.context);
5913
+ } // 创建图片纹理
5914
+
5915
+ }, {
5916
+ key: "createImgTexture",
5917
+ value: function createImgTexture(img) {
5918
+ return (0, _texture.createImgTexture)(this.context, img);
5919
+ } // 根根像素值生成纹理
5920
+
5921
+ }, {
5922
+ key: "createDataTexture",
5923
+ value: function createDataTexture(data) {
5924
+ return (0, _texture.createDataTexture)(this.context, data);
5925
+ } // 删除纹理
5926
+
5927
+ }, {
5928
+ key: "deleteTexture",
5929
+ value: function deleteTexture(texture) {
5930
+ try {
5931
+ return (0, _texture.deleteTexture)(this.context, texture.texture || texture);
5932
+ } catch (e) {
5933
+ console.error(e);
5934
+ }
5935
+
5936
+ return texture;
5937
+ } // 多边切割, 得到三角形顶点索引数组
5938
+ // polygonIndices 顶点索引,
5939
+
5940
+ }, {
5941
+ key: "earCutPoints",
5942
+ value: function earCutPoints(points) {
5943
+ var arr = this.pointsToArray(points);
5944
+ var ps = (0, _earcut["default"])(arr); // 切割得到3角色顶点索引,
5945
+
5946
+ return ps;
5947
+ } // 多边切割, 得到三角形顶点
5948
+ // polygonIndices 顶点索引,
5949
+
5950
+ }, {
5951
+ key: "earCutPointsToTriangles",
5952
+ value: function earCutPointsToTriangles(points) {
5953
+ var ps = this.earCutPoints(points); // 切割得到3角色顶点索引,
5954
+
5955
+ var triangles = []; // 用顶点索引再组合成坐标数组
5956
+
5957
+ for (var i = 0; i < ps.length; i += 3) {
5958
+ var p1 = points[ps[i]];
5959
+ var p2 = points[ps[i + 1]];
5960
+ var p3 = points[ps[i + 2]];
5961
+ triangles.push([p1, p2, p3]); // 每三个顶点构成一个三角
5962
+ }
5963
+
5964
+ return triangles;
5965
+ } // 点坐标数组转为一维数组
5966
+
5967
+ }, {
5968
+ key: "pointsToArray",
5969
+ value: function pointsToArray(points) {
5970
+ var _ref;
5971
+
5972
+ return (_ref = []).concat.apply(_ref, _toConsumableArray(points.map(function (p) {
5973
+ return [p.x, p.y];
5974
+ }))); // 把x,y转为数组元素
5975
+ } // 每2位表示坐标x,y转为坐标点对象
5976
+
5977
+ }, {
5978
+ key: "arrayToPoints",
5979
+ value: function arrayToPoints(arr) {
5980
+ var points = [];
5981
+
5982
+ for (var i = 0; i < arr.length; i += 2) {
5983
+ points.push({
5984
+ x: arr[i],
5985
+ y: arr[i + 1]
5986
+ });
5987
+ }
5988
+
5989
+ return points;
5990
+ } // 创建线性渐变
5991
+
5992
+ }, {
5993
+ key: "createLinearGradient",
5994
+ value: function createLinearGradient(x1, y1, x2, y2, bounds) {
5995
+ return new _gradient["default"]('linear', {
5996
+ x1: x1,
5997
+ y1: y1,
5998
+ x2: x2,
5999
+ y2: y2,
6000
+ bounds: bounds,
6001
+ control: this
6002
+ });
6003
+ } // 创建放射性渐变
6004
+
6005
+ }, {
6006
+ key: "createRadialGradient",
6007
+ value: function createRadialGradient(x1, y1, r1, x2, y2, r2, bounds) {
6008
+ return new _gradient["default"]('radial', {
6009
+ x1: x1,
6010
+ y1: y1,
6011
+ r1: r1,
6012
+ x2: x2,
6013
+ y2: y2,
6014
+ r2: r2,
6015
+ bounds: bounds,
6016
+ control: this
6017
+ });
6018
+ } // 判断是否是一个渐变对象
6019
+
6020
+ }, {
6021
+ key: "isGradient",
6022
+ value: function isGradient(obj) {
6023
+ return obj && obj instanceof _gradient["default"];
6024
+ }
6025
+ /**
6026
+ * 测试获取文本所占大小
6027
+ *
6028
+ * @method testSize
6029
+ * @return {object} 含文本大小的对象
6030
+ */
6031
+
6032
+ }, {
6033
+ key: "testSize",
6034
+ value: function testSize(text) {
6035
+ var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.style;
6036
+ this.textureContext.save && this.textureContext.save(); // 修改字体,用来计算
6037
+
6038
+ if (style.font || style.fontSize) this.textureContext.font = style.font || style.fontSize + 'px ' + style.fontFamily; //计算宽度
6039
+
6040
+ var size = this.textureContext.measureText ? this.textureContext.measureText(text) : {
6041
+ width: 15
6042
+ };
6043
+ this.textureContext.restore && this.textureContext.restore();
6044
+ size.height = this.style.fontSize ? this.style.fontSize : 15;
6045
+ return size;
6046
+ } // 使用纹理canvas生成图,
6047
+ // 填充可以是颜色或渐变对象
6048
+ // 如果指定了points,则表明要绘制不规则的图形
6049
+
6050
+ }, {
6051
+ key: "toFillTexture",
6052
+ value: function toFillTexture(fillStyle, bounds) {
6053
+ var points = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
6054
+ var canvas = this.textureCanvas;
6055
+
6056
+ if (!canvas) {
6057
+ return fillStyle;
6058
+ }
6059
+
6060
+ canvas.width = bounds.width;
6061
+ canvas.height = bounds.height;
6062
+
6063
+ if (!canvas.width || !canvas.height) {
6064
+ return fillStyle;
6065
+ }
6066
+
6067
+ this.textureContext.clearRect(0, 0, canvas.width, canvas.height);
6068
+ this.textureContext.fillStyle = fillStyle;
6069
+ this.textureContext.beginPath();
6070
+
6071
+ if (!points || !points.length) {
6072
+ points = [];
6073
+ points.push({
6074
+ x: bounds.left,
6075
+ y: bounds.top
6076
+ });
6077
+ points.push({
6078
+ x: bounds.left + bounds.width,
6079
+ y: bounds.top
6080
+ });
6081
+ points.push({
6082
+ x: bounds.left + bounds.width,
6083
+ y: bounds.top + bounds.height
6084
+ });
6085
+ points.push({
6086
+ x: bounds.left,
6087
+ y: bounds.top + bounds.height
6088
+ });
6089
+ points.push({
6090
+ x: bounds.left,
6091
+ y: bounds.top
6092
+ });
6093
+ }
6094
+
6095
+ if (points && points.length) {
6096
+ var _iterator = _createForOfIteratorHelper(points),
6097
+ _step;
6098
+
6099
+ try {
6100
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6101
+ var p = _step.value;
6102
+
6103
+ //移至当前坐标
6104
+ if (p.m) {
6105
+ this.textureContext.moveTo(p.x - bounds.left, p.y - bounds.top);
6106
+ } else {
6107
+ this.textureContext.lineTo(p.x - bounds.left, p.y - bounds.top);
6108
+ }
6109
+ }
6110
+ } catch (err) {
6111
+ _iterator.e(err);
6112
+ } finally {
6113
+ _iterator.f();
6114
+ }
6115
+ } else {
6116
+ this.textureContext.moveTo(0, 0);
6117
+ this.textureContext.lineTo(bounds.width, 0);
6118
+ this.textureContext.lineTo(bounds.width, bounds.height);
6119
+ this.textureContext.lineTo(0, bounds.height);
6120
+ this.textureContext.lineTo(0, 0);
6121
+ }
6122
+
6123
+ this.textureContext.closePath();
6124
+ this.textureContext.fill();
6125
+ var data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
6126
+ return {
6127
+ data: data,
6128
+ points: points
6129
+ };
6130
+ }
6131
+ }]);
6132
+
6133
+ return WeblBase;
6134
+ }();
6135
+
6136
+ var _default = WeblBase;
6137
+ exports["default"] = _default;
6138
+
6139
+ },{"../earcut.js":12,"./core/buffer.js":14,"./core/program.js":17,"./core/texture.js":19,"./gradient.js":20}],14:[function(require,module,exports){
6140
+ "use strict";
6141
+
6142
+ Object.defineProperty(exports, "__esModule", {
6143
+ value: true
6144
+ });
6145
+ exports.createBuffer = createBuffer;
6146
+ exports.createUint16Buffer = createUint16Buffer;
6147
+ exports.createFloat32Buffer = createFloat32Buffer;
6148
+ exports.deleteBuffer = deleteBuffer;
6149
+
6150
+ // 创建缓冲区
6151
+ function createBuffer(gl, data) {
6152
+ var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
6153
+ var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
6154
+ //先创建一个缓存对象
6155
+ var buffer = gl.createBuffer();
6156
+
6157
+ if (!buffer) {
6158
+ throw Error('创建缓冲区对象失败');
6159
+ } //说明缓存对象保存的类型
6160
+
6161
+
6162
+ gl.bindBuffer(type, buffer); //写入坐标数据
6163
+ // 因为会将数据发送到 GPU,为了省去数据解析,这里使用 Float32Array 直接传送数据
6164
+ // data.buffer这里要使用data.buffer,否则在edge下可能导至数据发生较大的改变
6165
+
6166
+ gl.bufferData(type, data.buffer || data, drawType); // 表示缓冲区的内容不会经常更改
6167
+
6168
+ return {
6169
+ type: type,
6170
+ drawType: drawType,
6171
+ buffer: buffer,
6172
+ // 获取到数组中单个元素的字节数
6173
+ unitSize: data.BYTES_PER_ELEMENT
6174
+ };
6175
+ } // 创建float32的buffer
6176
+
6177
+
6178
+ function createFloat32Buffer(gl, data) {
6179
+ var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
6180
+ var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
6181
+ var vertices = new Float32Array(data);
6182
+ var buffer = createBuffer(gl, vertices, type, drawType);
6183
+ return buffer;
6184
+ } // 创建uint16的bugger
6185
+
6186
+
6187
+ function createUint16Buffer(gl, data) {
6188
+ var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
6189
+ var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
6190
+ var vertices = new Uint16Array(data);
6191
+ var buffer = createBuffer(gl, vertices, type, drawType);
6192
+ return buffer;
6193
+ } // 释放
6194
+
6195
+
6196
+ function deleteBuffer(gl, buffer) {
6197
+ gl.deleteBuffer(buffer.buffer || buffer);
6198
+ }
6199
+
6200
+ },{}],15:[function(require,module,exports){
6201
+ "use strict";
6202
+
6203
+ Object.defineProperty(exports, "__esModule", {
6204
+ value: true
6205
+ });
6206
+ exports.mapSize = void 0;
6207
+ var GLSL_TO_SIZE = {
6208
+ 'float': 1,
6209
+ 'vec2': 2,
6210
+ 'vec3': 3,
6211
+ 'vec4': 4,
6212
+ 'int': 1,
6213
+ 'ivec2': 2,
6214
+ 'ivec3': 3,
6215
+ 'ivec4': 4,
6216
+ 'bool': 1,
6217
+ 'bvec2': 2,
6218
+ 'bvec3': 3,
6219
+ 'bvec4': 4,
6220
+ 'mat2': 4,
6221
+ 'mat3': 9,
6222
+ 'mat4': 16,
6223
+ 'sampler2D': 1
6224
+ };
6225
+ /**
6226
+ * @class
6227
+ * @memberof PIXI.glCore.shader
6228
+ * @param type {String}
6229
+ * @return {Number}
6230
+ */
6231
+
6232
+ var mapSize = function mapSize(type) {
6233
+ return GLSL_TO_SIZE[type];
6234
+ };
6235
+
6236
+ exports.mapSize = mapSize;
6237
+
6238
+ },{}],16:[function(require,module,exports){
6239
+ "use strict";
6240
+
6241
+ Object.defineProperty(exports, "__esModule", {
6242
+ value: true
6243
+ });
6244
+ exports.mapType = void 0;
6245
+ var GL_TABLE = null;
6246
+ var GL_TO_GLSL_TYPES = {
6247
+ 'FLOAT': 'float',
6248
+ 'FLOAT_VEC2': 'vec2',
6249
+ 'FLOAT_VEC3': 'vec3',
6250
+ 'FLOAT_VEC4': 'vec4',
6251
+ 'INT': 'int',
6252
+ 'INT_VEC2': 'ivec2',
6253
+ 'INT_VEC3': 'ivec3',
6254
+ 'INT_VEC4': 'ivec4',
6255
+ 'BOOL': 'bool',
6256
+ 'BOOL_VEC2': 'bvec2',
6257
+ 'BOOL_VEC3': 'bvec3',
6258
+ 'BOOL_VEC4': 'bvec4',
6259
+ 'FLOAT_MAT2': 'mat2',
6260
+ 'FLOAT_MAT3': 'mat3',
6261
+ 'FLOAT_MAT4': 'mat4',
6262
+ 'SAMPLER_2D': 'sampler2D'
6263
+ };
6264
+
6265
+ var mapType = function mapType(gl, type) {
6266
+ if (!GL_TABLE) {
6267
+ var typeNames = Object.keys(GL_TO_GLSL_TYPES);
6268
+ GL_TABLE = {};
6269
+
6270
+ for (var i = 0; i < typeNames.length; ++i) {
6271
+ var tn = typeNames[i];
6272
+ GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn];
6273
+ }
6274
+ }
6275
+
6276
+ return GL_TABLE[type];
6277
+ };
6278
+
6279
+ exports.mapType = mapType;
6280
+
6281
+ },{}],17:[function(require,module,exports){
6282
+ "use strict";
6283
+
6284
+ Object.defineProperty(exports, "__esModule", {
6285
+ value: true
6286
+ });
6287
+ exports.createProgram = createProgram;
6288
+ exports.useProgram = useProgram;
6289
+ exports.getAttribLocation = getAttribLocation;
6290
+ exports.getUniformLocation = getUniformLocation;
6291
+ exports.extractAttributes = extractAttributes;
6292
+ exports.extractUniforms = extractUniforms;
6293
+ exports.writeVertexAttrib = writeVertexAttrib;
6294
+ exports.disableVertexAttribArray = disableVertexAttribArray;
6295
+
6296
+ var _shader = require("./shader.js");
6297
+
6298
+ var _mapSize = require("./mapSize.js");
6299
+
6300
+ var _mapType = require("./mapType.js");
6301
+
6302
+ // 创建程序
6303
+ function createProgram(gl, vertexSrc, fragmentSrc) {
6304
+ // 创建顶点着色器
6305
+ var vertexShader = (0, _shader.createShader)(gl, gl.VERTEX_SHADER, vertexSrc); // 创建片段着色器
6306
+
6307
+ var fragmentShader = (0, _shader.createShader)(gl, gl.FRAGMENT_SHADER, fragmentSrc);
6308
+ var program = gl.createProgram(); // 创建一个程序
6309
+
6310
+ gl.attachShader(program, vertexShader); // 添加顶点着色器
6311
+
6312
+ gl.attachShader(program, fragmentShader); // 添加片元着色器
6313
+
6314
+ gl.linkProgram(program); // 连接 program 中的着色器
6315
+ // 检查程序链接状态
6316
+
6317
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
6318
+ console.error('PError: Could not initialize shader.');
6319
+ console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS));
6320
+ console.error('gl.getError()', gl.getError()); // if there is a program info log, log it
6321
+
6322
+ if (gl.getProgramInfoLog(program) !== '') {
6323
+ console.warn('Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
6324
+ }
6325
+
6326
+ gl.deleteProgram(program);
6327
+ }
6328
+
6329
+ useProgram(gl, program); // clean up some shaders
6330
+
6331
+ gl.deleteShader(vertexShader);
6332
+ gl.deleteShader(fragmentShader);
6333
+ var attrs = extractAttributes(gl, program);
6334
+ var uniforms = extractUniforms(gl, program);
6335
+ return {
6336
+ program: program,
6337
+ attrs: attrs,
6338
+ uniforms: uniforms
6339
+ };
6340
+ } // 采用program
6341
+
6342
+
6343
+ function useProgram(gl, program) {
6344
+ return gl.useProgram(program); // 告诉 webgl 用这个 program 进行渲染
6345
+ }
6346
+
6347
+ function extractAttributes(gl, program) {
6348
+ var attributes = {};
6349
+ var count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
6350
+
6351
+ for (var i = 0; i < count; i++) {
6352
+ var attribData = gl.getActiveAttrib(program, i);
6353
+ var type = (0, _mapType.mapType)(gl, attribData.type);
6354
+ attributes[attribData.name] = {
6355
+ attribData: attribData,
6356
+ size: (0, _mapSize.mapSize)(type),
6357
+ type: type,
6358
+ location: gl.getAttribLocation(program, attribData.name)
6359
+ };
6360
+ }
6361
+
6362
+ return attributes;
6363
+ }
6364
+
6365
+ function extractUniforms(gl, program) {
6366
+ var uniforms = {};
6367
+ var count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
6368
+
6369
+ for (var i = 0; i < count; i++) {
6370
+ var uniformData = gl.getActiveUniform(program, i);
6371
+ var name = uniformData.name.replace(/\[.*?\]/, "");
6372
+ var type = (0, _mapType.mapType)(gl, uniformData.type);
6373
+ uniforms[name] = {
6374
+ uniformData: uniformData,
6375
+ type: type,
6376
+ size: uniformData.size,
6377
+ location: gl.getUniformLocation(program, name)
6378
+ };
6379
+ }
6380
+
6381
+ return uniforms;
6382
+ }
6383
+
6384
+ ; // 把缓冲区的值写入变量
6385
+ // size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
6386
+ // strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
6387
+ // offset: 字节偏移量,必须是类型的字节长度的倍数。
6388
+ // dataType: 每个元素的数据类型
6389
+
6390
+ function writeVertexAttrib(gl, buffer, attr) {
6391
+ var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
6392
+ var strip = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
6393
+ var offset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
6394
+ var dataType = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : gl.FLOAT;
6395
+ gl.bindBuffer(buffer.type, buffer.buffer);
6396
+ gl.vertexAttribPointer( // 告诉 OpenGL 如何从 Buffer 中获取数据
6397
+ attr.location, // 顶点属性的索引
6398
+ size, // 组成数量,必须是1,2,3或4。我们只提供了 x 和 y
6399
+ dataType, false, // 是否归一化到特定的范围,对 FLOAT 类型数据设置无效
6400
+ strip * buffer.unitSize, offset);
6401
+ gl.enableVertexAttribArray(attr.location);
6402
+ return buffer;
6403
+ }
6404
+
6405
+ function disableVertexAttribArray(gl, attr) {
6406
+ return gl.disableVertexAttribArray(attr.location);
6407
+ }
6408
+
6409
+ function getAttribLocation(gl, program, name) {
6410
+ return gl.getAttribLocation(program, name);
6411
+ }
6412
+
6413
+ function getUniformLocation(gl, program, name) {
6414
+ return gl.getUniformLocation(program, name);
6415
+ }
6416
+
6417
+ },{"./mapSize.js":15,"./mapType.js":16,"./shader.js":18}],18:[function(require,module,exports){
6418
+ "use strict";
6419
+
6420
+ Object.defineProperty(exports, "__esModule", {
6421
+ value: true
6422
+ });
6423
+ exports.createShader = createShader;
6424
+
6425
+ // 生成着色器
6426
+ // type: gl.VERTEX_SHADER 顶点着色器 , gl.FRAGMENT_SHADER 片段着色器
6427
+ // src: 着色器代码
6428
+ function createShader(gl, type, src) {
6429
+ var shader = gl.createShader(type); // 创建一个顶点着色器
6430
+
6431
+ gl.shaderSource(shader, src); // 编写顶点着色器代码
6432
+
6433
+ gl.compileShader(shader); // 编译着色器
6434
+
6435
+ return shader;
6436
+ }
6437
+
6438
+ },{}],19:[function(require,module,exports){
6439
+ "use strict";
6440
+
6441
+ Object.defineProperty(exports, "__esModule", {
6442
+ value: true
6443
+ });
6444
+ exports.create2DTexture = create2DTexture;
6445
+ exports.createImgTexture = createImgTexture;
6446
+ exports.createDataTexture = createDataTexture;
6447
+ exports.deleteTexture = deleteTexture;
6448
+
6449
+ // 生成纹理
6450
+ function create2DTexture(gl) {
6451
+ var texture = gl.createTexture();
6452
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); // 图像反转Y轴
6453
+
6454
+ gl.activeTexture(gl.TEXTURE0); // 激活纹理单元
6455
+
6456
+ gl.bindTexture(gl.TEXTURE_2D, texture); // 绑定纹理对象
6457
+ //gl.generateMipmap(gl.TEXTURE_2D);
6458
+
6459
+ gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); // 放大处理方式 // LINEAR / NEAREST
6460
+
6461
+ gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); // 缩小处理方式
6462
+
6463
+ gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // 水平平铺方式
6464
+
6465
+ gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // 竖直平铺方式
6466
+
6467
+ return texture;
6468
+ } // 创建图片纹理
6469
+
6470
+
6471
+ function createImgTexture(gl, img) {
6472
+ var texture = create2DTexture(gl);
6473
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); // 配置纹理图像
6474
+
6475
+ return {
6476
+ texture: texture
6477
+ };
6478
+ } // 用像素值来绘制纹理
6479
+
6480
+
6481
+ function createDataTexture(gl, pixels) {
6482
+ var data = new Uint8Array(pixels.data || pixels);
6483
+ var texture = create2DTexture(gl);
6484
+ gl.texImage2D(gl.TEXTURE_2D, // 纹理目标
6485
+ 0, // 细节级别,指定详细级别。0 级是基本图像等级,n 级是第 n 个金字塔简化级。
6486
+ gl.RGBA, // 纹理内部格式
6487
+ pixels.width || 1, // 指定纹理的宽度
6488
+ pixels.height || 1, // 指定纹理的高度
6489
+ 0, // 指定纹理的边框宽度。必须为 0。
6490
+ gl.RGBA, // 源图像数据格式
6491
+ gl.UNSIGNED_BYTE, // 纹理数据类型
6492
+ data // 数据
6493
+ );
6494
+ return {
6495
+ texture: texture
6496
+ };
6497
+ } // 删除纹理
6498
+
6499
+
6500
+ function deleteTexture(gl, texture) {
6501
+ return gl.deleteTexture(texture);
6502
+ }
6503
+
6504
+ },{}],20:[function(require,module,exports){
6505
+ "use strict";
6506
+
6507
+ Object.defineProperty(exports, "__esModule", {
6508
+ value: true
6509
+ });
6510
+ exports["default"] = void 0;
6511
+
6512
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6513
+
6514
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6515
+
6516
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6517
+
6518
+ var WebglGradientTextureCache = {}; // 渐变
6519
+
6520
+ var WebglGradient = /*#__PURE__*/function () {
6521
+ // type:[linear= 线性渐变,radial=放射性渐变]
6522
+ function WebglGradient() {
6523
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'linear';
6524
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6525
+
6526
+ _classCallCheck(this, WebglGradient);
6527
+
6528
+ this.type = type || 'linear';
6529
+ this.x1 = params.x1 || 0;
6530
+ this.y1 = params.y1 || 0;
6531
+ this.r1 = params.r1 || 0;
6532
+ this.x2 = params.x2 || 0;
6533
+ this.y2 = params.y2 || 0;
6534
+ this.r2 = params.r2 || 0;
6535
+ this.bounds = params.bounds || {
6536
+ left: 0,
6537
+ top: 0,
6538
+ width: 0,
6539
+ height: 0
6540
+ };
6541
+ this.control = params.control;
6542
+ this.stops = [];
6543
+ this.init();
6544
+ }
6545
+
6546
+ _createClass(WebglGradient, [{
6547
+ key: "init",
6548
+ value: function init() {
6549
+ var dx = this.x2 - this.x1;
6550
+ var dy = this.y2 - this.y1;
6551
+
6552
+ if (this.type === 'radial') {
6553
+ this.length = this.r2 - this.r1;
6554
+ } else if (dx === 0 && dy === 0) {
6555
+ this.length = 0;
6556
+ } else {
6557
+ // 渐变中心的距离
6558
+ this.length = Math.sqrt(Math.pow(dx, 2), Math.pow(dy, 2));
6559
+ this.sin = dy / this.length;
6560
+ this.cos = dx / this.length;
6561
+ }
6562
+ } // 渐变颜色
6563
+
6564
+ }, {
6565
+ key: "addColorStop",
6566
+ value: function addColorStop(offset, color) {
6567
+ this.stops.push({
6568
+ offset: offset,
6569
+ color: color
6570
+ });
6571
+ } // 转为渐变为纹理
6572
+
6573
+ }, {
6574
+ key: "toImageData",
6575
+ value: function toImageData(control, bounds) {
6576
+ var points = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
6577
+
6578
+ //const key = this.key || this.toString();
6579
+ //if(WebglGradientTextureCache[key]) return WebglGradientTextureCache[key];
6580
+ if (!control.textureContext) {
6581
+ return null;
6582
+ }
6583
+
6584
+ var gradient = null;
6585
+
6586
+ if (this.type === 'linear') {
6587
+ gradient = control.textureContext.createLinearGradient(this.x1, this.y1, this.x2, this.y2);
6588
+ } else {
6589
+ gradient = control.textureContext.createRadialGradient(this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
6590
+ }
6591
+
6592
+ this.stops.forEach(function (s, i) {
6593
+ var c = control.graph.utils.toColor(s.color);
6594
+ gradient && gradient.addColorStop(s.offset, c);
6595
+ });
6596
+ var data = control.toFillTexture(gradient, bounds, points); //WebglGradientTextureCache[key] = data;
6597
+
6598
+ return data;
6599
+ } // 根据绘制图形的坐标计算出对应点的颜色
6600
+
6601
+ /*
6602
+ toPointColors(points) {
6603
+ const stops = this.getStops();
6604
+ const colors = [];
6605
+ for(let i=0; i<points.length; i+=2) {
6606
+ const p = {
6607
+ x: points[i],
6608
+ y: points[i+1]
6609
+ }
6610
+ if(this.type === 'radial') {
6611
+ const dx = p.x - this.x1;
6612
+ const dy = p.y - this.y1;
6613
+ const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
6614
+ const rang = this.getStopRange(len, stops);
6615
+ if(!rang.start && rang.end) {
6616
+ colors.push(rang.end.color);
6617
+ }
6618
+ else if(!rang.end && rang.start) {
6619
+ colors.push(rang.start.color);
6620
+ }
6621
+ else {
6622
+ const rangLength = rang.end.length - rang.start.length;
6623
+ const offlen = len - rang.start.length;
6624
+ const per = offlen / rangLength;
6625
+ const color = {
6626
+ r: rang.start.color.r + (rang.end.color.r - rang.start.color.r) * per,
6627
+ g: rang.start.color.g + (rang.end.color.g - rang.start.color.g) * per,
6628
+ b: rang.start.color.b + (rang.end.color.b - rang.start.color.b) * per,
6629
+ a: rang.start.color.a + (rang.end.color.a - rang.start.color.a) * per,
6630
+ };
6631
+ colors.push(color);
6632
+ }
6633
+ }
6634
+ }
6635
+ return colors;
6636
+ }
6637
+ */
6638
+ // 根据起点距离获取边界stop
6639
+
6640
+ /*
6641
+ getStopRange(len, stops) {
6642
+ const res = {};
6643
+ for(const s of stops) {
6644
+ if(s.length <= len) {
6645
+ res.start = s;
6646
+ }
6647
+ else {
6648
+ res.end = s;
6649
+ }
6650
+ }
6651
+ return res;
6652
+ }
6653
+ // 根据stop计算offset长度
6654
+ getStops() {
6655
+ const stops = this.stops.sort((p1, p2) => p1.offset - p2.offset); // 渐变色排序从小于大
6656
+ for(const s of stops) {
6657
+
6658
+ const color = typeof s.color === 'string'? this.control.graph.utils.hexToRGBA(s.color) : s.color;
6659
+ console.log(s, color);
6660
+ s.color = this.control.graph.utils.rgbToDecimal(color);
6661
+ s.length = s.offset * this.length;
6662
+ }
6663
+ return stops;
6664
+ }
6665
+ */
6666
+
6667
+ /**
6668
+ * 转换为渐变的字符串表达
6669
+ *
6670
+ * @method toString
6671
+ * @for jmGradient
6672
+ * @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
6673
+ */
6674
+
6675
+ }, {
6676
+ key: "toString",
6677
+ value: function toString() {
6678
+ var str = this.type + '-gradient(';
6679
+
6680
+ if (this.type == 'linear') {
6681
+ str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
6682
+ } else {
6683
+ str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
6684
+ } //颜色渐变
6685
+
6686
+
6687
+ this.stops.forEach(function (s) {
6688
+ str += ',' + s.color + ' ' + s.offset;
6689
+ });
6690
+ return str + ')';
6691
+ }
6692
+ }]);
6693
+
6694
+ return WebglGradient;
6695
+ }();
6696
+
6697
+ var _default = WebglGradient;
6698
+ exports["default"] = _default;
6699
+
6700
+ },{}],21:[function(require,module,exports){
6701
+ "use strict";
6702
+
6703
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
6704
+
6705
+ Object.defineProperty(exports, "__esModule", {
6706
+ value: true
6707
+ });
6708
+ exports["default"] = void 0;
6709
+
6710
+ var _base = _interopRequireDefault(require("./base.js"));
6711
+
6712
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6713
+
6714
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6715
+
6716
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6717
+
6718
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6719
+
6720
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6721
+
6722
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
6723
+
6724
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6725
+
6726
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6727
+
6728
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6729
+
6730
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6731
+
6732
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6733
+
6734
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
6735
+
6736
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6737
+
6738
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
6739
+
6740
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
6741
+
6742
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
6743
+
6744
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
6745
+
6746
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
6747
+
6748
+ // path 绘制类
6749
+ var WebglPath = /*#__PURE__*/function (_WebglBase) {
6750
+ _inherits(WebglPath, _WebglBase);
6751
+
6752
+ var _super = _createSuper(WebglPath);
6753
+
6754
+ function WebglPath(graph, option) {
6755
+ var _this;
6756
+
6757
+ _classCallCheck(this, WebglPath);
6758
+
6759
+ _this = _super.call(this, graph, option); // 是否是规则的,不规则的处理方式更为复杂和耗性能
6760
+
6761
+ _this.isRegular = option.isRegular || false;
6762
+ _this.needCut = option.needCut || false;
6763
+ _this.control = option.control;
6764
+ _this.points = [];
6765
+ return _this;
6766
+ }
6767
+
6768
+ _createClass(WebglPath, [{
6769
+ key: "setParentBounds",
6770
+ value: function setParentBounds() {
6771
+ var parentBounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.parentAbsoluteBounds;
6772
+ //this.useProgram();
6773
+ if (parentBounds) this.parentAbsoluteBounds = parentBounds; // 写入当前canvas大小
6774
+
6775
+ this.context.uniform2f(this.program.uniforms.a_center_point.location, this.graph.width / 2, this.graph.height / 2);
6776
+ }
6777
+ }, {
6778
+ key: "setFragColor",
6779
+ value: function setFragColor(color) {
6780
+ if (!Array.isArray(color)) {
6781
+ color = this.convertColor(color);
6782
+ if (typeof color.a === 'undefined') color.a = 1;
6783
+ this.context.uniform4f(this.program.uniforms.v_single_color.location, color.r, color.g, color.b, color.a * this.style.globalAlpha);
6784
+ return null;
6785
+ }
6786
+
6787
+ var colorData = [];
6788
+
6789
+ var _iterator = _createForOfIteratorHelper(color),
6790
+ _step;
6791
+
6792
+ try {
6793
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
6794
+ var c = _step.value;
6795
+ c = this.convertColor(c);
6796
+ if (typeof c.a === 'undefined') c.a = 1;
6797
+ colorData.push(c.r, c.g, c.b, c.a * this.style.globalAlpha);
6798
+ }
6799
+ } catch (err) {
6800
+ _iterator.e(err);
6801
+ } finally {
6802
+ _iterator.f();
6803
+ }
6804
+
6805
+ var colorBuffer = this.createFloat32Buffer(colorData);
6806
+ this.writeVertexAttrib(colorBuffer, this.program.attrs.a_color, 4, 0, 0);
6807
+ colorBuffer.attr = this.program.attrs.a_color;
6808
+ return colorBuffer;
6809
+ }
6810
+ }, {
6811
+ key: "beginDraw",
6812
+ value: function beginDraw() {
6813
+ this.useProgram();
6814
+ } // 开始绘制
6815
+
6816
+ }, {
6817
+ key: "draw",
6818
+ value: function draw(points) {
6819
+ var parentBounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.parentAbsoluteBounds;
6820
+ //this.useProgram();
6821
+ this.setParentBounds(parentBounds);
6822
+ this.points = points;
6823
+ }
6824
+ }, {
6825
+ key: "endDraw",
6826
+ value: function endDraw() {
6827
+ if (this.points) delete this.points;
6828
+ if (this.pathPoints) delete this.pathPoints;
6829
+ } // 图形封闭
6830
+
6831
+ }, {
6832
+ key: "closePath",
6833
+ value: function closePath() {
6834
+ if (this.points && this.points.length > 2 && this.points[0] !== this.points[this.points.length - 1]) {
6835
+ var start = this.points[0];
6836
+ var end = this.points[this.points.length - 1];
6837
+ if (start != end && !(start.x === end.x && start.y === end.y)) this.points.push(start);
6838
+ }
6839
+ } // 绘制点数组
6840
+
6841
+ }, {
6842
+ key: "writePoints",
6843
+ value: function writePoints(points) {
6844
+ var attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.program.attrs.a_position;
6845
+ var fixedPoints = [];
6846
+
6847
+ var _iterator2 = _createForOfIteratorHelper(points),
6848
+ _step2;
6849
+
6850
+ try {
6851
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6852
+ var p = _step2.value;
6853
+ fixedPoints.push(p.x + this.parentAbsoluteBounds.left, p.y + this.parentAbsoluteBounds.top);
6854
+ }
6855
+ } catch (err) {
6856
+ _iterator2.e(err);
6857
+ } finally {
6858
+ _iterator2.f();
6859
+ }
6860
+
6861
+ var vertexBuffer = this.createFloat32Buffer(fixedPoints);
6862
+ this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
6863
+ vertexBuffer.attr = attr;
6864
+ return vertexBuffer;
6865
+ } // 连接二个点
6866
+
6867
+ }, {
6868
+ key: "genLinePoints",
6869
+ value: function genLinePoints(start, end) {
6870
+ var points = [start];
6871
+ var dx = end.x - start.x;
6872
+ var dy = end.y - start.y;
6873
+
6874
+ if (dx !== 0 || dy !== 0) {
6875
+ var len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
6876
+ var cos = dx / len;
6877
+ var sin = dy / len;
6878
+ var step = 0.5;
6879
+
6880
+ for (var l = step; l < len; l += step) {
6881
+ var x = start.x + cos * l;
6882
+ var y = start.y + sin * l;
6883
+ points.push({
6884
+ x: x,
6885
+ y: y
6886
+ });
6887
+ }
6888
+ }
6889
+
6890
+ points.push(end);
6891
+ return points;
6892
+ } // 把path坐标集合分解成一个个点,并且处理moveTo线段能力
6893
+
6894
+ }, {
6895
+ key: "pathToPoints",
6896
+ value: function pathToPoints() {
6897
+ var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.points;
6898
+ var start = null;
6899
+ var res = [];
6900
+
6901
+ for (var i = 0; i < points.length; i++) {
6902
+ var p = points[i];
6903
+
6904
+ if (start && !p.m) {
6905
+ var linePoints = this.genLinePoints(start, p);
6906
+ res.push.apply(res, _toConsumableArray(linePoints));
6907
+ } else if (start && !res.includes(start)) {
6908
+ res.push(start);
6909
+ }
6910
+
6911
+ start = p;
6912
+ }
6913
+
6914
+ if (!res.includes(start)) res.push(start);
6915
+ return res;
6916
+ } // 二点是否重合
6917
+
6918
+ }, {
6919
+ key: "equalPoint",
6920
+ value: function equalPoint(p1, p2) {
6921
+ return p1.x === p2.x && p1.y === p2.y;
6922
+ } // 把path坐标集合转为线段集
6923
+
6924
+ }, {
6925
+ key: "pathToLines",
6926
+ value: function pathToLines(points) {
6927
+ var start = null;
6928
+ var res = [];
6929
+
6930
+ for (var i = 0; i < points.length; i++) {
6931
+ var p = points[i]; // 不重合的二个点,组成线段
6932
+
6933
+ if (start && !p.m && !(start.x == p.x && start.y == p.y)) {
6934
+ var line = {
6935
+ start: start,
6936
+ end: p
6937
+ };
6938
+ res.push(line);
6939
+ }
6940
+
6941
+ start = p;
6942
+ }
6943
+
6944
+ return res;
6945
+ } // 裁剪线段,如果二段线段有交点,则分割成四段, 端头相交的线段不用分割
6946
+
6947
+ }, {
6948
+ key: "cutLines",
6949
+ value: function cutLines(lines) {
6950
+ var index1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
6951
+ var index2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
6952
+ if (lines && lines.length < 3) return lines;
6953
+ index2 = Math.max(index1 + 1, index2); //如果指定了比下一个更大的索引,则用更大的,说明前面的已经处理过了,不需要重复
6954
+ // 找出线段相交的点,并切割线段
6955
+
6956
+ while (index1 < lines.length) {
6957
+ var line1 = lines[index1];
6958
+
6959
+ while (index2 < lines.length) {
6960
+ var line2 = lines[index2]; // 如果二条线顶点有重合,则不用处理
6961
+
6962
+ if (this.equalPoint(line1.start, line2.start) || this.equalPoint(line1.end, line2.end) || this.equalPoint(line1.start, line2.end) || this.equalPoint(line1.end, line2.start)) {
6963
+ index2++;
6964
+ continue;
6965
+ }
6966
+
6967
+ var cuted = false;
6968
+ var intersection = this.getIntersection(line1, line2); // 计算交点
6969
+
6970
+ if (intersection) {
6971
+ // 如果交点不是线段的端点,则分割成二条线段
6972
+ if (!this.equalPoint(line1.start, intersection) && !this.equalPoint(line1.end, intersection)) {
6973
+ var sub1 = {
6974
+ start: line1.start,
6975
+ end: intersection
6976
+ };
6977
+ var sub2 = {
6978
+ start: intersection,
6979
+ end: line1.end
6980
+ }; // 从原数组中删除当前线段,替换成新的线段
6981
+
6982
+ lines.splice(index1, 1, sub1, sub2); // 当前线段被重新替换,需要重新从它开始处理
6983
+
6984
+ cuted = true;
6985
+ index2++; // 因为多加入了一个线段,则对比线索引需要加1
6986
+ } // 如果交点不是线段的端点,则分割成二条线段
6987
+
6988
+
6989
+ if (!this.equalPoint(line2.start, intersection) && !this.equalPoint(line2.end, intersection)) {
6990
+ var _sub = {
6991
+ start: line2.start,
6992
+ end: intersection
6993
+ };
6994
+ var _sub2 = {
6995
+ start: intersection,
6996
+ end: line2.end
6997
+ }; // 从原数组中删除当前线段,替换成新的线段
6998
+
6999
+ lines.splice(index2, 1, _sub, _sub2);
7000
+ index2++; // 线段2也切成了二段,对比索引要继续加1
7001
+ }
7002
+ }
7003
+
7004
+ index2++; // 如果已经分割了起始线段,则第一个子线段开始,重新对比后面还未对比完的。直接所有对比完成返回
7005
+
7006
+ if (cuted) return this.cutLines(lines, index1, index2);
7007
+ }
7008
+
7009
+ index1++;
7010
+ index2 = index1 + 1;
7011
+ }
7012
+
7013
+ return lines;
7014
+ } // 计算二个线段的交点
7015
+
7016
+ }, {
7017
+ key: "getIntersection",
7018
+ value: function getIntersection(line1, line2) {
7019
+ // 如果首尾相接,也认为是有交点
7020
+ if (this.equalPoint(line1.start, line2.start) || this.equalPoint(line1.start, line2.end)) return line1.start;
7021
+ if (this.equalPoint(line1.end, line2.start) || this.equalPoint(line1.end, line2.end)) return line1.end; // 三角形abc 面积的2倍
7022
+
7023
+ var area_abc = (line1.start.x - line2.start.x) * (line1.end.y - line2.start.y) - (line1.start.y - line2.start.y) * (line1.end.x - line2.start.x); // 三角形abd 面积的2倍
7024
+
7025
+ var area_abd = (line1.start.x - line2.end.x) * (line1.end.y - line2.end.y) - (line1.start.y - line2.end.y) * (line1.end.x - line2.end.x); // 面积符号相同则两点在线段同侧,不相交 (=0表示在线段顶点上);
7026
+
7027
+ if (area_abc * area_abd > 0) {
7028
+ return null;
7029
+ } // 三角形cda 面积的2倍
7030
+
7031
+
7032
+ var area_cda = (line2.start.x - line1.start.x) * (line2.end.y - line1.start.y) - (line2.start.y - line1.start.y) * (line2.end.x - line1.start.x); // 三角形cdb 面积的2倍
7033
+ // 注意: 这里有一个小优化.不需要再用公式计算面积,而是通过已知的三个面积加减得出.
7034
+
7035
+ var area_cdb = area_cda + area_abc - area_abd;
7036
+
7037
+ if (area_cda * area_cdb > 0) {
7038
+ return null;
7039
+ }
7040
+
7041
+ if (area_abd === area_abc) return null; //计算交点坐标
7042
+
7043
+ var t = area_cda / (area_abd - area_abc);
7044
+ var dx = t * (line1.end.x - line1.start.x);
7045
+ var dy = t * (line1.end.y - line1.start.y);
7046
+ return {
7047
+ x: line1.start.x + dx,
7048
+ y: line1.start.y + dy
7049
+ };
7050
+ } // 找出跟当前线段尾部相交的所有线段
7051
+
7052
+ }, {
7053
+ key: "getIntersectionLines",
7054
+ value: function getIntersectionLines(line, lines, index) {
7055
+ var point = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : line.end;
7056
+ var points = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
7057
+ var root = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
7058
+ var res = {
7059
+ line: line,
7060
+ polygons: []
7061
+ };
7062
+ points.push(point);
7063
+
7064
+ if (root && this.equalPoint(root.line.start, point)) {
7065
+ points.unshift(root.line.start); // 把起始地址加入进去
7066
+
7067
+ root.polygons.push(points);
7068
+ return res;
7069
+ }
7070
+
7071
+ for (; index < lines.length; index++) {
7072
+ var l = lines[index];
7073
+
7074
+ if (this.equalPoint(point, l.start)) {
7075
+ if (points.includes(l.end)) continue;
7076
+ this.getIntersectionLines(l, lines, index + 1, l.end, _toConsumableArray(points), root || res);
7077
+ } else if (this.equalPoint(point, l.end)) {
7078
+ if (points.includes(l.start)) continue;
7079
+ this.getIntersectionLines(l, lines, index + 1, l.start, _toConsumableArray(points), root || res);
7080
+ }
7081
+ }
7082
+
7083
+ return res;
7084
+ } // 根据路径点坐标,切割出封闭的多边形
7085
+
7086
+ }, {
7087
+ key: "getPolygon",
7088
+ value: function getPolygon(points) {
7089
+ var polygons = [];
7090
+ var lines = this.pathToLines(points); // 分解得到线段
7091
+
7092
+ if (lines && lines.length > 2) {
7093
+ lines = this.cutLines(lines); // 把所有相交点切割线段找出来
7094
+
7095
+ for (var i = 0; i < lines.length - 1; i++) {
7096
+ var line1 = lines[i];
7097
+ var polygon = []; // 当前图形
7098
+
7099
+ var treeLine = this.getIntersectionLines(line1, lines, i + 1);
7100
+ if (treeLine.polygons.length) polygons.push.apply(polygons, _toConsumableArray(treeLine.polygons));
7101
+ continue;
7102
+ var lastLine = line1; // 下一个还在连接状态的线
7103
+
7104
+ for (var j = i + 1; j < lines.length; j++) {
7105
+ var line2 = lines[j]; // 如果跟下一条线相接,则表示还在形成图形中
7106
+
7107
+ if (this.equalPoint(lastLine.end, line2.start)) {
7108
+ polygon.push(lastLine.end);
7109
+ lastLine = line2;
7110
+ if (i === j + 1) continue; //下一条相连 则不需要处理相交情况
7111
+ } else {
7112
+ polygon = [];
7113
+ } // 因为前面进行了分割线段,则里只有处理端点相连的情况
7114
+
7115
+
7116
+ var intersection = this.equalPoint(line1.start, line2.end) ? line1.start : null; //this.getIntersection(line1, line2);// 计算交点
7117
+
7118
+ if (intersection) {
7119
+ polygon.push(intersection); // 交叉点为图形顶点
7120
+ // 如果上一个连接线不是当前交叉线,则表示重新开始闭合
7121
+ // 如果上一个连接线是当前交叉线,形成了封闭的图形
7122
+
7123
+ if (lastLine === line2 && polygon.length > 1) {
7124
+ polygons.push(polygon); // 封闭后,下一个起始线条就是从交点开始计算起
7125
+
7126
+ /*lastLine = {
7127
+ start: intersection,
7128
+ end: line2.end
7129
+ };*/
7130
+
7131
+ polygon = []; // 重新开始新一轮找图形
7132
+
7133
+ /*
7134
+ // 如果交点是上一条线的终点,则新图形为空
7135
+ if(this.equalPoint(line2.end, intersection)) {
7136
+ polygon = [];// 重新开始新一轮找图形
7137
+ }
7138
+ else {
7139
+ // 同时交点也要加到上一个图形中第一个点,形成封闭
7140
+ polygon.unshift(intersection);
7141
+ polygon = [ intersection ];// 重新开始新一轮找图形
7142
+ }*/
7143
+ } else {
7144
+ lastLine = line2;
7145
+ }
7146
+ }
7147
+ }
7148
+ }
7149
+ } // 当有多个封闭图形时,再弟归一下,里面是不是有封闭图形内还有子封闭图形
7150
+
7151
+ /*if(polygons.length > 1) {
7152
+ const newPolygons = [];
7153
+ for(const polygon of polygons) {
7154
+ // 只有大于4才有可能有子封闭图形
7155
+ if(polygon.length > 4) {
7156
+ const childPolygons = this.getPolygon(polygon);
7157
+ // 当有多个子图形时,表示它不是最终封闭图形,跳过,
7158
+ // 因为它的子图形之前有加入的,不需要重复加入
7159
+ if(childPolygons.length > 1) {
7160
+ //newPolygons.push(...childPolygons);
7161
+ continue;
7162
+ }
7163
+ }
7164
+ newPolygons.push(polygon);
7165
+ }
7166
+ polygons = newPolygons;
7167
+ }*/
7168
+
7169
+
7170
+ return polygons;
7171
+ } // 分割成一个个规则的三角形,不规则的多边形不全割的话纹理就会没法正确覆盖
7172
+
7173
+ }, {
7174
+ key: "getTriangles",
7175
+ value: function getTriangles(points) {
7176
+ //this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
7177
+ //const key = JSON.stringify(points);
7178
+ //if(this.trianglesCache[key]) return this.trianglesCache[key];
7179
+ var res = [];
7180
+ var polygons = this.getPolygon(points);
7181
+
7182
+ if (polygons.length) {
7183
+ var _iterator3 = _createForOfIteratorHelper(polygons),
7184
+ _step3;
7185
+
7186
+ try {
7187
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
7188
+ var polygon = _step3.value;
7189
+ // 需要分割三角形,不然填充会有问题
7190
+ var triangles = this.earCutPointsToTriangles(polygon);
7191
+ res.push.apply(res, _toConsumableArray(triangles));
7192
+ }
7193
+ } catch (err) {
7194
+ _iterator3.e(err);
7195
+ } finally {
7196
+ _iterator3.f();
7197
+ }
7198
+ } //this.trianglesCache[key] = res;
7199
+
7200
+
7201
+ return res;
7202
+ } // 画线条
7203
+
7204
+ }, {
7205
+ key: "stroke",
7206
+ value: function stroke() {
7207
+ var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.points;
7208
+ var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.style.strokeStyle;
7209
+ var lineWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.style.lineWidth;
7210
+ if (!points || !points.length) return; // this.useProgram();
7211
+
7212
+ var colorBuffer = null;
7213
+
7214
+ if (color) {
7215
+ colorBuffer = this.setFragColor(color);
7216
+ } // 线宽
7217
+
7218
+
7219
+ if (lineWidth) {
7220
+ this.context.uniform1f(this.program.uniforms.a_point_size.location, lineWidth); // * this.graph.devicePixelRatio
7221
+ } // 标注为stroke
7222
+
7223
+
7224
+ if (this.program.uniforms.a_type) {
7225
+ // 4表示单画一个圆点,1表示方块形成的线条
7226
+ this.context.uniform1i(this.program.uniforms.a_type.location, points.length === 1 ? 4 : 1);
7227
+ }
7228
+
7229
+ if (points && points.length) {
7230
+ var regular = lineWidth <= 1.2;
7231
+ points = regular ? points : this.pathToPoints(points);
7232
+ var buffer = this.writePoints(points);
7233
+ this.context.drawArrays(regular ? this.context.LINE_LOOP : this.context.POINTS, 0, points.length);
7234
+ this.deleteBuffer(buffer);
7235
+ }
7236
+
7237
+ colorBuffer && this.deleteBuffer(colorBuffer);
7238
+ colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
7239
+ } // 填充图形
7240
+
7241
+ }, {
7242
+ key: "fill",
7243
+ value: function fill() {
7244
+ var bounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
7245
+ left: 0,
7246
+ top: 0,
7247
+ width: 0,
7248
+ height: 0
7249
+ };
7250
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7251
+
7252
+ if (this.points && this.points.length) {
7253
+ // 如果是颜色rgba
7254
+ if (this.style.fillStyle) {
7255
+ this.fillColor(this.style.fillStyle, this.points, bounds, type);
7256
+ }
7257
+
7258
+ if (this.style.fillImage) {
7259
+ this.fillImage(this.style.fillImage, this.points, bounds, type);
7260
+ }
7261
+ }
7262
+ }
7263
+ }, {
7264
+ key: "fillColor",
7265
+ value: function fillColor(color, points, bounds) {
7266
+ var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
7267
+
7268
+ // 如果是渐变色,则需要计算偏移量的颜色
7269
+ if (this.isGradient(color)) {
7270
+ var imgData = color.toImageData(this, bounds, points);
7271
+ return this.fillImage(imgData.data, imgData.points, bounds);
7272
+ } // 标注为fill
7273
+
7274
+
7275
+ this.context.uniform1i(this.program.uniforms.a_type.location, type);
7276
+ var colorBuffer = this.setFragColor(color);
7277
+ this.fillPolygons(points);
7278
+ colorBuffer && this.deleteBuffer(colorBuffer);
7279
+ colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
7280
+ } // 区域填充图片
7281
+ // points绘制的图形顶点
7282
+ // 图片整体绘制区域
7283
+
7284
+ }, {
7285
+ key: "fillImage",
7286
+ value: function fillImage(img, points, bounds) {
7287
+ if (!img) return; // 设置纹理
7288
+
7289
+ var texture = img instanceof ImageData ? this.createDataTexture(img) : this.createImgTexture(img);
7290
+ this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
7291
+ // 指定纹理区域尺寸
7292
+
7293
+ this.context.uniform4f(this.program.uniforms.v_texture_bounds.location, bounds.left + this.parentAbsoluteBounds.left, bounds.top + this.parentAbsoluteBounds.top, bounds.width, bounds.height); // 纹理单元传递给着色器
7294
+
7295
+ this.fillTexture(points);
7296
+ this.deleteTexture(texture);
7297
+ }
7298
+ }, {
7299
+ key: "fillTexture",
7300
+ value: function fillTexture(points) {
7301
+ if (points && points.length) {
7302
+ // 标注为纹理对象
7303
+ this.context.uniform1i(this.program.uniforms.a_type.location, 2); // 纹理坐标
7304
+ //const coordBuffer = this.writePoints(points, this.program.attrs.a_text_coord);
7305
+
7306
+ this.fillPolygons(points, true); //this.deleteBuffer(coordBuffer);
7307
+
7308
+ this.disableVertexAttribArray(this.program.attrs.a_text_coord);
7309
+ }
7310
+ } // 进行多边形填充
7311
+
7312
+ }, {
7313
+ key: "fillPolygons",
7314
+ value: function fillPolygons(points) {
7315
+ var isTexture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7316
+ //const indexBuffer = this.createUint16Buffer(triangles, this.context.ELEMENT_ARRAY_BUFFER);
7317
+ //this.context.drawElements(this.context.TRIANGLES, triangles.length, this.context.UNSIGMED_SHORT, 0);
7318
+ //this.deleteBuffer(indexBuffer);
7319
+
7320
+ /*if(points.length > 3 && (!regular || this.needCut)) {
7321
+ const triangles = regular && this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
7322
+ if(triangles.length) {
7323
+ for(const triangle of triangles) {
7324
+ this.fillPolygons(triangle, isTexture);// 这里就变成了规则的图形了
7325
+ }
7326
+ }
7327
+ }
7328
+ else {*/
7329
+ var buffer = this.writePoints(points); // 纹理坐标
7330
+
7331
+ var coordBuffer = isTexture ? this.writePoints(points, this.program.attrs.a_text_coord) : null;
7332
+ this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
7333
+ this.deleteBuffer(buffer);
7334
+ coordBuffer && this.deleteBuffer(coordBuffer); //}
7335
+ } // 填充图形
7336
+
7337
+ }, {
7338
+ key: "drawImage",
7339
+ value: function drawImage(img) {
7340
+ var left = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
7341
+ var top = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
7342
+ var width = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : img.width;
7343
+ var height = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : img.height;
7344
+ width = width || img.width;
7345
+ height = height || img.height;
7346
+ this.fillImage(img, this.points, {
7347
+ left: left,
7348
+ top: top,
7349
+ width: width,
7350
+ height: height
7351
+ });
7352
+ }
7353
+ }, {
7354
+ key: "drawText",
7355
+ value: function drawText(text, x, y, bounds) {
7356
+ var canvas = this.textureCanvas;
7357
+
7358
+ if (!canvas) {
7359
+ return null;
7360
+ }
7361
+
7362
+ canvas.width = bounds.width;
7363
+ canvas.height = bounds.height;
7364
+
7365
+ if (!canvas.width || !canvas.height) {
7366
+ return null;
7367
+ }
7368
+
7369
+ this.textureContext.clearRect(0, 0, canvas.width, canvas.height); // 修改字体
7370
+
7371
+ this.textureContext.font = this.style.font || this.style.fontSize + 'px ' + this.style.fontFamily;
7372
+ x -= bounds.left;
7373
+ y -= bounds.top;
7374
+ this.setTextureStyle(this.style);
7375
+
7376
+ if (this.style.fillStyle && this.textureContext.fillText) {
7377
+ if (this.style.maxWidth) {
7378
+ this.textureContext.fillText(text, x, y, this.style.maxWidth);
7379
+ } else {
7380
+ this.textureContext.fillText(text, x, y);
7381
+ }
7382
+ }
7383
+
7384
+ if (this.textureContext.strokeText) {
7385
+ if (this.style.maxWidth) {
7386
+ this.textureContext.strokeText(text, x, y, this.style.maxWidth);
7387
+ } else {
7388
+ this.textureContext.strokeText(text, x, y);
7389
+ }
7390
+ } // 用纹理图片代替文字
7391
+
7392
+
7393
+ var data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
7394
+ this.fillImage(data, this.points, bounds);
7395
+ }
7396
+ }]);
7397
+
7398
+ return WebglPath;
7399
+ }(_base["default"]);
7400
+
7401
+ var _default = WebglPath;
7402
+ exports["default"] = _default;
7403
+
7404
+ },{"./base.js":13}],22:[function(require,module,exports){
7405
+ "use strict";
7406
+
7407
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
7408
+
7409
+ Object.defineProperty(exports, "__esModule", {
7410
+ value: true
7411
+ });
7412
+ exports.jmArc = exports["default"] = void 0;
7413
+
7414
+ var _jmPath2 = require("../core/jmPath.js");
7415
+
7416
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7417
+
7418
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
7419
+
7420
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
7421
+
7422
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
7423
+
7424
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7425
+
7426
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7427
+
7428
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
7429
+
7430
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
7431
+
7432
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
7433
+
7434
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
7435
+
7436
+ /**
7437
+ * 圆弧图型 继承自jmPath
7438
+ *
7439
+ * @class jmArc
7440
+ * @extends jmPath
7441
+ * @param {object} params center=当前圆弧中心,radius=圆弧半径,start=圆弧起始角度,end=圆弧结束角度,anticlockwise= false 顺时针,true 逆时针
7442
+ */
7443
+ var jmArc = /*#__PURE__*/function (_jmPath) {
7444
+ _inherits(jmArc, _jmPath);
7445
+
7446
+ var _super = _createSuper(jmArc);
7447
+
7448
+ function jmArc(params) {
7449
+ var _this;
7450
+
7451
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'jmArc';
7452
+
7453
+ _classCallCheck(this, jmArc);
7454
+
7455
+ if (!params) params = {};
7456
+ params.isRegular = params.isRegular === false ? false : true; // 规则的
7457
+
7458
+ params.needCut = params.needCut === true ? true : false; // 规则的
7459
+
7460
+ _this = _super.call(this, params, t);
7461
+ _this.center = params.center || {
7462
+ x: 0,
7463
+ y: 0
7464
+ };
7465
+ _this.radius = params.radius || 0;
7466
+ _this.startAngle = params.start || params.startAngle || 0;
7467
+ _this.endAngle = params.end || params.endAngle || Math.PI * 2;
7468
+ _this.anticlockwise = params.anticlockwise || 0;
7469
+ _this.isFan = !!params.isFan;
7470
+ return _this;
7471
+ }
7472
+ /**
7473
+ * 中心点
7474
+ * point格式:{x:0,y:0,m:true}
7475
+ * @property center
7476
+ * @type {point}
7477
+ */
7478
+
7479
+
7480
+ _createClass(jmArc, [{
7481
+ key: "center",
7482
+ get: function get() {
7483
+ return this.property('center');
7484
+ },
7485
+ set: function set(v) {
7486
+ this.needUpdate = true;
7487
+ return this.property('center', v);
7488
+ }
7489
+ /**
7490
+ * 半径
7491
+ * @property radius
7492
+ * @type {number}
7493
+ */
7494
+
7495
+ }, {
7496
+ key: "radius",
7497
+ get: function get() {
7498
+ return this.property('radius');
7499
+ },
7500
+ set: function set(v) {
7501
+ this.needUpdate = true;
7502
+ return this.property('radius', v);
7503
+ }
7504
+ /**
7505
+ * 扇形起始角度
7506
+ * @property startAngle
7507
+ * @type {number}
7508
+ */
7509
+
7510
+ }, {
7511
+ key: "startAngle",
7512
+ get: function get() {
7513
+ return this.property('startAngle');
7514
+ },
7515
+ set: function set(v) {
7516
+ this.needUpdate = true;
7517
+ return this.property('startAngle', v);
7518
+ }
7519
+ /**
7520
+ * 扇形结束角度
7521
+ * @property endAngle
7522
+ * @type {number}
7523
+ */
7524
+
7525
+ }, {
7526
+ key: "endAngle",
7527
+ get: function get() {
7528
+ return this.property('endAngle');
7529
+ },
7530
+ set: function set(v) {
7531
+ this.needUpdate = true;
7532
+ return this.property('endAngle', v);
7533
+ }
7534
+ /**
7535
+ * 可选。规定应该逆时针还是顺时针绘图
7536
+ * false 顺时针,true 逆时针
7537
+ * @property anticlockwise
7538
+ * @type {boolean}
7539
+ */
7540
+
7541
+ }, {
5103
7542
  key: "anticlockwise",
5104
7543
  get: function get() {
5105
7544
  return this.property('anticlockwise');
@@ -5169,7 +7608,7 @@ var jmArc = /*#__PURE__*/function (_jmPath) {
5169
7608
 
5170
7609
  exports.jmArc = exports["default"] = jmArc;
5171
7610
 
5172
- },{"../core/jmPath.js":8}],13:[function(require,module,exports){
7611
+ },{"../core/jmPath.js":8}],23:[function(require,module,exports){
5173
7612
  "use strict";
5174
7613
 
5175
7614
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5393,7 +7832,7 @@ var jmArrow = /*#__PURE__*/function (_jmPath) {
5393
7832
 
5394
7833
  exports.jmArrow = exports["default"] = jmArrow;
5395
7834
 
5396
- },{"../core/jmPath.js":8,"../core/jmUtils.js":11}],14:[function(require,module,exports){
7835
+ },{"../core/jmPath.js":8,"../core/jmUtils.js":11}],24:[function(require,module,exports){
5397
7836
  "use strict";
5398
7837
 
5399
7838
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5487,7 +7926,7 @@ var jmArrowLine = /*#__PURE__*/function (_jmLine) {
5487
7926
 
5488
7927
  exports.jmArrowLine = exports["default"] = jmArrowLine;
5489
7928
 
5490
- },{"./jmArrow.js":13,"./jmLine.js":20}],15:[function(require,module,exports){
7929
+ },{"./jmArrow.js":23,"./jmLine.js":30}],25:[function(require,module,exports){
5491
7930
  "use strict";
5492
7931
 
5493
7932
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5659,7 +8098,7 @@ var jmBezier = /*#__PURE__*/function (_jmPath) {
5659
8098
 
5660
8099
  exports.jmBezier = exports["default"] = jmBezier;
5661
8100
 
5662
- },{"../core/jmPath.js":8}],16:[function(require,module,exports){
8101
+ },{"../core/jmPath.js":8}],26:[function(require,module,exports){
5663
8102
  "use strict";
5664
8103
 
5665
8104
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5789,7 +8228,7 @@ var jmCircle = /*#__PURE__*/function (_jmArc) {
5789
8228
 
5790
8229
  exports.jmCircle = exports["default"] = jmCircle;
5791
8230
 
5792
- },{"./jmArc.js":12}],17:[function(require,module,exports){
8231
+ },{"./jmArc.js":22}],27:[function(require,module,exports){
5793
8232
  "use strict";
5794
8233
 
5795
8234
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5949,7 +8388,7 @@ var jmHArc = /*#__PURE__*/function (_jmArc) {
5949
8388
 
5950
8389
  exports.jmHArc = exports["default"] = jmHArc;
5951
8390
 
5952
- },{"./jmArc.js":12}],18:[function(require,module,exports){
8391
+ },{"./jmArc.js":22}],28:[function(require,module,exports){
5953
8392
  "use strict";
5954
8393
 
5955
8394
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -5967,6 +8406,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
5967
8406
 
5968
8407
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
5969
8408
 
8409
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
8410
+
8411
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
8412
+
5970
8413
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
5971
8414
 
5972
8415
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
@@ -6162,7 +8605,9 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
6162
8605
 
6163
8606
  }, {
6164
8607
  key: "getBounds",
6165
- value: function getBounds() {
8608
+ value: function getBounds(isReset) {
8609
+ //如果当次计算过,则不重复计算
8610
+ if (this.bounds && !isReset) return this.bounds;
6166
8611
  var rect = {};
6167
8612
  var img = this.getImage();
6168
8613
  var p = this.getLocation();
@@ -6174,7 +8619,23 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
6174
8619
  rect.bottom = p.top + h;
6175
8620
  rect.width = w;
6176
8621
  rect.height = h;
6177
- return rect;
8622
+ return this.bounds = rect;
8623
+ }
8624
+ }, {
8625
+ key: "getLocation",
8626
+ value: function getLocation() {
8627
+ var img = this.getImage();
8628
+
8629
+ var loc = _get(_getPrototypeOf(jmImage.prototype), "getLocation", this).call(this); // 如果指定了宽度,但没有指定高宽,则等比缩放
8630
+
8631
+
8632
+ if (loc.width && !loc.height) {
8633
+ loc.height = loc.width / img.width * img.height;
8634
+ } else if (loc.height && !loc.width) {
8635
+ loc.width = loc.height / img.height * img.width;
8636
+ }
8637
+
8638
+ return loc;
6178
8639
  }
6179
8640
  /**
6180
8641
  * img对象
@@ -6226,7 +8687,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
6226
8687
 
6227
8688
  exports.jmImage = exports["default"] = jmImage;
6228
8689
 
6229
- },{"../core/jmControl.js":2}],19:[function(require,module,exports){
8690
+ },{"../core/jmControl.js":2}],29:[function(require,module,exports){
6230
8691
  "use strict";
6231
8692
 
6232
8693
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -6238,6 +8699,12 @@ exports.jmLabel = exports["default"] = void 0;
6238
8699
 
6239
8700
  var _jmControl2 = require("../core/jmControl.js");
6240
8701
 
8702
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
8703
+
8704
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8705
+
8706
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8707
+
6241
8708
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6242
8709
 
6243
8710
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -6407,17 +8874,19 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
6407
8874
  key: "testSize",
6408
8875
  value: function testSize() {
6409
8876
  if (this.__size) return this.__size;
6410
- this.context.save && this.context.save(); // 修改字体,用来计算
8877
+ if (this.webglControl) this.__size = this.webglControl.testSize(this.text, this.style);else {
8878
+ this.context.save && this.context.save(); // 修改字体,用来计算
6411
8879
 
6412
- this.setStyle({
6413
- font: this.style.font || "".concat(this.style.fontSize, "px \"").concat(this.style.fontFamily, "\"")
6414
- }); //计算宽度
8880
+ this.setStyle({
8881
+ font: this.style.font || this.style.fontSize + 'px ' + this.style.fontFamily
8882
+ }); //计算宽度
6415
8883
 
6416
- this.__size = this.context.measureText ? this.context.measureText(this.text) : {
6417
- width: 15
6418
- };
6419
- this.context.restore && this.context.restore();
6420
- if (!this.__size.height) this.__size.height = this.style.fontSize ? this.style.fontSize : 15;
8884
+ this.__size = this.context.measureText ? this.context.measureText(this.text) : {
8885
+ width: 15
8886
+ };
8887
+ this.context.restore && this.context.restore();
8888
+ this.__size.height = this.style.fontSize ? this.style.fontSize : 15;
8889
+ }
6421
8890
  if (!this.width) this.width = this.__size.width;
6422
8891
  if (!this.height) this.height = this.__size.height;
6423
8892
  return this.__size;
@@ -6472,7 +8941,11 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
6472
8941
  var txt = this.text;
6473
8942
 
6474
8943
  if (typeof txt !== 'undefined') {
6475
- if (this.style.fill && this.context.fillText) {
8944
+ // webgl方式
8945
+ if (this.webglControl) {
8946
+ this.webglControl.draw(this.points, bounds);
8947
+ this.webglControl.drawText(txt, x, y, location);
8948
+ } else if (this.style.fill && this.context.fillText) {
6476
8949
  if (this.style.maxWidth) {
6477
8950
  this.context.fillText(txt, x, y, this.style.maxWidth);
6478
8951
  } else {
@@ -6495,33 +8968,67 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
6495
8968
  this.setStyle(this.style.border.style);
6496
8969
  }
6497
8970
 
6498
- this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
8971
+ if (this.mode === '2d') {
8972
+ this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
6499
8973
 
6500
- if (this.style.border.top) {
6501
- this.context.lineTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
6502
- }
8974
+ if (this.style.border.top) {
8975
+ this.context.lineTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
8976
+ }
6503
8977
 
6504
- if (this.style.border.right) {
6505
- this.context.moveTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
6506
- this.context.lineTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
6507
- }
8978
+ if (this.style.border.right) {
8979
+ this.context.moveTo(this.points[1].x + bounds.left, this.points[1].y + bounds.top);
8980
+ this.context.lineTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
8981
+ }
6508
8982
 
6509
- if (this.style.border.bottom) {
6510
- this.context.moveTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
6511
- this.context.lineTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
6512
- }
8983
+ if (this.style.border.bottom) {
8984
+ this.context.moveTo(this.points[2].x + bounds.left, this.points[2].y + bounds.top);
8985
+ this.context.lineTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
8986
+ }
6513
8987
 
6514
- if (this.style.border.left) {
6515
- this.context.moveTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
6516
- this.context.lineTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
6517
- } //如果指定了边框颜色
8988
+ if (this.style.border.left) {
8989
+ this.context.moveTo(this.points[3].x + bounds.left, this.points[3].y + bounds.top);
8990
+ this.context.lineTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
8991
+ }
8992
+ } else {
8993
+ var points = [];
6518
8994
 
8995
+ if (this.style.border.top) {
8996
+ points.push(this.points[0]);
8997
+ points.push(this.points[1]);
8998
+ }
6519
8999
 
6520
- if (this.style.border.style) {
6521
- this.context.restore && this.context.restore();
9000
+ if (this.style.border.right) {
9001
+ points.push(_objectSpread(_objectSpread({}, this.points[1]), {}, {
9002
+ m: true
9003
+ }));
9004
+ points.push(this.points[2]);
9005
+ }
9006
+
9007
+ if (this.style.border.bottom) {
9008
+ points.push(_objectSpread(_objectSpread({}, this.points[2]), {}, {
9009
+ m: true
9010
+ }));
9011
+ points.push(this.points[3]);
9012
+ }
9013
+
9014
+ if (this.style.border.left) {
9015
+ points.push(_objectSpread(_objectSpread({}, this.points[3]), {}, {
9016
+ m: true
9017
+ }));
9018
+ points.push(this.points[0]);
9019
+ }
9020
+
9021
+ points.length && this.webglControl && this.webglControl.stroke(points);
6522
9022
  }
6523
9023
  }
6524
9024
  }
9025
+ }, {
9026
+ key: "endDraw",
9027
+ value: function endDraw() {
9028
+ if (this.mode === '2d') {
9029
+ _get(_getPrototypeOf(jmLabel.prototype), "endDraw", this).call(this);
9030
+ }
9031
+ }
6525
9032
  }]);
6526
9033
 
6527
9034
  return jmLabel;
@@ -6529,7 +9036,7 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
6529
9036
 
6530
9037
  exports.jmLabel = exports["default"] = jmLabel;
6531
9038
 
6532
- },{"../core/jmControl.js":2}],20:[function(require,module,exports){
9039
+ },{"../core/jmControl.js":2}],30:[function(require,module,exports){
6533
9040
  "use strict";
6534
9041
 
6535
9042
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -6684,7 +9191,7 @@ var jmLine = /*#__PURE__*/function (_jmPath) {
6684
9191
 
6685
9192
  exports.jmLine = exports["default"] = jmLine;
6686
9193
 
6687
- },{"../core/jmPath.js":8}],21:[function(require,module,exports){
9194
+ },{"../core/jmPath.js":8}],31:[function(require,module,exports){
6688
9195
  "use strict";
6689
9196
 
6690
9197
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -6804,7 +9311,7 @@ var jmPrismatic = /*#__PURE__*/function (_jmPath) {
6804
9311
 
6805
9312
  exports.jmPrismatic = exports["default"] = jmPrismatic;
6806
9313
 
6807
- },{"../core/jmPath.js":8}],22:[function(require,module,exports){
9314
+ },{"../core/jmPath.js":8}],32:[function(require,module,exports){
6808
9315
  "use strict";
6809
9316
 
6810
9317
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -6907,7 +9414,9 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
6907
9414
 
6908
9415
  }, {
6909
9416
  key: "getBounds",
6910
- value: function getBounds() {
9417
+ value: function getBounds(isReset) {
9418
+ //如果当次计算过,则不重复计算
9419
+ if (this.bounds && !isReset) return this.bounds;
6911
9420
  var rect = {};
6912
9421
  this.initPoints();
6913
9422
  var p = this.getLocation();
@@ -6917,7 +9426,7 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
6917
9426
  rect.bottom = p.top + p.height;
6918
9427
  rect.width = rect.right - rect.left;
6919
9428
  rect.height = rect.bottom - rect.top;
6920
- return rect;
9429
+ return this.bounds = rect;
6921
9430
  }
6922
9431
  /**
6923
9432
  * 重写检查坐标是否在区域内
@@ -7068,7 +9577,7 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
7068
9577
 
7069
9578
  exports.jmRect = exports["default"] = jmRect;
7070
9579
 
7071
- },{"../core/jmPath.js":8,"./jmArc.js":12,"./jmLine.js":20}],23:[function(require,module,exports){
9580
+ },{"../core/jmPath.js":8,"./jmArc.js":22,"./jmLine.js":30}],33:[function(require,module,exports){
7072
9581
  "use strict";
7073
9582
 
7074
9583
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@@ -7423,5 +9932,5 @@ var jmResize = /*#__PURE__*/function (_jmRect) {
7423
9932
 
7424
9933
  exports.jmResize = exports["default"] = jmResize;
7425
9934
 
7426
- },{"./jmRect.js":22}]},{},[1]);
9935
+ },{"./jmRect.js":32}]},{},[1]);
7427
9936
  var _r=_m(1);_g.jmGraph=_r;return _r;})})(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:(typeof self!=='undefined'?self:this)));