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,360 +1,360 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
-
<style>
|
|
7
|
-
html,body{
|
|
8
|
-
margin:0;
|
|
9
|
-
padding: 0;
|
|
10
|
-
}
|
|
11
|
-
#mycanvas_container{
|
|
12
|
-
overflow: hidden;
|
|
13
|
-
}
|
|
14
|
-
</style>
|
|
15
|
-
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<div id="mycanvas_container"></div>
|
|
19
|
-
</body>
|
|
20
|
-
<script type="module">
|
|
21
|
-
import {jmGraph} from "../../index.js";
|
|
22
|
-
import {jmRect} from "../../src/shapes/jmRect.js";
|
|
23
|
-
import {jmPath} from "../../src/core/jmPath.js";
|
|
24
|
-
/**
|
|
25
|
-
* 测试
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
class jmTest extends jmPath {
|
|
29
|
-
constructor(params) {
|
|
30
|
-
if(!params) params = {};
|
|
31
|
-
super(params);
|
|
32
|
-
this.center = params.center || {x:0, y:0};
|
|
33
|
-
this.radius = params.radius || 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//定义属性
|
|
37
|
-
/**
|
|
38
|
-
* 中心点
|
|
39
|
-
* point格式:{x:0,y:0,m:true}
|
|
40
|
-
* @property center
|
|
41
|
-
* @type {point}
|
|
42
|
-
*/
|
|
43
|
-
get center() {
|
|
44
|
-
return this.property('center');
|
|
45
|
-
}
|
|
46
|
-
set center(v) {
|
|
47
|
-
return this.property('center', v);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* 中心点
|
|
51
|
-
* point格式:{x:0,y:0,m:true}
|
|
52
|
-
* @property center
|
|
53
|
-
* @type {point}
|
|
54
|
-
*/
|
|
55
|
-
get radius() {
|
|
56
|
-
return this.property('radius');
|
|
57
|
-
}
|
|
58
|
-
set radius(v) {
|
|
59
|
-
return this.property('radius', v);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 初始化图形点
|
|
64
|
-
* 控件都是由点形成
|
|
65
|
-
*
|
|
66
|
-
* @method initPoint
|
|
67
|
-
* @private
|
|
68
|
-
* @for jmArc
|
|
69
|
-
*/
|
|
70
|
-
initPoints() {
|
|
71
|
-
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
72
|
-
var location = this.getLocation();//获取位置参数
|
|
73
|
-
|
|
74
|
-
var cx = location.center.x ;
|
|
75
|
-
var cy = location.center.y ;
|
|
76
|
-
|
|
77
|
-
this.points = [];
|
|
78
|
-
|
|
79
|
-
//简单的画一个X
|
|
80
|
-
|
|
81
|
-
//根据半径计算x,y偏移量
|
|
82
|
-
//由于是圆,偏移量相同
|
|
83
|
-
var offw = Math.sqrt(location.radius * location.radius / 2);
|
|
84
|
-
//左上角到右下角对角线
|
|
85
|
-
this.points.push({x:cx - offw, y:cy-offw}, {x:cx + offw, y:cy+offw});
|
|
86
|
-
|
|
87
|
-
//左下角到右上角对角线
|
|
88
|
-
//画完上面的线后,需要重新移到这条线的起点,指定m:true即可
|
|
89
|
-
this.points.push({x:cx - offw, y:cy+offw, m:true}, {x:cx + offw, y:cy-offw});
|
|
90
|
-
|
|
91
|
-
return this.points;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 图片裁剪框
|
|
96
|
-
class ImageEditCover extends jmPath {
|
|
97
|
-
constructor(params = {}) {
|
|
98
|
-
super(params);
|
|
99
|
-
this.style.close = this.style.close || true;
|
|
100
|
-
this.init(params);
|
|
101
|
-
}
|
|
102
|
-
// 初始化控件元素
|
|
103
|
-
init(params) {
|
|
104
|
-
this.width = this.width || '100%';
|
|
105
|
-
this.height = this.height || '100%';
|
|
106
|
-
// 生成层
|
|
107
|
-
const rectStyle = {
|
|
108
|
-
stroke: 'transparent',
|
|
109
|
-
fill: 'rgba(100,100,100,0.4)',
|
|
110
|
-
lineWidth: 0.1,
|
|
111
|
-
zIndex: 1,
|
|
112
|
-
};
|
|
113
|
-
const graph = (this.graph || params.graph);
|
|
114
|
-
const leftRect = graph.createShape(jmRect, {
|
|
115
|
-
position:{x:0, y:0 },
|
|
116
|
-
width: 0,
|
|
117
|
-
height: '100%',
|
|
118
|
-
style: rectStyle,
|
|
119
|
-
interactive: false
|
|
120
|
-
});
|
|
121
|
-
const topRect = graph.createShape(jmRect, {
|
|
122
|
-
position:{x:0, y:0 },
|
|
123
|
-
width: '100%',
|
|
124
|
-
height: 0,
|
|
125
|
-
style: rectStyle,
|
|
126
|
-
interactive: false
|
|
127
|
-
});
|
|
128
|
-
const rightRect = graph.createShape(jmRect, {
|
|
129
|
-
position:{x:0, y:0 },
|
|
130
|
-
width: 0,
|
|
131
|
-
height: '100%',
|
|
132
|
-
style: rectStyle,
|
|
133
|
-
interactive: false
|
|
134
|
-
});
|
|
135
|
-
const bottomRect = graph.createShape(jmRect, {
|
|
136
|
-
position:{x:0, y:0 },
|
|
137
|
-
width: '100%',
|
|
138
|
-
height: 0,
|
|
139
|
-
style: rectStyle,
|
|
140
|
-
interactive: false
|
|
141
|
-
});
|
|
142
|
-
this.rects.push(leftRect, topRect, rightRect, bottomRect);
|
|
143
|
-
this.children.add(leftRect);
|
|
144
|
-
this.children.add(topRect);
|
|
145
|
-
this.children.add(rightRect);
|
|
146
|
-
this.children.add(bottomRect);
|
|
147
|
-
|
|
148
|
-
const controlStyle = {
|
|
149
|
-
lineWidth: 3,
|
|
150
|
-
stroke: '#fff',
|
|
151
|
-
zIndex: 100,
|
|
152
|
-
}
|
|
153
|
-
const c1 = graph.createShape(jmPath, {
|
|
154
|
-
style: controlStyle,
|
|
155
|
-
interactive: true
|
|
156
|
-
});
|
|
157
|
-
const c2 = graph.createShape(jmPath, {
|
|
158
|
-
style: controlStyle,
|
|
159
|
-
interactive: true
|
|
160
|
-
});
|
|
161
|
-
const c3 = graph.createShape(jmPath, {
|
|
162
|
-
style: controlStyle,
|
|
163
|
-
interactive: true
|
|
164
|
-
});
|
|
165
|
-
const c4 = graph.createShape(jmPath, {
|
|
166
|
-
style: controlStyle,
|
|
167
|
-
interactive: true
|
|
168
|
-
});
|
|
169
|
-
this.controls.push(c1, c2, c3, c4);
|
|
170
|
-
|
|
171
|
-
this.children.add(c1);
|
|
172
|
-
this.children.add(c2);
|
|
173
|
-
this.children.add(c3);
|
|
174
|
-
this.children.add(c4);
|
|
175
|
-
|
|
176
|
-
c1.canMove(true);
|
|
177
|
-
c2.canMove(true);
|
|
178
|
-
c3.canMove(true);
|
|
179
|
-
c4.canMove(true);
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// 裁剪的目录区域
|
|
184
|
-
// 最终改变结果也是这个参数
|
|
185
|
-
targetBounds = {
|
|
186
|
-
x: 0,
|
|
187
|
-
y: 0,
|
|
188
|
-
width: 0,
|
|
189
|
-
height: 0
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
rects = [];
|
|
193
|
-
// 操作折角
|
|
194
|
-
controls = [];
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* 初始化图形点
|
|
198
|
-
* 控件都是由点形成
|
|
199
|
-
*
|
|
200
|
-
* @method initPoint
|
|
201
|
-
* @private
|
|
202
|
-
* @for jmArc
|
|
203
|
-
*/
|
|
204
|
-
initPoints() {
|
|
205
|
-
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
206
|
-
const location = this.getLocation();//获取位置参数
|
|
207
|
-
|
|
208
|
-
const targetLeft = location.width / 2 - this.targetBounds.width / 2;
|
|
209
|
-
const targetRight = location.width / 2 + this.targetBounds.width / 2;
|
|
210
|
-
const targetBottom = this.targetBounds.y + this.targetBounds.height;
|
|
211
|
-
|
|
212
|
-
this.rects[0].width = targetLeft + 0.1;
|
|
213
|
-
|
|
214
|
-
this.rects[1].height = this.targetBounds.y;
|
|
215
|
-
this.rects[1].width = this.targetBounds.width + 0.1;
|
|
216
|
-
this.rects[1].position.x = targetLeft;
|
|
217
|
-
|
|
218
|
-
this.rects[2].width = location.width - targetRight;
|
|
219
|
-
this.rects[2].position.x = targetRight;
|
|
220
|
-
|
|
221
|
-
this.rects[3].height = location.height - targetBottom;
|
|
222
|
-
this.rects[3].width = this.targetBounds.width + 0.1;
|
|
223
|
-
this.rects[3].position.x = targetLeft;
|
|
224
|
-
this.rects[3].position.y = targetBottom;
|
|
225
|
-
|
|
226
|
-
return this.points;
|
|
227
|
-
}
|
|
228
|
-
resetControlsPosition() {
|
|
229
|
-
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
230
|
-
const location = this.getLocation();//获取位置参数
|
|
231
|
-
|
|
232
|
-
const targetLeft = location.width / 2 - this.targetBounds.width / 2;
|
|
233
|
-
const targetRight = location.width / 2 + this.targetBounds.width / 2;
|
|
234
|
-
const targetBottom = this.targetBounds.y + this.targetBounds.height;
|
|
235
|
-
|
|
236
|
-
// 操作折角位置
|
|
237
|
-
const controlWidth = 10;
|
|
238
|
-
const controlLineWidth = this.controls[0].style.lineWidth || 2;
|
|
239
|
-
this.controls[0].points = [
|
|
240
|
-
{
|
|
241
|
-
x: targetLeft - controlLineWidth/2,
|
|
242
|
-
y: this.targetBounds.y + controlWidth
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
x: targetLeft - controlLineWidth/2,
|
|
246
|
-
y: this.targetBounds.y - controlLineWidth/2
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
x: targetLeft + controlWidth,
|
|
250
|
-
y: this.targetBounds.y - controlLineWidth/2
|
|
251
|
-
}
|
|
252
|
-
];
|
|
253
|
-
|
|
254
|
-
this.controls[1].points = [
|
|
255
|
-
{
|
|
256
|
-
x: targetRight - controlWidth,
|
|
257
|
-
y: this.targetBounds.y - controlLineWidth/2
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
x: targetRight + controlLineWidth/2,
|
|
261
|
-
y: this.targetBounds.y - controlLineWidth/2
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
x: targetRight + controlLineWidth/2,
|
|
265
|
-
y: this.targetBounds.y + controlWidth
|
|
266
|
-
}
|
|
267
|
-
];
|
|
268
|
-
|
|
269
|
-
this.controls[2].points = [
|
|
270
|
-
{
|
|
271
|
-
x: targetRight - controlWidth,
|
|
272
|
-
y: targetBottom + controlLineWidth/2
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
x: targetRight + controlLineWidth/2,
|
|
276
|
-
y: targetBottom + controlLineWidth/2
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
x: targetRight + controlLineWidth/2,
|
|
280
|
-
y: targetBottom - controlWidth
|
|
281
|
-
}
|
|
282
|
-
];
|
|
283
|
-
|
|
284
|
-
this.controls[3].points = [
|
|
285
|
-
{
|
|
286
|
-
x: targetLeft - controlLineWidth/2,
|
|
287
|
-
y: targetBottom - controlWidth
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
x: targetLeft - controlLineWidth/2,
|
|
291
|
-
y: targetBottom + controlLineWidth/2
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
x: targetLeft + controlWidth,
|
|
295
|
-
y: targetBottom + controlLineWidth/2
|
|
296
|
-
}
|
|
297
|
-
];
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
var container = document.getElementById('mycanvas_container');
|
|
301
|
-
|
|
302
|
-
var g = jmGraph.create(container, {
|
|
303
|
-
width: 800,
|
|
304
|
-
height: 600,
|
|
305
|
-
mode: '2d',
|
|
306
|
-
style: {
|
|
307
|
-
fill: '#000'
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
init(g);
|
|
312
|
-
|
|
313
|
-
function init(g){
|
|
314
|
-
|
|
315
|
-
var style = {
|
|
316
|
-
stroke: '#23f24e',
|
|
317
|
-
lineWidth: 5,
|
|
318
|
-
shadow: '0,0,20,#fff'
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
//style.opacity = 0.2;
|
|
322
|
-
|
|
323
|
-
//创建一个自定义的控件
|
|
324
|
-
var t = g.createShape(jmTest, {
|
|
325
|
-
style: style,
|
|
326
|
-
center: {x:100,y:100},
|
|
327
|
-
radius: 20,
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
g.children.add(t);
|
|
331
|
-
t.canMove(true);
|
|
332
|
-
|
|
333
|
-
const editorCover = g.createShape(ImageEditCover, {
|
|
334
|
-
style: {
|
|
335
|
-
fill: 'transparent',
|
|
336
|
-
stroke: 'transparent',
|
|
337
|
-
},
|
|
338
|
-
interactive: true
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
editorCover.targetBounds = {
|
|
342
|
-
x: 100,
|
|
343
|
-
y: 100,
|
|
344
|
-
width: 200,
|
|
345
|
-
height: 300,
|
|
346
|
-
};
|
|
347
|
-
//editorCover.visible = false;
|
|
348
|
-
g.children.add(editorCover);
|
|
349
|
-
|
|
350
|
-
editorCover.resetControlsPosition();
|
|
351
|
-
|
|
352
|
-
function update() {
|
|
353
|
-
if(g.needUpdate) g.redraw();
|
|
354
|
-
requestAnimationFrame(update);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
update();
|
|
358
|
-
}
|
|
359
|
-
</script>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<style>
|
|
7
|
+
html,body{
|
|
8
|
+
margin:0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
}
|
|
11
|
+
#mycanvas_container{
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<div id="mycanvas_container"></div>
|
|
19
|
+
</body>
|
|
20
|
+
<script type="module">
|
|
21
|
+
import {jmGraph} from "../../index.js";
|
|
22
|
+
import {jmRect} from "../../src/shapes/jmRect.js";
|
|
23
|
+
import {jmPath} from "../../src/core/jmPath.js";
|
|
24
|
+
/**
|
|
25
|
+
* 测试
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
class jmTest extends jmPath {
|
|
29
|
+
constructor(params) {
|
|
30
|
+
if(!params) params = {};
|
|
31
|
+
super(params);
|
|
32
|
+
this.center = params.center || {x:0, y:0};
|
|
33
|
+
this.radius = params.radius || 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//定义属性
|
|
37
|
+
/**
|
|
38
|
+
* 中心点
|
|
39
|
+
* point格式:{x:0,y:0,m:true}
|
|
40
|
+
* @property center
|
|
41
|
+
* @type {point}
|
|
42
|
+
*/
|
|
43
|
+
get center() {
|
|
44
|
+
return this.property('center');
|
|
45
|
+
}
|
|
46
|
+
set center(v) {
|
|
47
|
+
return this.property('center', v);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 中心点
|
|
51
|
+
* point格式:{x:0,y:0,m:true}
|
|
52
|
+
* @property center
|
|
53
|
+
* @type {point}
|
|
54
|
+
*/
|
|
55
|
+
get radius() {
|
|
56
|
+
return this.property('radius');
|
|
57
|
+
}
|
|
58
|
+
set radius(v) {
|
|
59
|
+
return this.property('radius', v);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 初始化图形点
|
|
64
|
+
* 控件都是由点形成
|
|
65
|
+
*
|
|
66
|
+
* @method initPoint
|
|
67
|
+
* @private
|
|
68
|
+
* @for jmArc
|
|
69
|
+
*/
|
|
70
|
+
initPoints() {
|
|
71
|
+
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
72
|
+
var location = this.getLocation();//获取位置参数
|
|
73
|
+
|
|
74
|
+
var cx = location.center.x ;
|
|
75
|
+
var cy = location.center.y ;
|
|
76
|
+
|
|
77
|
+
this.points = [];
|
|
78
|
+
|
|
79
|
+
//简单的画一个X
|
|
80
|
+
|
|
81
|
+
//根据半径计算x,y偏移量
|
|
82
|
+
//由于是圆,偏移量相同
|
|
83
|
+
var offw = Math.sqrt(location.radius * location.radius / 2);
|
|
84
|
+
//左上角到右下角对角线
|
|
85
|
+
this.points.push({x:cx - offw, y:cy-offw}, {x:cx + offw, y:cy+offw});
|
|
86
|
+
|
|
87
|
+
//左下角到右上角对角线
|
|
88
|
+
//画完上面的线后,需要重新移到这条线的起点,指定m:true即可
|
|
89
|
+
this.points.push({x:cx - offw, y:cy+offw, m:true}, {x:cx + offw, y:cy-offw});
|
|
90
|
+
|
|
91
|
+
return this.points;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 图片裁剪框
|
|
96
|
+
class ImageEditCover extends jmPath {
|
|
97
|
+
constructor(params = {}) {
|
|
98
|
+
super(params);
|
|
99
|
+
this.style.close = this.style.close || true;
|
|
100
|
+
this.init(params);
|
|
101
|
+
}
|
|
102
|
+
// 初始化控件元素
|
|
103
|
+
init(params) {
|
|
104
|
+
this.width = this.width || '100%';
|
|
105
|
+
this.height = this.height || '100%';
|
|
106
|
+
// 生成层
|
|
107
|
+
const rectStyle = {
|
|
108
|
+
stroke: 'transparent',
|
|
109
|
+
fill: 'rgba(100,100,100,0.4)',
|
|
110
|
+
lineWidth: 0.1,
|
|
111
|
+
zIndex: 1,
|
|
112
|
+
};
|
|
113
|
+
const graph = (this.graph || params.graph);
|
|
114
|
+
const leftRect = graph.createShape(jmRect, {
|
|
115
|
+
position:{x:0, y:0 },
|
|
116
|
+
width: 0,
|
|
117
|
+
height: '100%',
|
|
118
|
+
style: rectStyle,
|
|
119
|
+
interactive: false
|
|
120
|
+
});
|
|
121
|
+
const topRect = graph.createShape(jmRect, {
|
|
122
|
+
position:{x:0, y:0 },
|
|
123
|
+
width: '100%',
|
|
124
|
+
height: 0,
|
|
125
|
+
style: rectStyle,
|
|
126
|
+
interactive: false
|
|
127
|
+
});
|
|
128
|
+
const rightRect = graph.createShape(jmRect, {
|
|
129
|
+
position:{x:0, y:0 },
|
|
130
|
+
width: 0,
|
|
131
|
+
height: '100%',
|
|
132
|
+
style: rectStyle,
|
|
133
|
+
interactive: false
|
|
134
|
+
});
|
|
135
|
+
const bottomRect = graph.createShape(jmRect, {
|
|
136
|
+
position:{x:0, y:0 },
|
|
137
|
+
width: '100%',
|
|
138
|
+
height: 0,
|
|
139
|
+
style: rectStyle,
|
|
140
|
+
interactive: false
|
|
141
|
+
});
|
|
142
|
+
this.rects.push(leftRect, topRect, rightRect, bottomRect);
|
|
143
|
+
this.children.add(leftRect);
|
|
144
|
+
this.children.add(topRect);
|
|
145
|
+
this.children.add(rightRect);
|
|
146
|
+
this.children.add(bottomRect);
|
|
147
|
+
|
|
148
|
+
const controlStyle = {
|
|
149
|
+
lineWidth: 3,
|
|
150
|
+
stroke: '#fff',
|
|
151
|
+
zIndex: 100,
|
|
152
|
+
}
|
|
153
|
+
const c1 = graph.createShape(jmPath, {
|
|
154
|
+
style: controlStyle,
|
|
155
|
+
interactive: true
|
|
156
|
+
});
|
|
157
|
+
const c2 = graph.createShape(jmPath, {
|
|
158
|
+
style: controlStyle,
|
|
159
|
+
interactive: true
|
|
160
|
+
});
|
|
161
|
+
const c3 = graph.createShape(jmPath, {
|
|
162
|
+
style: controlStyle,
|
|
163
|
+
interactive: true
|
|
164
|
+
});
|
|
165
|
+
const c4 = graph.createShape(jmPath, {
|
|
166
|
+
style: controlStyle,
|
|
167
|
+
interactive: true
|
|
168
|
+
});
|
|
169
|
+
this.controls.push(c1, c2, c3, c4);
|
|
170
|
+
|
|
171
|
+
this.children.add(c1);
|
|
172
|
+
this.children.add(c2);
|
|
173
|
+
this.children.add(c3);
|
|
174
|
+
this.children.add(c4);
|
|
175
|
+
|
|
176
|
+
c1.canMove(true);
|
|
177
|
+
c2.canMove(true);
|
|
178
|
+
c3.canMove(true);
|
|
179
|
+
c4.canMove(true);
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 裁剪的目录区域
|
|
184
|
+
// 最终改变结果也是这个参数
|
|
185
|
+
targetBounds = {
|
|
186
|
+
x: 0,
|
|
187
|
+
y: 0,
|
|
188
|
+
width: 0,
|
|
189
|
+
height: 0
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
rects = [];
|
|
193
|
+
// 操作折角
|
|
194
|
+
controls = [];
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 初始化图形点
|
|
198
|
+
* 控件都是由点形成
|
|
199
|
+
*
|
|
200
|
+
* @method initPoint
|
|
201
|
+
* @private
|
|
202
|
+
* @for jmArc
|
|
203
|
+
*/
|
|
204
|
+
initPoints() {
|
|
205
|
+
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
206
|
+
const location = this.getLocation();//获取位置参数
|
|
207
|
+
|
|
208
|
+
const targetLeft = location.width / 2 - this.targetBounds.width / 2;
|
|
209
|
+
const targetRight = location.width / 2 + this.targetBounds.width / 2;
|
|
210
|
+
const targetBottom = this.targetBounds.y + this.targetBounds.height;
|
|
211
|
+
|
|
212
|
+
this.rects[0].width = targetLeft + 0.1;
|
|
213
|
+
|
|
214
|
+
this.rects[1].height = this.targetBounds.y;
|
|
215
|
+
this.rects[1].width = this.targetBounds.width + 0.1;
|
|
216
|
+
this.rects[1].position.x = targetLeft;
|
|
217
|
+
|
|
218
|
+
this.rects[2].width = location.width - targetRight;
|
|
219
|
+
this.rects[2].position.x = targetRight;
|
|
220
|
+
|
|
221
|
+
this.rects[3].height = location.height - targetBottom;
|
|
222
|
+
this.rects[3].width = this.targetBounds.width + 0.1;
|
|
223
|
+
this.rects[3].position.x = targetLeft;
|
|
224
|
+
this.rects[3].position.y = targetBottom;
|
|
225
|
+
|
|
226
|
+
return this.points;
|
|
227
|
+
}
|
|
228
|
+
resetControlsPosition() {
|
|
229
|
+
//可以获取当前控件的左上坐标,可以用来画相对位置
|
|
230
|
+
const location = this.getLocation();//获取位置参数
|
|
231
|
+
|
|
232
|
+
const targetLeft = location.width / 2 - this.targetBounds.width / 2;
|
|
233
|
+
const targetRight = location.width / 2 + this.targetBounds.width / 2;
|
|
234
|
+
const targetBottom = this.targetBounds.y + this.targetBounds.height;
|
|
235
|
+
|
|
236
|
+
// 操作折角位置
|
|
237
|
+
const controlWidth = 10;
|
|
238
|
+
const controlLineWidth = this.controls[0].style.lineWidth || 2;
|
|
239
|
+
this.controls[0].points = [
|
|
240
|
+
{
|
|
241
|
+
x: targetLeft - controlLineWidth/2,
|
|
242
|
+
y: this.targetBounds.y + controlWidth
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
x: targetLeft - controlLineWidth/2,
|
|
246
|
+
y: this.targetBounds.y - controlLineWidth/2
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
x: targetLeft + controlWidth,
|
|
250
|
+
y: this.targetBounds.y - controlLineWidth/2
|
|
251
|
+
}
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
this.controls[1].points = [
|
|
255
|
+
{
|
|
256
|
+
x: targetRight - controlWidth,
|
|
257
|
+
y: this.targetBounds.y - controlLineWidth/2
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
x: targetRight + controlLineWidth/2,
|
|
261
|
+
y: this.targetBounds.y - controlLineWidth/2
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
x: targetRight + controlLineWidth/2,
|
|
265
|
+
y: this.targetBounds.y + controlWidth
|
|
266
|
+
}
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
this.controls[2].points = [
|
|
270
|
+
{
|
|
271
|
+
x: targetRight - controlWidth,
|
|
272
|
+
y: targetBottom + controlLineWidth/2
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
x: targetRight + controlLineWidth/2,
|
|
276
|
+
y: targetBottom + controlLineWidth/2
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
x: targetRight + controlLineWidth/2,
|
|
280
|
+
y: targetBottom - controlWidth
|
|
281
|
+
}
|
|
282
|
+
];
|
|
283
|
+
|
|
284
|
+
this.controls[3].points = [
|
|
285
|
+
{
|
|
286
|
+
x: targetLeft - controlLineWidth/2,
|
|
287
|
+
y: targetBottom - controlWidth
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
x: targetLeft - controlLineWidth/2,
|
|
291
|
+
y: targetBottom + controlLineWidth/2
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
x: targetLeft + controlWidth,
|
|
295
|
+
y: targetBottom + controlLineWidth/2
|
|
296
|
+
}
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
var container = document.getElementById('mycanvas_container');
|
|
301
|
+
|
|
302
|
+
var g = jmGraph.create(container, {
|
|
303
|
+
width: 800,
|
|
304
|
+
height: 600,
|
|
305
|
+
mode: '2d',
|
|
306
|
+
style: {
|
|
307
|
+
fill: '#000'
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
init(g);
|
|
312
|
+
|
|
313
|
+
function init(g){
|
|
314
|
+
|
|
315
|
+
var style = {
|
|
316
|
+
stroke: '#23f24e',
|
|
317
|
+
lineWidth: 5,
|
|
318
|
+
shadow: '0,0,20,#fff'
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
//style.opacity = 0.2;
|
|
322
|
+
|
|
323
|
+
//创建一个自定义的控件
|
|
324
|
+
var t = g.createShape(jmTest, {
|
|
325
|
+
style: style,
|
|
326
|
+
center: {x:100,y:100},
|
|
327
|
+
radius: 20,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
g.children.add(t);
|
|
331
|
+
t.canMove(true);
|
|
332
|
+
|
|
333
|
+
const editorCover = g.createShape(ImageEditCover, {
|
|
334
|
+
style: {
|
|
335
|
+
fill: 'transparent',
|
|
336
|
+
stroke: 'transparent',
|
|
337
|
+
},
|
|
338
|
+
interactive: true
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
editorCover.targetBounds = {
|
|
342
|
+
x: 100,
|
|
343
|
+
y: 100,
|
|
344
|
+
width: 200,
|
|
345
|
+
height: 300,
|
|
346
|
+
};
|
|
347
|
+
//editorCover.visible = false;
|
|
348
|
+
g.children.add(editorCover);
|
|
349
|
+
|
|
350
|
+
editorCover.resetControlsPosition();
|
|
351
|
+
|
|
352
|
+
function update() {
|
|
353
|
+
if(g.needUpdate) g.redraw();
|
|
354
|
+
requestAnimationFrame(update);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
update();
|
|
358
|
+
}
|
|
359
|
+
</script>
|
|
360
360
|
</html>
|