jmchart 1.2.13 → 1.2.16
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/jmchart.amd.js +1389 -1218
- package/dist/jmchart.cjs.js +1389 -1218
- package/dist/jmchart.esm.js +1389 -1218
- package/dist/jmchart.iife.js +1389 -1218
- package/dist/jmchart.system.js +1389 -1218
- package/package.json +2 -2
- package/src/component/vchart.js +24 -3
- package/src/core/axis/axis.js +6 -3
- package/src/core/markLine/manager.js +2 -6
- package/src/jmChart.js +40 -49
- package/src/series/areaSeries.js +7 -230
- package/src/series/barSeries.js +3 -6
- package/src/series/bubbleSeries.js +1 -4
- package/src/series/candlestickSeries.js +5 -4
- package/src/series/gaugeSeries.js +1 -4
- package/src/series/heatmapSeries.js +1 -4
- package/src/series/lineSeries.js +1 -4
- package/src/series/pieSeries.js +5 -3
- package/src/series/radarSeries.js +18 -11
- package/src/series/scatterSeries.js +1 -4
- package/src/series/series.js +18 -9
- package/src/series/stackBarSeries.js +6 -4
- package/src/series/waterfallSeries.js +1 -4
package/dist/jmchart.amd.js
CHANGED
|
@@ -279,66 +279,75 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
279
279
|
* @param {function} copyHandler 复制对象回调,如果返回undefined,就走后面的逻辑,否则到这里中止
|
|
280
280
|
* @return {object} 参数source的拷贝对象
|
|
281
281
|
*/
|
|
282
|
-
static clone(source, target, deep = false, copyHandler = null, deepIndex = 0) {
|
|
282
|
+
static clone(source, target, deep = false, copyHandler = null, deepIndex = 0, cloned = null) {
|
|
283
283
|
// 如果有指定回调,则用回调处理,否则走后面的复制逻辑
|
|
284
284
|
if(typeof copyHandler === 'function') {
|
|
285
285
|
const obj = copyHandler(source, deep, deepIndex);
|
|
286
286
|
if(obj) return obj;
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
|
|
289
|
+
// 首次调用时初始化克隆映射表(用于处理循环引用)
|
|
290
|
+
if(!cloned) cloned = new WeakMap();
|
|
289
291
|
|
|
290
292
|
if(typeof target === 'boolean') {
|
|
291
293
|
deep = target;
|
|
292
294
|
target = undefined;
|
|
293
295
|
}
|
|
294
296
|
|
|
295
|
-
//
|
|
296
|
-
if(
|
|
297
|
-
return target;
|
|
297
|
+
// 非对象直接返回
|
|
298
|
+
if(!source || typeof source !== 'object') {
|
|
299
|
+
return typeof target !== 'undefined' ? target : source;
|
|
298
300
|
}
|
|
299
301
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
// 如果source已经被克隆过,直接返回之前的克隆对象,打破循环引用
|
|
303
|
+
if(cloned.has(source)) return cloned.get(source);
|
|
302
304
|
|
|
305
|
+
// 数组处理
|
|
306
|
+
if(Array.isArray(source)) {
|
|
303
307
|
//如果为当前泛型,则直接new
|
|
304
308
|
if(this.isType(source, jmList)) {
|
|
305
309
|
return new jmList(source);
|
|
306
310
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
dest.push(this.clone(source[i], target[i], deep, copyHandler, deepIndex));
|
|
313
|
-
}
|
|
314
|
-
return dest;
|
|
315
|
-
}
|
|
316
|
-
return source.slice(0);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if(source.__proto__) target.__proto__ = source.__proto__;
|
|
320
|
-
|
|
321
|
-
for(let k in source) {
|
|
322
|
-
if(k === 'constructor') continue;
|
|
323
|
-
const v = source[k];
|
|
324
|
-
// 不复制页面元素和class对象
|
|
325
|
-
if(v && (v.tagName || v.getContext)) {
|
|
326
|
-
target[k] = v;
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// 如果不是对象和空,则采用target的属性
|
|
331
|
-
if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
|
|
332
|
-
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
|
|
311
|
+
if(deep) {
|
|
312
|
+
let dest = [];
|
|
313
|
+
cloned.set(source, dest);
|
|
314
|
+
for(let i = 0; i < source.length; i++) {
|
|
315
|
+
dest.push(this.clone(source[i], undefined, deep, copyHandler, deepIndex + 1, cloned));
|
|
333
316
|
}
|
|
317
|
+
return dest;
|
|
334
318
|
}
|
|
335
|
-
return
|
|
319
|
+
return source.slice(0);
|
|
336
320
|
}
|
|
337
|
-
|
|
338
|
-
|
|
321
|
+
|
|
322
|
+
// 不复制页面元素和class对象(如jmControl实例等复杂对象保持引用)
|
|
323
|
+
if(source.tagName || source.getContext || source.emit) {
|
|
324
|
+
return source;
|
|
339
325
|
}
|
|
340
326
|
|
|
341
|
-
|
|
327
|
+
// 普通对象处理
|
|
328
|
+
target = target || {};
|
|
329
|
+
cloned.set(source, target);
|
|
330
|
+
|
|
331
|
+
// 保持原型链一致
|
|
332
|
+
if(source.__proto__) target.__proto__ = source.__proto__;
|
|
333
|
+
|
|
334
|
+
// 遍历自身可枚举属性(字符串键 + Symbol键),避免触发原型链上宿主对象的getter
|
|
335
|
+
const keys = Object.keys(source).concat(Object.getOwnPropertySymbols(source));
|
|
336
|
+
for(const k of keys) {
|
|
337
|
+
if(k === 'constructor') continue;
|
|
338
|
+
const v = source[k];
|
|
339
|
+
// 不复制页面元素和class对象
|
|
340
|
+
if(v && (v.tagName || v.getContext || v.emit)) {
|
|
341
|
+
target[k] = v;
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 如果不是对象和空,则采用target的属性
|
|
346
|
+
if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
|
|
347
|
+
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex + 1, cloned);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return target;
|
|
342
351
|
}
|
|
343
352
|
|
|
344
353
|
/**
|
|
@@ -1108,7 +1117,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
1108
1117
|
let sy2 = Number(y2) + bounds.top;
|
|
1109
1118
|
if(this.type === 'linear') {
|
|
1110
1119
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1111
|
-
|
|
1120
|
+
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
1121
|
+
gradient = control.webglControl.createLinearGradient(sx1, sy1, sx2, sy2, bounds);
|
|
1112
1122
|
gradient.key = this.toString();
|
|
1113
1123
|
}
|
|
1114
1124
|
else {
|
|
@@ -1127,7 +1137,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
1127
1137
|
r2 = d * r2;
|
|
1128
1138
|
}
|
|
1129
1139
|
if(control.mode === 'webgl' && control.webglControl) {
|
|
1130
|
-
|
|
1140
|
+
// WebGL 着色器中 v_text_coord 是绝对坐标,需要传递绝对坐标
|
|
1141
|
+
gradient = control.webglControl.createRadialGradient(sx1, sy1, r1, sx2, sy2, r2, bounds);
|
|
1131
1142
|
gradient.key = this.toString();
|
|
1132
1143
|
}
|
|
1133
1144
|
//offsetLine = Math.abs(r2 - r1);//二圆半径差
|
|
@@ -1306,6 +1317,153 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
1306
1317
|
}
|
|
1307
1318
|
}
|
|
1308
1319
|
|
|
1320
|
+
/**
|
|
1321
|
+
* CSS滤镜效果类
|
|
1322
|
+
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
1323
|
+
*
|
|
1324
|
+
* @class jmFilter
|
|
1325
|
+
* @param {string|object} opt 滤镜参数
|
|
1326
|
+
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1327
|
+
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
1328
|
+
*/
|
|
1329
|
+
class jmFilter {
|
|
1330
|
+
constructor(opt) {
|
|
1331
|
+
this.filters = [];
|
|
1332
|
+
|
|
1333
|
+
if(typeof opt === 'string') {
|
|
1334
|
+
this.fromString(opt);
|
|
1335
|
+
}
|
|
1336
|
+
else if(opt && typeof opt === 'object') {
|
|
1337
|
+
for(let k in opt) {
|
|
1338
|
+
if(k === 'constructor' || k === 'filters') continue;
|
|
1339
|
+
this.addFilter(k, opt[k]);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* 添加单个滤镜
|
|
1346
|
+
* @param {string} name 滤镜名称 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
1347
|
+
* @param {number|string} value 滤镜值
|
|
1348
|
+
*/
|
|
1349
|
+
addFilter(name, value) {
|
|
1350
|
+
name = name.toLowerCase().trim();
|
|
1351
|
+
if(typeof value === 'string') {
|
|
1352
|
+
value = parseFloat(value);
|
|
1353
|
+
}
|
|
1354
|
+
if(isNaN(value)) return;
|
|
1355
|
+
|
|
1356
|
+
// 规范化滤镜名称
|
|
1357
|
+
const normalized = {
|
|
1358
|
+
'blur': 'blur',
|
|
1359
|
+
'grayscale': 'grayscale',
|
|
1360
|
+
'greyscale': 'grayscale',
|
|
1361
|
+
'sepia': 'sepia',
|
|
1362
|
+
'brightness': 'brightness',
|
|
1363
|
+
'contrast': 'contrast',
|
|
1364
|
+
'saturate': 'saturate',
|
|
1365
|
+
'hue-rotate': 'hueRotate',
|
|
1366
|
+
'hueRotate': 'hueRotate',
|
|
1367
|
+
'invert': 'invert',
|
|
1368
|
+
'opacity': 'opacity'
|
|
1369
|
+
}[name];
|
|
1370
|
+
|
|
1371
|
+
if(!normalized) return;
|
|
1372
|
+
|
|
1373
|
+
// 检查是否已有同名滤镜,有则更新
|
|
1374
|
+
const existing = this.filters.find(f => f.name === normalized);
|
|
1375
|
+
if(existing) {
|
|
1376
|
+
existing.value = value;
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
this.filters.push({ name: normalized, value: value });
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* 从字符串格式解析滤镜
|
|
1385
|
+
* 格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1386
|
+
* @param {string} s 滤镜字符串
|
|
1387
|
+
*/
|
|
1388
|
+
fromString(s) {
|
|
1389
|
+
if(!s || typeof s !== 'string') return;
|
|
1390
|
+
// 匹配 filterName(value) 模式
|
|
1391
|
+
const regex = /([a-zA-Z-]+)\s*\(\s*([^)]+)\s*\)/g;
|
|
1392
|
+
let match;
|
|
1393
|
+
while((match = regex.exec(s)) !== null) {
|
|
1394
|
+
const name = match[1];
|
|
1395
|
+
const valueStr = match[2].replace(/[a-z%]+$/i, '').trim();
|
|
1396
|
+
const value = parseFloat(valueStr);
|
|
1397
|
+
if(!isNaN(value)) {
|
|
1398
|
+
this.addFilter(name, value);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/**
|
|
1404
|
+
* 转换为CSS filter字符串格式
|
|
1405
|
+
* @returns {string}
|
|
1406
|
+
*/
|
|
1407
|
+
toString() {
|
|
1408
|
+
return this.filters.map(f => {
|
|
1409
|
+
switch(f.name) {
|
|
1410
|
+
case 'blur':
|
|
1411
|
+
return `blur(${f.value}px)`;
|
|
1412
|
+
case 'hueRotate':
|
|
1413
|
+
return `hue-rotate(${f.value}deg)`;
|
|
1414
|
+
default:
|
|
1415
|
+
return `${f.name}(${f.value})`;
|
|
1416
|
+
}
|
|
1417
|
+
}).join(' ');
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* 转换为Canvas context.filter可用的字符串
|
|
1422
|
+
* @returns {string}
|
|
1423
|
+
*/
|
|
1424
|
+
toCanvasFilter() {
|
|
1425
|
+
if(this.filters.length === 0) return 'none';
|
|
1426
|
+
return this.toString();
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* 检查是否有指定名称的滤镜
|
|
1431
|
+
* @param {string} name 滤镜名称
|
|
1432
|
+
* @returns {boolean}
|
|
1433
|
+
*/
|
|
1434
|
+
has(name) {
|
|
1435
|
+
return this.filters.some(f => f.name === name);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* 获取指定滤镜的值
|
|
1440
|
+
* @param {string} name 滤镜名称
|
|
1441
|
+
* @returns {number|undefined}
|
|
1442
|
+
*/
|
|
1443
|
+
get(name) {
|
|
1444
|
+
const f = this.filters.find(f => f.name === name);
|
|
1445
|
+
return f ? f.value : undefined;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* 移除指定滤镜
|
|
1450
|
+
* @param {string} name 滤镜名称
|
|
1451
|
+
*/
|
|
1452
|
+
remove(name) {
|
|
1453
|
+
const index = this.filters.findIndex(f => f.name === name);
|
|
1454
|
+
if(index > -1) {
|
|
1455
|
+
this.filters.splice(index, 1);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* 清空所有滤镜
|
|
1461
|
+
*/
|
|
1462
|
+
clear() {
|
|
1463
|
+
this.filters = [];
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1309
1467
|
let control_id_counter = 0;
|
|
1310
1468
|
|
|
1311
1469
|
class jmObject {
|
|
@@ -2127,10 +2285,14 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2127
2285
|
return result;
|
|
2128
2286
|
};
|
|
2129
2287
|
|
|
2130
|
-
|
|
2288
|
+
const MAX_STOPS = 16;
|
|
2289
|
+
|
|
2290
|
+
/**
|
|
2291
|
+
* WebGL 渐变对象
|
|
2292
|
+
* 支持 GLSL 着色器直接计算渐变色,无需 textureCanvas
|
|
2293
|
+
*/
|
|
2131
2294
|
class WebglGradient {
|
|
2132
|
-
|
|
2133
|
-
constructor(type='linear', params={}) {
|
|
2295
|
+
constructor(type = 'linear', params = {}) {
|
|
2134
2296
|
this.type = type || 'linear';
|
|
2135
2297
|
|
|
2136
2298
|
this.x1 = params.x1 || 0;
|
|
@@ -2150,148 +2312,114 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2150
2312
|
this.control = params.control;
|
|
2151
2313
|
|
|
2152
2314
|
this.stops = [];
|
|
2153
|
-
this.
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
init() {
|
|
2157
|
-
const dx = this.x2 - this.x1;
|
|
2158
|
-
const dy = this.y2 - this.y1;
|
|
2159
|
-
|
|
2160
|
-
if(this.type === 'radial') {
|
|
2161
|
-
this.length = this.r2 - this.r1;
|
|
2162
|
-
}
|
|
2163
|
-
else if(dx === 0 && dy === 0) {
|
|
2164
|
-
this.length = 0;
|
|
2165
|
-
}
|
|
2166
|
-
else {
|
|
2167
|
-
// 渐变中心的距离
|
|
2168
|
-
this.length = Math.sqrt(Math.pow(dx, 2), Math.pow(dy, 2));
|
|
2169
|
-
this.sin = dy / this.length;
|
|
2170
|
-
this.cos = dx / this.length;
|
|
2171
|
-
}
|
|
2315
|
+
this._sortedStops = null;
|
|
2316
|
+
this._paramsHash = null;
|
|
2172
2317
|
}
|
|
2173
2318
|
|
|
2174
|
-
|
|
2319
|
+
/**
|
|
2320
|
+
* 添加颜色断点
|
|
2321
|
+
*/
|
|
2175
2322
|
addColorStop(offset, color) {
|
|
2176
2323
|
this.stops.push({
|
|
2177
|
-
offset,
|
|
2324
|
+
offset: Math.max(0, Math.min(1, offset)),
|
|
2178
2325
|
color
|
|
2179
2326
|
});
|
|
2327
|
+
this._sortedStops = null;
|
|
2328
|
+
this._paramsHash = null;
|
|
2180
2329
|
}
|
|
2181
2330
|
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
if(
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
gradient = control.textureContext.createRadialGradient(this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
|
|
2195
|
-
}
|
|
2196
|
-
this.stops.forEach(function(s, i) {
|
|
2197
|
-
const c = control.graph.utils.toColor(s.color);
|
|
2198
|
-
gradient && gradient.addColorStop(s.offset, c);
|
|
2199
|
-
});
|
|
2200
|
-
|
|
2201
|
-
const data = control.toFillTexture(gradient, bounds, points);
|
|
2202
|
-
|
|
2203
|
-
//WebglGradientTextureCache[key] = data;
|
|
2204
|
-
|
|
2205
|
-
return data;
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
|
-
// 根据绘制图形的坐标计算出对应点的颜色
|
|
2209
|
-
/*
|
|
2210
|
-
toPointColors(points) {
|
|
2211
|
-
const stops = this.getStops();
|
|
2212
|
-
const colors = [];
|
|
2213
|
-
for(let i=0; i<points.length; i+=2) {
|
|
2214
|
-
const p = {
|
|
2215
|
-
x: points[i],
|
|
2216
|
-
y: points[i+1]
|
|
2217
|
-
}
|
|
2218
|
-
if(this.type === 'radial') {
|
|
2219
|
-
const dx = p.x - this.x1;
|
|
2220
|
-
const dy = p.y - this.y1;
|
|
2221
|
-
const len = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
2222
|
-
const rang = this.getStopRange(len, stops);
|
|
2223
|
-
if(!rang.start && rang.end) {
|
|
2224
|
-
colors.push(rang.end.color);
|
|
2225
|
-
}
|
|
2226
|
-
else if(!rang.end && rang.start) {
|
|
2227
|
-
colors.push(rang.start.color);
|
|
2331
|
+
/**
|
|
2332
|
+
* 获取排序后的 stops(带解析后的颜色)
|
|
2333
|
+
*/
|
|
2334
|
+
_getSortedStops() {
|
|
2335
|
+
if (this._sortedStops) return this._sortedStops;
|
|
2336
|
+
|
|
2337
|
+
const utils = this.control && this.control.graph && this.control.graph.utils;
|
|
2338
|
+
this._sortedStops = this.stops
|
|
2339
|
+
.map(s => {
|
|
2340
|
+
let c = s.color;
|
|
2341
|
+
if (utils && typeof c === 'string') {
|
|
2342
|
+
c = utils.hexToRGBA(c);
|
|
2228
2343
|
}
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
const
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2344
|
+
if (typeof c === 'object' && c !== null) {
|
|
2345
|
+
// hexToRGBA 返回 r/g/b 为 0~255,a 为 0~1
|
|
2346
|
+
// 但如果已经是 0~1 范围(由 rgbToDecimal 处理过),需要检测
|
|
2347
|
+
const needNormalize = (c.r > 1 || c.g > 1 || c.b > 1) ? 255 : 1;
|
|
2348
|
+
return {
|
|
2349
|
+
offset: s.offset,
|
|
2350
|
+
r: (c.r !== undefined ? c.r : 0) / needNormalize,
|
|
2351
|
+
g: (c.g !== undefined ? c.g : 0) / needNormalize,
|
|
2352
|
+
b: (c.b !== undefined ? c.b : 0) / needNormalize,
|
|
2353
|
+
a: c.a !== undefined ? c.a : 1
|
|
2238
2354
|
};
|
|
2239
|
-
colors.push(color);
|
|
2240
2355
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2356
|
+
return { offset: s.offset, r: 0, g: 0, b: 0, a: 1 };
|
|
2357
|
+
})
|
|
2358
|
+
.sort((a, b) => a.offset - b.offset);
|
|
2359
|
+
|
|
2360
|
+
return this._sortedStops;
|
|
2244
2361
|
}
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2362
|
+
|
|
2363
|
+
/**
|
|
2364
|
+
* 将渐变参数以 uniform 形式传递给着色器
|
|
2365
|
+
* 返回 { type, start, end, stopCount, stops } 供着色器使用
|
|
2366
|
+
*/
|
|
2367
|
+
toUniformParams() {
|
|
2368
|
+
const stops = this._getSortedStops();
|
|
2369
|
+
const count = Math.min(stops.length, MAX_STOPS);
|
|
2370
|
+
|
|
2371
|
+
// 展平为 Float32Array: [offset, r, g, b, a, ...]
|
|
2372
|
+
const flatStops = new Float32Array(count * 5);
|
|
2373
|
+
for (let i = 0; i < count; i++) {
|
|
2374
|
+
const s = stops[i];
|
|
2375
|
+
flatStops[i * 5 + 0] = s.offset;
|
|
2376
|
+
flatStops[i * 5 + 1] = s.r;
|
|
2377
|
+
flatStops[i * 5 + 2] = s.g;
|
|
2378
|
+
flatStops[i * 5 + 3] = s.b;
|
|
2379
|
+
flatStops[i * 5 + 4] = s.a;
|
|
2257
2380
|
}
|
|
2258
|
-
|
|
2381
|
+
|
|
2382
|
+
return {
|
|
2383
|
+
gradientType: this.type === 'radial' ? 2 : 1,
|
|
2384
|
+
gradientStart: new Float32Array([
|
|
2385
|
+
this.x1, this.y1,
|
|
2386
|
+
this.type === 'radial' ? Math.max(0, this.r1) : 0,
|
|
2387
|
+
0
|
|
2388
|
+
]),
|
|
2389
|
+
gradientEnd: new Float32Array([
|
|
2390
|
+
this.x2, this.y2,
|
|
2391
|
+
this.type === 'radial' ? Math.max(0, this.r2) : 0,
|
|
2392
|
+
0
|
|
2393
|
+
]),
|
|
2394
|
+
stopCount: count,
|
|
2395
|
+
stops: flatStops
|
|
2396
|
+
};
|
|
2259
2397
|
}
|
|
2260
2398
|
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
console.log(s, color);
|
|
2268
|
-
s.color = this.control.graph.utils.rgbToDecimal(color);
|
|
2269
|
-
s.length = s.offset * this.length;
|
|
2270
|
-
}
|
|
2271
|
-
return stops;
|
|
2399
|
+
/**
|
|
2400
|
+
* 使缓存失效
|
|
2401
|
+
*/
|
|
2402
|
+
invalidateCache() {
|
|
2403
|
+
this._sortedStops = null;
|
|
2404
|
+
this._paramsHash = null;
|
|
2272
2405
|
}
|
|
2273
|
-
|
|
2406
|
+
|
|
2274
2407
|
/**
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
this.stops.forEach(function(s) {
|
|
2291
|
-
str += ',' + s.color + ' ' + s.offset;
|
|
2292
|
-
});
|
|
2293
|
-
return str + ')';
|
|
2294
|
-
}
|
|
2408
|
+
* 转换为渐变的字符串表达
|
|
2409
|
+
*/
|
|
2410
|
+
toString() {
|
|
2411
|
+
let str = this.type + '-gradient(';
|
|
2412
|
+
if (this.type == 'linear') {
|
|
2413
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.x2 + ' ' + this.y2;
|
|
2414
|
+
}
|
|
2415
|
+
else {
|
|
2416
|
+
str += this.x1 + ' ' + this.y1 + ' ' + this.r1 + ' ' + this.x2 + ' ' + this.y2 + ' ' + this.r2;
|
|
2417
|
+
}
|
|
2418
|
+
this.stops.forEach(function(s) {
|
|
2419
|
+
str += ',' + s.color + ' ' + s.offset;
|
|
2420
|
+
});
|
|
2421
|
+
return str + ')';
|
|
2422
|
+
}
|
|
2295
2423
|
}
|
|
2296
2424
|
|
|
2297
2425
|
// 生成着色器
|
|
@@ -2616,8 +2744,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2616
2744
|
vec4 pos = translatePosition(a_position, a_center_point.x, a_center_point.y);
|
|
2617
2745
|
gl_Position = pos;
|
|
2618
2746
|
v_color = a_color;
|
|
2619
|
-
if(a_type == 2) {
|
|
2620
|
-
v_text_coord =
|
|
2747
|
+
if(a_type == 2 || a_type == 5) {
|
|
2748
|
+
v_text_coord = a_position.xy;
|
|
2621
2749
|
}
|
|
2622
2750
|
}
|
|
2623
2751
|
`;
|
|
@@ -2627,21 +2755,73 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2627
2755
|
uniform sampler2D u_sample;
|
|
2628
2756
|
uniform vec4 v_texture_bounds; // 纹理的左上坐标和大小 x,y,z,w
|
|
2629
2757
|
uniform vec4 v_single_color;
|
|
2758
|
+
// GLSL 渐变 uniforms
|
|
2759
|
+
uniform int u_gradient_type; // 0=无 1=线性 2=径向
|
|
2760
|
+
uniform vec4 u_gradient_start; // 线性:{x1,y1,0,0} 径向:{cx,cy,r1,0}
|
|
2761
|
+
uniform vec4 u_gradient_end; // 线性:{x2,y2,0,0} 径向:{cx,cy,r2,0}
|
|
2762
|
+
uniform int u_gradient_stop_count;
|
|
2763
|
+
uniform float u_gradient_offsets[${MAX_STOPS}];
|
|
2764
|
+
uniform vec4 u_gradient_colors[${MAX_STOPS}]; // {r, g, b, a} 0~1 范围
|
|
2630
2765
|
varying float v_type;
|
|
2631
2766
|
varying vec4 v_color;
|
|
2632
2767
|
varying vec2 v_text_coord;
|
|
2633
2768
|
|
|
2634
2769
|
${convertTexturePosition}
|
|
2635
2770
|
|
|
2771
|
+
// 在 sorted stops 中按 t 值采样颜色
|
|
2772
|
+
// 兼容 GLSL ES 1.0:循环仅与常量比较,无 break/continue
|
|
2773
|
+
vec4 sampleGradient(float t) {
|
|
2774
|
+
t = clamp(t, 0.0, 1.0);
|
|
2775
|
+
// 正向扫描:始终遍历 MAX_STOPS-1 次,找到 t 所在段并覆盖结果
|
|
2776
|
+
float localT = 0.0;
|
|
2777
|
+
vec4 c0 = u_gradient_colors[0];
|
|
2778
|
+
vec4 c1 = u_gradient_colors[0];
|
|
2779
|
+
for(int i = 0; i < ${MAX_STOPS - 1}; i++) {
|
|
2780
|
+
float s0 = u_gradient_offsets[i];
|
|
2781
|
+
float s1 = u_gradient_offsets[i + 1];
|
|
2782
|
+
if(t >= s0) {
|
|
2783
|
+
float range = s1 - s0;
|
|
2784
|
+
localT = range > 0.0001 ? clamp((t - s0) / range, 0.0, 1.0) : 0.0;
|
|
2785
|
+
c0 = u_gradient_colors[i];
|
|
2786
|
+
c1 = u_gradient_colors[i + 1];
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
return mix(c0, c1, localT);
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2636
2792
|
void main() {
|
|
2637
2793
|
// 如果是fill,则直接填充颜色
|
|
2638
2794
|
if(v_type == 1.0) {
|
|
2639
2795
|
gl_FragColor = v_single_color;
|
|
2640
2796
|
}
|
|
2641
|
-
// 渐变色
|
|
2797
|
+
// 渐变色 (旧方式,顶点颜色插值)
|
|
2642
2798
|
else if(v_type == 3.0) {
|
|
2643
2799
|
gl_FragColor = v_color;
|
|
2644
2800
|
}
|
|
2801
|
+
// GLSL 渐变填充 (type=5)
|
|
2802
|
+
else if(v_type == 5.0) {
|
|
2803
|
+
float t;
|
|
2804
|
+
if(u_gradient_type == 2) {
|
|
2805
|
+
// 径向渐变
|
|
2806
|
+
vec2 d = v_text_coord - u_gradient_start.xy;
|
|
2807
|
+
float dist = length(d);
|
|
2808
|
+
float r1 = u_gradient_start.z;
|
|
2809
|
+
float r2 = u_gradient_end.z;
|
|
2810
|
+
float range = r2 - r1;
|
|
2811
|
+
t = range > 0.001 ? (dist - r1) / range : 0.0;
|
|
2812
|
+
} else {
|
|
2813
|
+
// 线性渐变
|
|
2814
|
+
vec2 dir = u_gradient_end.xy - u_gradient_start.xy;
|
|
2815
|
+
float lenSq = dot(dir, dir);
|
|
2816
|
+
if(lenSq > 0.001) {
|
|
2817
|
+
vec2 pos = v_text_coord - u_gradient_start.xy;
|
|
2818
|
+
t = dot(pos, dir) / lenSq;
|
|
2819
|
+
} else {
|
|
2820
|
+
t = 0.0;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
gl_FragColor = sampleGradient(t) * v_single_color.a;
|
|
2824
|
+
}
|
|
2645
2825
|
else if(v_type == 2.0) {
|
|
2646
2826
|
vec2 pos = translateTexturePosition(v_text_coord, v_texture_bounds);
|
|
2647
2827
|
gl_FragColor = texture2D(u_sample, pos);
|
|
@@ -2712,7 +2892,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2712
2892
|
rotate(angle) {
|
|
2713
2893
|
const cos = Math.cos(angle);
|
|
2714
2894
|
const sin = Math.sin(angle);
|
|
2715
|
-
const [a, b, c, d
|
|
2895
|
+
const [a, b, c, d] = this.transformMatrix;
|
|
2716
2896
|
|
|
2717
2897
|
// 更新变换矩阵
|
|
2718
2898
|
this.transformMatrix[0] = a * cos - b * sin;
|
|
@@ -2743,21 +2923,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2743
2923
|
};
|
|
2744
2924
|
}
|
|
2745
2925
|
|
|
2746
|
-
//
|
|
2747
|
-
get
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2926
|
+
// 文本测量用的离屏 canvas context(1x1 单例缓存,不依赖 textureCanvas)
|
|
2927
|
+
get _measureCtx() {
|
|
2928
|
+
if(!this.__measureCtx) {
|
|
2929
|
+
try {
|
|
2930
|
+
if(typeof document !== 'undefined') {
|
|
2931
|
+
const c = document.createElement('canvas');
|
|
2932
|
+
c.width = c.height = 1;
|
|
2933
|
+
this.__measureCtx = c.getContext('2d');
|
|
2934
|
+
}
|
|
2935
|
+
} catch(e) {
|
|
2936
|
+
this.__measureCtx = null;
|
|
2937
|
+
}
|
|
2752
2938
|
}
|
|
2753
|
-
return
|
|
2754
|
-
}
|
|
2755
|
-
// 纹理绘制canvas ctx
|
|
2756
|
-
get textureContext() {
|
|
2757
|
-
const ctx = this.textureCanvas.ctx || (this.textureCanvas.ctx = this.textureCanvas.getContext('2d', {
|
|
2758
|
-
willReadFrequently: true
|
|
2759
|
-
}));
|
|
2760
|
-
return ctx;
|
|
2939
|
+
return this.__measureCtx;
|
|
2761
2940
|
}
|
|
2762
2941
|
|
|
2763
2942
|
// i当前程序
|
|
@@ -2803,29 +2982,42 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2803
2982
|
// 把传统颜色转为webgl识别的
|
|
2804
2983
|
convertColor(color) {
|
|
2805
2984
|
if(this.isGradient(color)) return color;
|
|
2806
|
-
if(typeof color === 'string')
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
if(['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(style) > -1) {
|
|
2814
|
-
value = this.graph.utils.toColor(value);
|
|
2985
|
+
if(typeof color === 'string') {
|
|
2986
|
+
// 先尝试 hexToRGBA 解析
|
|
2987
|
+
color = this.graph.utils.hexToRGBA(color);
|
|
2988
|
+
// hexToRGBA 对无法识别的格式(如 hsl)会原样返回字符串
|
|
2989
|
+
// 利用离屏 canvas 将任意 CSS 颜色转为 rgba
|
|
2990
|
+
if(typeof color === 'string') {
|
|
2991
|
+
color = this.__parseCSSColor(color);
|
|
2815
2992
|
}
|
|
2816
|
-
this.textureContext[style] = value;
|
|
2817
2993
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2994
|
+
if(typeof color === 'object' && color.r !== undefined) {
|
|
2995
|
+
return this.graph.utils.rgbToDecimal(color);
|
|
2996
|
+
}
|
|
2997
|
+
return color;
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
// 利用离屏 canvas 解析任意 CSS 颜色(hsl/hsla/命名颜色等)
|
|
3001
|
+
__parseCSSColor(colorStr) {
|
|
3002
|
+
const ctx = this._measureCtx;
|
|
3003
|
+
if(!ctx) return { r: 0, g: 0, b: 0, a: 0 };
|
|
3004
|
+
try {
|
|
3005
|
+
ctx.clearRect(0, 0, 1, 1);
|
|
3006
|
+
ctx.fillStyle = '#000000';
|
|
3007
|
+
ctx.fillStyle = colorStr;
|
|
3008
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
3009
|
+
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
|
|
3010
|
+
if(ctx.fillStyle === '#000000' && colorStr !== '#000000' && colorStr !== 'black') {
|
|
3011
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
2822
3012
|
}
|
|
3013
|
+
return { r, g, b, a: a / 255 };
|
|
3014
|
+
} catch(e) {
|
|
3015
|
+
return { r: 0, g: 0, b: 0, a: 0 };
|
|
2823
3016
|
}
|
|
2824
3017
|
}
|
|
2825
3018
|
|
|
2826
3019
|
// 创建程序
|
|
2827
3020
|
createProgram(vertexSrc, fragmentSrc) {
|
|
2828
|
-
this.context.lineWidth(1);
|
|
2829
3021
|
return createProgram(this.context, vertexSrc, fragmentSrc);
|
|
2830
3022
|
}
|
|
2831
3023
|
|
|
@@ -2938,7 +3130,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2938
3130
|
// polygonIndices 顶点索引,
|
|
2939
3131
|
earCutPointsToTriangles(points) {
|
|
2940
3132
|
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
2941
|
-
|
|
3133
|
+
// 快速缓存 key:用长度和首尾点坐标
|
|
3134
|
+
const len = points.length;
|
|
3135
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
2942
3136
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
2943
3137
|
|
|
2944
3138
|
const ps = this.earCutPoints(points);// 切割得到3角色顶点索引,
|
|
@@ -2993,97 +3187,23 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2993
3187
|
return obj && obj instanceof WebglGradient;
|
|
2994
3188
|
}
|
|
2995
3189
|
|
|
2996
|
-
|
|
3190
|
+
/**
|
|
2997
3191
|
* 测试获取文本所占大小
|
|
2998
3192
|
*
|
|
2999
3193
|
* @method testSize
|
|
3000
3194
|
* @return {object} 含文本大小的对象
|
|
3001
3195
|
*/
|
|
3002
3196
|
testSize(text, style=this.style) {
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
{width:15};
|
|
3012
|
-
this.textureContext.restore &&this.textureContext.restore();
|
|
3013
|
-
size.height = this.style.fontSize? this.style.fontSize: 15;
|
|
3197
|
+
const ctx = this._measureCtx;
|
|
3198
|
+
if(!ctx) return { width: 15, height: style.fontSize || 15 };
|
|
3199
|
+
|
|
3200
|
+
ctx.save && ctx.save();
|
|
3201
|
+
if(style.font || style.fontSize) ctx.font = style.font || (style.fontSize + 'px ' + style.fontFamily);
|
|
3202
|
+
const size = ctx.measureText ? ctx.measureText(text) : { width: 15 };
|
|
3203
|
+
ctx.restore && ctx.restore();
|
|
3204
|
+
size.height = style.fontSize ? parseInt(style.fontSize) : 15;
|
|
3014
3205
|
return size;
|
|
3015
3206
|
}
|
|
3016
|
-
|
|
3017
|
-
// 使用纹理canvas生成图,
|
|
3018
|
-
// 填充可以是颜色或渐变对象
|
|
3019
|
-
// 如果指定了points,则表明要绘制不规则的图形
|
|
3020
|
-
toFillTexture(fillStyle, bounds, points=null) {
|
|
3021
|
-
const canvas = this.textureCanvas;
|
|
3022
|
-
if(!canvas) {
|
|
3023
|
-
return fillStyle;
|
|
3024
|
-
}
|
|
3025
|
-
canvas.width = bounds.width;
|
|
3026
|
-
canvas.height = bounds.height;
|
|
3027
|
-
|
|
3028
|
-
if(!canvas.width || !canvas.height) {
|
|
3029
|
-
return fillStyle;
|
|
3030
|
-
}
|
|
3031
|
-
|
|
3032
|
-
this.textureContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
3033
|
-
|
|
3034
|
-
this.textureContext.fillStyle = fillStyle;
|
|
3035
|
-
|
|
3036
|
-
this.textureContext.beginPath();
|
|
3037
|
-
if(!points || !points.length) {
|
|
3038
|
-
points = [];
|
|
3039
|
-
points.push({
|
|
3040
|
-
x: bounds.left,
|
|
3041
|
-
y: bounds.top
|
|
3042
|
-
});
|
|
3043
|
-
points.push({
|
|
3044
|
-
x: bounds.left + bounds.width,
|
|
3045
|
-
y: bounds.top
|
|
3046
|
-
});
|
|
3047
|
-
points.push({
|
|
3048
|
-
x: bounds.left + bounds.width,
|
|
3049
|
-
y: bounds.top + bounds.height
|
|
3050
|
-
});
|
|
3051
|
-
points.push({
|
|
3052
|
-
x: bounds.left,
|
|
3053
|
-
y: bounds.top + bounds.height
|
|
3054
|
-
});
|
|
3055
|
-
points.push({
|
|
3056
|
-
x: bounds.left,
|
|
3057
|
-
y: bounds.top
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
if(points && points.length) {
|
|
3061
|
-
for(const p of points) {
|
|
3062
|
-
//移至当前坐标
|
|
3063
|
-
if(p.m) {
|
|
3064
|
-
this.textureContext.moveTo(p.x - bounds.left, p.y - bounds.top);
|
|
3065
|
-
}
|
|
3066
|
-
else {
|
|
3067
|
-
this.textureContext.lineTo(p.x - bounds.left, p.y - bounds.top);
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
else {
|
|
3072
|
-
this.textureContext.moveTo(0, 0);
|
|
3073
|
-
this.textureContext.lineTo(bounds.width, 0);
|
|
3074
|
-
this.textureContext.lineTo(bounds.width, bounds.height);
|
|
3075
|
-
this.textureContext.lineTo(0, bounds.height);
|
|
3076
|
-
this.textureContext.lineTo(0, 0);
|
|
3077
|
-
}
|
|
3078
|
-
this.textureContext.closePath();
|
|
3079
|
-
this.textureContext.fill();
|
|
3080
|
-
|
|
3081
|
-
const data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
|
|
3082
|
-
return {
|
|
3083
|
-
data,
|
|
3084
|
-
points
|
|
3085
|
-
};
|
|
3086
|
-
}
|
|
3087
3207
|
}
|
|
3088
3208
|
|
|
3089
3209
|
// path 绘制类
|
|
@@ -3095,6 +3215,40 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3095
3215
|
this.needCut = option.needCut || false;
|
|
3096
3216
|
this.control = option.control;
|
|
3097
3217
|
this.points = [];
|
|
3218
|
+
// 缓存 buffer 和纹理,避免每帧创建/销毁
|
|
3219
|
+
this.__cachedBuffers = [];
|
|
3220
|
+
this.__cachedTexture = null;
|
|
3221
|
+
this.__cachedTextureKey = null;
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
// 释放缓存的 WebGL 资源
|
|
3225
|
+
dispose() {
|
|
3226
|
+
for(const buf of this.__cachedBuffers) {
|
|
3227
|
+
this.deleteBuffer(buf);
|
|
3228
|
+
}
|
|
3229
|
+
this.__cachedBuffers = [];
|
|
3230
|
+
if(this.__cachedTexture) {
|
|
3231
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3232
|
+
this.__cachedTexture = null;
|
|
3233
|
+
this.__cachedTextureKey = null;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// 获取或创建 buffer,优先复用缓存
|
|
3238
|
+
getOrCreateBuffer(data, attr) {
|
|
3239
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3240
|
+
if(buffer) {
|
|
3241
|
+
const gl = this.context;
|
|
3242
|
+
const float32 = new Float32Array(data);
|
|
3243
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3244
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3245
|
+
buffer.data = data;
|
|
3246
|
+
return buffer;
|
|
3247
|
+
}
|
|
3248
|
+
buffer = this.createFloat32Buffer(data);
|
|
3249
|
+
buffer.attr = attr;
|
|
3250
|
+
this.__cachedBuffers.push(buffer);
|
|
3251
|
+
return buffer;
|
|
3098
3252
|
}
|
|
3099
3253
|
|
|
3100
3254
|
// 应用变换到点
|
|
@@ -3107,8 +3261,14 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3107
3261
|
//this.useProgram();
|
|
3108
3262
|
|
|
3109
3263
|
if(parentBounds) this.parentAbsoluteBounds = parentBounds;
|
|
3110
|
-
//
|
|
3111
|
-
|
|
3264
|
+
// 缓存中心点值,只在变化时才更新 uniform
|
|
3265
|
+
const cx = this.graph.width / 2;
|
|
3266
|
+
const cy = this.graph.height / 2;
|
|
3267
|
+
if(this.__lastCenterX !== cx || this.__lastCenterY !== cy) {
|
|
3268
|
+
this.context.uniform2f(this.program.uniforms.a_center_point.location, cx, cy);
|
|
3269
|
+
this.__lastCenterX = cx;
|
|
3270
|
+
this.__lastCenterY = cy;
|
|
3271
|
+
}
|
|
3112
3272
|
}
|
|
3113
3273
|
|
|
3114
3274
|
setFragColor(color) {
|
|
@@ -3149,6 +3309,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3149
3309
|
endDraw() {
|
|
3150
3310
|
if(this.points) delete this.points;
|
|
3151
3311
|
if(this.pathPoints) delete this.pathPoints;
|
|
3312
|
+
// 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
3152
3313
|
}
|
|
3153
3314
|
|
|
3154
3315
|
// 图形封闭
|
|
@@ -3160,21 +3321,47 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3160
3321
|
}
|
|
3161
3322
|
}
|
|
3162
3323
|
|
|
3163
|
-
//
|
|
3324
|
+
// 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
3164
3325
|
writePoints(points, attr = this.program.attrs.a_position) {
|
|
3165
|
-
|
|
3166
3326
|
const fixedPoints = [];
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3327
|
+
const [a, b, c, d, tx, ty] = this.transformMatrix;
|
|
3328
|
+
const isIdentity = (a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0);
|
|
3329
|
+
const offsetLeft = this.parentAbsoluteBounds.left;
|
|
3330
|
+
const offsetTop = this.parentAbsoluteBounds.top;
|
|
3331
|
+
|
|
3332
|
+
if(isIdentity) {
|
|
3333
|
+
// 单位矩阵时直接加偏移,避免逐点调用 applyTransform
|
|
3334
|
+
for(let i = 0; i < points.length; i++) {
|
|
3335
|
+
fixedPoints.push(points[i].x + offsetLeft, points[i].y + offsetTop);
|
|
3336
|
+
}
|
|
3337
|
+
} else {
|
|
3338
|
+
for(const p of points) {
|
|
3339
|
+
const transformedPoint = this.applyTransform(p);
|
|
3340
|
+
fixedPoints.push(
|
|
3341
|
+
transformedPoint.x + offsetLeft,
|
|
3342
|
+
transformedPoint.y + offsetTop
|
|
3343
|
+
);
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
const float32 = new Float32Array(fixedPoints);
|
|
3347
|
+
const gl = this.context;
|
|
3348
|
+
|
|
3349
|
+
// 复用已有 buffer 或创建新的
|
|
3350
|
+
if(this.__cachedBuffers.length > 0) {
|
|
3351
|
+
// 找一个同 attr 的 buffer 复用
|
|
3352
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3353
|
+
if(buffer) {
|
|
3354
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3355
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3356
|
+
buffer.data = fixedPoints;
|
|
3357
|
+
this.writeVertexAttrib(buffer, attr, 2, 0, 0);
|
|
3358
|
+
return buffer;
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
const vertexBuffer = this.createFloat32Buffer(float32, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3176
3362
|
this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
|
|
3177
3363
|
vertexBuffer.attr = attr;
|
|
3364
|
+
this.__cachedBuffers.push(vertexBuffer);
|
|
3178
3365
|
return vertexBuffer;
|
|
3179
3366
|
}
|
|
3180
3367
|
|
|
@@ -3223,6 +3410,112 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3223
3410
|
equalPoint(p1, p2) {
|
|
3224
3411
|
return p1.x === p2.x && p1.y === p2.y;
|
|
3225
3412
|
}
|
|
3413
|
+
|
|
3414
|
+
// 将带 moveTo 标记的点集拆分为外轮廓和多个洞
|
|
3415
|
+
splitSubPaths(points) {
|
|
3416
|
+
const subPaths = [];
|
|
3417
|
+
let current = [];
|
|
3418
|
+
for(let i = 0; i < points.length; i++) {
|
|
3419
|
+
const p = points[i];
|
|
3420
|
+
if(p.m && current.length > 0) {
|
|
3421
|
+
subPaths.push(current);
|
|
3422
|
+
current = [];
|
|
3423
|
+
}
|
|
3424
|
+
current.push(p);
|
|
3425
|
+
}
|
|
3426
|
+
if(current.length > 0) subPaths.push(current);
|
|
3427
|
+
|
|
3428
|
+
// 面积最大的作为外轮廓,其余作为洞
|
|
3429
|
+
let maxArea = -1;
|
|
3430
|
+
let outerIdx = 0;
|
|
3431
|
+
for(let i = 0; i < subPaths.length; i++) {
|
|
3432
|
+
const area = Math.abs(this.polygonArea(subPaths[i]));
|
|
3433
|
+
if(area > maxArea) {
|
|
3434
|
+
maxArea = area;
|
|
3435
|
+
outerIdx = i;
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
const outerPoints = subPaths[outerIdx];
|
|
3440
|
+
const holes = [];
|
|
3441
|
+
for(let i = 0; i < subPaths.length; i++) {
|
|
3442
|
+
if(i !== outerIdx) holes.push(subPaths[i]);
|
|
3443
|
+
}
|
|
3444
|
+
return { outerPoints, holes };
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
// 计算多边形面积(Shoelace 公式)
|
|
3448
|
+
polygonArea(points) {
|
|
3449
|
+
let area = 0;
|
|
3450
|
+
const n = points.length;
|
|
3451
|
+
for(let i = 0; i < n; i++) {
|
|
3452
|
+
const j = (i + 1) % n;
|
|
3453
|
+
area += points[i].x * points[j].y;
|
|
3454
|
+
area -= points[j].x * points[i].y;
|
|
3455
|
+
}
|
|
3456
|
+
return area / 2;
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// 使用 earcut 带 holes 填充多边形
|
|
3460
|
+
fillWithHoles(outerPoints, holes, isTexture = false) {
|
|
3461
|
+
// 将所有点合并:外轮廓 + 各个洞,并记录洞的起始索引
|
|
3462
|
+
const allPoints = [...outerPoints];
|
|
3463
|
+
const holeIndices = [];
|
|
3464
|
+
for(const hole of holes) {
|
|
3465
|
+
holeIndices.push(allPoints.length);
|
|
3466
|
+
allPoints.push(...hole);
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3469
|
+
const dim = 2;
|
|
3470
|
+
const vertexData = [];
|
|
3471
|
+
for(const p of allPoints) {
|
|
3472
|
+
vertexData.push(p.x, p.y);
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
// 用 earcut 进行带洞三角化
|
|
3476
|
+
const indices = earcut(vertexData, holeIndices, dim);
|
|
3477
|
+
|
|
3478
|
+
if(!indices || indices.length < 3) return;
|
|
3479
|
+
|
|
3480
|
+
// 构建 GPU 顶点数据
|
|
3481
|
+
const allVertices = [];
|
|
3482
|
+
const allTexCoords = [];
|
|
3483
|
+
for(let i = 0; i < indices.length; i++) {
|
|
3484
|
+
const p = allPoints[indices[i]];
|
|
3485
|
+
allVertices.push(p.x, p.y);
|
|
3486
|
+
if(isTexture) allTexCoords.push(p.x, p.y);
|
|
3487
|
+
}
|
|
3488
|
+
|
|
3489
|
+
const gl = this.context;
|
|
3490
|
+
const vertexArr = new Float32Array(allVertices);
|
|
3491
|
+
|
|
3492
|
+
let posBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_position);
|
|
3493
|
+
if(!posBuffer) {
|
|
3494
|
+
posBuffer = this.createFloat32Buffer(vertexArr, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3495
|
+
posBuffer.attr = this.program.attrs.a_position;
|
|
3496
|
+
this.__cachedBuffers.push(posBuffer);
|
|
3497
|
+
} else {
|
|
3498
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer.buffer);
|
|
3499
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertexArr, gl.DYNAMIC_DRAW);
|
|
3500
|
+
}
|
|
3501
|
+
this.writeVertexAttrib(posBuffer, this.program.attrs.a_position, 2, 0, 0);
|
|
3502
|
+
|
|
3503
|
+
if(isTexture && allTexCoords.length) {
|
|
3504
|
+
const texData = new Float32Array(allTexCoords);
|
|
3505
|
+
let texBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_text_coord);
|
|
3506
|
+
if(!texBuffer) {
|
|
3507
|
+
texBuffer = this.createFloat32Buffer(texData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3508
|
+
texBuffer.attr = this.program.attrs.a_text_coord;
|
|
3509
|
+
this.__cachedBuffers.push(texBuffer);
|
|
3510
|
+
} else {
|
|
3511
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texBuffer.buffer);
|
|
3512
|
+
gl.bufferData(gl.ARRAY_BUFFER, texData, gl.DYNAMIC_DRAW);
|
|
3513
|
+
}
|
|
3514
|
+
this.writeVertexAttrib(texBuffer, this.program.attrs.a_text_coord, 2, 0, 0);
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
gl.drawArrays(gl.TRIANGLES, 0, allVertices.length / 2);
|
|
3518
|
+
}
|
|
3226
3519
|
// 把path坐标集合转为线段集
|
|
3227
3520
|
pathToLines(points) {
|
|
3228
3521
|
let start = null;
|
|
@@ -3410,9 +3703,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3410
3703
|
|
|
3411
3704
|
// 分割成一个个规则的三角形,不规则的多边形不全割的话纹理就会没法正确覆盖
|
|
3412
3705
|
getTriangles(points) {
|
|
3413
|
-
|
|
3414
3706
|
this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
|
|
3415
|
-
|
|
3707
|
+
// 快速缓存 key:用长度和首尾点坐标(比 JSON.stringify 快几个数量级)
|
|
3708
|
+
const len = points.length;
|
|
3709
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
3416
3710
|
if(this.trianglesCache[key]) return this.trianglesCache[key];
|
|
3417
3711
|
|
|
3418
3712
|
const res = [];
|
|
@@ -3448,13 +3742,49 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3448
3742
|
}
|
|
3449
3743
|
if(points && points.length) {
|
|
3450
3744
|
const regular = lineWidth <= 1.2;
|
|
3451
|
-
|
|
3452
|
-
const
|
|
3453
|
-
|
|
3454
|
-
|
|
3745
|
+
const hasMoveTo = points.some && points.some(p => p.m);
|
|
3746
|
+
const isRing = !hasMoveTo && this.needCut; // 空心形状(jmHArc close=true 时无 m 标记)
|
|
3747
|
+
if(regular && (hasMoveTo || isRing)) {
|
|
3748
|
+
// 有 moveTo 标记或空心形状时,分段绘制每个子路径的 LINE_LOOP
|
|
3749
|
+
// 避免 LINE_LOOP 把不同子路径的点连起来产生拉扯线
|
|
3750
|
+
if(hasMoveTo) {
|
|
3751
|
+
let subPath = [];
|
|
3752
|
+
for(let i = 0; i < points.length; i++) {
|
|
3753
|
+
if(points[i].m && subPath.length > 0) {
|
|
3754
|
+
this.writePoints(subPath);
|
|
3755
|
+
this.context.drawArrays(this.context.LINE_LOOP, 0, subPath.length);
|
|
3756
|
+
subPath = [];
|
|
3757
|
+
}
|
|
3758
|
+
subPath.push(points[i]);
|
|
3759
|
+
}
|
|
3760
|
+
if(subPath.length > 1) {
|
|
3761
|
+
this.writePoints(subPath);
|
|
3762
|
+
this.context.drawArrays(this.context.LINE_LOOP, 0, subPath.length);
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
else if(isRing) {
|
|
3766
|
+
// 空心形状:前半段为内弧,后半段为外弧(反向),各自 LINE_LOOP
|
|
3767
|
+
const mid = Math.floor(points.length / 2);
|
|
3768
|
+
const inner = points.slice(0, mid);
|
|
3769
|
+
const outer = points.slice(mid);
|
|
3770
|
+
if(inner.length > 1) {
|
|
3771
|
+
this.writePoints(inner);
|
|
3772
|
+
this.context.drawArrays(this.context.LINE_LOOP, 0, inner.length);
|
|
3773
|
+
}
|
|
3774
|
+
if(outer.length > 1) {
|
|
3775
|
+
this.writePoints(outer);
|
|
3776
|
+
this.context.drawArrays(this.context.LINE_LOOP, 0, outer.length);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
else {
|
|
3781
|
+
points = regular? points : this.pathToPoints(points);
|
|
3782
|
+
this.writePoints(points);
|
|
3783
|
+
this.context.drawArrays(regular? this.context.LINE_LOOP: this.context.POINTS, 0, points.length);
|
|
3784
|
+
}
|
|
3785
|
+
// buffer 由 endDraw 统一清理
|
|
3455
3786
|
}
|
|
3456
|
-
colorBuffer && this.
|
|
3457
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3787
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3458
3788
|
}
|
|
3459
3789
|
|
|
3460
3790
|
// 填充图形
|
|
@@ -3473,10 +3803,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3473
3803
|
|
|
3474
3804
|
fillColor(color, points, bounds, type=1) {
|
|
3475
3805
|
|
|
3476
|
-
//
|
|
3806
|
+
// 如果是渐变色,使用 GLSL 着色器直接计算
|
|
3477
3807
|
if(this.isGradient(color)) {
|
|
3478
|
-
|
|
3479
|
-
return this.fillImage(imgData.data, imgData.points, bounds);
|
|
3808
|
+
return this.fillGradient(color, points, bounds);
|
|
3480
3809
|
}
|
|
3481
3810
|
|
|
3482
3811
|
// 标注为fill
|
|
@@ -3485,19 +3814,111 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3485
3814
|
|
|
3486
3815
|
this.fillPolygons(points);
|
|
3487
3816
|
|
|
3488
|
-
colorBuffer && this.
|
|
3489
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3817
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3490
3818
|
|
|
3491
3819
|
}
|
|
3492
3820
|
|
|
3821
|
+
/**
|
|
3822
|
+
* 使用 GLSL 着色器渲染渐变填充
|
|
3823
|
+
* 无需 textureCanvas,直接通过 uniform 传递渐变参数给 GPU
|
|
3824
|
+
*/
|
|
3825
|
+
fillGradient(gradient, points, bounds) {
|
|
3826
|
+
const params = gradient.toUniformParams();
|
|
3827
|
+
if(!params) return;
|
|
3828
|
+
|
|
3829
|
+
// 标注为 GLSL 渐变 (type=5)
|
|
3830
|
+
this.context.uniform1i(this.program.uniforms.a_type.location, 5);
|
|
3831
|
+
|
|
3832
|
+
// 设置 globalAlpha(通过 v_single_color.a 传递给着色器)
|
|
3833
|
+
this.context.uniform4f(this.program.uniforms.v_single_color.location, 1.0, 1.0, 1.0, this.style.globalAlpha);
|
|
3834
|
+
|
|
3835
|
+
// 设置渐变类型
|
|
3836
|
+
if(this.program.uniforms.u_gradient_type) {
|
|
3837
|
+
this.context.uniform1i(this.program.uniforms.u_gradient_type.location, params.gradientType);
|
|
3838
|
+
}
|
|
3839
|
+
|
|
3840
|
+
// 设置渐变起点/终点
|
|
3841
|
+
if(this.program.uniforms.u_gradient_start) {
|
|
3842
|
+
this.context.uniform4fv(this.program.uniforms.u_gradient_start.location, params.gradientStart);
|
|
3843
|
+
}
|
|
3844
|
+
if(this.program.uniforms.u_gradient_end) {
|
|
3845
|
+
this.context.uniform4fv(this.program.uniforms.u_gradient_end.location, params.gradientEnd);
|
|
3846
|
+
}
|
|
3847
|
+
|
|
3848
|
+
// 设置颜色断点数量
|
|
3849
|
+
if(this.program.uniforms.u_gradient_stop_count) {
|
|
3850
|
+
this.context.uniform1i(this.program.uniforms.u_gradient_stop_count.location, params.stopCount);
|
|
3851
|
+
}
|
|
3852
|
+
|
|
3853
|
+
// 设置每个 stop 的 offset
|
|
3854
|
+
// 关键:必须填充完整的 MAX_STOPS 长度数组,否则未初始化元素默认为 0
|
|
3855
|
+
// 会导致着色器循环中 t >= 0 始终为 true,返回黑色
|
|
3856
|
+
if(this.program.uniforms.u_gradient_offsets) {
|
|
3857
|
+
const offsets = new Float32Array(MAX_STOPS);
|
|
3858
|
+
for(let i = 0; i < params.stopCount; i++) {
|
|
3859
|
+
offsets[i] = params.stops[i * 5];
|
|
3860
|
+
}
|
|
3861
|
+
// 用 2.0 填充剩余项,使 t(0~1) >= 2.0 为 false,不会被匹配
|
|
3862
|
+
for(let i = params.stopCount; i < MAX_STOPS; i++) {
|
|
3863
|
+
offsets[i] = 2.0;
|
|
3864
|
+
}
|
|
3865
|
+
this.context.uniform1fv(this.program.uniforms.u_gradient_offsets.location, offsets);
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
// 设置每个 stop 的颜色 (rgba)
|
|
3869
|
+
if(this.program.uniforms.u_gradient_colors) {
|
|
3870
|
+
const colors = new Float32Array(MAX_STOPS * 4);
|
|
3871
|
+
for(let i = 0; i < params.stopCount; i++) {
|
|
3872
|
+
colors[i * 4 + 0] = params.stops[i * 5 + 1]; // r
|
|
3873
|
+
colors[i * 4 + 1] = params.stops[i * 5 + 2]; // g
|
|
3874
|
+
colors[i * 4 + 2] = params.stops[i * 5 + 3]; // b
|
|
3875
|
+
colors[i * 4 + 3] = params.stops[i * 5 + 4]; // a
|
|
3876
|
+
}
|
|
3877
|
+
// 用最后一个 stop 的颜色填充剩余项,确保不会返回黑色
|
|
3878
|
+
if(params.stopCount > 0) {
|
|
3879
|
+
const lastR = params.stops[(params.stopCount - 1) * 5 + 1];
|
|
3880
|
+
const lastG = params.stops[(params.stopCount - 1) * 5 + 2];
|
|
3881
|
+
const lastB = params.stops[(params.stopCount - 1) * 5 + 3];
|
|
3882
|
+
const lastA = params.stops[(params.stopCount - 1) * 5 + 4];
|
|
3883
|
+
for(let i = params.stopCount; i < MAX_STOPS; i++) {
|
|
3884
|
+
colors[i * 4 + 0] = lastR;
|
|
3885
|
+
colors[i * 4 + 1] = lastG;
|
|
3886
|
+
colors[i * 4 + 2] = lastB;
|
|
3887
|
+
colors[i * 4 + 3] = lastA;
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
this.context.uniform4fv(this.program.uniforms.u_gradient_colors.location, colors);
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
// 填充多边形(需要纹理坐标来计算渐变位置)
|
|
3894
|
+
this.fillPolygons(points, true);
|
|
3895
|
+
this.disableVertexAttribArray(this.program.attrs.a_text_coord);
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3493
3898
|
// 区域填充图片
|
|
3494
3899
|
// points绘制的图形顶点
|
|
3495
3900
|
// 图片整体绘制区域
|
|
3496
3901
|
fillImage(img, points, bounds) {
|
|
3497
3902
|
if(!img) return;
|
|
3498
3903
|
|
|
3499
|
-
//
|
|
3500
|
-
|
|
3904
|
+
// 对于 ImageData,生成缓存 key(基于渐变参数或 bounds),复用纹理
|
|
3905
|
+
let texture = null;
|
|
3906
|
+
if(img instanceof ImageData) {
|
|
3907
|
+
const key = `${img.width}_${img.height}_${bounds.width}_${bounds.height}_${bounds.left}_${bounds.top}`;
|
|
3908
|
+
if(this.__cachedTexture && this.__cachedTextureKey === key) {
|
|
3909
|
+
texture = this.__cachedTexture;
|
|
3910
|
+
} else {
|
|
3911
|
+
texture = this.createDataTexture(img);
|
|
3912
|
+
// 释放旧纹理
|
|
3913
|
+
if(this.__cachedTexture) {
|
|
3914
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3915
|
+
}
|
|
3916
|
+
this.__cachedTexture = texture;
|
|
3917
|
+
this.__cachedTextureKey = key;
|
|
3918
|
+
}
|
|
3919
|
+
} else {
|
|
3920
|
+
texture = this.createImgTexture(img);
|
|
3921
|
+
}
|
|
3501
3922
|
this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
|
|
3502
3923
|
|
|
3503
3924
|
// 指定纹理区域尺寸
|
|
@@ -3510,7 +3931,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3510
3931
|
|
|
3511
3932
|
this.fillTexture(points);
|
|
3512
3933
|
|
|
3513
|
-
|
|
3934
|
+
// 仅对非缓存纹理(非 ImageData)立即删除
|
|
3935
|
+
if(!(img instanceof ImageData)) {
|
|
3936
|
+
this.deleteTexture(texture);
|
|
3937
|
+
}
|
|
3514
3938
|
}
|
|
3515
3939
|
|
|
3516
3940
|
fillTexture(points) {
|
|
@@ -3526,23 +3950,90 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3526
3950
|
|
|
3527
3951
|
// 进行多边形填充
|
|
3528
3952
|
fillPolygons(points, isTexture = false) {
|
|
3529
|
-
if(points.length
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3953
|
+
if(points.length <= 3) {
|
|
3954
|
+
// 3个点以下的三角形直接画
|
|
3955
|
+
this.writePoints(points);
|
|
3956
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3957
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3958
|
+
return;
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
// 规则图形(凸多边形,如圆):直接用 TRIANGLE_FAN 一次性绘制,无需 earcut
|
|
3962
|
+
if(this.isRegular) {
|
|
3963
|
+
// 检查是否有 moveTo 标记,如果有说明路径包含多个子路径(如空心圆弧 jmHArc)
|
|
3964
|
+
const hasMoveTo = points.some && points.some(p => p.m);
|
|
3965
|
+
if(hasMoveTo) {
|
|
3966
|
+
// 有 m 标记:按 m 标记拆分子路径
|
|
3967
|
+
const { outerPoints, holes } = this.splitSubPaths(points);
|
|
3968
|
+
this.fillWithHoles(outerPoints, holes, isTexture);
|
|
3969
|
+
return;
|
|
3970
|
+
}
|
|
3971
|
+
// 无 m 标记但 needCut=true 表示空心形状(如 jmHArc close=true)
|
|
3972
|
+
// 前半段为内弧,后半段为外弧(反向),按中点拆分
|
|
3973
|
+
if(this.needCut && points.length >= 6) {
|
|
3974
|
+
const mid = Math.floor(points.length / 2);
|
|
3975
|
+
const inner = points.slice(0, mid);
|
|
3976
|
+
const outer = points.slice(mid);
|
|
3977
|
+
const innerArea = Math.abs(this.polygonArea(inner));
|
|
3978
|
+
const outerArea = Math.abs(this.polygonArea(outer));
|
|
3979
|
+
if(outerArea >= innerArea) {
|
|
3980
|
+
this.fillWithHoles(outer, [inner], isTexture);
|
|
3981
|
+
} else {
|
|
3982
|
+
this.fillWithHoles(inner, [outer], isTexture);
|
|
3534
3983
|
}
|
|
3984
|
+
return;
|
|
3535
3985
|
}
|
|
3986
|
+
this.writePoints(points);
|
|
3987
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3988
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3989
|
+
return;
|
|
3536
3990
|
}
|
|
3537
|
-
else {
|
|
3538
|
-
const buffer = this.writePoints(points);
|
|
3539
|
-
// 纹理坐标
|
|
3540
|
-
const coordBuffer = isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3541
3991
|
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3992
|
+
// 不规则图形:需要 earcut 三角化后,合并为一个大的顶点缓冲区,单次 drawArrays
|
|
3993
|
+
const triangles = this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
|
|
3994
|
+
if(!triangles.length) return;
|
|
3995
|
+
|
|
3996
|
+
// 合并所有三角形的顶点到一个数组
|
|
3997
|
+
const allVertices = [];
|
|
3998
|
+
const allTexCoords = [];
|
|
3999
|
+
for(const triangle of triangles) {
|
|
4000
|
+
for(const p of triangle) {
|
|
4001
|
+
allVertices.push(p.x, p.y);
|
|
4002
|
+
if(isTexture) allTexCoords.push(p.x, p.y);
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
// 一次性上传所有数据并绘制
|
|
4007
|
+
const vertexData = new Float32Array(allVertices);
|
|
4008
|
+
const gl = this.context;
|
|
4009
|
+
|
|
4010
|
+
// 复用或创建 position buffer
|
|
4011
|
+
let posBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_position);
|
|
4012
|
+
if(!posBuffer) {
|
|
4013
|
+
posBuffer = this.createFloat32Buffer(vertexData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
4014
|
+
posBuffer.attr = this.program.attrs.a_position;
|
|
4015
|
+
this.__cachedBuffers.push(posBuffer);
|
|
4016
|
+
} else {
|
|
4017
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer.buffer);
|
|
4018
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.DYNAMIC_DRAW);
|
|
4019
|
+
}
|
|
4020
|
+
this.writeVertexAttrib(posBuffer, this.program.attrs.a_position, 2, 0, 0);
|
|
4021
|
+
|
|
4022
|
+
if(isTexture && allTexCoords.length) {
|
|
4023
|
+
const texData = new Float32Array(allTexCoords);
|
|
4024
|
+
let texBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_text_coord);
|
|
4025
|
+
if(!texBuffer) {
|
|
4026
|
+
texBuffer = this.createFloat32Buffer(texData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
4027
|
+
texBuffer.attr = this.program.attrs.a_text_coord;
|
|
4028
|
+
this.__cachedBuffers.push(texBuffer);
|
|
4029
|
+
} else {
|
|
4030
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texBuffer.buffer);
|
|
4031
|
+
gl.bufferData(gl.ARRAY_BUFFER, texData, gl.DYNAMIC_DRAW);
|
|
4032
|
+
}
|
|
4033
|
+
this.writeVertexAttrib(texBuffer, this.program.attrs.a_text_coord, 2, 0, 0);
|
|
3545
4034
|
}
|
|
4035
|
+
|
|
4036
|
+
gl.drawArrays(gl.TRIANGLES, 0, allVertices.length / 2);
|
|
3546
4037
|
}
|
|
3547
4038
|
|
|
3548
4039
|
// 填充图形
|
|
@@ -3559,46 +4050,73 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3559
4050
|
}
|
|
3560
4051
|
|
|
3561
4052
|
drawText(text, x, y, bounds) {
|
|
3562
|
-
|
|
4053
|
+
// 文本渲染仍需要 2D canvas 绘制字形,然后作为纹理上传
|
|
4054
|
+
// 使用临时 canvas,不依赖共享的 textureCanvas
|
|
4055
|
+
if(!bounds.width || !bounds.height) return null;
|
|
4056
|
+
if(typeof document === 'undefined') return null;
|
|
4057
|
+
|
|
4058
|
+
let canvas = this.__textCanvas;
|
|
3563
4059
|
if(!canvas) {
|
|
3564
|
-
|
|
4060
|
+
canvas = document.createElement('canvas');
|
|
4061
|
+
this.__textCanvas = canvas;
|
|
3565
4062
|
}
|
|
3566
4063
|
canvas.width = bounds.width;
|
|
3567
4064
|
canvas.height = bounds.height;
|
|
3568
4065
|
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
}
|
|
4066
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
4067
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
3572
4068
|
|
|
3573
|
-
this.textureContext.clearRect(0, 0, canvas.width, canvas.height);
|
|
3574
4069
|
// 修改字体
|
|
3575
|
-
|
|
4070
|
+
ctx.font = this.style.font || (this.style.fontSize + 'px ' + this.style.fontFamily);
|
|
3576
4071
|
|
|
3577
4072
|
x -= bounds.left;
|
|
3578
4073
|
y -= bounds.top;
|
|
3579
4074
|
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
4075
|
+
// 设置文本样式
|
|
4076
|
+
if(this.style.fillStyle) {
|
|
4077
|
+
ctx.fillStyle = this.graph.utils.toColor(this.style.fillStyle);
|
|
4078
|
+
}
|
|
4079
|
+
if(this.style.strokeStyle) {
|
|
4080
|
+
ctx.strokeStyle = this.graph.utils.toColor(this.style.strokeStyle);
|
|
4081
|
+
}
|
|
4082
|
+
if(this.style.shadowColor) {
|
|
4083
|
+
ctx.shadowColor = this.graph.utils.toColor(this.style.shadowColor);
|
|
4084
|
+
}
|
|
4085
|
+
if(this.style.shadowBlur) {
|
|
4086
|
+
ctx.shadowBlur = this.style.shadowBlur;
|
|
4087
|
+
}
|
|
4088
|
+
if(this.style.shadowOffsetX !== undefined) {
|
|
4089
|
+
ctx.shadowOffsetX = this.style.shadowOffsetX;
|
|
4090
|
+
}
|
|
4091
|
+
if(this.style.shadowOffsetY !== undefined) {
|
|
4092
|
+
ctx.shadowOffsetY = this.style.shadowOffsetY;
|
|
4093
|
+
}
|
|
4094
|
+
if(this.style.textAlign) {
|
|
4095
|
+
ctx.textAlign = this.style.textAlign;
|
|
4096
|
+
}
|
|
4097
|
+
if(this.style.textBaseline) {
|
|
4098
|
+
ctx.textBaseline = this.style.textBaseline;
|
|
4099
|
+
}
|
|
3583
4100
|
|
|
4101
|
+
if(this.style.fillStyle && ctx.fillText) {
|
|
3584
4102
|
if(this.style.maxWidth) {
|
|
3585
|
-
|
|
4103
|
+
ctx.fillText(text, x, y, this.style.maxWidth);
|
|
3586
4104
|
}
|
|
3587
4105
|
else {
|
|
3588
|
-
|
|
4106
|
+
ctx.fillText(text, x, y);
|
|
3589
4107
|
}
|
|
3590
4108
|
}
|
|
3591
|
-
if(this.
|
|
3592
|
-
|
|
4109
|
+
if(this.style.strokeStyle && ctx.strokeText) {
|
|
3593
4110
|
if(this.style.maxWidth) {
|
|
3594
|
-
|
|
4111
|
+
ctx.strokeText(text, x, y, this.style.maxWidth);
|
|
3595
4112
|
}
|
|
3596
4113
|
else {
|
|
3597
|
-
|
|
4114
|
+
ctx.strokeText(text, x, y);
|
|
3598
4115
|
}
|
|
3599
4116
|
}
|
|
4117
|
+
|
|
3600
4118
|
// 用纹理图片代替文字
|
|
3601
|
-
const data =
|
|
4119
|
+
const data = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
3602
4120
|
this.fillImage(data, this.points, bounds);
|
|
3603
4121
|
}
|
|
3604
4122
|
}
|
|
@@ -3624,7 +4142,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3624
4142
|
'shadowOffsetY' : 'shadowOffsetY',
|
|
3625
4143
|
'shadowColor' : 'shadowColor',
|
|
3626
4144
|
'lineJoin': 'lineJoin',
|
|
3627
|
-
'lineCap':'lineCap'
|
|
4145
|
+
'lineCap':'lineCap',
|
|
4146
|
+
'lineDashOffset': 'lineDashOffset',
|
|
4147
|
+
'globalCompositeOperation': 'globalCompositeOperation'
|
|
3628
4148
|
};
|
|
3629
4149
|
|
|
3630
4150
|
class jmControl extends jmProperty {
|
|
@@ -3835,7 +4355,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3835
4355
|
}
|
|
3836
4356
|
|
|
3837
4357
|
setStyle(style) {
|
|
3838
|
-
|
|
4358
|
+
if(!style) {
|
|
4359
|
+
style = this.style;
|
|
4360
|
+
}
|
|
3839
4361
|
if(!style) return;
|
|
3840
4362
|
|
|
3841
4363
|
const __setStyle = (style, name, mpkey) => {
|
|
@@ -3919,6 +4441,120 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3919
4441
|
this.cursor = styleValue;
|
|
3920
4442
|
break;
|
|
3921
4443
|
}
|
|
4444
|
+
// ===== 新增样式特性 =====
|
|
4445
|
+
|
|
4446
|
+
// 虚线样式:支持自定义lineDash模式 (如 [5, 3, 2] 或 "5,3,2")
|
|
4447
|
+
case 'lineDash' : {
|
|
4448
|
+
if(!this.context.setLineDash) break;
|
|
4449
|
+
let dash;
|
|
4450
|
+
if(typeof styleValue === 'string') {
|
|
4451
|
+
dash = styleValue.split(',').map(v => parseFloat(v.trim())).filter(v => !isNaN(v));
|
|
4452
|
+
}
|
|
4453
|
+
else if(Array.isArray(styleValue)) {
|
|
4454
|
+
dash = styleValue.map(v => parseFloat(v)).filter(v => !isNaN(v));
|
|
4455
|
+
}
|
|
4456
|
+
if(dash && dash.length) {
|
|
4457
|
+
this.context.setLineDash(dash);
|
|
4458
|
+
}
|
|
4459
|
+
else {
|
|
4460
|
+
this.context.setLineDash([]);
|
|
4461
|
+
}
|
|
4462
|
+
break;
|
|
4463
|
+
}
|
|
4464
|
+
// 虚线偏移量
|
|
4465
|
+
case 'lineDashOffset' : {
|
|
4466
|
+
if(!this.context.setLineDash) break;
|
|
4467
|
+
this.context.lineDashOffset = Number(styleValue) || 0;
|
|
4468
|
+
break;
|
|
4469
|
+
}
|
|
4470
|
+
// CSS滤镜效果 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
4471
|
+
case 'filter' : {
|
|
4472
|
+
if(this.context.filter === undefined) break;
|
|
4473
|
+
if(styleValue instanceof jmFilter) {
|
|
4474
|
+
this.context.filter = styleValue.toCanvasFilter();
|
|
4475
|
+
}
|
|
4476
|
+
else if(typeof styleValue === 'string') {
|
|
4477
|
+
this.context.filter = styleValue || 'none';
|
|
4478
|
+
}
|
|
4479
|
+
else if(typeof styleValue === 'object') {
|
|
4480
|
+
this.context.filter = (new jmFilter(styleValue)).toCanvasFilter();
|
|
4481
|
+
}
|
|
4482
|
+
break;
|
|
4483
|
+
}
|
|
4484
|
+
// 混合模式 (source-over, multiply, screen, overlay, darken, lighten, etc.)
|
|
4485
|
+
case 'globalCompositeOperation' : {
|
|
4486
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4487
|
+
this.context.globalCompositeOperation = styleValue;
|
|
4488
|
+
break;
|
|
4489
|
+
}
|
|
4490
|
+
// 裁剪路径:通过canvas clip实现
|
|
4491
|
+
case 'clipPath' : {
|
|
4492
|
+
if(!this.context.clip) break;
|
|
4493
|
+
// clipPath可以是一个图形控件实例
|
|
4494
|
+
if(styleValue && styleValue.points && styleValue.points.length > 0) {
|
|
4495
|
+
const bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
4496
|
+
this.context.beginPath();
|
|
4497
|
+
this.context.moveTo(styleValue.points[0].x + (bounds ? bounds.left : 0), styleValue.points[0].y + (bounds ? bounds.top : 0));
|
|
4498
|
+
for(let i = 1; i < styleValue.points.length; i++) {
|
|
4499
|
+
if(styleValue.points[i].m) {
|
|
4500
|
+
this.context.moveTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4501
|
+
}
|
|
4502
|
+
else {
|
|
4503
|
+
this.context.lineTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4504
|
+
}
|
|
4505
|
+
}
|
|
4506
|
+
if(styleValue.style && styleValue.style.close) {
|
|
4507
|
+
this.context.closePath();
|
|
4508
|
+
}
|
|
4509
|
+
this.context.clip();
|
|
4510
|
+
}
|
|
4511
|
+
break;
|
|
4512
|
+
}
|
|
4513
|
+
// 遮罩效果:通过globalCompositeOperation + destination-in实现
|
|
4514
|
+
case 'mask' : {
|
|
4515
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4516
|
+
// mask是一个图形控件实例,在绘制前需要先应用mask
|
|
4517
|
+
// 这里只是标记,实际绘制在paint流程中处理
|
|
4518
|
+
this.__mask = styleValue;
|
|
4519
|
+
break;
|
|
4520
|
+
}
|
|
4521
|
+
// 图片阴影描边阴影(WebGL纹理canvas用)
|
|
4522
|
+
case 'shadowColor' : {
|
|
4523
|
+
if(this.webglControl) {
|
|
4524
|
+
this.webglControl.setStyle('shadowColor', styleValue);
|
|
4525
|
+
}
|
|
4526
|
+
else {
|
|
4527
|
+
this.context.shadowColor = jmUtils.toColor(styleValue);
|
|
4528
|
+
}
|
|
4529
|
+
break;
|
|
4530
|
+
}
|
|
4531
|
+
case 'shadowBlur' : {
|
|
4532
|
+
if(this.webglControl) {
|
|
4533
|
+
this.webglControl.setStyle('shadowBlur', styleValue);
|
|
4534
|
+
}
|
|
4535
|
+
else {
|
|
4536
|
+
this.context.shadowBlur = Number(styleValue) || 0;
|
|
4537
|
+
}
|
|
4538
|
+
break;
|
|
4539
|
+
}
|
|
4540
|
+
case 'shadowOffsetX' : {
|
|
4541
|
+
if(this.webglControl) {
|
|
4542
|
+
this.webglControl.setStyle('shadowOffsetX', styleValue);
|
|
4543
|
+
}
|
|
4544
|
+
else {
|
|
4545
|
+
this.context.shadowOffsetX = Number(styleValue) || 0;
|
|
4546
|
+
}
|
|
4547
|
+
break;
|
|
4548
|
+
}
|
|
4549
|
+
case 'shadowOffsetY' : {
|
|
4550
|
+
if(this.webglControl) {
|
|
4551
|
+
this.webglControl.setStyle('shadowOffsetY', styleValue);
|
|
4552
|
+
}
|
|
4553
|
+
else {
|
|
4554
|
+
this.context.shadowOffsetY = Number(styleValue) || 0;
|
|
4555
|
+
}
|
|
4556
|
+
break;
|
|
4557
|
+
}
|
|
3922
4558
|
}
|
|
3923
4559
|
}
|
|
3924
4560
|
}
|
|
@@ -3939,6 +4575,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3939
4575
|
else if(t == 'string' && k == 'shadow') {
|
|
3940
4576
|
style[k] = new jmShadow(style[k]);
|
|
3941
4577
|
}
|
|
4578
|
+
else if(t == 'string' && k == 'filter') {
|
|
4579
|
+
style[k] = new jmFilter(style[k]);
|
|
4580
|
+
}
|
|
3942
4581
|
__setStyle(style[k], k);
|
|
3943
4582
|
}
|
|
3944
4583
|
}
|
|
@@ -4083,25 +4722,30 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4083
4722
|
* @method getLocation
|
|
4084
4723
|
* @return {object} 当前控件位置参数,包括中心点坐标,右上角坐标,宽高
|
|
4085
4724
|
*/
|
|
4086
|
-
getLocation(
|
|
4725
|
+
getLocation() {
|
|
4087
4726
|
//如果已经计算过则直接返回
|
|
4088
4727
|
//在开画之前会清空此对象
|
|
4089
4728
|
//if(reset !== true && this.location) return this.location;
|
|
4090
4729
|
|
|
4091
4730
|
let local = this.location = {left: 0,top: 0,width: 0,height: 0};
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4731
|
+
|
|
4732
|
+
// 检查是否有百分比参数需要解析,没有则直接引用避免克隆开销
|
|
4733
|
+
const needResolve = this.parent && (jmUtils.checkPercent(this.width) || jmUtils.checkPercent(this.height) ||
|
|
4734
|
+
(this.position && jmUtils.checkPercent(this.position.x)) || (this.position && jmUtils.checkPercent(this.position.y)));
|
|
4735
|
+
local.position = typeof this.position == 'function'? this.position(): (needResolve? jmUtils.clone(this.position) : this.position);
|
|
4736
|
+
local.center = this.center && typeof this.center === 'function'?this.center(): (needResolve? jmUtils.clone(this.center) : this.center);//中心
|
|
4737
|
+
local.start = this.start && typeof this.start === 'function'?this.start(): (needResolve? jmUtils.clone(this.start) : this.start);//起点
|
|
4738
|
+
local.end = this.end && typeof this.end === 'function'?this.end(): (needResolve? jmUtils.clone(this.end) : this.end);//起点
|
|
4096
4739
|
local.radius = this.radius;//半径
|
|
4097
4740
|
local.width = this.width;
|
|
4098
4741
|
local.height = this.height;
|
|
4099
4742
|
|
|
4100
|
-
const margin =
|
|
4101
|
-
margin.
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4743
|
+
const margin = this.style.margin;
|
|
4744
|
+
const marginObj = needResolve && margin ? jmUtils.clone(margin, {}) : (margin || {});
|
|
4745
|
+
marginObj.left = (marginObj.left || 0);
|
|
4746
|
+
marginObj.top = (marginObj.top || 0);
|
|
4747
|
+
marginObj.right = (marginObj.right || 0);
|
|
4748
|
+
marginObj.bottom = (marginObj.bottom || 0);
|
|
4105
4749
|
|
|
4106
4750
|
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
4107
4751
|
if(local.position) {
|
|
@@ -4109,8 +4753,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4109
4753
|
local.top = local.position.y;
|
|
4110
4754
|
}
|
|
4111
4755
|
else {
|
|
4112
|
-
local.left =
|
|
4113
|
-
local.top =
|
|
4756
|
+
local.left = marginObj.left;
|
|
4757
|
+
local.top = marginObj.top;
|
|
4114
4758
|
}
|
|
4115
4759
|
|
|
4116
4760
|
if(this.parent) {
|
|
@@ -4372,22 +5016,31 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4372
5016
|
if(this.webglControl) this.webglControl.closePath();
|
|
4373
5017
|
this.context.closePath && this.context.closePath();
|
|
4374
5018
|
}
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
if(
|
|
4378
|
-
|
|
5019
|
+
|
|
5020
|
+
// 根据渲染模式选择不同的绘制路径
|
|
5021
|
+
if(this.webglControl) {
|
|
5022
|
+
// WebGL 模式:使用 WebGL 绘制
|
|
5023
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
5024
|
+
if(fill) {
|
|
4379
5025
|
const bounds = this.getBounds();
|
|
4380
5026
|
this.webglControl.fill(bounds);
|
|
4381
5027
|
}
|
|
4382
|
-
this.
|
|
5028
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
5029
|
+
this.webglControl.stroke();
|
|
5030
|
+
}
|
|
5031
|
+
if(this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4383
5032
|
}
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
this.
|
|
5033
|
+
else {
|
|
5034
|
+
// 2D 模式:使用 Canvas 2D API 绘制
|
|
5035
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
5036
|
+
if(fill) {
|
|
5037
|
+
this.context.fill && this.context.fill();
|
|
5038
|
+
}
|
|
5039
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
5040
|
+
this.context.stroke && this.context.stroke();
|
|
5041
|
+
}
|
|
4387
5042
|
}
|
|
4388
5043
|
|
|
4389
|
-
if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4390
|
-
|
|
4391
5044
|
this.needUpdate = false;
|
|
4392
5045
|
}
|
|
4393
5046
|
|
|
@@ -4403,9 +5056,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4403
5056
|
const bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
4404
5057
|
if(this.webglControl) {
|
|
4405
5058
|
this.webglControl.setParentBounds(bounds);
|
|
4406
|
-
this.webglControl.draw(
|
|
4407
|
-
...this.points
|
|
4408
|
-
]);
|
|
5059
|
+
this.webglControl.draw(this.points);
|
|
4409
5060
|
}
|
|
4410
5061
|
else if(this.context && this.context.moveTo) {
|
|
4411
5062
|
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
@@ -4450,9 +5101,44 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4450
5101
|
|
|
4451
5102
|
this.setStyle();//设定样式
|
|
4452
5103
|
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
5104
|
+
// 应用mask遮罩效果:在mask区域内绘制当前控件
|
|
5105
|
+
// 使用 destination-in 合成模式,只保留mask区域内的内容
|
|
5106
|
+
const maskStyle = this.style.mask || this.__mask;
|
|
5107
|
+
if(maskStyle && maskStyle.points && this.context.globalCompositeOperation) {
|
|
5108
|
+
// 先绘制当前控件
|
|
5109
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
5110
|
+
if(needDraw && this.draw) this.draw();
|
|
5111
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
5112
|
+
|
|
5113
|
+
// 再应用mask裁剪
|
|
5114
|
+
this.context.globalCompositeOperation = 'destination-in';
|
|
5115
|
+
if(maskStyle.initPoints) maskStyle.initPoints();
|
|
5116
|
+
const mBounds = maskStyle.parent && maskStyle.parent.absoluteBounds ? maskStyle.parent.absoluteBounds : this.absoluteBounds;
|
|
5117
|
+
this.context.beginPath();
|
|
5118
|
+
if(maskStyle.points && maskStyle.points.length > 0) {
|
|
5119
|
+
this.context.moveTo(maskStyle.points[0].x + (mBounds ? mBounds.left : 0), maskStyle.points[0].y + (mBounds ? mBounds.top : 0));
|
|
5120
|
+
for(let i = 1; i < maskStyle.points.length; i++) {
|
|
5121
|
+
if(maskStyle.points[i].m) {
|
|
5122
|
+
this.context.moveTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
5123
|
+
}
|
|
5124
|
+
else {
|
|
5125
|
+
this.context.lineTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
if(maskStyle.style && maskStyle.style.close) {
|
|
5129
|
+
this.context.closePath();
|
|
5130
|
+
}
|
|
5131
|
+
}
|
|
5132
|
+
this.context.fillStyle = '#ffffff';
|
|
5133
|
+
this.context.fill();
|
|
5134
|
+
// 恢复合成模式
|
|
5135
|
+
this.context.globalCompositeOperation = 'source-over';
|
|
5136
|
+
}
|
|
5137
|
+
else {
|
|
5138
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
5139
|
+
if(needDraw && this.draw) this.draw();
|
|
5140
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
5141
|
+
}
|
|
4456
5142
|
|
|
4457
5143
|
if(this.children) {
|
|
4458
5144
|
this.children.each(function(i,item) {
|
|
@@ -4542,7 +5228,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4542
5228
|
* @param {array} args 事件参数数组
|
|
4543
5229
|
*/
|
|
4544
5230
|
emit(...args) {
|
|
4545
|
-
|
|
5231
|
+
// 避免每帧 args.slice(1) 分配临时数组
|
|
5232
|
+
// runEventHandle 内部会把非数组参数包装成数组
|
|
5233
|
+
if(args.length > 2) {
|
|
5234
|
+
this.runEventHandle(args[0], args.slice(1));
|
|
5235
|
+
} else if(args.length === 2) {
|
|
5236
|
+
this.runEventHandle(args[0], [args[1]]);
|
|
5237
|
+
} else {
|
|
5238
|
+
this.runEventHandle(args[0], []);
|
|
5239
|
+
}
|
|
4546
5240
|
return this;
|
|
4547
5241
|
}
|
|
4548
5242
|
|
|
@@ -5182,7 +5876,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5182
5876
|
if((mw == 0 && mh == 0) || start == end) return;
|
|
5183
5877
|
|
|
5184
5878
|
let anticlockwise = this.anticlockwise;
|
|
5185
|
-
this.points = [];
|
|
5186
5879
|
let step = 1 / Math.max(mw, mh);
|
|
5187
5880
|
|
|
5188
5881
|
//如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
|
|
@@ -5193,18 +5886,33 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5193
5886
|
}
|
|
5194
5887
|
if(start > end) step = -step;
|
|
5195
5888
|
|
|
5196
|
-
|
|
5889
|
+
// 预计算需要的点数量
|
|
5890
|
+
let pointCount = Math.ceil(Math.abs(end - start) / Math.abs(step)) + 1;
|
|
5891
|
+
if(this.isFan) pointCount++;
|
|
5892
|
+
|
|
5893
|
+
// 复用已有数组,避免每帧分配;大小变化时才重建
|
|
5894
|
+
if(!this.points || this.points.length !== pointCount) {
|
|
5895
|
+
this.points = new Array(pointCount);
|
|
5896
|
+
for(let i = 0; i < pointCount; i++) {
|
|
5897
|
+
this.points[i] = { x: 0, y: 0 };
|
|
5898
|
+
}
|
|
5899
|
+
}
|
|
5900
|
+
|
|
5901
|
+
let idx = 0;
|
|
5902
|
+
if(this.isFan) {
|
|
5903
|
+
this.points[idx].x = location.center.x;
|
|
5904
|
+
this.points[idx].y = location.center.y;
|
|
5905
|
+
idx++;
|
|
5906
|
+
}
|
|
5197
5907
|
|
|
5198
5908
|
//椭圆方程x=a*cos(r) ,y=b*sin(r)
|
|
5199
5909
|
for(let r=start;;r += step) {
|
|
5200
5910
|
if(step > 0 && r > end) r = end;
|
|
5201
5911
|
else if(step < 0 && r < end) r = end;
|
|
5202
5912
|
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
};
|
|
5207
|
-
this.points.push(p);
|
|
5913
|
+
this.points[idx].x = Math.cos(r) * mw + cx;
|
|
5914
|
+
this.points[idx].y = Math.sin(r) * mh + cy;
|
|
5915
|
+
idx++;
|
|
5208
5916
|
|
|
5209
5917
|
if(r == end) break;
|
|
5210
5918
|
}
|
|
@@ -5641,8 +6349,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5641
6349
|
|
|
5642
6350
|
maxps.reverse();//大圆逆序
|
|
5643
6351
|
if(!this.style || !this.style.close) {
|
|
5644
|
-
maxps[0].m = true
|
|
5645
|
-
}
|
|
6352
|
+
maxps[0].m = true;//非闭合时标记 moveTo,分隔内外两个子路径
|
|
6353
|
+
}
|
|
5646
6354
|
this.points = minps.concat(maxps);
|
|
5647
6355
|
}
|
|
5648
6356
|
}
|
|
@@ -5803,6 +6511,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5803
6511
|
* @class jmRect
|
|
5804
6512
|
* @extends jmPath
|
|
5805
6513
|
* @param {object} params 参数 position=矩形左上角顶点坐标,width=宽,height=高,radius=边角弧度
|
|
6514
|
+
* radius支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
5806
6515
|
*/
|
|
5807
6516
|
class jmRect extends jmPath {
|
|
5808
6517
|
|
|
@@ -5812,12 +6521,24 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5812
6521
|
super(params, t);
|
|
5813
6522
|
|
|
5814
6523
|
this.style.close = true;
|
|
5815
|
-
|
|
6524
|
+
const r = params.radius || this.style.radius || this.style.borderRadius || 0;
|
|
6525
|
+
if(typeof r === 'object' && r !== null) {
|
|
6526
|
+
// 四角独立圆角
|
|
6527
|
+
this.radius = {
|
|
6528
|
+
topLeft: Number(r.topLeft) || 0,
|
|
6529
|
+
topRight: Number(r.topRight) || 0,
|
|
6530
|
+
bottomRight: Number(r.bottomRight) || 0,
|
|
6531
|
+
bottomLeft: Number(r.bottomLeft) || 0
|
|
6532
|
+
};
|
|
6533
|
+
}
|
|
6534
|
+
else {
|
|
6535
|
+
this.radius = r;
|
|
6536
|
+
}
|
|
5816
6537
|
}
|
|
5817
6538
|
/**
|
|
5818
|
-
*
|
|
6539
|
+
* 圆角半径,支持数字或四角独立对象
|
|
5819
6540
|
* @property radius
|
|
5820
|
-
* @type {number}
|
|
6541
|
+
* @type {number|object}
|
|
5821
6542
|
*/
|
|
5822
6543
|
get radius() {
|
|
5823
6544
|
return this.property('radius');
|
|
@@ -5825,6 +6546,36 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5825
6546
|
set radius(v) {
|
|
5826
6547
|
this.needUpdate = true;
|
|
5827
6548
|
return this.property('radius', v);
|
|
6549
|
+
}
|
|
6550
|
+
|
|
6551
|
+
/**
|
|
6552
|
+
* 获取规范化的圆角值(四角独立)
|
|
6553
|
+
* @returns {object} { topLeft, topRight, bottomRight, bottomLeft }
|
|
6554
|
+
*/
|
|
6555
|
+
getNormalizedRadius() {
|
|
6556
|
+
const r = this.radius;
|
|
6557
|
+
if(typeof r === 'number') {
|
|
6558
|
+
const v = Math.max(0, r);
|
|
6559
|
+
return { topLeft: v, topRight: v, bottomRight: v, bottomLeft: v };
|
|
6560
|
+
}
|
|
6561
|
+
if(typeof r === 'object' && r !== null) {
|
|
6562
|
+
return {
|
|
6563
|
+
topLeft: Math.max(0, Number(r.topLeft) || 0),
|
|
6564
|
+
topRight: Math.max(0, Number(r.topRight) || 0),
|
|
6565
|
+
bottomRight: Math.max(0, Number(r.bottomRight) || 0),
|
|
6566
|
+
bottomLeft: Math.max(0, Number(r.bottomLeft) || 0)
|
|
6567
|
+
};
|
|
6568
|
+
}
|
|
6569
|
+
return { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 };
|
|
6570
|
+
}
|
|
6571
|
+
|
|
6572
|
+
/**
|
|
6573
|
+
* 检查是否有圆角
|
|
6574
|
+
* @returns {boolean}
|
|
6575
|
+
*/
|
|
6576
|
+
hasRadius() {
|
|
6577
|
+
const nr = this.getNormalizedRadius();
|
|
6578
|
+
return nr.topLeft > 0 || nr.topRight > 0 || nr.bottomRight > 0 || nr.bottomLeft > 0;
|
|
5828
6579
|
}
|
|
5829
6580
|
|
|
5830
6581
|
/**
|
|
@@ -5887,7 +6638,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5887
6638
|
|
|
5888
6639
|
/**
|
|
5889
6640
|
* 初始化图形点
|
|
5890
|
-
*
|
|
6641
|
+
* 支持四角独立圆角,借助圆弧对象计算描点
|
|
5891
6642
|
*
|
|
5892
6643
|
* @method initPoints
|
|
5893
6644
|
* @private
|
|
@@ -5904,32 +6655,67 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5904
6655
|
this.dottedLine = this.graph.createShape(jmLine, {style: this.style});
|
|
5905
6656
|
}
|
|
5906
6657
|
|
|
5907
|
-
|
|
5908
|
-
|
|
6658
|
+
const nr = this.getNormalizedRadius();
|
|
6659
|
+
const hasRadius = this.hasRadius();
|
|
6660
|
+
|
|
6661
|
+
// 如果有圆角(支持四角独立),借助圆弧对象计算描点
|
|
6662
|
+
if(hasRadius) {
|
|
5909
6663
|
let q = Math.PI / 2;
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
6664
|
+
|
|
6665
|
+
// 限制圆角不超过短边的一半
|
|
6666
|
+
const maxR = Math.min(location.width / 2, location.height / 2);
|
|
6667
|
+
const rtl = Math.min(nr.topLeft, maxR);
|
|
6668
|
+
const rtr = Math.min(nr.topRight, maxR);
|
|
6669
|
+
const rbr = Math.min(nr.bottomRight, maxR);
|
|
6670
|
+
const rbl = Math.min(nr.bottomLeft, maxR);
|
|
6671
|
+
|
|
6672
|
+
// 左上角圆弧
|
|
6673
|
+
if(rtl > 0) {
|
|
6674
|
+
let arc = this.graph.createShape(jmArc,{radius:rtl,anticlockwise:false});
|
|
6675
|
+
arc.center = {x:location.left + rtl, y:location.top + rtl};
|
|
6676
|
+
arc.startAngle = Math.PI;
|
|
6677
|
+
arc.endAngle = Math.PI + q;
|
|
6678
|
+
var ps1 = arc.initPoints();
|
|
6679
|
+
}
|
|
6680
|
+
else {
|
|
6681
|
+
var ps1 = [p1];
|
|
6682
|
+
}
|
|
6683
|
+
|
|
6684
|
+
// 右上角圆弧
|
|
6685
|
+
if(rtr > 0) {
|
|
6686
|
+
let arc = this.graph.createShape(jmArc,{radius:rtr,anticlockwise:false});
|
|
6687
|
+
arc.center = {x:p2.x - rtr, y:p2.y + rtr};
|
|
6688
|
+
arc.startAngle = Math.PI + q;
|
|
6689
|
+
arc.endAngle = Math.PI * 2;
|
|
6690
|
+
var ps2 = arc.initPoints();
|
|
6691
|
+
}
|
|
6692
|
+
else {
|
|
6693
|
+
var ps2 = [p2];
|
|
6694
|
+
}
|
|
6695
|
+
|
|
6696
|
+
// 右下角圆弧
|
|
6697
|
+
if(rbr > 0) {
|
|
6698
|
+
let arc = this.graph.createShape(jmArc,{radius:rbr,anticlockwise:false});
|
|
6699
|
+
arc.center = {x:p3.x - rbr, y:p3.y - rbr};
|
|
6700
|
+
arc.startAngle = 0;
|
|
6701
|
+
arc.endAngle = q;
|
|
6702
|
+
var ps3 = arc.initPoints();
|
|
6703
|
+
}
|
|
6704
|
+
else {
|
|
6705
|
+
var ps3 = [p3];
|
|
6706
|
+
}
|
|
6707
|
+
|
|
6708
|
+
// 左下角圆弧
|
|
6709
|
+
if(rbl > 0) {
|
|
6710
|
+
let arc = this.graph.createShape(jmArc,{radius:rbl,anticlockwise:false});
|
|
6711
|
+
arc.center = {x:p4.x + rbl, y:p4.y - rbl};
|
|
6712
|
+
arc.startAngle = q;
|
|
6713
|
+
arc.endAngle = Math.PI;
|
|
6714
|
+
var ps4 = arc.initPoints();
|
|
6715
|
+
}
|
|
6716
|
+
else {
|
|
6717
|
+
var ps4 = [p4];
|
|
6718
|
+
}
|
|
5933
6719
|
this.points = ps1.concat(ps2,ps3,ps4);
|
|
5934
6720
|
}
|
|
5935
6721
|
else {
|
|
@@ -6268,7 +7054,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
6268
7054
|
this.style.textAlign = this.style.textAlign || 'left';
|
|
6269
7055
|
//文字垂直对齐
|
|
6270
7056
|
this.style.textBaseline = this.style.textBaseline || 'middle';
|
|
6271
|
-
this.text = params.text || '';
|
|
7057
|
+
this.text = params.text || params.value || '';
|
|
6272
7058
|
|
|
6273
7059
|
this.center = params.center || null;
|
|
6274
7060
|
}
|
|
@@ -6557,67 +7343,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
6557
7343
|
}
|
|
6558
7344
|
}
|
|
6559
7345
|
}
|
|
6560
|
-
//如果有指定边框,则画出边框
|
|
6561
|
-
if(this.style.border) {
|
|
6562
|
-
//如果指定了边框样式
|
|
6563
|
-
if(this.style.border.style) {
|
|
6564
|
-
this.context.save && this.context.save();
|
|
6565
|
-
this.setStyle(this.style.border.style);
|
|
6566
|
-
}
|
|
6567
|
-
if(this.mode === '2d') {
|
|
6568
|
-
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
6569
|
-
if(this.style.border.top) {
|
|
6570
|
-
this.context.lineTo(this.points[1].x + bounds.left,this.points[1].y + bounds.top);
|
|
6571
|
-
}
|
|
6572
|
-
|
|
6573
|
-
if(this.style.border.right) {
|
|
6574
|
-
this.context.moveTo(this.points[1].x + bounds.left,this.points[1].y + bounds.top);
|
|
6575
|
-
this.context.lineTo(this.points[2].x + bounds.left,this.points[2].y + bounds.top);
|
|
6576
|
-
}
|
|
6577
|
-
|
|
6578
|
-
if(this.style.border.bottom) {
|
|
6579
|
-
this.context.moveTo(this.points[2].x + bounds.left,this.points[2].y + bounds.top);
|
|
6580
|
-
this.context.lineTo(this.points[3].x + bounds.left,this.points[3].y + bounds.top);
|
|
6581
|
-
}
|
|
6582
|
-
|
|
6583
|
-
if(this.style.border.left) {
|
|
6584
|
-
this.context.moveTo(this.points[3].x + bounds.left,this.points[3].y + bounds.top);
|
|
6585
|
-
this.context.lineTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
6586
|
-
}
|
|
6587
|
-
}
|
|
6588
|
-
else {
|
|
6589
|
-
const points = [];
|
|
6590
|
-
if(this.style.border.top) {
|
|
6591
|
-
points.push(this.points[0]);
|
|
6592
|
-
points.push(this.points[1]);
|
|
6593
|
-
}
|
|
6594
|
-
|
|
6595
|
-
if(this.style.border.right) {
|
|
6596
|
-
points.push({
|
|
6597
|
-
...this.points[1],
|
|
6598
|
-
m: true
|
|
6599
|
-
});
|
|
6600
|
-
points.push(this.points[2]);
|
|
6601
|
-
}
|
|
6602
|
-
|
|
6603
|
-
if(this.style.border.bottom) {
|
|
6604
|
-
points.push({
|
|
6605
|
-
...this.points[2],
|
|
6606
|
-
m: true
|
|
6607
|
-
});
|
|
6608
|
-
points.push(this.points[3]);
|
|
6609
|
-
}
|
|
6610
|
-
|
|
6611
|
-
if(this.style.border.left) {
|
|
6612
|
-
points.push({
|
|
6613
|
-
...this.points[3],
|
|
6614
|
-
m: true
|
|
6615
|
-
});
|
|
6616
|
-
points.push(this.points[0]);
|
|
6617
|
-
}
|
|
6618
|
-
points.length && this.webglControl && this.webglControl.stroke(points);
|
|
6619
|
-
}
|
|
6620
|
-
}
|
|
6621
7346
|
}
|
|
6622
7347
|
|
|
6623
7348
|
endDraw() {
|
|
@@ -7566,145 +8291,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7566
8291
|
}
|
|
7567
8292
|
}
|
|
7568
8293
|
|
|
7569
|
-
/**
|
|
7570
|
-
* 图层类
|
|
7571
|
-
* 用于组织和管理图形对象,支持可见性和锁定控制
|
|
7572
|
-
* 图层可以包含多个图形对象,并控制它们的显示和交互
|
|
7573
|
-
*
|
|
7574
|
-
* @class jmLayer
|
|
7575
|
-
* @extends jmControl
|
|
7576
|
-
* @param {object} params 图层参数
|
|
7577
|
-
* @param {string} [params.name] 图层名称,默认为 'Layer_${timestamp}'
|
|
7578
|
-
* @param {boolean} [params.visible=true] 图层是否可见
|
|
7579
|
-
* @param {boolean} [params.locked=false] 图层是否锁定(锁定后不可交互)
|
|
7580
|
-
* @param {jmGraph} [params.graph] 所属的画布对象
|
|
7581
|
-
*/
|
|
7582
|
-
class jmLayer extends jmControl {
|
|
7583
|
-
|
|
7584
|
-
constructor(params, t='jmLayer') {
|
|
7585
|
-
params = params || {};
|
|
7586
|
-
params.interactive = false; // 图层本身不响应交互事件
|
|
7587
|
-
super(params, t);
|
|
7588
|
-
|
|
7589
|
-
this.name = params.name || `Layer_${Date.now()}`;
|
|
7590
|
-
this.visible = params.visible !== false;
|
|
7591
|
-
this.locked = params.locked || false;
|
|
7592
|
-
}
|
|
7593
|
-
|
|
7594
|
-
/**
|
|
7595
|
-
* 图层名称
|
|
7596
|
-
* 图层的唯一标识符,用于查找和管理图层
|
|
7597
|
-
*
|
|
7598
|
-
* @property name
|
|
7599
|
-
* @type {string}
|
|
7600
|
-
*/
|
|
7601
|
-
get name() {
|
|
7602
|
-
return this.property('name');
|
|
7603
|
-
}
|
|
7604
|
-
set name(v) {
|
|
7605
|
-
if(!v || typeof v !== 'string') {
|
|
7606
|
-
console.warn('jmLayer: name must be a non-empty string');
|
|
7607
|
-
return;
|
|
7608
|
-
}
|
|
7609
|
-
return this.property('name', v);
|
|
7610
|
-
}
|
|
7611
|
-
|
|
7612
|
-
/**
|
|
7613
|
-
* 图层是否可见
|
|
7614
|
-
* 不可见的图层不会被渲染,但仍然存在于图层列表中
|
|
7615
|
-
*
|
|
7616
|
-
* @property visible
|
|
7617
|
-
* @type {boolean}
|
|
7618
|
-
*/
|
|
7619
|
-
get visible() {
|
|
7620
|
-
return this.property('visible');
|
|
7621
|
-
}
|
|
7622
|
-
set visible(v) {
|
|
7623
|
-
this.needUpdate = true;
|
|
7624
|
-
return this.property('visible', v);
|
|
7625
|
-
}
|
|
7626
|
-
|
|
7627
|
-
/**
|
|
7628
|
-
* 图层是否锁定
|
|
7629
|
-
* 锁定的图层中的图形不可被选中或移动,但仍然可见
|
|
7630
|
-
* 适用于背景图层或参考图层
|
|
7631
|
-
*
|
|
7632
|
-
* @property locked
|
|
7633
|
-
* @type {boolean}
|
|
7634
|
-
*/
|
|
7635
|
-
get locked() {
|
|
7636
|
-
return this.property('locked');
|
|
7637
|
-
}
|
|
7638
|
-
set locked(v) {
|
|
7639
|
-
return this.property('locked', v);
|
|
7640
|
-
}
|
|
7641
|
-
|
|
7642
|
-
/**
|
|
7643
|
-
* 绘制图层
|
|
7644
|
-
* 只有可见的图层才会被绘制
|
|
7645
|
-
*
|
|
7646
|
-
* @method paint
|
|
7647
|
-
* @param {boolean} v 是否需要重绘
|
|
7648
|
-
*/
|
|
7649
|
-
paint(v) {
|
|
7650
|
-
if(this.visible !== false) {
|
|
7651
|
-
super.paint(v);
|
|
7652
|
-
}
|
|
7653
|
-
}
|
|
7654
|
-
|
|
7655
|
-
/**
|
|
7656
|
-
* 检查点是否在图层内
|
|
7657
|
-
* 锁定的图层不会响应鼠标事件
|
|
7658
|
-
*
|
|
7659
|
-
* @method checkPoint
|
|
7660
|
-
* @param {object} p 坐标点 {x, y}
|
|
7661
|
-
* @param {number} [pad] padding,额外的检测范围
|
|
7662
|
-
* @return {boolean} 是否在图层内
|
|
7663
|
-
*/
|
|
7664
|
-
checkPoint(p, pad) {
|
|
7665
|
-
// 锁定的图层不响应交互
|
|
7666
|
-
if(this.locked) return false;
|
|
7667
|
-
return super.checkPoint(p, pad);
|
|
7668
|
-
}
|
|
7669
|
-
|
|
7670
|
-
/**
|
|
7671
|
-
* 清空图层
|
|
7672
|
-
* 移除图层中的所有图形对象
|
|
7673
|
-
*
|
|
7674
|
-
* @method clear
|
|
7675
|
-
*/
|
|
7676
|
-
clear() {
|
|
7677
|
-
this.children.clear();
|
|
7678
|
-
this.needUpdate = true;
|
|
7679
|
-
}
|
|
7680
|
-
|
|
7681
|
-
/**
|
|
7682
|
-
* 获取图层中的图形数量
|
|
7683
|
-
*
|
|
7684
|
-
* @method getShapeCount
|
|
7685
|
-
* @return {number} 图形数量
|
|
7686
|
-
*/
|
|
7687
|
-
getShapeCount() {
|
|
7688
|
-
return this.children.length;
|
|
7689
|
-
}
|
|
7690
|
-
|
|
7691
|
-
/**
|
|
7692
|
-
* 获取图层信息
|
|
7693
|
-
* 返回图层的基本信息,用于调试和日志
|
|
7694
|
-
*
|
|
7695
|
-
* @method getInfo
|
|
7696
|
-
* @return {object} 图层信息对象
|
|
7697
|
-
*/
|
|
7698
|
-
getInfo() {
|
|
7699
|
-
return {
|
|
7700
|
-
name: this.name,
|
|
7701
|
-
visible: this.visible,
|
|
7702
|
-
locked: this.locked,
|
|
7703
|
-
shapeCount: this.getShapeCount()
|
|
7704
|
-
};
|
|
7705
|
-
}
|
|
7706
|
-
}
|
|
7707
|
-
|
|
7708
8294
|
/**
|
|
7709
8295
|
* jmGraph画图类库
|
|
7710
8296
|
* 对canvas画图api进行二次封装,使其更易调用,省去很多重复的工作。
|
|
@@ -7716,7 +8302,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7716
8302
|
* @param {object} option 参数:{width:宽,height:高}
|
|
7717
8303
|
* @param {function} callback 初始化后的回调
|
|
7718
8304
|
*/
|
|
7719
|
-
class jmGraph
|
|
8305
|
+
class jmGraph extends jmControl {
|
|
7720
8306
|
|
|
7721
8307
|
constructor(canvas, option, callback) {
|
|
7722
8308
|
if(typeof option == 'function') {
|
|
@@ -7782,8 +8368,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7782
8368
|
else {
|
|
7783
8369
|
this.context = canvas.getContext(this.mode);
|
|
7784
8370
|
}
|
|
7785
|
-
|
|
7786
|
-
this.textureCanvas = option.textureCanvas || null;
|
|
7787
8371
|
|
|
7788
8372
|
// webgl模式
|
|
7789
8373
|
if(this.mode === 'webgl') {
|
|
@@ -7934,7 +8518,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7934
8518
|
* @return {jmGraph} jmGraph实例对象
|
|
7935
8519
|
*/
|
|
7936
8520
|
static create(...args) {
|
|
7937
|
-
return new jmGraph
|
|
8521
|
+
return new jmGraph(...args);
|
|
7938
8522
|
}
|
|
7939
8523
|
|
|
7940
8524
|
/**
|
|
@@ -7983,9 +8567,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7983
8567
|
if(shape) {
|
|
7984
8568
|
if(!args) args = {};
|
|
7985
8569
|
args.graph = this;
|
|
7986
|
-
|
|
7987
|
-
// 添加到活动图层
|
|
7988
|
-
this.addShapeToLayer(obj);
|
|
8570
|
+
const obj = new shape(args);
|
|
7989
8571
|
return obj;
|
|
7990
8572
|
}
|
|
7991
8573
|
}
|
|
@@ -8111,13 +8693,19 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8111
8693
|
this.context.clearRect(0, 0, w, h);
|
|
8112
8694
|
}
|
|
8113
8695
|
else if(this.mode === 'webgl' && this.context.clear) {
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
a
|
|
8119
|
-
}
|
|
8120
|
-
this.
|
|
8696
|
+
// 缓存 clearColor 对象,避免每帧创建
|
|
8697
|
+
if(this.style && this.style.fill) {
|
|
8698
|
+
const color = this.utils.hexToRGBA(this.style.fill);
|
|
8699
|
+
this.__lastClearColor = color;
|
|
8700
|
+
this.context.clearColor(color.r, color.g, color.b, color.a);
|
|
8701
|
+
}
|
|
8702
|
+
else if(!this.__lastClearColor) {
|
|
8703
|
+
this.__lastClearColor = { r: 0, g: 0, b: 0, a: 0 };
|
|
8704
|
+
this.context.clearColor(0, 0, 0, 0);
|
|
8705
|
+
}
|
|
8706
|
+
else {
|
|
8707
|
+
this.context.clearColor(this.__lastClearColor.r, this.__lastClearColor.g, this.__lastClearColor.b, this.__lastClearColor.a);
|
|
8708
|
+
}
|
|
8121
8709
|
this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
|
|
8122
8710
|
}
|
|
8123
8711
|
}
|
|
@@ -8298,240 +8886,14 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8298
8886
|
*
|
|
8299
8887
|
* @method resetTransform
|
|
8300
8888
|
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8301
|
-
*/
|
|
8302
|
-
resetTransform() {
|
|
8303
|
-
this.scaleFactor = 1;
|
|
8304
|
-
this.translation = {x: 0, y: 0};
|
|
8305
|
-
this.needUpdate = true;
|
|
8306
|
-
this.redraw();
|
|
8307
|
-
|
|
8308
|
-
return this; // 支持链式调用
|
|
8309
|
-
}
|
|
8310
|
-
|
|
8311
|
-
/**
|
|
8312
|
-
* 初始化图层系统
|
|
8313
|
-
* 创建图层管理的基础结构,包括默认图层
|
|
8314
|
-
*
|
|
8315
|
-
* @method initLayers
|
|
8316
|
-
* @private
|
|
8317
|
-
*/
|
|
8318
|
-
initLayers() {
|
|
8319
|
-
if(!this.layers) {
|
|
8320
|
-
this.layers = new jmList();
|
|
8321
|
-
// 创建默认图层
|
|
8322
|
-
const defaultLayer = this.createLayer('Default Layer');
|
|
8323
|
-
this.activeLayer = defaultLayer;
|
|
8324
|
-
}
|
|
8325
|
-
}
|
|
8326
|
-
|
|
8327
|
-
/**
|
|
8328
|
-
* 创建新图层
|
|
8329
|
-
* 图层用于组织和管理图形对象,支持可见性和锁定控制
|
|
8330
|
-
*
|
|
8331
|
-
* @method createLayer
|
|
8332
|
-
* @param {string} name 图层名称(必须唯一)
|
|
8333
|
-
* @param {object} [options] 图层选项
|
|
8334
|
-
* @param {boolean} [options.visible=true] 图层是否可见
|
|
8335
|
-
* @param {boolean} [options.locked=false] 图层是否锁定(锁定后不可交互)
|
|
8336
|
-
* @return {jmLayer} 新创建的图层
|
|
8337
|
-
*/
|
|
8338
|
-
createLayer(name, options = {}) {
|
|
8339
|
-
// 参数验证
|
|
8340
|
-
if(!name || typeof name !== 'string') {
|
|
8341
|
-
console.warn('jmGraph: createLayer - 图层名称必须是非空字符串');
|
|
8342
|
-
name = `Layer_${Date.now()}`;
|
|
8343
|
-
}
|
|
8344
|
-
|
|
8345
|
-
this.initLayers();
|
|
8346
|
-
|
|
8347
|
-
// 检查图层名称是否已存在
|
|
8348
|
-
const existingLayer = this.getLayer(name);
|
|
8349
|
-
if(existingLayer) {
|
|
8350
|
-
console.warn(`jmGraph: 图层 "${name}" 已存在,将返回现有图层`);
|
|
8351
|
-
return existingLayer;
|
|
8352
|
-
}
|
|
8353
|
-
|
|
8354
|
-
const layer = new jmLayer({
|
|
8355
|
-
name: name,
|
|
8356
|
-
graph: this,
|
|
8357
|
-
...options
|
|
8358
|
-
});
|
|
8359
|
-
|
|
8360
|
-
this.layers.add(layer);
|
|
8361
|
-
this.children.add(layer);
|
|
8362
|
-
this.needUpdate = true;
|
|
8363
|
-
return layer;
|
|
8364
|
-
}
|
|
8365
|
-
|
|
8366
|
-
/**
|
|
8367
|
-
* 获取所有图层
|
|
8368
|
-
*
|
|
8369
|
-
* @method getLayers
|
|
8370
|
-
* @return {jmList} 图层列表
|
|
8371
|
-
*/
|
|
8372
|
-
getLayers() {
|
|
8373
|
-
this.initLayers();
|
|
8374
|
-
return this.layers;
|
|
8375
|
-
}
|
|
8376
|
-
|
|
8377
|
-
/**
|
|
8378
|
-
* 根据名称获取图层
|
|
8379
|
-
*
|
|
8380
|
-
* @method getLayer
|
|
8381
|
-
* @param {string} name 图层名称
|
|
8382
|
-
* @return {jmLayer|null} 图层对象,如果不存在则返回null
|
|
8383
|
-
*/
|
|
8384
|
-
getLayer(name) {
|
|
8385
|
-
this.initLayers();
|
|
8386
|
-
|
|
8387
|
-
if(!name) return null;
|
|
8388
|
-
|
|
8389
|
-
let result = null;
|
|
8390
|
-
this.layers.each((i, layer) => {
|
|
8391
|
-
if(layer.name === name) {
|
|
8392
|
-
result = layer;
|
|
8393
|
-
return false; // 找到后停止遍历
|
|
8394
|
-
}
|
|
8395
|
-
});
|
|
8396
|
-
return result;
|
|
8397
|
-
}
|
|
8398
|
-
|
|
8399
|
-
/**
|
|
8400
|
-
* 设置活动图层
|
|
8401
|
-
* 新创建的图形将自动添加到活动图层
|
|
8402
|
-
*
|
|
8403
|
-
* @method setActiveLayer
|
|
8404
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
8405
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8406
|
-
*/
|
|
8407
|
-
setActiveLayer(layer) {
|
|
8408
|
-
this.initLayers();
|
|
8409
|
-
|
|
8410
|
-
// 支持传入图层名称或图层对象
|
|
8411
|
-
if(typeof layer === 'string') {
|
|
8412
|
-
layer = this.getLayer(layer);
|
|
8413
|
-
}
|
|
8414
|
-
|
|
8415
|
-
if(!layer || !(layer instanceof jmLayer)) {
|
|
8416
|
-
console.warn('jmGraph: setActiveLayer - 无效的图层');
|
|
8417
|
-
return this;
|
|
8418
|
-
}
|
|
8419
|
-
|
|
8420
|
-
this.activeLayer = layer;
|
|
8421
|
-
return this;
|
|
8422
|
-
}
|
|
8423
|
-
|
|
8424
|
-
/**
|
|
8425
|
-
* 获取当前活动图层
|
|
8426
|
-
* 活动图层是新创建图形的默认容器
|
|
8427
|
-
*
|
|
8428
|
-
* @method getActiveLayer
|
|
8429
|
-
* @return {jmLayer} 当前活动图层
|
|
8430
|
-
*/
|
|
8431
|
-
getActiveLayer() {
|
|
8432
|
-
this.initLayers();
|
|
8433
|
-
return this.activeLayer;
|
|
8434
|
-
}
|
|
8435
|
-
|
|
8436
|
-
/**
|
|
8437
|
-
* 移除图层
|
|
8438
|
-
* 删除指定图层及其包含的所有图形
|
|
8439
|
-
* 注意:默认图层不可删除
|
|
8440
|
-
*
|
|
8441
|
-
* @method removeLayer
|
|
8442
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
8443
|
-
* @return {boolean} 是否成功删除
|
|
8444
|
-
*/
|
|
8445
|
-
removeLayer(layer) {
|
|
8446
|
-
this.initLayers();
|
|
8447
|
-
|
|
8448
|
-
// 支持传入图层名称或图层对象
|
|
8449
|
-
if(typeof layer === 'string') {
|
|
8450
|
-
layer = this.getLayer(layer);
|
|
8451
|
-
}
|
|
8452
|
-
|
|
8453
|
-
if(!layer) {
|
|
8454
|
-
console.warn('jmGraph: removeLayer - 图层不存在');
|
|
8455
|
-
return false;
|
|
8456
|
-
}
|
|
8457
|
-
|
|
8458
|
-
// 禁止删除默认图层
|
|
8459
|
-
if(layer.name === 'Default Layer') {
|
|
8460
|
-
console.warn('jmGraph: 不能删除默认图层');
|
|
8461
|
-
return false;
|
|
8462
|
-
}
|
|
8463
|
-
|
|
8464
|
-
// 如果删除的是当前活动图层,切换到默认图层
|
|
8465
|
-
if(this.activeLayer === layer) {
|
|
8466
|
-
this.activeLayer = this.getLayer('Default Layer');
|
|
8467
|
-
}
|
|
8468
|
-
|
|
8469
|
-
this.layers.remove(layer);
|
|
8470
|
-
this.children.remove(layer);
|
|
8471
|
-
this.needUpdate = true;
|
|
8472
|
-
return true;
|
|
8473
|
-
}
|
|
8474
|
-
|
|
8475
|
-
/**
|
|
8476
|
-
* 将形状添加到指定图层
|
|
8477
|
-
* 如果未指定图层,则添加到当前活动图层
|
|
8478
|
-
*
|
|
8479
|
-
* @method addShapeToLayer
|
|
8480
|
-
* @param {jmControl} shape 要添加的形状对象
|
|
8481
|
-
* @param {string|jmLayer} [layer] 图层名称或图层对象,默认为当前活动图层
|
|
8482
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8483
|
-
*/
|
|
8484
|
-
addShapeToLayer(shape, layer) {
|
|
8485
|
-
this.initLayers();
|
|
8486
|
-
|
|
8487
|
-
// 参数验证
|
|
8488
|
-
if(!shape) {
|
|
8489
|
-
console.warn('jmGraph: addShapeToLayer - 无效的形状对象');
|
|
8490
|
-
return this;
|
|
8491
|
-
}
|
|
8492
|
-
|
|
8493
|
-
// 确定目标图层
|
|
8494
|
-
if(!layer) {
|
|
8495
|
-
layer = this.activeLayer;
|
|
8496
|
-
} else if(typeof layer === 'string') {
|
|
8497
|
-
layer = this.getLayer(layer);
|
|
8498
|
-
}
|
|
8499
|
-
|
|
8500
|
-
if(!layer) {
|
|
8501
|
-
console.warn('jmGraph: addShapeToLayer - 图层不存在');
|
|
8502
|
-
return this;
|
|
8503
|
-
}
|
|
8504
|
-
|
|
8505
|
-
layer.children.add(shape);
|
|
8506
|
-
this.needUpdate = true;
|
|
8507
|
-
return this;
|
|
8508
|
-
}
|
|
8509
|
-
|
|
8510
|
-
/**
|
|
8511
|
-
* 从图层中移除形状
|
|
8512
|
-
*
|
|
8513
|
-
* @method removeShapeFromLayer
|
|
8514
|
-
* @param {jmControl} shape 要移除的形状对象
|
|
8515
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8516
|
-
*/
|
|
8517
|
-
removeShapeFromLayer(shape) {
|
|
8518
|
-
if(!shape) {
|
|
8519
|
-
console.warn('jmGraph: removeShapeFromLayer - 无效的形状对象');
|
|
8520
|
-
return this;
|
|
8521
|
-
}
|
|
8522
|
-
|
|
8523
|
-
// 从所有图层中查找并移除
|
|
8524
|
-
if(this.layers) {
|
|
8525
|
-
this.layers.each((i, layer) => {
|
|
8526
|
-
if(layer.children.contains(shape)) {
|
|
8527
|
-
layer.children.remove(shape);
|
|
8528
|
-
this.needUpdate = true;
|
|
8529
|
-
return false; // 找到后停止遍历
|
|
8530
|
-
}
|
|
8531
|
-
});
|
|
8532
|
-
}
|
|
8889
|
+
*/
|
|
8890
|
+
resetTransform() {
|
|
8891
|
+
this.scaleFactor = 1;
|
|
8892
|
+
this.translation = {x: 0, y: 0};
|
|
8893
|
+
this.needUpdate = true;
|
|
8894
|
+
this.redraw();
|
|
8533
8895
|
|
|
8534
|
-
return this;
|
|
8896
|
+
return this; // 支持链式调用
|
|
8535
8897
|
}
|
|
8536
8898
|
|
|
8537
8899
|
/**
|
|
@@ -8600,48 +8962,27 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8600
8962
|
}
|
|
8601
8963
|
|
|
8602
8964
|
/**
|
|
8603
|
-
*
|
|
8604
|
-
*
|
|
8605
|
-
*
|
|
8965
|
+
* 遍历所有形状,生成SVG标记
|
|
8966
|
+
*
|
|
8606
8967
|
* @method toSVG
|
|
8607
8968
|
* @return {string} SVG字符串
|
|
8608
8969
|
*/
|
|
8609
8970
|
toSVG() {
|
|
8610
8971
|
// SVG头部,包含命名空间和画布尺寸
|
|
8611
8972
|
let svg = `<svg width="${this.width}" height="${this.height}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.width} ${this.height}">`;
|
|
8612
|
-
|
|
8973
|
+
|
|
8613
8974
|
// 添加背景色(如果有)
|
|
8614
8975
|
if(this.style && this.style.fill) {
|
|
8615
8976
|
svg += `<rect width="100%" height="100%" fill="${this.style.fill}"/>`;
|
|
8616
8977
|
}
|
|
8617
|
-
|
|
8618
|
-
//
|
|
8619
|
-
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
// 遍历图层中的所有形状
|
|
8626
|
-
layer.children.each((j, shape) => {
|
|
8627
|
-
if(shape.toSVG) {
|
|
8628
|
-
svg += shape.toSVG();
|
|
8629
|
-
}
|
|
8630
|
-
});
|
|
8631
|
-
|
|
8632
|
-
svg += '</g>';
|
|
8633
|
-
}
|
|
8634
|
-
});
|
|
8635
|
-
}
|
|
8636
|
-
else {
|
|
8637
|
-
// 遍历直接添加的形状(兼容没有图层系统的情况)
|
|
8638
|
-
this.children.each((i, shape) => {
|
|
8639
|
-
if(shape.toSVG) {
|
|
8640
|
-
svg += shape.toSVG();
|
|
8641
|
-
}
|
|
8642
|
-
});
|
|
8643
|
-
}
|
|
8644
|
-
|
|
8978
|
+
|
|
8979
|
+
// 遍历所有直接添加的形状
|
|
8980
|
+
this.children.each((i, shape) => {
|
|
8981
|
+
if(shape.toSVG) {
|
|
8982
|
+
svg += shape.toSVG();
|
|
8983
|
+
}
|
|
8984
|
+
});
|
|
8985
|
+
|
|
8645
8986
|
svg += '</svg>';
|
|
8646
8987
|
return svg;
|
|
8647
8988
|
}
|
|
@@ -8691,7 +9032,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8691
9032
|
// 触发刷新事件
|
|
8692
9033
|
self.emit('update', time);
|
|
8693
9034
|
|
|
8694
|
-
|
|
9035
|
+
// 直接 requestAnimationFrame,无需先 cancel
|
|
8695
9036
|
self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
|
|
8696
9037
|
if(callback) callback();
|
|
8697
9038
|
}
|
|
@@ -8726,41 +9067,25 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8726
9067
|
"star": jmStar
|
|
8727
9068
|
};
|
|
8728
9069
|
|
|
8729
|
-
class
|
|
9070
|
+
class jmGraphImpl extends jmGraph {
|
|
8730
9071
|
constructor(canvas, option, callback) {
|
|
8731
|
-
|
|
8732
|
-
const targetType = new.target;
|
|
8733
|
-
|
|
8734
9072
|
// 合并shapes
|
|
8735
9073
|
option = Object.assign({}, option);
|
|
8736
9074
|
option.shapes = Object.assign(shapes, option.shapes||{});
|
|
8737
|
-
|
|
8738
|
-
//不是用new实例化的话,返回一个promise
|
|
8739
|
-
if(!targetType || !(targetType.prototype instanceof jmGraph$1)) {
|
|
8740
|
-
return new Promise(function(resolve, reject){
|
|
8741
|
-
var g = new jmGraph(canvas, option, callback);
|
|
8742
|
-
if(resolve) resolve(g);
|
|
8743
|
-
});
|
|
8744
|
-
}
|
|
8745
9075
|
|
|
8746
9076
|
if(typeof option == 'function') {
|
|
8747
9077
|
callback = option;
|
|
8748
9078
|
option = {};
|
|
8749
|
-
|
|
9079
|
+
}
|
|
8750
9080
|
|
|
8751
9081
|
super(canvas, option, callback);
|
|
8752
9082
|
}
|
|
8753
9083
|
|
|
8754
9084
|
static create(...args) {
|
|
8755
|
-
return
|
|
9085
|
+
return new jmGraphImpl(...args);
|
|
8756
9086
|
}
|
|
8757
9087
|
}
|
|
8758
9088
|
|
|
8759
|
-
//创建实例
|
|
8760
|
-
const createJmGraph = (...args) => {
|
|
8761
|
-
return new jmGraph(...args);
|
|
8762
|
-
};
|
|
8763
|
-
|
|
8764
9089
|
/**
|
|
8765
9090
|
* 基础样式
|
|
8766
9091
|
*
|
|
@@ -9962,13 +10287,16 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
9962
10287
|
clear() {
|
|
9963
10288
|
this._min = null;
|
|
9964
10289
|
this._max = null;
|
|
10290
|
+
this._width = null; // 清除宽度缓存
|
|
9965
10291
|
this.children.each((i, c) => {
|
|
9966
10292
|
c.remove();
|
|
9967
10293
|
}, true);
|
|
9968
10294
|
// 清空栅格线
|
|
9969
|
-
this.gridLines && this.gridLines.
|
|
9970
|
-
|
|
9971
|
-
|
|
10295
|
+
if (this.gridLines && this.gridLines.length) {
|
|
10296
|
+
for (let i = 0; i < this.gridLines.length; i++) {
|
|
10297
|
+
this.gridLines[i].remove();
|
|
10298
|
+
}
|
|
10299
|
+
}
|
|
9972
10300
|
this.labels && this.labels.forEach(label => {
|
|
9973
10301
|
label.remove();
|
|
9974
10302
|
});
|
|
@@ -10180,7 +10508,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10180
10508
|
}
|
|
10181
10509
|
};
|
|
10182
10510
|
|
|
10183
|
-
|
|
10511
|
+
// 公共常量提取到基类,避免每个子类重复定义
|
|
10512
|
+
const ANIMATION_DATA_THRESHOLD = 100;
|
|
10513
|
+
const DEFAULT_ANIMATION_COUNT = 10;
|
|
10184
10514
|
|
|
10185
10515
|
/**
|
|
10186
10516
|
* 图表系列基类
|
|
@@ -10299,14 +10629,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10299
10629
|
*/
|
|
10300
10630
|
initDataPoint(...args) {
|
|
10301
10631
|
let dataChanged = false;
|
|
10302
|
-
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10632
|
+
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD) {
|
|
10633
|
+
// 仅在数据引用变化时才做深度比较
|
|
10634
|
+
if (this._lastData !== this.data) {
|
|
10635
|
+
this.lastPoints = this.graph.utils.clone(this.dataPoints, null, true, obj => {
|
|
10636
|
+
if (obj instanceof jmControl) return obj;
|
|
10637
|
+
});
|
|
10638
|
+
this.dataPoints = this.createPoints(...args);
|
|
10639
|
+
dataChanged = utils.arrayIsChange(this.lastPoints, this.dataPoints, (s, t) => {
|
|
10640
|
+
return s.x === t.x && s.y === t.y;
|
|
10641
|
+
});
|
|
10642
|
+
this._lastData = this.data;
|
|
10643
|
+
} else {
|
|
10644
|
+
this.dataPoints = this.createPoints(...args);
|
|
10645
|
+
}
|
|
10310
10646
|
if (dataChanged) {
|
|
10311
10647
|
this.___animateCounter = 0;
|
|
10312
10648
|
}
|
|
@@ -10439,7 +10775,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10439
10775
|
xValue: xv,
|
|
10440
10776
|
xLabel: xv,
|
|
10441
10777
|
points: [],
|
|
10442
|
-
style: this.
|
|
10778
|
+
style: this.style // 共享引用,避免深拷贝;子类如需修改应自行创建副本
|
|
10443
10779
|
};
|
|
10444
10780
|
p.x = xstep * i + this.xAxis.labelStart;
|
|
10445
10781
|
for (let j = 0; j < fields.length; j++) {
|
|
@@ -10605,9 +10941,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10605
10941
|
}
|
|
10606
10942
|
}
|
|
10607
10943
|
|
|
10608
|
-
const ANIMATION_DATA_THRESHOLD$6 = 100;
|
|
10609
|
-
const DEFAULT_ANIMATION_COUNT$6 = 10;
|
|
10610
|
-
|
|
10611
10944
|
/**
|
|
10612
10945
|
* 柱图
|
|
10613
10946
|
*
|
|
@@ -10637,16 +10970,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10637
10970
|
const len = points.length;
|
|
10638
10971
|
if (!len) return;
|
|
10639
10972
|
this.initWidth(len);
|
|
10640
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
10973
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
10641
10974
|
let aniIsEnd = true;
|
|
10642
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
10975
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
10643
10976
|
for (let i = 0; i < len; i++) {
|
|
10644
10977
|
const point = points[i];
|
|
10645
10978
|
if (typeof point.y === 'undefined' || point.y === null) {
|
|
10646
10979
|
continue;
|
|
10647
10980
|
}
|
|
10648
|
-
|
|
10649
|
-
|
|
10981
|
+
const style = Object.assign({}, point.style, {
|
|
10982
|
+
fill: this.getColor(point)
|
|
10983
|
+
});
|
|
10984
|
+
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10650
10985
|
const p1 = {
|
|
10651
10986
|
x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex,
|
|
10652
10987
|
y: this.baseY
|
|
@@ -10781,16 +11116,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10781
11116
|
let topStartY = this.baseY;
|
|
10782
11117
|
let bottomStartY = this.baseY;
|
|
10783
11118
|
for (let index = 0; index < point.points.length; index++) {
|
|
10784
|
-
const style = this.graph.utils.clone(this.style);
|
|
10785
11119
|
const p = point.points[index];
|
|
10786
|
-
|
|
10787
|
-
|
|
11120
|
+
let fillColor;
|
|
11121
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
11122
|
+
fillColor = this.style.color.call(this, {
|
|
10788
11123
|
index,
|
|
10789
11124
|
point: p
|
|
10790
11125
|
});
|
|
10791
11126
|
} else {
|
|
10792
|
-
|
|
11127
|
+
fillColor = this.graph.getColor(index);
|
|
10793
11128
|
}
|
|
11129
|
+
// 使用浅拷贝而非深拷贝
|
|
11130
|
+
const style = Object.assign({}, this.style, {
|
|
11131
|
+
fill: fillColor
|
|
11132
|
+
});
|
|
10794
11133
|
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10795
11134
|
let startY = topStartY;
|
|
10796
11135
|
if (p.yValue < this.baseYValue) startY = bottomStartY;
|
|
@@ -10899,7 +11238,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10899
11238
|
this.totalValue = 0;
|
|
10900
11239
|
//计算最大值和最小值
|
|
10901
11240
|
if (this.data) {
|
|
10902
|
-
for (
|
|
11241
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
10903
11242
|
const s = this.data[i];
|
|
10904
11243
|
const vy = s[this.field];
|
|
10905
11244
|
if (vy) {
|
|
@@ -10996,15 +11335,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10996
11335
|
yLabel: yv,
|
|
10997
11336
|
step: Math.abs(yv / this.totalValue),
|
|
10998
11337
|
// 每个数值点比
|
|
10999
|
-
style: this.
|
|
11338
|
+
style: this.style,
|
|
11339
|
+
// 共享引用,仅在需要修改时才拷贝
|
|
11000
11340
|
anticlockwise
|
|
11001
11341
|
};
|
|
11002
11342
|
points.push(p);
|
|
11003
11343
|
//p.style.color = this.graph.getColor(index);
|
|
11004
11344
|
if (p.style.color && typeof p.style.color === 'function') {
|
|
11345
|
+
p.style = this.graph.utils.clone(this.style);
|
|
11005
11346
|
p.style.fill = p.style.color.call(this, p);
|
|
11006
11347
|
} else {
|
|
11007
|
-
|
|
11348
|
+
// fill 需要独立,创建轻量样式覆盖
|
|
11349
|
+
p.style = Object.assign({}, this.style, {
|
|
11350
|
+
fill: this.graph.getColor(index)
|
|
11351
|
+
});
|
|
11008
11352
|
}
|
|
11009
11353
|
const start = startAni; // 上一个扇形的结束角度为当前的起始角度
|
|
11010
11354
|
// 计算当前结束角度, 同时也是下一个的起始角度
|
|
@@ -11210,11 +11554,12 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11210
11554
|
const rotateStep = Math.PI * 2 / yCount;
|
|
11211
11555
|
|
|
11212
11556
|
// 清空除了一个默认外的所有Y轴
|
|
11213
|
-
|
|
11214
|
-
|
|
11557
|
+
const yAxisKeys = Object.keys(this.graph.yAxises || {});
|
|
11558
|
+
for (let k = 0; k < yAxisKeys.length; k++) {
|
|
11559
|
+
const axis = this.graph.yAxises[yAxisKeys[k]];
|
|
11215
11560
|
if (!axis || axis === this.yAxis) continue;
|
|
11216
11561
|
axis.remove();
|
|
11217
|
-
delete this.graph.yAxises[
|
|
11562
|
+
delete this.graph.yAxises[yAxisKeys[k]];
|
|
11218
11563
|
}
|
|
11219
11564
|
for (let index = 0; index < yCount; index++) {
|
|
11220
11565
|
if (!this.field[index]) continue;
|
|
@@ -11361,21 +11706,30 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11361
11706
|
const points = [];
|
|
11362
11707
|
for (var i = 0; i < this.data.length; i++) {
|
|
11363
11708
|
const s = this.data[i];
|
|
11364
|
-
|
|
11365
|
-
if (style.color && typeof style.color === 'function') {
|
|
11366
|
-
|
|
11709
|
+
let strokeColor;
|
|
11710
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
11711
|
+
strokeColor = this.style.color.call(this, {
|
|
11367
11712
|
data: s,
|
|
11368
11713
|
index: i
|
|
11369
11714
|
});
|
|
11370
11715
|
} else {
|
|
11371
|
-
|
|
11716
|
+
strokeColor = this.graph.getColor(i);
|
|
11372
11717
|
}
|
|
11373
|
-
|
|
11374
|
-
|
|
11718
|
+
let fillColor;
|
|
11719
|
+
if (typeof this.style.fill === 'function') {
|
|
11720
|
+
fillColor = this.style.fill.call(this, {
|
|
11721
|
+
...this.style,
|
|
11722
|
+
stroke: strokeColor
|
|
11723
|
+
});
|
|
11375
11724
|
} else {
|
|
11376
|
-
const color = this.graph.utils.hexToRGBA(
|
|
11377
|
-
|
|
11725
|
+
const color = this.graph.utils.hexToRGBA(strokeColor);
|
|
11726
|
+
fillColor = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
11378
11727
|
}
|
|
11728
|
+
// 使用浅拷贝而非深拷贝
|
|
11729
|
+
const style = Object.assign({}, this.style, {
|
|
11730
|
+
stroke: strokeColor,
|
|
11731
|
+
fill: fillColor
|
|
11732
|
+
});
|
|
11379
11733
|
const shapePoints = [];
|
|
11380
11734
|
for (const axis of this.axises) {
|
|
11381
11735
|
if (!axis || !axis.field) continue;
|
|
@@ -11469,9 +11823,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11469
11823
|
});
|
|
11470
11824
|
};
|
|
11471
11825
|
|
|
11472
|
-
const ANIMATION_DATA_THRESHOLD$5 = 100;
|
|
11473
|
-
const DEFAULT_ANIMATION_COUNT$5 = 10;
|
|
11474
|
-
|
|
11475
11826
|
/**
|
|
11476
11827
|
* 线图
|
|
11477
11828
|
*
|
|
@@ -11503,9 +11854,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11503
11854
|
if (!len) return;
|
|
11504
11855
|
this.style.stroke = this.style.color;
|
|
11505
11856
|
this.style.item.stroke = this.style.color;
|
|
11506
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
11857
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
11507
11858
|
let shapePoints = [];
|
|
11508
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
11859
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11509
11860
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11510
11861
|
for (let i = 0; i < len; i++) {
|
|
11511
11862
|
const p = points[i];
|
|
@@ -11888,7 +12239,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11888
12239
|
console.warn('K线图数据不完整,需要4个字段(开盘、收盘、最高、最低)');
|
|
11889
12240
|
continue;
|
|
11890
12241
|
}
|
|
11891
|
-
const sp = this.addShape(this.graph.createPath([], p.style));
|
|
11892
12242
|
const bl = {
|
|
11893
12243
|
x: p.x - w,
|
|
11894
12244
|
y: p.points[0].y
|
|
@@ -11907,14 +12257,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11907
12257
|
};
|
|
11908
12258
|
let tm = p.points[1];
|
|
11909
12259
|
let bm = p.points[0];
|
|
11910
|
-
|
|
12260
|
+
|
|
12261
|
+
// 使用浅拷贝避免污染共享引用
|
|
12262
|
+
const style = Object.assign({}, p.style);
|
|
12263
|
+
style.stroke = style.fill = style.masculineColor || 'red';
|
|
11911
12264
|
if (p.points[0].yValue > p.points[1].yValue) {
|
|
11912
|
-
|
|
12265
|
+
style.stroke = style.fill = style.negativeColor || 'green';
|
|
11913
12266
|
bl.y = br.y = p.points[1].y;
|
|
11914
12267
|
tl.y = tr.y = p.points[0].y;
|
|
11915
12268
|
tm = p.points[0];
|
|
11916
12269
|
bm = p.points[1];
|
|
11917
12270
|
}
|
|
12271
|
+
const sp = this.addShape(this.graph.createPath([], style));
|
|
11918
12272
|
sp.points.push(p.points[2], tm, tl, bl, bm, p.points[3], bm, br, tr, tm, p.points[2]);
|
|
11919
12273
|
this.emit('onPointCreated', p);
|
|
11920
12274
|
}
|
|
@@ -11939,9 +12293,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11939
12293
|
}
|
|
11940
12294
|
}
|
|
11941
12295
|
|
|
11942
|
-
const ANIMATION_DATA_THRESHOLD$4 = 100;
|
|
11943
|
-
const DEFAULT_ANIMATION_COUNT$4 = 10;
|
|
11944
|
-
|
|
11945
12296
|
/**
|
|
11946
12297
|
* 散点图
|
|
11947
12298
|
*
|
|
@@ -11973,8 +12324,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11973
12324
|
if (!len) return;
|
|
11974
12325
|
this.style.stroke = this.style.color;
|
|
11975
12326
|
this.style.item.stroke = this.style.color;
|
|
11976
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
11977
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12327
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12328
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11978
12329
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11979
12330
|
for (let i = 0; i < len; i++) {
|
|
11980
12331
|
const p = points[i];
|
|
@@ -12047,9 +12398,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12047
12398
|
}
|
|
12048
12399
|
}
|
|
12049
12400
|
|
|
12050
|
-
const ANIMATION_DATA_THRESHOLD$3 = 100;
|
|
12051
|
-
const DEFAULT_ANIMATION_COUNT$3 = 10;
|
|
12052
|
-
|
|
12053
12401
|
/**
|
|
12054
12402
|
* 气泡图
|
|
12055
12403
|
*
|
|
@@ -12081,8 +12429,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12081
12429
|
if (!len) return;
|
|
12082
12430
|
this.style.stroke = this.style.color;
|
|
12083
12431
|
this.style.item.stroke = this.style.color;
|
|
12084
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
12085
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12432
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12433
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12086
12434
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12087
12435
|
for (let i = 0; i < len; i++) {
|
|
12088
12436
|
const p = points[i];
|
|
@@ -12161,9 +12509,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12161
12509
|
}
|
|
12162
12510
|
}
|
|
12163
12511
|
|
|
12164
|
-
const ANIMATION_DATA_THRESHOLD$2 = 100;
|
|
12165
|
-
const DEFAULT_ANIMATION_COUNT$2 = 10;
|
|
12166
|
-
|
|
12167
12512
|
/**
|
|
12168
12513
|
* 热力图
|
|
12169
12514
|
*
|
|
@@ -12206,8 +12551,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12206
12551
|
}
|
|
12207
12552
|
this.minValue = minValue;
|
|
12208
12553
|
this.maxValue = maxValue;
|
|
12209
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
12210
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12554
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12555
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12211
12556
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12212
12557
|
for (let i = 0; i < len; i++) {
|
|
12213
12558
|
const p = points[i];
|
|
@@ -12574,20 +12919,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12574
12919
|
}
|
|
12575
12920
|
}
|
|
12576
12921
|
|
|
12577
|
-
const ANIMATION_DATA_THRESHOLD$1 = 100;
|
|
12578
|
-
const DEFAULT_ANIMATION_COUNT$1 = 10;
|
|
12579
|
-
|
|
12580
12922
|
/**
|
|
12581
12923
|
* 面积图
|
|
12924
|
+
* 继承自折线图,默认启用区域填充
|
|
12582
12925
|
*
|
|
12583
12926
|
* @class jmAreaSeries
|
|
12584
12927
|
* @module jmChart
|
|
12585
|
-
* @
|
|
12586
|
-
* @param {array} mappings 图形字段映射
|
|
12587
|
-
* @param {style} style 样式
|
|
12928
|
+
* @extends jmLineSeries
|
|
12588
12929
|
*/
|
|
12589
|
-
|
|
12590
|
-
class jmAreaSeries extends jmSeries {
|
|
12930
|
+
class jmAreaSeries extends jmLineSeries {
|
|
12591
12931
|
constructor(options) {
|
|
12592
12932
|
options.style = options.style || options.graph.style.area;
|
|
12593
12933
|
super(options);
|
|
@@ -12595,193 +12935,13 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12595
12935
|
this.style.area = true;
|
|
12596
12936
|
}
|
|
12597
12937
|
|
|
12598
|
-
/**
|
|
12599
|
-
* 初始化面积图
|
|
12600
|
-
*
|
|
12601
|
-
* @method init
|
|
12602
|
-
* @for jmAreaSeries
|
|
12603
|
-
*/
|
|
12604
|
-
init() {
|
|
12605
|
-
const {
|
|
12606
|
-
points,
|
|
12607
|
-
dataChanged
|
|
12608
|
-
} = this.initDataPoint();
|
|
12609
|
-
const len = points.length;
|
|
12610
|
-
if (!len) return;
|
|
12611
|
-
this.style.stroke = this.style.color;
|
|
12612
|
-
this.style.item.stroke = this.style.color;
|
|
12613
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD$1;
|
|
12614
|
-
let shapePoints = [];
|
|
12615
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT$1;
|
|
12616
|
-
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12617
|
-
for (let i = 0; i < len; i++) {
|
|
12618
|
-
const p = points[i];
|
|
12619
|
-
if (typeof p.y === 'undefined' || p.y === null) {
|
|
12620
|
-
continue;
|
|
12621
|
-
}
|
|
12622
|
-
if (isRunningAni && i > this.___animateCounter) {
|
|
12623
|
-
break;
|
|
12624
|
-
}
|
|
12625
|
-
if (this.style.showItem) {
|
|
12626
|
-
this.createPointItem(p);
|
|
12627
|
-
}
|
|
12628
|
-
if (this.style.curve) {
|
|
12629
|
-
shapePoints = this.createCurePoints(shapePoints, p);
|
|
12630
|
-
} else if (this.style.lineType === 'dotted') {
|
|
12631
|
-
shapePoints = this.createDotLine(shapePoints, p);
|
|
12632
|
-
}
|
|
12633
|
-
shapePoints.push(p);
|
|
12634
|
-
this.createItemLabel(p);
|
|
12635
|
-
this.emit('onPointCreated', p);
|
|
12636
|
-
}
|
|
12637
|
-
if (this.___animateCounter >= len - 1) {
|
|
12638
|
-
this.___animateCounter = 0;
|
|
12639
|
-
} else if (isRunningAni) {
|
|
12640
|
-
this.___animateCounter += aniStep;
|
|
12641
|
-
this.graph.utils.requestAnimationFrame(() => {
|
|
12642
|
-
this.needUpdate = true;
|
|
12643
|
-
});
|
|
12644
|
-
}
|
|
12645
|
-
this.points = shapePoints;
|
|
12646
|
-
this.createArea(shapePoints);
|
|
12647
|
-
}
|
|
12648
|
-
|
|
12649
|
-
/**
|
|
12650
|
-
* 生成点的小圆圈
|
|
12651
|
-
*
|
|
12652
|
-
* @method createPointItem
|
|
12653
|
-
* @for jmAreaSeries
|
|
12654
|
-
* @param {object} p 数据点
|
|
12655
|
-
*/
|
|
12656
|
-
createPointItem(p) {
|
|
12657
|
-
const pointShape = this.graph.createShape('circle', {
|
|
12658
|
-
style: this.style.item,
|
|
12659
|
-
center: p,
|
|
12660
|
-
radius: this.style.radius || 3
|
|
12661
|
-
});
|
|
12662
|
-
pointShape.zIndex = (pointShape.style.zIndex || 1) + 1;
|
|
12663
|
-
return this.addShape(pointShape);
|
|
12664
|
-
}
|
|
12665
|
-
|
|
12666
|
-
/**
|
|
12667
|
-
* 创建曲线点
|
|
12668
|
-
*
|
|
12669
|
-
* @method createCurePoints
|
|
12670
|
-
* @for jmAreaSeries
|
|
12671
|
-
* @param {array} shapePoints 形状点数组
|
|
12672
|
-
* @param {object} p 当前点
|
|
12673
|
-
* @return {array} 新的形状点数组
|
|
12674
|
-
*/
|
|
12675
|
-
createCurePoints(shapePoints, p) {
|
|
12676
|
-
const startPoint = shapePoints[shapePoints.length - 1];
|
|
12677
|
-
if (!startPoint || !p) return shapePoints;
|
|
12678
|
-
if (startPoint.x === undefined || startPoint.x === null || startPoint.y === undefined || startPoint.y === null || p.x === undefined || p.x === null || p.y === undefined || p.y === null) {
|
|
12679
|
-
return shapePoints;
|
|
12680
|
-
}
|
|
12681
|
-
const p1 = {
|
|
12682
|
-
x: startPoint.x + (p.x - startPoint.x) / 5,
|
|
12683
|
-
y: startPoint.y
|
|
12684
|
-
};
|
|
12685
|
-
const p2 = {
|
|
12686
|
-
x: startPoint.x + (p.x - startPoint.x) / 2,
|
|
12687
|
-
y: p.y - (p.y - startPoint.y) / 2
|
|
12688
|
-
};
|
|
12689
|
-
const p3 = {
|
|
12690
|
-
x: p.x - (p.x - startPoint.x) / 5,
|
|
12691
|
-
y: p.y
|
|
12692
|
-
};
|
|
12693
|
-
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
12694
|
-
this.__bezier.cpoints = [startPoint, p1, p2, p3, p];
|
|
12695
|
-
const bzpoints = this.__bezier.initPoints();
|
|
12696
|
-
if (bzpoints && bzpoints.length) {
|
|
12697
|
-
shapePoints = shapePoints.concat(bzpoints);
|
|
12698
|
-
}
|
|
12699
|
-
return shapePoints;
|
|
12700
|
-
}
|
|
12701
|
-
|
|
12702
|
-
/**
|
|
12703
|
-
* 创建虚线点
|
|
12704
|
-
*
|
|
12705
|
-
* @method createDotLine
|
|
12706
|
-
* @for jmAreaSeries
|
|
12707
|
-
* @param {array} shapePoints 形状点数组
|
|
12708
|
-
* @param {object} p 当前点
|
|
12709
|
-
* @return {array} 新的形状点数组
|
|
12710
|
-
*/
|
|
12711
|
-
createDotLine(shapePoints, p) {
|
|
12712
|
-
const startPoint = shapePoints[shapePoints.length - 1];
|
|
12713
|
-
if (!startPoint || !p) return shapePoints;
|
|
12714
|
-
if (startPoint.x === undefined || startPoint.x === null || startPoint.y === undefined || startPoint.y === null || p.x === undefined || p.x === null || p.y === undefined || p.y === null) {
|
|
12715
|
-
return shapePoints;
|
|
12716
|
-
}
|
|
12717
|
-
this.__line = this.__line || this.graph.createShape('line', {
|
|
12718
|
-
style: this.style
|
|
12719
|
-
});
|
|
12720
|
-
this.__line.start = startPoint;
|
|
12721
|
-
this.__line.end = p;
|
|
12722
|
-
const dots = this.__line.initPoints();
|
|
12723
|
-
if (dots && dots.length) {
|
|
12724
|
-
shapePoints = shapePoints.concat(dots);
|
|
12725
|
-
}
|
|
12726
|
-
return shapePoints;
|
|
12727
|
-
}
|
|
12728
|
-
|
|
12729
|
-
/**
|
|
12730
|
-
* 生成面积效果
|
|
12731
|
-
*
|
|
12732
|
-
* @method createArea
|
|
12733
|
-
* @for jmAreaSeries
|
|
12734
|
-
* @param {array} points 数据点数组
|
|
12735
|
-
* @param {boolean} needClosePoint 是否需要闭合点
|
|
12736
|
-
*/
|
|
12737
|
-
createArea(points, needClosePoint = true) {
|
|
12738
|
-
// 有指定绘制区域效果才展示
|
|
12739
|
-
if (!this.style.area || points.length < 2) return;
|
|
12740
|
-
const start = points[0];
|
|
12741
|
-
const end = points[points.length - 1];
|
|
12742
|
-
const style = this.graph.utils.clone(this.style.area, {}, true);
|
|
12743
|
-
// 连框颜色如果没指定,就透明
|
|
12744
|
-
style.stroke = style.stroke || 'transparent';
|
|
12745
|
-
if (!style.fill) {
|
|
12746
|
-
const color = this.graph.utils.hexToRGBA(this.style.stroke);
|
|
12747
|
-
style.fill = `linear-gradient(50% 0 50% 100%,
|
|
12748
|
-
rgba(${color.r},${color.g},${color.b}, 0) 1,
|
|
12749
|
-
rgba(${color.r},${color.g},${color.b}, 0.1) 0.7,
|
|
12750
|
-
rgba(${color.r},${color.g},${color.b}, 0.3) 0)`;
|
|
12751
|
-
} else if (typeof style.fill === 'function') {
|
|
12752
|
-
style.fill = style.fill.call(this, style);
|
|
12753
|
-
}
|
|
12754
|
-
const area = this.graph.createShape('path', {
|
|
12755
|
-
points: this.graph.utils.clone(points, true),
|
|
12756
|
-
style,
|
|
12757
|
-
width: this.graph.chartArea.width,
|
|
12758
|
-
height: this.graph.chartArea.height
|
|
12759
|
-
});
|
|
12760
|
-
|
|
12761
|
-
// 在点集合前后加上落地到X轴的点就可以组成一个封闭的图形area
|
|
12762
|
-
if (needClosePoint) {
|
|
12763
|
-
area.points.unshift({
|
|
12764
|
-
x: start.x,
|
|
12765
|
-
y: this.baseY
|
|
12766
|
-
});
|
|
12767
|
-
area.points.push({
|
|
12768
|
-
x: end.x,
|
|
12769
|
-
y: this.baseY
|
|
12770
|
-
});
|
|
12771
|
-
}
|
|
12772
|
-
this.addShape(area);
|
|
12773
|
-
}
|
|
12774
|
-
|
|
12775
12938
|
/**
|
|
12776
12939
|
* 生成图例
|
|
12777
|
-
*
|
|
12778
|
-
* @method createLegend
|
|
12779
|
-
* @for jmAreaSeries
|
|
12780
12940
|
*/
|
|
12781
12941
|
createLegend() {
|
|
12782
|
-
// 生成图例前的图标
|
|
12783
12942
|
var style = this.graph.utils.clone(this.style);
|
|
12784
12943
|
style.stroke = style.color;
|
|
12944
|
+
style.fill = style.color;
|
|
12785
12945
|
var shape = this.graph.createShape('path', {
|
|
12786
12946
|
style: style
|
|
12787
12947
|
});
|
|
@@ -12803,8 +12963,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12803
12963
|
y: 0
|
|
12804
12964
|
};
|
|
12805
12965
|
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
12806
|
-
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12807
|
-
|
|
12966
|
+
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12808
12967
|
shape.points = this.__bezier.initPoints();
|
|
12809
12968
|
} else {
|
|
12810
12969
|
shape.points = [{
|
|
@@ -12819,8 +12978,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12819
12978
|
}
|
|
12820
12979
|
}
|
|
12821
12980
|
|
|
12822
|
-
const ANIMATION_DATA_THRESHOLD = 100;
|
|
12823
|
-
const DEFAULT_ANIMATION_COUNT = 10;
|
|
12824
12981
|
class jmWaterfallSeries extends jmSeries {
|
|
12825
12982
|
constructor(options) {
|
|
12826
12983
|
options.style = options.style || options.graph.style.waterfall;
|
|
@@ -14253,12 +14410,11 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14253
14410
|
if (chart.style.markLine.longtap) {
|
|
14254
14411
|
longtap = 1;
|
|
14255
14412
|
longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
|
|
14256
|
-
|
|
14413
|
+
const tapStartTime = Date.now();
|
|
14257
14414
|
const reqFun = () => {
|
|
14258
|
-
const elapsed = Date.now() - tapStartTime;
|
|
14259
14415
|
if (longtap === 1 || longtap === 2) {
|
|
14260
14416
|
// 如果还未过一定时间,则继续等待
|
|
14261
|
-
if (
|
|
14417
|
+
if (Date.now() - tapStartTime < 500) {
|
|
14262
14418
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14263
14419
|
return;
|
|
14264
14420
|
}
|
|
@@ -14269,9 +14425,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14269
14425
|
};
|
|
14270
14426
|
// 如果一定时间后还没有取消,则表示长按了
|
|
14271
14427
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14272
|
-
|
|
14273
|
-
//args.event.stopPropagation();
|
|
14274
|
-
//args.event.preventDefault();// 阻止默认行为
|
|
14275
14428
|
} else {
|
|
14276
14429
|
this.startMove(args);
|
|
14277
14430
|
}
|
|
@@ -14378,7 +14531,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14378
14531
|
* @module jmChart
|
|
14379
14532
|
* @param {element} container 图表容器
|
|
14380
14533
|
*/
|
|
14381
|
-
class jmChart extends
|
|
14534
|
+
class jmChart extends jmGraphImpl {
|
|
14382
14535
|
constructor(container, options) {
|
|
14383
14536
|
options = options || {};
|
|
14384
14537
|
const enableAnimate = !!options.enableAnimate;
|
|
@@ -14472,25 +14625,27 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14472
14625
|
|
|
14473
14626
|
// 绑定点击事件
|
|
14474
14627
|
this.on('click', args => {
|
|
14475
|
-
if (this.option.onClick)
|
|
14476
|
-
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14628
|
+
if (!this.option.onClick) return;
|
|
14629
|
+
// 找到点击位置的数据点
|
|
14630
|
+
let closestPoint = null;
|
|
14631
|
+
let minDistance = 20; // 20px 范围,同时作为阈值,无需再比较小于阈值
|
|
14632
|
+
|
|
14633
|
+
this.series.each((i, serie) => {
|
|
14634
|
+
if (!serie.dataPoints) return;
|
|
14635
|
+
const points = serie.dataPoints;
|
|
14636
|
+
for (let j = 0, len = points.length; j < len; j++) {
|
|
14637
|
+
const point = points[j];
|
|
14638
|
+
const dx = args.position.x - point.x;
|
|
14639
|
+
const dy = args.position.y - point.y;
|
|
14640
|
+
const distance = dx * dx + dy * dy; // 避免开方,直接比较平方
|
|
14641
|
+
if (distance < minDistance * minDistance) {
|
|
14642
|
+
minDistance = distance;
|
|
14643
|
+
closestPoint = point;
|
|
14489
14644
|
}
|
|
14490
|
-
});
|
|
14491
|
-
if (closestPoint) {
|
|
14492
|
-
this.option.onClick(closestPoint);
|
|
14493
14645
|
}
|
|
14646
|
+
});
|
|
14647
|
+
if (closestPoint) {
|
|
14648
|
+
this.option.onClick(closestPoint);
|
|
14494
14649
|
}
|
|
14495
14650
|
});
|
|
14496
14651
|
}
|
|
@@ -14520,7 +14675,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14520
14675
|
options = this.utils.clone(options, {
|
|
14521
14676
|
autoRefresh: true
|
|
14522
14677
|
}, true);
|
|
14523
|
-
this.touchGraph = new
|
|
14678
|
+
this.touchGraph = new jmGraphImpl(cn, options);
|
|
14524
14679
|
this.touchGraph.chartGraph = this;
|
|
14525
14680
|
this.on('propertyChange', (name, args) => {
|
|
14526
14681
|
if (['width', 'height'].includes(name)) {
|
|
@@ -14560,8 +14715,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14560
14715
|
delete this.xAxis;
|
|
14561
14716
|
}
|
|
14562
14717
|
if (this.yAxises) {
|
|
14563
|
-
|
|
14564
|
-
|
|
14718
|
+
const keys = Object.keys(this.yAxises);
|
|
14719
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14720
|
+
this.yAxises[keys[k]].remove();
|
|
14565
14721
|
}
|
|
14566
14722
|
delete this.yAxises;
|
|
14567
14723
|
}
|
|
@@ -14573,18 +14729,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14573
14729
|
* @param {int} index 颜色索引
|
|
14574
14730
|
*/
|
|
14575
14731
|
getColor(index) {
|
|
14576
|
-
const
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
}
|
|
14580
|
-
let color;
|
|
14581
|
-
if (index >= this.style.chartColors.length) {
|
|
14582
|
-
color = this.style.chartColors[index % this.style.chartColors.length];
|
|
14583
|
-
} else {
|
|
14584
|
-
color = this.style.chartColors[index];
|
|
14585
|
-
}
|
|
14586
|
-
this._cache.set(cacheKey, color);
|
|
14587
|
-
return color;
|
|
14732
|
+
const colors = this.style.chartColors;
|
|
14733
|
+
const colorIndex = index % colors.length;
|
|
14734
|
+
return colors[colorIndex];
|
|
14588
14735
|
}
|
|
14589
14736
|
|
|
14590
14737
|
/**
|
|
@@ -14602,40 +14749,43 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14602
14749
|
this.xAxis.clear();
|
|
14603
14750
|
}
|
|
14604
14751
|
if (this.yAxises) {
|
|
14605
|
-
|
|
14606
|
-
|
|
14752
|
+
const keys = Object.keys(this.yAxises);
|
|
14753
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14754
|
+
this.yAxises[keys[k]].clear();
|
|
14607
14755
|
}
|
|
14608
14756
|
}
|
|
14609
14757
|
this.barSeriesCount = 0;
|
|
14758
|
+
// 合并两次 series 遍历为一次,减少遍历开销
|
|
14759
|
+
const seriesInited = [];
|
|
14610
14760
|
this.series.each((i, serie) => {
|
|
14611
14761
|
if (!serie.style.color) {
|
|
14612
14762
|
serie.style.color = serie.graph.getColor(i);
|
|
14613
14763
|
}
|
|
14614
|
-
if (serie
|
|
14615
|
-
if (serie
|
|
14764
|
+
if (serie instanceof jmBarSeries) {
|
|
14765
|
+
if (serie.graph.style.layout != 'inside') {
|
|
14616
14766
|
serie.graph.style.layout = 'inside';
|
|
14617
14767
|
}
|
|
14618
|
-
}
|
|
14619
|
-
if (serie instanceof jmBarSeries) {
|
|
14620
14768
|
serie.barIndex = serie.graph.barSeriesCount;
|
|
14621
14769
|
serie.graph.barSeriesCount++;
|
|
14622
14770
|
}
|
|
14623
14771
|
serie.reset();
|
|
14772
|
+
seriesInited.push(serie);
|
|
14624
14773
|
});
|
|
14625
14774
|
if (this.legend) {
|
|
14626
14775
|
this.legend.reset();
|
|
14627
14776
|
}
|
|
14628
14777
|
if (this.yAxises) {
|
|
14629
|
-
|
|
14630
|
-
|
|
14778
|
+
const keys = Object.keys(this.yAxises);
|
|
14779
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14780
|
+
this.yAxises[keys[k]].reset();
|
|
14631
14781
|
}
|
|
14632
14782
|
}
|
|
14633
14783
|
if (this.xAxis) {
|
|
14634
14784
|
this.xAxis.reset();
|
|
14635
14785
|
}
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
}
|
|
14786
|
+
for (let i = 0; i < seriesInited.length; i++) {
|
|
14787
|
+
seriesInited[i].init && seriesInited[i].init();
|
|
14788
|
+
}
|
|
14639
14789
|
}
|
|
14640
14790
|
|
|
14641
14791
|
/**
|
|
@@ -14813,14 +14963,35 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14813
14963
|
this.initChart();
|
|
14814
14964
|
},
|
|
14815
14965
|
updated() {
|
|
14816
|
-
this.
|
|
14966
|
+
this.refresh();
|
|
14817
14967
|
},
|
|
14818
14968
|
destroyed() {
|
|
14819
14969
|
this.chartInstance && this.chartInstance.destroy();
|
|
14820
14970
|
},
|
|
14821
14971
|
watch: {
|
|
14822
|
-
chartData:
|
|
14823
|
-
|
|
14972
|
+
chartData: {
|
|
14973
|
+
handler: function (newData, oldData) {
|
|
14974
|
+
this.refresh();
|
|
14975
|
+
},
|
|
14976
|
+
deep: false // 仅监听引用变化,由使用者显式替换数组时触发
|
|
14977
|
+
},
|
|
14978
|
+
chartOptions: {
|
|
14979
|
+
handler: function (newOptions, oldOptions) {
|
|
14980
|
+
// 配置变化时需要重建图表
|
|
14981
|
+
if (this.chartInstance) {
|
|
14982
|
+
this.chartInstance.destroy();
|
|
14983
|
+
this.chartInstance = null;
|
|
14984
|
+
}
|
|
14985
|
+
this.option = Object.assign({
|
|
14986
|
+
enableAnimate: false,
|
|
14987
|
+
legendPosition: 'top',
|
|
14988
|
+
legendVisible: true,
|
|
14989
|
+
width: this.width,
|
|
14990
|
+
height: this.height
|
|
14991
|
+
}, newOptions);
|
|
14992
|
+
this.$nextTick(() => this.initChart());
|
|
14993
|
+
},
|
|
14994
|
+
deep: false
|
|
14824
14995
|
},
|
|
14825
14996
|
width: function (newWidth, oldWidth) {
|
|
14826
14997
|
if (!this.chartInstance) return;
|