jmgraph 3.2.2 → 3.2.3
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/README.md +4 -4
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3064 -351
- package/dist/jmgraph.min.js +1 -1
- package/index.js +4 -0
- package/package.json +4 -4
- package/src/core/jmControl.js +97 -57
- package/src/core/jmGradient.js +29 -14
- package/src/core/jmGraph.js +70 -26
- package/src/core/jmObject.js +2 -3
- package/src/core/jmPath.js +19 -3
- package/src/core/jmProperty.js +29 -14
- package/src/core/jmUtils.js +218 -31
- package/src/lib/earcut.js +680 -0
- package/src/lib/earcut.md +73 -0
- package/src/lib/webgl/base.js +201 -0
- package/src/lib/webgl/core/buffer.js +48 -0
- package/src/lib/webgl/core/mapSize.js +40 -0
- package/src/lib/webgl/core/mapType.js +43 -0
- package/src/lib/webgl/core/program.js +139 -0
- package/src/lib/webgl/core/shader.js +14 -0
- package/src/lib/webgl/core/texture.js +61 -0
- package/src/lib/webgl/gradient.js +196 -0
- package/src/lib/webgl/index.js +11 -0
- package/src/lib/webgl/path.js +679 -0
- package/src/shapes/jmArc.js +15 -11
- package/src/shapes/jmArrow.js +10 -10
- package/src/shapes/jmBezier.js +2 -2
- package/src/shapes/jmCircle.js +8 -1
- package/src/shapes/jmHArc.js +17 -15
- package/src/shapes/jmImage.js +68 -38
- package/src/shapes/jmLabel.js +11 -10
- package/src/shapes/jmLine.js +20 -12
- package/src/shapes/jmPrismatic.js +4 -2
- package/src/shapes/jmRect.js +5 -4
- package/src/shapes/jmResize.js +6 -4
package/src/shapes/jmArc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {jmPath} from "../core/jmPath.js";
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* 圆弧图型 继承自jmPath
|
|
4
5
|
*
|
|
@@ -10,6 +11,9 @@ export default class jmArc extends jmPath {
|
|
|
10
11
|
|
|
11
12
|
constructor(params, t='jmArc') {
|
|
12
13
|
if(!params) params = {};
|
|
14
|
+
params.isRegular = params.isRegular === false? false: true;// 规则的
|
|
15
|
+
params.needCut = params.needCut === true? true: false;// 规则的
|
|
16
|
+
|
|
13
17
|
super(params, t);
|
|
14
18
|
|
|
15
19
|
this.center = params.center || {x:0,y:0};
|
|
@@ -30,11 +34,11 @@ export default class jmArc extends jmPath {
|
|
|
30
34
|
* @type {point}
|
|
31
35
|
*/
|
|
32
36
|
get center() {
|
|
33
|
-
return this.
|
|
37
|
+
return this.property('center');
|
|
34
38
|
}
|
|
35
39
|
set center(v) {
|
|
36
40
|
this.needUpdate = true;
|
|
37
|
-
return this.
|
|
41
|
+
return this.property('center', v);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
@@ -43,11 +47,11 @@ export default class jmArc extends jmPath {
|
|
|
43
47
|
* @type {number}
|
|
44
48
|
*/
|
|
45
49
|
get radius() {
|
|
46
|
-
return this.
|
|
50
|
+
return this.property('radius');
|
|
47
51
|
}
|
|
48
52
|
set radius(v) {
|
|
49
53
|
this.needUpdate = true;
|
|
50
|
-
return this.
|
|
54
|
+
return this.property('radius', v);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
/**
|
|
@@ -56,11 +60,11 @@ export default class jmArc extends jmPath {
|
|
|
56
60
|
* @type {number}
|
|
57
61
|
*/
|
|
58
62
|
get startAngle() {
|
|
59
|
-
return this.
|
|
63
|
+
return this.property('startAngle');
|
|
60
64
|
}
|
|
61
65
|
set startAngle(v) {
|
|
62
66
|
this.needUpdate = true;
|
|
63
|
-
return this.
|
|
67
|
+
return this.property('startAngle', v);
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
/**
|
|
@@ -69,11 +73,11 @@ export default class jmArc extends jmPath {
|
|
|
69
73
|
* @type {number}
|
|
70
74
|
*/
|
|
71
75
|
get endAngle() {
|
|
72
|
-
return this.
|
|
76
|
+
return this.property('endAngle');
|
|
73
77
|
}
|
|
74
78
|
set endAngle(v) {
|
|
75
79
|
this.needUpdate = true;
|
|
76
|
-
return this.
|
|
80
|
+
return this.property('endAngle', v);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
/**
|
|
@@ -83,11 +87,11 @@ export default class jmArc extends jmPath {
|
|
|
83
87
|
* @type {boolean}
|
|
84
88
|
*/
|
|
85
89
|
get anticlockwise() {
|
|
86
|
-
return this.
|
|
90
|
+
return this.property('anticlockwise');
|
|
87
91
|
}
|
|
88
92
|
set anticlockwise(v) {
|
|
89
93
|
this.needUpdate = true;
|
|
90
|
-
return this.
|
|
94
|
+
return this.property('anticlockwise', v);
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
|
|
@@ -137,7 +141,7 @@ export default class jmArc extends jmPath {
|
|
|
137
141
|
if(step > 0 && r > end) r = end;
|
|
138
142
|
else if(step < 0 && r < end) r = end;
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
const p = {
|
|
141
145
|
x : Math.cos(r) * mw + cx,
|
|
142
146
|
y : Math.sin(r) * mh + cy
|
|
143
147
|
};
|
package/src/shapes/jmArrow.js
CHANGED
|
@@ -29,11 +29,11 @@ export default class jmArrow extends jmPath {
|
|
|
29
29
|
* @type {point}
|
|
30
30
|
*/
|
|
31
31
|
get start() {
|
|
32
|
-
return this.
|
|
32
|
+
return this.property('start');
|
|
33
33
|
}
|
|
34
34
|
set start(v) {
|
|
35
35
|
this.needUpdate = true;
|
|
36
|
-
return this.
|
|
36
|
+
return this.property('start', v);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -44,11 +44,11 @@ export default class jmArrow extends jmPath {
|
|
|
44
44
|
* @type {point} 结束点
|
|
45
45
|
*/
|
|
46
46
|
get end() {
|
|
47
|
-
return this.
|
|
47
|
+
return this.property('end');
|
|
48
48
|
}
|
|
49
49
|
set end(v) {
|
|
50
50
|
this.needUpdate = true;
|
|
51
|
-
return this.
|
|
51
|
+
return this.property('end', v);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -59,11 +59,11 @@ export default class jmArrow extends jmPath {
|
|
|
59
59
|
* @type {number} 箭头角度
|
|
60
60
|
*/
|
|
61
61
|
get angle() {
|
|
62
|
-
return this.
|
|
62
|
+
return this.property('angle');
|
|
63
63
|
}
|
|
64
64
|
set angle(v) {
|
|
65
65
|
this.needUpdate = true;
|
|
66
|
-
return this.
|
|
66
|
+
return this.property('angle', v);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -74,11 +74,11 @@ export default class jmArrow extends jmPath {
|
|
|
74
74
|
* @type {number}
|
|
75
75
|
*/
|
|
76
76
|
get offsetX() {
|
|
77
|
-
return this.
|
|
77
|
+
return this.property('offsetX');
|
|
78
78
|
}
|
|
79
79
|
set offsetX(v) {
|
|
80
80
|
this.needUpdate = true;
|
|
81
|
-
return this.
|
|
81
|
+
return this.property('offsetX', v);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -89,11 +89,11 @@ export default class jmArrow extends jmPath {
|
|
|
89
89
|
* @type {number}
|
|
90
90
|
*/
|
|
91
91
|
get offsetY() {
|
|
92
|
-
return this.
|
|
92
|
+
return this.property('offsetY');
|
|
93
93
|
}
|
|
94
94
|
set offsetY(v) {
|
|
95
95
|
this.needUpdate = true;
|
|
96
|
-
return this.
|
|
96
|
+
return this.property('offsetY', v);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
package/src/shapes/jmBezier.js
CHANGED
|
@@ -27,11 +27,11 @@ export default class jmBezier extends jmPath {
|
|
|
27
27
|
* @type {array}
|
|
28
28
|
*/
|
|
29
29
|
get cpoints() {
|
|
30
|
-
return this.
|
|
30
|
+
return this.property('cpoints');
|
|
31
31
|
}
|
|
32
32
|
set cpoints(v) {
|
|
33
33
|
this.needUpdate = true;
|
|
34
|
-
return this.
|
|
34
|
+
return this.property('cpoints', v);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
package/src/shapes/jmCircle.js
CHANGED
|
@@ -9,6 +9,7 @@ import {jmArc} from "./jmArc.js";
|
|
|
9
9
|
export default class jmCircle extends jmArc {
|
|
10
10
|
|
|
11
11
|
constructor(params, t='jmCircle') {
|
|
12
|
+
params.isRegular = true;// 规则的
|
|
12
13
|
super(params, t);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
@@ -18,7 +19,10 @@ export default class jmCircle extends jmArc {
|
|
|
18
19
|
* @private
|
|
19
20
|
* @for jmCircle
|
|
20
21
|
*/
|
|
21
|
-
initPoints() {
|
|
22
|
+
initPoints() {
|
|
23
|
+
if(this.graph.mode === 'webgl') {
|
|
24
|
+
return super.initPoints();
|
|
25
|
+
}
|
|
22
26
|
let location = this.getLocation();
|
|
23
27
|
|
|
24
28
|
if(!location.radius) {
|
|
@@ -37,6 +41,9 @@ export default class jmCircle extends jmArc {
|
|
|
37
41
|
* @method draw
|
|
38
42
|
*/
|
|
39
43
|
draw() {
|
|
44
|
+
if(this.graph.mode === 'webgl') {
|
|
45
|
+
return super.draw();
|
|
46
|
+
}
|
|
40
47
|
let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
41
48
|
let location = this.getLocation();
|
|
42
49
|
|
package/src/shapes/jmHArc.js
CHANGED
|
@@ -10,6 +10,8 @@ import {jmArc} from "./jmArc.js";
|
|
|
10
10
|
export default class jmHArc extends jmArc {
|
|
11
11
|
|
|
12
12
|
constructor(params, t='jmHArc') {
|
|
13
|
+
params.isRegular = true;// 规则的
|
|
14
|
+
params.needCut = true;
|
|
13
15
|
super(params, t);
|
|
14
16
|
|
|
15
17
|
this.minRadius = params.minRadius || this.style.minRadius || 0;
|
|
@@ -24,11 +26,11 @@ export default class jmHArc extends jmArc {
|
|
|
24
26
|
* @type {number}
|
|
25
27
|
*/
|
|
26
28
|
get minRadius() {
|
|
27
|
-
return this.
|
|
29
|
+
return this.property('minRadius');
|
|
28
30
|
}
|
|
29
31
|
set minRadius(v) {
|
|
30
32
|
this.needUpdate = true;
|
|
31
|
-
return this.
|
|
33
|
+
return this.property('minRadius', v);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -39,11 +41,11 @@ export default class jmHArc extends jmArc {
|
|
|
39
41
|
* @type {number}
|
|
40
42
|
*/
|
|
41
43
|
get maxRadius() {
|
|
42
|
-
return this.
|
|
44
|
+
return this.property('maxRadius');
|
|
43
45
|
}
|
|
44
46
|
set maxRadius(v) {
|
|
45
47
|
this.needUpdate = true;
|
|
46
|
-
return this.
|
|
48
|
+
return this.property('maxRadius', v);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
@@ -53,18 +55,18 @@ export default class jmHArc extends jmArc {
|
|
|
53
55
|
* @private
|
|
54
56
|
*/
|
|
55
57
|
initPoints() {
|
|
56
|
-
|
|
58
|
+
const location = this.getLocation();
|
|
57
59
|
//如果设定了半径。则以半径为主
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
const minr = this.minRadius;
|
|
61
|
+
const maxr = this.maxRadius;
|
|
60
62
|
|
|
61
63
|
let start = this.startAngle;
|
|
62
64
|
let end = this.endAngle;
|
|
63
|
-
|
|
65
|
+
const anticlockwise = this.anticlockwise;
|
|
64
66
|
|
|
65
67
|
//如果是逆时针绘制,则角度为负数,并且结束角为2Math.PI-end
|
|
66
68
|
if(anticlockwise) {
|
|
67
|
-
|
|
69
|
+
const p2 = Math.PI*2;
|
|
68
70
|
start = p2 - start;
|
|
69
71
|
end = p2 - end;
|
|
70
72
|
}
|
|
@@ -72,8 +74,8 @@ export default class jmHArc extends jmArc {
|
|
|
72
74
|
let step = 0.1;
|
|
73
75
|
if(start > end) step = -step;
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const minps = [];
|
|
78
|
+
const maxps = [];
|
|
77
79
|
//椭圆方程x=a*cos(r) ,y=b*sin(r)
|
|
78
80
|
for(let r=start;;r += step) {
|
|
79
81
|
if(step > 0 && r > end) {
|
|
@@ -83,13 +85,13 @@ export default class jmHArc extends jmArc {
|
|
|
83
85
|
r = end;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const cos = Math.cos(r);
|
|
89
|
+
const sin = Math.sin(r);
|
|
90
|
+
const p1 = {
|
|
89
91
|
x : cos * minr + location.center.x,
|
|
90
92
|
y : sin * minr + location.center.y
|
|
91
93
|
};
|
|
92
|
-
|
|
94
|
+
const p2 = {
|
|
93
95
|
x : cos * maxr + location.center.x,
|
|
94
96
|
y : sin * maxr + location.center.y
|
|
95
97
|
};
|
package/src/shapes/jmImage.js
CHANGED
|
@@ -12,6 +12,7 @@ export default class jmImage extends jmControl {
|
|
|
12
12
|
|
|
13
13
|
constructor(params, t) {
|
|
14
14
|
params = params || {};
|
|
15
|
+
params.isRegular = true;// 规则的
|
|
15
16
|
super(params, t||'jmImage');
|
|
16
17
|
|
|
17
18
|
this.style.fill = this.fill || 'transparent';//默认指定一个fill,为了可以鼠标选中
|
|
@@ -29,10 +30,10 @@ export default class jmImage extends jmControl {
|
|
|
29
30
|
* @type {point}
|
|
30
31
|
*/
|
|
31
32
|
get sourcePosition() {
|
|
32
|
-
return this.
|
|
33
|
+
return this.property('sourcePosition');
|
|
33
34
|
}
|
|
34
35
|
set sourcePosition(v) {
|
|
35
|
-
return this.
|
|
36
|
+
return this.property('sourcePosition', v);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -42,11 +43,11 @@ export default class jmImage extends jmControl {
|
|
|
42
43
|
* @type {number}
|
|
43
44
|
*/
|
|
44
45
|
get sourceWidth() {
|
|
45
|
-
return this.
|
|
46
|
+
return this.property('sourceWidth');
|
|
46
47
|
}
|
|
47
48
|
set sourceWidth(v) {
|
|
48
49
|
this.needUpdate = true;
|
|
49
|
-
return this.
|
|
50
|
+
return this.property('sourceWidth', v);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -56,11 +57,11 @@ export default class jmImage extends jmControl {
|
|
|
56
57
|
* @type {number}
|
|
57
58
|
*/
|
|
58
59
|
get sourceHeight() {
|
|
59
|
-
return this.
|
|
60
|
+
return this.property('sourceHeight');
|
|
60
61
|
}
|
|
61
62
|
set sourceHeight(v) {
|
|
62
63
|
this.needUpdate = true;
|
|
63
|
-
return this.
|
|
64
|
+
return this.property('sourceHeight', v);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -70,11 +71,11 @@ export default class jmImage extends jmControl {
|
|
|
70
71
|
* @type {img}
|
|
71
72
|
*/
|
|
72
73
|
get image() {
|
|
73
|
-
return this.
|
|
74
|
+
return this.property('image');
|
|
74
75
|
}
|
|
75
76
|
set image(v) {
|
|
76
77
|
this.needUpdate = true;
|
|
77
|
-
return this.
|
|
78
|
+
return this.property('image', v);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -84,23 +85,9 @@ export default class jmImage extends jmControl {
|
|
|
84
85
|
* @method draw
|
|
85
86
|
*/
|
|
86
87
|
draw() {
|
|
87
|
-
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if(this.graph.isWXMiniApp && this.graph.canvas && typeof img === 'string') {
|
|
91
|
-
// 图片对象
|
|
92
|
-
const image = this.graph.canvas.createImage();
|
|
93
|
-
// 图片加载完成回调
|
|
94
|
-
image.onload = () => {
|
|
95
|
-
// 将图片绘制到 canvas 上
|
|
96
|
-
this.drawImg(image);
|
|
97
|
-
}
|
|
98
|
-
// 设置图片src
|
|
99
|
-
image.src = img;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
this.drawImg(img);
|
|
103
|
-
}
|
|
88
|
+
try {
|
|
89
|
+
const img = this.getImage();
|
|
90
|
+
this.drawImg(img);
|
|
104
91
|
}
|
|
105
92
|
catch(e) {
|
|
106
93
|
console.error && console.error(e);
|
|
@@ -109,42 +96,72 @@ export default class jmImage extends jmControl {
|
|
|
109
96
|
|
|
110
97
|
// 绘制
|
|
111
98
|
drawImg(img) {
|
|
112
|
-
if(!img) {
|
|
99
|
+
if(!img || !img.complete) {
|
|
113
100
|
console.warn('image is empty');
|
|
114
101
|
return;
|
|
115
102
|
}
|
|
116
103
|
let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
117
104
|
if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
|
|
118
|
-
|
|
119
|
-
p
|
|
120
|
-
p.top += bounds.top;
|
|
105
|
+
|
|
106
|
+
let p = this.getLocation();
|
|
121
107
|
|
|
122
108
|
let sp = this.sourcePosition;
|
|
123
109
|
let sw = this.sourceWidth;
|
|
124
110
|
let sh = this.sourceHeight;
|
|
125
111
|
|
|
112
|
+
const ctx = this.webglControl || this.context;
|
|
113
|
+
if(this.webglControl) {
|
|
114
|
+
ctx.setParentBounds && ctx.setParentBounds(bounds);
|
|
115
|
+
const localBounds = this.getBounds();
|
|
116
|
+
// 给图片给定顶点
|
|
117
|
+
ctx.draw([
|
|
118
|
+
{
|
|
119
|
+
x: localBounds.left,
|
|
120
|
+
y: localBounds.top
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
x: localBounds.left + localBounds.width,
|
|
124
|
+
y: localBounds.top
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
x: localBounds.left + localBounds.width,
|
|
128
|
+
y: localBounds.top + localBounds.height
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
x: localBounds.left,
|
|
132
|
+
y: localBounds.top + localBounds.height
|
|
133
|
+
}
|
|
134
|
+
], bounds);
|
|
135
|
+
ctx.drawImage(img, localBounds.left, localBounds.top, localBounds.width, localBounds.height);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 计算绝对定位
|
|
140
|
+
p.left += bounds.left;
|
|
141
|
+
p.top += bounds.top;
|
|
142
|
+
|
|
126
143
|
if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
|
|
127
144
|
if(typeof sw == 'undefined') sw= p.width || img.width || 0;
|
|
128
145
|
if(typeof sh == 'undefined') sh= p.height || img.height || 0;
|
|
129
146
|
sp = sp || {x:0, y:0};
|
|
130
147
|
|
|
131
|
-
if(p.width && p.height)
|
|
148
|
+
if(p.width && p.height) ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
|
|
132
149
|
else if(p.width) {
|
|
133
|
-
|
|
150
|
+
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
|
|
134
151
|
}
|
|
135
152
|
else if(p.height) {
|
|
136
|
-
|
|
153
|
+
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
|
|
137
154
|
}
|
|
138
|
-
else
|
|
155
|
+
else ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
|
|
139
156
|
}
|
|
140
157
|
else if(p) {
|
|
141
|
-
if(p.width && p.height)
|
|
142
|
-
else if(p.width)
|
|
143
|
-
else if(p.height)
|
|
144
|
-
else
|
|
158
|
+
if(p.width && p.height) ctx.drawImage(img,p.left,p.top,p.width,p.height);
|
|
159
|
+
else if(p.width) ctx.drawImage(img,p.left,p.top,p.width,img.height);
|
|
160
|
+
else if(p.height) ctx.drawImage(img,p.left,p.top,img.width,p.height);
|
|
161
|
+
else ctx.drawImage(img,p.left,p.top);
|
|
145
162
|
}
|
|
146
163
|
else {
|
|
147
|
-
|
|
164
|
+
ctx.drawImage(img);
|
|
148
165
|
}
|
|
149
166
|
}
|
|
150
167
|
|
|
@@ -185,11 +202,24 @@ export default class jmImage extends jmControl {
|
|
|
185
202
|
}
|
|
186
203
|
else if(typeof document !== 'undefined' && document.createElement) {
|
|
187
204
|
this.__img = document.createElement('img');
|
|
205
|
+
this.__img.onload = ()=>{
|
|
206
|
+
this.needUpdate = true;
|
|
207
|
+
};
|
|
188
208
|
if(src && typeof src == 'string') this.__img.src = src;
|
|
189
209
|
}
|
|
210
|
+
else if(this.graph.isWXMiniApp && this.graph.canvas && typeof src === 'string') {
|
|
211
|
+
// 图片对象
|
|
212
|
+
this.__img = this.graph.canvas.createImage();
|
|
213
|
+
this.__img.onload = ()=>{
|
|
214
|
+
this.needUpdate = true;
|
|
215
|
+
};
|
|
216
|
+
// 设置图片src
|
|
217
|
+
this.__img.src = src;
|
|
218
|
+
}
|
|
190
219
|
else {
|
|
191
220
|
this.__img = src;
|
|
192
221
|
}
|
|
222
|
+
this.image = this.__img.src;
|
|
193
223
|
return this.__img;
|
|
194
224
|
}
|
|
195
225
|
}
|
package/src/shapes/jmLabel.js
CHANGED
|
@@ -10,6 +10,7 @@ export default class jmLabel extends jmControl {
|
|
|
10
10
|
|
|
11
11
|
constructor(params, t) {
|
|
12
12
|
params = params || {};
|
|
13
|
+
params.isRegular = true;// 规则的
|
|
13
14
|
super(params, t||'jmLabel');
|
|
14
15
|
|
|
15
16
|
this.style.font = this.style.font || "15px Arial";
|
|
@@ -32,11 +33,11 @@ export default class jmLabel extends jmControl {
|
|
|
32
33
|
* @type {string}
|
|
33
34
|
*/
|
|
34
35
|
get text() {
|
|
35
|
-
return this.
|
|
36
|
+
return this.property('text');
|
|
36
37
|
}
|
|
37
38
|
set text(v) {
|
|
38
39
|
this.needUpdate = true;
|
|
39
|
-
return this.
|
|
40
|
+
return this.property('text', v);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -46,11 +47,11 @@ export default class jmLabel extends jmControl {
|
|
|
46
47
|
* @type {point}
|
|
47
48
|
*/
|
|
48
49
|
get center() {
|
|
49
|
-
return this.
|
|
50
|
+
return this.property('center');
|
|
50
51
|
}
|
|
51
52
|
set center(v) {
|
|
52
53
|
this.needUpdate = true;
|
|
53
|
-
return this.
|
|
54
|
+
return this.property('center', v);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/**
|
|
@@ -59,11 +60,11 @@ export default class jmLabel extends jmControl {
|
|
|
59
60
|
* @type {point}
|
|
60
61
|
*/
|
|
61
62
|
get position() {
|
|
62
|
-
return this.
|
|
63
|
+
return this.property('position');
|
|
63
64
|
}
|
|
64
65
|
set position(v) {
|
|
65
66
|
this.needUpdate = true;
|
|
66
|
-
return this.
|
|
67
|
+
return this.property('position', v);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/**
|
|
@@ -114,7 +115,7 @@ export default class jmLabel extends jmControl {
|
|
|
114
115
|
testSize() {
|
|
115
116
|
if(this.__size) return this.__size;
|
|
116
117
|
|
|
117
|
-
this.context.save();
|
|
118
|
+
this.context.save && this.context.save();
|
|
118
119
|
// 修改字体,用来计算
|
|
119
120
|
this.setStyle({
|
|
120
121
|
font: this.style.font || (this.style.fontSize + 'px ' + this.style.fontFamily)
|
|
@@ -123,7 +124,7 @@ export default class jmLabel extends jmControl {
|
|
|
123
124
|
this.__size = this.context.measureText?
|
|
124
125
|
this.context.measureText(this.text):
|
|
125
126
|
{width:15};
|
|
126
|
-
this.context.restore();
|
|
127
|
+
this.context.restore && this.context.restore();
|
|
127
128
|
this.__size.height = this.style.fontSize?this.style.fontSize:15;
|
|
128
129
|
if(!this.width) this.width = this.__size.width;
|
|
129
130
|
if(!this.height) this.height = this.__size.height;
|
|
@@ -192,7 +193,7 @@ export default class jmLabel extends jmControl {
|
|
|
192
193
|
if(this.style.border) {
|
|
193
194
|
//如果指定了边框样式
|
|
194
195
|
if(this.style.border.style) {
|
|
195
|
-
this.context.save();
|
|
196
|
+
this.context.save && this.context.save();
|
|
196
197
|
this.setStyle(this.style.border.style);
|
|
197
198
|
}
|
|
198
199
|
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
@@ -216,7 +217,7 @@ export default class jmLabel extends jmControl {
|
|
|
216
217
|
}
|
|
217
218
|
//如果指定了边框颜色
|
|
218
219
|
if(this.style.border.style) {
|
|
219
|
-
this.context.restore();
|
|
220
|
+
this.context.restore && this.context.restore();
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
}
|
package/src/shapes/jmLine.js
CHANGED
|
@@ -9,12 +9,16 @@ import {jmPath} from "../core/jmPath.js";
|
|
|
9
9
|
export default class jmLine extends jmPath {
|
|
10
10
|
|
|
11
11
|
constructor(params, t='jmLine') {
|
|
12
|
+
|
|
13
|
+
params.isRegular = true;// 规则的
|
|
14
|
+
|
|
12
15
|
super(params, t);
|
|
13
16
|
|
|
14
17
|
this.start = params.start || {x:0,y:0};
|
|
15
18
|
this.end = params.end || {x:0,y:0};
|
|
16
19
|
this.style.lineType = this.style.lineType || 'solid';
|
|
17
20
|
this.style.dashLength = this.style.dashLength || 4;
|
|
21
|
+
this.style.close = false;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
/**
|
|
@@ -25,11 +29,11 @@ export default class jmLine extends jmPath {
|
|
|
25
29
|
* @type {point}
|
|
26
30
|
*/
|
|
27
31
|
get start() {
|
|
28
|
-
return this.
|
|
32
|
+
return this.property('start');
|
|
29
33
|
}
|
|
30
34
|
set start(v) {
|
|
31
35
|
this.needUpdate = true;
|
|
32
|
-
return this.
|
|
36
|
+
return this.property('start', v);
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -40,11 +44,11 @@ export default class jmLine extends jmPath {
|
|
|
40
44
|
* @type {point}
|
|
41
45
|
*/
|
|
42
46
|
get end() {
|
|
43
|
-
return this.
|
|
47
|
+
return this.property('end');
|
|
44
48
|
}
|
|
45
49
|
set end(v) {
|
|
46
50
|
this.needUpdate = true;
|
|
47
|
-
return this.
|
|
51
|
+
return this.property('end', v);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
@@ -53,30 +57,34 @@ export default class jmLine extends jmPath {
|
|
|
53
57
|
* @private
|
|
54
58
|
*/
|
|
55
59
|
initPoints() {
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const start = this.start;
|
|
61
|
+
const end = this.end;
|
|
58
62
|
this.points = [];
|
|
59
63
|
this.points.push(start);
|
|
60
64
|
|
|
61
65
|
if(this.style.lineType === 'dotted') {
|
|
62
66
|
let dx = end.x - start.x;
|
|
63
67
|
let dy = end.y - start.y;
|
|
64
|
-
|
|
68
|
+
const lineLen = Math.sqrt(dx * dx + dy * dy);
|
|
65
69
|
dx = dx / lineLen;
|
|
66
70
|
dy = dy / lineLen;
|
|
67
71
|
let dottedstart = false;
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
const dashLen = this.style.dashLength || 5;
|
|
74
|
+
const dottedsp = dashLen / 2;
|
|
71
75
|
for(let l=dashLen; l<=lineLen;) {
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
const p = {
|
|
77
|
+
x: start.x + dx * l,
|
|
78
|
+
y: start.y + dy * l
|
|
79
|
+
};
|
|
80
|
+
if(dottedstart === false) {
|
|
74
81
|
l += dottedsp;
|
|
75
82
|
}
|
|
76
83
|
else {
|
|
77
|
-
|
|
84
|
+
p.m = true;// 移动到当时坐标
|
|
78
85
|
l += dashLen;
|
|
79
86
|
}
|
|
87
|
+
this.points.push(p);
|
|
80
88
|
dottedstart = !dottedstart;
|
|
81
89
|
}
|
|
82
90
|
}
|
|
@@ -9,6 +9,8 @@ import {jmPath} from "../core/jmPath.js";
|
|
|
9
9
|
export default class jmPrismatic extends jmPath {
|
|
10
10
|
|
|
11
11
|
constructor(params, t='jmPrismatic') {
|
|
12
|
+
params.isRegular = true;// 规则的
|
|
13
|
+
|
|
12
14
|
super(params, t);
|
|
13
15
|
this.style.close = typeof this.style.close == 'undefined'? true : this.style.close;
|
|
14
16
|
|
|
@@ -26,11 +28,11 @@ export default class jmPrismatic extends jmPath {
|
|
|
26
28
|
* @type {point}
|
|
27
29
|
*/
|
|
28
30
|
get center() {
|
|
29
|
-
return this.
|
|
31
|
+
return this.property('center');
|
|
30
32
|
}
|
|
31
33
|
set center(v) {
|
|
32
34
|
this.needUpdate = true;
|
|
33
|
-
return this.
|
|
35
|
+
return this.property('center', v);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|