jmgraph 3.1.96 → 3.1.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +105 -140
- package/dist/jmgraph.min.js +1 -1
- package/package.json +1 -1
- package/src/core/jmControl.js +59 -94
- package/src/core/jmGraph.js +6 -6
- package/src/core/jmProperty.js +18 -0
- package/src/core/jmUtils.js +6 -14
package/src/core/jmControl.js
CHANGED
|
@@ -5,6 +5,30 @@ import {jmGradient} from "./jmGradient.js";
|
|
|
5
5
|
import {jmShadow} from "./jmShadow.js";
|
|
6
6
|
import {jmProperty} from "./jmProperty.js";
|
|
7
7
|
|
|
8
|
+
//样式名称,也当做白名单使用
|
|
9
|
+
const jmStyleMap = {
|
|
10
|
+
'fill':'fillStyle',
|
|
11
|
+
'stroke':'strokeStyle',
|
|
12
|
+
'shadow.blur':'shadowBlur',
|
|
13
|
+
'shadow.x':'shadowOffsetX',
|
|
14
|
+
'shadow.y':'shadowOffsetY',
|
|
15
|
+
'shadow.color':'shadowColor',
|
|
16
|
+
'lineWidth' : 'lineWidth',
|
|
17
|
+
'miterLimit': 'miterLimit',
|
|
18
|
+
'fillStyle' : 'fillStyle',
|
|
19
|
+
'strokeStyle' : 'strokeStyle',
|
|
20
|
+
'font' : 'font',
|
|
21
|
+
'opacity' : 'globalAlpha',
|
|
22
|
+
'textAlign' : 'textAlign',
|
|
23
|
+
'textBaseline' : 'textBaseline',
|
|
24
|
+
'shadowBlur' : 'shadowBlur',
|
|
25
|
+
'shadowOffsetX' : 'shadowOffsetX',
|
|
26
|
+
'shadowOffsetY' : 'shadowOffsetY',
|
|
27
|
+
'shadowColor' : 'shadowColor',
|
|
28
|
+
'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
|
|
29
|
+
'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
|
|
30
|
+
};
|
|
31
|
+
|
|
8
32
|
/**
|
|
9
33
|
* 控件基础对象
|
|
10
34
|
* 控件的基础属性和方法
|
|
@@ -31,30 +55,6 @@ export default class jmControl extends jmProperty {
|
|
|
31
55
|
this.zIndex = params.zIndex || 0;
|
|
32
56
|
this.interactive = typeof params.interactive == 'undefined'? true : params.interactive;
|
|
33
57
|
|
|
34
|
-
//样式名称,也当做白名单使用
|
|
35
|
-
this.jmStyleMap = {
|
|
36
|
-
'fill':'fillStyle',
|
|
37
|
-
'stroke':'strokeStyle',
|
|
38
|
-
'shadow.blur':'shadowBlur',
|
|
39
|
-
'shadow.x':'shadowOffsetX',
|
|
40
|
-
'shadow.y':'shadowOffsetY',
|
|
41
|
-
'shadow.color':'shadowColor',
|
|
42
|
-
'lineWidth' : 'lineWidth',
|
|
43
|
-
'miterLimit': 'miterLimit',
|
|
44
|
-
'fillStyle' : 'fillStyle',
|
|
45
|
-
'strokeStyle' : 'strokeStyle',
|
|
46
|
-
'font' : 'font',
|
|
47
|
-
'opacity' : 'globalAlpha',
|
|
48
|
-
'textAlign' : 'textAlign',
|
|
49
|
-
'textBaseline' : 'textBaseline',
|
|
50
|
-
'shadowBlur' : 'shadowBlur',
|
|
51
|
-
'shadowOffsetX' : 'shadowOffsetX',
|
|
52
|
-
'shadowOffsetY' : 'shadowOffsetY',
|
|
53
|
-
'shadowColor' : 'shadowColor',
|
|
54
|
-
'lineJoin': 'lineJoin',//线交汇处的形状,miter(默认,尖角),bevel(斜角),round(圆角)
|
|
55
|
-
'lineCap':'lineCap' //线条终端点,butt(默认,平),round(圆),square(方)
|
|
56
|
-
};
|
|
57
|
-
|
|
58
58
|
this.initializing();
|
|
59
59
|
|
|
60
60
|
this.on = this.bind;
|
|
@@ -352,120 +352,93 @@ export default class jmControl extends jmProperty {
|
|
|
352
352
|
* @param {string} mpkey 样式名称在映射中的key(例如:shadow.blur为模糊值)
|
|
353
353
|
*/
|
|
354
354
|
let __setStyle = (style, name, mpkey) => {
|
|
355
|
-
|
|
356
|
-
if(style) {
|
|
357
|
-
|
|
355
|
+
|
|
356
|
+
if(style) {
|
|
357
|
+
let styleValue = style;
|
|
358
|
+
if(typeof styleValue === 'function') {
|
|
358
359
|
try {
|
|
359
|
-
|
|
360
|
+
styleValue = styleValue.call(this);
|
|
360
361
|
}
|
|
361
362
|
catch(e) {
|
|
362
363
|
console.warn(e);
|
|
363
364
|
return;
|
|
364
365
|
}
|
|
365
366
|
}
|
|
366
|
-
let t = typeof
|
|
367
|
-
let mpname =
|
|
367
|
+
let t = typeof styleValue;
|
|
368
|
+
let mpname = jmStyleMap[mpkey || name];
|
|
368
369
|
|
|
369
370
|
//如果为渐变对象
|
|
370
|
-
if((
|
|
371
|
+
if((styleValue instanceof jmGradient) || (t == 'string' && styleValue.indexOf('-gradient') > -1)) {
|
|
371
372
|
//如果是渐变,则需要转换
|
|
372
|
-
if(t == 'string' &&
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
__setStyle(style.toGradient(this), mpname||name);
|
|
376
|
-
}
|
|
377
|
-
else if(t == 'function') {
|
|
378
|
-
if(mpname) {
|
|
379
|
-
style = style.call(this, mpname);
|
|
380
|
-
if(style) {
|
|
381
|
-
__setStyle(style, mpname);
|
|
382
|
-
}
|
|
373
|
+
if(t == 'string' && styleValue.indexOf('-gradient') > -1) {
|
|
374
|
+
styleValue = new jmGradient(styleValue);
|
|
383
375
|
}
|
|
376
|
+
__setStyle(styleValue.toGradient(this), mpname||name);
|
|
384
377
|
}
|
|
385
378
|
else if(mpname) {
|
|
386
379
|
//只有存在白名单中才处理
|
|
387
380
|
//颜色转换
|
|
388
381
|
if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
|
|
389
|
-
|
|
382
|
+
styleValue = jmUtils.toColor(styleValue);
|
|
390
383
|
}
|
|
391
|
-
|
|
392
|
-
// 按比例需要放大的样式
|
|
393
|
-
/*if(scale && style) {
|
|
394
|
-
switch(mpname) {
|
|
395
|
-
case 'lineWidth': {
|
|
396
|
-
style *= scale;
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
// 字体放大
|
|
400
|
-
case 'fontSize':
|
|
401
|
-
case 'font': {
|
|
402
|
-
const ms = style.toString().match(/[\d\.]+/);
|
|
403
|
-
if(ms && ms.length) {
|
|
404
|
-
const size = Number(ms[0]) * scale;
|
|
405
|
-
style = style.toString().replace(ms[0], size);
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
} */
|
|
411
|
-
this.context[mpname] = style;
|
|
384
|
+
this.context[mpname] = styleValue;
|
|
412
385
|
}
|
|
413
386
|
else {
|
|
414
387
|
switch(name) {
|
|
415
388
|
//阴影样式
|
|
416
389
|
case 'shadow' : {
|
|
417
390
|
if(t == 'string') {
|
|
418
|
-
__setStyle(new jmShadow(
|
|
391
|
+
__setStyle(new jmShadow(styleValue), name);
|
|
419
392
|
break;
|
|
420
393
|
}
|
|
421
|
-
for(let k in
|
|
422
|
-
__setStyle(
|
|
394
|
+
for(let k in styleValue) {
|
|
395
|
+
__setStyle(styleValue[k], k, name + '.' + k);
|
|
423
396
|
}
|
|
424
397
|
break;
|
|
425
398
|
}
|
|
426
399
|
//平移
|
|
427
400
|
case 'translate' : {
|
|
428
|
-
this.context.translate(
|
|
401
|
+
this.context.translate(styleValue.x, styleValue.y);
|
|
429
402
|
break;
|
|
430
403
|
}
|
|
431
404
|
//旋转
|
|
432
405
|
case 'rotation' : {
|
|
433
|
-
if(!
|
|
406
|
+
if(!styleValue.angle) break;
|
|
434
407
|
//旋 转先移位偏移量
|
|
435
408
|
let tranX = 0;
|
|
436
409
|
let tranY = 0;
|
|
437
410
|
//旋转,则移位,如果有中心位则按中心旋转,否则按左上角旋转
|
|
438
411
|
//这里只有style中的旋转才能生效,不然会导至子控件多次旋转
|
|
439
|
-
if(
|
|
412
|
+
if(styleValue.point) {
|
|
440
413
|
let bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
|
|
441
|
-
|
|
414
|
+
styleValue = this.getRotation(styleValue);
|
|
442
415
|
|
|
443
|
-
tranX =
|
|
444
|
-
tranY =
|
|
416
|
+
tranX = styleValue.rotateX + bounds.left;
|
|
417
|
+
tranY = styleValue.rotateY + bounds.top;
|
|
445
418
|
}
|
|
446
419
|
|
|
447
420
|
if(tranX!=0 || tranY != 0) this.context.translate(tranX,tranY);
|
|
448
|
-
this.context.rotate(
|
|
421
|
+
this.context.rotate(styleValue.angle);
|
|
449
422
|
if(tranX!=0 || tranY != 0) this.context.translate(-tranX,-tranY);
|
|
450
423
|
break;
|
|
451
424
|
}
|
|
452
425
|
case 'transform' : {
|
|
453
|
-
if(Array.isArray(
|
|
454
|
-
this.context.transform.apply(this.context,
|
|
426
|
+
if(Array.isArray(styleValue)) {
|
|
427
|
+
this.context.transform.apply(this.context, styleValue);
|
|
455
428
|
}
|
|
456
|
-
else if(typeof
|
|
457
|
-
this.context.transform(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
429
|
+
else if(typeof styleValue == 'object') {
|
|
430
|
+
this.context.transform(styleValue.scaleX,//水平缩放
|
|
431
|
+
styleValue.skewX,//水平倾斜
|
|
432
|
+
styleValue.skewY,//垂直倾斜
|
|
433
|
+
styleValue.scaleY,//垂直缩放
|
|
434
|
+
styleValue.offsetX,//水平位移
|
|
435
|
+
styleValue.offsetY);//垂直位移
|
|
463
436
|
}
|
|
464
437
|
break;
|
|
465
438
|
}
|
|
466
439
|
//鼠标指针
|
|
467
440
|
case 'cursor' : {
|
|
468
|
-
this.cursor =
|
|
441
|
+
this.cursor = styleValue;
|
|
469
442
|
break;
|
|
470
443
|
}
|
|
471
444
|
}
|
|
@@ -514,9 +487,6 @@ export default class jmControl extends jmProperty {
|
|
|
514
487
|
if(typeof this.canvas.width === 'function') {
|
|
515
488
|
rect.right = this.canvas.width();
|
|
516
489
|
}
|
|
517
|
-
else if(this.canvas.width) {
|
|
518
|
-
rect.right = this.canvas.width;
|
|
519
|
-
}
|
|
520
490
|
else if(this.width) {
|
|
521
491
|
rect.right = this.width;
|
|
522
492
|
}
|
|
@@ -524,9 +494,6 @@ export default class jmControl extends jmProperty {
|
|
|
524
494
|
if(typeof this.canvas.height === 'function') {
|
|
525
495
|
rect.bottom = this.canvas.height();
|
|
526
496
|
}
|
|
527
|
-
else if(this.canvas.height) {
|
|
528
|
-
rect.bottom = this.canvas.height;
|
|
529
|
-
}
|
|
530
497
|
else if(this.height) {
|
|
531
498
|
rect.bottom = this.height;
|
|
532
499
|
}
|
|
@@ -900,8 +867,6 @@ export default class jmControl extends jmProperty {
|
|
|
900
867
|
this.emit('endDraw',this);
|
|
901
868
|
this.context.restore();
|
|
902
869
|
|
|
903
|
-
//兼容小程序
|
|
904
|
-
if(this.is('jmGraph') && this.context.draw) this.context.draw();
|
|
905
870
|
this.needUpdate = false;
|
|
906
871
|
}
|
|
907
872
|
}
|
|
@@ -1021,8 +986,8 @@ export default class jmControl extends jmProperty {
|
|
|
1021
986
|
//获取dom位置
|
|
1022
987
|
let position = this.getPosition();
|
|
1023
988
|
// 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
|
|
1024
|
-
const right = position.left +
|
|
1025
|
-
const bottom = position.top +
|
|
989
|
+
const right = position.left + this.width;
|
|
990
|
+
const bottom = position.top + this.height;
|
|
1026
991
|
if(p.pageX > right || p.pageX < position.left) {
|
|
1027
992
|
return false;
|
|
1028
993
|
}
|
package/src/core/jmGraph.js
CHANGED
|
@@ -210,8 +210,8 @@ export default class jmGraph extends jmControl {
|
|
|
210
210
|
*/
|
|
211
211
|
getPosition() {
|
|
212
212
|
let p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
|
|
213
|
-
p.width = this.
|
|
214
|
-
p.height = this.
|
|
213
|
+
p.width = this.width;
|
|
214
|
+
p.height = this.height;
|
|
215
215
|
p.right = p.left + p.width;
|
|
216
216
|
p.bottom = p.top + p.height;
|
|
217
217
|
return p;
|
|
@@ -499,12 +499,12 @@ export default class jmGraph extends jmControl {
|
|
|
499
499
|
// 触发刷新事件
|
|
500
500
|
self.emit('update');
|
|
501
501
|
|
|
502
|
-
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
503
|
-
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
502
|
+
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
|
|
503
|
+
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
|
|
504
504
|
if(callback) callback();
|
|
505
505
|
}
|
|
506
|
-
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
|
|
507
|
-
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
|
|
506
|
+
self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler, self.canvas);
|
|
507
|
+
self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update, self.canvas);
|
|
508
508
|
return this;
|
|
509
509
|
}
|
|
510
510
|
|
package/src/core/jmProperty.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import {jmUtils} from "./jmUtils.js";
|
|
1
3
|
import { jmObject } from "./jmObject.js";
|
|
2
4
|
|
|
3
5
|
const PROPERTY_KEY = Symbol("properties");
|
|
@@ -70,6 +72,22 @@ export default class jmProperty extends jmObject {
|
|
|
70
72
|
set graph(v) {
|
|
71
73
|
return this.__pro('graph', v);
|
|
72
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 在下次进行重绘时执行
|
|
78
|
+
* @param {Function} handler
|
|
79
|
+
*/
|
|
80
|
+
requestAnimationFrame(handler) {
|
|
81
|
+
return jmUtils.requestAnimationFrame(handler, this.graph? this.graph.canvas: null);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 清除执行回调
|
|
85
|
+
* @param {Function} handler
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
cancelAnimationFrame(handler) {
|
|
89
|
+
return jmUtils.cancelAnimationFrame(handler, this.graph? this.graph.canvas: null);
|
|
90
|
+
}
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
export { jmProperty };
|
package/src/core/jmUtils.js
CHANGED
|
@@ -703,21 +703,13 @@ export default class jmUtils {
|
|
|
703
703
|
return r;
|
|
704
704
|
}
|
|
705
705
|
// window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画。该方法需要传入一个回调函数作为参数,该回调函数会在浏览器下一次重绘之前执行
|
|
706
|
-
static requestAnimationFrame(callback) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
return requestAnimationFrame(callback);
|
|
712
|
-
}
|
|
706
|
+
static requestAnimationFrame(callback, win) {
|
|
707
|
+
let fun = win && win.requestAnimationFrame? win.requestAnimationFrame: (typeof window !== 'undefined' && window.requestAnimationFrame? window.requestAnimationFrame: setTimeout);
|
|
708
|
+
return fun(callback, 20);
|
|
713
709
|
}
|
|
714
|
-
static cancelAnimationFrame(handler) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
return cancelAnimationFrame(handler);
|
|
720
|
-
}
|
|
710
|
+
static cancelAnimationFrame(handler, win) {
|
|
711
|
+
let fun = win && win.cancelAnimationFrame? win.cancelAnimationFrame: (typeof window !== 'undefined' && window.cancelAnimationFrame? window.cancelAnimationFrame: clearTimeout);
|
|
712
|
+
return fun(handler);
|
|
721
713
|
}
|
|
722
714
|
}
|
|
723
715
|
export { jmUtils };
|