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.cjs.js
CHANGED
|
@@ -281,66 +281,75 @@ class jmUtils {
|
|
|
281
281
|
* @param {function} copyHandler 复制对象回调,如果返回undefined,就走后面的逻辑,否则到这里中止
|
|
282
282
|
* @return {object} 参数source的拷贝对象
|
|
283
283
|
*/
|
|
284
|
-
static clone(source, target, deep = false, copyHandler = null, deepIndex = 0) {
|
|
284
|
+
static clone(source, target, deep = false, copyHandler = null, deepIndex = 0, cloned = null) {
|
|
285
285
|
// 如果有指定回调,则用回调处理,否则走后面的复制逻辑
|
|
286
286
|
if(typeof copyHandler === 'function') {
|
|
287
287
|
const obj = copyHandler(source, deep, deepIndex);
|
|
288
288
|
if(obj) return obj;
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
|
|
291
|
+
// 首次调用时初始化克隆映射表(用于处理循环引用)
|
|
292
|
+
if(!cloned) cloned = new WeakMap();
|
|
291
293
|
|
|
292
294
|
if(typeof target === 'boolean') {
|
|
293
295
|
deep = target;
|
|
294
296
|
target = undefined;
|
|
295
297
|
}
|
|
296
298
|
|
|
297
|
-
//
|
|
298
|
-
if(
|
|
299
|
-
return target;
|
|
299
|
+
// 非对象直接返回
|
|
300
|
+
if(!source || typeof source !== 'object') {
|
|
301
|
+
return typeof target !== 'undefined' ? target : source;
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
+
// 如果source已经被克隆过,直接返回之前的克隆对象,打破循环引用
|
|
305
|
+
if(cloned.has(source)) return cloned.get(source);
|
|
304
306
|
|
|
307
|
+
// 数组处理
|
|
308
|
+
if(Array.isArray(source)) {
|
|
305
309
|
//如果为当前泛型,则直接new
|
|
306
310
|
if(this.isType(source, jmList)) {
|
|
307
311
|
return new jmList(source);
|
|
308
312
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
dest.push(this.clone(source[i], target[i], deep, copyHandler, deepIndex));
|
|
315
|
-
}
|
|
316
|
-
return dest;
|
|
317
|
-
}
|
|
318
|
-
return source.slice(0);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if(source.__proto__) target.__proto__ = source.__proto__;
|
|
322
|
-
|
|
323
|
-
for(let k in source) {
|
|
324
|
-
if(k === 'constructor') continue;
|
|
325
|
-
const v = source[k];
|
|
326
|
-
// 不复制页面元素和class对象
|
|
327
|
-
if(v && (v.tagName || v.getContext)) {
|
|
328
|
-
target[k] = v;
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// 如果不是对象和空,则采用target的属性
|
|
333
|
-
if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
|
|
334
|
-
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex);
|
|
313
|
+
if(deep) {
|
|
314
|
+
let dest = [];
|
|
315
|
+
cloned.set(source, dest);
|
|
316
|
+
for(let i = 0; i < source.length; i++) {
|
|
317
|
+
dest.push(this.clone(source[i], undefined, deep, copyHandler, deepIndex + 1, cloned));
|
|
335
318
|
}
|
|
319
|
+
return dest;
|
|
336
320
|
}
|
|
337
|
-
return
|
|
321
|
+
return source.slice(0);
|
|
338
322
|
}
|
|
339
|
-
|
|
340
|
-
|
|
323
|
+
|
|
324
|
+
// 不复制页面元素和class对象(如jmControl实例等复杂对象保持引用)
|
|
325
|
+
if(source.tagName || source.getContext || source.emit) {
|
|
326
|
+
return source;
|
|
341
327
|
}
|
|
342
328
|
|
|
343
|
-
|
|
329
|
+
// 普通对象处理
|
|
330
|
+
target = target || {};
|
|
331
|
+
cloned.set(source, target);
|
|
332
|
+
|
|
333
|
+
// 保持原型链一致
|
|
334
|
+
if(source.__proto__) target.__proto__ = source.__proto__;
|
|
335
|
+
|
|
336
|
+
// 遍历自身可枚举属性(字符串键 + Symbol键),避免触发原型链上宿主对象的getter
|
|
337
|
+
const keys = Object.keys(source).concat(Object.getOwnPropertySymbols(source));
|
|
338
|
+
for(const k of keys) {
|
|
339
|
+
if(k === 'constructor') continue;
|
|
340
|
+
const v = source[k];
|
|
341
|
+
// 不复制页面元素和class对象
|
|
342
|
+
if(v && (v.tagName || v.getContext || v.emit)) {
|
|
343
|
+
target[k] = v;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 如果不是对象和空,则采用target的属性
|
|
348
|
+
if(typeof target[k] === 'object' || typeof target[k] === 'undefined') {
|
|
349
|
+
target[k] = this.clone(v, target[k], deep, copyHandler, deepIndex + 1, cloned);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return target;
|
|
344
353
|
}
|
|
345
354
|
|
|
346
355
|
/**
|
|
@@ -1308,6 +1317,153 @@ class jmShadow {
|
|
|
1308
1317
|
}
|
|
1309
1318
|
}
|
|
1310
1319
|
|
|
1320
|
+
/**
|
|
1321
|
+
* CSS滤镜效果类
|
|
1322
|
+
* 支持的滤镜: blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity
|
|
1323
|
+
*
|
|
1324
|
+
* @class jmFilter
|
|
1325
|
+
* @param {string|object} opt 滤镜参数
|
|
1326
|
+
* 字符串格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1327
|
+
* 对象格式: { blur: 2, grayscale: 0.5, brightness: 1.2 }
|
|
1328
|
+
*/
|
|
1329
|
+
class jmFilter {
|
|
1330
|
+
constructor(opt) {
|
|
1331
|
+
this.filters = [];
|
|
1332
|
+
|
|
1333
|
+
if(typeof opt === 'string') {
|
|
1334
|
+
this.fromString(opt);
|
|
1335
|
+
}
|
|
1336
|
+
else if(opt && typeof opt === 'object') {
|
|
1337
|
+
for(let k in opt) {
|
|
1338
|
+
if(k === 'constructor' || k === 'filters') continue;
|
|
1339
|
+
this.addFilter(k, opt[k]);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* 添加单个滤镜
|
|
1346
|
+
* @param {string} name 滤镜名称 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
1347
|
+
* @param {number|string} value 滤镜值
|
|
1348
|
+
*/
|
|
1349
|
+
addFilter(name, value) {
|
|
1350
|
+
name = name.toLowerCase().trim();
|
|
1351
|
+
if(typeof value === 'string') {
|
|
1352
|
+
value = parseFloat(value);
|
|
1353
|
+
}
|
|
1354
|
+
if(isNaN(value)) return;
|
|
1355
|
+
|
|
1356
|
+
// 规范化滤镜名称
|
|
1357
|
+
const normalized = {
|
|
1358
|
+
'blur': 'blur',
|
|
1359
|
+
'grayscale': 'grayscale',
|
|
1360
|
+
'greyscale': 'grayscale',
|
|
1361
|
+
'sepia': 'sepia',
|
|
1362
|
+
'brightness': 'brightness',
|
|
1363
|
+
'contrast': 'contrast',
|
|
1364
|
+
'saturate': 'saturate',
|
|
1365
|
+
'hue-rotate': 'hueRotate',
|
|
1366
|
+
'hueRotate': 'hueRotate',
|
|
1367
|
+
'invert': 'invert',
|
|
1368
|
+
'opacity': 'opacity'
|
|
1369
|
+
}[name];
|
|
1370
|
+
|
|
1371
|
+
if(!normalized) return;
|
|
1372
|
+
|
|
1373
|
+
// 检查是否已有同名滤镜,有则更新
|
|
1374
|
+
const existing = this.filters.find(f => f.name === normalized);
|
|
1375
|
+
if(existing) {
|
|
1376
|
+
existing.value = value;
|
|
1377
|
+
}
|
|
1378
|
+
else {
|
|
1379
|
+
this.filters.push({ name: normalized, value: value });
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* 从字符串格式解析滤镜
|
|
1385
|
+
* 格式: "blur(2px) grayscale(50%) brightness(1.2)"
|
|
1386
|
+
* @param {string} s 滤镜字符串
|
|
1387
|
+
*/
|
|
1388
|
+
fromString(s) {
|
|
1389
|
+
if(!s || typeof s !== 'string') return;
|
|
1390
|
+
// 匹配 filterName(value) 模式
|
|
1391
|
+
const regex = /([a-zA-Z-]+)\s*\(\s*([^)]+)\s*\)/g;
|
|
1392
|
+
let match;
|
|
1393
|
+
while((match = regex.exec(s)) !== null) {
|
|
1394
|
+
const name = match[1];
|
|
1395
|
+
const valueStr = match[2].replace(/[a-z%]+$/i, '').trim();
|
|
1396
|
+
const value = parseFloat(valueStr);
|
|
1397
|
+
if(!isNaN(value)) {
|
|
1398
|
+
this.addFilter(name, value);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
/**
|
|
1404
|
+
* 转换为CSS filter字符串格式
|
|
1405
|
+
* @returns {string}
|
|
1406
|
+
*/
|
|
1407
|
+
toString() {
|
|
1408
|
+
return this.filters.map(f => {
|
|
1409
|
+
switch(f.name) {
|
|
1410
|
+
case 'blur':
|
|
1411
|
+
return `blur(${f.value}px)`;
|
|
1412
|
+
case 'hueRotate':
|
|
1413
|
+
return `hue-rotate(${f.value}deg)`;
|
|
1414
|
+
default:
|
|
1415
|
+
return `${f.name}(${f.value})`;
|
|
1416
|
+
}
|
|
1417
|
+
}).join(' ');
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* 转换为Canvas context.filter可用的字符串
|
|
1422
|
+
* @returns {string}
|
|
1423
|
+
*/
|
|
1424
|
+
toCanvasFilter() {
|
|
1425
|
+
if(this.filters.length === 0) return 'none';
|
|
1426
|
+
return this.toString();
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* 检查是否有指定名称的滤镜
|
|
1431
|
+
* @param {string} name 滤镜名称
|
|
1432
|
+
* @returns {boolean}
|
|
1433
|
+
*/
|
|
1434
|
+
has(name) {
|
|
1435
|
+
return this.filters.some(f => f.name === name);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* 获取指定滤镜的值
|
|
1440
|
+
* @param {string} name 滤镜名称
|
|
1441
|
+
* @returns {number|undefined}
|
|
1442
|
+
*/
|
|
1443
|
+
get(name) {
|
|
1444
|
+
const f = this.filters.find(f => f.name === name);
|
|
1445
|
+
return f ? f.value : undefined;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* 移除指定滤镜
|
|
1450
|
+
* @param {string} name 滤镜名称
|
|
1451
|
+
*/
|
|
1452
|
+
remove(name) {
|
|
1453
|
+
const index = this.filters.findIndex(f => f.name === name);
|
|
1454
|
+
if(index > -1) {
|
|
1455
|
+
this.filters.splice(index, 1);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* 清空所有滤镜
|
|
1461
|
+
*/
|
|
1462
|
+
clear() {
|
|
1463
|
+
this.filters = [];
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1311
1467
|
let control_id_counter = 0;
|
|
1312
1468
|
|
|
1313
1469
|
class jmObject {
|
|
@@ -2183,8 +2339,14 @@ class WebglGradient {
|
|
|
2183
2339
|
|
|
2184
2340
|
// 转为渐变为纹理
|
|
2185
2341
|
toImageData(control, bounds, points=null) {
|
|
2186
|
-
//
|
|
2187
|
-
|
|
2342
|
+
// 缓存基于渐变参数(不含 bounds,因为同一个渐变只是位置不同时纹理相同)
|
|
2343
|
+
const gradientKey = this.toString();
|
|
2344
|
+
if(this.__cachedData && this.__cacheKey === gradientKey &&
|
|
2345
|
+
this.__cachedData.data && this.__cachedData.data.width === Math.ceil(bounds.width) &&
|
|
2346
|
+
this.__cachedData.data.data && this.__cachedData.data.data.height === Math.ceil(bounds.height)) {
|
|
2347
|
+
return this.__cachedData;
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2188
2350
|
if(!control.textureContext) {
|
|
2189
2351
|
return null;
|
|
2190
2352
|
}
|
|
@@ -2202,11 +2364,18 @@ class WebglGradient {
|
|
|
2202
2364
|
|
|
2203
2365
|
const data = control.toFillTexture(gradient, bounds, points);
|
|
2204
2366
|
|
|
2205
|
-
|
|
2367
|
+
this.__cachedData = data;
|
|
2368
|
+
this.__cacheKey = gradientKey;
|
|
2206
2369
|
|
|
2207
2370
|
return data;
|
|
2208
2371
|
}
|
|
2209
2372
|
|
|
2373
|
+
// 当渐变参数变化时使缓存失效
|
|
2374
|
+
invalidateCache() {
|
|
2375
|
+
this.__cachedData = null;
|
|
2376
|
+
this.__cacheKey = null;
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2210
2379
|
// 根据绘制图形的坐标计算出对应点的颜色
|
|
2211
2380
|
/*
|
|
2212
2381
|
toPointColors(points) {
|
|
@@ -2827,7 +2996,6 @@ class WeblBase {
|
|
|
2827
2996
|
|
|
2828
2997
|
// 创建程序
|
|
2829
2998
|
createProgram(vertexSrc, fragmentSrc) {
|
|
2830
|
-
this.context.lineWidth(1);
|
|
2831
2999
|
return createProgram(this.context, vertexSrc, fragmentSrc);
|
|
2832
3000
|
}
|
|
2833
3001
|
|
|
@@ -2940,7 +3108,9 @@ class WeblBase {
|
|
|
2940
3108
|
// polygonIndices 顶点索引,
|
|
2941
3109
|
earCutPointsToTriangles(points) {
|
|
2942
3110
|
this.earCutCache = this.earCutCache || (this.earCutCache = {});
|
|
2943
|
-
|
|
3111
|
+
// 快速缓存 key:用长度和首尾点坐标
|
|
3112
|
+
const len = points.length;
|
|
3113
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
2944
3114
|
if (this.earCutCache[key]) return this.earCutCache[key];
|
|
2945
3115
|
|
|
2946
3116
|
const ps = this.earCutPoints(points);// 切割得到3角色顶点索引,
|
|
@@ -3035,31 +3205,11 @@ class WeblBase {
|
|
|
3035
3205
|
|
|
3036
3206
|
this.textureContext.fillStyle = fillStyle;
|
|
3037
3207
|
|
|
3038
|
-
|
|
3208
|
+
// 规则图形用 fillRect,比 beginPath/lineTo/fill 快
|
|
3039
3209
|
if(!points || !points.length) {
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
y: bounds.top
|
|
3044
|
-
});
|
|
3045
|
-
points.push({
|
|
3046
|
-
x: bounds.left + bounds.width,
|
|
3047
|
-
y: bounds.top
|
|
3048
|
-
});
|
|
3049
|
-
points.push({
|
|
3050
|
-
x: bounds.left + bounds.width,
|
|
3051
|
-
y: bounds.top + bounds.height
|
|
3052
|
-
});
|
|
3053
|
-
points.push({
|
|
3054
|
-
x: bounds.left,
|
|
3055
|
-
y: bounds.top + bounds.height
|
|
3056
|
-
});
|
|
3057
|
-
points.push({
|
|
3058
|
-
x: bounds.left,
|
|
3059
|
-
y: bounds.top
|
|
3060
|
-
});
|
|
3061
|
-
}
|
|
3062
|
-
if(points && points.length) {
|
|
3210
|
+
this.textureContext.fillRect(0, 0, bounds.width, bounds.height);
|
|
3211
|
+
} else {
|
|
3212
|
+
this.textureContext.beginPath();
|
|
3063
3213
|
for(const p of points) {
|
|
3064
3214
|
//移至当前坐标
|
|
3065
3215
|
if(p.m) {
|
|
@@ -3068,17 +3218,10 @@ class WeblBase {
|
|
|
3068
3218
|
else {
|
|
3069
3219
|
this.textureContext.lineTo(p.x - bounds.left, p.y - bounds.top);
|
|
3070
3220
|
}
|
|
3071
|
-
}
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
this.textureContext.moveTo(0, 0);
|
|
3075
|
-
this.textureContext.lineTo(bounds.width, 0);
|
|
3076
|
-
this.textureContext.lineTo(bounds.width, bounds.height);
|
|
3077
|
-
this.textureContext.lineTo(0, bounds.height);
|
|
3078
|
-
this.textureContext.lineTo(0, 0);
|
|
3221
|
+
}
|
|
3222
|
+
this.textureContext.closePath();
|
|
3223
|
+
this.textureContext.fill();
|
|
3079
3224
|
}
|
|
3080
|
-
this.textureContext.closePath();
|
|
3081
|
-
this.textureContext.fill();
|
|
3082
3225
|
|
|
3083
3226
|
const data = this.textureContext.getImageData(0, 0, canvas.width, canvas.height);
|
|
3084
3227
|
return {
|
|
@@ -3097,6 +3240,40 @@ class WebglPath extends WeblBase {
|
|
|
3097
3240
|
this.needCut = option.needCut || false;
|
|
3098
3241
|
this.control = option.control;
|
|
3099
3242
|
this.points = [];
|
|
3243
|
+
// 缓存 buffer 和纹理,避免每帧创建/销毁
|
|
3244
|
+
this.__cachedBuffers = [];
|
|
3245
|
+
this.__cachedTexture = null;
|
|
3246
|
+
this.__cachedTextureKey = null;
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
// 释放缓存的 WebGL 资源
|
|
3250
|
+
dispose() {
|
|
3251
|
+
for(const buf of this.__cachedBuffers) {
|
|
3252
|
+
this.deleteBuffer(buf);
|
|
3253
|
+
}
|
|
3254
|
+
this.__cachedBuffers = [];
|
|
3255
|
+
if(this.__cachedTexture) {
|
|
3256
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3257
|
+
this.__cachedTexture = null;
|
|
3258
|
+
this.__cachedTextureKey = null;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
// 获取或创建 buffer,优先复用缓存
|
|
3263
|
+
getOrCreateBuffer(data, attr) {
|
|
3264
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3265
|
+
if(buffer) {
|
|
3266
|
+
const gl = this.context;
|
|
3267
|
+
const float32 = new Float32Array(data);
|
|
3268
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3269
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3270
|
+
buffer.data = data;
|
|
3271
|
+
return buffer;
|
|
3272
|
+
}
|
|
3273
|
+
buffer = this.createFloat32Buffer(data);
|
|
3274
|
+
buffer.attr = attr;
|
|
3275
|
+
this.__cachedBuffers.push(buffer);
|
|
3276
|
+
return buffer;
|
|
3100
3277
|
}
|
|
3101
3278
|
|
|
3102
3279
|
// 应用变换到点
|
|
@@ -3109,8 +3286,14 @@ class WebglPath extends WeblBase {
|
|
|
3109
3286
|
//this.useProgram();
|
|
3110
3287
|
|
|
3111
3288
|
if(parentBounds) this.parentAbsoluteBounds = parentBounds;
|
|
3112
|
-
//
|
|
3113
|
-
|
|
3289
|
+
// 缓存中心点值,只在变化时才更新 uniform
|
|
3290
|
+
const cx = this.graph.width / 2;
|
|
3291
|
+
const cy = this.graph.height / 2;
|
|
3292
|
+
if(this.__lastCenterX !== cx || this.__lastCenterY !== cy) {
|
|
3293
|
+
this.context.uniform2f(this.program.uniforms.a_center_point.location, cx, cy);
|
|
3294
|
+
this.__lastCenterX = cx;
|
|
3295
|
+
this.__lastCenterY = cy;
|
|
3296
|
+
}
|
|
3114
3297
|
}
|
|
3115
3298
|
|
|
3116
3299
|
setFragColor(color) {
|
|
@@ -3151,6 +3334,7 @@ class WebglPath extends WeblBase {
|
|
|
3151
3334
|
endDraw() {
|
|
3152
3335
|
if(this.points) delete this.points;
|
|
3153
3336
|
if(this.pathPoints) delete this.pathPoints;
|
|
3337
|
+
// 缓存的纹理保留到下次绘制(渐变可能不变)
|
|
3154
3338
|
}
|
|
3155
3339
|
|
|
3156
3340
|
// 图形封闭
|
|
@@ -3162,21 +3346,47 @@ class WebglPath extends WeblBase {
|
|
|
3162
3346
|
}
|
|
3163
3347
|
}
|
|
3164
3348
|
|
|
3165
|
-
//
|
|
3349
|
+
// 绘制点数组(使用 DYNAMIC_DRAW 复用 buffer,避免每帧 create/delete)
|
|
3166
3350
|
writePoints(points, attr = this.program.attrs.a_position) {
|
|
3167
|
-
|
|
3168
3351
|
const fixedPoints = [];
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3352
|
+
const [a, b, c, d, tx, ty] = this.transformMatrix;
|
|
3353
|
+
const isIdentity = (a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0);
|
|
3354
|
+
const offsetLeft = this.parentAbsoluteBounds.left;
|
|
3355
|
+
const offsetTop = this.parentAbsoluteBounds.top;
|
|
3356
|
+
|
|
3357
|
+
if(isIdentity) {
|
|
3358
|
+
// 单位矩阵时直接加偏移,避免逐点调用 applyTransform
|
|
3359
|
+
for(let i = 0; i < points.length; i++) {
|
|
3360
|
+
fixedPoints.push(points[i].x + offsetLeft, points[i].y + offsetTop);
|
|
3361
|
+
}
|
|
3362
|
+
} else {
|
|
3363
|
+
for(const p of points) {
|
|
3364
|
+
const transformedPoint = this.applyTransform(p);
|
|
3365
|
+
fixedPoints.push(
|
|
3366
|
+
transformedPoint.x + offsetLeft,
|
|
3367
|
+
transformedPoint.y + offsetTop
|
|
3368
|
+
);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
const float32 = new Float32Array(fixedPoints);
|
|
3372
|
+
const gl = this.context;
|
|
3373
|
+
|
|
3374
|
+
// 复用已有 buffer 或创建新的
|
|
3375
|
+
if(this.__cachedBuffers.length > 0) {
|
|
3376
|
+
// 找一个同 attr 的 buffer 复用
|
|
3377
|
+
let buffer = this.__cachedBuffers.find(b => b.attr === attr);
|
|
3378
|
+
if(buffer) {
|
|
3379
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer.buffer);
|
|
3380
|
+
gl.bufferData(gl.ARRAY_BUFFER, float32, gl.DYNAMIC_DRAW);
|
|
3381
|
+
buffer.data = fixedPoints;
|
|
3382
|
+
this.writeVertexAttrib(buffer, attr, 2, 0, 0);
|
|
3383
|
+
return buffer;
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
const vertexBuffer = this.createFloat32Buffer(float32, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3178
3387
|
this.writeVertexAttrib(vertexBuffer, attr, 2, 0, 0);
|
|
3179
3388
|
vertexBuffer.attr = attr;
|
|
3389
|
+
this.__cachedBuffers.push(vertexBuffer);
|
|
3180
3390
|
return vertexBuffer;
|
|
3181
3391
|
}
|
|
3182
3392
|
|
|
@@ -3412,9 +3622,10 @@ class WebglPath extends WeblBase {
|
|
|
3412
3622
|
|
|
3413
3623
|
// 分割成一个个规则的三角形,不规则的多边形不全割的话纹理就会没法正确覆盖
|
|
3414
3624
|
getTriangles(points) {
|
|
3415
|
-
|
|
3416
3625
|
this.trianglesCache = this.trianglesCache||(this.trianglesCache={});
|
|
3417
|
-
|
|
3626
|
+
// 快速缓存 key:用长度和首尾点坐标(比 JSON.stringify 快几个数量级)
|
|
3627
|
+
const len = points.length;
|
|
3628
|
+
const key = len + '_' + points[0].x + '_' + points[0].y + '_' + points[len-1].x + '_' + points[len-1].y;
|
|
3418
3629
|
if(this.trianglesCache[key]) return this.trianglesCache[key];
|
|
3419
3630
|
|
|
3420
3631
|
const res = [];
|
|
@@ -3451,12 +3662,11 @@ class WebglPath extends WeblBase {
|
|
|
3451
3662
|
if(points && points.length) {
|
|
3452
3663
|
const regular = lineWidth <= 1.2;
|
|
3453
3664
|
points = regular? points : this.pathToPoints(points);
|
|
3454
|
-
|
|
3665
|
+
this.writePoints(points);
|
|
3455
3666
|
this.context.drawArrays(regular? this.context.LINE_LOOP: this.context.POINTS, 0, points.length);
|
|
3456
|
-
|
|
3667
|
+
// buffer 由 endDraw 统一清理
|
|
3457
3668
|
}
|
|
3458
|
-
colorBuffer && this.
|
|
3459
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3669
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3460
3670
|
}
|
|
3461
3671
|
|
|
3462
3672
|
// 填充图形
|
|
@@ -3487,8 +3697,7 @@ class WebglPath extends WeblBase {
|
|
|
3487
3697
|
|
|
3488
3698
|
this.fillPolygons(points);
|
|
3489
3699
|
|
|
3490
|
-
colorBuffer && this.
|
|
3491
|
-
colorBuffer && this.disableVertexAttribArray(colorBuffer.attr);
|
|
3700
|
+
colorBuffer && this.disableVertexAttribArray(colorBuffer && colorBuffer.attr);
|
|
3492
3701
|
|
|
3493
3702
|
}
|
|
3494
3703
|
|
|
@@ -3498,8 +3707,24 @@ class WebglPath extends WeblBase {
|
|
|
3498
3707
|
fillImage(img, points, bounds) {
|
|
3499
3708
|
if(!img) return;
|
|
3500
3709
|
|
|
3501
|
-
//
|
|
3502
|
-
|
|
3710
|
+
// 对于 ImageData,生成缓存 key(基于渐变参数或 bounds),复用纹理
|
|
3711
|
+
let texture = null;
|
|
3712
|
+
if(img instanceof ImageData) {
|
|
3713
|
+
const key = `${img.width}_${img.height}_${bounds.width}_${bounds.height}_${bounds.left}_${bounds.top}`;
|
|
3714
|
+
if(this.__cachedTexture && this.__cachedTextureKey === key) {
|
|
3715
|
+
texture = this.__cachedTexture;
|
|
3716
|
+
} else {
|
|
3717
|
+
texture = this.createDataTexture(img);
|
|
3718
|
+
// 释放旧纹理
|
|
3719
|
+
if(this.__cachedTexture) {
|
|
3720
|
+
this.deleteTexture(this.__cachedTexture);
|
|
3721
|
+
}
|
|
3722
|
+
this.__cachedTexture = texture;
|
|
3723
|
+
this.__cachedTextureKey = key;
|
|
3724
|
+
}
|
|
3725
|
+
} else {
|
|
3726
|
+
texture = this.createImgTexture(img);
|
|
3727
|
+
}
|
|
3503
3728
|
this.context.uniform1i(this.program.uniforms.u_sample.location, 0); // 纹理单元传递给着色器
|
|
3504
3729
|
|
|
3505
3730
|
// 指定纹理区域尺寸
|
|
@@ -3512,7 +3737,10 @@ class WebglPath extends WeblBase {
|
|
|
3512
3737
|
|
|
3513
3738
|
this.fillTexture(points);
|
|
3514
3739
|
|
|
3515
|
-
|
|
3740
|
+
// 仅对非缓存纹理(非 ImageData)立即删除
|
|
3741
|
+
if(!(img instanceof ImageData)) {
|
|
3742
|
+
this.deleteTexture(texture);
|
|
3743
|
+
}
|
|
3516
3744
|
}
|
|
3517
3745
|
|
|
3518
3746
|
fillTexture(points) {
|
|
@@ -3528,23 +3756,67 @@ class WebglPath extends WeblBase {
|
|
|
3528
3756
|
|
|
3529
3757
|
// 进行多边形填充
|
|
3530
3758
|
fillPolygons(points, isTexture = false) {
|
|
3531
|
-
if(points.length
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
}
|
|
3759
|
+
if(points.length <= 3) {
|
|
3760
|
+
// 3个点以下的三角形直接画
|
|
3761
|
+
this.writePoints(points);
|
|
3762
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3763
|
+
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3764
|
+
return;
|
|
3538
3765
|
}
|
|
3539
|
-
else {
|
|
3540
|
-
const buffer = this.writePoints(points);
|
|
3541
|
-
// 纹理坐标
|
|
3542
|
-
const coordBuffer = isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3543
3766
|
|
|
3767
|
+
// 规则图形(凸多边形,如圆):直接用 TRIANGLE_FAN 一次性绘制,无需 earcut
|
|
3768
|
+
if(this.isRegular) {
|
|
3769
|
+
this.writePoints(points);
|
|
3770
|
+
isTexture? this.writePoints(points, this.program.attrs.a_text_coord): null;
|
|
3544
3771
|
this.context.drawArrays(this.context.TRIANGLE_FAN, 0, points.length);
|
|
3545
|
-
|
|
3546
|
-
|
|
3772
|
+
return;
|
|
3773
|
+
}
|
|
3774
|
+
|
|
3775
|
+
// 不规则图形:需要 earcut 三角化后,合并为一个大的顶点缓冲区,单次 drawArrays
|
|
3776
|
+
const triangles = this.needCut? this.earCutPointsToTriangles(points): this.getTriangles(points);
|
|
3777
|
+
if(!triangles.length) return;
|
|
3778
|
+
|
|
3779
|
+
// 合并所有三角形的顶点到一个数组
|
|
3780
|
+
const allVertices = [];
|
|
3781
|
+
const allTexCoords = [];
|
|
3782
|
+
for(const triangle of triangles) {
|
|
3783
|
+
for(const p of triangle) {
|
|
3784
|
+
allVertices.push(p.x, p.y);
|
|
3785
|
+
if(isTexture) allTexCoords.push(p.x, p.y);
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
// 一次性上传所有数据并绘制
|
|
3790
|
+
const vertexData = new Float32Array(allVertices);
|
|
3791
|
+
const gl = this.context;
|
|
3792
|
+
|
|
3793
|
+
// 复用或创建 position buffer
|
|
3794
|
+
let posBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_position);
|
|
3795
|
+
if(!posBuffer) {
|
|
3796
|
+
posBuffer = this.createFloat32Buffer(vertexData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3797
|
+
posBuffer.attr = this.program.attrs.a_position;
|
|
3798
|
+
this.__cachedBuffers.push(posBuffer);
|
|
3799
|
+
} else {
|
|
3800
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer.buffer);
|
|
3801
|
+
gl.bufferData(gl.ARRAY_BUFFER, vertexData, gl.DYNAMIC_DRAW);
|
|
3802
|
+
}
|
|
3803
|
+
this.writeVertexAttrib(posBuffer, this.program.attrs.a_position, 2, 0, 0);
|
|
3804
|
+
|
|
3805
|
+
if(isTexture && allTexCoords.length) {
|
|
3806
|
+
const texData = new Float32Array(allTexCoords);
|
|
3807
|
+
let texBuffer = this.__cachedBuffers.find(b => b.attr === this.program.attrs.a_text_coord);
|
|
3808
|
+
if(!texBuffer) {
|
|
3809
|
+
texBuffer = this.createFloat32Buffer(texData, gl.ARRAY_BUFFER, gl.DYNAMIC_DRAW);
|
|
3810
|
+
texBuffer.attr = this.program.attrs.a_text_coord;
|
|
3811
|
+
this.__cachedBuffers.push(texBuffer);
|
|
3812
|
+
} else {
|
|
3813
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, texBuffer.buffer);
|
|
3814
|
+
gl.bufferData(gl.ARRAY_BUFFER, texData, gl.DYNAMIC_DRAW);
|
|
3815
|
+
}
|
|
3816
|
+
this.writeVertexAttrib(texBuffer, this.program.attrs.a_text_coord, 2, 0, 0);
|
|
3547
3817
|
}
|
|
3818
|
+
|
|
3819
|
+
gl.drawArrays(gl.TRIANGLES, 0, allVertices.length / 2);
|
|
3548
3820
|
}
|
|
3549
3821
|
|
|
3550
3822
|
// 填充图形
|
|
@@ -3626,7 +3898,9 @@ const jmStyleMap = {
|
|
|
3626
3898
|
'shadowOffsetY' : 'shadowOffsetY',
|
|
3627
3899
|
'shadowColor' : 'shadowColor',
|
|
3628
3900
|
'lineJoin': 'lineJoin',
|
|
3629
|
-
'lineCap':'lineCap'
|
|
3901
|
+
'lineCap':'lineCap',
|
|
3902
|
+
'lineDashOffset': 'lineDashOffset',
|
|
3903
|
+
'globalCompositeOperation': 'globalCompositeOperation'
|
|
3630
3904
|
};
|
|
3631
3905
|
|
|
3632
3906
|
class jmControl extends jmProperty {
|
|
@@ -3837,7 +4111,9 @@ class jmControl extends jmProperty {
|
|
|
3837
4111
|
}
|
|
3838
4112
|
|
|
3839
4113
|
setStyle(style) {
|
|
3840
|
-
|
|
4114
|
+
if(!style) {
|
|
4115
|
+
style = this.style;
|
|
4116
|
+
}
|
|
3841
4117
|
if(!style) return;
|
|
3842
4118
|
|
|
3843
4119
|
const __setStyle = (style, name, mpkey) => {
|
|
@@ -3921,6 +4197,120 @@ class jmControl extends jmProperty {
|
|
|
3921
4197
|
this.cursor = styleValue;
|
|
3922
4198
|
break;
|
|
3923
4199
|
}
|
|
4200
|
+
// ===== 新增样式特性 =====
|
|
4201
|
+
|
|
4202
|
+
// 虚线样式:支持自定义lineDash模式 (如 [5, 3, 2] 或 "5,3,2")
|
|
4203
|
+
case 'lineDash' : {
|
|
4204
|
+
if(!this.context.setLineDash) break;
|
|
4205
|
+
let dash;
|
|
4206
|
+
if(typeof styleValue === 'string') {
|
|
4207
|
+
dash = styleValue.split(',').map(v => parseFloat(v.trim())).filter(v => !isNaN(v));
|
|
4208
|
+
}
|
|
4209
|
+
else if(Array.isArray(styleValue)) {
|
|
4210
|
+
dash = styleValue.map(v => parseFloat(v)).filter(v => !isNaN(v));
|
|
4211
|
+
}
|
|
4212
|
+
if(dash && dash.length) {
|
|
4213
|
+
this.context.setLineDash(dash);
|
|
4214
|
+
}
|
|
4215
|
+
else {
|
|
4216
|
+
this.context.setLineDash([]);
|
|
4217
|
+
}
|
|
4218
|
+
break;
|
|
4219
|
+
}
|
|
4220
|
+
// 虚线偏移量
|
|
4221
|
+
case 'lineDashOffset' : {
|
|
4222
|
+
if(!this.context.setLineDash) break;
|
|
4223
|
+
this.context.lineDashOffset = Number(styleValue) || 0;
|
|
4224
|
+
break;
|
|
4225
|
+
}
|
|
4226
|
+
// CSS滤镜效果 (blur, grayscale, sepia, brightness, contrast, saturate, hue-rotate, invert, opacity)
|
|
4227
|
+
case 'filter' : {
|
|
4228
|
+
if(this.context.filter === undefined) break;
|
|
4229
|
+
if(styleValue instanceof jmFilter) {
|
|
4230
|
+
this.context.filter = styleValue.toCanvasFilter();
|
|
4231
|
+
}
|
|
4232
|
+
else if(typeof styleValue === 'string') {
|
|
4233
|
+
this.context.filter = styleValue || 'none';
|
|
4234
|
+
}
|
|
4235
|
+
else if(typeof styleValue === 'object') {
|
|
4236
|
+
this.context.filter = (new jmFilter(styleValue)).toCanvasFilter();
|
|
4237
|
+
}
|
|
4238
|
+
break;
|
|
4239
|
+
}
|
|
4240
|
+
// 混合模式 (source-over, multiply, screen, overlay, darken, lighten, etc.)
|
|
4241
|
+
case 'globalCompositeOperation' : {
|
|
4242
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4243
|
+
this.context.globalCompositeOperation = styleValue;
|
|
4244
|
+
break;
|
|
4245
|
+
}
|
|
4246
|
+
// 裁剪路径:通过canvas clip实现
|
|
4247
|
+
case 'clipPath' : {
|
|
4248
|
+
if(!this.context.clip) break;
|
|
4249
|
+
// clipPath可以是一个图形控件实例
|
|
4250
|
+
if(styleValue && styleValue.points && styleValue.points.length > 0) {
|
|
4251
|
+
const bounds = this.parent && this.parent.absoluteBounds ? this.parent.absoluteBounds : this.absoluteBounds;
|
|
4252
|
+
this.context.beginPath();
|
|
4253
|
+
this.context.moveTo(styleValue.points[0].x + (bounds ? bounds.left : 0), styleValue.points[0].y + (bounds ? bounds.top : 0));
|
|
4254
|
+
for(let i = 1; i < styleValue.points.length; i++) {
|
|
4255
|
+
if(styleValue.points[i].m) {
|
|
4256
|
+
this.context.moveTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4257
|
+
}
|
|
4258
|
+
else {
|
|
4259
|
+
this.context.lineTo(styleValue.points[i].x + (bounds ? bounds.left : 0), styleValue.points[i].y + (bounds ? bounds.top : 0));
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
if(styleValue.style && styleValue.style.close) {
|
|
4263
|
+
this.context.closePath();
|
|
4264
|
+
}
|
|
4265
|
+
this.context.clip();
|
|
4266
|
+
}
|
|
4267
|
+
break;
|
|
4268
|
+
}
|
|
4269
|
+
// 遮罩效果:通过globalCompositeOperation + destination-in实现
|
|
4270
|
+
case 'mask' : {
|
|
4271
|
+
if(!this.context.globalCompositeOperation) break;
|
|
4272
|
+
// mask是一个图形控件实例,在绘制前需要先应用mask
|
|
4273
|
+
// 这里只是标记,实际绘制在paint流程中处理
|
|
4274
|
+
this.__mask = styleValue;
|
|
4275
|
+
break;
|
|
4276
|
+
}
|
|
4277
|
+
// 图片阴影描边阴影(WebGL纹理canvas用)
|
|
4278
|
+
case 'shadowColor' : {
|
|
4279
|
+
if(this.webglControl) {
|
|
4280
|
+
this.webglControl.setStyle('shadowColor', styleValue);
|
|
4281
|
+
}
|
|
4282
|
+
else {
|
|
4283
|
+
this.context.shadowColor = jmUtils.toColor(styleValue);
|
|
4284
|
+
}
|
|
4285
|
+
break;
|
|
4286
|
+
}
|
|
4287
|
+
case 'shadowBlur' : {
|
|
4288
|
+
if(this.webglControl) {
|
|
4289
|
+
this.webglControl.setStyle('shadowBlur', styleValue);
|
|
4290
|
+
}
|
|
4291
|
+
else {
|
|
4292
|
+
this.context.shadowBlur = Number(styleValue) || 0;
|
|
4293
|
+
}
|
|
4294
|
+
break;
|
|
4295
|
+
}
|
|
4296
|
+
case 'shadowOffsetX' : {
|
|
4297
|
+
if(this.webglControl) {
|
|
4298
|
+
this.webglControl.setStyle('shadowOffsetX', styleValue);
|
|
4299
|
+
}
|
|
4300
|
+
else {
|
|
4301
|
+
this.context.shadowOffsetX = Number(styleValue) || 0;
|
|
4302
|
+
}
|
|
4303
|
+
break;
|
|
4304
|
+
}
|
|
4305
|
+
case 'shadowOffsetY' : {
|
|
4306
|
+
if(this.webglControl) {
|
|
4307
|
+
this.webglControl.setStyle('shadowOffsetY', styleValue);
|
|
4308
|
+
}
|
|
4309
|
+
else {
|
|
4310
|
+
this.context.shadowOffsetY = Number(styleValue) || 0;
|
|
4311
|
+
}
|
|
4312
|
+
break;
|
|
4313
|
+
}
|
|
3924
4314
|
}
|
|
3925
4315
|
}
|
|
3926
4316
|
}
|
|
@@ -3941,6 +4331,9 @@ class jmControl extends jmProperty {
|
|
|
3941
4331
|
else if(t == 'string' && k == 'shadow') {
|
|
3942
4332
|
style[k] = new jmShadow(style[k]);
|
|
3943
4333
|
}
|
|
4334
|
+
else if(t == 'string' && k == 'filter') {
|
|
4335
|
+
style[k] = new jmFilter(style[k]);
|
|
4336
|
+
}
|
|
3944
4337
|
__setStyle(style[k], k);
|
|
3945
4338
|
}
|
|
3946
4339
|
}
|
|
@@ -4085,25 +4478,30 @@ class jmControl extends jmProperty {
|
|
|
4085
4478
|
* @method getLocation
|
|
4086
4479
|
* @return {object} 当前控件位置参数,包括中心点坐标,右上角坐标,宽高
|
|
4087
4480
|
*/
|
|
4088
|
-
getLocation(
|
|
4481
|
+
getLocation() {
|
|
4089
4482
|
//如果已经计算过则直接返回
|
|
4090
4483
|
//在开画之前会清空此对象
|
|
4091
4484
|
//if(reset !== true && this.location) return this.location;
|
|
4092
4485
|
|
|
4093
4486
|
let local = this.location = {left: 0,top: 0,width: 0,height: 0};
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4487
|
+
|
|
4488
|
+
// 检查是否有百分比参数需要解析,没有则直接引用避免克隆开销
|
|
4489
|
+
const needResolve = this.parent && (jmUtils.checkPercent(this.width) || jmUtils.checkPercent(this.height) ||
|
|
4490
|
+
(this.position && jmUtils.checkPercent(this.position.x)) || (this.position && jmUtils.checkPercent(this.position.y)));
|
|
4491
|
+
local.position = typeof this.position == 'function'? this.position(): (needResolve? jmUtils.clone(this.position) : this.position);
|
|
4492
|
+
local.center = this.center && typeof this.center === 'function'?this.center(): (needResolve? jmUtils.clone(this.center) : this.center);//中心
|
|
4493
|
+
local.start = this.start && typeof this.start === 'function'?this.start(): (needResolve? jmUtils.clone(this.start) : this.start);//起点
|
|
4494
|
+
local.end = this.end && typeof this.end === 'function'?this.end(): (needResolve? jmUtils.clone(this.end) : this.end);//起点
|
|
4098
4495
|
local.radius = this.radius;//半径
|
|
4099
4496
|
local.width = this.width;
|
|
4100
4497
|
local.height = this.height;
|
|
4101
4498
|
|
|
4102
|
-
const margin =
|
|
4103
|
-
margin.
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4499
|
+
const margin = this.style.margin;
|
|
4500
|
+
const marginObj = needResolve && margin ? jmUtils.clone(margin, {}) : (margin || {});
|
|
4501
|
+
marginObj.left = (marginObj.left || 0);
|
|
4502
|
+
marginObj.top = (marginObj.top || 0);
|
|
4503
|
+
marginObj.right = (marginObj.right || 0);
|
|
4504
|
+
marginObj.bottom = (marginObj.bottom || 0);
|
|
4107
4505
|
|
|
4108
4506
|
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
4109
4507
|
if(local.position) {
|
|
@@ -4111,8 +4509,8 @@ class jmControl extends jmProperty {
|
|
|
4111
4509
|
local.top = local.position.y;
|
|
4112
4510
|
}
|
|
4113
4511
|
else {
|
|
4114
|
-
local.left =
|
|
4115
|
-
local.top =
|
|
4512
|
+
local.left = marginObj.left;
|
|
4513
|
+
local.top = marginObj.top;
|
|
4116
4514
|
}
|
|
4117
4515
|
|
|
4118
4516
|
if(this.parent) {
|
|
@@ -4374,22 +4772,31 @@ class jmControl extends jmProperty {
|
|
|
4374
4772
|
if(this.webglControl) this.webglControl.closePath();
|
|
4375
4773
|
this.context.closePath && this.context.closePath();
|
|
4376
4774
|
}
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
if(
|
|
4380
|
-
|
|
4775
|
+
|
|
4776
|
+
// 根据渲染模式选择不同的绘制路径
|
|
4777
|
+
if(this.webglControl) {
|
|
4778
|
+
// WebGL 模式:使用 WebGL 绘制
|
|
4779
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
4780
|
+
if(fill) {
|
|
4381
4781
|
const bounds = this.getBounds();
|
|
4382
4782
|
this.webglControl.fill(bounds);
|
|
4383
4783
|
}
|
|
4384
|
-
this.
|
|
4784
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
4785
|
+
this.webglControl.stroke();
|
|
4786
|
+
}
|
|
4787
|
+
if(this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4385
4788
|
}
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
this.
|
|
4789
|
+
else {
|
|
4790
|
+
// 2D 模式:使用 Canvas 2D API 绘制
|
|
4791
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
4792
|
+
if(fill) {
|
|
4793
|
+
this.context.fill && this.context.fill();
|
|
4794
|
+
}
|
|
4795
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
4796
|
+
this.context.stroke && this.context.stroke();
|
|
4797
|
+
}
|
|
4389
4798
|
}
|
|
4390
4799
|
|
|
4391
|
-
if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
4392
|
-
|
|
4393
4800
|
this.needUpdate = false;
|
|
4394
4801
|
}
|
|
4395
4802
|
|
|
@@ -4405,9 +4812,7 @@ class jmControl extends jmProperty {
|
|
|
4405
4812
|
const bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
4406
4813
|
if(this.webglControl) {
|
|
4407
4814
|
this.webglControl.setParentBounds(bounds);
|
|
4408
|
-
this.webglControl.draw(
|
|
4409
|
-
...this.points
|
|
4410
|
-
]);
|
|
4815
|
+
this.webglControl.draw(this.points);
|
|
4411
4816
|
}
|
|
4412
4817
|
else if(this.context && this.context.moveTo) {
|
|
4413
4818
|
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
@@ -4452,9 +4857,44 @@ class jmControl extends jmProperty {
|
|
|
4452
4857
|
|
|
4453
4858
|
this.setStyle();//设定样式
|
|
4454
4859
|
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4860
|
+
// 应用mask遮罩效果:在mask区域内绘制当前控件
|
|
4861
|
+
// 使用 destination-in 合成模式,只保留mask区域内的内容
|
|
4862
|
+
const maskStyle = this.style.mask || this.__mask;
|
|
4863
|
+
if(maskStyle && maskStyle.points && this.context.globalCompositeOperation) {
|
|
4864
|
+
// 先绘制当前控件
|
|
4865
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
4866
|
+
if(needDraw && this.draw) this.draw();
|
|
4867
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
4868
|
+
|
|
4869
|
+
// 再应用mask裁剪
|
|
4870
|
+
this.context.globalCompositeOperation = 'destination-in';
|
|
4871
|
+
if(maskStyle.initPoints) maskStyle.initPoints();
|
|
4872
|
+
const mBounds = maskStyle.parent && maskStyle.parent.absoluteBounds ? maskStyle.parent.absoluteBounds : this.absoluteBounds;
|
|
4873
|
+
this.context.beginPath();
|
|
4874
|
+
if(maskStyle.points && maskStyle.points.length > 0) {
|
|
4875
|
+
this.context.moveTo(maskStyle.points[0].x + (mBounds ? mBounds.left : 0), maskStyle.points[0].y + (mBounds ? mBounds.top : 0));
|
|
4876
|
+
for(let i = 1; i < maskStyle.points.length; i++) {
|
|
4877
|
+
if(maskStyle.points[i].m) {
|
|
4878
|
+
this.context.moveTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
4879
|
+
}
|
|
4880
|
+
else {
|
|
4881
|
+
this.context.lineTo(maskStyle.points[i].x + (mBounds ? mBounds.left : 0), maskStyle.points[i].y + (mBounds ? mBounds.top : 0));
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
if(maskStyle.style && maskStyle.style.close) {
|
|
4885
|
+
this.context.closePath();
|
|
4886
|
+
}
|
|
4887
|
+
}
|
|
4888
|
+
this.context.fillStyle = '#ffffff';
|
|
4889
|
+
this.context.fill();
|
|
4890
|
+
// 恢复合成模式
|
|
4891
|
+
this.context.globalCompositeOperation = 'source-over';
|
|
4892
|
+
}
|
|
4893
|
+
else {
|
|
4894
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
4895
|
+
if(needDraw && this.draw) this.draw();
|
|
4896
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
4897
|
+
}
|
|
4458
4898
|
|
|
4459
4899
|
if(this.children) {
|
|
4460
4900
|
this.children.each(function(i,item) {
|
|
@@ -4544,7 +4984,15 @@ class jmControl extends jmProperty {
|
|
|
4544
4984
|
* @param {array} args 事件参数数组
|
|
4545
4985
|
*/
|
|
4546
4986
|
emit(...args) {
|
|
4547
|
-
|
|
4987
|
+
// 避免每帧 args.slice(1) 分配临时数组
|
|
4988
|
+
// runEventHandle 内部会把非数组参数包装成数组
|
|
4989
|
+
if(args.length > 2) {
|
|
4990
|
+
this.runEventHandle(args[0], args.slice(1));
|
|
4991
|
+
} else if(args.length === 2) {
|
|
4992
|
+
this.runEventHandle(args[0], [args[1]]);
|
|
4993
|
+
} else {
|
|
4994
|
+
this.runEventHandle(args[0], []);
|
|
4995
|
+
}
|
|
4548
4996
|
return this;
|
|
4549
4997
|
}
|
|
4550
4998
|
|
|
@@ -5184,7 +5632,6 @@ class jmArc extends jmPath {
|
|
|
5184
5632
|
if((mw == 0 && mh == 0) || start == end) return;
|
|
5185
5633
|
|
|
5186
5634
|
let anticlockwise = this.anticlockwise;
|
|
5187
|
-
this.points = [];
|
|
5188
5635
|
let step = 1 / Math.max(mw, mh);
|
|
5189
5636
|
|
|
5190
5637
|
//如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
|
|
@@ -5195,18 +5642,33 @@ class jmArc extends jmPath {
|
|
|
5195
5642
|
}
|
|
5196
5643
|
if(start > end) step = -step;
|
|
5197
5644
|
|
|
5198
|
-
|
|
5645
|
+
// 预计算需要的点数量
|
|
5646
|
+
let pointCount = Math.ceil(Math.abs(end - start) / Math.abs(step)) + 1;
|
|
5647
|
+
if(this.isFan) pointCount++;
|
|
5648
|
+
|
|
5649
|
+
// 复用已有数组,避免每帧分配;大小变化时才重建
|
|
5650
|
+
if(!this.points || this.points.length !== pointCount) {
|
|
5651
|
+
this.points = new Array(pointCount);
|
|
5652
|
+
for(let i = 0; i < pointCount; i++) {
|
|
5653
|
+
this.points[i] = { x: 0, y: 0 };
|
|
5654
|
+
}
|
|
5655
|
+
}
|
|
5656
|
+
|
|
5657
|
+
let idx = 0;
|
|
5658
|
+
if(this.isFan) {
|
|
5659
|
+
this.points[idx].x = location.center.x;
|
|
5660
|
+
this.points[idx].y = location.center.y;
|
|
5661
|
+
idx++;
|
|
5662
|
+
}
|
|
5199
5663
|
|
|
5200
5664
|
//椭圆方程x=a*cos(r) ,y=b*sin(r)
|
|
5201
5665
|
for(let r=start;;r += step) {
|
|
5202
5666
|
if(step > 0 && r > end) r = end;
|
|
5203
5667
|
else if(step < 0 && r < end) r = end;
|
|
5204
5668
|
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
};
|
|
5209
|
-
this.points.push(p);
|
|
5669
|
+
this.points[idx].x = Math.cos(r) * mw + cx;
|
|
5670
|
+
this.points[idx].y = Math.sin(r) * mh + cy;
|
|
5671
|
+
idx++;
|
|
5210
5672
|
|
|
5211
5673
|
if(r == end) break;
|
|
5212
5674
|
}
|
|
@@ -5805,6 +6267,7 @@ class jmPrismatic extends jmPath {
|
|
|
5805
6267
|
* @class jmRect
|
|
5806
6268
|
* @extends jmPath
|
|
5807
6269
|
* @param {object} params 参数 position=矩形左上角顶点坐标,width=宽,height=高,radius=边角弧度
|
|
6270
|
+
* radius支持数字(四角相同)或对象 { topLeft, topRight, bottomRight, bottomLeft }
|
|
5808
6271
|
*/
|
|
5809
6272
|
class jmRect extends jmPath {
|
|
5810
6273
|
|
|
@@ -5814,12 +6277,24 @@ class jmRect extends jmPath {
|
|
|
5814
6277
|
super(params, t);
|
|
5815
6278
|
|
|
5816
6279
|
this.style.close = true;
|
|
5817
|
-
|
|
6280
|
+
const r = params.radius || this.style.radius || this.style.borderRadius || 0;
|
|
6281
|
+
if(typeof r === 'object' && r !== null) {
|
|
6282
|
+
// 四角独立圆角
|
|
6283
|
+
this.radius = {
|
|
6284
|
+
topLeft: Number(r.topLeft) || 0,
|
|
6285
|
+
topRight: Number(r.topRight) || 0,
|
|
6286
|
+
bottomRight: Number(r.bottomRight) || 0,
|
|
6287
|
+
bottomLeft: Number(r.bottomLeft) || 0
|
|
6288
|
+
};
|
|
6289
|
+
}
|
|
6290
|
+
else {
|
|
6291
|
+
this.radius = r;
|
|
6292
|
+
}
|
|
5818
6293
|
}
|
|
5819
6294
|
/**
|
|
5820
|
-
*
|
|
6295
|
+
* 圆角半径,支持数字或四角独立对象
|
|
5821
6296
|
* @property radius
|
|
5822
|
-
* @type {number}
|
|
6297
|
+
* @type {number|object}
|
|
5823
6298
|
*/
|
|
5824
6299
|
get radius() {
|
|
5825
6300
|
return this.property('radius');
|
|
@@ -5827,6 +6302,36 @@ class jmRect extends jmPath {
|
|
|
5827
6302
|
set radius(v) {
|
|
5828
6303
|
this.needUpdate = true;
|
|
5829
6304
|
return this.property('radius', v);
|
|
6305
|
+
}
|
|
6306
|
+
|
|
6307
|
+
/**
|
|
6308
|
+
* 获取规范化的圆角值(四角独立)
|
|
6309
|
+
* @returns {object} { topLeft, topRight, bottomRight, bottomLeft }
|
|
6310
|
+
*/
|
|
6311
|
+
getNormalizedRadius() {
|
|
6312
|
+
const r = this.radius;
|
|
6313
|
+
if(typeof r === 'number') {
|
|
6314
|
+
const v = Math.max(0, r);
|
|
6315
|
+
return { topLeft: v, topRight: v, bottomRight: v, bottomLeft: v };
|
|
6316
|
+
}
|
|
6317
|
+
if(typeof r === 'object' && r !== null) {
|
|
6318
|
+
return {
|
|
6319
|
+
topLeft: Math.max(0, Number(r.topLeft) || 0),
|
|
6320
|
+
topRight: Math.max(0, Number(r.topRight) || 0),
|
|
6321
|
+
bottomRight: Math.max(0, Number(r.bottomRight) || 0),
|
|
6322
|
+
bottomLeft: Math.max(0, Number(r.bottomLeft) || 0)
|
|
6323
|
+
};
|
|
6324
|
+
}
|
|
6325
|
+
return { topLeft: 0, topRight: 0, bottomRight: 0, bottomLeft: 0 };
|
|
6326
|
+
}
|
|
6327
|
+
|
|
6328
|
+
/**
|
|
6329
|
+
* 检查是否有圆角
|
|
6330
|
+
* @returns {boolean}
|
|
6331
|
+
*/
|
|
6332
|
+
hasRadius() {
|
|
6333
|
+
const nr = this.getNormalizedRadius();
|
|
6334
|
+
return nr.topLeft > 0 || nr.topRight > 0 || nr.bottomRight > 0 || nr.bottomLeft > 0;
|
|
5830
6335
|
}
|
|
5831
6336
|
|
|
5832
6337
|
/**
|
|
@@ -5889,7 +6394,7 @@ class jmRect extends jmPath {
|
|
|
5889
6394
|
|
|
5890
6395
|
/**
|
|
5891
6396
|
* 初始化图形点
|
|
5892
|
-
*
|
|
6397
|
+
* 支持四角独立圆角,借助圆弧对象计算描点
|
|
5893
6398
|
*
|
|
5894
6399
|
* @method initPoints
|
|
5895
6400
|
* @private
|
|
@@ -5906,32 +6411,67 @@ class jmRect extends jmPath {
|
|
|
5906
6411
|
this.dottedLine = this.graph.createShape(jmLine, {style: this.style});
|
|
5907
6412
|
}
|
|
5908
6413
|
|
|
5909
|
-
|
|
5910
|
-
|
|
6414
|
+
const nr = this.getNormalizedRadius();
|
|
6415
|
+
const hasRadius = this.hasRadius();
|
|
6416
|
+
|
|
6417
|
+
// 如果有圆角(支持四角独立),借助圆弧对象计算描点
|
|
6418
|
+
if(hasRadius) {
|
|
5911
6419
|
let q = Math.PI / 2;
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
6420
|
+
|
|
6421
|
+
// 限制圆角不超过短边的一半
|
|
6422
|
+
const maxR = Math.min(location.width / 2, location.height / 2);
|
|
6423
|
+
const rtl = Math.min(nr.topLeft, maxR);
|
|
6424
|
+
const rtr = Math.min(nr.topRight, maxR);
|
|
6425
|
+
const rbr = Math.min(nr.bottomRight, maxR);
|
|
6426
|
+
const rbl = Math.min(nr.bottomLeft, maxR);
|
|
6427
|
+
|
|
6428
|
+
// 左上角圆弧
|
|
6429
|
+
if(rtl > 0) {
|
|
6430
|
+
let arc = this.graph.createShape(jmArc,{radius:rtl,anticlockwise:false});
|
|
6431
|
+
arc.center = {x:location.left + rtl, y:location.top + rtl};
|
|
6432
|
+
arc.startAngle = Math.PI;
|
|
6433
|
+
arc.endAngle = Math.PI + q;
|
|
6434
|
+
var ps1 = arc.initPoints();
|
|
6435
|
+
}
|
|
6436
|
+
else {
|
|
6437
|
+
var ps1 = [p1];
|
|
6438
|
+
}
|
|
6439
|
+
|
|
6440
|
+
// 右上角圆弧
|
|
6441
|
+
if(rtr > 0) {
|
|
6442
|
+
let arc = this.graph.createShape(jmArc,{radius:rtr,anticlockwise:false});
|
|
6443
|
+
arc.center = {x:p2.x - rtr, y:p2.y + rtr};
|
|
6444
|
+
arc.startAngle = Math.PI + q;
|
|
6445
|
+
arc.endAngle = Math.PI * 2;
|
|
6446
|
+
var ps2 = arc.initPoints();
|
|
6447
|
+
}
|
|
6448
|
+
else {
|
|
6449
|
+
var ps2 = [p2];
|
|
6450
|
+
}
|
|
6451
|
+
|
|
6452
|
+
// 右下角圆弧
|
|
6453
|
+
if(rbr > 0) {
|
|
6454
|
+
let arc = this.graph.createShape(jmArc,{radius:rbr,anticlockwise:false});
|
|
6455
|
+
arc.center = {x:p3.x - rbr, y:p3.y - rbr};
|
|
6456
|
+
arc.startAngle = 0;
|
|
6457
|
+
arc.endAngle = q;
|
|
6458
|
+
var ps3 = arc.initPoints();
|
|
6459
|
+
}
|
|
6460
|
+
else {
|
|
6461
|
+
var ps3 = [p3];
|
|
6462
|
+
}
|
|
6463
|
+
|
|
6464
|
+
// 左下角圆弧
|
|
6465
|
+
if(rbl > 0) {
|
|
6466
|
+
let arc = this.graph.createShape(jmArc,{radius:rbl,anticlockwise:false});
|
|
6467
|
+
arc.center = {x:p4.x + rbl, y:p4.y - rbl};
|
|
6468
|
+
arc.startAngle = q;
|
|
6469
|
+
arc.endAngle = Math.PI;
|
|
6470
|
+
var ps4 = arc.initPoints();
|
|
6471
|
+
}
|
|
6472
|
+
else {
|
|
6473
|
+
var ps4 = [p4];
|
|
6474
|
+
}
|
|
5935
6475
|
this.points = ps1.concat(ps2,ps3,ps4);
|
|
5936
6476
|
}
|
|
5937
6477
|
else {
|
|
@@ -6270,7 +6810,7 @@ class jmLabel extends jmControl {
|
|
|
6270
6810
|
this.style.textAlign = this.style.textAlign || 'left';
|
|
6271
6811
|
//文字垂直对齐
|
|
6272
6812
|
this.style.textBaseline = this.style.textBaseline || 'middle';
|
|
6273
|
-
this.text = params.text || '';
|
|
6813
|
+
this.text = params.text || params.value || '';
|
|
6274
6814
|
|
|
6275
6815
|
this.center = params.center || null;
|
|
6276
6816
|
}
|
|
@@ -6559,67 +7099,6 @@ class jmLabel extends jmControl {
|
|
|
6559
7099
|
}
|
|
6560
7100
|
}
|
|
6561
7101
|
}
|
|
6562
|
-
//如果有指定边框,则画出边框
|
|
6563
|
-
if(this.style.border) {
|
|
6564
|
-
//如果指定了边框样式
|
|
6565
|
-
if(this.style.border.style) {
|
|
6566
|
-
this.context.save && this.context.save();
|
|
6567
|
-
this.setStyle(this.style.border.style);
|
|
6568
|
-
}
|
|
6569
|
-
if(this.mode === '2d') {
|
|
6570
|
-
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
6571
|
-
if(this.style.border.top) {
|
|
6572
|
-
this.context.lineTo(this.points[1].x + bounds.left,this.points[1].y + bounds.top);
|
|
6573
|
-
}
|
|
6574
|
-
|
|
6575
|
-
if(this.style.border.right) {
|
|
6576
|
-
this.context.moveTo(this.points[1].x + bounds.left,this.points[1].y + bounds.top);
|
|
6577
|
-
this.context.lineTo(this.points[2].x + bounds.left,this.points[2].y + bounds.top);
|
|
6578
|
-
}
|
|
6579
|
-
|
|
6580
|
-
if(this.style.border.bottom) {
|
|
6581
|
-
this.context.moveTo(this.points[2].x + bounds.left,this.points[2].y + bounds.top);
|
|
6582
|
-
this.context.lineTo(this.points[3].x + bounds.left,this.points[3].y + bounds.top);
|
|
6583
|
-
}
|
|
6584
|
-
|
|
6585
|
-
if(this.style.border.left) {
|
|
6586
|
-
this.context.moveTo(this.points[3].x + bounds.left,this.points[3].y + bounds.top);
|
|
6587
|
-
this.context.lineTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
6588
|
-
}
|
|
6589
|
-
}
|
|
6590
|
-
else {
|
|
6591
|
-
const points = [];
|
|
6592
|
-
if(this.style.border.top) {
|
|
6593
|
-
points.push(this.points[0]);
|
|
6594
|
-
points.push(this.points[1]);
|
|
6595
|
-
}
|
|
6596
|
-
|
|
6597
|
-
if(this.style.border.right) {
|
|
6598
|
-
points.push({
|
|
6599
|
-
...this.points[1],
|
|
6600
|
-
m: true
|
|
6601
|
-
});
|
|
6602
|
-
points.push(this.points[2]);
|
|
6603
|
-
}
|
|
6604
|
-
|
|
6605
|
-
if(this.style.border.bottom) {
|
|
6606
|
-
points.push({
|
|
6607
|
-
...this.points[2],
|
|
6608
|
-
m: true
|
|
6609
|
-
});
|
|
6610
|
-
points.push(this.points[3]);
|
|
6611
|
-
}
|
|
6612
|
-
|
|
6613
|
-
if(this.style.border.left) {
|
|
6614
|
-
points.push({
|
|
6615
|
-
...this.points[3],
|
|
6616
|
-
m: true
|
|
6617
|
-
});
|
|
6618
|
-
points.push(this.points[0]);
|
|
6619
|
-
}
|
|
6620
|
-
points.length && this.webglControl && this.webglControl.stroke(points);
|
|
6621
|
-
}
|
|
6622
|
-
}
|
|
6623
7102
|
}
|
|
6624
7103
|
|
|
6625
7104
|
endDraw() {
|
|
@@ -7568,145 +8047,6 @@ class jmKeyEvent {
|
|
|
7568
8047
|
}
|
|
7569
8048
|
}
|
|
7570
8049
|
|
|
7571
|
-
/**
|
|
7572
|
-
* 图层类
|
|
7573
|
-
* 用于组织和管理图形对象,支持可见性和锁定控制
|
|
7574
|
-
* 图层可以包含多个图形对象,并控制它们的显示和交互
|
|
7575
|
-
*
|
|
7576
|
-
* @class jmLayer
|
|
7577
|
-
* @extends jmControl
|
|
7578
|
-
* @param {object} params 图层参数
|
|
7579
|
-
* @param {string} [params.name] 图层名称,默认为 'Layer_${timestamp}'
|
|
7580
|
-
* @param {boolean} [params.visible=true] 图层是否可见
|
|
7581
|
-
* @param {boolean} [params.locked=false] 图层是否锁定(锁定后不可交互)
|
|
7582
|
-
* @param {jmGraph} [params.graph] 所属的画布对象
|
|
7583
|
-
*/
|
|
7584
|
-
class jmLayer extends jmControl {
|
|
7585
|
-
|
|
7586
|
-
constructor(params, t='jmLayer') {
|
|
7587
|
-
params = params || {};
|
|
7588
|
-
params.interactive = false; // 图层本身不响应交互事件
|
|
7589
|
-
super(params, t);
|
|
7590
|
-
|
|
7591
|
-
this.name = params.name || `Layer_${Date.now()}`;
|
|
7592
|
-
this.visible = params.visible !== false;
|
|
7593
|
-
this.locked = params.locked || false;
|
|
7594
|
-
}
|
|
7595
|
-
|
|
7596
|
-
/**
|
|
7597
|
-
* 图层名称
|
|
7598
|
-
* 图层的唯一标识符,用于查找和管理图层
|
|
7599
|
-
*
|
|
7600
|
-
* @property name
|
|
7601
|
-
* @type {string}
|
|
7602
|
-
*/
|
|
7603
|
-
get name() {
|
|
7604
|
-
return this.property('name');
|
|
7605
|
-
}
|
|
7606
|
-
set name(v) {
|
|
7607
|
-
if(!v || typeof v !== 'string') {
|
|
7608
|
-
console.warn('jmLayer: name must be a non-empty string');
|
|
7609
|
-
return;
|
|
7610
|
-
}
|
|
7611
|
-
return this.property('name', v);
|
|
7612
|
-
}
|
|
7613
|
-
|
|
7614
|
-
/**
|
|
7615
|
-
* 图层是否可见
|
|
7616
|
-
* 不可见的图层不会被渲染,但仍然存在于图层列表中
|
|
7617
|
-
*
|
|
7618
|
-
* @property visible
|
|
7619
|
-
* @type {boolean}
|
|
7620
|
-
*/
|
|
7621
|
-
get visible() {
|
|
7622
|
-
return this.property('visible');
|
|
7623
|
-
}
|
|
7624
|
-
set visible(v) {
|
|
7625
|
-
this.needUpdate = true;
|
|
7626
|
-
return this.property('visible', v);
|
|
7627
|
-
}
|
|
7628
|
-
|
|
7629
|
-
/**
|
|
7630
|
-
* 图层是否锁定
|
|
7631
|
-
* 锁定的图层中的图形不可被选中或移动,但仍然可见
|
|
7632
|
-
* 适用于背景图层或参考图层
|
|
7633
|
-
*
|
|
7634
|
-
* @property locked
|
|
7635
|
-
* @type {boolean}
|
|
7636
|
-
*/
|
|
7637
|
-
get locked() {
|
|
7638
|
-
return this.property('locked');
|
|
7639
|
-
}
|
|
7640
|
-
set locked(v) {
|
|
7641
|
-
return this.property('locked', v);
|
|
7642
|
-
}
|
|
7643
|
-
|
|
7644
|
-
/**
|
|
7645
|
-
* 绘制图层
|
|
7646
|
-
* 只有可见的图层才会被绘制
|
|
7647
|
-
*
|
|
7648
|
-
* @method paint
|
|
7649
|
-
* @param {boolean} v 是否需要重绘
|
|
7650
|
-
*/
|
|
7651
|
-
paint(v) {
|
|
7652
|
-
if(this.visible !== false) {
|
|
7653
|
-
super.paint(v);
|
|
7654
|
-
}
|
|
7655
|
-
}
|
|
7656
|
-
|
|
7657
|
-
/**
|
|
7658
|
-
* 检查点是否在图层内
|
|
7659
|
-
* 锁定的图层不会响应鼠标事件
|
|
7660
|
-
*
|
|
7661
|
-
* @method checkPoint
|
|
7662
|
-
* @param {object} p 坐标点 {x, y}
|
|
7663
|
-
* @param {number} [pad] padding,额外的检测范围
|
|
7664
|
-
* @return {boolean} 是否在图层内
|
|
7665
|
-
*/
|
|
7666
|
-
checkPoint(p, pad) {
|
|
7667
|
-
// 锁定的图层不响应交互
|
|
7668
|
-
if(this.locked) return false;
|
|
7669
|
-
return super.checkPoint(p, pad);
|
|
7670
|
-
}
|
|
7671
|
-
|
|
7672
|
-
/**
|
|
7673
|
-
* 清空图层
|
|
7674
|
-
* 移除图层中的所有图形对象
|
|
7675
|
-
*
|
|
7676
|
-
* @method clear
|
|
7677
|
-
*/
|
|
7678
|
-
clear() {
|
|
7679
|
-
this.children.clear();
|
|
7680
|
-
this.needUpdate = true;
|
|
7681
|
-
}
|
|
7682
|
-
|
|
7683
|
-
/**
|
|
7684
|
-
* 获取图层中的图形数量
|
|
7685
|
-
*
|
|
7686
|
-
* @method getShapeCount
|
|
7687
|
-
* @return {number} 图形数量
|
|
7688
|
-
*/
|
|
7689
|
-
getShapeCount() {
|
|
7690
|
-
return this.children.length;
|
|
7691
|
-
}
|
|
7692
|
-
|
|
7693
|
-
/**
|
|
7694
|
-
* 获取图层信息
|
|
7695
|
-
* 返回图层的基本信息,用于调试和日志
|
|
7696
|
-
*
|
|
7697
|
-
* @method getInfo
|
|
7698
|
-
* @return {object} 图层信息对象
|
|
7699
|
-
*/
|
|
7700
|
-
getInfo() {
|
|
7701
|
-
return {
|
|
7702
|
-
name: this.name,
|
|
7703
|
-
visible: this.visible,
|
|
7704
|
-
locked: this.locked,
|
|
7705
|
-
shapeCount: this.getShapeCount()
|
|
7706
|
-
};
|
|
7707
|
-
}
|
|
7708
|
-
}
|
|
7709
|
-
|
|
7710
8050
|
/**
|
|
7711
8051
|
* jmGraph画图类库
|
|
7712
8052
|
* 对canvas画图api进行二次封装,使其更易调用,省去很多重复的工作。
|
|
@@ -7718,7 +8058,7 @@ class jmLayer extends jmControl {
|
|
|
7718
8058
|
* @param {object} option 参数:{width:宽,height:高}
|
|
7719
8059
|
* @param {function} callback 初始化后的回调
|
|
7720
8060
|
*/
|
|
7721
|
-
class jmGraph
|
|
8061
|
+
class jmGraph extends jmControl {
|
|
7722
8062
|
|
|
7723
8063
|
constructor(canvas, option, callback) {
|
|
7724
8064
|
if(typeof option == 'function') {
|
|
@@ -7936,7 +8276,7 @@ class jmGraph$1 extends jmControl {
|
|
|
7936
8276
|
* @return {jmGraph} jmGraph实例对象
|
|
7937
8277
|
*/
|
|
7938
8278
|
static create(...args) {
|
|
7939
|
-
return new jmGraph
|
|
8279
|
+
return new jmGraph(...args);
|
|
7940
8280
|
}
|
|
7941
8281
|
|
|
7942
8282
|
/**
|
|
@@ -7985,9 +8325,7 @@ class jmGraph$1 extends jmControl {
|
|
|
7985
8325
|
if(shape) {
|
|
7986
8326
|
if(!args) args = {};
|
|
7987
8327
|
args.graph = this;
|
|
7988
|
-
|
|
7989
|
-
// 添加到活动图层
|
|
7990
|
-
this.addShapeToLayer(obj);
|
|
8328
|
+
const obj = new shape(args);
|
|
7991
8329
|
return obj;
|
|
7992
8330
|
}
|
|
7993
8331
|
}
|
|
@@ -8113,13 +8451,19 @@ class jmGraph$1 extends jmControl {
|
|
|
8113
8451
|
this.context.clearRect(0, 0, w, h);
|
|
8114
8452
|
}
|
|
8115
8453
|
else if(this.mode === 'webgl' && this.context.clear) {
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
a
|
|
8121
|
-
}
|
|
8122
|
-
this.
|
|
8454
|
+
// 缓存 clearColor 对象,避免每帧创建
|
|
8455
|
+
if(this.style && this.style.fill) {
|
|
8456
|
+
const color = this.utils.hexToRGBA(this.style.fill);
|
|
8457
|
+
this.__lastClearColor = color;
|
|
8458
|
+
this.context.clearColor(color.r, color.g, color.b, color.a);
|
|
8459
|
+
}
|
|
8460
|
+
else if(!this.__lastClearColor) {
|
|
8461
|
+
this.__lastClearColor = { r: 0, g: 0, b: 0, a: 0 };
|
|
8462
|
+
this.context.clearColor(0, 0, 0, 0);
|
|
8463
|
+
}
|
|
8464
|
+
else {
|
|
8465
|
+
this.context.clearColor(this.__lastClearColor.r, this.__lastClearColor.g, this.__lastClearColor.b, this.__lastClearColor.a);
|
|
8466
|
+
}
|
|
8123
8467
|
this.context.clear(this.context.COLOR_BUFFER_BIT); // 清空颜色缓冲区,也就是清空画布
|
|
8124
8468
|
}
|
|
8125
8469
|
}
|
|
@@ -8310,232 +8654,6 @@ class jmGraph$1 extends jmControl {
|
|
|
8310
8654
|
return this; // 支持链式调用
|
|
8311
8655
|
}
|
|
8312
8656
|
|
|
8313
|
-
/**
|
|
8314
|
-
* 初始化图层系统
|
|
8315
|
-
* 创建图层管理的基础结构,包括默认图层
|
|
8316
|
-
*
|
|
8317
|
-
* @method initLayers
|
|
8318
|
-
* @private
|
|
8319
|
-
*/
|
|
8320
|
-
initLayers() {
|
|
8321
|
-
if(!this.layers) {
|
|
8322
|
-
this.layers = new jmList();
|
|
8323
|
-
// 创建默认图层
|
|
8324
|
-
const defaultLayer = this.createLayer('Default Layer');
|
|
8325
|
-
this.activeLayer = defaultLayer;
|
|
8326
|
-
}
|
|
8327
|
-
}
|
|
8328
|
-
|
|
8329
|
-
/**
|
|
8330
|
-
* 创建新图层
|
|
8331
|
-
* 图层用于组织和管理图形对象,支持可见性和锁定控制
|
|
8332
|
-
*
|
|
8333
|
-
* @method createLayer
|
|
8334
|
-
* @param {string} name 图层名称(必须唯一)
|
|
8335
|
-
* @param {object} [options] 图层选项
|
|
8336
|
-
* @param {boolean} [options.visible=true] 图层是否可见
|
|
8337
|
-
* @param {boolean} [options.locked=false] 图层是否锁定(锁定后不可交互)
|
|
8338
|
-
* @return {jmLayer} 新创建的图层
|
|
8339
|
-
*/
|
|
8340
|
-
createLayer(name, options = {}) {
|
|
8341
|
-
// 参数验证
|
|
8342
|
-
if(!name || typeof name !== 'string') {
|
|
8343
|
-
console.warn('jmGraph: createLayer - 图层名称必须是非空字符串');
|
|
8344
|
-
name = `Layer_${Date.now()}`;
|
|
8345
|
-
}
|
|
8346
|
-
|
|
8347
|
-
this.initLayers();
|
|
8348
|
-
|
|
8349
|
-
// 检查图层名称是否已存在
|
|
8350
|
-
const existingLayer = this.getLayer(name);
|
|
8351
|
-
if(existingLayer) {
|
|
8352
|
-
console.warn(`jmGraph: 图层 "${name}" 已存在,将返回现有图层`);
|
|
8353
|
-
return existingLayer;
|
|
8354
|
-
}
|
|
8355
|
-
|
|
8356
|
-
const layer = new jmLayer({
|
|
8357
|
-
name: name,
|
|
8358
|
-
graph: this,
|
|
8359
|
-
...options
|
|
8360
|
-
});
|
|
8361
|
-
|
|
8362
|
-
this.layers.add(layer);
|
|
8363
|
-
this.children.add(layer);
|
|
8364
|
-
this.needUpdate = true;
|
|
8365
|
-
return layer;
|
|
8366
|
-
}
|
|
8367
|
-
|
|
8368
|
-
/**
|
|
8369
|
-
* 获取所有图层
|
|
8370
|
-
*
|
|
8371
|
-
* @method getLayers
|
|
8372
|
-
* @return {jmList} 图层列表
|
|
8373
|
-
*/
|
|
8374
|
-
getLayers() {
|
|
8375
|
-
this.initLayers();
|
|
8376
|
-
return this.layers;
|
|
8377
|
-
}
|
|
8378
|
-
|
|
8379
|
-
/**
|
|
8380
|
-
* 根据名称获取图层
|
|
8381
|
-
*
|
|
8382
|
-
* @method getLayer
|
|
8383
|
-
* @param {string} name 图层名称
|
|
8384
|
-
* @return {jmLayer|null} 图层对象,如果不存在则返回null
|
|
8385
|
-
*/
|
|
8386
|
-
getLayer(name) {
|
|
8387
|
-
this.initLayers();
|
|
8388
|
-
|
|
8389
|
-
if(!name) return null;
|
|
8390
|
-
|
|
8391
|
-
let result = null;
|
|
8392
|
-
this.layers.each((i, layer) => {
|
|
8393
|
-
if(layer.name === name) {
|
|
8394
|
-
result = layer;
|
|
8395
|
-
return false; // 找到后停止遍历
|
|
8396
|
-
}
|
|
8397
|
-
});
|
|
8398
|
-
return result;
|
|
8399
|
-
}
|
|
8400
|
-
|
|
8401
|
-
/**
|
|
8402
|
-
* 设置活动图层
|
|
8403
|
-
* 新创建的图形将自动添加到活动图层
|
|
8404
|
-
*
|
|
8405
|
-
* @method setActiveLayer
|
|
8406
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
8407
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8408
|
-
*/
|
|
8409
|
-
setActiveLayer(layer) {
|
|
8410
|
-
this.initLayers();
|
|
8411
|
-
|
|
8412
|
-
// 支持传入图层名称或图层对象
|
|
8413
|
-
if(typeof layer === 'string') {
|
|
8414
|
-
layer = this.getLayer(layer);
|
|
8415
|
-
}
|
|
8416
|
-
|
|
8417
|
-
if(!layer || !(layer instanceof jmLayer)) {
|
|
8418
|
-
console.warn('jmGraph: setActiveLayer - 无效的图层');
|
|
8419
|
-
return this;
|
|
8420
|
-
}
|
|
8421
|
-
|
|
8422
|
-
this.activeLayer = layer;
|
|
8423
|
-
return this;
|
|
8424
|
-
}
|
|
8425
|
-
|
|
8426
|
-
/**
|
|
8427
|
-
* 获取当前活动图层
|
|
8428
|
-
* 活动图层是新创建图形的默认容器
|
|
8429
|
-
*
|
|
8430
|
-
* @method getActiveLayer
|
|
8431
|
-
* @return {jmLayer} 当前活动图层
|
|
8432
|
-
*/
|
|
8433
|
-
getActiveLayer() {
|
|
8434
|
-
this.initLayers();
|
|
8435
|
-
return this.activeLayer;
|
|
8436
|
-
}
|
|
8437
|
-
|
|
8438
|
-
/**
|
|
8439
|
-
* 移除图层
|
|
8440
|
-
* 删除指定图层及其包含的所有图形
|
|
8441
|
-
* 注意:默认图层不可删除
|
|
8442
|
-
*
|
|
8443
|
-
* @method removeLayer
|
|
8444
|
-
* @param {string|jmLayer} layer 图层名称或图层对象
|
|
8445
|
-
* @return {boolean} 是否成功删除
|
|
8446
|
-
*/
|
|
8447
|
-
removeLayer(layer) {
|
|
8448
|
-
this.initLayers();
|
|
8449
|
-
|
|
8450
|
-
// 支持传入图层名称或图层对象
|
|
8451
|
-
if(typeof layer === 'string') {
|
|
8452
|
-
layer = this.getLayer(layer);
|
|
8453
|
-
}
|
|
8454
|
-
|
|
8455
|
-
if(!layer) {
|
|
8456
|
-
console.warn('jmGraph: removeLayer - 图层不存在');
|
|
8457
|
-
return false;
|
|
8458
|
-
}
|
|
8459
|
-
|
|
8460
|
-
// 禁止删除默认图层
|
|
8461
|
-
if(layer.name === 'Default Layer') {
|
|
8462
|
-
console.warn('jmGraph: 不能删除默认图层');
|
|
8463
|
-
return false;
|
|
8464
|
-
}
|
|
8465
|
-
|
|
8466
|
-
// 如果删除的是当前活动图层,切换到默认图层
|
|
8467
|
-
if(this.activeLayer === layer) {
|
|
8468
|
-
this.activeLayer = this.getLayer('Default Layer');
|
|
8469
|
-
}
|
|
8470
|
-
|
|
8471
|
-
this.layers.remove(layer);
|
|
8472
|
-
this.children.remove(layer);
|
|
8473
|
-
this.needUpdate = true;
|
|
8474
|
-
return true;
|
|
8475
|
-
}
|
|
8476
|
-
|
|
8477
|
-
/**
|
|
8478
|
-
* 将形状添加到指定图层
|
|
8479
|
-
* 如果未指定图层,则添加到当前活动图层
|
|
8480
|
-
*
|
|
8481
|
-
* @method addShapeToLayer
|
|
8482
|
-
* @param {jmControl} shape 要添加的形状对象
|
|
8483
|
-
* @param {string|jmLayer} [layer] 图层名称或图层对象,默认为当前活动图层
|
|
8484
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8485
|
-
*/
|
|
8486
|
-
addShapeToLayer(shape, layer) {
|
|
8487
|
-
this.initLayers();
|
|
8488
|
-
|
|
8489
|
-
// 参数验证
|
|
8490
|
-
if(!shape) {
|
|
8491
|
-
console.warn('jmGraph: addShapeToLayer - 无效的形状对象');
|
|
8492
|
-
return this;
|
|
8493
|
-
}
|
|
8494
|
-
|
|
8495
|
-
// 确定目标图层
|
|
8496
|
-
if(!layer) {
|
|
8497
|
-
layer = this.activeLayer;
|
|
8498
|
-
} else if(typeof layer === 'string') {
|
|
8499
|
-
layer = this.getLayer(layer);
|
|
8500
|
-
}
|
|
8501
|
-
|
|
8502
|
-
if(!layer) {
|
|
8503
|
-
console.warn('jmGraph: addShapeToLayer - 图层不存在');
|
|
8504
|
-
return this;
|
|
8505
|
-
}
|
|
8506
|
-
|
|
8507
|
-
layer.children.add(shape);
|
|
8508
|
-
this.needUpdate = true;
|
|
8509
|
-
return this;
|
|
8510
|
-
}
|
|
8511
|
-
|
|
8512
|
-
/**
|
|
8513
|
-
* 从图层中移除形状
|
|
8514
|
-
*
|
|
8515
|
-
* @method removeShapeFromLayer
|
|
8516
|
-
* @param {jmControl} shape 要移除的形状对象
|
|
8517
|
-
* @return {jmGraph} 返回当前实例,支持链式调用
|
|
8518
|
-
*/
|
|
8519
|
-
removeShapeFromLayer(shape) {
|
|
8520
|
-
if(!shape) {
|
|
8521
|
-
console.warn('jmGraph: removeShapeFromLayer - 无效的形状对象');
|
|
8522
|
-
return this;
|
|
8523
|
-
}
|
|
8524
|
-
|
|
8525
|
-
// 从所有图层中查找并移除
|
|
8526
|
-
if(this.layers) {
|
|
8527
|
-
this.layers.each((i, layer) => {
|
|
8528
|
-
if(layer.children.contains(shape)) {
|
|
8529
|
-
layer.children.remove(shape);
|
|
8530
|
-
this.needUpdate = true;
|
|
8531
|
-
return false; // 找到后停止遍历
|
|
8532
|
-
}
|
|
8533
|
-
});
|
|
8534
|
-
}
|
|
8535
|
-
|
|
8536
|
-
return this;
|
|
8537
|
-
}
|
|
8538
|
-
|
|
8539
8657
|
/**
|
|
8540
8658
|
* 保存为base64图形数据
|
|
8541
8659
|
*
|
|
@@ -8602,48 +8720,27 @@ class jmGraph$1 extends jmControl {
|
|
|
8602
8720
|
}
|
|
8603
8721
|
|
|
8604
8722
|
/**
|
|
8605
|
-
*
|
|
8606
|
-
*
|
|
8607
|
-
*
|
|
8723
|
+
* 遍历所有形状,生成SVG标记
|
|
8724
|
+
*
|
|
8608
8725
|
* @method toSVG
|
|
8609
8726
|
* @return {string} SVG字符串
|
|
8610
8727
|
*/
|
|
8611
8728
|
toSVG() {
|
|
8612
8729
|
// SVG头部,包含命名空间和画布尺寸
|
|
8613
8730
|
let svg = `<svg width="${this.width}" height="${this.height}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.width} ${this.height}">`;
|
|
8614
|
-
|
|
8731
|
+
|
|
8615
8732
|
// 添加背景色(如果有)
|
|
8616
8733
|
if(this.style && this.style.fill) {
|
|
8617
8734
|
svg += `<rect width="100%" height="100%" fill="${this.style.fill}"/>`;
|
|
8618
8735
|
}
|
|
8619
|
-
|
|
8620
|
-
//
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
// 遍历图层中的所有形状
|
|
8628
|
-
layer.children.each((j, shape) => {
|
|
8629
|
-
if(shape.toSVG) {
|
|
8630
|
-
svg += shape.toSVG();
|
|
8631
|
-
}
|
|
8632
|
-
});
|
|
8633
|
-
|
|
8634
|
-
svg += '</g>';
|
|
8635
|
-
}
|
|
8636
|
-
});
|
|
8637
|
-
}
|
|
8638
|
-
else {
|
|
8639
|
-
// 遍历直接添加的形状(兼容没有图层系统的情况)
|
|
8640
|
-
this.children.each((i, shape) => {
|
|
8641
|
-
if(shape.toSVG) {
|
|
8642
|
-
svg += shape.toSVG();
|
|
8643
|
-
}
|
|
8644
|
-
});
|
|
8645
|
-
}
|
|
8646
|
-
|
|
8736
|
+
|
|
8737
|
+
// 遍历所有直接添加的形状
|
|
8738
|
+
this.children.each((i, shape) => {
|
|
8739
|
+
if(shape.toSVG) {
|
|
8740
|
+
svg += shape.toSVG();
|
|
8741
|
+
}
|
|
8742
|
+
});
|
|
8743
|
+
|
|
8647
8744
|
svg += '</svg>';
|
|
8648
8745
|
return svg;
|
|
8649
8746
|
}
|
|
@@ -8693,7 +8790,7 @@ class jmGraph$1 extends jmControl {
|
|
|
8693
8790
|
// 触发刷新事件
|
|
8694
8791
|
self.emit('update', time);
|
|
8695
8792
|
|
|
8696
|
-
|
|
8793
|
+
// 直接 requestAnimationFrame,无需先 cancel
|
|
8697
8794
|
self.__requestAnimationFrameFunHandler = self.requestAnimationFrame(update);
|
|
8698
8795
|
if(callback) callback();
|
|
8699
8796
|
}
|
|
@@ -8728,22 +8825,11 @@ const shapes = {
|
|
|
8728
8825
|
"star": jmStar
|
|
8729
8826
|
};
|
|
8730
8827
|
|
|
8731
|
-
class
|
|
8828
|
+
class jmGraphImpl extends jmGraph {
|
|
8732
8829
|
constructor(canvas, option, callback) {
|
|
8733
|
-
|
|
8734
|
-
const targetType = new.target;
|
|
8735
|
-
|
|
8736
8830
|
// 合并shapes
|
|
8737
8831
|
option = Object.assign({}, option);
|
|
8738
8832
|
option.shapes = Object.assign(shapes, option.shapes||{});
|
|
8739
|
-
|
|
8740
|
-
//不是用new实例化的话,返回一个promise
|
|
8741
|
-
if(!targetType || !(targetType.prototype instanceof jmGraph$1)) {
|
|
8742
|
-
return new Promise(function(resolve, reject){
|
|
8743
|
-
var g = new jmGraph(canvas, option, callback);
|
|
8744
|
-
if(resolve) resolve(g);
|
|
8745
|
-
});
|
|
8746
|
-
}
|
|
8747
8833
|
|
|
8748
8834
|
if(typeof option == 'function') {
|
|
8749
8835
|
callback = option;
|
|
@@ -8752,17 +8838,8 @@ class jmGraph extends jmGraph$1 {
|
|
|
8752
8838
|
|
|
8753
8839
|
super(canvas, option, callback);
|
|
8754
8840
|
}
|
|
8755
|
-
|
|
8756
|
-
static create(...args) {
|
|
8757
|
-
return createJmGraph(...args);
|
|
8758
|
-
}
|
|
8759
8841
|
}
|
|
8760
8842
|
|
|
8761
|
-
//创建实例
|
|
8762
|
-
const createJmGraph = (...args) => {
|
|
8763
|
-
return new jmGraph(...args);
|
|
8764
|
-
};
|
|
8765
|
-
|
|
8766
8843
|
/**
|
|
8767
8844
|
* 基础样式
|
|
8768
8845
|
*
|
|
@@ -9964,13 +10041,16 @@ class jmAxis extends jmArrowLine {
|
|
|
9964
10041
|
clear() {
|
|
9965
10042
|
this._min = null;
|
|
9966
10043
|
this._max = null;
|
|
10044
|
+
this._width = null; // 清除宽度缓存
|
|
9967
10045
|
this.children.each((i, c) => {
|
|
9968
10046
|
c.remove();
|
|
9969
10047
|
}, true);
|
|
9970
10048
|
// 清空栅格线
|
|
9971
|
-
this.gridLines && this.gridLines.
|
|
9972
|
-
|
|
9973
|
-
|
|
10049
|
+
if (this.gridLines && this.gridLines.length) {
|
|
10050
|
+
for (let i = 0; i < this.gridLines.length; i++) {
|
|
10051
|
+
this.gridLines[i].remove();
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
9974
10054
|
this.labels && this.labels.forEach(label => {
|
|
9975
10055
|
label.remove();
|
|
9976
10056
|
});
|
|
@@ -10182,7 +10262,9 @@ var utils = {
|
|
|
10182
10262
|
}
|
|
10183
10263
|
};
|
|
10184
10264
|
|
|
10185
|
-
|
|
10265
|
+
// 公共常量提取到基类,避免每个子类重复定义
|
|
10266
|
+
const ANIMATION_DATA_THRESHOLD = 100;
|
|
10267
|
+
const DEFAULT_ANIMATION_COUNT = 10;
|
|
10186
10268
|
|
|
10187
10269
|
/**
|
|
10188
10270
|
* 图表系列基类
|
|
@@ -10301,14 +10383,20 @@ class jmSeries extends jmPath {
|
|
|
10301
10383
|
*/
|
|
10302
10384
|
initDataPoint(...args) {
|
|
10303
10385
|
let dataChanged = false;
|
|
10304
|
-
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10386
|
+
if (this.enableAnimate && this.data && this.data.length < ANIMATION_DATA_THRESHOLD) {
|
|
10387
|
+
// 仅在数据引用变化时才做深度比较
|
|
10388
|
+
if (this._lastData !== this.data) {
|
|
10389
|
+
this.lastPoints = this.graph.utils.clone(this.dataPoints, null, true, obj => {
|
|
10390
|
+
if (obj instanceof jmControl) return obj;
|
|
10391
|
+
});
|
|
10392
|
+
this.dataPoints = this.createPoints(...args);
|
|
10393
|
+
dataChanged = utils.arrayIsChange(this.lastPoints, this.dataPoints, (s, t) => {
|
|
10394
|
+
return s.x === t.x && s.y === t.y;
|
|
10395
|
+
});
|
|
10396
|
+
this._lastData = this.data;
|
|
10397
|
+
} else {
|
|
10398
|
+
this.dataPoints = this.createPoints(...args);
|
|
10399
|
+
}
|
|
10312
10400
|
if (dataChanged) {
|
|
10313
10401
|
this.___animateCounter = 0;
|
|
10314
10402
|
}
|
|
@@ -10441,7 +10529,7 @@ class jmSeries extends jmPath {
|
|
|
10441
10529
|
xValue: xv,
|
|
10442
10530
|
xLabel: xv,
|
|
10443
10531
|
points: [],
|
|
10444
|
-
style: this.
|
|
10532
|
+
style: this.style // 共享引用,避免深拷贝;子类如需修改应自行创建副本
|
|
10445
10533
|
};
|
|
10446
10534
|
p.x = xstep * i + this.xAxis.labelStart;
|
|
10447
10535
|
for (let j = 0; j < fields.length; j++) {
|
|
@@ -10607,9 +10695,6 @@ class jmSeries extends jmPath {
|
|
|
10607
10695
|
}
|
|
10608
10696
|
}
|
|
10609
10697
|
|
|
10610
|
-
const ANIMATION_DATA_THRESHOLD$6 = 100;
|
|
10611
|
-
const DEFAULT_ANIMATION_COUNT$6 = 10;
|
|
10612
|
-
|
|
10613
10698
|
/**
|
|
10614
10699
|
* 柱图
|
|
10615
10700
|
*
|
|
@@ -10639,16 +10724,18 @@ class jmBarSeries extends jmSeries {
|
|
|
10639
10724
|
const len = points.length;
|
|
10640
10725
|
if (!len) return;
|
|
10641
10726
|
this.initWidth(len);
|
|
10642
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
10727
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
10643
10728
|
let aniIsEnd = true;
|
|
10644
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
10729
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
10645
10730
|
for (let i = 0; i < len; i++) {
|
|
10646
10731
|
const point = points[i];
|
|
10647
10732
|
if (typeof point.y === 'undefined' || point.y === null) {
|
|
10648
10733
|
continue;
|
|
10649
10734
|
}
|
|
10650
|
-
|
|
10651
|
-
|
|
10735
|
+
const style = Object.assign({}, point.style, {
|
|
10736
|
+
fill: this.getColor(point)
|
|
10737
|
+
});
|
|
10738
|
+
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10652
10739
|
const p1 = {
|
|
10653
10740
|
x: point.x - this.barTotalWidth / 2 + this.barWidth * this.barIndex,
|
|
10654
10741
|
y: this.baseY
|
|
@@ -10783,16 +10870,20 @@ class jmStackBarSeries extends jmBarSeries {
|
|
|
10783
10870
|
let topStartY = this.baseY;
|
|
10784
10871
|
let bottomStartY = this.baseY;
|
|
10785
10872
|
for (let index = 0; index < point.points.length; index++) {
|
|
10786
|
-
const style = this.graph.utils.clone(this.style);
|
|
10787
10873
|
const p = point.points[index];
|
|
10788
|
-
|
|
10789
|
-
|
|
10874
|
+
let fillColor;
|
|
10875
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
10876
|
+
fillColor = this.style.color.call(this, {
|
|
10790
10877
|
index,
|
|
10791
10878
|
point: p
|
|
10792
10879
|
});
|
|
10793
10880
|
} else {
|
|
10794
|
-
|
|
10881
|
+
fillColor = this.graph.getColor(index);
|
|
10795
10882
|
}
|
|
10883
|
+
// 使用浅拷贝而非深拷贝
|
|
10884
|
+
const style = Object.assign({}, this.style, {
|
|
10885
|
+
fill: fillColor
|
|
10886
|
+
});
|
|
10796
10887
|
const sp = this.addShape(this.graph.createPath(null, style));
|
|
10797
10888
|
let startY = topStartY;
|
|
10798
10889
|
if (p.yValue < this.baseYValue) startY = bottomStartY;
|
|
@@ -10901,7 +10992,7 @@ class jmPieSeries extends jmSeries {
|
|
|
10901
10992
|
this.totalValue = 0;
|
|
10902
10993
|
//计算最大值和最小值
|
|
10903
10994
|
if (this.data) {
|
|
10904
|
-
for (
|
|
10995
|
+
for (let i = 0; i < this.data.length; i++) {
|
|
10905
10996
|
const s = this.data[i];
|
|
10906
10997
|
const vy = s[this.field];
|
|
10907
10998
|
if (vy) {
|
|
@@ -10998,15 +11089,20 @@ class jmPieSeries extends jmSeries {
|
|
|
10998
11089
|
yLabel: yv,
|
|
10999
11090
|
step: Math.abs(yv / this.totalValue),
|
|
11000
11091
|
// 每个数值点比
|
|
11001
|
-
style: this.
|
|
11092
|
+
style: this.style,
|
|
11093
|
+
// 共享引用,仅在需要修改时才拷贝
|
|
11002
11094
|
anticlockwise
|
|
11003
11095
|
};
|
|
11004
11096
|
points.push(p);
|
|
11005
11097
|
//p.style.color = this.graph.getColor(index);
|
|
11006
11098
|
if (p.style.color && typeof p.style.color === 'function') {
|
|
11099
|
+
p.style = this.graph.utils.clone(this.style);
|
|
11007
11100
|
p.style.fill = p.style.color.call(this, p);
|
|
11008
11101
|
} else {
|
|
11009
|
-
|
|
11102
|
+
// fill 需要独立,创建轻量样式覆盖
|
|
11103
|
+
p.style = Object.assign({}, this.style, {
|
|
11104
|
+
fill: this.graph.getColor(index)
|
|
11105
|
+
});
|
|
11010
11106
|
}
|
|
11011
11107
|
const start = startAni; // 上一个扇形的结束角度为当前的起始角度
|
|
11012
11108
|
// 计算当前结束角度, 同时也是下一个的起始角度
|
|
@@ -11212,11 +11308,12 @@ class jmRadarSeries extends jmSeries {
|
|
|
11212
11308
|
const rotateStep = Math.PI * 2 / yCount;
|
|
11213
11309
|
|
|
11214
11310
|
// 清空除了一个默认外的所有Y轴
|
|
11215
|
-
|
|
11216
|
-
|
|
11311
|
+
const yAxisKeys = Object.keys(this.graph.yAxises || {});
|
|
11312
|
+
for (let k = 0; k < yAxisKeys.length; k++) {
|
|
11313
|
+
const axis = this.graph.yAxises[yAxisKeys[k]];
|
|
11217
11314
|
if (!axis || axis === this.yAxis) continue;
|
|
11218
11315
|
axis.remove();
|
|
11219
|
-
delete this.graph.yAxises[
|
|
11316
|
+
delete this.graph.yAxises[yAxisKeys[k]];
|
|
11220
11317
|
}
|
|
11221
11318
|
for (let index = 0; index < yCount; index++) {
|
|
11222
11319
|
if (!this.field[index]) continue;
|
|
@@ -11363,21 +11460,30 @@ class jmRadarSeries extends jmSeries {
|
|
|
11363
11460
|
const points = [];
|
|
11364
11461
|
for (var i = 0; i < this.data.length; i++) {
|
|
11365
11462
|
const s = this.data[i];
|
|
11366
|
-
|
|
11367
|
-
if (style.color && typeof style.color === 'function') {
|
|
11368
|
-
|
|
11463
|
+
let strokeColor;
|
|
11464
|
+
if (this.style.color && typeof this.style.color === 'function') {
|
|
11465
|
+
strokeColor = this.style.color.call(this, {
|
|
11369
11466
|
data: s,
|
|
11370
11467
|
index: i
|
|
11371
11468
|
});
|
|
11372
11469
|
} else {
|
|
11373
|
-
|
|
11470
|
+
strokeColor = this.graph.getColor(i);
|
|
11374
11471
|
}
|
|
11375
|
-
|
|
11376
|
-
|
|
11472
|
+
let fillColor;
|
|
11473
|
+
if (typeof this.style.fill === 'function') {
|
|
11474
|
+
fillColor = this.style.fill.call(this, {
|
|
11475
|
+
...this.style,
|
|
11476
|
+
stroke: strokeColor
|
|
11477
|
+
});
|
|
11377
11478
|
} else {
|
|
11378
|
-
const color = this.graph.utils.hexToRGBA(
|
|
11379
|
-
|
|
11479
|
+
const color = this.graph.utils.hexToRGBA(strokeColor);
|
|
11480
|
+
fillColor = `rgba(${color.r},${color.g},${color.b}, 0.2)`;
|
|
11380
11481
|
}
|
|
11482
|
+
// 使用浅拷贝而非深拷贝
|
|
11483
|
+
const style = Object.assign({}, this.style, {
|
|
11484
|
+
stroke: strokeColor,
|
|
11485
|
+
fill: fillColor
|
|
11486
|
+
});
|
|
11381
11487
|
const shapePoints = [];
|
|
11382
11488
|
for (const axis of this.axises) {
|
|
11383
11489
|
if (!axis || !axis.field) continue;
|
|
@@ -11471,9 +11577,6 @@ jmRadarSeries.prototype.createLegend = function (point) {
|
|
|
11471
11577
|
});
|
|
11472
11578
|
};
|
|
11473
11579
|
|
|
11474
|
-
const ANIMATION_DATA_THRESHOLD$5 = 100;
|
|
11475
|
-
const DEFAULT_ANIMATION_COUNT$5 = 10;
|
|
11476
|
-
|
|
11477
11580
|
/**
|
|
11478
11581
|
* 线图
|
|
11479
11582
|
*
|
|
@@ -11505,9 +11608,9 @@ class jmLineSeries extends jmSeries {
|
|
|
11505
11608
|
if (!len) return;
|
|
11506
11609
|
this.style.stroke = this.style.color;
|
|
11507
11610
|
this.style.item.stroke = this.style.color;
|
|
11508
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
11611
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
11509
11612
|
let shapePoints = [];
|
|
11510
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
11613
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11511
11614
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11512
11615
|
for (let i = 0; i < len; i++) {
|
|
11513
11616
|
const p = points[i];
|
|
@@ -11890,7 +11993,6 @@ class jmCandlestickSeries extends jmSeries {
|
|
|
11890
11993
|
console.warn('K线图数据不完整,需要4个字段(开盘、收盘、最高、最低)');
|
|
11891
11994
|
continue;
|
|
11892
11995
|
}
|
|
11893
|
-
const sp = this.addShape(this.graph.createPath([], p.style));
|
|
11894
11996
|
const bl = {
|
|
11895
11997
|
x: p.x - w,
|
|
11896
11998
|
y: p.points[0].y
|
|
@@ -11909,14 +12011,18 @@ class jmCandlestickSeries extends jmSeries {
|
|
|
11909
12011
|
};
|
|
11910
12012
|
let tm = p.points[1];
|
|
11911
12013
|
let bm = p.points[0];
|
|
11912
|
-
|
|
12014
|
+
|
|
12015
|
+
// 使用浅拷贝避免污染共享引用
|
|
12016
|
+
const style = Object.assign({}, p.style);
|
|
12017
|
+
style.stroke = style.fill = style.masculineColor || 'red';
|
|
11913
12018
|
if (p.points[0].yValue > p.points[1].yValue) {
|
|
11914
|
-
|
|
12019
|
+
style.stroke = style.fill = style.negativeColor || 'green';
|
|
11915
12020
|
bl.y = br.y = p.points[1].y;
|
|
11916
12021
|
tl.y = tr.y = p.points[0].y;
|
|
11917
12022
|
tm = p.points[0];
|
|
11918
12023
|
bm = p.points[1];
|
|
11919
12024
|
}
|
|
12025
|
+
const sp = this.addShape(this.graph.createPath([], style));
|
|
11920
12026
|
sp.points.push(p.points[2], tm, tl, bl, bm, p.points[3], bm, br, tr, tm, p.points[2]);
|
|
11921
12027
|
this.emit('onPointCreated', p);
|
|
11922
12028
|
}
|
|
@@ -11941,9 +12047,6 @@ class jmCandlestickSeries extends jmSeries {
|
|
|
11941
12047
|
}
|
|
11942
12048
|
}
|
|
11943
12049
|
|
|
11944
|
-
const ANIMATION_DATA_THRESHOLD$4 = 100;
|
|
11945
|
-
const DEFAULT_ANIMATION_COUNT$4 = 10;
|
|
11946
|
-
|
|
11947
12050
|
/**
|
|
11948
12051
|
* 散点图
|
|
11949
12052
|
*
|
|
@@ -11975,8 +12078,8 @@ class jmScatterSeries extends jmSeries {
|
|
|
11975
12078
|
if (!len) return;
|
|
11976
12079
|
this.style.stroke = this.style.color;
|
|
11977
12080
|
this.style.item.stroke = this.style.color;
|
|
11978
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
11979
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12081
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12082
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
11980
12083
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
11981
12084
|
for (let i = 0; i < len; i++) {
|
|
11982
12085
|
const p = points[i];
|
|
@@ -12049,9 +12152,6 @@ class jmScatterSeries extends jmSeries {
|
|
|
12049
12152
|
}
|
|
12050
12153
|
}
|
|
12051
12154
|
|
|
12052
|
-
const ANIMATION_DATA_THRESHOLD$3 = 100;
|
|
12053
|
-
const DEFAULT_ANIMATION_COUNT$3 = 10;
|
|
12054
|
-
|
|
12055
12155
|
/**
|
|
12056
12156
|
* 气泡图
|
|
12057
12157
|
*
|
|
@@ -12083,8 +12183,8 @@ class jmBubbleSeries extends jmSeries {
|
|
|
12083
12183
|
if (!len) return;
|
|
12084
12184
|
this.style.stroke = this.style.color;
|
|
12085
12185
|
this.style.item.stroke = this.style.color;
|
|
12086
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
12087
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12186
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12187
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12088
12188
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12089
12189
|
for (let i = 0; i < len; i++) {
|
|
12090
12190
|
const p = points[i];
|
|
@@ -12163,9 +12263,6 @@ class jmBubbleSeries extends jmSeries {
|
|
|
12163
12263
|
}
|
|
12164
12264
|
}
|
|
12165
12265
|
|
|
12166
|
-
const ANIMATION_DATA_THRESHOLD$2 = 100;
|
|
12167
|
-
const DEFAULT_ANIMATION_COUNT$2 = 10;
|
|
12168
|
-
|
|
12169
12266
|
/**
|
|
12170
12267
|
* 热力图
|
|
12171
12268
|
*
|
|
@@ -12208,8 +12305,8 @@ class jmHeatmapSeries extends jmSeries {
|
|
|
12208
12305
|
}
|
|
12209
12306
|
this.minValue = minValue;
|
|
12210
12307
|
this.maxValue = maxValue;
|
|
12211
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD
|
|
12212
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT
|
|
12308
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
12309
|
+
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT;
|
|
12213
12310
|
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12214
12311
|
for (let i = 0; i < len; i++) {
|
|
12215
12312
|
const p = points[i];
|
|
@@ -12576,20 +12673,15 @@ class jmGaugeSeries extends jmSeries {
|
|
|
12576
12673
|
}
|
|
12577
12674
|
}
|
|
12578
12675
|
|
|
12579
|
-
const ANIMATION_DATA_THRESHOLD$1 = 100;
|
|
12580
|
-
const DEFAULT_ANIMATION_COUNT$1 = 10;
|
|
12581
|
-
|
|
12582
12676
|
/**
|
|
12583
12677
|
* 面积图
|
|
12678
|
+
* 继承自折线图,默认启用区域填充
|
|
12584
12679
|
*
|
|
12585
12680
|
* @class jmAreaSeries
|
|
12586
12681
|
* @module jmChart
|
|
12587
|
-
* @
|
|
12588
|
-
* @param {array} mappings 图形字段映射
|
|
12589
|
-
* @param {style} style 样式
|
|
12682
|
+
* @extends jmLineSeries
|
|
12590
12683
|
*/
|
|
12591
|
-
|
|
12592
|
-
class jmAreaSeries extends jmSeries {
|
|
12684
|
+
class jmAreaSeries extends jmLineSeries {
|
|
12593
12685
|
constructor(options) {
|
|
12594
12686
|
options.style = options.style || options.graph.style.area;
|
|
12595
12687
|
super(options);
|
|
@@ -12597,193 +12689,13 @@ class jmAreaSeries extends jmSeries {
|
|
|
12597
12689
|
this.style.area = true;
|
|
12598
12690
|
}
|
|
12599
12691
|
|
|
12600
|
-
/**
|
|
12601
|
-
* 初始化面积图
|
|
12602
|
-
*
|
|
12603
|
-
* @method init
|
|
12604
|
-
* @for jmAreaSeries
|
|
12605
|
-
*/
|
|
12606
|
-
init() {
|
|
12607
|
-
const {
|
|
12608
|
-
points,
|
|
12609
|
-
dataChanged
|
|
12610
|
-
} = this.initDataPoint();
|
|
12611
|
-
const len = points.length;
|
|
12612
|
-
if (!len) return;
|
|
12613
|
-
this.style.stroke = this.style.color;
|
|
12614
|
-
this.style.item.stroke = this.style.color;
|
|
12615
|
-
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD$1;
|
|
12616
|
-
let shapePoints = [];
|
|
12617
|
-
const aniCount = this.style.aniCount || DEFAULT_ANIMATION_COUNT$1;
|
|
12618
|
-
const aniStep = Math.floor(len / aniCount) || 1;
|
|
12619
|
-
for (let i = 0; i < len; i++) {
|
|
12620
|
-
const p = points[i];
|
|
12621
|
-
if (typeof p.y === 'undefined' || p.y === null) {
|
|
12622
|
-
continue;
|
|
12623
|
-
}
|
|
12624
|
-
if (isRunningAni && i > this.___animateCounter) {
|
|
12625
|
-
break;
|
|
12626
|
-
}
|
|
12627
|
-
if (this.style.showItem) {
|
|
12628
|
-
this.createPointItem(p);
|
|
12629
|
-
}
|
|
12630
|
-
if (this.style.curve) {
|
|
12631
|
-
shapePoints = this.createCurePoints(shapePoints, p);
|
|
12632
|
-
} else if (this.style.lineType === 'dotted') {
|
|
12633
|
-
shapePoints = this.createDotLine(shapePoints, p);
|
|
12634
|
-
}
|
|
12635
|
-
shapePoints.push(p);
|
|
12636
|
-
this.createItemLabel(p);
|
|
12637
|
-
this.emit('onPointCreated', p);
|
|
12638
|
-
}
|
|
12639
|
-
if (this.___animateCounter >= len - 1) {
|
|
12640
|
-
this.___animateCounter = 0;
|
|
12641
|
-
} else if (isRunningAni) {
|
|
12642
|
-
this.___animateCounter += aniStep;
|
|
12643
|
-
this.graph.utils.requestAnimationFrame(() => {
|
|
12644
|
-
this.needUpdate = true;
|
|
12645
|
-
});
|
|
12646
|
-
}
|
|
12647
|
-
this.points = shapePoints;
|
|
12648
|
-
this.createArea(shapePoints);
|
|
12649
|
-
}
|
|
12650
|
-
|
|
12651
|
-
/**
|
|
12652
|
-
* 生成点的小圆圈
|
|
12653
|
-
*
|
|
12654
|
-
* @method createPointItem
|
|
12655
|
-
* @for jmAreaSeries
|
|
12656
|
-
* @param {object} p 数据点
|
|
12657
|
-
*/
|
|
12658
|
-
createPointItem(p) {
|
|
12659
|
-
const pointShape = this.graph.createShape('circle', {
|
|
12660
|
-
style: this.style.item,
|
|
12661
|
-
center: p,
|
|
12662
|
-
radius: this.style.radius || 3
|
|
12663
|
-
});
|
|
12664
|
-
pointShape.zIndex = (pointShape.style.zIndex || 1) + 1;
|
|
12665
|
-
return this.addShape(pointShape);
|
|
12666
|
-
}
|
|
12667
|
-
|
|
12668
|
-
/**
|
|
12669
|
-
* 创建曲线点
|
|
12670
|
-
*
|
|
12671
|
-
* @method createCurePoints
|
|
12672
|
-
* @for jmAreaSeries
|
|
12673
|
-
* @param {array} shapePoints 形状点数组
|
|
12674
|
-
* @param {object} p 当前点
|
|
12675
|
-
* @return {array} 新的形状点数组
|
|
12676
|
-
*/
|
|
12677
|
-
createCurePoints(shapePoints, p) {
|
|
12678
|
-
const startPoint = shapePoints[shapePoints.length - 1];
|
|
12679
|
-
if (!startPoint || !p) return shapePoints;
|
|
12680
|
-
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) {
|
|
12681
|
-
return shapePoints;
|
|
12682
|
-
}
|
|
12683
|
-
const p1 = {
|
|
12684
|
-
x: startPoint.x + (p.x - startPoint.x) / 5,
|
|
12685
|
-
y: startPoint.y
|
|
12686
|
-
};
|
|
12687
|
-
const p2 = {
|
|
12688
|
-
x: startPoint.x + (p.x - startPoint.x) / 2,
|
|
12689
|
-
y: p.y - (p.y - startPoint.y) / 2
|
|
12690
|
-
};
|
|
12691
|
-
const p3 = {
|
|
12692
|
-
x: p.x - (p.x - startPoint.x) / 5,
|
|
12693
|
-
y: p.y
|
|
12694
|
-
};
|
|
12695
|
-
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
12696
|
-
this.__bezier.cpoints = [startPoint, p1, p2, p3, p];
|
|
12697
|
-
const bzpoints = this.__bezier.initPoints();
|
|
12698
|
-
if (bzpoints && bzpoints.length) {
|
|
12699
|
-
shapePoints = shapePoints.concat(bzpoints);
|
|
12700
|
-
}
|
|
12701
|
-
return shapePoints;
|
|
12702
|
-
}
|
|
12703
|
-
|
|
12704
|
-
/**
|
|
12705
|
-
* 创建虚线点
|
|
12706
|
-
*
|
|
12707
|
-
* @method createDotLine
|
|
12708
|
-
* @for jmAreaSeries
|
|
12709
|
-
* @param {array} shapePoints 形状点数组
|
|
12710
|
-
* @param {object} p 当前点
|
|
12711
|
-
* @return {array} 新的形状点数组
|
|
12712
|
-
*/
|
|
12713
|
-
createDotLine(shapePoints, p) {
|
|
12714
|
-
const startPoint = shapePoints[shapePoints.length - 1];
|
|
12715
|
-
if (!startPoint || !p) return shapePoints;
|
|
12716
|
-
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) {
|
|
12717
|
-
return shapePoints;
|
|
12718
|
-
}
|
|
12719
|
-
this.__line = this.__line || this.graph.createShape('line', {
|
|
12720
|
-
style: this.style
|
|
12721
|
-
});
|
|
12722
|
-
this.__line.start = startPoint;
|
|
12723
|
-
this.__line.end = p;
|
|
12724
|
-
const dots = this.__line.initPoints();
|
|
12725
|
-
if (dots && dots.length) {
|
|
12726
|
-
shapePoints = shapePoints.concat(dots);
|
|
12727
|
-
}
|
|
12728
|
-
return shapePoints;
|
|
12729
|
-
}
|
|
12730
|
-
|
|
12731
|
-
/**
|
|
12732
|
-
* 生成面积效果
|
|
12733
|
-
*
|
|
12734
|
-
* @method createArea
|
|
12735
|
-
* @for jmAreaSeries
|
|
12736
|
-
* @param {array} points 数据点数组
|
|
12737
|
-
* @param {boolean} needClosePoint 是否需要闭合点
|
|
12738
|
-
*/
|
|
12739
|
-
createArea(points, needClosePoint = true) {
|
|
12740
|
-
// 有指定绘制区域效果才展示
|
|
12741
|
-
if (!this.style.area || points.length < 2) return;
|
|
12742
|
-
const start = points[0];
|
|
12743
|
-
const end = points[points.length - 1];
|
|
12744
|
-
const style = this.graph.utils.clone(this.style.area, {}, true);
|
|
12745
|
-
// 连框颜色如果没指定,就透明
|
|
12746
|
-
style.stroke = style.stroke || 'transparent';
|
|
12747
|
-
if (!style.fill) {
|
|
12748
|
-
const color = this.graph.utils.hexToRGBA(this.style.stroke);
|
|
12749
|
-
style.fill = `linear-gradient(50% 0 50% 100%,
|
|
12750
|
-
rgba(${color.r},${color.g},${color.b}, 0) 1,
|
|
12751
|
-
rgba(${color.r},${color.g},${color.b}, 0.1) 0.7,
|
|
12752
|
-
rgba(${color.r},${color.g},${color.b}, 0.3) 0)`;
|
|
12753
|
-
} else if (typeof style.fill === 'function') {
|
|
12754
|
-
style.fill = style.fill.call(this, style);
|
|
12755
|
-
}
|
|
12756
|
-
const area = this.graph.createShape('path', {
|
|
12757
|
-
points: this.graph.utils.clone(points, true),
|
|
12758
|
-
style,
|
|
12759
|
-
width: this.graph.chartArea.width,
|
|
12760
|
-
height: this.graph.chartArea.height
|
|
12761
|
-
});
|
|
12762
|
-
|
|
12763
|
-
// 在点集合前后加上落地到X轴的点就可以组成一个封闭的图形area
|
|
12764
|
-
if (needClosePoint) {
|
|
12765
|
-
area.points.unshift({
|
|
12766
|
-
x: start.x,
|
|
12767
|
-
y: this.baseY
|
|
12768
|
-
});
|
|
12769
|
-
area.points.push({
|
|
12770
|
-
x: end.x,
|
|
12771
|
-
y: this.baseY
|
|
12772
|
-
});
|
|
12773
|
-
}
|
|
12774
|
-
this.addShape(area);
|
|
12775
|
-
}
|
|
12776
|
-
|
|
12777
12692
|
/**
|
|
12778
12693
|
* 生成图例
|
|
12779
|
-
*
|
|
12780
|
-
* @method createLegend
|
|
12781
|
-
* @for jmAreaSeries
|
|
12782
12694
|
*/
|
|
12783
12695
|
createLegend() {
|
|
12784
|
-
// 生成图例前的图标
|
|
12785
12696
|
var style = this.graph.utils.clone(this.style);
|
|
12786
12697
|
style.stroke = style.color;
|
|
12698
|
+
style.fill = style.color;
|
|
12787
12699
|
var shape = this.graph.createShape('path', {
|
|
12788
12700
|
style: style
|
|
12789
12701
|
});
|
|
@@ -12805,8 +12717,7 @@ class jmAreaSeries extends jmSeries {
|
|
|
12805
12717
|
y: 0
|
|
12806
12718
|
};
|
|
12807
12719
|
this.__bezier = this.__bezier || this.graph.createShape('bezier');
|
|
12808
|
-
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12809
|
-
|
|
12720
|
+
this.__bezier.cpoints = [p1, p2, p3, p4];
|
|
12810
12721
|
shape.points = this.__bezier.initPoints();
|
|
12811
12722
|
} else {
|
|
12812
12723
|
shape.points = [{
|
|
@@ -12821,8 +12732,6 @@ class jmAreaSeries extends jmSeries {
|
|
|
12821
12732
|
}
|
|
12822
12733
|
}
|
|
12823
12734
|
|
|
12824
|
-
const ANIMATION_DATA_THRESHOLD = 100;
|
|
12825
|
-
const DEFAULT_ANIMATION_COUNT = 10;
|
|
12826
12735
|
class jmWaterfallSeries extends jmSeries {
|
|
12827
12736
|
constructor(options) {
|
|
12828
12737
|
options.style = options.style || options.graph.style.waterfall;
|
|
@@ -14255,12 +14164,11 @@ class jmMarkLineManager {
|
|
|
14255
14164
|
if (chart.style.markLine.longtap) {
|
|
14256
14165
|
longtap = 1;
|
|
14257
14166
|
longtapHandler && graph.utils.cancelAnimationFrame(longtapHandler);
|
|
14258
|
-
|
|
14167
|
+
const tapStartTime = Date.now();
|
|
14259
14168
|
const reqFun = () => {
|
|
14260
|
-
const elapsed = Date.now() - tapStartTime;
|
|
14261
14169
|
if (longtap === 1 || longtap === 2) {
|
|
14262
14170
|
// 如果还未过一定时间,则继续等待
|
|
14263
|
-
if (
|
|
14171
|
+
if (Date.now() - tapStartTime < 500) {
|
|
14264
14172
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14265
14173
|
return;
|
|
14266
14174
|
}
|
|
@@ -14271,9 +14179,6 @@ class jmMarkLineManager {
|
|
|
14271
14179
|
};
|
|
14272
14180
|
// 如果一定时间后还没有取消,则表示长按了
|
|
14273
14181
|
longtapHandler = graph.utils.requestAnimationFrame(reqFun);
|
|
14274
|
-
|
|
14275
|
-
//args.event.stopPropagation();
|
|
14276
|
-
//args.event.preventDefault();// 阻止默认行为
|
|
14277
14182
|
} else {
|
|
14278
14183
|
this.startMove(args);
|
|
14279
14184
|
}
|
|
@@ -14380,7 +14285,7 @@ class jmMarkLineManager {
|
|
|
14380
14285
|
* @module jmChart
|
|
14381
14286
|
* @param {element} container 图表容器
|
|
14382
14287
|
*/
|
|
14383
|
-
class jmChart extends
|
|
14288
|
+
class jmChart extends jmGraphImpl {
|
|
14384
14289
|
constructor(container, options) {
|
|
14385
14290
|
options = options || {};
|
|
14386
14291
|
const enableAnimate = !!options.enableAnimate;
|
|
@@ -14474,25 +14379,27 @@ class jmChart extends jmGraph {
|
|
|
14474
14379
|
|
|
14475
14380
|
// 绑定点击事件
|
|
14476
14381
|
this.on('click', args => {
|
|
14477
|
-
if (this.option.onClick)
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14382
|
+
if (!this.option.onClick) return;
|
|
14383
|
+
// 找到点击位置的数据点
|
|
14384
|
+
let closestPoint = null;
|
|
14385
|
+
let minDistance = 20; // 20px 范围,同时作为阈值,无需再比较小于阈值
|
|
14386
|
+
|
|
14387
|
+
this.series.each((i, serie) => {
|
|
14388
|
+
if (!serie.dataPoints) return;
|
|
14389
|
+
const points = serie.dataPoints;
|
|
14390
|
+
for (let j = 0, len = points.length; j < len; j++) {
|
|
14391
|
+
const point = points[j];
|
|
14392
|
+
const dx = args.position.x - point.x;
|
|
14393
|
+
const dy = args.position.y - point.y;
|
|
14394
|
+
const distance = dx * dx + dy * dy; // 避免开方,直接比较平方
|
|
14395
|
+
if (distance < minDistance * minDistance) {
|
|
14396
|
+
minDistance = distance;
|
|
14397
|
+
closestPoint = point;
|
|
14491
14398
|
}
|
|
14492
|
-
});
|
|
14493
|
-
if (closestPoint) {
|
|
14494
|
-
this.option.onClick(closestPoint);
|
|
14495
14399
|
}
|
|
14400
|
+
});
|
|
14401
|
+
if (closestPoint) {
|
|
14402
|
+
this.option.onClick(closestPoint);
|
|
14496
14403
|
}
|
|
14497
14404
|
});
|
|
14498
14405
|
}
|
|
@@ -14522,7 +14429,7 @@ class jmChart extends jmGraph {
|
|
|
14522
14429
|
options = this.utils.clone(options, {
|
|
14523
14430
|
autoRefresh: true
|
|
14524
14431
|
}, true);
|
|
14525
|
-
this.touchGraph = new
|
|
14432
|
+
this.touchGraph = new jmGraphImpl(cn, options);
|
|
14526
14433
|
this.touchGraph.chartGraph = this;
|
|
14527
14434
|
this.on('propertyChange', (name, args) => {
|
|
14528
14435
|
if (['width', 'height'].includes(name)) {
|
|
@@ -14562,8 +14469,9 @@ class jmChart extends jmGraph {
|
|
|
14562
14469
|
delete this.xAxis;
|
|
14563
14470
|
}
|
|
14564
14471
|
if (this.yAxises) {
|
|
14565
|
-
|
|
14566
|
-
|
|
14472
|
+
const keys = Object.keys(this.yAxises);
|
|
14473
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14474
|
+
this.yAxises[keys[k]].remove();
|
|
14567
14475
|
}
|
|
14568
14476
|
delete this.yAxises;
|
|
14569
14477
|
}
|
|
@@ -14575,18 +14483,9 @@ class jmChart extends jmGraph {
|
|
|
14575
14483
|
* @param {int} index 颜色索引
|
|
14576
14484
|
*/
|
|
14577
14485
|
getColor(index) {
|
|
14578
|
-
const
|
|
14579
|
-
|
|
14580
|
-
|
|
14581
|
-
}
|
|
14582
|
-
let color;
|
|
14583
|
-
if (index >= this.style.chartColors.length) {
|
|
14584
|
-
color = this.style.chartColors[index % this.style.chartColors.length];
|
|
14585
|
-
} else {
|
|
14586
|
-
color = this.style.chartColors[index];
|
|
14587
|
-
}
|
|
14588
|
-
this._cache.set(cacheKey, color);
|
|
14589
|
-
return color;
|
|
14486
|
+
const colors = this.style.chartColors;
|
|
14487
|
+
const colorIndex = index % colors.length;
|
|
14488
|
+
return colors[colorIndex];
|
|
14590
14489
|
}
|
|
14591
14490
|
|
|
14592
14491
|
/**
|
|
@@ -14604,40 +14503,43 @@ class jmChart extends jmGraph {
|
|
|
14604
14503
|
this.xAxis.clear();
|
|
14605
14504
|
}
|
|
14606
14505
|
if (this.yAxises) {
|
|
14607
|
-
|
|
14608
|
-
|
|
14506
|
+
const keys = Object.keys(this.yAxises);
|
|
14507
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14508
|
+
this.yAxises[keys[k]].clear();
|
|
14609
14509
|
}
|
|
14610
14510
|
}
|
|
14611
14511
|
this.barSeriesCount = 0;
|
|
14512
|
+
// 合并两次 series 遍历为一次,减少遍历开销
|
|
14513
|
+
const seriesInited = [];
|
|
14612
14514
|
this.series.each((i, serie) => {
|
|
14613
14515
|
if (!serie.style.color) {
|
|
14614
14516
|
serie.style.color = serie.graph.getColor(i);
|
|
14615
14517
|
}
|
|
14616
|
-
if (serie
|
|
14617
|
-
if (serie
|
|
14518
|
+
if (serie instanceof jmBarSeries) {
|
|
14519
|
+
if (serie.graph.style.layout != 'inside') {
|
|
14618
14520
|
serie.graph.style.layout = 'inside';
|
|
14619
14521
|
}
|
|
14620
|
-
}
|
|
14621
|
-
if (serie instanceof jmBarSeries) {
|
|
14622
14522
|
serie.barIndex = serie.graph.barSeriesCount;
|
|
14623
14523
|
serie.graph.barSeriesCount++;
|
|
14624
14524
|
}
|
|
14625
14525
|
serie.reset();
|
|
14526
|
+
seriesInited.push(serie);
|
|
14626
14527
|
});
|
|
14627
14528
|
if (this.legend) {
|
|
14628
14529
|
this.legend.reset();
|
|
14629
14530
|
}
|
|
14630
14531
|
if (this.yAxises) {
|
|
14631
|
-
|
|
14632
|
-
|
|
14532
|
+
const keys = Object.keys(this.yAxises);
|
|
14533
|
+
for (let k = 0; k < keys.length; k++) {
|
|
14534
|
+
this.yAxises[keys[k]].reset();
|
|
14633
14535
|
}
|
|
14634
14536
|
}
|
|
14635
14537
|
if (this.xAxis) {
|
|
14636
14538
|
this.xAxis.reset();
|
|
14637
14539
|
}
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
}
|
|
14540
|
+
for (let i = 0; i < seriesInited.length; i++) {
|
|
14541
|
+
seriesInited[i].init && seriesInited[i].init();
|
|
14542
|
+
}
|
|
14641
14543
|
}
|
|
14642
14544
|
|
|
14643
14545
|
/**
|
|
@@ -14815,14 +14717,35 @@ var vchart = {
|
|
|
14815
14717
|
this.initChart();
|
|
14816
14718
|
},
|
|
14817
14719
|
updated() {
|
|
14818
|
-
this.
|
|
14720
|
+
this.refresh();
|
|
14819
14721
|
},
|
|
14820
14722
|
destroyed() {
|
|
14821
14723
|
this.chartInstance && this.chartInstance.destroy();
|
|
14822
14724
|
},
|
|
14823
14725
|
watch: {
|
|
14824
|
-
chartData:
|
|
14825
|
-
|
|
14726
|
+
chartData: {
|
|
14727
|
+
handler: function (newData, oldData) {
|
|
14728
|
+
this.refresh();
|
|
14729
|
+
},
|
|
14730
|
+
deep: false // 仅监听引用变化,由使用者显式替换数组时触发
|
|
14731
|
+
},
|
|
14732
|
+
chartOptions: {
|
|
14733
|
+
handler: function (newOptions, oldOptions) {
|
|
14734
|
+
// 配置变化时需要重建图表
|
|
14735
|
+
if (this.chartInstance) {
|
|
14736
|
+
this.chartInstance.destroy();
|
|
14737
|
+
this.chartInstance = null;
|
|
14738
|
+
}
|
|
14739
|
+
this.option = Object.assign({
|
|
14740
|
+
enableAnimate: false,
|
|
14741
|
+
legendPosition: 'top',
|
|
14742
|
+
legendVisible: true,
|
|
14743
|
+
width: this.width,
|
|
14744
|
+
height: this.height
|
|
14745
|
+
}, newOptions);
|
|
14746
|
+
this.$nextTick(() => this.initChart());
|
|
14747
|
+
},
|
|
14748
|
+
deep: false
|
|
14826
14749
|
},
|
|
14827
14750
|
width: function (newWidth, oldWidth) {
|
|
14828
14751
|
if (!this.chartInstance) return;
|