jmgraph 3.2.16 → 3.2.18
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/LICENSE +21 -21
- package/README.md +251 -428
- package/build/gulpfile.js +142 -142
- package/build/package-lock.json +10666 -0
- package/build/package.json +71 -71
- package/dev.js +9 -9
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3500 -2668
- package/dist/jmgraph.min.js +1 -1
- package/example/ball.html +216 -216
- package/example/base.html +111 -111
- package/example/canvas.html +53 -53
- package/example/cell.html +283 -283
- package/example/controls/arc.html +128 -128
- package/example/controls/arrowline.html +77 -77
- package/example/controls/bezier.html +298 -298
- package/example/controls/img.html +96 -96
- package/example/controls/label.html +86 -86
- package/example/controls/line.html +172 -172
- package/example/controls/prismatic.html +62 -62
- package/example/controls/rect.html +63 -63
- package/example/controls/resize.html +111 -111
- package/example/controls/test.html +359 -359
- package/example/es.html +69 -69
- package/example/es5module.html +62 -63
- package/example/heartarc.html +115 -115
- package/example/index.html +46 -46
- package/example/js/require.js +4 -4
- package/example/love/img/bling/bling.tps +265 -265
- package/example/love/img/bling.json +87 -87
- package/example/love/img/bling.tps +295 -295
- package/example/love/img/love.json +95 -95
- package/example/love/img/love.tps +315 -315
- package/example/love/img/qq/qq.tps +399 -399
- package/example/love/img/qq.json +242 -242
- package/example/love/index.html +40 -40
- package/example/love/js/game.js +558 -558
- package/example/music.html +210 -210
- package/example/node/test.js +137 -137
- package/example/pdf.html +186 -186
- package/example/progress.html +172 -172
- package/example/pso.html +147 -147
- package/example/sort.html +804 -815
- package/example/tweenjs.html +83 -83
- package/example/webgl.html +278 -278
- package/example/xfj/index.html +331 -331
- package/example/xfj/shake.js +48 -48
- package/example/xfj/testori.html +75 -75
- package/index.js +99 -99
- package/package.json +58 -56
- package/src/core/jmControl.js +1376 -1531
- package/src/core/jmEvents.js +240 -281
- package/src/core/jmGradient.js +231 -231
- package/src/core/jmGraph.js +569 -569
- package/src/core/jmList.js +92 -157
- package/src/core/jmObject.js +83 -103
- package/src/core/jmPath.js +35 -35
- package/src/core/jmProperty.js +71 -110
- package/src/core/jmShadow.js +65 -65
- package/src/core/jmUtils.js +906 -919
- package/src/lib/earcut.js +680 -680
- package/src/lib/earcut.md +73 -73
- package/src/lib/webgl/base.js +522 -452
- package/src/lib/webgl/core/buffer.js +48 -48
- package/src/lib/webgl/core/mapSize.js +40 -40
- package/src/lib/webgl/core/mapType.js +43 -43
- package/src/lib/webgl/core/program.js +138 -138
- package/src/lib/webgl/core/shader.js +13 -13
- package/src/lib/webgl/core/texture.js +60 -60
- package/src/lib/webgl/gradient.js +168 -168
- package/src/lib/webgl/index.js +137 -11
- package/src/lib/webgl/path.js +568 -561
- package/src/shapes/jmArrowLine.js +36 -36
- package/src/shapes/jmImage.js +244 -244
- package/src/shapes/jmLabel.js +271 -271
- package/src/shapes/jmResize.js +332 -330
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import {jmLine} from "./jmLine.js";
|
|
2
|
-
import {jmArrow} from "./jmArrow.js";
|
|
3
|
-
/**
|
|
4
|
-
* 带箭头的直线,继承jmPath
|
|
5
|
-
*
|
|
6
|
-
* @class jmArrowLine
|
|
7
|
-
* @extends jmLine
|
|
8
|
-
* @param {object} params 生成当前直线的参数对象,(style=当前线条样式,start=直线起始点,end=直线终结点)
|
|
9
|
-
*/
|
|
10
|
-
export default class jmArrowLine extends jmLine {
|
|
11
|
-
|
|
12
|
-
constructor(params, t) {
|
|
13
|
-
|
|
14
|
-
params.start = params.start || {x:0,y:0};
|
|
15
|
-
params.end = params.end || {x:0,y:0};
|
|
16
|
-
|
|
17
|
-
super(params, t||'jmArrowLine');
|
|
18
|
-
this.style.lineJoin = this.style.lineJoin || 'miter';
|
|
19
|
-
this.arrow = new jmArrow(params);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 初始化直线和箭头描点
|
|
24
|
-
*
|
|
25
|
-
* @method initPoints
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
initPoints() {
|
|
29
|
-
this.points = super.initPoints();
|
|
30
|
-
if(this.arrowVisible !== false) {
|
|
31
|
-
this.points = this.points.concat(this.arrow.initPoints());
|
|
32
|
-
}
|
|
33
|
-
return this.points;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
1
|
+
import {jmLine} from "./jmLine.js";
|
|
2
|
+
import {jmArrow} from "./jmArrow.js";
|
|
3
|
+
/**
|
|
4
|
+
* 带箭头的直线,继承jmPath
|
|
5
|
+
*
|
|
6
|
+
* @class jmArrowLine
|
|
7
|
+
* @extends jmLine
|
|
8
|
+
* @param {object} params 生成当前直线的参数对象,(style=当前线条样式,start=直线起始点,end=直线终结点)
|
|
9
|
+
*/
|
|
10
|
+
export default class jmArrowLine extends jmLine {
|
|
11
|
+
|
|
12
|
+
constructor(params, t) {
|
|
13
|
+
|
|
14
|
+
params.start = params.start || {x:0,y:0};
|
|
15
|
+
params.end = params.end || {x:0,y:0};
|
|
16
|
+
|
|
17
|
+
super(params, t||'jmArrowLine');
|
|
18
|
+
this.style.lineJoin = this.style.lineJoin || 'miter';
|
|
19
|
+
this.arrow = new jmArrow(params);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 初始化直线和箭头描点
|
|
24
|
+
*
|
|
25
|
+
* @method initPoints
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
initPoints() {
|
|
29
|
+
this.points = super.initPoints();
|
|
30
|
+
if(this.arrowVisible !== false) {
|
|
31
|
+
this.points = this.points.concat(this.arrow.initPoints());
|
|
32
|
+
}
|
|
33
|
+
return this.points;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
37
|
export { jmArrowLine };
|
package/src/shapes/jmImage.js
CHANGED
|
@@ -1,245 +1,245 @@
|
|
|
1
|
-
import {jmControl} from "../core/jmControl.js";
|
|
2
|
-
/**
|
|
3
|
-
* 图片控件,继承自jmControl
|
|
4
|
-
* params参数中image为指定的图片源地址或图片img对象,
|
|
5
|
-
* postion=当前控件的位置,width=其宽度,height=高度,sourcePosition=从当前图片中展示的位置,sourceWidth=从图片中截取的宽度,sourceHeight=从图片中截取的高度。
|
|
6
|
-
*
|
|
7
|
-
* @class jmImage
|
|
8
|
-
* @extends jmControl
|
|
9
|
-
* @param {object} params 控件参数
|
|
10
|
-
*/
|
|
11
|
-
export default class jmImage extends jmControl {
|
|
12
|
-
|
|
13
|
-
constructor(params, t) {
|
|
14
|
-
params = params || {};
|
|
15
|
-
params.isRegular = true;// 规则的
|
|
16
|
-
super(params, t||'jmImage');
|
|
17
|
-
|
|
18
|
-
this.style.fill = this.fill || 'transparent';//默认指定一个fill,为了可以鼠标选中
|
|
19
|
-
|
|
20
|
-
this.sourceWidth = params.sourceWidth;
|
|
21
|
-
this.sourceHeight = params.sourceHeight;
|
|
22
|
-
this.sourcePosition = params.sourcePosition;
|
|
23
|
-
this.image = params.image || this.style.image;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 画图开始剪切位置
|
|
28
|
-
*
|
|
29
|
-
* @property sourcePosition
|
|
30
|
-
* @type {point}
|
|
31
|
-
*/
|
|
32
|
-
get sourcePosition() {
|
|
33
|
-
return this.property('sourcePosition');
|
|
34
|
-
}
|
|
35
|
-
set sourcePosition(v) {
|
|
36
|
-
return this.property('sourcePosition', v);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 被剪切宽度
|
|
41
|
-
*
|
|
42
|
-
* @property sourceWidth
|
|
43
|
-
* @type {number}
|
|
44
|
-
*/
|
|
45
|
-
get sourceWidth() {
|
|
46
|
-
return this.property('sourceWidth');
|
|
47
|
-
}
|
|
48
|
-
set sourceWidth(v) {
|
|
49
|
-
this.needUpdate = true;
|
|
50
|
-
return this.property('sourceWidth', v);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 被剪切高度
|
|
55
|
-
*
|
|
56
|
-
* @method sourceHeight
|
|
57
|
-
* @type {number}
|
|
58
|
-
*/
|
|
59
|
-
get sourceHeight() {
|
|
60
|
-
return this.property('sourceHeight');
|
|
61
|
-
}
|
|
62
|
-
set sourceHeight(v) {
|
|
63
|
-
this.needUpdate = true;
|
|
64
|
-
return this.property('sourceHeight', v);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 设定要绘制的图像或其它多媒体对象,可以是图片地址,或图片image对象
|
|
69
|
-
*
|
|
70
|
-
* @method image
|
|
71
|
-
* @type {img}
|
|
72
|
-
*/
|
|
73
|
-
get image() {
|
|
74
|
-
return this.property('image');
|
|
75
|
-
}
|
|
76
|
-
set image(v) {
|
|
77
|
-
this.needUpdate = true;
|
|
78
|
-
return this.property('image', v);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 重写控件绘制
|
|
83
|
-
* 根据父边界偏移和此控件参数绘制图片
|
|
84
|
-
*
|
|
85
|
-
* @method draw
|
|
86
|
-
*/
|
|
87
|
-
draw() {
|
|
88
|
-
try {
|
|
89
|
-
const img = this.getImage();
|
|
90
|
-
this.drawImg(img);
|
|
91
|
-
}
|
|
92
|
-
catch(e) {
|
|
93
|
-
console.error && console.error(e);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 绘制
|
|
98
|
-
drawImg(img) {
|
|
99
|
-
if(!img || !img.complete) {
|
|
100
|
-
console.warn('image is empty');
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
104
|
-
if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
|
|
105
|
-
|
|
106
|
-
let p = this.getLocation();
|
|
107
|
-
|
|
108
|
-
let sp = this.sourcePosition;
|
|
109
|
-
let sw = this.sourceWidth;
|
|
110
|
-
let sh = this.sourceHeight;
|
|
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
|
-
|
|
143
|
-
if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
|
|
144
|
-
if(typeof sw == 'undefined') sw= p.width || img.width || 0;
|
|
145
|
-
if(typeof sh == 'undefined') sh= p.height || img.height || 0;
|
|
146
|
-
sp = sp || {x:0, y:0};
|
|
147
|
-
|
|
148
|
-
if(p.width && p.height) ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
|
|
149
|
-
else if(p.width) {
|
|
150
|
-
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
|
|
151
|
-
}
|
|
152
|
-
else if(p.height) {
|
|
153
|
-
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
|
|
154
|
-
}
|
|
155
|
-
else ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
|
|
156
|
-
}
|
|
157
|
-
else if(p) {
|
|
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);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
ctx.drawImage(img);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 获取当前控件的边界
|
|
170
|
-
*
|
|
171
|
-
* @method getBounds
|
|
172
|
-
* @return {object} 边界对象(left,top,right,bottom,width,height)
|
|
173
|
-
*/
|
|
174
|
-
getBounds(isReset) {
|
|
175
|
-
//如果当次计算过,则不重复计算
|
|
176
|
-
if(this.bounds && !isReset) return this.bounds;
|
|
177
|
-
let rect = {};
|
|
178
|
-
let img = this.getImage() || {
|
|
179
|
-
width: 0,
|
|
180
|
-
height: 0
|
|
181
|
-
};
|
|
182
|
-
let p = this.getLocation();
|
|
183
|
-
let w = p.width || img.width;
|
|
184
|
-
let h = p.height || img.height;
|
|
185
|
-
rect.left = p.left;
|
|
186
|
-
rect.top = p.top;
|
|
187
|
-
rect.right = p.left + w;
|
|
188
|
-
rect.bottom = p.top + h;
|
|
189
|
-
rect.width = w;
|
|
190
|
-
rect.height = h;
|
|
191
|
-
return this.bounds=rect;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getLocation() {
|
|
195
|
-
const img = this.getImage();
|
|
196
|
-
const loc = super.getLocation();
|
|
197
|
-
// 如果指定了宽度,但没有指定高宽,则等比缩放
|
|
198
|
-
if(loc.width && !loc.height) {
|
|
199
|
-
loc.height = loc.width / img.width * img.height;
|
|
200
|
-
}
|
|
201
|
-
else if(loc.height && !loc.width) {
|
|
202
|
-
loc.width = loc.height / img.height * img.width;
|
|
203
|
-
}
|
|
204
|
-
return loc;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* img对象
|
|
209
|
-
*
|
|
210
|
-
* @method getImage
|
|
211
|
-
* @return {img} 图片对象
|
|
212
|
-
*/
|
|
213
|
-
getImage() {
|
|
214
|
-
const src = this.image || this.style.src || this.style.image;
|
|
215
|
-
if(this.__img && this.__img.src && this.__img.src.indexOf(src) != -1) {
|
|
216
|
-
return this.__img;
|
|
217
|
-
}
|
|
218
|
-
else if(src && src.src) {
|
|
219
|
-
this.__img = src;
|
|
220
|
-
}
|
|
221
|
-
else if(typeof document !== 'undefined' && document.createElement) {
|
|
222
|
-
this.__img = document.createElement('img');
|
|
223
|
-
this.__img.onload = ()=>{
|
|
224
|
-
this.needUpdate = true;
|
|
225
|
-
};
|
|
226
|
-
if(src && typeof src == 'string') this.__img.src = src;
|
|
227
|
-
}
|
|
228
|
-
else if(this.graph.isWXMiniApp && this.graph.canvas && typeof src === 'string') {
|
|
229
|
-
// 图片对象
|
|
230
|
-
this.__img = this.graph.canvas.createImage();
|
|
231
|
-
this.__img.onload = ()=>{
|
|
232
|
-
this.needUpdate = true;
|
|
233
|
-
};
|
|
234
|
-
// 设置图片src
|
|
235
|
-
this.__img.src = src;
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
this.__img = src;
|
|
239
|
-
}
|
|
240
|
-
if(this.__img) this.image = this.__img.src;
|
|
241
|
-
return this.__img;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
1
|
+
import {jmControl} from "../core/jmControl.js";
|
|
2
|
+
/**
|
|
3
|
+
* 图片控件,继承自jmControl
|
|
4
|
+
* params参数中image为指定的图片源地址或图片img对象,
|
|
5
|
+
* postion=当前控件的位置,width=其宽度,height=高度,sourcePosition=从当前图片中展示的位置,sourceWidth=从图片中截取的宽度,sourceHeight=从图片中截取的高度。
|
|
6
|
+
*
|
|
7
|
+
* @class jmImage
|
|
8
|
+
* @extends jmControl
|
|
9
|
+
* @param {object} params 控件参数
|
|
10
|
+
*/
|
|
11
|
+
export default class jmImage extends jmControl {
|
|
12
|
+
|
|
13
|
+
constructor(params, t) {
|
|
14
|
+
params = params || {};
|
|
15
|
+
params.isRegular = true;// 规则的
|
|
16
|
+
super(params, t||'jmImage');
|
|
17
|
+
|
|
18
|
+
this.style.fill = this.fill || 'transparent';//默认指定一个fill,为了可以鼠标选中
|
|
19
|
+
|
|
20
|
+
this.sourceWidth = params.sourceWidth;
|
|
21
|
+
this.sourceHeight = params.sourceHeight;
|
|
22
|
+
this.sourcePosition = params.sourcePosition;
|
|
23
|
+
this.image = params.image || this.style.image;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 画图开始剪切位置
|
|
28
|
+
*
|
|
29
|
+
* @property sourcePosition
|
|
30
|
+
* @type {point}
|
|
31
|
+
*/
|
|
32
|
+
get sourcePosition() {
|
|
33
|
+
return this.property('sourcePosition');
|
|
34
|
+
}
|
|
35
|
+
set sourcePosition(v) {
|
|
36
|
+
return this.property('sourcePosition', v);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 被剪切宽度
|
|
41
|
+
*
|
|
42
|
+
* @property sourceWidth
|
|
43
|
+
* @type {number}
|
|
44
|
+
*/
|
|
45
|
+
get sourceWidth() {
|
|
46
|
+
return this.property('sourceWidth');
|
|
47
|
+
}
|
|
48
|
+
set sourceWidth(v) {
|
|
49
|
+
this.needUpdate = true;
|
|
50
|
+
return this.property('sourceWidth', v);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 被剪切高度
|
|
55
|
+
*
|
|
56
|
+
* @method sourceHeight
|
|
57
|
+
* @type {number}
|
|
58
|
+
*/
|
|
59
|
+
get sourceHeight() {
|
|
60
|
+
return this.property('sourceHeight');
|
|
61
|
+
}
|
|
62
|
+
set sourceHeight(v) {
|
|
63
|
+
this.needUpdate = true;
|
|
64
|
+
return this.property('sourceHeight', v);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 设定要绘制的图像或其它多媒体对象,可以是图片地址,或图片image对象
|
|
69
|
+
*
|
|
70
|
+
* @method image
|
|
71
|
+
* @type {img}
|
|
72
|
+
*/
|
|
73
|
+
get image() {
|
|
74
|
+
return this.property('image');
|
|
75
|
+
}
|
|
76
|
+
set image(v) {
|
|
77
|
+
this.needUpdate = true;
|
|
78
|
+
return this.property('image', v);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 重写控件绘制
|
|
83
|
+
* 根据父边界偏移和此控件参数绘制图片
|
|
84
|
+
*
|
|
85
|
+
* @method draw
|
|
86
|
+
*/
|
|
87
|
+
draw() {
|
|
88
|
+
try {
|
|
89
|
+
const img = this.getImage();
|
|
90
|
+
this.drawImg(img);
|
|
91
|
+
}
|
|
92
|
+
catch(e) {
|
|
93
|
+
console.error && console.error(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 绘制
|
|
98
|
+
drawImg(img) {
|
|
99
|
+
if(!img || !img.complete) {
|
|
100
|
+
console.warn('image is empty');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
104
|
+
if(!bounds) bounds = this.parent && this.parent.getAbsoluteBounds?this.parent.getAbsoluteBounds():this.getAbsoluteBounds();
|
|
105
|
+
|
|
106
|
+
let p = this.getLocation();
|
|
107
|
+
|
|
108
|
+
let sp = this.sourcePosition;
|
|
109
|
+
let sw = this.sourceWidth;
|
|
110
|
+
let sh = this.sourceHeight;
|
|
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
|
+
|
|
143
|
+
if(sp || typeof sw != 'undefined' || typeof sh != 'undefined') {
|
|
144
|
+
if(typeof sw == 'undefined') sw= p.width || img.width || 0;
|
|
145
|
+
if(typeof sh == 'undefined') sh= p.height || img.height || 0;
|
|
146
|
+
sp = sp || {x:0, y:0};
|
|
147
|
+
|
|
148
|
+
if(p.width && p.height) ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,p.height);
|
|
149
|
+
else if(p.width) {
|
|
150
|
+
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,p.width,sh);
|
|
151
|
+
}
|
|
152
|
+
else if(p.height) {
|
|
153
|
+
ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,p.height);
|
|
154
|
+
}
|
|
155
|
+
else ctx.drawImage(img,sp.x,sp.y,sw,sh,p.left,p.top,sw,sh);
|
|
156
|
+
}
|
|
157
|
+
else if(p) {
|
|
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);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
ctx.drawImage(img);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 获取当前控件的边界
|
|
170
|
+
*
|
|
171
|
+
* @method getBounds
|
|
172
|
+
* @return {object} 边界对象(left,top,right,bottom,width,height)
|
|
173
|
+
*/
|
|
174
|
+
getBounds(isReset) {
|
|
175
|
+
//如果当次计算过,则不重复计算
|
|
176
|
+
if(this.bounds && !isReset) return this.bounds;
|
|
177
|
+
let rect = {};
|
|
178
|
+
let img = this.getImage() || {
|
|
179
|
+
width: 0,
|
|
180
|
+
height: 0
|
|
181
|
+
};
|
|
182
|
+
let p = this.getLocation();
|
|
183
|
+
let w = p.width || img.width;
|
|
184
|
+
let h = p.height || img.height;
|
|
185
|
+
rect.left = p.left;
|
|
186
|
+
rect.top = p.top;
|
|
187
|
+
rect.right = p.left + w;
|
|
188
|
+
rect.bottom = p.top + h;
|
|
189
|
+
rect.width = w;
|
|
190
|
+
rect.height = h;
|
|
191
|
+
return this.bounds=rect;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
getLocation() {
|
|
195
|
+
const img = this.getImage();
|
|
196
|
+
const loc = super.getLocation();
|
|
197
|
+
// 如果指定了宽度,但没有指定高宽,则等比缩放
|
|
198
|
+
if(loc.width && !loc.height) {
|
|
199
|
+
loc.height = loc.width / img.width * img.height;
|
|
200
|
+
}
|
|
201
|
+
else if(loc.height && !loc.width) {
|
|
202
|
+
loc.width = loc.height / img.height * img.width;
|
|
203
|
+
}
|
|
204
|
+
return loc;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* img对象
|
|
209
|
+
*
|
|
210
|
+
* @method getImage
|
|
211
|
+
* @return {img} 图片对象
|
|
212
|
+
*/
|
|
213
|
+
getImage() {
|
|
214
|
+
const src = this.image || this.style.src || this.style.image;
|
|
215
|
+
if(this.__img && this.__img.src && this.__img.src.indexOf(src) != -1) {
|
|
216
|
+
return this.__img;
|
|
217
|
+
}
|
|
218
|
+
else if(src && src.src) {
|
|
219
|
+
this.__img = src;
|
|
220
|
+
}
|
|
221
|
+
else if(typeof document !== 'undefined' && document.createElement) {
|
|
222
|
+
this.__img = document.createElement('img');
|
|
223
|
+
this.__img.onload = ()=>{
|
|
224
|
+
this.needUpdate = true;
|
|
225
|
+
};
|
|
226
|
+
if(src && typeof src == 'string') this.__img.src = src;
|
|
227
|
+
}
|
|
228
|
+
else if(this.graph.isWXMiniApp && this.graph.canvas && typeof src === 'string') {
|
|
229
|
+
// 图片对象
|
|
230
|
+
this.__img = this.graph.canvas.createImage();
|
|
231
|
+
this.__img.onload = ()=>{
|
|
232
|
+
this.needUpdate = true;
|
|
233
|
+
};
|
|
234
|
+
// 设置图片src
|
|
235
|
+
this.__img.src = src;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this.__img = src;
|
|
239
|
+
}
|
|
240
|
+
if(this.__img) this.image = this.__img.src;
|
|
241
|
+
return this.__img;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
245
|
export { jmImage };
|