jmchart 1.2.13 → 1.2.15
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 +903 -980
- package/dist/jmchart.cjs.js +903 -980
- package/dist/jmchart.esm.js +903 -980
- package/dist/jmchart.iife.js +903 -980
- package/dist/jmchart.system.js +903 -980
- 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
|
/**
|
|
@@ -1306,6 +1315,153 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
1306
1315
|
}
|
|
1307
1316
|
}
|
|
1308
1317
|
|
|
1318
|
+
/**
|
|
1319
|
+
* CSS滤镜效果类
|
|
1320
|
+
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
1321
|
+
*
|
|
1322
|
+
* @class jmFilter
|
|
1323
|
+
* @param {string|object} opt 滤镜参数
|
|
1324
|
+
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1325
|
+
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
1326
|
+
*/
|
|
1327
|
+
class jmFilter {
|
|
1328
|
+
constructor(opt) {
|
|
1329
|
+
this.filters = [];
|
|
1330
|
+
|
|
1331
|
+
if(typeof opt === 'string') {
|
|
1332
|
+
this.fromString(opt);
|
|
1333
|
+
}
|
|
1334
|
+
else if(opt && typeof opt === 'object') {
|
|
1335
|
+
for(let k in opt) {
|
|
1336
|
+
if(k === 'constructor' || k === 'filters') continue;
|
|
1337
|
+
this.addFilter(k, opt[k]);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* 添加单个滤镜
|
|
1344
|
+
* @param {string} name 滤镜名称 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
1345
|
+
* @param {number|string} value 滤镜值
|
|
1346
|
+
*/
|
|
1347
|
+
addFilter(name, value) {
|
|
1348
|
+
name = name.toLowerCase().trim();
|
|
1349
|
+
if(typeof value === 'string') {
|
|
1350
|
+
value = parseFloat(value);
|
|
1351
|
+
}
|
|
1352
|
+
if(isNaN(value)) return;
|
|
1353
|
+
|
|
1354
|
+
// 规范化滤镜名称
|
|
1355
|
+
const normalized = {
|
|
1356
|
+
'blur': 'blur',
|
|
1357
|
+
'grayscale': 'grayscale',
|
|
1358
|
+
'greyscale': 'grayscale',
|
|
1359
|
+
'sepia': 'sepia',
|
|
1360
|
+
'brightness': 'brightness',
|
|
1361
|
+
'contrast': 'contrast',
|
|
1362
|
+
'saturate': 'saturate',
|
|
1363
|
+
'hue-rotate': 'hueRotate',
|
|
1364
|
+
'hueRotate': 'hueRotate',
|
|
1365
|
+
'invert': 'invert',
|
|
1366
|
+
'opacity': 'opacity'
|
|
1367
|
+
}[name];
|
|
1368
|
+
|
|
1369
|
+
if(!normalized) return;
|
|
1370
|
+
|
|
1371
|
+
// 检查是否已有同名滤镜,有则更新
|
|
1372
|
+
const existing = this.filters.find(f => f.name === normalized);
|
|
1373
|
+
if(existing) {
|
|
1374
|
+
existing.value = value;
|
|
1375
|
+
}
|
|
1376
|
+
else {
|
|
1377
|
+
this.filters.push({ name: normalized, value: value });
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* 从字符串格式解析滤镜
|
|
1383
|
+
* 格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1384
|
+
* @param {string} s 滤镜字符串
|
|
1385
|
+
*/
|
|
1386
|
+
fromString(s) {
|
|
1387
|
+
if(!s || typeof s !== 'string') return;
|
|
1388
|
+
// 匹配 filterName(value) 模式
|
|
1389
|
+
const regex = /([a-zA-Z-]+)\s*\(\s*([^)]+)\s*\)/g;
|
|
1390
|
+
let match;
|
|
1391
|
+
while((match = regex.exec(s)) !== null) {
|
|
1392
|
+
const name = match[1];
|
|
1393
|
+
const valueStr = match[2].replace(/[a-z%]+$/i, '').trim();
|
|
1394
|
+
const value = parseFloat(valueStr);
|
|
1395
|
+
if(!isNaN(value)) {
|
|
1396
|
+
this.addFilter(name, value);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* 转换为CSS filter字符串格式
|
|
1403
|
+
* @returns {string}
|
|
1404
|
+
*/
|
|
1405
|
+
toString() {
|
|
1406
|
+
return this.filters.map(f => {
|
|
1407
|
+
switch(f.name) {
|
|
1408
|
+
case 'blur':
|
|
1409
|
+
return `blur(${f.value}px)`;
|
|
1410
|
+
case 'hueRotate':
|
|
1411
|
+
return `hue-rotate(${f.value}deg)`;
|
|
1412
|
+
default:
|
|
1413
|
+
return `${f.name}(${f.value})`;
|
|
1414
|
+
}
|
|
1415
|
+
}).join(' ');
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* 转换为Canvas context.filter可用的字符串
|
|
1420
|
+
* @returns {string}
|
|
1421
|
+
*/
|
|
1422
|
+
toCanvasFilter() {
|
|
1423
|
+
if(this.filters.length === 0) return 'none';
|
|
1424
|
+
return this.toString();
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* 检查是否有指定名称的滤镜
|
|
1429
|
+
* @param {string} name 滤镜名称
|
|
1430
|
+
* @returns {boolean}
|
|
1431
|
+
*/
|
|
1432
|
+
has(name) {
|
|
1433
|
+
return this.filters.some(f => f.name === name);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* 获取指定滤镜的值
|
|
1438
|
+
* @param {string} name 滤镜名称
|
|
1439
|
+
* @returns {number|undefined}
|
|
1440
|
+
*/
|
|
1441
|
+
get(name) {
|
|
1442
|
+
const f = this.filters.find(f => f.name === name);
|
|
1443
|
+
return f ? f.value : undefined;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* 移除指定滤镜
|
|
1448
|
+
* @param {string} name 滤镜名称
|
|
1449
|
+
*/
|
|
1450
|
+
remove(name) {
|
|
1451
|
+
const index = this.filters.findIndex(f => f.name === name);
|
|
1452
|
+
if(index > -1) {
|
|
1453
|
+
this.filters.splice(index, 1);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* 清空所有滤镜
|
|
1459
|
+
*/
|
|
1460
|
+
clear() {
|
|
1461
|
+
this.filters = [];
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1309
1465
|
let control_id_counter = 0;
|
|
1310
1466
|
|
|
1311
1467
|
class jmObject {
|
|
@@ -2181,8 +2337,14 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2181
2337
|
|
|
2182
2338
|
// 转为渐变为纹理
|
|
2183
2339
|
toImageData(control, bounds, points=null) {
|
|
2184
|
-
//
|
|
2185
|
-
|
|
2340
|
+
// 缓存基于渐变参数(不含 bounds,因为同一个渐变只是位置不同时纹理相同)
|
|
2341
|
+
const gradientKey = this.toString();
|
|
2342
|
+
if(this.__cachedData && this.__cacheKey === gradientKey &&
|
|
2343
|
+
this.__cachedData.data && this.__cachedData.data.width === Math.ceil(bounds.width) &&
|
|
2344
|
+
this.__cachedData.data.data && this.__cachedData.data.data.height === Math.ceil(bounds.height)) {
|
|
2345
|
+
return this.__cachedData;
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2186
2348
|
if(!control.textureContext) {
|
|
2187
2349
|
return null;
|
|
2188
2350
|
}
|
|
@@ -2200,11 +2362,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2200
2362
|
|
|
2201
2363
|
const data = control.toFillTexture(gradient, bounds, points);
|
|
2202
2364
|
|
|
2203
|
-
|
|
2365
|
+
this.__cachedData = data;
|
|
2366
|
+
this.__cacheKey = gradientKey;
|
|
2204
2367
|
|
|
2205
2368
|
return data;
|
|
2206
2369
|
}
|
|
2207
2370
|
|
|
2371
|
+
// 当渐变参数变化时使缓存失效
|
|
2372
|
+
invalidateCache() {
|
|
2373
|
+
this.__cachedData = null;
|
|
2374
|
+
this.__cacheKey = null;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2208
2377
|
// 根据绘制图形的坐标计算出对应点的颜色
|
|
2209
2378
|
/*
|
|
2210
2379
|
toPointColors(points) {
|
|
@@ -2825,7 +2994,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2825
2994
|
|
|
2826
2995
|
// 创建程序
|
|
2827
2996
|
createProgram(vertexSrc, fragmentSrc) {
|
|
2828
|
-
this.context.lineWidth(1);
|
|
2829
2997
|
return createProgram(this.context, vertexSrc, fragmentSrc);
|
|
2830
2998
|
}
|
|
2831
2999
|
|
|
@@ -2938,7 +3106,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2938
3106
|
// polygonIndices 顶点索引,
|
|
2939
3107
|
earCutPointsToTriangles(points) {
|
|
2940
3108
|
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
2941
|
-
|
|
3109
|
+
// 快速缓存 key:用长度和首尾点坐标
|
|
3110
|
+
const len = points.length;
|
|
3111
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
2942
3112
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
2943
3113
|
|
|
2944
3114
|
const ps = this.earCutPoints(points);// 切割得到3角色顶点索引,
|
|
@@ -3033,31 +3203,11 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3033
3203
|
|
|
3034
3204
|
this.textureContext.fillStyle = fillStyle;
|
|
3035
3205
|
|
|
3036
|
-
|
|
3206
|
+
// 规则图形用 fillRect,比 beginPath/lineTo/fill 快
|
|
3037
3207
|
if(!points || !points.length) {
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
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) {
|
|
3208
|
+
this.textureContext.fillRect(0, 0, bounds.width, bounds.height);
|
|
3209
|
+
} else {
|
|
3210
|
+
this.textureContext.beginPath();
|
|
3061
3211
|
for(const p of points) {
|
|
3062
3212
|
//移至当前坐标
|
|
3063
3213
|
if(p.m) {
|
|
@@ -3066,17 +3216,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3066
3216
|
else {
|
|
3067
3217
|
this.textureContext.lineTo(p.x - bounds.left, p.y - bounds.top);
|
|
3068
3218
|
}
|
|
3069
|
-
}
|
|
3070
|
-
|
|
3071
|
-
|
|
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);
|
|
3219
|
+
}
|
|
3220
|
+
this.textureContext.closePath();
|
|
3221
|
+
this.textureContext.fill();
|
|
3077
3222
|
}
|
|
3078
|
-
this.textureContext.closePath();
|
|
3079
|
-
this.textureContext.fill();
|
|
3080
3223
|
|
|
3081
3224
|
const data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
|
|
3082
3225
|
return {
|
|
@@ -3095,6 +3238,40 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3095
3238
|
this.needCut = option.needCut || false;
|
|
3096
3239
|
this.control = option.control;
|
|
3097
3240
|
this.points = [];
|
|
3241
|
+
// 缓存 buffer 和纹理,避免每帧创建/销毁
|
|
3242
|
+
this.__cachedBuffers = [];
|
|
3243
|
+
this.__cachedTexture = null;
|
|
3244
|
+
this.__cachedTextureKey = null;
|
|
3245
|
+
}
|
|
3246
|
+
|
|
3247
|
+
// 释放缓存的 WebGL 资源
|
|
3248
|
+
dispose() {
|
|
3249
|
+
for(const buf of this.__cachedBuffers) {
|
|
3250
|
+
this.deleteBuffer(buf);
|
|
3251
|
+
}
|
|
3252
|
+
this.__cachedBuffers = [];
|
|
3253
|
+
if(this.__cachedTexture) {
|
|
3254
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3255
|
+
this.__cachedTexture = null;
|
|
3256
|
+
this.__cachedTextureKey = null;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
// 获取或创建 buffer,优先复用缓存
|
|
3261
|
+
getOrCreateBuffer(data, attr) {
|
|
3262
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3263
|
+
if(buffer) {
|
|
3264
|
+
const gl = this.context;
|
|
3265
|
+
const float32 = new Float32Array(data);
|
|
3266
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3267
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3268
|
+
buffer.data = data;
|
|
3269
|
+
return buffer;
|
|
3270
|
+
}
|
|
3271
|
+
buffer = this.createFloat32Buffer(data);
|
|
3272
|
+
buffer.attr = attr;
|
|
3273
|
+
this.__cachedBuffers.push(buffer);
|
|
3274
|
+
return buffer;
|
|
3098
3275
|
}
|
|
3099
3276
|
|
|
3100
3277
|
// 应用变换到点
|
|
@@ -3107,8 +3284,14 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3107
3284
|
//this.useProgram();
|
|
3108
3285
|
|
|
3109
3286
|
if(parentBounds) this.parentAbsoluteBounds = parentBounds;
|
|
3110
|
-
//
|
|
3111
|
-
|
|
3287
|
+
// 缓存中心点值,只在变化时才更新 uniform
|
|
3288
|
+
const cx = this.graph.width / 2;
|
|
3289
|
+
const cy = this.graph.height / 2;
|
|
3290
|
+
if(this.__lastCenterX !== cx || this.__lastCenterY !== cy) {
|
|
3291
|
+
this.context.uniform2f(this.program.uniforms.a_center_point.location, cx, cy);
|
|
3292
|
+
this.__lastCenterX = cx;
|
|
3293
|
+
this.__lastCenterY = cy;
|
|
3294
|
+
}
|
|
3112
3295
|
}
|
|
3113
3296
|
|
|
3114
3297
|
setFragColor(color) {
|
|
@@ -3149,6 +3332,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3149
3332
|
endDraw() {
|
|
3150
3333
|
if(this.points) delete this.points;
|
|
3151
3334
|
if(this.pathPoints) delete this.pathPoints;
|
|
3335
|
+
// 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
3152
3336
|
}
|
|
3153
3337
|
|
|
3154
3338
|
// 图形封闭
|
|
@@ -3160,21 +3344,47 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3160
3344
|
}
|
|
3161
3345
|
}
|
|
3162
3346
|
|
|
3163
|
-
//
|
|
3347
|
+
// 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
3164
3348
|
writePoints(points, attr = this.program.attrs.a_position) {
|
|
3165
|
-
|
|
3166
3349
|
const fixedPoints = [];
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3350
|
+
const [a, b, c, d, tx, ty] = this.transformMatrix;
|
|
3351
|
+
const isIdentity = (a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0);
|
|
3352
|
+
const offsetLeft = this.parentAbsoluteBounds.left;
|
|
3353
|
+
const offsetTop = this.parentAbsoluteBounds.top;
|
|
3354
|
+
|
|
3355
|
+
if(isIdentity) {
|
|
3356
|
+
// 单位矩阵时直接加偏移,避免逐点调用 applyTransform
|
|
3357
|
+
for(let i = 0; i < points.length; i++) {
|
|
3358
|
+
fixedPoints.push(points[i].x + offsetLeft, points[i].y + offsetTop);
|
|
3359
|
+
}
|
|
3360
|
+
} else {
|
|
3361
|
+
for(const p of points) {
|
|
3362
|
+
const transformedPoint = this.applyTransform(p);
|
|
3363
|
+
fixedPoints.push(
|
|
3364
|
+
transformedPoint.x + offsetLeft,
|
|
3365
|
+
transformedPoint.y + offsetTop
|
|
3366
|
+
);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
const float32 = new Float32Array(fixedPoints);
|
|
3370
|
+
const gl = this.context;
|
|
3371
|
+
|
|
3372
|
+
// 复用已有 buffer 或创建新的
|
|
3373
|
+
if(this.__cachedBuffers.length > 0) {
|
|
3374
|
+
// 找一个同 attr 的 buffer 复用
|
|
3375
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3376
|
+
if(buffer) {
|
|
3377
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3378
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3379
|
+
buffer.data = fixedPoints;
|
|
3380
|
+
this.writeVertexAttrib(buffer, attr, 2, 0, 0);
|
|
3381
|
+
return buffer;
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
const vertexBuffer = this.createFloat32Buffer(float32, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3176
3385
|
this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
|
|
3177
3386
|
vertexBuffer.attr = attr;
|
|
3387
|
+
this.__cachedBuffers.push(vertexBuffer);
|
|
3178
3388
|
return vertexBuffer;
|
|
3179
3389
|
}
|
|
3180
3390
|
|
|
@@ -3410,9 +3620,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3410
3620
|
|
|
3411
3621
|
// 分割成一个个规则的三角形,不规则的多边形不全割的话纹理就会没法正确覆盖
|
|
3412
3622
|
getTriangles(points) {
|
|
3413
|
-
|
|
3414
3623
|
this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
|
|
3415
|
-
|
|
3624
|
+
// 快速缓存 key:用长度和首尾点坐标(比 JSON.stringify 快几个数量级)
|
|
3625
|
+
const len = points.length;
|
|
3626
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
3416
3627
|
if(this.trianglesCache[key]) return this.trianglesCache[key];
|
|
3417
3628
|
|
|
3418
3629
|
const res = [];
|
|
@@ -3449,12 +3660,11 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3449
3660
|
if(points && points.length) {
|
|
3450
3661
|
const regular = lineWidth <= 1.2;
|
|
3451
3662
|
points = regular? points : this.pathToPoints(points);
|
|
3452
|
-
|
|
3663
|
+
this.writePoints(points);
|
|
3453
3664
|
this.context.drawArrays(regular? this.context.LINE_LOOP: this.context.POINTS, 0, points.length);
|
|
3454
|
-
|
|
3665
|
+
// buffer 由 endDraw 统一清理
|
|
3455
3666
|
}
|
|
3456
|
-
colorBuffer && this.
|
|
3457
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3667
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3458
3668
|
}
|
|
3459
3669
|
|
|
3460
3670
|
// 填充图形
|
|
@@ -3485,8 +3695,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3485
3695
|
|
|
3486
3696
|
this.fillPolygons(points);
|
|
3487
3697
|
|
|
3488
|
-
colorBuffer && this.
|
|
3489
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3698
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3490
3699
|
|
|
3491
3700
|
}
|
|
3492
3701
|
|
|
@@ -3496,8 +3705,24 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3496
3705
|
fillImage(img, points, bounds) {
|
|
3497
3706
|
if(!img) return;
|
|
3498
3707
|
|
|
3499
|
-
//
|
|
3500
|
-
|
|
3708
|
+
// 对于 ImageData,生成缓存 key(基于渐变参数或 bounds),复用纹理
|
|
3709
|
+
let texture = null;
|
|
3710
|
+
if(img instanceof ImageData) {
|
|
3711
|
+
const key = `${img.width}_${img.height}_${bounds.width}_${bounds.height}_${bounds.left}_${bounds.top}`;
|
|
3712
|
+
if(this.__cachedTexture && this.__cachedTextureKey === key) {
|
|
3713
|
+
texture = this.__cachedTexture;
|
|
3714
|
+
} else {
|
|
3715
|
+
texture = this.createDataTexture(img);
|
|
3716
|
+
// 释放旧纹理
|
|
3717
|
+
if(this.__cachedTexture) {
|
|
3718
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3719
|
+
}
|
|
3720
|
+
this.__cachedTexture = texture;
|
|
3721
|
+
this.__cachedTextureKey = key;
|
|
3722
|
+
}
|
|
3723
|
+
} else {
|
|
3724
|
+
texture = this.createImgTexture(img);
|
|
3725
|
+
}
|
|
3501
3726
|
this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
|
|
3502
3727
|
|
|
3503
3728
|
// 指定纹理区域尺寸
|
|
@@ -3510,7 +3735,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3510
3735
|
|
|
3511
3736
|
this.fillTexture(points);
|
|
3512
3737
|
|
|
3513
|
-
|
|
3738
|
+
// 仅对非缓存纹理(非 ImageData)立即删除
|
|
3739
|
+
if(!(img instanceof ImageData)) {
|
|
3740
|
+
this.deleteTexture(texture);
|
|
3741
|
+
}
|
|
3514
3742
|
}
|
|
3515
3743
|
|
|
3516
3744
|
fillTexture(points) {
|
|
@@ -3526,23 +3754,67 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3526
3754
|
|
|
3527
3755
|
// 进行多边形填充
|
|
3528
3756
|
fillPolygons(points, isTexture = false) {
|
|
3529
|
-
if(points.length
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
}
|
|
3757
|
+
if(points.length <= 3) {
|
|
3758
|
+
// 3个点以下的三角形直接画
|
|
3759
|
+
this.writePoints(points);
|
|
3760
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3761
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3762
|
+
return;
|
|
3536
3763
|
}
|
|
3537
|
-
else {
|
|
3538
|
-
const buffer = this.writePoints(points);
|
|
3539
|
-
// 纹理坐标
|
|
3540
|
-
const coordBuffer = isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3541
3764
|
|
|
3765
|
+
// 规则图形(凸多边形,如圆):直接用 TRIANGLE_FAN 一次性绘制,无需 earcut
|
|
3766
|
+
if(this.isRegular) {
|
|
3767
|
+
this.writePoints(points);
|
|
3768
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3542
3769
|
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3543
|
-
|
|
3544
|
-
|
|
3770
|
+
return;
|
|
3771
|
+
}
|
|
3772
|
+
|
|
3773
|
+
// 不规则图形:需要 earcut 三角化后,合并为一个大的顶点缓冲区,单次 drawArrays
|
|
3774
|
+
const triangles = this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
|
|
3775
|
+
if(!triangles.length) return;
|
|
3776
|
+
|
|
3777
|
+
// 合并所有三角形的顶点到一个数组
|
|
3778
|
+
const allVertices = [];
|
|
3779
|
+
const allTexCoords = [];
|
|
3780
|
+
for(const triangle of triangles) {
|
|
3781
|
+
for(const p of triangle) {
|
|
3782
|
+
allVertices.push(p.x, p.y);
|
|
3783
|
+
if(isTexture) allTexCoords.push(p.x, p.y);
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
|
|
3787
|
+
// 一次性上传所有数据并绘制
|
|
3788
|
+
const vertexData = new Float32Array(allVertices);
|
|
3789
|
+
const gl = this.context;
|
|
3790
|
+
|
|
3791
|
+
// 复用或创建 position buffer
|
|
3792
|
+
let posBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_position);
|
|
3793
|
+
if(!posBuffer) {
|
|
3794
|
+
posBuffer = this.createFloat32Buffer(vertexData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3795
|
+
posBuffer.attr = this.program.attrs.a_position;
|
|
3796
|
+
this.__cachedBuffers.push(posBuffer);
|
|
3797
|
+
} else {
|
|
3798
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer.buffer);
|
|
3799
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.DYNAMIC_DRAW);
|
|
3800
|
+
}
|
|
3801
|
+
this.writeVertexAttrib(posBuffer, this.program.attrs.a_position, 2, 0, 0);
|
|
3802
|
+
|
|
3803
|
+
if(isTexture && allTexCoords.length) {
|
|
3804
|
+
const texData = new Float32Array(allTexCoords);
|
|
3805
|
+
let texBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_text_coord);
|
|
3806
|
+
if(!texBuffer) {
|
|
3807
|
+
texBuffer = this.createFloat32Buffer(texData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3808
|
+
texBuffer.attr = this.program.attrs.a_text_coord;
|
|
3809
|
+
this.__cachedBuffers.push(texBuffer);
|
|
3810
|
+
} else {
|
|
3811
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texBuffer.buffer);
|
|
3812
|
+
gl.bufferData(gl.ARRAY_BUFFER, texData, gl.DYNAMIC_DRAW);
|
|
3813
|
+
}
|
|
3814
|
+
this.writeVertexAttrib(texBuffer, this.program.attrs.a_text_coord, 2, 0, 0);
|
|
3545
3815
|
}
|
|
3816
|
+
|
|
3817
|
+
gl.drawArrays(gl.TRIANGLES, 0, allVertices.length / 2);
|
|
3546
3818
|
}
|
|
3547
3819
|
|
|
3548
3820
|
// 填充图形
|
|
@@ -3624,7 +3896,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3624
3896
|
'shadowOffsetY' : 'shadowOffsetY',
|
|
3625
3897
|
'shadowColor' : 'shadowColor',
|
|
3626
3898
|
'lineJoin': 'lineJoin',
|
|
3627
|
-
'lineCap':'lineCap'
|
|
3899
|
+
'lineCap':'lineCap',
|
|
3900
|
+
'lineDashOffset': 'lineDashOffset',
|
|
3901
|
+
'globalCompositeOperation': 'globalCompositeOperation'
|
|
3628
3902
|
};
|
|
3629
3903
|
|
|
3630
3904
|
class jmControl extends jmProperty {
|
|
@@ -3835,7 +4109,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3835
4109
|
}
|
|
3836
4110
|
|
|
3837
4111
|
setStyle(style) {
|
|
3838
|
-
|
|
4112
|
+
if(!style) {
|
|
4113
|
+
style = this.style;
|
|
4114
|
+
}
|
|
3839
4115
|
if(!style) return;
|
|
3840
4116
|
|
|
3841
4117
|
const __setStyle = (style, name, mpkey) => {
|
|
@@ -3919,6 +4195,120 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3919
4195
|
this.cursor = styleValue;
|
|
3920
4196
|
break;
|
|
3921
4197
|
}
|
|
4198
|
+
// ===== 新增样式特性 =====
|
|
4199
|
+
|
|
4200
|
+
// 虚线样式:支持自定义lineDash模式 (如 [5, 3, 2] 或 "5,3,2")
|
|
4201
|
+
case 'lineDash' : {
|
|
4202
|
+
if(!this.context.setLineDash) break;
|
|
4203
|
+
let dash;
|
|
4204
|
+
if(typeof styleValue === 'string') {
|
|
4205
|
+
dash = styleValue.split(',').map(v => parseFloat(v.trim())).filter(v => !isNaN(v));
|
|
4206
|
+
}
|
|
4207
|
+
else if(Array.isArray(styleValue)) {
|
|
4208
|
+
dash = styleValue.map(v => parseFloat(v)).filter(v => !isNaN(v));
|
|
4209
|
+
}
|
|
4210
|
+
if(dash && dash.length) {
|
|
4211
|
+
this.context.setLineDash(dash);
|
|
4212
|
+
}
|
|
4213
|
+
else {
|
|
4214
|
+
this.context.setLineDash([]);
|
|
4215
|
+
}
|
|
4216
|
+
break;
|
|
4217
|
+
}
|
|
4218
|
+
// 虚线偏移量
|
|
4219
|
+
case 'lineDashOffset' : {
|
|
4220
|
+
if(!this.context.setLineDash) break;
|
|
4221
|
+
this.context.lineDashOffset = Number(styleValue) || 0;
|
|
4222
|
+
break;
|
|
4223
|
+
}
|
|
4224
|
+
// CSS滤镜效果 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
4225
|
+
case 'filter' : {
|
|
4226
|
+
if(this.context.filter === undefined) break;
|
|
4227
|
+
if(styleValue instanceof jmFilter) {
|
|
4228
|
+
this.context.filter = styleValue.toCanvasFilter();
|
|
4229
|
+
}
|
|
4230
|
+
else if(typeof styleValue === 'string') {
|
|
4231
|
+
this.context.filter = styleValue || 'none';
|
|
4232
|
+
}
|
|
4233
|
+
else if(typeof styleValue === 'object') {
|
|
4234
|
+
this.context.filter = (new jmFilter(styleValue)).toCanvasFilter();
|
|
4235
|
+
}
|
|
4236
|
+
break;
|
|
4237
|
+
}
|
|
4238
|
+
// 混合模式 (source-over, multiply, screen, overlay, darken, lighten, etc.)
|
|
4239
|
+
case 'globalCompositeOperation' : {
|
|
4240
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4241
|
+
this.context.globalCompositeOperation = styleValue;
|
|
4242
|
+
break;
|
|
4243
|
+
}
|
|
4244
|
+
// 裁剪路径:通过canvas clip实现
|
|
4245
|
+
case 'clipPath' : {
|
|
4246
|
+
if(!this.context.clip) break;
|
|
4247
|
+
// clipPath可以是一个图形控件实例
|
|
4248
|
+
if(styleValue && styleValue.points && styleValue.points.length > 0) {
|
|
4249
|
+
const bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
4250
|
+
this.context.beginPath();
|
|
4251
|
+
this.context.moveTo(styleValue.points[0].x + (bounds ? bounds.left : 0), styleValue.points[0].y + (bounds ? bounds.top : 0));
|
|
4252
|
+
for(let i = 1; i < styleValue.points.length; i++) {
|
|
4253
|
+
if(styleValue.points[i].m) {
|
|
4254
|
+
this.context.moveTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4255
|
+
}
|
|
4256
|
+
else {
|
|
4257
|
+
this.context.lineTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
if(styleValue.style && styleValue.style.close) {
|
|
4261
|
+
this.context.closePath();
|
|
4262
|
+
}
|
|
4263
|
+
this.context.clip();
|
|
4264
|
+
}
|
|
4265
|
+
break;
|
|
4266
|
+
}
|
|
4267
|
+
// 遮罩效果:通过globalCompositeOperation + destination-in实现
|
|
4268
|
+
case 'mask' : {
|
|
4269
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4270
|
+
// mask是一个图形控件实例,在绘制前需要先应用mask
|
|
4271
|
+
// 这里只是标记,实际绘制在paint流程中处理
|
|
4272
|
+
this.__mask = styleValue;
|
|
4273
|
+
break;
|
|
4274
|
+
}
|
|
4275
|
+
// 图片阴影描边阴影(WebGL纹理canvas用)
|
|
4276
|
+
case 'shadowColor' : {
|
|
4277
|
+
if(this.webglControl) {
|
|
4278
|
+
this.webglControl.setStyle('shadowColor', styleValue);
|
|
4279
|
+
}
|
|
4280
|
+
else {
|
|
4281
|
+
this.context.shadowColor = jmUtils.toColor(styleValue);
|
|
4282
|
+
}
|
|
4283
|
+
break;
|
|
4284
|
+
}
|
|
4285
|
+
case 'shadowBlur' : {
|
|
4286
|
+
if(this.webglControl) {
|
|
4287
|
+
this.webglControl.setStyle('shadowBlur', styleValue);
|
|
4288
|
+
}
|
|
4289
|
+
else {
|
|
4290
|
+
this.context.shadowBlur = Number(styleValue) || 0;
|
|
4291
|
+
}
|
|
4292
|
+
break;
|
|
4293
|
+
}
|
|
4294
|
+
case 'shadowOffsetX' : {
|
|
4295
|
+
if(this.webglControl) {
|
|
4296
|
+
this.webglControl.setStyle('shadowOffsetX', styleValue);
|
|
4297
|
+
}
|
|
4298
|
+
else {
|
|
4299
|
+
this.context.shadowOffsetX = Number(styleValue) || 0;
|
|
4300
|
+
}
|
|
4301
|
+
break;
|
|
4302
|
+
}
|
|
4303
|
+
case 'shadowOffsetY' : {
|
|
4304
|
+
if(this.webglControl) {
|
|
4305
|
+
this.webglControl.setStyle('shadowOffsetY', styleValue);
|
|
4306
|
+
}
|
|
4307
|
+
else {
|
|
4308
|
+
this.context.shadowOffsetY = Number(styleValue) || 0;
|
|
4309
|
+
}
|
|
4310
|
+
break;
|
|
4311
|
+
}
|
|
3922
4312
|
}
|
|
3923
4313
|
}
|
|
3924
4314
|
}
|
|
@@ -3939,6 +4329,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3939
4329
|
else if(t == 'string' && k == 'shadow') {
|
|
3940
4330
|
style[k] = new jmShadow(style[k]);
|
|
3941
4331
|
}
|
|
4332
|
+
else if(t == 'string' && k == 'filter') {
|
|
4333
|
+
style[k] = new jmFilter(style[k]);
|
|
4334
|
+
}
|
|
3942
4335
|
__setStyle(style[k], k);
|
|
3943
4336
|
}
|
|
3944
4337
|
}
|
|
@@ -4083,25 +4476,30 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4083
4476
|
* @method getLocation
|
|
4084
4477
|
* @return {object} 当前控件位置参数,包括中心点坐标,右上角坐标,宽高
|
|
4085
4478
|
*/
|
|
4086
|
-
getLocation(
|
|
4479
|
+
getLocation() {
|
|
4087
4480
|
//如果已经计算过则直接返回
|
|
4088
4481
|
//在开画之前会清空此对象
|
|
4089
4482
|
//if(reset !== true && this.location) return this.location;
|
|
4090
4483
|
|
|
4091
4484
|
let local = this.location = {left: 0,top: 0,width: 0,height: 0};
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4485
|
+
|
|
4486
|
+
// 检查是否有百分比参数需要解析,没有则直接引用避免克隆开销
|
|
4487
|
+
const needResolve = this.parent && (jmUtils.checkPercent(this.width) || jmUtils.checkPercent(this.height) ||
|
|
4488
|
+
(this.position && jmUtils.checkPercent(this.position.x)) || (this.position && jmUtils.checkPercent(this.position.y)));
|
|
4489
|
+
local.position = typeof this.position == 'function'? this.position(): (needResolve? jmUtils.clone(this.position) : this.position);
|
|
4490
|
+
local.center = this.center && typeof this.center === 'function'?this.center(): (needResolve? jmUtils.clone(this.center) : this.center);//中心
|
|
4491
|
+
local.start = this.start && typeof this.start === 'function'?this.start(): (needResolve? jmUtils.clone(this.start) : this.start);//起点
|
|
4492
|
+
local.end = this.end && typeof this.end === 'function'?this.end(): (needResolve? jmUtils.clone(this.end) : this.end);//起点
|
|
4096
4493
|
local.radius = this.radius;//半径
|
|
4097
4494
|
local.width = this.width;
|
|
4098
4495
|
local.height = this.height;
|
|
4099
4496
|
|
|
4100
|
-
const margin =
|
|
4101
|
-
margin.
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4497
|
+
const margin = this.style.margin;
|
|
4498
|
+
const marginObj = needResolve && margin ? jmUtils.clone(margin, {}) : (margin || {});
|
|
4499
|
+
marginObj.left = (marginObj.left || 0);
|
|
4500
|
+
marginObj.top = (marginObj.top || 0);
|
|
4501
|
+
marginObj.right = (marginObj.right || 0);
|
|
4502
|
+
marginObj.bottom = (marginObj.bottom || 0);
|
|
4105
4503
|
|
|
4106
4504
|
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
4107
4505
|
if(local.position) {
|
|
@@ -4109,8 +4507,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4109
4507
|
local.top = local.position.y;
|
|
4110
4508
|
}
|
|
4111
4509
|
else {
|
|
4112
|
-
local.left =
|
|
4113
|
-
local.top =
|
|
4510
|
+
local.left = marginObj.left;
|
|
4511
|
+
local.top = marginObj.top;
|
|
4114
4512
|
}
|
|
4115
4513
|
|
|
4116
4514
|
if(this.parent) {
|
|
@@ -4372,22 +4770,31 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4372
4770
|
if(this.webglControl) this.webglControl.closePath();
|
|
4373
4771
|
this.context.closePath && this.context.closePath();
|
|
4374
4772
|
}
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
if(
|
|
4378
|
-
|
|
4773
|
+
|
|
4774
|
+
// 根据渲染模式选择不同的绘制路径
|
|
4775
|
+
if(this.webglControl) {
|
|
4776
|
+
// WebGL 模式:使用 WebGL 绘制
|
|
4777
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
4778
|
+
if(fill) {
|
|
4379
4779
|
const bounds = this.getBounds();
|
|
4380
4780
|
this.webglControl.fill(bounds);
|
|
4381
4781
|
}
|
|
4382
|
-
this.
|
|
4782
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
4783
|
+
this.webglControl.stroke();
|
|
4784
|
+
}
|
|
4785
|
+
if(this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4383
4786
|
}
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
this.
|
|
4787
|
+
else {
|
|
4788
|
+
// 2D 模式:使用 Canvas 2D API 绘制
|
|
4789
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
4790
|
+
if(fill) {
|
|
4791
|
+
this.context.fill && this.context.fill();
|
|
4792
|
+
}
|
|
4793
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
4794
|
+
this.context.stroke && this.context.stroke();
|
|
4795
|
+
}
|
|
4387
4796
|
}
|
|
4388
4797
|
|
|
4389
|
-
if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4390
|
-
|
|
4391
4798
|
this.needUpdate = false;
|
|
4392
4799
|
}
|
|
4393
4800
|
|
|
@@ -4403,9 +4810,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4403
4810
|
const bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
4404
4811
|
if(this.webglControl) {
|
|
4405
4812
|
this.webglControl.setParentBounds(bounds);
|
|
4406
|
-
this.webglControl.draw(
|
|
4407
|
-
...this.points
|
|
4408
|
-
]);
|
|
4813
|
+
this.webglControl.draw(this.points);
|
|
4409
4814
|
}
|
|
4410
4815
|
else if(this.context && this.context.moveTo) {
|
|
4411
4816
|
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
@@ -4450,9 +4855,44 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4450
4855
|
|
|
4451
4856
|
this.setStyle();//设定样式
|
|
4452
4857
|
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4858
|
+
// 应用mask遮罩效果:在mask区域内绘制当前控件
|
|
4859
|
+
// 使用 destination-in 合成模式,只保留mask区域内的内容
|
|
4860
|
+
const maskStyle = this.style.mask || this.__mask;
|
|
4861
|
+
if(maskStyle && maskStyle.points && this.context.globalCompositeOperation) {
|
|
4862
|
+
// 先绘制当前控件
|
|
4863
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
4864
|
+
if(needDraw && this.draw) this.draw();
|
|
4865
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
4866
|
+
|
|
4867
|
+
// 再应用mask裁剪
|
|
4868
|
+
this.context.globalCompositeOperation = 'destination-in';
|
|
4869
|
+
if(maskStyle.initPoints) maskStyle.initPoints();
|
|
4870
|
+
const mBounds = maskStyle.parent && maskStyle.parent.absoluteBounds ? maskStyle.parent.absoluteBounds : this.absoluteBounds;
|
|
4871
|
+
this.context.beginPath();
|
|
4872
|
+
if(maskStyle.points && maskStyle.points.length > 0) {
|
|
4873
|
+
this.context.moveTo(maskStyle.points[0].x + (mBounds ? mBounds.left : 0), maskStyle.points[0].y + (mBounds ? mBounds.top : 0));
|
|
4874
|
+
for(let i = 1; i < maskStyle.points.length; i++) {
|
|
4875
|
+
if(maskStyle.points[i].m) {
|
|
4876
|
+
this.context.moveTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
4877
|
+
}
|
|
4878
|
+
else {
|
|
4879
|
+
this.context.lineTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
if(maskStyle.style && maskStyle.style.close) {
|
|
4883
|
+
this.context.closePath();
|
|
4884
|
+
}
|
|
4885
|
+
}
|
|
4886
|
+
this.context.fillStyle = '#ffffff';
|
|
4887
|
+
this.context.fill();
|
|
4888
|
+
// 恢复合成模式
|
|
4889
|
+
this.context.globalCompositeOperation = 'source-over';
|
|
4890
|
+
}
|
|
4891
|
+
else {
|
|
4892
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
4893
|
+
if(needDraw && this.draw) this.draw();
|
|
4894
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
4895
|
+
}
|
|
4456
4896
|
|
|
4457
4897
|
if(this.children) {
|
|
4458
4898
|
this.children.each(function(i,item) {
|
|
@@ -4542,7 +4982,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
4542
4982
|
* @param {array} args 事件参数数组
|
|
4543
4983
|
*/
|
|
4544
4984
|
emit(...args) {
|
|
4545
|
-
|
|
4985
|
+
// 避免每帧 args.slice(1) 分配临时数组
|
|
4986
|
+
// runEventHandle 内部会把非数组参数包装成数组
|
|
4987
|
+
if(args.length > 2) {
|
|
4988
|
+
this.runEventHandle(args[0], args.slice(1));
|
|
4989
|
+
} else if(args.length === 2) {
|
|
4990
|
+
this.runEventHandle(args[0], [args[1]]);
|
|
4991
|
+
} else {
|
|
4992
|
+
this.runEventHandle(args[0], []);
|
|
4993
|
+
}
|
|
4546
4994
|
return this;
|
|
4547
4995
|
}
|
|
4548
4996
|
|
|
@@ -5182,7 +5630,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5182
5630
|
if((mw == 0 && mh == 0) || start == end) return;
|
|
5183
5631
|
|
|
5184
5632
|
let anticlockwise = this.anticlockwise;
|
|
5185
|
-
this.points = [];
|
|
5186
5633
|
let step = 1 / Math.max(mw, mh);
|
|
5187
5634
|
|
|
5188
5635
|
//如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
|
|
@@ -5193,18 +5640,33 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5193
5640
|
}
|
|
5194
5641
|
if(start > end) step = -step;
|
|
5195
5642
|
|
|
5196
|
-
|
|
5643
|
+
// 预计算需要的点数量
|
|
5644
|
+
let pointCount = Math.ceil(Math.abs(end - start) / Math.abs(step)) + 1;
|
|
5645
|
+
if(this.isFan) pointCount++;
|
|
5646
|
+
|
|
5647
|
+
// 复用已有数组,避免每帧分配;大小变化时才重建
|
|
5648
|
+
if(!this.points || this.points.length !== pointCount) {
|
|
5649
|
+
this.points = new Array(pointCount);
|
|
5650
|
+
for(let i = 0; i < pointCount; i++) {
|
|
5651
|
+
this.points[i] = { x: 0, y: 0 };
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
|
|
5655
|
+
let idx = 0;
|
|
5656
|
+
if(this.isFan) {
|
|
5657
|
+
this.points[idx].x = location.center.x;
|
|
5658
|
+
this.points[idx].y = location.center.y;
|
|
5659
|
+
idx++;
|
|
5660
|
+
}
|
|
5197
5661
|
|
|
5198
5662
|
//椭圆方程x=a*cos(r) ,y=b*sin(r)
|
|
5199
5663
|
for(let r=start;;r += step) {
|
|
5200
5664
|
if(step > 0 && r > end) r = end;
|
|
5201
5665
|
else if(step < 0 && r < end) r = end;
|
|
5202
5666
|
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
};
|
|
5207
|
-
this.points.push(p);
|
|
5667
|
+
this.points[idx].x = Math.cos(r) * mw + cx;
|
|
5668
|
+
this.points[idx].y = Math.sin(r) * mh + cy;
|
|
5669
|
+
idx++;
|
|
5208
5670
|
|
|
5209
5671
|
if(r == end) break;
|
|
5210
5672
|
}
|
|
@@ -5803,6 +6265,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5803
6265
|
* @class jmRect
|
|
5804
6266
|
* @extends jmPath
|
|
5805
6267
|
* @param {object} params 参数 position=矩形左上角顶点坐标,width=宽,height=高,radius=边角弧度
|
|
6268
|
+
* radius支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
5806
6269
|
*/
|
|
5807
6270
|
class jmRect extends jmPath {
|
|
5808
6271
|
|
|
@@ -5812,12 +6275,24 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5812
6275
|
super(params, t);
|
|
5813
6276
|
|
|
5814
6277
|
this.style.close = true;
|
|
5815
|
-
|
|
6278
|
+
const r = params.radius || this.style.radius || this.style.borderRadius || 0;
|
|
6279
|
+
if(typeof r === 'object' && r !== null) {
|
|
6280
|
+
// 四角独立圆角
|
|
6281
|
+
this.radius = {
|
|
6282
|
+
topLeft: Number(r.topLeft) || 0,
|
|
6283
|
+
topRight: Number(r.topRight) || 0,
|
|
6284
|
+
bottomRight: Number(r.bottomRight) || 0,
|
|
6285
|
+
bottomLeft: Number(r.bottomLeft) || 0
|
|
6286
|
+
};
|
|
6287
|
+
}
|
|
6288
|
+
else {
|
|
6289
|
+
this.radius = r;
|
|
6290
|
+
}
|
|
5816
6291
|
}
|
|
5817
6292
|
/**
|
|
5818
|
-
*
|
|
6293
|
+
* 圆角半径,支持数字或四角独立对象
|
|
5819
6294
|
* @property radius
|
|
5820
|
-
* @type {number}
|
|
6295
|
+
* @type {number|object}
|
|
5821
6296
|
*/
|
|
5822
6297
|
get radius() {
|
|
5823
6298
|
return this.property('radius');
|
|
@@ -5825,6 +6300,36 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5825
6300
|
set radius(v) {
|
|
5826
6301
|
this.needUpdate = true;
|
|
5827
6302
|
return this.property('radius', v);
|
|
6303
|
+
}
|
|
6304
|
+
|
|
6305
|
+
/**
|
|
6306
|
+
* 获取规范化的圆角值(四角独立)
|
|
6307
|
+
* @returns {object} { topLeft, topRight, bottomRight, bottomLeft }
|
|
6308
|
+
*/
|
|
6309
|
+
getNormalizedRadius() {
|
|
6310
|
+
const r = this.radius;
|
|
6311
|
+
if(typeof r === 'number') {
|
|
6312
|
+
const v = Math.max(0, r);
|
|
6313
|
+
return { topLeft: v, topRight: v, bottomRight: v, bottomLeft: v };
|
|
6314
|
+
}
|
|
6315
|
+
if(typeof r === 'object' && r !== null) {
|
|
6316
|
+
return {
|
|
6317
|
+
topLeft: Math.max(0, Number(r.topLeft) || 0),
|
|
6318
|
+
topRight: Math.max(0, Number(r.topRight) || 0),
|
|
6319
|
+
bottomRight: Math.max(0, Number(r.bottomRight) || 0),
|
|
6320
|
+
bottomLeft: Math.max(0, Number(r.bottomLeft) || 0)
|
|
6321
|
+
};
|
|
6322
|
+
}
|
|
6323
|
+
return { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 };
|
|
6324
|
+
}
|
|
6325
|
+
|
|
6326
|
+
/**
|
|
6327
|
+
* 检查是否有圆角
|
|
6328
|
+
* @returns {boolean}
|
|
6329
|
+
*/
|
|
6330
|
+
hasRadius() {
|
|
6331
|
+
const nr = this.getNormalizedRadius();
|
|
6332
|
+
return nr.topLeft > 0 || nr.topRight > 0 || nr.bottomRight > 0 || nr.bottomLeft > 0;
|
|
5828
6333
|
}
|
|
5829
6334
|
|
|
5830
6335
|
/**
|
|
@@ -5887,7 +6392,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5887
6392
|
|
|
5888
6393
|
/**
|
|
5889
6394
|
* 初始化图形点
|
|
5890
|
-
*
|
|
6395
|
+
* 支持四角独立圆角,借助圆弧对象计算描点
|
|
5891
6396
|
*
|
|
5892
6397
|
* @method initPoints
|
|
5893
6398
|
* @private
|
|
@@ -5904,32 +6409,67 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5904
6409
|
this.dottedLine = this.graph.createShape(jmLine, {style: this.style});
|
|
5905
6410
|
}
|
|
5906
6411
|
|
|
5907
|
-
|
|
5908
|
-
|
|
6412
|
+
const nr = this.getNormalizedRadius();
|
|
6413
|
+
const hasRadius = this.hasRadius();
|
|
6414
|
+
|
|
6415
|
+
// 如果有圆角(支持四角独立),借助圆弧对象计算描点
|
|
6416
|
+
if(hasRadius) {
|
|
5909
6417
|
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
|
-
|
|
6418
|
+
|
|
6419
|
+
// 限制圆角不超过短边的一半
|
|
6420
|
+
const maxR = Math.min(location.width / 2, location.height / 2);
|
|
6421
|
+
const rtl = Math.min(nr.topLeft, maxR);
|
|
6422
|
+
const rtr = Math.min(nr.topRight, maxR);
|
|
6423
|
+
const rbr = Math.min(nr.bottomRight, maxR);
|
|
6424
|
+
const rbl = Math.min(nr.bottomLeft, maxR);
|
|
6425
|
+
|
|
6426
|
+
// 左上角圆弧
|
|
6427
|
+
if(rtl > 0) {
|
|
6428
|
+
let arc = this.graph.createShape(jmArc,{radius:rtl,anticlockwise:false});
|
|
6429
|
+
arc.center = {x:location.left + rtl, y:location.top + rtl};
|
|
6430
|
+
arc.startAngle = Math.PI;
|
|
6431
|
+
arc.endAngle = Math.PI + q;
|
|
6432
|
+
var ps1 = arc.initPoints();
|
|
6433
|
+
}
|
|
6434
|
+
else {
|
|
6435
|
+
var ps1 = [p1];
|
|
6436
|
+
}
|
|
6437
|
+
|
|
6438
|
+
// 右上角圆弧
|
|
6439
|
+
if(rtr > 0) {
|
|
6440
|
+
let arc = this.graph.createShape(jmArc,{radius:rtr,anticlockwise:false});
|
|
6441
|
+
arc.center = {x:p2.x - rtr, y:p2.y + rtr};
|
|
6442
|
+
arc.startAngle = Math.PI + q;
|
|
6443
|
+
arc.endAngle = Math.PI * 2;
|
|
6444
|
+
var ps2 = arc.initPoints();
|
|
6445
|
+
}
|
|
6446
|
+
else {
|
|
6447
|
+
var ps2 = [p2];
|
|
6448
|
+
}
|
|
6449
|
+
|
|
6450
|
+
// 右下角圆弧
|
|
6451
|
+
if(rbr > 0) {
|
|
6452
|
+
let arc = this.graph.createShape(jmArc,{radius:rbr,anticlockwise:false});
|
|
6453
|
+
arc.center = {x:p3.x - rbr, y:p3.y - rbr};
|
|
6454
|
+
arc.startAngle = 0;
|
|
6455
|
+
arc.endAngle = q;
|
|
6456
|
+
var ps3 = arc.initPoints();
|
|
6457
|
+
}
|
|
6458
|
+
else {
|
|
6459
|
+
var ps3 = [p3];
|
|
6460
|
+
}
|
|
6461
|
+
|
|
6462
|
+
// 左下角圆弧
|
|
6463
|
+
if(rbl > 0) {
|
|
6464
|
+
let arc = this.graph.createShape(jmArc,{radius:rbl,anticlockwise:false});
|
|
6465
|
+
arc.center = {x:p4.x + rbl, y:p4.y - rbl};
|
|
6466
|
+
arc.startAngle = q;
|
|
6467
|
+
arc.endAngle = Math.PI;
|
|
6468
|
+
var ps4 = arc.initPoints();
|
|
6469
|
+
}
|
|
6470
|
+
else {
|
|
6471
|
+
var ps4 = [p4];
|
|
6472
|
+
}
|
|
5933
6473
|
this.points = ps1.concat(ps2,ps3,ps4);
|
|
5934
6474
|
}
|
|
5935
6475
|
else {
|
|
@@ -6268,7 +6808,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
6268
6808
|
this.style.textAlign = this.style.textAlign || 'left';
|
|
6269
6809
|
//文字垂直对齐
|
|
6270
6810
|
this.style.textBaseline = this.style.textBaseline || 'middle';
|
|
6271
|
-
this.text = params.text || '';
|
|
6811
|
+
this.text = params.text || params.value || '';
|
|
6272
6812
|
|
|
6273
6813
|
this.center = params.center || null;
|
|
6274
6814
|
}
|
|
@@ -6557,67 +7097,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
6557
7097
|
}
|
|
6558
7098
|
}
|
|
6559
7099
|
}
|
|
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
7100
|
}
|
|
6622
7101
|
|
|
6623
7102
|
endDraw() {
|
|
@@ -7566,145 +8045,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7566
8045
|
}
|
|
7567
8046
|
}
|
|
7568
8047
|
|
|
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
8048
|
/**
|
|
7709
8049
|
* jmGraph画图类库
|
|
7710
8050
|
* 对canvas画图api进行二次封装,使其更易调用,省去很多重复的工作。
|
|
@@ -7716,7 +8056,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7716
8056
|
* @param {object} option 参数:{width:宽,height:高}
|
|
7717
8057
|
* @param {function} callback 初始化后的回调
|
|
7718
8058
|
*/
|
|
7719
|
-
class jmGraph
|
|
8059
|
+
class jmGraph extends jmControl {
|
|
7720
8060
|
|
|
7721
8061
|
constructor(canvas, option, callback) {
|
|
7722
8062
|
if(typeof option == 'function') {
|
|
@@ -7934,7 +8274,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7934
8274
|
* @return {jmGraph} jmGraph实例对象
|
|
7935
8275
|
*/
|
|
7936
8276
|
static create(...args) {
|
|
7937
|
-
return new jmGraph
|
|
8277
|
+
return new jmGraph(...args);
|
|
7938
8278
|
}
|
|
7939
8279
|
|
|
7940
8280
|
/**
|
|
@@ -7983,9 +8323,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
7983
8323
|
if(shape) {
|
|
7984
8324
|
if(!args) args = {};
|
|
7985
8325
|
args.graph = this;
|
|
7986
|
-
|
|
7987
|
-
// 添加到活动图层
|
|
7988
|
-
this.addShapeToLayer(obj);
|
|
8326
|
+
const obj = new shape(args);
|
|
7989
8327
|
return obj;
|
|
7990
8328
|
}
|
|
7991
8329
|
}
|
|
@@ -8111,13 +8449,19 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8111
8449
|
this.context.clearRect(0, 0, w, h);
|
|
8112
8450
|
}
|
|
8113
8451
|
else if(this.mode === 'webgl' && this.context.clear) {
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
a
|
|
8119
|
-
}
|
|
8120
|
-
this.
|
|
8452
|
+
// 缓存 clearColor 对象,避免每帧创建
|
|
8453
|
+
if(this.style && this.style.fill) {
|
|
8454
|
+
const color = this.utils.hexToRGBA(this.style.fill);
|
|
8455
|
+
this.__lastClearColor = color;
|
|
8456
|
+
this.context.clearColor(color.r, color.g, color.b, color.a);
|
|
8457
|
+
}
|
|
8458
|
+
else if(!this.__lastClearColor) {
|
|
8459
|
+
this.__lastClearColor = { r: 0, g: 0, b: 0, a: 0 };
|
|
8460
|
+
this.context.clearColor(0, 0, 0, 0);
|
|
8461
|
+
}
|
|
8462
|
+
else {
|
|
8463
|
+
this.context.clearColor(this.__lastClearColor.r, this.__lastClearColor.g, this.__lastClearColor.b, this.__lastClearColor.a);
|
|
8464
|
+
}
|
|
8121
8465
|
this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
|
|
8122
8466
|
}
|
|
8123
8467
|
}
|
|
@@ -8308,232 +8652,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8308
8652
|
return this; // 支持链式调用
|
|
8309
8653
|
}
|
|
8310
8654
|
|
|
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
|
-
}
|
|
8533
|
-
|
|
8534
|
-
return this;
|
|
8535
|
-
}
|
|
8536
|
-
|
|
8537
8655
|
/**
|
|
8538
8656
|
* 保存为base64图形数据
|
|
8539
8657
|
*
|
|
@@ -8600,48 +8718,27 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8600
8718
|
}
|
|
8601
8719
|
|
|
8602
8720
|
/**
|
|
8603
|
-
*
|
|
8604
|
-
*
|
|
8605
|
-
*
|
|
8721
|
+
* 遍历所有形状,生成SVG标记
|
|
8722
|
+
*
|
|
8606
8723
|
* @method toSVG
|
|
8607
8724
|
* @return {string} SVG字符串
|
|
8608
8725
|
*/
|
|
8609
8726
|
toSVG() {
|
|
8610
8727
|
// SVG头部,包含命名空间和画布尺寸
|
|
8611
8728
|
let svg = `<svg width="${this.width}" height="${this.height}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.width} ${this.height}">`;
|
|
8612
|
-
|
|
8729
|
+
|
|
8613
8730
|
// 添加背景色(如果有)
|
|
8614
8731
|
if(this.style && this.style.fill) {
|
|
8615
8732
|
svg += `<rect width="100%" height="100%" fill="${this.style.fill}"/>`;
|
|
8616
8733
|
}
|
|
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
|
-
|
|
8734
|
+
|
|
8735
|
+
// 遍历所有直接添加的形状
|
|
8736
|
+
this.children.each((i, shape) => {
|
|
8737
|
+
if(shape.toSVG) {
|
|
8738
|
+
svg += shape.toSVG();
|
|
8739
|
+
}
|
|
8740
|
+
});
|
|
8741
|
+
|
|
8645
8742
|
svg += '</svg>';
|
|
8646
8743
|
return svg;
|
|
8647
8744
|
}
|
|
@@ -8691,7 +8788,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8691
8788
|
// 触发刷新事件
|
|
8692
8789
|
self.emit('update', time);
|
|
8693
8790
|
|
|
8694
|
-
|
|
8791
|
+
// 直接 requestAnimationFrame,无需先 cancel
|
|
8695
8792
|
self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
|
|
8696
8793
|
if(callback) callback();
|
|
8697
8794
|
}
|
|
@@ -8726,22 +8823,11 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8726
8823
|
"star": jmStar
|
|
8727
8824
|
};
|
|
8728
8825
|
|
|
8729
|
-
class
|
|
8826
|
+
class jmGraphImpl extends jmGraph {
|
|
8730
8827
|
constructor(canvas, option, callback) {
|
|
8731
|
-
|
|
8732
|
-
const targetType = new.target;
|
|
8733
|
-
|
|
8734
8828
|
// 合并shapes
|
|
8735
8829
|
option = Object.assign({}, option);
|
|
8736
8830
|
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
8831
|
|
|
8746
8832
|
if(typeof option == 'function') {
|
|
8747
8833
|
callback = option;
|
|
@@ -8750,17 +8836,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
8750
8836
|
|
|
8751
8837
|
super(canvas, option, callback);
|
|
8752
8838
|
}
|
|
8753
|
-
|
|
8754
|
-
static create(...args) {
|
|
8755
|
-
return createJmGraph(...args);
|
|
8756
|
-
}
|
|
8757
8839
|
}
|
|
8758
8840
|
|
|
8759
|
-
//创建实例
|
|
8760
|
-
const createJmGraph = (...args) => {
|
|
8761
|
-
return new jmGraph(...args);
|
|
8762
|
-
};
|
|
8763
|
-
|
|
8764
8841
|
/**
|
|
8765
8842
|
* 基础样式
|
|
8766
8843
|
*
|
|
@@ -9962,13 +10039,16 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
9962
10039
|
clear() {
|
|
9963
10040
|
this._min = null;
|
|
9964
10041
|
this._max = null;
|
|
10042
|
+
this._width = null; // 清除宽度缓存
|
|
9965
10043
|
this.children.each((i, c) => {
|
|
9966
10044
|
c.remove();
|
|
9967
10045
|
}, true);
|
|
9968
10046
|
// 清空栅格线
|
|
9969
|
-
this.gridLines && this.gridLines.
|
|
9970
|
-
|
|
9971
|
-
|
|
10047
|
+
if (this.gridLines && this.gridLines.length) {
|
|
10048
|
+
for (let i = 0; i < this.gridLines.length; i++) {
|
|
10049
|
+
this.gridLines[i].remove();
|
|
10050
|
+
}
|
|
10051
|
+
}
|
|
9972
10052
|
this.labels && this.labels.forEach(label => {
|
|
9973
10053
|
label.remove();
|
|
9974
10054
|
});
|
|
@@ -10180,7 +10260,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10180
10260
|
}
|
|
10181
10261
|
};
|
|
10182
10262
|
|
|
10183
|
-
|
|
10263
|
+
// 公共常量提取到基类,避免每个子类重复定义
|
|
10264
|
+
const ANIMATION_DATA_THRESHOLD = 100;
|
|
10265
|
+
const DEFAULT_ANIMATION_COUNT = 10;
|
|
10184
10266
|
|
|
10185
10267
|
/**
|
|
10186
10268
|
* 图表系列基类
|
|
@@ -10299,14 +10381,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10299
10381
|
*/
|
|
10300
10382
|
initDataPoint(...args) {
|
|
10301
10383
|
let dataChanged = false;
|
|
10302
|
-
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10384
|
+
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD) {
|
|
10385
|
+
// 仅在数据引用变化时才做深度比较
|
|
10386
|
+
if (this._lastData !== this.data) {
|
|
10387
|
+
this.lastPoints = this.graph.utils.clone(this.dataPoints, null, true, obj => {
|
|
10388
|
+
if (obj instanceof jmControl) return obj;
|
|
10389
|
+
});
|
|
10390
|
+
this.dataPoints = this.createPoints(...args);
|
|
10391
|
+
dataChanged = utils.arrayIsChange(this.lastPoints, this.dataPoints, (s, t) => {
|
|
10392
|
+
return s.x === t.x && s.y === t.y;
|
|
10393
|
+
});
|
|
10394
|
+
this._lastData = this.data;
|
|
10395
|
+
} else {
|
|
10396
|
+
this.dataPoints = this.createPoints(...args);
|
|
10397
|
+
}
|
|
10310
10398
|
if (dataChanged) {
|
|
10311
10399
|
this.___animateCounter = 0;
|
|
10312
10400
|
}
|
|
@@ -10439,7 +10527,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10439
10527
|
xValue: xv,
|
|
10440
10528
|
xLabel: xv,
|
|
10441
10529
|
points: [],
|
|
10442
|
-
style: this.
|
|
10530
|
+
style: this.style // 共享引用,避免深拷贝;子类如需修改应自行创建副本
|
|
10443
10531
|
};
|
|
10444
10532
|
p.x = xstep * i + this.xAxis.labelStart;
|
|
10445
10533
|
for (let j = 0; j < fields.length; j++) {
|
|
@@ -10605,9 +10693,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10605
10693
|
}
|
|
10606
10694
|
}
|
|
10607
10695
|
|
|
10608
|
-
const ANIMATION_DATA_THRESHOLD$6 = 100;
|
|
10609
|
-
const DEFAULT_ANIMATION_COUNT$6 = 10;
|
|
10610
|
-
|
|
10611
10696
|
/**
|
|
10612
10697
|
* 柱图
|
|
10613
10698
|
*
|
|
@@ -10637,16 +10722,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10637
10722
|
const len = points.length;
|
|
10638
10723
|
if (!len) return;
|
|
10639
10724
|
this.initWidth(len);
|
|
10640
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
10725
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
10641
10726
|
let aniIsEnd = true;
|
|
10642
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
10727
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
10643
10728
|
for (let i = 0; i < len; i++) {
|
|
10644
10729
|
const point = points[i];
|
|
10645
10730
|
if (typeof point.y === 'undefined' || point.y === null) {
|
|
10646
10731
|
continue;
|
|
10647
10732
|
}
|
|
10648
|
-
|
|
10649
|
-
|
|
10733
|
+
const style = Object.assign({}, point.style, {
|
|
10734
|
+
fill: this.getColor(point)
|
|
10735
|
+
});
|
|
10736
|
+
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10650
10737
|
const p1 = {
|
|
10651
10738
|
x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex,
|
|
10652
10739
|
y: this.baseY
|
|
@@ -10781,16 +10868,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10781
10868
|
let topStartY = this.baseY;
|
|
10782
10869
|
let bottomStartY = this.baseY;
|
|
10783
10870
|
for (let index = 0; index < point.points.length; index++) {
|
|
10784
|
-
const style = this.graph.utils.clone(this.style);
|
|
10785
10871
|
const p = point.points[index];
|
|
10786
|
-
|
|
10787
|
-
|
|
10872
|
+
let fillColor;
|
|
10873
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
10874
|
+
fillColor = this.style.color.call(this, {
|
|
10788
10875
|
index,
|
|
10789
10876
|
point: p
|
|
10790
10877
|
});
|
|
10791
10878
|
} else {
|
|
10792
|
-
|
|
10879
|
+
fillColor = this.graph.getColor(index);
|
|
10793
10880
|
}
|
|
10881
|
+
// 使用浅拷贝而非深拷贝
|
|
10882
|
+
const style = Object.assign({}, this.style, {
|
|
10883
|
+
fill: fillColor
|
|
10884
|
+
});
|
|
10794
10885
|
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10795
10886
|
let startY = topStartY;
|
|
10796
10887
|
if (p.yValue < this.baseYValue) startY = bottomStartY;
|
|
@@ -10899,7 +10990,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10899
10990
|
this.totalValue = 0;
|
|
10900
10991
|
//计算最大值和最小值
|
|
10901
10992
|
if (this.data) {
|
|
10902
|
-
for (
|
|
10993
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
10903
10994
|
const s = this.data[i];
|
|
10904
10995
|
const vy = s[this.field];
|
|
10905
10996
|
if (vy) {
|
|
@@ -10996,15 +11087,20 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
10996
11087
|
yLabel: yv,
|
|
10997
11088
|
step: Math.abs(yv / this.totalValue),
|
|
10998
11089
|
// 每个数值点比
|
|
10999
|
-
style: this.
|
|
11090
|
+
style: this.style,
|
|
11091
|
+
// 共享引用,仅在需要修改时才拷贝
|
|
11000
11092
|
anticlockwise
|
|
11001
11093
|
};
|
|
11002
11094
|
points.push(p);
|
|
11003
11095
|
//p.style.color = this.graph.getColor(index);
|
|
11004
11096
|
if (p.style.color && typeof p.style.color === 'function') {
|
|
11097
|
+
p.style = this.graph.utils.clone(this.style);
|
|
11005
11098
|
p.style.fill = p.style.color.call(this, p);
|
|
11006
11099
|
} else {
|
|
11007
|
-
|
|
11100
|
+
// fill 需要独立,创建轻量样式覆盖
|
|
11101
|
+
p.style = Object.assign({}, this.style, {
|
|
11102
|
+
fill: this.graph.getColor(index)
|
|
11103
|
+
});
|
|
11008
11104
|
}
|
|
11009
11105
|
const start = startAni; // 上一个扇形的结束角度为当前的起始角度
|
|
11010
11106
|
// 计算当前结束角度, 同时也是下一个的起始角度
|
|
@@ -11210,11 +11306,12 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11210
11306
|
const rotateStep = Math.PI * 2 / yCount;
|
|
11211
11307
|
|
|
11212
11308
|
// 清空除了一个默认外的所有Y轴
|
|
11213
|
-
|
|
11214
|
-
|
|
11309
|
+
const yAxisKeys = Object.keys(this.graph.yAxises || {});
|
|
11310
|
+
for (let k = 0; k < yAxisKeys.length; k++) {
|
|
11311
|
+
const axis = this.graph.yAxises[yAxisKeys[k]];
|
|
11215
11312
|
if (!axis || axis === this.yAxis) continue;
|
|
11216
11313
|
axis.remove();
|
|
11217
|
-
delete this.graph.yAxises[
|
|
11314
|
+
delete this.graph.yAxises[yAxisKeys[k]];
|
|
11218
11315
|
}
|
|
11219
11316
|
for (let index = 0; index < yCount; index++) {
|
|
11220
11317
|
if (!this.field[index]) continue;
|
|
@@ -11361,21 +11458,30 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11361
11458
|
const points = [];
|
|
11362
11459
|
for (var i = 0; i < this.data.length; i++) {
|
|
11363
11460
|
const s = this.data[i];
|
|
11364
|
-
|
|
11365
|
-
if (style.color && typeof style.color === 'function') {
|
|
11366
|
-
|
|
11461
|
+
let strokeColor;
|
|
11462
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
11463
|
+
strokeColor = this.style.color.call(this, {
|
|
11367
11464
|
data: s,
|
|
11368
11465
|
index: i
|
|
11369
11466
|
});
|
|
11370
11467
|
} else {
|
|
11371
|
-
|
|
11468
|
+
strokeColor = this.graph.getColor(i);
|
|
11372
11469
|
}
|
|
11373
|
-
|
|
11374
|
-
|
|
11470
|
+
let fillColor;
|
|
11471
|
+
if (typeof this.style.fill === 'function') {
|
|
11472
|
+
fillColor = this.style.fill.call(this, {
|
|
11473
|
+
...this.style,
|
|
11474
|
+
stroke: strokeColor
|
|
11475
|
+
});
|
|
11375
11476
|
} else {
|
|
11376
|
-
const color = this.graph.utils.hexToRGBA(
|
|
11377
|
-
|
|
11477
|
+
const color = this.graph.utils.hexToRGBA(strokeColor);
|
|
11478
|
+
fillColor = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
11378
11479
|
}
|
|
11480
|
+
// 使用浅拷贝而非深拷贝
|
|
11481
|
+
const style = Object.assign({}, this.style, {
|
|
11482
|
+
stroke: strokeColor,
|
|
11483
|
+
fill: fillColor
|
|
11484
|
+
});
|
|
11379
11485
|
const shapePoints = [];
|
|
11380
11486
|
for (const axis of this.axises) {
|
|
11381
11487
|
if (!axis || !axis.field) continue;
|
|
@@ -11469,9 +11575,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11469
11575
|
});
|
|
11470
11576
|
};
|
|
11471
11577
|
|
|
11472
|
-
const ANIMATION_DATA_THRESHOLD$5 = 100;
|
|
11473
|
-
const DEFAULT_ANIMATION_COUNT$5 = 10;
|
|
11474
|
-
|
|
11475
11578
|
/**
|
|
11476
11579
|
* 线图
|
|
11477
11580
|
*
|
|
@@ -11503,9 +11606,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11503
11606
|
if (!len) return;
|
|
11504
11607
|
this.style.stroke = this.style.color;
|
|
11505
11608
|
this.style.item.stroke = this.style.color;
|
|
11506
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
11609
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
11507
11610
|
let shapePoints = [];
|
|
11508
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
11611
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11509
11612
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11510
11613
|
for (let i = 0; i < len; i++) {
|
|
11511
11614
|
const p = points[i];
|
|
@@ -11888,7 +11991,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11888
11991
|
console.warn('K线图数据不完整,需要4个字段(开盘、收盘、最高、最低)');
|
|
11889
11992
|
continue;
|
|
11890
11993
|
}
|
|
11891
|
-
const sp = this.addShape(this.graph.createPath([], p.style));
|
|
11892
11994
|
const bl = {
|
|
11893
11995
|
x: p.x - w,
|
|
11894
11996
|
y: p.points[0].y
|
|
@@ -11907,14 +12009,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11907
12009
|
};
|
|
11908
12010
|
let tm = p.points[1];
|
|
11909
12011
|
let bm = p.points[0];
|
|
11910
|
-
|
|
12012
|
+
|
|
12013
|
+
// 使用浅拷贝避免污染共享引用
|
|
12014
|
+
const style = Object.assign({}, p.style);
|
|
12015
|
+
style.stroke = style.fill = style.masculineColor || 'red';
|
|
11911
12016
|
if (p.points[0].yValue > p.points[1].yValue) {
|
|
11912
|
-
|
|
12017
|
+
style.stroke = style.fill = style.negativeColor || 'green';
|
|
11913
12018
|
bl.y = br.y = p.points[1].y;
|
|
11914
12019
|
tl.y = tr.y = p.points[0].y;
|
|
11915
12020
|
tm = p.points[0];
|
|
11916
12021
|
bm = p.points[1];
|
|
11917
12022
|
}
|
|
12023
|
+
const sp = this.addShape(this.graph.createPath([], style));
|
|
11918
12024
|
sp.points.push(p.points[2], tm, tl, bl, bm, p.points[3], bm, br, tr, tm, p.points[2]);
|
|
11919
12025
|
this.emit('onPointCreated', p);
|
|
11920
12026
|
}
|
|
@@ -11939,9 +12045,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11939
12045
|
}
|
|
11940
12046
|
}
|
|
11941
12047
|
|
|
11942
|
-
const ANIMATION_DATA_THRESHOLD$4 = 100;
|
|
11943
|
-
const DEFAULT_ANIMATION_COUNT$4 = 10;
|
|
11944
|
-
|
|
11945
12048
|
/**
|
|
11946
12049
|
* 散点图
|
|
11947
12050
|
*
|
|
@@ -11973,8 +12076,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
11973
12076
|
if (!len) return;
|
|
11974
12077
|
this.style.stroke = this.style.color;
|
|
11975
12078
|
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
|
|
12079
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12080
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11978
12081
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11979
12082
|
for (let i = 0; i < len; i++) {
|
|
11980
12083
|
const p = points[i];
|
|
@@ -12047,9 +12150,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12047
12150
|
}
|
|
12048
12151
|
}
|
|
12049
12152
|
|
|
12050
|
-
const ANIMATION_DATA_THRESHOLD$3 = 100;
|
|
12051
|
-
const DEFAULT_ANIMATION_COUNT$3 = 10;
|
|
12052
|
-
|
|
12053
12153
|
/**
|
|
12054
12154
|
* 气泡图
|
|
12055
12155
|
*
|
|
@@ -12081,8 +12181,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12081
12181
|
if (!len) return;
|
|
12082
12182
|
this.style.stroke = this.style.color;
|
|
12083
12183
|
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
|
|
12184
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12185
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12086
12186
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12087
12187
|
for (let i = 0; i < len; i++) {
|
|
12088
12188
|
const p = points[i];
|
|
@@ -12161,9 +12261,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12161
12261
|
}
|
|
12162
12262
|
}
|
|
12163
12263
|
|
|
12164
|
-
const ANIMATION_DATA_THRESHOLD$2 = 100;
|
|
12165
|
-
const DEFAULT_ANIMATION_COUNT$2 = 10;
|
|
12166
|
-
|
|
12167
12264
|
/**
|
|
12168
12265
|
* 热力图
|
|
12169
12266
|
*
|
|
@@ -12206,8 +12303,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12206
12303
|
}
|
|
12207
12304
|
this.minValue = minValue;
|
|
12208
12305
|
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
|
|
12306
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12307
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12211
12308
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12212
12309
|
for (let i = 0; i < len; i++) {
|
|
12213
12310
|
const p = points[i];
|
|
@@ -12574,20 +12671,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12574
12671
|
}
|
|
12575
12672
|
}
|
|
12576
12673
|
|
|
12577
|
-
const ANIMATION_DATA_THRESHOLD$1 = 100;
|
|
12578
|
-
const DEFAULT_ANIMATION_COUNT$1 = 10;
|
|
12579
|
-
|
|
12580
12674
|
/**
|
|
12581
12675
|
* 面积图
|
|
12676
|
+
* 继承自折线图,默认启用区域填充
|
|
12582
12677
|
*
|
|
12583
12678
|
* @class jmAreaSeries
|
|
12584
12679
|
* @module jmChart
|
|
12585
|
-
* @
|
|
12586
|
-
* @param {array} mappings 图形字段映射
|
|
12587
|
-
* @param {style} style 样式
|
|
12680
|
+
* @extends jmLineSeries
|
|
12588
12681
|
*/
|
|
12589
|
-
|
|
12590
|
-
class jmAreaSeries extends jmSeries {
|
|
12682
|
+
class jmAreaSeries extends jmLineSeries {
|
|
12591
12683
|
constructor(options) {
|
|
12592
12684
|
options.style = options.style || options.graph.style.area;
|
|
12593
12685
|
super(options);
|
|
@@ -12595,193 +12687,13 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12595
12687
|
this.style.area = true;
|
|
12596
12688
|
}
|
|
12597
12689
|
|
|
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
12690
|
/**
|
|
12776
12691
|
* 生成图例
|
|
12777
|
-
*
|
|
12778
|
-
* @method createLegend
|
|
12779
|
-
* @for jmAreaSeries
|
|
12780
12692
|
*/
|
|
12781
12693
|
createLegend() {
|
|
12782
|
-
// 生成图例前的图标
|
|
12783
12694
|
var style = this.graph.utils.clone(this.style);
|
|
12784
12695
|
style.stroke = style.color;
|
|
12696
|
+
style.fill = style.color;
|
|
12785
12697
|
var shape = this.graph.createShape('path', {
|
|
12786
12698
|
style: style
|
|
12787
12699
|
});
|
|
@@ -12803,8 +12715,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12803
12715
|
y: 0
|
|
12804
12716
|
};
|
|
12805
12717
|
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
12806
|
-
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12807
|
-
|
|
12718
|
+
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12808
12719
|
shape.points = this.__bezier.initPoints();
|
|
12809
12720
|
} else {
|
|
12810
12721
|
shape.points = [{
|
|
@@ -12819,8 +12730,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
12819
12730
|
}
|
|
12820
12731
|
}
|
|
12821
12732
|
|
|
12822
|
-
const ANIMATION_DATA_THRESHOLD = 100;
|
|
12823
|
-
const DEFAULT_ANIMATION_COUNT = 10;
|
|
12824
12733
|
class jmWaterfallSeries extends jmSeries {
|
|
12825
12734
|
constructor(options) {
|
|
12826
12735
|
options.style = options.style || options.graph.style.waterfall;
|
|
@@ -14253,12 +14162,11 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14253
14162
|
if (chart.style.markLine.longtap) {
|
|
14254
14163
|
longtap = 1;
|
|
14255
14164
|
longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
|
|
14256
|
-
|
|
14165
|
+
const tapStartTime = Date.now();
|
|
14257
14166
|
const reqFun = () => {
|
|
14258
|
-
const elapsed = Date.now() - tapStartTime;
|
|
14259
14167
|
if (longtap === 1 || longtap === 2) {
|
|
14260
14168
|
// 如果还未过一定时间,则继续等待
|
|
14261
|
-
if (
|
|
14169
|
+
if (Date.now() - tapStartTime < 500) {
|
|
14262
14170
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14263
14171
|
return;
|
|
14264
14172
|
}
|
|
@@ -14269,9 +14177,6 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14269
14177
|
};
|
|
14270
14178
|
// 如果一定时间后还没有取消,则表示长按了
|
|
14271
14179
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14272
|
-
|
|
14273
|
-
//args.event.stopPropagation();
|
|
14274
|
-
//args.event.preventDefault();// 阻止默认行为
|
|
14275
14180
|
} else {
|
|
14276
14181
|
this.startMove(args);
|
|
14277
14182
|
}
|
|
@@ -14378,7 +14283,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14378
14283
|
* @module jmChart
|
|
14379
14284
|
* @param {element} container 图表容器
|
|
14380
14285
|
*/
|
|
14381
|
-
class jmChart extends
|
|
14286
|
+
class jmChart extends jmGraphImpl {
|
|
14382
14287
|
constructor(container, options) {
|
|
14383
14288
|
options = options || {};
|
|
14384
14289
|
const enableAnimate = !!options.enableAnimate;
|
|
@@ -14472,25 +14377,27 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14472
14377
|
|
|
14473
14378
|
// 绑定点击事件
|
|
14474
14379
|
this.on('click', args => {
|
|
14475
|
-
if (this.option.onClick)
|
|
14476
|
-
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14380
|
+
if (!this.option.onClick) return;
|
|
14381
|
+
// 找到点击位置的数据点
|
|
14382
|
+
let closestPoint = null;
|
|
14383
|
+
let minDistance = 20; // 20px 范围,同时作为阈值,无需再比较小于阈值
|
|
14384
|
+
|
|
14385
|
+
this.series.each((i, serie) => {
|
|
14386
|
+
if (!serie.dataPoints) return;
|
|
14387
|
+
const points = serie.dataPoints;
|
|
14388
|
+
for (let j = 0, len = points.length; j < len; j++) {
|
|
14389
|
+
const point = points[j];
|
|
14390
|
+
const dx = args.position.x - point.x;
|
|
14391
|
+
const dy = args.position.y - point.y;
|
|
14392
|
+
const distance = dx * dx + dy * dy; // 避免开方,直接比较平方
|
|
14393
|
+
if (distance < minDistance * minDistance) {
|
|
14394
|
+
minDistance = distance;
|
|
14395
|
+
closestPoint = point;
|
|
14489
14396
|
}
|
|
14490
|
-
});
|
|
14491
|
-
if (closestPoint) {
|
|
14492
|
-
this.option.onClick(closestPoint);
|
|
14493
14397
|
}
|
|
14398
|
+
});
|
|
14399
|
+
if (closestPoint) {
|
|
14400
|
+
this.option.onClick(closestPoint);
|
|
14494
14401
|
}
|
|
14495
14402
|
});
|
|
14496
14403
|
}
|
|
@@ -14520,7 +14427,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14520
14427
|
options = this.utils.clone(options, {
|
|
14521
14428
|
autoRefresh: true
|
|
14522
14429
|
}, true);
|
|
14523
|
-
this.touchGraph = new
|
|
14430
|
+
this.touchGraph = new jmGraphImpl(cn, options);
|
|
14524
14431
|
this.touchGraph.chartGraph = this;
|
|
14525
14432
|
this.on('propertyChange', (name, args) => {
|
|
14526
14433
|
if (['width', 'height'].includes(name)) {
|
|
@@ -14560,8 +14467,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14560
14467
|
delete this.xAxis;
|
|
14561
14468
|
}
|
|
14562
14469
|
if (this.yAxises) {
|
|
14563
|
-
|
|
14564
|
-
|
|
14470
|
+
const keys = Object.keys(this.yAxises);
|
|
14471
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14472
|
+
this.yAxises[keys[k]].remove();
|
|
14565
14473
|
}
|
|
14566
14474
|
delete this.yAxises;
|
|
14567
14475
|
}
|
|
@@ -14573,18 +14481,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14573
14481
|
* @param {int} index 颜色索引
|
|
14574
14482
|
*/
|
|
14575
14483
|
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;
|
|
14484
|
+
const colors = this.style.chartColors;
|
|
14485
|
+
const colorIndex = index % colors.length;
|
|
14486
|
+
return colors[colorIndex];
|
|
14588
14487
|
}
|
|
14589
14488
|
|
|
14590
14489
|
/**
|
|
@@ -14602,40 +14501,43 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14602
14501
|
this.xAxis.clear();
|
|
14603
14502
|
}
|
|
14604
14503
|
if (this.yAxises) {
|
|
14605
|
-
|
|
14606
|
-
|
|
14504
|
+
const keys = Object.keys(this.yAxises);
|
|
14505
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14506
|
+
this.yAxises[keys[k]].clear();
|
|
14607
14507
|
}
|
|
14608
14508
|
}
|
|
14609
14509
|
this.barSeriesCount = 0;
|
|
14510
|
+
// 合并两次 series 遍历为一次,减少遍历开销
|
|
14511
|
+
const seriesInited = [];
|
|
14610
14512
|
this.series.each((i, serie) => {
|
|
14611
14513
|
if (!serie.style.color) {
|
|
14612
14514
|
serie.style.color = serie.graph.getColor(i);
|
|
14613
14515
|
}
|
|
14614
|
-
if (serie
|
|
14615
|
-
if (serie
|
|
14516
|
+
if (serie instanceof jmBarSeries) {
|
|
14517
|
+
if (serie.graph.style.layout != 'inside') {
|
|
14616
14518
|
serie.graph.style.layout = 'inside';
|
|
14617
14519
|
}
|
|
14618
|
-
}
|
|
14619
|
-
if (serie instanceof jmBarSeries) {
|
|
14620
14520
|
serie.barIndex = serie.graph.barSeriesCount;
|
|
14621
14521
|
serie.graph.barSeriesCount++;
|
|
14622
14522
|
}
|
|
14623
14523
|
serie.reset();
|
|
14524
|
+
seriesInited.push(serie);
|
|
14624
14525
|
});
|
|
14625
14526
|
if (this.legend) {
|
|
14626
14527
|
this.legend.reset();
|
|
14627
14528
|
}
|
|
14628
14529
|
if (this.yAxises) {
|
|
14629
|
-
|
|
14630
|
-
|
|
14530
|
+
const keys = Object.keys(this.yAxises);
|
|
14531
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14532
|
+
this.yAxises[keys[k]].reset();
|
|
14631
14533
|
}
|
|
14632
14534
|
}
|
|
14633
14535
|
if (this.xAxis) {
|
|
14634
14536
|
this.xAxis.reset();
|
|
14635
14537
|
}
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
}
|
|
14538
|
+
for (let i = 0; i < seriesInited.length; i++) {
|
|
14539
|
+
seriesInited[i].init && seriesInited[i].init();
|
|
14540
|
+
}
|
|
14639
14541
|
}
|
|
14640
14542
|
|
|
14641
14543
|
/**
|
|
@@ -14813,14 +14715,35 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
14813
14715
|
this.initChart();
|
|
14814
14716
|
},
|
|
14815
14717
|
updated() {
|
|
14816
|
-
this.
|
|
14718
|
+
this.refresh();
|
|
14817
14719
|
},
|
|
14818
14720
|
destroyed() {
|
|
14819
14721
|
this.chartInstance && this.chartInstance.destroy();
|
|
14820
14722
|
},
|
|
14821
14723
|
watch: {
|
|
14822
|
-
chartData:
|
|
14823
|
-
|
|
14724
|
+
chartData: {
|
|
14725
|
+
handler: function (newData, oldData) {
|
|
14726
|
+
this.refresh();
|
|
14727
|
+
},
|
|
14728
|
+
deep: false // 仅监听引用变化,由使用者显式替换数组时触发
|
|
14729
|
+
},
|
|
14730
|
+
chartOptions: {
|
|
14731
|
+
handler: function (newOptions, oldOptions) {
|
|
14732
|
+
// 配置变化时需要重建图表
|
|
14733
|
+
if (this.chartInstance) {
|
|
14734
|
+
this.chartInstance.destroy();
|
|
14735
|
+
this.chartInstance = null;
|
|
14736
|
+
}
|
|
14737
|
+
this.option = Object.assign({
|
|
14738
|
+
enableAnimate: false,
|
|
14739
|
+
legendPosition: 'top',
|
|
14740
|
+
legendVisible: true,
|
|
14741
|
+
width: this.width,
|
|
14742
|
+
height: this.height
|
|
14743
|
+
}, newOptions);
|
|
14744
|
+
this.$nextTick(() => this.initChart());
|
|
14745
|
+
},
|
|
14746
|
+
deep: false
|
|
14824
14747
|
},
|
|
14825
14748
|
width: function (newWidth, oldWidth) {
|
|
14826
14749
|
if (!this.chartInstance) return;
|