jmgraph 3.2.3 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +42 -2372
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +15 -15
- package/src/core/jmGraph.js +1 -1
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":
|
|
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){
|
|
237
237
|
"use strict";
|
|
238
238
|
|
|
239
239
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -251,22 +251,10 @@ 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
254
|
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; } } }; }
|
|
259
255
|
|
|
260
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
261
|
-
|
|
262
|
-
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."); }
|
|
263
|
-
|
|
264
256
|
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); }
|
|
265
257
|
|
|
266
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
267
|
-
|
|
268
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
269
|
-
|
|
270
258
|
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; }
|
|
271
259
|
|
|
272
260
|
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); }
|
|
@@ -291,6 +279,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
291
279
|
|
|
292
280
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
293
281
|
|
|
282
|
+
//import WebglPath from "../lib/webgl/path.js";
|
|
294
283
|
//样式名称,也当做白名单使用
|
|
295
284
|
var jmStyleMap = {
|
|
296
285
|
'fill': 'fillStyle',
|
|
@@ -353,13 +342,13 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
353
342
|
_this2.zIndex = params.zIndex || 0;
|
|
354
343
|
_this2.interactive = typeof params.interactive == 'undefined' ? true : params.interactive; // webgl模式
|
|
355
344
|
|
|
356
|
-
if
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
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
|
+
}*/
|
|
363
352
|
|
|
364
353
|
_this2.initializing();
|
|
365
354
|
|
|
@@ -1185,8 +1174,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1185
1174
|
value: function beginDraw() {
|
|
1186
1175
|
this.getLocation(true); //重置位置信息
|
|
1187
1176
|
|
|
1188
|
-
this.context.beginPath && this.context.beginPath();
|
|
1189
|
-
if (this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
|
|
1177
|
+
this.context.beginPath && this.context.beginPath(); //if(this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
|
|
1190
1178
|
}
|
|
1191
1179
|
/**
|
|
1192
1180
|
* 结束控件绘制
|
|
@@ -1199,21 +1187,24 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1199
1187
|
value: function endDraw() {
|
|
1200
1188
|
//如果当前为封闭路径
|
|
1201
1189
|
if (this.style.close) {
|
|
1202
|
-
if
|
|
1190
|
+
//if(this.webglControl) this.webglControl.closePath();
|
|
1191
|
+
this.context.closePath && this.context.closePath();
|
|
1203
1192
|
}
|
|
1204
1193
|
|
|
1205
1194
|
if (this.style['fill']) {
|
|
1206
|
-
if
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1195
|
+
/*if(this.webglControl) {
|
|
1196
|
+
const bounds = this.getBounds();
|
|
1197
|
+
this.webglControl.fill(bounds);
|
|
1198
|
+
}*/
|
|
1199
|
+
this.context.fill && this.context.fill();
|
|
1210
1200
|
}
|
|
1211
1201
|
|
|
1212
1202
|
if (this.style['stroke'] || !this.style['fill'] && !this.is('jmGraph')) {
|
|
1213
|
-
if
|
|
1214
|
-
|
|
1203
|
+
//if(this.webglControl) this.webglControl.stroke();
|
|
1204
|
+
this.context.stroke && this.context.stroke();
|
|
1205
|
+
} //if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
1206
|
+
|
|
1215
1207
|
|
|
1216
|
-
if (this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
1217
1208
|
this.needUpdate = false;
|
|
1218
1209
|
}
|
|
1219
1210
|
/**
|
|
@@ -1229,11 +1220,14 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1229
1220
|
if (this.points && this.points.length > 0) {
|
|
1230
1221
|
//获取当前控件的绝对位置
|
|
1231
1222
|
var bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
1223
|
+
/*if(this.webglControl) {
|
|
1224
|
+
this.webglControl.setParentBounds(bounds);
|
|
1225
|
+
this.webglControl.draw([
|
|
1226
|
+
...this.points
|
|
1227
|
+
]);
|
|
1228
|
+
}*/
|
|
1232
1229
|
|
|
1233
|
-
if (this.
|
|
1234
|
-
this.webglControl.setParentBounds(bounds);
|
|
1235
|
-
this.webglControl.draw(_toConsumableArray(this.points));
|
|
1236
|
-
} else if (this.context && this.context.moveTo) {
|
|
1230
|
+
if (this.context && this.context.moveTo) {
|
|
1237
1231
|
this.context.moveTo(this.points[0].x + bounds.left, this.points[0].y + bounds.top);
|
|
1238
1232
|
var len = this.points.length;
|
|
1239
1233
|
|
|
@@ -1887,7 +1881,7 @@ var jmControl = /*#__PURE__*/function (_jmProperty) {
|
|
|
1887
1881
|
exports.jmControl = exports["default"] = jmControl;
|
|
1888
1882
|
;
|
|
1889
1883
|
|
|
1890
|
-
},{"
|
|
1884
|
+
},{"./jmGradient.js":4,"./jmList.js":6,"./jmProperty.js":9,"./jmShadow.js":10,"./jmUtils.js":11}],3:[function(require,module,exports){
|
|
1891
1885
|
"use strict";
|
|
1892
1886
|
|
|
1893
1887
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -2590,7 +2584,7 @@ var jmGraph = /*#__PURE__*/function (_jmControl) {
|
|
|
2590
2584
|
}
|
|
2591
2585
|
|
|
2592
2586
|
option = option || {};
|
|
2593
|
-
option.mode =
|
|
2587
|
+
option.mode = '2d'; // webgl | 2d 暂不支持webgl
|
|
2594
2588
|
|
|
2595
2589
|
option.interactive = true;
|
|
2596
2590
|
option.isRegular = true; // 规则的
|
|
@@ -4946,2330 +4940,6 @@ var jmUtils = /*#__PURE__*/function () {
|
|
|
4946
4940
|
exports.jmUtils = exports["default"] = jmUtils;
|
|
4947
4941
|
|
|
4948
4942
|
},{"./jmList.js":6}],12:[function(require,module,exports){
|
|
4949
|
-
'use strict';
|
|
4950
|
-
|
|
4951
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4952
|
-
value: true
|
|
4953
|
-
});
|
|
4954
|
-
exports["default"] = void 0;
|
|
4955
|
-
var _default = earcut;
|
|
4956
|
-
exports["default"] = _default;
|
|
4957
|
-
|
|
4958
|
-
function earcut(data, holeIndices, dim) {
|
|
4959
|
-
dim = dim || 2;
|
|
4960
|
-
var hasHoles = holeIndices && holeIndices.length,
|
|
4961
|
-
outerLen = hasHoles ? holeIndices[0] * dim : data.length,
|
|
4962
|
-
outerNode = linkedList(data, 0, outerLen, dim, true),
|
|
4963
|
-
triangles = [];
|
|
4964
|
-
if (!outerNode || outerNode.next === outerNode.prev) return triangles;
|
|
4965
|
-
var minX, minY, maxX, maxY, x, y, invSize;
|
|
4966
|
-
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
|
|
4967
|
-
|
|
4968
|
-
if (data.length > 80 * dim) {
|
|
4969
|
-
minX = maxX = data[0];
|
|
4970
|
-
minY = maxY = data[1];
|
|
4971
|
-
|
|
4972
|
-
for (var i = dim; i < outerLen; i += dim) {
|
|
4973
|
-
x = data[i];
|
|
4974
|
-
y = data[i + 1];
|
|
4975
|
-
if (x < minX) minX = x;
|
|
4976
|
-
if (y < minY) minY = y;
|
|
4977
|
-
if (x > maxX) maxX = x;
|
|
4978
|
-
if (y > maxY) maxY = y;
|
|
4979
|
-
} // minX, minY and invSize are later used to transform coords into integers for z-order calculation
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
invSize = Math.max(maxX - minX, maxY - minY);
|
|
4983
|
-
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
4984
|
-
}
|
|
4985
|
-
|
|
4986
|
-
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
|
4987
|
-
return triangles;
|
|
4988
|
-
} // create a circular doubly linked list from polygon points in the specified winding order
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
function linkedList(data, start, end, dim, clockwise) {
|
|
4992
|
-
var i, last;
|
|
4993
|
-
|
|
4994
|
-
if (clockwise === signedArea(data, start, end, dim) > 0) {
|
|
4995
|
-
for (i = start; i < end; i += dim) {
|
|
4996
|
-
last = insertNode(i, data[i], data[i + 1], last);
|
|
4997
|
-
}
|
|
4998
|
-
} else {
|
|
4999
|
-
for (i = end - dim; i >= start; i -= dim) {
|
|
5000
|
-
last = insertNode(i, data[i], data[i + 1], last);
|
|
5001
|
-
}
|
|
5002
|
-
}
|
|
5003
|
-
|
|
5004
|
-
if (last && equals(last, last.next)) {
|
|
5005
|
-
removeNode(last);
|
|
5006
|
-
last = last.next;
|
|
5007
|
-
}
|
|
5008
|
-
|
|
5009
|
-
return last;
|
|
5010
|
-
} // eliminate colinear or duplicate points
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
function filterPoints(start, end) {
|
|
5014
|
-
if (!start) return start;
|
|
5015
|
-
if (!end) end = start;
|
|
5016
|
-
var p = start,
|
|
5017
|
-
again;
|
|
5018
|
-
|
|
5019
|
-
do {
|
|
5020
|
-
again = false;
|
|
5021
|
-
|
|
5022
|
-
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
5023
|
-
removeNode(p);
|
|
5024
|
-
p = end = p.prev;
|
|
5025
|
-
if (p === p.next) break;
|
|
5026
|
-
again = true;
|
|
5027
|
-
} else {
|
|
5028
|
-
p = p.next;
|
|
5029
|
-
}
|
|
5030
|
-
} while (again || p !== end);
|
|
5031
|
-
|
|
5032
|
-
return end;
|
|
5033
|
-
} // main ear slicing loop which triangulates a polygon (given as a linked list)
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
5037
|
-
if (!ear) return; // interlink polygon nodes in z-order
|
|
5038
|
-
|
|
5039
|
-
if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
|
|
5040
|
-
var stop = ear,
|
|
5041
|
-
prev,
|
|
5042
|
-
next; // iterate through ears, slicing them one by one
|
|
5043
|
-
|
|
5044
|
-
while (ear.prev !== ear.next) {
|
|
5045
|
-
prev = ear.prev;
|
|
5046
|
-
next = ear.next;
|
|
5047
|
-
|
|
5048
|
-
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
5049
|
-
// cut off the triangle
|
|
5050
|
-
triangles.push(prev.i / dim | 0);
|
|
5051
|
-
triangles.push(ear.i / dim | 0);
|
|
5052
|
-
triangles.push(next.i / dim | 0);
|
|
5053
|
-
removeNode(ear); // skipping the next vertex leads to less sliver triangles
|
|
5054
|
-
|
|
5055
|
-
ear = next.next;
|
|
5056
|
-
stop = next.next;
|
|
5057
|
-
continue;
|
|
5058
|
-
}
|
|
5059
|
-
|
|
5060
|
-
ear = next; // if we looped through the whole remaining polygon and can't find any more ears
|
|
5061
|
-
|
|
5062
|
-
if (ear === stop) {
|
|
5063
|
-
// try filtering points and slicing again
|
|
5064
|
-
if (!pass) {
|
|
5065
|
-
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
|
|
5066
|
-
} else if (pass === 1) {
|
|
5067
|
-
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
5068
|
-
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
|
|
5069
|
-
} else if (pass === 2) {
|
|
5070
|
-
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
5071
|
-
}
|
|
5072
|
-
|
|
5073
|
-
break;
|
|
5074
|
-
}
|
|
5075
|
-
}
|
|
5076
|
-
} // check whether a polygon node forms a valid ear with adjacent nodes
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
function isEar(ear) {
|
|
5080
|
-
var a = ear.prev,
|
|
5081
|
-
b = ear,
|
|
5082
|
-
c = ear.next;
|
|
5083
|
-
if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
|
|
5084
|
-
// now make sure we don't have other points inside the potential ear
|
|
5085
|
-
|
|
5086
|
-
var ax = a.x,
|
|
5087
|
-
bx = b.x,
|
|
5088
|
-
cx = c.x,
|
|
5089
|
-
ay = a.y,
|
|
5090
|
-
by = b.y,
|
|
5091
|
-
cy = c.y; // triangle bbox; min & max are calculated like this for speed
|
|
5092
|
-
|
|
5093
|
-
var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
|
|
5094
|
-
y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
|
|
5095
|
-
x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
|
|
5096
|
-
y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
5097
|
-
var p = c.next;
|
|
5098
|
-
|
|
5099
|
-
while (p !== a) {
|
|
5100
|
-
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;
|
|
5101
|
-
p = p.next;
|
|
5102
|
-
}
|
|
5103
|
-
|
|
5104
|
-
return true;
|
|
5105
|
-
}
|
|
5106
|
-
|
|
5107
|
-
function isEarHashed(ear, minX, minY, invSize) {
|
|
5108
|
-
var a = ear.prev,
|
|
5109
|
-
b = ear,
|
|
5110
|
-
c = ear.next;
|
|
5111
|
-
if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
|
|
5112
|
-
|
|
5113
|
-
var ax = a.x,
|
|
5114
|
-
bx = b.x,
|
|
5115
|
-
cx = c.x,
|
|
5116
|
-
ay = a.y,
|
|
5117
|
-
by = b.y,
|
|
5118
|
-
cy = c.y; // triangle bbox; min & max are calculated like this for speed
|
|
5119
|
-
|
|
5120
|
-
var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
|
|
5121
|
-
y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
|
|
5122
|
-
x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
|
|
5123
|
-
y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy; // z-order range for the current triangle bbox;
|
|
5124
|
-
|
|
5125
|
-
var minZ = zOrder(x0, y0, minX, minY, invSize),
|
|
5126
|
-
maxZ = zOrder(x1, y1, minX, minY, invSize);
|
|
5127
|
-
var p = ear.prevZ,
|
|
5128
|
-
n = ear.nextZ; // look for points inside the triangle in both directions
|
|
5129
|
-
|
|
5130
|
-
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
5131
|
-
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;
|
|
5132
|
-
p = p.prevZ;
|
|
5133
|
-
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;
|
|
5134
|
-
n = n.nextZ;
|
|
5135
|
-
} // look for remaining points in decreasing z-order
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
while (p && p.z >= minZ) {
|
|
5139
|
-
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;
|
|
5140
|
-
p = p.prevZ;
|
|
5141
|
-
} // look for remaining points in increasing z-order
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
while (n && n.z <= maxZ) {
|
|
5145
|
-
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;
|
|
5146
|
-
n = n.nextZ;
|
|
5147
|
-
}
|
|
5148
|
-
|
|
5149
|
-
return true;
|
|
5150
|
-
} // go through all polygon nodes and cure small local self-intersections
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
function cureLocalIntersections(start, triangles, dim) {
|
|
5154
|
-
var p = start;
|
|
5155
|
-
|
|
5156
|
-
do {
|
|
5157
|
-
var a = p.prev,
|
|
5158
|
-
b = p.next.next;
|
|
5159
|
-
|
|
5160
|
-
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
5161
|
-
triangles.push(a.i / dim | 0);
|
|
5162
|
-
triangles.push(p.i / dim | 0);
|
|
5163
|
-
triangles.push(b.i / dim | 0); // remove two nodes involved
|
|
5164
|
-
|
|
5165
|
-
removeNode(p);
|
|
5166
|
-
removeNode(p.next);
|
|
5167
|
-
p = start = b;
|
|
5168
|
-
}
|
|
5169
|
-
|
|
5170
|
-
p = p.next;
|
|
5171
|
-
} while (p !== start);
|
|
5172
|
-
|
|
5173
|
-
return filterPoints(p);
|
|
5174
|
-
} // try splitting polygon into two and triangulate them independently
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
5178
|
-
// look for a valid diagonal that divides the polygon into two
|
|
5179
|
-
var a = start;
|
|
5180
|
-
|
|
5181
|
-
do {
|
|
5182
|
-
var b = a.next.next;
|
|
5183
|
-
|
|
5184
|
-
while (b !== a.prev) {
|
|
5185
|
-
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
5186
|
-
// split the polygon in two by the diagonal
|
|
5187
|
-
var c = splitPolygon(a, b); // filter colinear points around the cuts
|
|
5188
|
-
|
|
5189
|
-
a = filterPoints(a, a.next);
|
|
5190
|
-
c = filterPoints(c, c.next); // run earcut on each half
|
|
5191
|
-
|
|
5192
|
-
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
|
5193
|
-
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
|
5194
|
-
return;
|
|
5195
|
-
}
|
|
5196
|
-
|
|
5197
|
-
b = b.next;
|
|
5198
|
-
}
|
|
5199
|
-
|
|
5200
|
-
a = a.next;
|
|
5201
|
-
} while (a !== start);
|
|
5202
|
-
} // link every hole into the outer loop, producing a single-ring polygon without holes
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
function eliminateHoles(data, holeIndices, outerNode, dim) {
|
|
5206
|
-
var queue = [],
|
|
5207
|
-
i,
|
|
5208
|
-
len,
|
|
5209
|
-
start,
|
|
5210
|
-
end,
|
|
5211
|
-
list;
|
|
5212
|
-
|
|
5213
|
-
for (i = 0, len = holeIndices.length; i < len; i++) {
|
|
5214
|
-
start = holeIndices[i] * dim;
|
|
5215
|
-
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
5216
|
-
list = linkedList(data, start, end, dim, false);
|
|
5217
|
-
if (list === list.next) list.steiner = true;
|
|
5218
|
-
queue.push(getLeftmost(list));
|
|
5219
|
-
}
|
|
5220
|
-
|
|
5221
|
-
queue.sort(compareX); // process holes from left to right
|
|
5222
|
-
|
|
5223
|
-
for (i = 0; i < queue.length; i++) {
|
|
5224
|
-
outerNode = eliminateHole(queue[i], outerNode);
|
|
5225
|
-
}
|
|
5226
|
-
|
|
5227
|
-
return outerNode;
|
|
5228
|
-
}
|
|
5229
|
-
|
|
5230
|
-
function compareX(a, b) {
|
|
5231
|
-
return a.x - b.x;
|
|
5232
|
-
} // find a bridge between vertices that connects hole with an outer ring and and link it
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
function eliminateHole(hole, outerNode) {
|
|
5236
|
-
var bridge = findHoleBridge(hole, outerNode);
|
|
5237
|
-
|
|
5238
|
-
if (!bridge) {
|
|
5239
|
-
return outerNode;
|
|
5240
|
-
}
|
|
5241
|
-
|
|
5242
|
-
var bridgeReverse = splitPolygon(bridge, hole); // filter collinear points around the cuts
|
|
5243
|
-
|
|
5244
|
-
filterPoints(bridgeReverse, bridgeReverse.next);
|
|
5245
|
-
return filterPoints(bridge, bridge.next);
|
|
5246
|
-
} // David Eberly's algorithm for finding a bridge between hole and outer polygon
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
function findHoleBridge(hole, outerNode) {
|
|
5250
|
-
var p = outerNode,
|
|
5251
|
-
hx = hole.x,
|
|
5252
|
-
hy = hole.y,
|
|
5253
|
-
qx = -Infinity,
|
|
5254
|
-
m; // find a segment intersected by a ray from the hole's leftmost point to the left;
|
|
5255
|
-
// segment's endpoint with lesser x will be potential connection point
|
|
5256
|
-
|
|
5257
|
-
do {
|
|
5258
|
-
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
5259
|
-
var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
5260
|
-
|
|
5261
|
-
if (x <= hx && x > qx) {
|
|
5262
|
-
qx = x;
|
|
5263
|
-
m = p.x < p.next.x ? p : p.next;
|
|
5264
|
-
if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint
|
|
5265
|
-
}
|
|
5266
|
-
}
|
|
5267
|
-
|
|
5268
|
-
p = p.next;
|
|
5269
|
-
} while (p !== outerNode);
|
|
5270
|
-
|
|
5271
|
-
if (!m) return null; // look for points inside the triangle of hole point, segment intersection and endpoint;
|
|
5272
|
-
// if there are no points found, we have a valid connection;
|
|
5273
|
-
// otherwise choose the point of the minimum angle with the ray as connection point
|
|
5274
|
-
|
|
5275
|
-
var stop = m,
|
|
5276
|
-
mx = m.x,
|
|
5277
|
-
my = m.y,
|
|
5278
|
-
tanMin = Infinity,
|
|
5279
|
-
tan;
|
|
5280
|
-
p = m;
|
|
5281
|
-
|
|
5282
|
-
do {
|
|
5283
|
-
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)) {
|
|
5284
|
-
tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
|
5285
|
-
|
|
5286
|
-
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
5287
|
-
m = p;
|
|
5288
|
-
tanMin = tan;
|
|
5289
|
-
}
|
|
5290
|
-
}
|
|
5291
|
-
|
|
5292
|
-
p = p.next;
|
|
5293
|
-
} while (p !== stop);
|
|
5294
|
-
|
|
5295
|
-
return m;
|
|
5296
|
-
} // whether sector in vertex m contains sector in vertex p in the same coordinates
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
function sectorContainsSector(m, p) {
|
|
5300
|
-
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
5301
|
-
} // interlink polygon nodes in z-order
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
function indexCurve(start, minX, minY, invSize) {
|
|
5305
|
-
var p = start;
|
|
5306
|
-
|
|
5307
|
-
do {
|
|
5308
|
-
if (p.z === 0) p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
5309
|
-
p.prevZ = p.prev;
|
|
5310
|
-
p.nextZ = p.next;
|
|
5311
|
-
p = p.next;
|
|
5312
|
-
} while (p !== start);
|
|
5313
|
-
|
|
5314
|
-
p.prevZ.nextZ = null;
|
|
5315
|
-
p.prevZ = null;
|
|
5316
|
-
sortLinked(p);
|
|
5317
|
-
} // Simon Tatham's linked list merge sort algorithm
|
|
5318
|
-
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
function sortLinked(list) {
|
|
5322
|
-
var i,
|
|
5323
|
-
p,
|
|
5324
|
-
q,
|
|
5325
|
-
e,
|
|
5326
|
-
tail,
|
|
5327
|
-
numMerges,
|
|
5328
|
-
pSize,
|
|
5329
|
-
qSize,
|
|
5330
|
-
inSize = 1;
|
|
5331
|
-
|
|
5332
|
-
do {
|
|
5333
|
-
p = list;
|
|
5334
|
-
list = null;
|
|
5335
|
-
tail = null;
|
|
5336
|
-
numMerges = 0;
|
|
5337
|
-
|
|
5338
|
-
while (p) {
|
|
5339
|
-
numMerges++;
|
|
5340
|
-
q = p;
|
|
5341
|
-
pSize = 0;
|
|
5342
|
-
|
|
5343
|
-
for (i = 0; i < inSize; i++) {
|
|
5344
|
-
pSize++;
|
|
5345
|
-
q = q.nextZ;
|
|
5346
|
-
if (!q) break;
|
|
5347
|
-
}
|
|
5348
|
-
|
|
5349
|
-
qSize = inSize;
|
|
5350
|
-
|
|
5351
|
-
while (pSize > 0 || qSize > 0 && q) {
|
|
5352
|
-
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
5353
|
-
e = p;
|
|
5354
|
-
p = p.nextZ;
|
|
5355
|
-
pSize--;
|
|
5356
|
-
} else {
|
|
5357
|
-
e = q;
|
|
5358
|
-
q = q.nextZ;
|
|
5359
|
-
qSize--;
|
|
5360
|
-
}
|
|
5361
|
-
|
|
5362
|
-
if (tail) tail.nextZ = e;else list = e;
|
|
5363
|
-
e.prevZ = tail;
|
|
5364
|
-
tail = e;
|
|
5365
|
-
}
|
|
5366
|
-
|
|
5367
|
-
p = q;
|
|
5368
|
-
}
|
|
5369
|
-
|
|
5370
|
-
tail.nextZ = null;
|
|
5371
|
-
inSize *= 2;
|
|
5372
|
-
} while (numMerges > 1);
|
|
5373
|
-
|
|
5374
|
-
return list;
|
|
5375
|
-
} // z-order of a point given coords and inverse of the longer side of data bbox
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
function zOrder(x, y, minX, minY, invSize) {
|
|
5379
|
-
// coords are transformed into non-negative 15-bit integer range
|
|
5380
|
-
x = (x - minX) * invSize | 0;
|
|
5381
|
-
y = (y - minY) * invSize | 0;
|
|
5382
|
-
x = (x | x << 8) & 0x00FF00FF;
|
|
5383
|
-
x = (x | x << 4) & 0x0F0F0F0F;
|
|
5384
|
-
x = (x | x << 2) & 0x33333333;
|
|
5385
|
-
x = (x | x << 1) & 0x55555555;
|
|
5386
|
-
y = (y | y << 8) & 0x00FF00FF;
|
|
5387
|
-
y = (y | y << 4) & 0x0F0F0F0F;
|
|
5388
|
-
y = (y | y << 2) & 0x33333333;
|
|
5389
|
-
y = (y | y << 1) & 0x55555555;
|
|
5390
|
-
return x | y << 1;
|
|
5391
|
-
} // find the leftmost node of a polygon ring
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
function getLeftmost(start) {
|
|
5395
|
-
var p = start,
|
|
5396
|
-
leftmost = start;
|
|
5397
|
-
|
|
5398
|
-
do {
|
|
5399
|
-
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
|
|
5400
|
-
p = p.next;
|
|
5401
|
-
} while (p !== start);
|
|
5402
|
-
|
|
5403
|
-
return leftmost;
|
|
5404
|
-
} // check if a point lies within a convex triangle
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
5408
|
-
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);
|
|
5409
|
-
} // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
function isValidDiagonal(a, b) {
|
|
5413
|
-
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
|
|
5414
|
-
equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
|
|
5415
|
-
} // signed area of a triangle
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
function area(p, q, r) {
|
|
5419
|
-
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
5420
|
-
} // check if two points are equal
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
function equals(p1, p2) {
|
|
5424
|
-
return p1.x === p2.x && p1.y === p2.y;
|
|
5425
|
-
} // check if two segments intersect
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
function intersects(p1, q1, p2, q2) {
|
|
5429
|
-
var o1 = sign(area(p1, q1, p2));
|
|
5430
|
-
var o2 = sign(area(p1, q1, q2));
|
|
5431
|
-
var o3 = sign(area(p2, q2, p1));
|
|
5432
|
-
var o4 = sign(area(p2, q2, q1));
|
|
5433
|
-
if (o1 !== o2 && o3 !== o4) return true; // general case
|
|
5434
|
-
|
|
5435
|
-
if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
|
|
5436
|
-
|
|
5437
|
-
if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
|
|
5438
|
-
|
|
5439
|
-
if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
|
|
5440
|
-
|
|
5441
|
-
if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
|
|
5442
|
-
|
|
5443
|
-
return false;
|
|
5444
|
-
} // for collinear points p, q, r, check if point q lies on segment pr
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
function onSegment(p, q, r) {
|
|
5448
|
-
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);
|
|
5449
|
-
}
|
|
5450
|
-
|
|
5451
|
-
function sign(num) {
|
|
5452
|
-
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
5453
|
-
} // check if a polygon diagonal intersects any polygon segments
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
function intersectsPolygon(a, b) {
|
|
5457
|
-
var p = a;
|
|
5458
|
-
|
|
5459
|
-
do {
|
|
5460
|
-
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;
|
|
5461
|
-
p = p.next;
|
|
5462
|
-
} while (p !== a);
|
|
5463
|
-
|
|
5464
|
-
return false;
|
|
5465
|
-
} // check if a polygon diagonal is locally inside the polygon
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
function locallyInside(a, b) {
|
|
5469
|
-
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;
|
|
5470
|
-
} // check if the middle point of a polygon diagonal is inside the polygon
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
function middleInside(a, b) {
|
|
5474
|
-
var p = a,
|
|
5475
|
-
inside = false,
|
|
5476
|
-
px = (a.x + b.x) / 2,
|
|
5477
|
-
py = (a.y + b.y) / 2;
|
|
5478
|
-
|
|
5479
|
-
do {
|
|
5480
|
-
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;
|
|
5481
|
-
p = p.next;
|
|
5482
|
-
} while (p !== a);
|
|
5483
|
-
|
|
5484
|
-
return inside;
|
|
5485
|
-
} // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
|
|
5486
|
-
// if one belongs to the outer ring and another to a hole, it merges it into a single ring
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
function splitPolygon(a, b) {
|
|
5490
|
-
var a2 = new Node(a.i, a.x, a.y),
|
|
5491
|
-
b2 = new Node(b.i, b.x, b.y),
|
|
5492
|
-
an = a.next,
|
|
5493
|
-
bp = b.prev;
|
|
5494
|
-
a.next = b;
|
|
5495
|
-
b.prev = a;
|
|
5496
|
-
a2.next = an;
|
|
5497
|
-
an.prev = a2;
|
|
5498
|
-
b2.next = a2;
|
|
5499
|
-
a2.prev = b2;
|
|
5500
|
-
bp.next = b2;
|
|
5501
|
-
b2.prev = bp;
|
|
5502
|
-
return b2;
|
|
5503
|
-
} // create a node and optionally link it with previous one (in a circular doubly linked list)
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
function insertNode(i, x, y, last) {
|
|
5507
|
-
var p = new Node(i, x, y);
|
|
5508
|
-
|
|
5509
|
-
if (!last) {
|
|
5510
|
-
p.prev = p;
|
|
5511
|
-
p.next = p;
|
|
5512
|
-
} else {
|
|
5513
|
-
p.next = last.next;
|
|
5514
|
-
p.prev = last;
|
|
5515
|
-
last.next.prev = p;
|
|
5516
|
-
last.next = p;
|
|
5517
|
-
}
|
|
5518
|
-
|
|
5519
|
-
return p;
|
|
5520
|
-
}
|
|
5521
|
-
|
|
5522
|
-
function removeNode(p) {
|
|
5523
|
-
p.next.prev = p.prev;
|
|
5524
|
-
p.prev.next = p.next;
|
|
5525
|
-
if (p.prevZ) p.prevZ.nextZ = p.nextZ;
|
|
5526
|
-
if (p.nextZ) p.nextZ.prevZ = p.prevZ;
|
|
5527
|
-
}
|
|
5528
|
-
|
|
5529
|
-
function Node(i, x, y) {
|
|
5530
|
-
// vertex index in coordinates array
|
|
5531
|
-
this.i = i; // vertex coordinates
|
|
5532
|
-
|
|
5533
|
-
this.x = x;
|
|
5534
|
-
this.y = y; // previous and next vertex nodes in a polygon ring
|
|
5535
|
-
|
|
5536
|
-
this.prev = null;
|
|
5537
|
-
this.next = null; // z-order curve value
|
|
5538
|
-
|
|
5539
|
-
this.z = 0; // previous and next nodes in z-order
|
|
5540
|
-
|
|
5541
|
-
this.prevZ = null;
|
|
5542
|
-
this.nextZ = null; // indicates whether this is a steiner point
|
|
5543
|
-
|
|
5544
|
-
this.steiner = false;
|
|
5545
|
-
} // return a percentage difference between the polygon area and its triangulation area;
|
|
5546
|
-
// used to verify correctness of triangulation
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
earcut.deviation = function (data, holeIndices, dim, triangles) {
|
|
5550
|
-
var hasHoles = holeIndices && holeIndices.length;
|
|
5551
|
-
var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
5552
|
-
var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
|
|
5553
|
-
|
|
5554
|
-
if (hasHoles) {
|
|
5555
|
-
for (var i = 0, len = holeIndices.length; i < len; i++) {
|
|
5556
|
-
var start = holeIndices[i] * dim;
|
|
5557
|
-
var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
5558
|
-
polygonArea -= Math.abs(signedArea(data, start, end, dim));
|
|
5559
|
-
}
|
|
5560
|
-
}
|
|
5561
|
-
|
|
5562
|
-
var trianglesArea = 0;
|
|
5563
|
-
|
|
5564
|
-
for (i = 0; i < triangles.length; i += 3) {
|
|
5565
|
-
var a = triangles[i] * dim;
|
|
5566
|
-
var b = triangles[i + 1] * dim;
|
|
5567
|
-
var c = triangles[i + 2] * dim;
|
|
5568
|
-
trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
|
|
5569
|
-
}
|
|
5570
|
-
|
|
5571
|
-
return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
|
|
5572
|
-
};
|
|
5573
|
-
|
|
5574
|
-
function signedArea(data, start, end, dim) {
|
|
5575
|
-
var sum = 0;
|
|
5576
|
-
|
|
5577
|
-
for (var i = start, j = end - dim; i < end; i += dim) {
|
|
5578
|
-
sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
|
|
5579
|
-
j = i;
|
|
5580
|
-
}
|
|
5581
|
-
|
|
5582
|
-
return sum;
|
|
5583
|
-
} // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
earcut.flatten = function (data) {
|
|
5587
|
-
var dim = data[0][0].length,
|
|
5588
|
-
result = {
|
|
5589
|
-
vertices: [],
|
|
5590
|
-
holes: [],
|
|
5591
|
-
dimensions: dim
|
|
5592
|
-
},
|
|
5593
|
-
holeIndex = 0;
|
|
5594
|
-
|
|
5595
|
-
for (var i = 0; i < data.length; i++) {
|
|
5596
|
-
for (var j = 0; j < data[i].length; j++) {
|
|
5597
|
-
for (var d = 0; d < dim; d++) {
|
|
5598
|
-
result.vertices.push(data[i][j][d]);
|
|
5599
|
-
}
|
|
5600
|
-
}
|
|
5601
|
-
|
|
5602
|
-
if (i > 0) {
|
|
5603
|
-
holeIndex += data[i - 1].length;
|
|
5604
|
-
result.holes.push(holeIndex);
|
|
5605
|
-
}
|
|
5606
|
-
}
|
|
5607
|
-
|
|
5608
|
-
return result;
|
|
5609
|
-
};
|
|
5610
|
-
|
|
5611
|
-
},{}],13:[function(require,module,exports){
|
|
5612
|
-
"use strict";
|
|
5613
|
-
|
|
5614
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5615
|
-
value: true
|
|
5616
|
-
});
|
|
5617
|
-
exports["default"] = void 0;
|
|
5618
|
-
|
|
5619
|
-
var _earcut = _interopRequireDefault(require("../earcut.js"));
|
|
5620
|
-
|
|
5621
|
-
var _gradient = _interopRequireDefault(require("./gradient.js"));
|
|
5622
|
-
|
|
5623
|
-
var _program = require("./core/program.js");
|
|
5624
|
-
|
|
5625
|
-
var _buffer = require("./core/buffer.js");
|
|
5626
|
-
|
|
5627
|
-
var _texture = require("./core/texture.js");
|
|
5628
|
-
|
|
5629
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
5630
|
-
|
|
5631
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5632
|
-
|
|
5633
|
-
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."); }
|
|
5634
|
-
|
|
5635
|
-
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); }
|
|
5636
|
-
|
|
5637
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5638
|
-
|
|
5639
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5640
|
-
|
|
5641
|
-
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; }
|
|
5642
|
-
|
|
5643
|
-
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; }
|
|
5644
|
-
|
|
5645
|
-
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; }
|
|
5646
|
-
|
|
5647
|
-
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; }
|
|
5648
|
-
|
|
5649
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5650
|
-
|
|
5651
|
-
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); } }
|
|
5652
|
-
|
|
5653
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5654
|
-
|
|
5655
|
-
var WeblBase = /*#__PURE__*/function () {
|
|
5656
|
-
function WeblBase(graph, option) {
|
|
5657
|
-
_classCallCheck(this, WeblBase);
|
|
5658
|
-
|
|
5659
|
-
this.graph = graph;
|
|
5660
|
-
this.option = option || {};
|
|
5661
|
-
this.style = {
|
|
5662
|
-
globalAlpha: 1
|
|
5663
|
-
};
|
|
5664
|
-
}
|
|
5665
|
-
|
|
5666
|
-
_createClass(WeblBase, [{
|
|
5667
|
-
key: "context",
|
|
5668
|
-
get: function get() {
|
|
5669
|
-
if (this.graph) return this.graph.context;
|
|
5670
|
-
} // 创建程序
|
|
5671
|
-
|
|
5672
|
-
}, {
|
|
5673
|
-
key: "createProgram",
|
|
5674
|
-
value: function createProgram(vertexSrc, fragmentSrc) {
|
|
5675
|
-
return (0, _program.createProgram)(this.context, vertexSrc, fragmentSrc);
|
|
5676
|
-
} // 指定使用某个程序
|
|
5677
|
-
|
|
5678
|
-
}, {
|
|
5679
|
-
key: "useProgram",
|
|
5680
|
-
value: function useProgram() {
|
|
5681
|
-
var program = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.program;
|
|
5682
|
-
program = program.program || program;
|
|
5683
|
-
if (this.context.__curent_program === program) return program;
|
|
5684
|
-
(0, _program.useProgram)(this.context, program.program || program);
|
|
5685
|
-
this.context.__curent_program = program;
|
|
5686
|
-
return program;
|
|
5687
|
-
}
|
|
5688
|
-
}, {
|
|
5689
|
-
key: "getAttribLocation",
|
|
5690
|
-
value: function getAttribLocation(name) {
|
|
5691
|
-
return this.context.getAttribLocation(this.program.program, name);
|
|
5692
|
-
}
|
|
5693
|
-
}, {
|
|
5694
|
-
key: "getUniformLocation",
|
|
5695
|
-
value: function getUniformLocation(name) {
|
|
5696
|
-
return this.context.getUniformLocation(this.program.program, name);
|
|
5697
|
-
} // 把缓冲区的值写入变量
|
|
5698
|
-
// buffer: 缓冲区
|
|
5699
|
-
// size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
|
|
5700
|
-
// strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
|
|
5701
|
-
// offset: 字节偏移量,必须是类型的字节长度的倍数。
|
|
5702
|
-
// dataType: 每个元素的数据类型
|
|
5703
|
-
|
|
5704
|
-
}, {
|
|
5705
|
-
key: "writeVertexAttrib",
|
|
5706
|
-
value: function writeVertexAttrib(buffer, attr) {
|
|
5707
|
-
var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
|
5708
|
-
var strip = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
5709
|
-
var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
5710
|
-
var dataType = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : this.context.FLOAT;
|
|
5711
|
-
buffer.attr = attr;
|
|
5712
|
-
return (0, _program.writeVertexAttrib)(this.context, buffer, attr, size, strip, offset, dataType);
|
|
5713
|
-
} // 禁用attri
|
|
5714
|
-
|
|
5715
|
-
}, {
|
|
5716
|
-
key: "disableVertexAttribArray",
|
|
5717
|
-
value: function disableVertexAttribArray(attr) {
|
|
5718
|
-
try {
|
|
5719
|
-
if (!attr) return attr;
|
|
5720
|
-
return (0, _program.disableVertexAttribArray)(this.context, attr);
|
|
5721
|
-
} catch (e) {
|
|
5722
|
-
console.error(e);
|
|
5723
|
-
}
|
|
5724
|
-
|
|
5725
|
-
return attr;
|
|
5726
|
-
} // 创建float32的buffer
|
|
5727
|
-
|
|
5728
|
-
}, {
|
|
5729
|
-
key: "createFloat32Buffer",
|
|
5730
|
-
value: function createFloat32Buffer(data) {
|
|
5731
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.context.ARRAY_BUFFER;
|
|
5732
|
-
var drawType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.context.STATIC_DRAW;
|
|
5733
|
-
var buffer = (0, _buffer.createFloat32Buffer)(this.context, data, type, drawType);
|
|
5734
|
-
return _objectSpread({
|
|
5735
|
-
data: data
|
|
5736
|
-
}, buffer);
|
|
5737
|
-
}
|
|
5738
|
-
}, {
|
|
5739
|
-
key: "createUint16Buffer",
|
|
5740
|
-
value: function createUint16Buffer(data) {
|
|
5741
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.context.ARRAY_BUFFER;
|
|
5742
|
-
var drawType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.context.STATIC_DRAW;
|
|
5743
|
-
var buffer = (0, _buffer.createUint16Buffer)(this.context, data, type, drawType);
|
|
5744
|
-
return _objectSpread({
|
|
5745
|
-
data: data
|
|
5746
|
-
}, buffer);
|
|
5747
|
-
} // 释放
|
|
5748
|
-
|
|
5749
|
-
}, {
|
|
5750
|
-
key: "deleteBuffer",
|
|
5751
|
-
value: function deleteBuffer(buffer) {
|
|
5752
|
-
try {
|
|
5753
|
-
if (!buffer) return;
|
|
5754
|
-
var bufferHandler = buffer.buffer || buffer;
|
|
5755
|
-
if (bufferHandler) return (0, _buffer.deleteBuffer)(this.context, bufferHandler);
|
|
5756
|
-
} catch (e) {
|
|
5757
|
-
console.log(buffer);
|
|
5758
|
-
console.error(e);
|
|
5759
|
-
}
|
|
5760
|
-
|
|
5761
|
-
return buffer;
|
|
5762
|
-
} // 生成纹理
|
|
5763
|
-
|
|
5764
|
-
}, {
|
|
5765
|
-
key: "create2DTexture",
|
|
5766
|
-
value: function create2DTexture() {
|
|
5767
|
-
return (0, _texture.create2DTexture)(this.context);
|
|
5768
|
-
} // 创建图片纹理
|
|
5769
|
-
|
|
5770
|
-
}, {
|
|
5771
|
-
key: "createImgTexture",
|
|
5772
|
-
value: function createImgTexture(img) {
|
|
5773
|
-
return (0, _texture.createImgTexture)(this.context, img);
|
|
5774
|
-
} // 根根像素值生成纹理
|
|
5775
|
-
|
|
5776
|
-
}, {
|
|
5777
|
-
key: "createDataTexture",
|
|
5778
|
-
value: function createDataTexture(data) {
|
|
5779
|
-
return (0, _texture.createDataTexture)(this.context, data);
|
|
5780
|
-
} // 删除纹理
|
|
5781
|
-
|
|
5782
|
-
}, {
|
|
5783
|
-
key: "deleteTexture",
|
|
5784
|
-
value: function deleteTexture(texture) {
|
|
5785
|
-
try {
|
|
5786
|
-
return (0, _texture.deleteTexture)(this.context, texture.texture || texture);
|
|
5787
|
-
} catch (e) {
|
|
5788
|
-
console.error(e);
|
|
5789
|
-
}
|
|
5790
|
-
|
|
5791
|
-
return texture;
|
|
5792
|
-
} // 多边切割, 得到三角形顶点索引数组
|
|
5793
|
-
// polygonIndices 顶点索引,
|
|
5794
|
-
|
|
5795
|
-
}, {
|
|
5796
|
-
key: "earCutPoints",
|
|
5797
|
-
value: function earCutPoints(points) {
|
|
5798
|
-
var arr = this.pointsToArray(points);
|
|
5799
|
-
var ps = (0, _earcut["default"])(arr); // 切割得到3角色顶点索引,
|
|
5800
|
-
|
|
5801
|
-
return ps;
|
|
5802
|
-
} // 多边切割, 得到三角形顶点
|
|
5803
|
-
// polygonIndices 顶点索引,
|
|
5804
|
-
|
|
5805
|
-
}, {
|
|
5806
|
-
key: "earCutPointsToTriangles",
|
|
5807
|
-
value: function earCutPointsToTriangles(points) {
|
|
5808
|
-
var ps = this.earCutPoints(points); // 切割得到3角色顶点索引,
|
|
5809
|
-
|
|
5810
|
-
var triangles = []; // 用顶点索引再组合成坐标数组
|
|
5811
|
-
|
|
5812
|
-
for (var i = 0; i < ps.length; i += 3) {
|
|
5813
|
-
var p1 = points[ps[i]];
|
|
5814
|
-
var p2 = points[ps[i + 1]];
|
|
5815
|
-
var p3 = points[ps[i + 2]];
|
|
5816
|
-
triangles.push([p1, p2, p3]); // 每三个顶点构成一个三角
|
|
5817
|
-
}
|
|
5818
|
-
|
|
5819
|
-
return triangles;
|
|
5820
|
-
} // 点坐标数组转为一维数组
|
|
5821
|
-
|
|
5822
|
-
}, {
|
|
5823
|
-
key: "pointsToArray",
|
|
5824
|
-
value: function pointsToArray(points) {
|
|
5825
|
-
var _ref;
|
|
5826
|
-
|
|
5827
|
-
return (_ref = []).concat.apply(_ref, _toConsumableArray(points.map(function (p) {
|
|
5828
|
-
return [p.x, p.y];
|
|
5829
|
-
}))); // 把x,y转为数组元素
|
|
5830
|
-
} // 每2位表示坐标x,y转为坐标点对象
|
|
5831
|
-
|
|
5832
|
-
}, {
|
|
5833
|
-
key: "arrayToPoints",
|
|
5834
|
-
value: function arrayToPoints(arr) {
|
|
5835
|
-
var points = [];
|
|
5836
|
-
|
|
5837
|
-
for (var i = 0; i < arr.length; i += 2) {
|
|
5838
|
-
points.push({
|
|
5839
|
-
x: arr[i],
|
|
5840
|
-
y: arr[i + 1]
|
|
5841
|
-
});
|
|
5842
|
-
}
|
|
5843
|
-
|
|
5844
|
-
return points;
|
|
5845
|
-
} // 创建线性渐变
|
|
5846
|
-
|
|
5847
|
-
}, {
|
|
5848
|
-
key: "createLinearGradient",
|
|
5849
|
-
value: function createLinearGradient(x1, y1, x2, y2, bounds) {
|
|
5850
|
-
return new _gradient["default"]('linear', {
|
|
5851
|
-
x1: x1,
|
|
5852
|
-
y1: y1,
|
|
5853
|
-
x2: x2,
|
|
5854
|
-
y2: y2,
|
|
5855
|
-
bounds: bounds,
|
|
5856
|
-
control: this
|
|
5857
|
-
});
|
|
5858
|
-
} // 创建放射性渐变
|
|
5859
|
-
|
|
5860
|
-
}, {
|
|
5861
|
-
key: "createRadialGradient",
|
|
5862
|
-
value: function createRadialGradient(x1, y1, r1, x2, y2, r2, bounds) {
|
|
5863
|
-
return new _gradient["default"]('radial', {
|
|
5864
|
-
x1: x1,
|
|
5865
|
-
y1: y1,
|
|
5866
|
-
r1: r1,
|
|
5867
|
-
x2: x2,
|
|
5868
|
-
y2: y2,
|
|
5869
|
-
r2: r2,
|
|
5870
|
-
bounds: bounds,
|
|
5871
|
-
control: this
|
|
5872
|
-
});
|
|
5873
|
-
} // 判断是否是一个渐变对象
|
|
5874
|
-
|
|
5875
|
-
}, {
|
|
5876
|
-
key: "isGradient",
|
|
5877
|
-
value: function isGradient(obj) {
|
|
5878
|
-
return obj && obj instanceof _gradient["default"];
|
|
5879
|
-
}
|
|
5880
|
-
}]);
|
|
5881
|
-
|
|
5882
|
-
return WeblBase;
|
|
5883
|
-
}();
|
|
5884
|
-
|
|
5885
|
-
var _default = WeblBase;
|
|
5886
|
-
exports["default"] = _default;
|
|
5887
|
-
|
|
5888
|
-
},{"../earcut.js":12,"./core/buffer.js":14,"./core/program.js":17,"./core/texture.js":19,"./gradient.js":20}],14:[function(require,module,exports){
|
|
5889
|
-
"use strict";
|
|
5890
|
-
|
|
5891
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5892
|
-
value: true
|
|
5893
|
-
});
|
|
5894
|
-
exports.createBuffer = createBuffer;
|
|
5895
|
-
exports.createUint16Buffer = createUint16Buffer;
|
|
5896
|
-
exports.createFloat32Buffer = createFloat32Buffer;
|
|
5897
|
-
exports.deleteBuffer = deleteBuffer;
|
|
5898
|
-
|
|
5899
|
-
// 创建缓冲区
|
|
5900
|
-
function createBuffer(gl, data) {
|
|
5901
|
-
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
|
|
5902
|
-
var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
|
|
5903
|
-
//先创建一个缓存对象
|
|
5904
|
-
var buffer = gl.createBuffer();
|
|
5905
|
-
|
|
5906
|
-
if (!buffer) {
|
|
5907
|
-
throw Error('创建缓冲区对象失败');
|
|
5908
|
-
} //说明缓存对象保存的类型
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
gl.bindBuffer(type, buffer); //写入坐标数据
|
|
5912
|
-
// 因为会将数据发送到 GPU,为了省去数据解析,这里使用 Float32Array 直接传送数据
|
|
5913
|
-
|
|
5914
|
-
gl.bufferData(type, data, drawType); // 表示缓冲区的内容不会经常更改
|
|
5915
|
-
|
|
5916
|
-
return {
|
|
5917
|
-
type: type,
|
|
5918
|
-
drawType: drawType,
|
|
5919
|
-
buffer: buffer,
|
|
5920
|
-
// 获取到数组中单个元素的字节数
|
|
5921
|
-
unitSize: data.BYTES_PER_ELEMENT
|
|
5922
|
-
};
|
|
5923
|
-
} // 创建float32的buffer
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
function createFloat32Buffer(gl, data) {
|
|
5927
|
-
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
|
|
5928
|
-
var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
|
|
5929
|
-
var vertices = new Float32Array(data);
|
|
5930
|
-
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
5931
|
-
return buffer;
|
|
5932
|
-
} // 创建uint16的bugger
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
function createUint16Buffer(gl, data) {
|
|
5936
|
-
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gl.ARRAY_BUFFER;
|
|
5937
|
-
var drawType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : gl.STATIC_DRAW;
|
|
5938
|
-
var vertices = new Uint16Array(data);
|
|
5939
|
-
var buffer = createBuffer(gl, vertices, type, drawType);
|
|
5940
|
-
return buffer;
|
|
5941
|
-
} // 释放
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
function deleteBuffer(gl, buffer) {
|
|
5945
|
-
gl.deleteBuffer(buffer.buffer || buffer);
|
|
5946
|
-
}
|
|
5947
|
-
|
|
5948
|
-
},{}],15:[function(require,module,exports){
|
|
5949
|
-
"use strict";
|
|
5950
|
-
|
|
5951
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5952
|
-
value: true
|
|
5953
|
-
});
|
|
5954
|
-
exports.mapSize = void 0;
|
|
5955
|
-
var GLSL_TO_SIZE = {
|
|
5956
|
-
'float': 1,
|
|
5957
|
-
'vec2': 2,
|
|
5958
|
-
'vec3': 3,
|
|
5959
|
-
'vec4': 4,
|
|
5960
|
-
'int': 1,
|
|
5961
|
-
'ivec2': 2,
|
|
5962
|
-
'ivec3': 3,
|
|
5963
|
-
'ivec4': 4,
|
|
5964
|
-
'bool': 1,
|
|
5965
|
-
'bvec2': 2,
|
|
5966
|
-
'bvec3': 3,
|
|
5967
|
-
'bvec4': 4,
|
|
5968
|
-
'mat2': 4,
|
|
5969
|
-
'mat3': 9,
|
|
5970
|
-
'mat4': 16,
|
|
5971
|
-
'sampler2D': 1
|
|
5972
|
-
};
|
|
5973
|
-
/**
|
|
5974
|
-
* @class
|
|
5975
|
-
* @memberof PIXI.glCore.shader
|
|
5976
|
-
* @param type {String}
|
|
5977
|
-
* @return {Number}
|
|
5978
|
-
*/
|
|
5979
|
-
|
|
5980
|
-
var mapSize = function mapSize(type) {
|
|
5981
|
-
return GLSL_TO_SIZE[type];
|
|
5982
|
-
};
|
|
5983
|
-
|
|
5984
|
-
exports.mapSize = mapSize;
|
|
5985
|
-
|
|
5986
|
-
},{}],16:[function(require,module,exports){
|
|
5987
|
-
"use strict";
|
|
5988
|
-
|
|
5989
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5990
|
-
value: true
|
|
5991
|
-
});
|
|
5992
|
-
exports.mapType = void 0;
|
|
5993
|
-
var GL_TABLE = null;
|
|
5994
|
-
var GL_TO_GLSL_TYPES = {
|
|
5995
|
-
'FLOAT': 'float',
|
|
5996
|
-
'FLOAT_VEC2': 'vec2',
|
|
5997
|
-
'FLOAT_VEC3': 'vec3',
|
|
5998
|
-
'FLOAT_VEC4': 'vec4',
|
|
5999
|
-
'INT': 'int',
|
|
6000
|
-
'INT_VEC2': 'ivec2',
|
|
6001
|
-
'INT_VEC3': 'ivec3',
|
|
6002
|
-
'INT_VEC4': 'ivec4',
|
|
6003
|
-
'BOOL': 'bool',
|
|
6004
|
-
'BOOL_VEC2': 'bvec2',
|
|
6005
|
-
'BOOL_VEC3': 'bvec3',
|
|
6006
|
-
'BOOL_VEC4': 'bvec4',
|
|
6007
|
-
'FLOAT_MAT2': 'mat2',
|
|
6008
|
-
'FLOAT_MAT3': 'mat3',
|
|
6009
|
-
'FLOAT_MAT4': 'mat4',
|
|
6010
|
-
'SAMPLER_2D': 'sampler2D'
|
|
6011
|
-
};
|
|
6012
|
-
|
|
6013
|
-
var mapType = function mapType(gl, type) {
|
|
6014
|
-
if (!GL_TABLE) {
|
|
6015
|
-
var typeNames = Object.keys(GL_TO_GLSL_TYPES);
|
|
6016
|
-
GL_TABLE = {};
|
|
6017
|
-
|
|
6018
|
-
for (var i = 0; i < typeNames.length; ++i) {
|
|
6019
|
-
var tn = typeNames[i];
|
|
6020
|
-
GL_TABLE[gl[tn]] = GL_TO_GLSL_TYPES[tn];
|
|
6021
|
-
}
|
|
6022
|
-
}
|
|
6023
|
-
|
|
6024
|
-
return GL_TABLE[type];
|
|
6025
|
-
};
|
|
6026
|
-
|
|
6027
|
-
exports.mapType = mapType;
|
|
6028
|
-
|
|
6029
|
-
},{}],17:[function(require,module,exports){
|
|
6030
|
-
"use strict";
|
|
6031
|
-
|
|
6032
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6033
|
-
value: true
|
|
6034
|
-
});
|
|
6035
|
-
exports.createProgram = createProgram;
|
|
6036
|
-
exports.useProgram = useProgram;
|
|
6037
|
-
exports.getAttribLocation = getAttribLocation;
|
|
6038
|
-
exports.getUniformLocation = getUniformLocation;
|
|
6039
|
-
exports.extractAttributes = extractAttributes;
|
|
6040
|
-
exports.extractUniforms = extractUniforms;
|
|
6041
|
-
exports.writeVertexAttrib = writeVertexAttrib;
|
|
6042
|
-
exports.disableVertexAttribArray = disableVertexAttribArray;
|
|
6043
|
-
|
|
6044
|
-
var _shader = require("./shader.js");
|
|
6045
|
-
|
|
6046
|
-
var _mapSize = require("./mapSize.js");
|
|
6047
|
-
|
|
6048
|
-
var _mapType = require("./mapType.js");
|
|
6049
|
-
|
|
6050
|
-
// 创建程序
|
|
6051
|
-
function createProgram(gl, vertexSrc, fragmentSrc) {
|
|
6052
|
-
// 创建顶点着色器
|
|
6053
|
-
var vertexShader = (0, _shader.createShader)(gl, gl.VERTEX_SHADER, vertexSrc); // 创建片段着色器
|
|
6054
|
-
|
|
6055
|
-
var fragmentShader = (0, _shader.createShader)(gl, gl.FRAGMENT_SHADER, fragmentSrc);
|
|
6056
|
-
var program = gl.createProgram(); // 创建一个程序
|
|
6057
|
-
|
|
6058
|
-
gl.attachShader(program, vertexShader); // 添加顶点着色器
|
|
6059
|
-
|
|
6060
|
-
gl.attachShader(program, fragmentShader); // 添加片元着色器
|
|
6061
|
-
|
|
6062
|
-
gl.linkProgram(program); // 连接 program 中的着色器
|
|
6063
|
-
// 检查程序链接状态
|
|
6064
|
-
|
|
6065
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
6066
|
-
console.error('PError: Could not initialize shader.');
|
|
6067
|
-
console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS));
|
|
6068
|
-
console.error('gl.getError()', gl.getError()); // if there is a program info log, log it
|
|
6069
|
-
|
|
6070
|
-
if (gl.getProgramInfoLog(program) !== '') {
|
|
6071
|
-
console.warn('Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program));
|
|
6072
|
-
}
|
|
6073
|
-
|
|
6074
|
-
gl.deleteProgram(program);
|
|
6075
|
-
}
|
|
6076
|
-
|
|
6077
|
-
useProgram(gl, program); // clean up some shaders
|
|
6078
|
-
|
|
6079
|
-
gl.deleteShader(vertexShader);
|
|
6080
|
-
gl.deleteShader(fragmentShader);
|
|
6081
|
-
var attrs = extractAttributes(gl, program);
|
|
6082
|
-
var uniforms = extractUniforms(gl, program);
|
|
6083
|
-
return {
|
|
6084
|
-
program: program,
|
|
6085
|
-
attrs: attrs,
|
|
6086
|
-
uniforms: uniforms
|
|
6087
|
-
};
|
|
6088
|
-
} // 采用program
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
function useProgram(gl, program) {
|
|
6092
|
-
return gl.useProgram(program); // 告诉 webgl 用这个 program 进行渲染
|
|
6093
|
-
}
|
|
6094
|
-
|
|
6095
|
-
function extractAttributes(gl, program) {
|
|
6096
|
-
var attributes = {};
|
|
6097
|
-
var count = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
|
|
6098
|
-
|
|
6099
|
-
for (var i = 0; i < count; i++) {
|
|
6100
|
-
var attribData = gl.getActiveAttrib(program, i);
|
|
6101
|
-
var type = (0, _mapType.mapType)(gl, attribData.type);
|
|
6102
|
-
attributes[attribData.name] = {
|
|
6103
|
-
attribData: attribData,
|
|
6104
|
-
size: (0, _mapSize.mapSize)(type),
|
|
6105
|
-
type: type,
|
|
6106
|
-
location: gl.getAttribLocation(program, attribData.name)
|
|
6107
|
-
};
|
|
6108
|
-
}
|
|
6109
|
-
|
|
6110
|
-
return attributes;
|
|
6111
|
-
}
|
|
6112
|
-
|
|
6113
|
-
function extractUniforms(gl, program) {
|
|
6114
|
-
var uniforms = {};
|
|
6115
|
-
var count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
6116
|
-
|
|
6117
|
-
for (var i = 0; i < count; i++) {
|
|
6118
|
-
var uniformData = gl.getActiveUniform(program, i);
|
|
6119
|
-
var name = uniformData.name.replace(/\[.*?\]/, "");
|
|
6120
|
-
var type = (0, _mapType.mapType)(gl, uniformData.type);
|
|
6121
|
-
uniforms[name] = {
|
|
6122
|
-
uniformData: uniformData,
|
|
6123
|
-
type: type,
|
|
6124
|
-
size: uniformData.size,
|
|
6125
|
-
location: gl.getUniformLocation(program, name)
|
|
6126
|
-
};
|
|
6127
|
-
}
|
|
6128
|
-
|
|
6129
|
-
return uniforms;
|
|
6130
|
-
}
|
|
6131
|
-
|
|
6132
|
-
; // 把缓冲区的值写入变量
|
|
6133
|
-
// size: 组成数量,必须是1,2,3或4. 每个单元由多少个数组成
|
|
6134
|
-
// strip: 步长 数组中一行长度,0 表示数据是紧密的没有空隙,让OpenGL决定具体步长
|
|
6135
|
-
// offset: 字节偏移量,必须是类型的字节长度的倍数。
|
|
6136
|
-
// dataType: 每个元素的数据类型
|
|
6137
|
-
|
|
6138
|
-
function writeVertexAttrib(gl, buffer, attr) {
|
|
6139
|
-
var size = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
|
|
6140
|
-
var strip = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
6141
|
-
var offset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
|
|
6142
|
-
var dataType = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : gl.FLOAT;
|
|
6143
|
-
gl.bindBuffer(buffer.type, buffer.buffer);
|
|
6144
|
-
gl.vertexAttribPointer( // 告诉 OpenGL 如何从 Buffer 中获取数据
|
|
6145
|
-
attr.location, // 顶点属性的索引
|
|
6146
|
-
size, // 组成数量,必须是1,2,3或4。我们只提供了 x 和 y
|
|
6147
|
-
dataType, false, // 是否归一化到特定的范围,对 FLOAT 类型数据设置无效
|
|
6148
|
-
strip * buffer.unitSize, offset);
|
|
6149
|
-
gl.enableVertexAttribArray(attr.location);
|
|
6150
|
-
return buffer;
|
|
6151
|
-
}
|
|
6152
|
-
|
|
6153
|
-
function disableVertexAttribArray(gl, attr) {
|
|
6154
|
-
return gl.disableVertexAttribArray(attr.location);
|
|
6155
|
-
}
|
|
6156
|
-
|
|
6157
|
-
function getAttribLocation(gl, program, name) {
|
|
6158
|
-
return gl.getAttribLocation(program, name);
|
|
6159
|
-
}
|
|
6160
|
-
|
|
6161
|
-
function getUniformLocation(gl, program, name) {
|
|
6162
|
-
return gl.getUniformLocation(program, name);
|
|
6163
|
-
}
|
|
6164
|
-
|
|
6165
|
-
},{"./mapSize.js":15,"./mapType.js":16,"./shader.js":18}],18:[function(require,module,exports){
|
|
6166
|
-
"use strict";
|
|
6167
|
-
|
|
6168
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6169
|
-
value: true
|
|
6170
|
-
});
|
|
6171
|
-
exports.createShader = createShader;
|
|
6172
|
-
|
|
6173
|
-
// 生成着色器
|
|
6174
|
-
// type: gl.VERTEX_SHADER 顶点着色器 , gl.FRAGMENT_SHADER 片段着色器
|
|
6175
|
-
// src: 着色器代码
|
|
6176
|
-
function createShader(gl, type, src) {
|
|
6177
|
-
var shader = gl.createShader(type); // 创建一个顶点着色器
|
|
6178
|
-
|
|
6179
|
-
gl.shaderSource(shader, src); // 编写顶点着色器代码
|
|
6180
|
-
|
|
6181
|
-
gl.compileShader(shader); // 编译着色器
|
|
6182
|
-
|
|
6183
|
-
return shader;
|
|
6184
|
-
}
|
|
6185
|
-
|
|
6186
|
-
},{}],19:[function(require,module,exports){
|
|
6187
|
-
"use strict";
|
|
6188
|
-
|
|
6189
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6190
|
-
value: true
|
|
6191
|
-
});
|
|
6192
|
-
exports.create2DTexture = create2DTexture;
|
|
6193
|
-
exports.createImgTexture = createImgTexture;
|
|
6194
|
-
exports.createDataTexture = createDataTexture;
|
|
6195
|
-
exports.deleteTexture = deleteTexture;
|
|
6196
|
-
|
|
6197
|
-
// 生成纹理
|
|
6198
|
-
function create2DTexture(gl) {
|
|
6199
|
-
var texture = gl.createTexture();
|
|
6200
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1); // 图像反转Y轴
|
|
6201
|
-
|
|
6202
|
-
gl.activeTexture(gl.TEXTURE0); // 激活纹理单元
|
|
6203
|
-
|
|
6204
|
-
gl.bindTexture(gl.TEXTURE_2D, texture); // 绑定纹理对象
|
|
6205
|
-
|
|
6206
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // 放大处理方式
|
|
6207
|
-
|
|
6208
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // 缩小处理方式
|
|
6209
|
-
|
|
6210
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); // 水平平铺方式
|
|
6211
|
-
|
|
6212
|
-
gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); // 竖直平铺方式
|
|
6213
|
-
|
|
6214
|
-
return texture;
|
|
6215
|
-
} // 创建图片纹理
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
function createImgTexture(gl, img) {
|
|
6219
|
-
var texture = create2DTexture(gl);
|
|
6220
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); // 配置纹理图像
|
|
6221
|
-
|
|
6222
|
-
return {
|
|
6223
|
-
texture: texture
|
|
6224
|
-
};
|
|
6225
|
-
} // 用像素值来绘制纹理
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
function createDataTexture(gl, pixels) {
|
|
6229
|
-
var data = new Uint8Array(pixels.data || pixels);
|
|
6230
|
-
var texture = create2DTexture(gl);
|
|
6231
|
-
gl.texImage2D(gl.TEXTURE_2D, // 纹理目标
|
|
6232
|
-
0, // 细节级别,指定详细级别。0 级是基本图像等级,n 级是第 n 个金字塔简化级。
|
|
6233
|
-
gl.RGBA, // 纹理内部格式
|
|
6234
|
-
pixels.width || 1, // 指定纹理的宽度
|
|
6235
|
-
pixels.height || 1, // 指定纹理的高度
|
|
6236
|
-
0, // 指定纹理的边框宽度。必须为 0。
|
|
6237
|
-
gl.RGBA, // 源图像数据格式
|
|
6238
|
-
gl.UNSIGNED_BYTE, // 纹理数据类型
|
|
6239
|
-
data // 数据
|
|
6240
|
-
);
|
|
6241
|
-
return {
|
|
6242
|
-
texture: texture
|
|
6243
|
-
};
|
|
6244
|
-
} // 删除纹理
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
function deleteTexture(gl, texture) {
|
|
6248
|
-
return gl.deleteTexture(texture);
|
|
6249
|
-
}
|
|
6250
|
-
|
|
6251
|
-
},{}],20:[function(require,module,exports){
|
|
6252
|
-
"use strict";
|
|
6253
|
-
|
|
6254
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6255
|
-
value: true
|
|
6256
|
-
});
|
|
6257
|
-
exports["default"] = void 0;
|
|
6258
|
-
|
|
6259
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6260
|
-
|
|
6261
|
-
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); } }
|
|
6262
|
-
|
|
6263
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
6264
|
-
|
|
6265
|
-
var WebglGradientTextureCache = {}; // 渐变
|
|
6266
|
-
|
|
6267
|
-
var WeblGradient = /*#__PURE__*/function () {
|
|
6268
|
-
// type:[linear= 线性渐变,radial=放射性渐变]
|
|
6269
|
-
function WeblGradient() {
|
|
6270
|
-
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'linear';
|
|
6271
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6272
|
-
|
|
6273
|
-
_classCallCheck(this, WeblGradient);
|
|
6274
|
-
|
|
6275
|
-
this.type = type || 'linear';
|
|
6276
|
-
this.x1 = params.x1 || 0;
|
|
6277
|
-
this.y1 = params.y1 || 0;
|
|
6278
|
-
this.r1 = params.r1 || 0;
|
|
6279
|
-
this.x2 = params.x2 || 0;
|
|
6280
|
-
this.y2 = params.y2 || 0;
|
|
6281
|
-
this.r2 = params.r2 || 0;
|
|
6282
|
-
this.bounds = params.bounds || {
|
|
6283
|
-
left: 0,
|
|
6284
|
-
top: 0,
|
|
6285
|
-
width: 0,
|
|
6286
|
-
height: 0
|
|
6287
|
-
};
|
|
6288
|
-
this.control = params.control;
|
|
6289
|
-
this.stops = [];
|
|
6290
|
-
this.init();
|
|
6291
|
-
}
|
|
6292
|
-
|
|
6293
|
-
_createClass(WeblGradient, [{
|
|
6294
|
-
key: "init",
|
|
6295
|
-
value: function init() {
|
|
6296
|
-
var dx = this.x2 - this.x1;
|
|
6297
|
-
var dy = this.y2 - this.y1;
|
|
6298
|
-
|
|
6299
|
-
if (this.type === 'radial') {
|
|
6300
|
-
this.length = this.r2 - this.r1;
|
|
6301
|
-
} else if (dx === 0 && dy === 0) {
|
|
6302
|
-
this.length = 0;
|
|
6303
|
-
} else {
|
|
6304
|
-
// 渐变中心的距离
|
|
6305
|
-
this.length = Math.sqrt(Math.pow(dx, 2), Math.pow(dy, 2));
|
|
6306
|
-
this.sin = dy / this.length;
|
|
6307
|
-
this.cos = dx / this.length;
|
|
6308
|
-
}
|
|
6309
|
-
} // 渐变颜色
|
|
6310
|
-
|
|
6311
|
-
}, {
|
|
6312
|
-
key: "addColorStop",
|
|
6313
|
-
value: function addColorStop(offset, color) {
|
|
6314
|
-
this.stops.push({
|
|
6315
|
-
offset: offset,
|
|
6316
|
-
color: color
|
|
6317
|
-
});
|
|
6318
|
-
} // 转为渐变为纹理
|
|
6319
|
-
|
|
6320
|
-
}, {
|
|
6321
|
-
key: "toImageData",
|
|
6322
|
-
value: function toImageData(control, bounds) {
|
|
6323
|
-
var key = this.toString() + "-".concat(bounds.width.toFixed(4), "x").concat(bounds.height.toFixed(4));
|
|
6324
|
-
if (WebglGradientTextureCache[key]) return WebglGradientTextureCache[key];
|
|
6325
|
-
var canvas = control.graph.textureCanvas;
|
|
6326
|
-
|
|
6327
|
-
if (!canvas) {
|
|
6328
|
-
canvas = control.graph.textureCanvas = document.createElement('canvas');
|
|
6329
|
-
}
|
|
6330
|
-
|
|
6331
|
-
canvas.width = bounds.width;
|
|
6332
|
-
canvas.height = bounds.height;
|
|
6333
|
-
|
|
6334
|
-
if (!canvas.width || !canvas.height) {
|
|
6335
|
-
return null;
|
|
6336
|
-
}
|
|
6337
|
-
|
|
6338
|
-
var ctx = canvas.getContext('2d', {
|
|
6339
|
-
willReadFrequently: true
|
|
6340
|
-
});
|
|
6341
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
6342
|
-
var gradient = null;
|
|
6343
|
-
|
|
6344
|
-
if (this.type === 'linear') {
|
|
6345
|
-
gradient = ctx.createLinearGradient(this.x1, this.y1, this.x2, this.y2);
|
|
6346
|
-
} else {
|
|
6347
|
-
gradient = ctx.createRadialGradient(this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
|
|
6348
|
-
}
|
|
6349
|
-
|
|
6350
|
-
this.stops.forEach(function (s, i) {
|
|
6351
|
-
var c = control.graph.utils.toColor(s.color);
|
|
6352
|
-
gradient && gradient.addColorStop(s.offset, c);
|
|
6353
|
-
});
|
|
6354
|
-
ctx.fillStyle = gradient;
|
|
6355
|
-
ctx.beginPath();
|
|
6356
|
-
ctx.moveTo(0, 0);
|
|
6357
|
-
ctx.lineTo(bounds.width, 0);
|
|
6358
|
-
ctx.lineTo(bounds.width, bounds.height);
|
|
6359
|
-
ctx.lineTo(0, bounds.height);
|
|
6360
|
-
ctx.lineTo(0, 0);
|
|
6361
|
-
ctx.closePath();
|
|
6362
|
-
ctx.fill();
|
|
6363
|
-
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
6364
|
-
WebglGradientTextureCache[key] = data;
|
|
6365
|
-
return data;
|
|
6366
|
-
} // 根据绘制图形的坐标计算出对应点的颜色
|
|
6367
|
-
|
|
6368
|
-
/*
|
|
6369
|
-
toPointColors(points) {
|
|
6370
|
-
const stops = this.getStops();
|
|
6371
|
-
const colors = [];
|
|
6372
|
-
for(let i=0; i<points.length; i+=2) {
|
|
6373
|
-
const p = {
|
|
6374
|
-
x: points[i],
|
|
6375
|
-
y: points[i+1]
|
|
6376
|
-
}
|
|
6377
|
-
if(this.type === 'radial') {
|
|
6378
|
-
const dx = p.x - this.x1;
|
|
6379
|
-
const dy = p.y - this.y1;
|
|
6380
|
-
const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
6381
|
-
const rang = this.getStopRange(len, stops);
|
|
6382
|
-
if(!rang.start && rang.end) {
|
|
6383
|
-
colors.push(rang.end.color);
|
|
6384
|
-
}
|
|
6385
|
-
else if(!rang.end && rang.start) {
|
|
6386
|
-
colors.push(rang.start.color);
|
|
6387
|
-
}
|
|
6388
|
-
else {
|
|
6389
|
-
const rangLength = rang.end.length - rang.start.length;
|
|
6390
|
-
const offlen = len - rang.start.length;
|
|
6391
|
-
const per = offlen / rangLength;
|
|
6392
|
-
const color = {
|
|
6393
|
-
r: rang.start.color.r + (rang.end.color.r - rang.start.color.r) * per,
|
|
6394
|
-
g: rang.start.color.g + (rang.end.color.g - rang.start.color.g) * per,
|
|
6395
|
-
b: rang.start.color.b + (rang.end.color.b - rang.start.color.b) * per,
|
|
6396
|
-
a: rang.start.color.a + (rang.end.color.a - rang.start.color.a) * per,
|
|
6397
|
-
};
|
|
6398
|
-
colors.push(color);
|
|
6399
|
-
}
|
|
6400
|
-
}
|
|
6401
|
-
}
|
|
6402
|
-
return colors;
|
|
6403
|
-
}
|
|
6404
|
-
*/
|
|
6405
|
-
// 根据起点距离获取边界stop
|
|
6406
|
-
|
|
6407
|
-
/*
|
|
6408
|
-
getStopRange(len, stops) {
|
|
6409
|
-
const res = {};
|
|
6410
|
-
for(const s of stops) {
|
|
6411
|
-
if(s.length <= len) {
|
|
6412
|
-
res.start = s;
|
|
6413
|
-
}
|
|
6414
|
-
else {
|
|
6415
|
-
res.end = s;
|
|
6416
|
-
}
|
|
6417
|
-
}
|
|
6418
|
-
return res;
|
|
6419
|
-
}
|
|
6420
|
-
// 根据stop计算offset长度
|
|
6421
|
-
getStops() {
|
|
6422
|
-
const stops = this.stops.sort((p1, p2) => p1.offset - p2.offset); // 渐变色排序从小于大
|
|
6423
|
-
for(const s of stops) {
|
|
6424
|
-
|
|
6425
|
-
const color = typeof s.color === 'string'? this.control.graph.utils.hexToRGBA(s.color) : s.color;
|
|
6426
|
-
console.log(s, color);
|
|
6427
|
-
s.color = this.control.graph.utils.rgbToDecimal(color);
|
|
6428
|
-
s.length = s.offset * this.length;
|
|
6429
|
-
}
|
|
6430
|
-
return stops;
|
|
6431
|
-
}
|
|
6432
|
-
*/
|
|
6433
|
-
|
|
6434
|
-
/**
|
|
6435
|
-
* 转换为渐变的字符串表达
|
|
6436
|
-
*
|
|
6437
|
-
* @method toString
|
|
6438
|
-
* @for jmGradient
|
|
6439
|
-
* @return {string} linear-gradient(x1 y1 x2 y2, color1 step, color2 step, ...); //radial-gradient(x1 y1 r1 x2 y2 r2, color1 step,color2 step, ...);
|
|
6440
|
-
*/
|
|
6441
|
-
|
|
6442
|
-
}, {
|
|
6443
|
-
key: "toString",
|
|
6444
|
-
value: function toString() {
|
|
6445
|
-
var str = this.type + '-gradient(';
|
|
6446
|
-
|
|
6447
|
-
if (this.type == 'linear') {
|
|
6448
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
6449
|
-
} else {
|
|
6450
|
-
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
6451
|
-
} //颜色渐变
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
this.stops.forEach(function (s) {
|
|
6455
|
-
str += ',' + s.color + ' ' + s.offset;
|
|
6456
|
-
});
|
|
6457
|
-
return str + ')';
|
|
6458
|
-
}
|
|
6459
|
-
}]);
|
|
6460
|
-
|
|
6461
|
-
return WeblGradient;
|
|
6462
|
-
}();
|
|
6463
|
-
|
|
6464
|
-
var _default = WeblGradient;
|
|
6465
|
-
exports["default"] = _default;
|
|
6466
|
-
|
|
6467
|
-
},{}],21:[function(require,module,exports){
|
|
6468
|
-
"use strict";
|
|
6469
|
-
|
|
6470
|
-
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); }
|
|
6471
|
-
|
|
6472
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6473
|
-
value: true
|
|
6474
|
-
});
|
|
6475
|
-
exports["default"] = void 0;
|
|
6476
|
-
|
|
6477
|
-
var _base = _interopRequireDefault(require("./base.js"));
|
|
6478
|
-
|
|
6479
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
6480
|
-
|
|
6481
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6482
|
-
|
|
6483
|
-
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."); }
|
|
6484
|
-
|
|
6485
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6486
|
-
|
|
6487
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6488
|
-
|
|
6489
|
-
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; } } }; }
|
|
6490
|
-
|
|
6491
|
-
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); }
|
|
6492
|
-
|
|
6493
|
-
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; }
|
|
6494
|
-
|
|
6495
|
-
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; }
|
|
6496
|
-
|
|
6497
|
-
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; }
|
|
6498
|
-
|
|
6499
|
-
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; }
|
|
6500
|
-
|
|
6501
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6502
|
-
|
|
6503
|
-
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); } }
|
|
6504
|
-
|
|
6505
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
6506
|
-
|
|
6507
|
-
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); }
|
|
6508
|
-
|
|
6509
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
6510
|
-
|
|
6511
|
-
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); }; }
|
|
6512
|
-
|
|
6513
|
-
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); }
|
|
6514
|
-
|
|
6515
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
6516
|
-
|
|
6517
|
-
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; } }
|
|
6518
|
-
|
|
6519
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
6520
|
-
|
|
6521
|
-
// 把canvas坐标转为webgl坐标系
|
|
6522
|
-
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坐标转为纹理的坐标系
|
|
6523
|
-
|
|
6524
|
-
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顶点着色器源码
|
|
6525
|
-
|
|
6526
|
-
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 片段着色器源码
|
|
6527
|
-
|
|
6528
|
-
var pathFragmentSource = "\n precision highp 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"); // path 绘制类
|
|
6529
|
-
|
|
6530
|
-
var WebglPath = /*#__PURE__*/function (_WebglBase) {
|
|
6531
|
-
_inherits(WebglPath, _WebglBase);
|
|
6532
|
-
|
|
6533
|
-
var _super = _createSuper(WebglPath);
|
|
6534
|
-
|
|
6535
|
-
function WebglPath(graph, option) {
|
|
6536
|
-
var _this;
|
|
6537
|
-
|
|
6538
|
-
_classCallCheck(this, WebglPath);
|
|
6539
|
-
|
|
6540
|
-
_this = _super.call(this, graph, option); // 是否是规则的,不规则的处理方式更为复杂和耗性能
|
|
6541
|
-
|
|
6542
|
-
_this.isRegular = option.isRegular || false;
|
|
6543
|
-
_this.needCut = option.needCut || false;
|
|
6544
|
-
_this.points = [];
|
|
6545
|
-
return _this;
|
|
6546
|
-
} // i当前程序
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
_createClass(WebglPath, [{
|
|
6550
|
-
key: "program",
|
|
6551
|
-
get: function get() {
|
|
6552
|
-
// 默认所有path用同一个编译好的program
|
|
6553
|
-
return this.graph.context.pathProgram || (this.graph.context.pathProgram = this.createProgram(pathVertexSource, pathFragmentSource));
|
|
6554
|
-
} // 设置样式
|
|
6555
|
-
|
|
6556
|
-
}, {
|
|
6557
|
-
key: "setStyle",
|
|
6558
|
-
value: function setStyle() {
|
|
6559
|
-
var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.style;
|
|
6560
|
-
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
6561
|
-
this.useProgram();
|
|
6562
|
-
|
|
6563
|
-
if (typeof style === 'string') {
|
|
6564
|
-
var obj = {};
|
|
6565
|
-
obj[style] = value;
|
|
6566
|
-
style = obj;
|
|
6567
|
-
} // 设置线条颜色或填充色
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
if (style.strokeStyle) {
|
|
6571
|
-
var color = style.strokeStyle;
|
|
6572
|
-
if (typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
|
|
6573
|
-
this.style.strokeStyle = this.graph.utils.rgbToDecimal(color);
|
|
6574
|
-
delete style.strokeStyle;
|
|
6575
|
-
} else if (style.fillStyle) {
|
|
6576
|
-
var _color = style.fillStyle;
|
|
6577
|
-
|
|
6578
|
-
if (this.isGradient(_color)) {
|
|
6579
|
-
this.style.fillStyle = _color;
|
|
6580
|
-
} else {
|
|
6581
|
-
if (typeof _color === 'string') _color = this.graph.utils.hexToRGBA(_color);
|
|
6582
|
-
this.style.fillStyle = this.graph.utils.rgbToDecimal(_color);
|
|
6583
|
-
}
|
|
6584
|
-
|
|
6585
|
-
delete style.fillStyle;
|
|
6586
|
-
}
|
|
6587
|
-
|
|
6588
|
-
this.style = _objectSpread(_objectSpread({}, this.style), style);
|
|
6589
|
-
}
|
|
6590
|
-
}, {
|
|
6591
|
-
key: "setParentBounds",
|
|
6592
|
-
value: function setParentBounds() {
|
|
6593
|
-
var parentBounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.parentAbsoluteBounds;
|
|
6594
|
-
//this.useProgram();
|
|
6595
|
-
if (parentBounds) this.parentAbsoluteBounds = parentBounds; // 写入当前canvas大小
|
|
6596
|
-
|
|
6597
|
-
this.context.uniform2f(this.program.uniforms.a_center_point.location, this.graph.width / 2, this.graph.height / 2);
|
|
6598
|
-
}
|
|
6599
|
-
}, {
|
|
6600
|
-
key: "setFragColor",
|
|
6601
|
-
value: function setFragColor(color) {
|
|
6602
|
-
if (!Array.isArray(color)) {
|
|
6603
|
-
if (typeof color === 'string') color = this.graph.utils.hexToRGBA(color);
|
|
6604
|
-
if (typeof color.a === 'undefined') color.a = 1;
|
|
6605
|
-
this.context.uniform4f(this.program.uniforms.v_single_color.location, color.r, color.g, color.b, color.a * this.style.globalAlpha);
|
|
6606
|
-
return null;
|
|
6607
|
-
}
|
|
6608
|
-
|
|
6609
|
-
var colorData = [];
|
|
6610
|
-
|
|
6611
|
-
var _iterator = _createForOfIteratorHelper(color),
|
|
6612
|
-
_step;
|
|
6613
|
-
|
|
6614
|
-
try {
|
|
6615
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
6616
|
-
var c = _step.value;
|
|
6617
|
-
if (typeof c === 'string') c = this.graph.utils.hexToRGBA(c);
|
|
6618
|
-
if (typeof c.a === 'undefined') c.a = 1;
|
|
6619
|
-
colorData.push(c.r, c.g, c.b, c.a * this.style.globalAlpha);
|
|
6620
|
-
}
|
|
6621
|
-
} catch (err) {
|
|
6622
|
-
_iterator.e(err);
|
|
6623
|
-
} finally {
|
|
6624
|
-
_iterator.f();
|
|
6625
|
-
}
|
|
6626
|
-
|
|
6627
|
-
var colorBuffer = this.createFloat32Buffer(colorData);
|
|
6628
|
-
this.writeVertexAttrib(colorBuffer, this.program.attrs.a_color, 4, 0, 0);
|
|
6629
|
-
colorBuffer.attr = this.program.attrs.a_color;
|
|
6630
|
-
return colorBuffer;
|
|
6631
|
-
}
|
|
6632
|
-
}, {
|
|
6633
|
-
key: "beginDraw",
|
|
6634
|
-
value: function beginDraw() {
|
|
6635
|
-
this.useProgram();
|
|
6636
|
-
} // 开始绘制
|
|
6637
|
-
|
|
6638
|
-
}, {
|
|
6639
|
-
key: "draw",
|
|
6640
|
-
value: function draw(points) {
|
|
6641
|
-
var parentBounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.parentAbsoluteBounds;
|
|
6642
|
-
//this.useProgram();
|
|
6643
|
-
this.setParentBounds(parentBounds);
|
|
6644
|
-
this.points = points;
|
|
6645
|
-
}
|
|
6646
|
-
}, {
|
|
6647
|
-
key: "endDraw",
|
|
6648
|
-
value: function endDraw() {
|
|
6649
|
-
if (this.points) delete this.points;
|
|
6650
|
-
if (this.pathPoints) delete this.pathPoints;
|
|
6651
|
-
} // 图形封闭
|
|
6652
|
-
|
|
6653
|
-
}, {
|
|
6654
|
-
key: "closePath",
|
|
6655
|
-
value: function closePath() {
|
|
6656
|
-
if (this.points && this.points.length > 2 && this.points[0] !== this.points[this.points.length - 1]) {
|
|
6657
|
-
var start = this.points[0];
|
|
6658
|
-
var end = this.points[this.points.length - 1];
|
|
6659
|
-
if (start != end && !(start.x === end.x && start.y === end.y)) this.points.push(start);
|
|
6660
|
-
}
|
|
6661
|
-
} // 绘制点数组
|
|
6662
|
-
|
|
6663
|
-
}, {
|
|
6664
|
-
key: "writePoints",
|
|
6665
|
-
value: function writePoints(points) {
|
|
6666
|
-
var attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.program.attrs.a_position;
|
|
6667
|
-
var fixedPoints = [];
|
|
6668
|
-
|
|
6669
|
-
var _iterator2 = _createForOfIteratorHelper(points),
|
|
6670
|
-
_step2;
|
|
6671
|
-
|
|
6672
|
-
try {
|
|
6673
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
6674
|
-
var p = _step2.value;
|
|
6675
|
-
fixedPoints.push(p.x + this.parentAbsoluteBounds.left, p.y + this.parentAbsoluteBounds.top);
|
|
6676
|
-
}
|
|
6677
|
-
} catch (err) {
|
|
6678
|
-
_iterator2.e(err);
|
|
6679
|
-
} finally {
|
|
6680
|
-
_iterator2.f();
|
|
6681
|
-
}
|
|
6682
|
-
|
|
6683
|
-
var vertexBuffer = this.createFloat32Buffer(fixedPoints);
|
|
6684
|
-
this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
|
|
6685
|
-
vertexBuffer.attr = attr;
|
|
6686
|
-
return vertexBuffer;
|
|
6687
|
-
} // 连接二个点
|
|
6688
|
-
|
|
6689
|
-
}, {
|
|
6690
|
-
key: "genLinePoints",
|
|
6691
|
-
value: function genLinePoints(start, end) {
|
|
6692
|
-
var points = [start];
|
|
6693
|
-
var dx = end.x - start.x;
|
|
6694
|
-
var dy = end.y - start.y;
|
|
6695
|
-
|
|
6696
|
-
if (dx !== 0 || dy !== 0) {
|
|
6697
|
-
var len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
6698
|
-
var cos = dx / len;
|
|
6699
|
-
var sin = dy / len;
|
|
6700
|
-
var step = 0.5;
|
|
6701
|
-
|
|
6702
|
-
for (var l = step; l < len; l += step) {
|
|
6703
|
-
var x = start.x + cos * l;
|
|
6704
|
-
var y = start.y + sin * l;
|
|
6705
|
-
points.push({
|
|
6706
|
-
x: Number(x.toFixed(2)),
|
|
6707
|
-
y: Number(y.toFixed(2))
|
|
6708
|
-
});
|
|
6709
|
-
}
|
|
6710
|
-
}
|
|
6711
|
-
|
|
6712
|
-
points.push(end);
|
|
6713
|
-
return points;
|
|
6714
|
-
} // 把path坐标集合分解成一个个点,并且处理moveTo线段能力
|
|
6715
|
-
|
|
6716
|
-
}, {
|
|
6717
|
-
key: "pathToPoints",
|
|
6718
|
-
value: function pathToPoints() {
|
|
6719
|
-
var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.points;
|
|
6720
|
-
var start = null;
|
|
6721
|
-
var res = [];
|
|
6722
|
-
|
|
6723
|
-
for (var i = 0; i < points.length; i++) {
|
|
6724
|
-
var p = points[i];
|
|
6725
|
-
|
|
6726
|
-
if (start && !p.m) {
|
|
6727
|
-
var linePoints = this.genLinePoints(start, p);
|
|
6728
|
-
res.push.apply(res, _toConsumableArray(linePoints));
|
|
6729
|
-
} else if (start && !res.includes(start)) {
|
|
6730
|
-
res.push(start);
|
|
6731
|
-
}
|
|
6732
|
-
|
|
6733
|
-
start = p;
|
|
6734
|
-
}
|
|
6735
|
-
|
|
6736
|
-
if (!res.includes(start)) res.push(start);
|
|
6737
|
-
return res;
|
|
6738
|
-
} // 二点是否重合
|
|
6739
|
-
|
|
6740
|
-
}, {
|
|
6741
|
-
key: "equalPoint",
|
|
6742
|
-
value: function equalPoint(p1, p2) {
|
|
6743
|
-
return p1.x === p2.x && p1.y === p2.y;
|
|
6744
|
-
} // 把path坐标集合转为线段集
|
|
6745
|
-
|
|
6746
|
-
}, {
|
|
6747
|
-
key: "pathToLines",
|
|
6748
|
-
value: function pathToLines(points) {
|
|
6749
|
-
var start = null;
|
|
6750
|
-
var res = [];
|
|
6751
|
-
|
|
6752
|
-
for (var i = 0; i < points.length; i++) {
|
|
6753
|
-
var p = points[i]; // 不重合的二个点,组成线段
|
|
6754
|
-
|
|
6755
|
-
if (start && !p.m && !(start.x == p.x && start.y == p.y)) {
|
|
6756
|
-
var line = {
|
|
6757
|
-
start: start,
|
|
6758
|
-
end: p
|
|
6759
|
-
};
|
|
6760
|
-
res.push(line);
|
|
6761
|
-
}
|
|
6762
|
-
|
|
6763
|
-
start = p;
|
|
6764
|
-
}
|
|
6765
|
-
|
|
6766
|
-
return res;
|
|
6767
|
-
} // 裁剪线段,如果二段线段有交点,则分割成四段, 端头相交的线段不用分割
|
|
6768
|
-
|
|
6769
|
-
}, {
|
|
6770
|
-
key: "cutLines",
|
|
6771
|
-
value: function cutLines(lines) {
|
|
6772
|
-
var index1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
6773
|
-
var index2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
6774
|
-
if (lines && lines.length < 3) return lines;
|
|
6775
|
-
index2 = Math.max(index1 + 1, index2); //如果指定了比下一个更大的索引,则用更大的,说明前面的已经处理过了,不需要重复
|
|
6776
|
-
// 找出线段相交的点,并切割线段
|
|
6777
|
-
|
|
6778
|
-
while (index1 < lines.length) {
|
|
6779
|
-
var line1 = lines[index1];
|
|
6780
|
-
|
|
6781
|
-
while (index2 < lines.length) {
|
|
6782
|
-
var line2 = lines[index2]; // 如果二条线顶点有重合,则不用处理
|
|
6783
|
-
|
|
6784
|
-
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)) {
|
|
6785
|
-
index2++;
|
|
6786
|
-
continue;
|
|
6787
|
-
}
|
|
6788
|
-
|
|
6789
|
-
var cuted = false;
|
|
6790
|
-
var intersection = this.getIntersection(line1, line2); // 计算交点
|
|
6791
|
-
|
|
6792
|
-
if (intersection) {
|
|
6793
|
-
// 如果交点不是线段的端点,则分割成二条线段
|
|
6794
|
-
if (!this.equalPoint(line1.start, intersection) && !this.equalPoint(line1.end, intersection)) {
|
|
6795
|
-
var sub1 = {
|
|
6796
|
-
start: line1.start,
|
|
6797
|
-
end: intersection
|
|
6798
|
-
};
|
|
6799
|
-
var sub2 = {
|
|
6800
|
-
start: intersection,
|
|
6801
|
-
end: line1.end
|
|
6802
|
-
}; // 从原数组中删除当前线段,替换成新的线段
|
|
6803
|
-
|
|
6804
|
-
lines.splice(index1, 1, sub1, sub2); // 当前线段被重新替换,需要重新从它开始处理
|
|
6805
|
-
|
|
6806
|
-
cuted = true;
|
|
6807
|
-
index2++; // 因为多加入了一个线段,则对比线索引需要加1
|
|
6808
|
-
} // 如果交点不是线段的端点,则分割成二条线段
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
if (!this.equalPoint(line2.start, intersection) && !this.equalPoint(line2.end, intersection)) {
|
|
6812
|
-
var _sub = {
|
|
6813
|
-
start: line2.start,
|
|
6814
|
-
end: intersection
|
|
6815
|
-
};
|
|
6816
|
-
var _sub2 = {
|
|
6817
|
-
start: intersection,
|
|
6818
|
-
end: line2.end
|
|
6819
|
-
}; // 从原数组中删除当前线段,替换成新的线段
|
|
6820
|
-
|
|
6821
|
-
lines.splice(index2, 1, _sub, _sub2);
|
|
6822
|
-
index2++; // 线段2也切成了二段,对比索引要继续加1
|
|
6823
|
-
}
|
|
6824
|
-
}
|
|
6825
|
-
|
|
6826
|
-
index2++; // 如果已经分割了起始线段,则第一个子线段开始,重新对比后面还未对比完的。直接所有对比完成返回
|
|
6827
|
-
|
|
6828
|
-
if (cuted) return this.cutLines(lines, index1, index2);
|
|
6829
|
-
}
|
|
6830
|
-
|
|
6831
|
-
index1++;
|
|
6832
|
-
index2 = index1 + 1;
|
|
6833
|
-
}
|
|
6834
|
-
|
|
6835
|
-
return lines;
|
|
6836
|
-
} // 计算二个线段的交点
|
|
6837
|
-
|
|
6838
|
-
}, {
|
|
6839
|
-
key: "getIntersection",
|
|
6840
|
-
value: function getIntersection(line1, line2) {
|
|
6841
|
-
// 如果首尾相接,也认为是有交点
|
|
6842
|
-
if (this.equalPoint(line1.start, line2.start) || this.equalPoint(line1.start, line2.end)) return line1.start;
|
|
6843
|
-
if (this.equalPoint(line1.end, line2.start) || this.equalPoint(line1.end, line2.end)) return line1.end; // 三角形abc 面积的2倍
|
|
6844
|
-
|
|
6845
|
-
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倍
|
|
6846
|
-
|
|
6847
|
-
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表示在线段顶点上);
|
|
6848
|
-
|
|
6849
|
-
if (area_abc * area_abd > 0) {
|
|
6850
|
-
return null;
|
|
6851
|
-
} // 三角形cda 面积的2倍
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
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倍
|
|
6855
|
-
// 注意: 这里有一个小优化.不需要再用公式计算面积,而是通过已知的三个面积加减得出.
|
|
6856
|
-
|
|
6857
|
-
var area_cdb = area_cda + area_abc - area_abd;
|
|
6858
|
-
|
|
6859
|
-
if (area_cda * area_cdb > 0) {
|
|
6860
|
-
return null;
|
|
6861
|
-
}
|
|
6862
|
-
|
|
6863
|
-
if (area_abd === area_abc) return null; //计算交点坐标
|
|
6864
|
-
|
|
6865
|
-
var t = area_cda / (area_abd - area_abc);
|
|
6866
|
-
var dx = t * (line1.end.x - line1.start.x);
|
|
6867
|
-
var dy = t * (line1.end.y - line1.start.y);
|
|
6868
|
-
return {
|
|
6869
|
-
x: Number((line1.start.x + dx).toFixed(2)),
|
|
6870
|
-
y: Number((line1.start.y + dy).toFixed(2))
|
|
6871
|
-
};
|
|
6872
|
-
} // 找出跟当前线段尾部相交的所有线段
|
|
6873
|
-
|
|
6874
|
-
}, {
|
|
6875
|
-
key: "getIntersectionLines",
|
|
6876
|
-
value: function getIntersectionLines(line, lines, index) {
|
|
6877
|
-
var point = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : line.end;
|
|
6878
|
-
var points = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
6879
|
-
var root = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
|
|
6880
|
-
var res = {
|
|
6881
|
-
line: line,
|
|
6882
|
-
polygons: []
|
|
6883
|
-
};
|
|
6884
|
-
points.push(point);
|
|
6885
|
-
|
|
6886
|
-
if (root && this.equalPoint(root.line.start, point)) {
|
|
6887
|
-
points.unshift(root.line.start); // 把起始地址加入进去
|
|
6888
|
-
|
|
6889
|
-
root.polygons.push(points);
|
|
6890
|
-
return res;
|
|
6891
|
-
}
|
|
6892
|
-
|
|
6893
|
-
for (; index < lines.length; index++) {
|
|
6894
|
-
var l = lines[index];
|
|
6895
|
-
|
|
6896
|
-
if (this.equalPoint(point, l.start)) {
|
|
6897
|
-
if (points.includes(l.end)) continue;
|
|
6898
|
-
this.getIntersectionLines(l, lines, index + 1, l.end, _toConsumableArray(points), root || res);
|
|
6899
|
-
} else if (this.equalPoint(point, l.end)) {
|
|
6900
|
-
if (points.includes(l.start)) continue;
|
|
6901
|
-
this.getIntersectionLines(l, lines, index + 1, l.start, _toConsumableArray(points), root || res);
|
|
6902
|
-
}
|
|
6903
|
-
}
|
|
6904
|
-
|
|
6905
|
-
return res;
|
|
6906
|
-
} // 根据路径点坐标,切割出封闭的多边形
|
|
6907
|
-
|
|
6908
|
-
}, {
|
|
6909
|
-
key: "getPolygon",
|
|
6910
|
-
value: function getPolygon(points) {
|
|
6911
|
-
var polygons = [];
|
|
6912
|
-
var lines = this.pathToLines(points); // 分解得到线段
|
|
6913
|
-
|
|
6914
|
-
if (lines && lines.length > 2) {
|
|
6915
|
-
lines = this.cutLines(lines); // 把所有相交点切割线段找出来
|
|
6916
|
-
|
|
6917
|
-
for (var i = 0; i < lines.length - 1; i++) {
|
|
6918
|
-
var line1 = lines[i];
|
|
6919
|
-
var polygon = []; // 当前图形
|
|
6920
|
-
|
|
6921
|
-
var treeLine = this.getIntersectionLines(line1, lines, i + 1);
|
|
6922
|
-
if (treeLine.polygons.length) polygons.push.apply(polygons, _toConsumableArray(treeLine.polygons));
|
|
6923
|
-
continue;
|
|
6924
|
-
var lastLine = line1; // 下一个还在连接状态的线
|
|
6925
|
-
|
|
6926
|
-
for (var j = i + 1; j < lines.length; j++) {
|
|
6927
|
-
var line2 = lines[j]; // 如果跟下一条线相接,则表示还在形成图形中
|
|
6928
|
-
|
|
6929
|
-
if (this.equalPoint(lastLine.end, line2.start)) {
|
|
6930
|
-
polygon.push(lastLine.end);
|
|
6931
|
-
lastLine = line2;
|
|
6932
|
-
if (i === j + 1) continue; //下一条相连 则不需要处理相交情况
|
|
6933
|
-
} else {
|
|
6934
|
-
polygon = [];
|
|
6935
|
-
} // 因为前面进行了分割线段,则里只有处理端点相连的情况
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
var intersection = this.equalPoint(line1.start, line2.end) ? line1.start : null; //this.getIntersection(line1, line2);// 计算交点
|
|
6939
|
-
|
|
6940
|
-
if (intersection) {
|
|
6941
|
-
polygon.push(intersection); // 交叉点为图形顶点
|
|
6942
|
-
// 如果上一个连接线不是当前交叉线,则表示重新开始闭合
|
|
6943
|
-
// 如果上一个连接线是当前交叉线,形成了封闭的图形
|
|
6944
|
-
|
|
6945
|
-
if (lastLine === line2 && polygon.length > 1) {
|
|
6946
|
-
polygons.push(polygon); // 封闭后,下一个起始线条就是从交点开始计算起
|
|
6947
|
-
|
|
6948
|
-
/*lastLine = {
|
|
6949
|
-
start: intersection,
|
|
6950
|
-
end: line2.end
|
|
6951
|
-
};*/
|
|
6952
|
-
|
|
6953
|
-
polygon = []; // 重新开始新一轮找图形
|
|
6954
|
-
|
|
6955
|
-
/*
|
|
6956
|
-
// 如果交点是上一条线的终点,则新图形为空
|
|
6957
|
-
if(this.equalPoint(line2.end, intersection)) {
|
|
6958
|
-
polygon = [];// 重新开始新一轮找图形
|
|
6959
|
-
}
|
|
6960
|
-
else {
|
|
6961
|
-
// 同时交点也要加到上一个图形中第一个点,形成封闭
|
|
6962
|
-
polygon.unshift(intersection);
|
|
6963
|
-
polygon = [ intersection ];// 重新开始新一轮找图形
|
|
6964
|
-
}*/
|
|
6965
|
-
} else {
|
|
6966
|
-
lastLine = line2;
|
|
6967
|
-
}
|
|
6968
|
-
}
|
|
6969
|
-
}
|
|
6970
|
-
}
|
|
6971
|
-
} // 当有多个封闭图形时,再弟归一下,里面是不是有封闭图形内还有子封闭图形
|
|
6972
|
-
|
|
6973
|
-
/*if(polygons.length > 1) {
|
|
6974
|
-
const newPolygons = [];
|
|
6975
|
-
for(const polygon of polygons) {
|
|
6976
|
-
// 只有大于4才有可能有子封闭图形
|
|
6977
|
-
if(polygon.length > 4) {
|
|
6978
|
-
const childPolygons = this.getPolygon(polygon);
|
|
6979
|
-
// 当有多个子图形时,表示它不是最终封闭图形,跳过,
|
|
6980
|
-
// 因为它的子图形之前有加入的,不需要重复加入
|
|
6981
|
-
if(childPolygons.length > 1) {
|
|
6982
|
-
//newPolygons.push(...childPolygons);
|
|
6983
|
-
continue;
|
|
6984
|
-
}
|
|
6985
|
-
}
|
|
6986
|
-
newPolygons.push(polygon);
|
|
6987
|
-
}
|
|
6988
|
-
polygons = newPolygons;
|
|
6989
|
-
}*/
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
return polygons;
|
|
6993
|
-
} // 画线条
|
|
6994
|
-
|
|
6995
|
-
}, {
|
|
6996
|
-
key: "stroke",
|
|
6997
|
-
value: function stroke() {
|
|
6998
|
-
var points = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.points;
|
|
6999
|
-
var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.style.strokeStyle;
|
|
7000
|
-
var lineWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.style.lineWidth;
|
|
7001
|
-
if (!points || !points.length) return; // this.useProgram();
|
|
7002
|
-
|
|
7003
|
-
var colorBuffer = null;
|
|
7004
|
-
|
|
7005
|
-
if (color) {
|
|
7006
|
-
colorBuffer = this.setFragColor(color);
|
|
7007
|
-
} // 线宽
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
if (lineWidth) {
|
|
7011
|
-
this.context.uniform1f(this.program.uniforms.a_point_size.location, lineWidth); // * this.graph.devicePixelRatio
|
|
7012
|
-
} // 标注为stroke
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
if (this.program.uniforms.a_type) {
|
|
7016
|
-
// 4表示单画一个圆点,1表示方块形成的线条
|
|
7017
|
-
this.context.uniform1i(this.program.uniforms.a_type.location, points.length === 1 ? 4 : 1);
|
|
7018
|
-
}
|
|
7019
|
-
|
|
7020
|
-
if (points && points.length) {
|
|
7021
|
-
var regular = this.isRegular && lineWidth == 1;
|
|
7022
|
-
points = regular ? points : this.pathToPoints(points); //this.context.lineWidth(10);
|
|
7023
|
-
|
|
7024
|
-
var buffer = this.writePoints(points);
|
|
7025
|
-
this.context.drawArrays(regular ? this.context.LINES : this.context.POINTS, 0, points.length);
|
|
7026
|
-
this.deleteBuffer(buffer);
|
|
7027
|
-
}
|
|
7028
|
-
|
|
7029
|
-
colorBuffer && this.deleteBuffer(colorBuffer);
|
|
7030
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
7031
|
-
} // 填充图形
|
|
7032
|
-
|
|
7033
|
-
}, {
|
|
7034
|
-
key: "fill",
|
|
7035
|
-
value: function fill() {
|
|
7036
|
-
var bounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
7037
|
-
left: 0,
|
|
7038
|
-
top: 0,
|
|
7039
|
-
width: 0,
|
|
7040
|
-
height: 0
|
|
7041
|
-
};
|
|
7042
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
7043
|
-
|
|
7044
|
-
//this.useProgram();
|
|
7045
|
-
if (this.points && this.points.length) {
|
|
7046
|
-
// 如果是颜色rgba
|
|
7047
|
-
if (this.style.fillStyle) {
|
|
7048
|
-
var filled = false; // 是否成功填充
|
|
7049
|
-
// 3个以上的点,且非规则图形才需要切割
|
|
7050
|
-
|
|
7051
|
-
if (this.points.length > 3) {
|
|
7052
|
-
if (this.isRegular && this.needCut) {
|
|
7053
|
-
// 需要分割三角形,不然填充会有问题
|
|
7054
|
-
var triangles = this.earCutPointsToTriangles(this.points); // 切割得到三角形顶点二维数组
|
|
7055
|
-
|
|
7056
|
-
if (triangles && triangles.length) {
|
|
7057
|
-
var _iterator3 = _createForOfIteratorHelper(triangles),
|
|
7058
|
-
_step3;
|
|
7059
|
-
|
|
7060
|
-
try {
|
|
7061
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
7062
|
-
var triangle = _step3.value;
|
|
7063
|
-
this.fillColor(triangle, this.style.fillStyle, bounds, type); // 单独为每个分割的图形填充
|
|
7064
|
-
// 如果指定的是img,则采用填充图片的方式
|
|
7065
|
-
|
|
7066
|
-
if (this.style.fillImage) {
|
|
7067
|
-
this.fillImage(this.style.fillImage, triangle, bounds);
|
|
7068
|
-
}
|
|
7069
|
-
}
|
|
7070
|
-
} catch (err) {
|
|
7071
|
-
_iterator3.e(err);
|
|
7072
|
-
} finally {
|
|
7073
|
-
_iterator3.f();
|
|
7074
|
-
}
|
|
7075
|
-
|
|
7076
|
-
filled = true; // 表示已填充过了
|
|
7077
|
-
}
|
|
7078
|
-
} else if (!this.isRegular) {
|
|
7079
|
-
var polygons = this.getPolygon(this.points);
|
|
7080
|
-
|
|
7081
|
-
if (polygons.length) {
|
|
7082
|
-
var _iterator4 = _createForOfIteratorHelper(polygons),
|
|
7083
|
-
_step4;
|
|
7084
|
-
|
|
7085
|
-
try {
|
|
7086
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
7087
|
-
var polygon = _step4.value;
|
|
7088
|
-
|
|
7089
|
-
// 需要分割三角形,不然填充会有问题
|
|
7090
|
-
var _triangles = this.earCutPointsToTriangles(polygon); // 切割得到三角形顶点二维数组
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
if (_triangles && _triangles.length) {
|
|
7094
|
-
var _iterator5 = _createForOfIteratorHelper(_triangles),
|
|
7095
|
-
_step5;
|
|
7096
|
-
|
|
7097
|
-
try {
|
|
7098
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
7099
|
-
var _triangle = _step5.value;
|
|
7100
|
-
this.fillColor(_triangle, this.style.fillStyle, bounds, type); // 单独为每个分割的图形填充
|
|
7101
|
-
// 如果指定的是img,则采用填充图片的方式
|
|
7102
|
-
|
|
7103
|
-
if (this.style.fillImage) {
|
|
7104
|
-
this.fillImage(this.style.fillImage, _triangle, bounds);
|
|
7105
|
-
}
|
|
7106
|
-
}
|
|
7107
|
-
} catch (err) {
|
|
7108
|
-
_iterator5.e(err);
|
|
7109
|
-
} finally {
|
|
7110
|
-
_iterator5.f();
|
|
7111
|
-
}
|
|
7112
|
-
|
|
7113
|
-
filled = true; // 表示已填充过了
|
|
7114
|
-
}
|
|
7115
|
-
}
|
|
7116
|
-
} catch (err) {
|
|
7117
|
-
_iterator4.e(err);
|
|
7118
|
-
} finally {
|
|
7119
|
-
_iterator4.f();
|
|
7120
|
-
}
|
|
7121
|
-
}
|
|
7122
|
-
}
|
|
7123
|
-
} // 如果前面的条件没有填充成功,则直接按正常填充
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
if (!filled) {
|
|
7127
|
-
this.fillColor(this.points, this.style.fillStyle, bounds, type); // 如果指定的是img,则采用填充图片的方式
|
|
7128
|
-
|
|
7129
|
-
if (this.style.fillImage) {
|
|
7130
|
-
this.fillImage(this.style.fillImage, this.points, bounds);
|
|
7131
|
-
}
|
|
7132
|
-
}
|
|
7133
|
-
}
|
|
7134
|
-
}
|
|
7135
|
-
}
|
|
7136
|
-
}, {
|
|
7137
|
-
key: "fillColor",
|
|
7138
|
-
value: function fillColor(points, color, bounds) {
|
|
7139
|
-
var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
7140
|
-
|
|
7141
|
-
// 如果是渐变色,则需要计算偏移量的颜色
|
|
7142
|
-
if (this.isGradient(color)) {
|
|
7143
|
-
var imgData = color.toImageData(this, bounds);
|
|
7144
|
-
return this.fillImage(imgData, points, bounds);
|
|
7145
|
-
} // 标注为fill
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
this.context.uniform1i(this.program.uniforms.a_type.location, type);
|
|
7149
|
-
var colorBuffer = this.setFragColor(color);
|
|
7150
|
-
var buffer = this.writePoints(points);
|
|
7151
|
-
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
7152
|
-
|
|
7153
|
-
if (buffer) {
|
|
7154
|
-
this.deleteBuffer(buffer);
|
|
7155
|
-
this.disableVertexAttribArray(buffer.attr);
|
|
7156
|
-
}
|
|
7157
|
-
|
|
7158
|
-
colorBuffer && this.deleteBuffer(colorBuffer);
|
|
7159
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr); // 为线段顶点绘制
|
|
7160
|
-
|
|
7161
|
-
/*for(const p of points) {
|
|
7162
|
-
this.stroke([p], 'red', 10);
|
|
7163
|
-
}*/
|
|
7164
|
-
} // 区域填充图片
|
|
7165
|
-
// points绘制的图形顶点
|
|
7166
|
-
// 图片整体绘制区域
|
|
7167
|
-
|
|
7168
|
-
}, {
|
|
7169
|
-
key: "fillImage",
|
|
7170
|
-
value: function fillImage(img, points, bounds) {
|
|
7171
|
-
if (!img) return; // 设置纹理
|
|
7172
|
-
|
|
7173
|
-
var texture = img instanceof ImageData ? this.createDataTexture(img) : this.createImgTexture(img);
|
|
7174
|
-
this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
|
|
7175
|
-
// 指定纹理区域尺寸
|
|
7176
|
-
|
|
7177
|
-
this.context.uniform4f(this.program.uniforms.v_texture_bounds.location, bounds.left + this.parentAbsoluteBounds.left, bounds.top + this.parentAbsoluteBounds.top, bounds.width, bounds.height); // 纹理单元传递给着色器
|
|
7178
|
-
// 标注为纹理对象
|
|
7179
|
-
|
|
7180
|
-
this.context.uniform1i(this.program.uniforms.a_type.location, 2);
|
|
7181
|
-
var filled = false; // 是否成功填充
|
|
7182
|
-
// 3个以上的点,且非规则图形才需要切割
|
|
7183
|
-
|
|
7184
|
-
if (points.length > 3 && !this.isRegular) {
|
|
7185
|
-
var polygons = this.getPolygon(points);
|
|
7186
|
-
|
|
7187
|
-
if (polygons.length) {
|
|
7188
|
-
var _iterator6 = _createForOfIteratorHelper(polygons),
|
|
7189
|
-
_step6;
|
|
7190
|
-
|
|
7191
|
-
try {
|
|
7192
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
7193
|
-
var polygon = _step6.value;
|
|
7194
|
-
// 需要分割三角形,不然填充会有问题
|
|
7195
|
-
var triangles = this.earCutPointsToTriangles(polygon); // 切割得到三角形顶点二维数组
|
|
7196
|
-
|
|
7197
|
-
if (triangles && triangles.length) {
|
|
7198
|
-
var _iterator7 = _createForOfIteratorHelper(triangles),
|
|
7199
|
-
_step7;
|
|
7200
|
-
|
|
7201
|
-
try {
|
|
7202
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
7203
|
-
var triangle = _step7.value;
|
|
7204
|
-
this.fillTexture(triangle); // 单独为每个分割的图形填充
|
|
7205
|
-
}
|
|
7206
|
-
} catch (err) {
|
|
7207
|
-
_iterator7.e(err);
|
|
7208
|
-
} finally {
|
|
7209
|
-
_iterator7.f();
|
|
7210
|
-
}
|
|
7211
|
-
|
|
7212
|
-
filled = true; // 表示已填充过了
|
|
7213
|
-
}
|
|
7214
|
-
}
|
|
7215
|
-
} catch (err) {
|
|
7216
|
-
_iterator6.e(err);
|
|
7217
|
-
} finally {
|
|
7218
|
-
_iterator6.f();
|
|
7219
|
-
}
|
|
7220
|
-
}
|
|
7221
|
-
} // 如果前面的条件没有填充成功,则直接按正常填充
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
if (!filled) {
|
|
7225
|
-
this.fillTexture(points);
|
|
7226
|
-
}
|
|
7227
|
-
|
|
7228
|
-
this.deleteTexture(texture);
|
|
7229
|
-
} // 填充图形
|
|
7230
|
-
|
|
7231
|
-
}, {
|
|
7232
|
-
key: "drawImage",
|
|
7233
|
-
value: function drawImage(img) {
|
|
7234
|
-
var left = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
7235
|
-
var top = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
7236
|
-
var width = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : img.width;
|
|
7237
|
-
var height = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : img.height;
|
|
7238
|
-
width = width || img.width;
|
|
7239
|
-
height = height || img.height; //this.useProgram();
|
|
7240
|
-
|
|
7241
|
-
this.fillImage(img, this.points, {
|
|
7242
|
-
left: left,
|
|
7243
|
-
top: top,
|
|
7244
|
-
width: width,
|
|
7245
|
-
height: height
|
|
7246
|
-
});
|
|
7247
|
-
}
|
|
7248
|
-
}, {
|
|
7249
|
-
key: "fillTexture",
|
|
7250
|
-
value: function fillTexture(points) {
|
|
7251
|
-
// 纹理坐标
|
|
7252
|
-
var coordBuffer = this.writePoints(points, this.program.attrs.a_text_coord);
|
|
7253
|
-
|
|
7254
|
-
if (points && points.length) {
|
|
7255
|
-
var buffer = this.writePoints(points);
|
|
7256
|
-
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
7257
|
-
this.deleteBuffer(buffer);
|
|
7258
|
-
this.disableVertexAttribArray(buffer.attr);
|
|
7259
|
-
}
|
|
7260
|
-
|
|
7261
|
-
this.disableVertexAttribArray(coordBuffer.attr);
|
|
7262
|
-
this.deleteBuffer(coordBuffer);
|
|
7263
|
-
}
|
|
7264
|
-
}]);
|
|
7265
|
-
|
|
7266
|
-
return WebglPath;
|
|
7267
|
-
}(_base["default"]);
|
|
7268
|
-
|
|
7269
|
-
var _default = WebglPath;
|
|
7270
|
-
exports["default"] = _default;
|
|
7271
|
-
|
|
7272
|
-
},{"./base.js":13}],22:[function(require,module,exports){
|
|
7273
4943
|
"use strict";
|
|
7274
4944
|
|
|
7275
4945
|
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); }
|
|
@@ -7476,7 +5146,7 @@ var jmArc = /*#__PURE__*/function (_jmPath) {
|
|
|
7476
5146
|
|
|
7477
5147
|
exports.jmArc = exports["default"] = jmArc;
|
|
7478
5148
|
|
|
7479
|
-
},{"../core/jmPath.js":8}],
|
|
5149
|
+
},{"../core/jmPath.js":8}],13:[function(require,module,exports){
|
|
7480
5150
|
"use strict";
|
|
7481
5151
|
|
|
7482
5152
|
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); }
|
|
@@ -7700,7 +5370,7 @@ var jmArrow = /*#__PURE__*/function (_jmPath) {
|
|
|
7700
5370
|
|
|
7701
5371
|
exports.jmArrow = exports["default"] = jmArrow;
|
|
7702
5372
|
|
|
7703
|
-
},{"../core/jmPath.js":8,"../core/jmUtils.js":11}],
|
|
5373
|
+
},{"../core/jmPath.js":8,"../core/jmUtils.js":11}],14:[function(require,module,exports){
|
|
7704
5374
|
"use strict";
|
|
7705
5375
|
|
|
7706
5376
|
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); }
|
|
@@ -7794,7 +5464,7 @@ var jmArrowLine = /*#__PURE__*/function (_jmLine) {
|
|
|
7794
5464
|
|
|
7795
5465
|
exports.jmArrowLine = exports["default"] = jmArrowLine;
|
|
7796
5466
|
|
|
7797
|
-
},{"./jmArrow.js":
|
|
5467
|
+
},{"./jmArrow.js":13,"./jmLine.js":20}],15:[function(require,module,exports){
|
|
7798
5468
|
"use strict";
|
|
7799
5469
|
|
|
7800
5470
|
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); }
|
|
@@ -7966,7 +5636,7 @@ var jmBezier = /*#__PURE__*/function (_jmPath) {
|
|
|
7966
5636
|
|
|
7967
5637
|
exports.jmBezier = exports["default"] = jmBezier;
|
|
7968
5638
|
|
|
7969
|
-
},{"../core/jmPath.js":8}],
|
|
5639
|
+
},{"../core/jmPath.js":8}],16:[function(require,module,exports){
|
|
7970
5640
|
"use strict";
|
|
7971
5641
|
|
|
7972
5642
|
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); }
|
|
@@ -8096,7 +5766,7 @@ var jmCircle = /*#__PURE__*/function (_jmArc) {
|
|
|
8096
5766
|
|
|
8097
5767
|
exports.jmCircle = exports["default"] = jmCircle;
|
|
8098
5768
|
|
|
8099
|
-
},{"./jmArc.js":
|
|
5769
|
+
},{"./jmArc.js":12}],17:[function(require,module,exports){
|
|
8100
5770
|
"use strict";
|
|
8101
5771
|
|
|
8102
5772
|
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); }
|
|
@@ -8256,7 +5926,7 @@ var jmHArc = /*#__PURE__*/function (_jmArc) {
|
|
|
8256
5926
|
|
|
8257
5927
|
exports.jmHArc = exports["default"] = jmHArc;
|
|
8258
5928
|
|
|
8259
|
-
},{"./jmArc.js":
|
|
5929
|
+
},{"./jmArc.js":12}],18:[function(require,module,exports){
|
|
8260
5930
|
"use strict";
|
|
8261
5931
|
|
|
8262
5932
|
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); }
|
|
@@ -8533,7 +6203,7 @@ var jmImage = /*#__PURE__*/function (_jmControl) {
|
|
|
8533
6203
|
|
|
8534
6204
|
exports.jmImage = exports["default"] = jmImage;
|
|
8535
6205
|
|
|
8536
|
-
},{"../core/jmControl.js":2}],
|
|
6206
|
+
},{"../core/jmControl.js":2}],19:[function(require,module,exports){
|
|
8537
6207
|
"use strict";
|
|
8538
6208
|
|
|
8539
6209
|
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); }
|
|
@@ -8836,7 +6506,7 @@ var jmLabel = /*#__PURE__*/function (_jmControl) {
|
|
|
8836
6506
|
|
|
8837
6507
|
exports.jmLabel = exports["default"] = jmLabel;
|
|
8838
6508
|
|
|
8839
|
-
},{"../core/jmControl.js":2}],
|
|
6509
|
+
},{"../core/jmControl.js":2}],20:[function(require,module,exports){
|
|
8840
6510
|
"use strict";
|
|
8841
6511
|
|
|
8842
6512
|
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); }
|
|
@@ -8991,7 +6661,7 @@ var jmLine = /*#__PURE__*/function (_jmPath) {
|
|
|
8991
6661
|
|
|
8992
6662
|
exports.jmLine = exports["default"] = jmLine;
|
|
8993
6663
|
|
|
8994
|
-
},{"../core/jmPath.js":8}],
|
|
6664
|
+
},{"../core/jmPath.js":8}],21:[function(require,module,exports){
|
|
8995
6665
|
"use strict";
|
|
8996
6666
|
|
|
8997
6667
|
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); }
|
|
@@ -9111,7 +6781,7 @@ var jmPrismatic = /*#__PURE__*/function (_jmPath) {
|
|
|
9111
6781
|
|
|
9112
6782
|
exports.jmPrismatic = exports["default"] = jmPrismatic;
|
|
9113
6783
|
|
|
9114
|
-
},{"../core/jmPath.js":8}],
|
|
6784
|
+
},{"../core/jmPath.js":8}],22:[function(require,module,exports){
|
|
9115
6785
|
"use strict";
|
|
9116
6786
|
|
|
9117
6787
|
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); }
|
|
@@ -9375,7 +7045,7 @@ var jmRect = /*#__PURE__*/function (_jmPath) {
|
|
|
9375
7045
|
|
|
9376
7046
|
exports.jmRect = exports["default"] = jmRect;
|
|
9377
7047
|
|
|
9378
|
-
},{"../core/jmPath.js":8,"./jmArc.js":
|
|
7048
|
+
},{"../core/jmPath.js":8,"./jmArc.js":12,"./jmLine.js":20}],23:[function(require,module,exports){
|
|
9379
7049
|
"use strict";
|
|
9380
7050
|
|
|
9381
7051
|
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); }
|
|
@@ -9730,5 +7400,5 @@ var jmResize = /*#__PURE__*/function (_jmRect) {
|
|
|
9730
7400
|
|
|
9731
7401
|
exports.jmResize = exports["default"] = jmResize;
|
|
9732
7402
|
|
|
9733
|
-
},{"./jmRect.js":
|
|
7403
|
+
},{"./jmRect.js":22}]},{},[1]);
|
|
9734
7404
|
var _r=_m(1);_g.jmGraph=_r;return _r;})})(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:(typeof self!=='undefined'?self:this)));
|