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