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.
Files changed (77) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +251 -428
  3. package/build/gulpfile.js +142 -142
  4. package/build/package-lock.json +10666 -0
  5. package/build/package.json +71 -71
  6. package/dev.js +9 -9
  7. package/dist/jmgraph.core.min.js +1 -1
  8. package/dist/jmgraph.core.min.js.map +1 -1
  9. package/dist/jmgraph.js +3500 -2668
  10. package/dist/jmgraph.min.js +1 -1
  11. package/example/ball.html +216 -216
  12. package/example/base.html +111 -111
  13. package/example/canvas.html +53 -53
  14. package/example/cell.html +283 -283
  15. package/example/controls/arc.html +128 -128
  16. package/example/controls/arrowline.html +77 -77
  17. package/example/controls/bezier.html +298 -298
  18. package/example/controls/img.html +96 -96
  19. package/example/controls/label.html +86 -86
  20. package/example/controls/line.html +172 -172
  21. package/example/controls/prismatic.html +62 -62
  22. package/example/controls/rect.html +63 -63
  23. package/example/controls/resize.html +111 -111
  24. package/example/controls/test.html +359 -359
  25. package/example/es.html +69 -69
  26. package/example/es5module.html +62 -63
  27. package/example/heartarc.html +115 -115
  28. package/example/index.html +46 -46
  29. package/example/js/require.js +4 -4
  30. package/example/love/img/bling/bling.tps +265 -265
  31. package/example/love/img/bling.json +87 -87
  32. package/example/love/img/bling.tps +295 -295
  33. package/example/love/img/love.json +95 -95
  34. package/example/love/img/love.tps +315 -315
  35. package/example/love/img/qq/qq.tps +399 -399
  36. package/example/love/img/qq.json +242 -242
  37. package/example/love/index.html +40 -40
  38. package/example/love/js/game.js +558 -558
  39. package/example/music.html +210 -210
  40. package/example/node/test.js +137 -137
  41. package/example/pdf.html +186 -186
  42. package/example/progress.html +172 -172
  43. package/example/pso.html +147 -147
  44. package/example/sort.html +804 -815
  45. package/example/tweenjs.html +83 -83
  46. package/example/webgl.html +278 -278
  47. package/example/xfj/index.html +331 -331
  48. package/example/xfj/shake.js +48 -48
  49. package/example/xfj/testori.html +75 -75
  50. package/index.js +99 -99
  51. package/package.json +58 -56
  52. package/src/core/jmControl.js +1376 -1531
  53. package/src/core/jmEvents.js +240 -281
  54. package/src/core/jmGradient.js +231 -231
  55. package/src/core/jmGraph.js +569 -569
  56. package/src/core/jmList.js +92 -157
  57. package/src/core/jmObject.js +83 -103
  58. package/src/core/jmPath.js +35 -35
  59. package/src/core/jmProperty.js +71 -110
  60. package/src/core/jmShadow.js +65 -65
  61. package/src/core/jmUtils.js +906 -919
  62. package/src/lib/earcut.js +680 -680
  63. package/src/lib/earcut.md +73 -73
  64. package/src/lib/webgl/base.js +522 -452
  65. package/src/lib/webgl/core/buffer.js +48 -48
  66. package/src/lib/webgl/core/mapSize.js +40 -40
  67. package/src/lib/webgl/core/mapType.js +43 -43
  68. package/src/lib/webgl/core/program.js +138 -138
  69. package/src/lib/webgl/core/shader.js +13 -13
  70. package/src/lib/webgl/core/texture.js +60 -60
  71. package/src/lib/webgl/gradient.js +168 -168
  72. package/src/lib/webgl/index.js +137 -11
  73. package/src/lib/webgl/path.js +568 -561
  74. package/src/shapes/jmArrowLine.js +36 -36
  75. package/src/shapes/jmImage.js +244 -244
  76. package/src/shapes/jmLabel.js +271 -271
  77. package/src/shapes/jmResize.js +332 -330
@@ -1,331 +1,333 @@
1
- import {jmRect} from "./jmRect.js";
2
- /**
3
- * 可拉伸的缩放控件
4
- * 继承jmRect
5
- * 如果此控件加入到了当前控制的对象的子控件中,请在参数中加入movable:false,否则导致当前控件会偏离被控制的控件。
6
- *
7
- * @class jmResize
8
- * @extends jmRect
9
- */
10
- export default class jmResize extends jmRect {
11
-
12
- constructor(params, t='jmResize') {
13
- params = params || {};
14
- params.isRegular = true;// 规则的
15
-
16
- super(params, t);
17
- //是否可拉伸
18
- this.resizable = params.resizable === false?false:true;
19
- this.movable = params.movable;
20
- this.rectSize = params.rectSize || 8;
21
- this.style.close = this.style.close || true;
22
-
23
- // 方块鼠标指针方向
24
- this.rectCursors = ['w-resize','nw-resize','n-resize','ne-resize','e-resize','se-resize','s-resize','sw-resize'];
25
-
26
- this.init(params);
27
- }
28
- /**
29
- * 拉动的小方块大小
30
- * @property rectSize
31
- * @type {number}
32
- */
33
- get rectSize() {
34
- return this.property('rectSize');
35
- }
36
- set rectSize(v) {
37
- return this.property('rectSize', v);
38
- }
39
-
40
- /**
41
- * 是否可以拉大缩小
42
- * @property resizable
43
- * @type {boolean}
44
- */
45
- get resizable() {
46
- return this.property('resizable');
47
- }
48
- set resizable(v) {
49
- return this.property('resizable', v);
50
- }
51
-
52
- /**
53
- * 初始化控件的8个拉伸方框
54
- *
55
- * @method init
56
- * @private
57
- */
58
- init(params) {
59
- //如果不可改变大小。则直接退出
60
- if(this.resizable === false) return;
61
- this.resizeRects = [];
62
- let rs = this.rectSize;
63
- let rectStyle = this.style.rectStyle || {
64
- stroke: 'red',
65
- fill: 'transparent',
66
- lineWidth: 2,
67
- close: true,
68
- zIndex:100
69
- };
70
- rectStyle.close = true;
71
- rectStyle.fill = rectStyle.fill || 'transparent';
72
-
73
- for(let i = 0; i<8; i++) {
74
- //生成改变大小方块
75
- const r = (this.graph || params.graph).createShape(jmRect,{
76
- position:{x:0,y:0},
77
- width: rs,
78
- height: rs,
79
- style: rectStyle,
80
- interactive: true
81
- });
82
- r.index = i;
83
- r.visible = true;
84
- this.resizeRects.push(r);
85
- this.children.add(r);
86
- r.canMove(true,this.graph);
87
- }
88
- this.reset(0,0,0,0);//初始化位置
89
- //绑定其事件
90
- this.bindRectEvents();
91
- }
92
-
93
- /**
94
- * 绑定周边拉伸的小方块事件
95
- *
96
- * @method bindRectEvents
97
- * @private
98
- */
99
- bindRectEvents() {
100
- for(let i =0; i<this.resizeRects.length; i++) {
101
- const r = this.resizeRects[i];
102
- //小方块移动监听
103
- r.on('move',function(arg) {
104
- let px=0, py=0, dx=0, dy=0;
105
- if(this.index == 0) {
106
- dx = - arg.offsetX;
107
- px = arg.offsetX;
108
- }
109
- else if(this.index == 1) {
110
- dx = - arg.offsetX;
111
- px = arg.offsetX;
112
- dy = - arg.offsetY;
113
- py = arg.offsetY;
114
- }
115
- else if(this.index == 2) {
116
- dy = -arg.offsetY;
117
- py = arg.offsetY;
118
- }
119
- else if(this.index == 3) {
120
- dx = arg.offsetX;
121
- dy = -arg.offsetY;
122
- py = arg.offsetY;
123
- }
124
- else if(this.index == 4) {
125
- dx = arg.offsetX;
126
- }
127
- else if(this.index == 5) {
128
- dx = arg.offsetX;
129
- dy = arg.offsetY;
130
- }
131
- else if(this.index == 6) {
132
- dy = arg.offsetY;
133
- }
134
- else if(this.index == 7) {
135
- dx = - arg.offsetX;
136
- dx = - arg.offsetX;
137
- px = arg.offsetX;
138
- dy = arg.offsetY;
139
- }
140
- //重新定位
141
- this.parent.reset(px, py, dx, dy);
142
- this.needUpdate = true;
143
- });
144
- //鼠标指针
145
- r.bind('mousemove', function() {
146
- // 如果有旋转方位,则重新定义小块的作用
147
- const rotation = this.parent.getRotation();
148
- let cursor = this.parent.rectCursors[this.index];
149
-
150
- // 旋转一定角度后的位置
151
- const position = rotation && rotation.angle? this.graph.utils.rotatePoints(this.graph.utils.clone(this.position), rotation, rotation.angle): this.position;
152
- const center = {
153
- x: this.parent.width / 2,
154
- y: this.parent.height / 2
155
- };
156
-
157
- this.rotationAngleByCenter = Math.atan((position.y - center.y) / (position.x - center.x));// 与中心连线和x轴的夹角
158
- // 把90度分割成三个区域,不同的指针
159
- const angleSplit1 = Math.atan(center.y / center.x) / 2;
160
- const angleSplit2 = angleSplit1 * 2 + Math.PI / 4;
161
-
162
- // 如果在左边,
163
- if(position.x < center.x) {
164
- if(this.rotationAngleByCenter >= -angleSplit1 && this.rotationAngleByCenter <= angleSplit1) {
165
- cursor = this.parent.rectCursors[0];
166
- }
167
- else if(this.rotationAngleByCenter > angleSplit1 && this.rotationAngleByCenter < angleSplit2) {
168
- cursor = this.parent.rectCursors[1];
169
- }
170
- else if(this.rotationAngleByCenter >= angleSplit2) {
171
- cursor = this.parent.rectCursors[2];
172
- }
173
- else if(this.rotationAngleByCenter <= -angleSplit1 && this.rotationAngleByCenter > -angleSplit2) {
174
- cursor = this.parent.rectCursors[7];
175
- }
176
- else if(this.rotationAngleByCenter <= -angleSplit2) {
177
- cursor = this.parent.rectCursors[6];
178
- }
179
- }
180
- else {
181
- if(this.rotationAngleByCenter >= -angleSplit1 && this.rotationAngleByCenter <= angleSplit1) {
182
- cursor = this.parent.rectCursors[4];
183
- }
184
- else if(this.rotationAngleByCenter > angleSplit1 && this.rotationAngleByCenter < angleSplit2) {
185
- cursor = this.parent.rectCursors[5];
186
- }
187
- else if(this.rotationAngleByCenter >= angleSplit2) {
188
- cursor = this.parent.rectCursors[6];
189
- }
190
- else if(this.rotationAngleByCenter <= -angleSplit1 && this.rotationAngleByCenter > -angleSplit2) {
191
- cursor = this.parent.rectCursors[3];
192
- }
193
- else if(this.rotationAngleByCenter <= -angleSplit2) {
194
- cursor = this.parent.rectCursors[2];
195
- }
196
- }
197
-
198
- this.cursor = cursor;
199
- });
200
- r.bind('mouseleave', function() {
201
- this.cursor = 'default';
202
- });
203
- }
204
- /*
205
- // 如果是双指开始滑动
206
- let touchPositions;
207
- this.on('touchstart', (evt) => {
208
- if(evt.touches && evt.touches.legnth === 2) {
209
- touchPositions = evt.touches;
210
- }
211
- });
212
-
213
- // 如果是双指滑动
214
- //计算二手指滑动距离,然后再通过在父容器中的占比得到缩放比例
215
- this.on('touchmove', (evt) => {
216
- if(touchPositions && evt.touches && evt.touches.length == 2) {
217
- //上次滑动二指的距离
218
- const preOffX = touchPositions[0].x - touchPositions[1].x;
219
- const preOffY = touchPositions[0].y - touchPositions[1].y;
220
- const preDis = Math.sqrt(preOffX * preOffX + preOffY * preOffY);
221
- //当次滑动二指的距离
222
- const curOffX = evt.touches[0].x - evt.touches[1].x;
223
- const curOffY = evt.touches[0].y - evt.touches[1].y;
224
- const curDis = Math.sqrt(curOffX * curOffX + curOffY * curOffY);
225
-
226
- //const disx = Math.abs(preOffX - curOffX);//x轴滑行的距离
227
- //const disy = Math.abs(preOffY - curOffY);//y轴滑行的距离
228
-
229
- const offset = curDis - preDis;
230
-
231
- this.reset(0, 0, offset, offset);
232
- }
233
- });
234
- // 结束滑动
235
- this.on('touchend touchcancel', (evt) => {
236
- touchPositions = null;
237
- });*/
238
- }
239
-
240
- /**
241
- * 按移动偏移量重置当前对象,并触发大小和位置改变事件
242
- * @method reset
243
- * @param {number} px 位置X轴偏移
244
- * @param {number} py 位置y轴偏移
245
- * @param {number} dx 大小x轴偏移
246
- * @param {number} dy 大小y轴偏移
247
- */
248
- reset(px, py, dx, dy) {
249
- const minWidth = typeof this.style.minWidth=='undefined'?5:this.style.minWidth;
250
- const minHeight = typeof this.style.minHeight=='undefined'?5:this.style.minHeight;
251
-
252
- const location = this.getLocation();
253
- if(dx != 0 || dy != 0) {
254
- const w = location.width + dx;
255
- const h = location.height + dy;
256
- if(w >= minWidth || h >= minHeight) {
257
- if(w >= minWidth) {
258
- this.width = w;
259
- }
260
- else {
261
- px = 0;
262
- dx = 0;
263
- }
264
- if(h >= minHeight) {
265
- this.height = h;
266
- }
267
- else {
268
- py = 0;
269
- dy = 0;
270
- }
271
- //如果当前控件能移动才能改变其位置
272
- if(this.movable !== false && (px||py)) {
273
- const p = this.position;
274
- p.x = location.left + px;
275
- p.y = location.top + py;
276
- this.position = p;
277
- }
278
- //触发大小改变事件
279
- this.emit('resize',px,py,dx,dy);
280
- }
281
- }
282
-
283
- for(let i in this.resizeRects) {
284
- const r = this.resizeRects[i];
285
- switch(r.index) {
286
- case 0: {
287
- r.position.x = -r.width / 2;
288
- r.position.y = (location.height - r.height) / 2;
289
- break;
290
- }
291
- case 1: {
292
- r.position.x = -r.width / 2;
293
- r.position.y = -r.height / 2;
294
- break;
295
- }
296
- case 2: {
297
- r.position.x = (location.width - r.width) / 2;
298
- r.position.y = -r.height / 2;
299
- break;
300
- }
301
- case 3: {
302
- r.position.x = location.width - r.width / 2;
303
- r.position.y = -r.height / 2;
304
- break;
305
- }
306
- case 4: {
307
- r.position.x = location.width - r.width / 2;
308
- r.position.y = (location.height - r.height) / 2;
309
- break;
310
- }
311
- case 5: {
312
- r.position.x = location.width - r.width / 2;
313
- r.position.y = location.height - r.height /2;
314
- break;
315
- }
316
- case 6: {
317
- r.position.x = (location.width - r.height) / 2;
318
- r.position.y = location.height - r.height / 2;
319
- break;
320
- }
321
- case 7: {
322
- r.position.x = -r.width / 2;
323
- r.position.y = location.height - r.height / 2;
324
- break;
325
- }
326
- }
327
- }
328
- }
329
- }
330
-
1
+ import {jmRect} from "./jmRect.js";
2
+ /**
3
+ * 可拉伸的缩放控件
4
+ * 继承jmRect
5
+ * 如果此控件加入到了当前控制的对象的子控件中,请在参数中加入movable:false,否则导致当前控件会偏离被控制的控件。
6
+ *
7
+ * @class jmResize
8
+ * @extends jmRect
9
+ */
10
+ export default class jmResize extends jmRect {
11
+
12
+ constructor(params, t='jmResize') {
13
+ params = params || {};
14
+ params.isRegular = true;// 规则的
15
+
16
+ super(params, t);
17
+ //是否可拉伸
18
+ this.resizable = params.resizable === false?false:true;
19
+ this.movable = params.movable;
20
+ this.rectSize = params.rectSize || 8;
21
+ this.style.close = this.style.close || true;
22
+
23
+ // 方块鼠标指针方向
24
+ this.rectCursors = ['w-resize','nw-resize','n-resize','ne-resize','e-resize','se-resize','s-resize','sw-resize'];
25
+
26
+ this.init(params);
27
+ }
28
+ /**
29
+ * 拉动的小方块大小
30
+ * @property rectSize
31
+ * @type {number}
32
+ */
33
+ get rectSize() {
34
+ return this.property('rectSize');
35
+ }
36
+ set rectSize(v) {
37
+ return this.property('rectSize', v);
38
+ }
39
+
40
+ /**
41
+ * 是否可以拉大缩小
42
+ * @property resizable
43
+ * @type {boolean}
44
+ */
45
+ get resizable() {
46
+ return this.property('resizable');
47
+ }
48
+ set resizable(v) {
49
+ return this.property('resizable', v);
50
+ }
51
+
52
+ /**
53
+ * 初始化控件的8个拉伸方框
54
+ *
55
+ * @method init
56
+ * @private
57
+ */
58
+ init(params) {
59
+ //如果不可改变大小。则直接退出
60
+ if(this.resizable === false) return;
61
+ this.resizeRects = [];
62
+ let rs = this.rectSize;
63
+ let rectStyle = this.style.rectStyle || {
64
+ stroke: 'red',
65
+ fill: 'transparent',
66
+ lineWidth: 2,
67
+ close: true,
68
+ zIndex:100
69
+ };
70
+ rectStyle.close = true;
71
+ rectStyle.fill = rectStyle.fill || 'transparent';
72
+
73
+ for(let i = 0; i<8; i++) {
74
+ //生成改变大小方块
75
+ const r = (this.graph || params.graph).createShape(jmRect,{
76
+ position:{x:0,y:0},
77
+ width: rs,
78
+ height: rs,
79
+ style: rectStyle,
80
+ interactive: true
81
+ });
82
+ r.index = i;
83
+ r.visible = true;
84
+ this.resizeRects.push(r);
85
+ this.children.add(r);
86
+ r.canMove(true,this.graph);
87
+ }
88
+ this.reset(0,0,0,0);//初始化位置
89
+ //绑定其事件
90
+ this.bindRectEvents();
91
+ }
92
+
93
+ /**
94
+ * 绑定周边拉伸的小方块事件
95
+ *
96
+ * @method bindRectEvents
97
+ * @private
98
+ */
99
+ bindRectEvents() {
100
+ for(let i =0; i<this.resizeRects.length; i++) {
101
+ const r = this.resizeRects[i];
102
+ //小方块移动监听
103
+ r.on('move',function(arg) {
104
+ arg.cancel = true;
105
+ let px=0, py=0, dx=0, dy=0;
106
+ if(this.index == 0) {
107
+ dx = - arg.offsetX;
108
+ px = arg.offsetX;
109
+ }
110
+ else if(this.index == 1) {
111
+ dx = - arg.offsetX;
112
+ px = arg.offsetX;
113
+ dy = - arg.offsetY;
114
+ py = arg.offsetY;
115
+ }
116
+ else if(this.index == 2) {
117
+ dy = -arg.offsetY;
118
+ py = arg.offsetY;
119
+ }
120
+ else if(this.index == 3) {
121
+ dx = arg.offsetX;
122
+ dy = -arg.offsetY;
123
+ py = arg.offsetY;
124
+ }
125
+ else if(this.index == 4) {
126
+ dx = arg.offsetX;
127
+ }
128
+ else if(this.index == 5) {
129
+ dx = arg.offsetX;
130
+ dy = arg.offsetY;
131
+ }
132
+ else if(this.index == 6) {
133
+ dy = arg.offsetY;
134
+ }
135
+ else if(this.index == 7) {
136
+ dx = - arg.offsetX;
137
+ dx = - arg.offsetX;
138
+ px = arg.offsetX;
139
+ dy = arg.offsetY;
140
+ }
141
+ //重新定位
142
+ this.parent.reset(px, py, dx, dy);
143
+ });
144
+ //鼠标指针
145
+ r.bind('mousemove', function() {
146
+ // 如果有旋转方位,则重新定义小块的作用
147
+ const rotation = this.parent.getRotation();
148
+ let cursor = this.parent.rectCursors[this.index];
149
+
150
+ // 旋转一定角度后的位置
151
+ const position = rotation && rotation.angle? this.graph.utils.rotatePoints(this.graph.utils.clone(this.position), rotation, rotation.angle): this.position;
152
+ const center = {
153
+ x: this.parent.width / 2,
154
+ y: this.parent.height / 2
155
+ };
156
+
157
+ this.rotationAngleByCenter = Math.atan((position.y - center.y) / (position.x - center.x));// 与中心连线和x轴的夹角
158
+ // 把90度分割成三个区域,不同的指针
159
+ const angleSplit1 = Math.atan(center.y / center.x) / 2;
160
+ const angleSplit2 = angleSplit1 * 2 + Math.PI / 4;
161
+
162
+ // 如果在左边,
163
+ if(position.x < center.x) {
164
+ if(this.rotationAngleByCenter >= -angleSplit1 && this.rotationAngleByCenter <= angleSplit1) {
165
+ cursor = this.parent.rectCursors[0];
166
+ }
167
+ else if(this.rotationAngleByCenter > angleSplit1 && this.rotationAngleByCenter < angleSplit2) {
168
+ cursor = this.parent.rectCursors[1];
169
+ }
170
+ else if(this.rotationAngleByCenter >= angleSplit2) {
171
+ cursor = this.parent.rectCursors[2];
172
+ }
173
+ else if(this.rotationAngleByCenter <= -angleSplit1 && this.rotationAngleByCenter > -angleSplit2) {
174
+ cursor = this.parent.rectCursors[7];
175
+ }
176
+ else if(this.rotationAngleByCenter <= -angleSplit2) {
177
+ cursor = this.parent.rectCursors[6];
178
+ }
179
+ }
180
+ else {
181
+ if(this.rotationAngleByCenter >= -angleSplit1 && this.rotationAngleByCenter <= angleSplit1) {
182
+ cursor = this.parent.rectCursors[4];
183
+ }
184
+ else if(this.rotationAngleByCenter > angleSplit1 && this.rotationAngleByCenter < angleSplit2) {
185
+ cursor = this.parent.rectCursors[5];
186
+ }
187
+ else if(this.rotationAngleByCenter >= angleSplit2) {
188
+ cursor = this.parent.rectCursors[6];
189
+ }
190
+ else if(this.rotationAngleByCenter <= -angleSplit1 && this.rotationAngleByCenter > -angleSplit2) {
191
+ cursor = this.parent.rectCursors[3];
192
+ }
193
+ else if(this.rotationAngleByCenter <= -angleSplit2) {
194
+ cursor = this.parent.rectCursors[2];
195
+ }
196
+ }
197
+
198
+ this.cursor = cursor;
199
+ });
200
+ r.bind('mouseleave', function() {
201
+ this.cursor = 'default';
202
+ });
203
+ }
204
+ /*
205
+ // 如果是双指开始滑动
206
+ let touchPositions;
207
+ this.on('touchstart', (evt) => {
208
+ if(evt.touches && evt.touches.legnth === 2) {
209
+ touchPositions = evt.touches;
210
+ }
211
+ });
212
+
213
+ // 如果是双指滑动
214
+ //计算二手指滑动距离,然后再通过在父容器中的占比得到缩放比例
215
+ this.on('touchmove', (evt) => {
216
+ if(touchPositions && evt.touches && evt.touches.length == 2) {
217
+ //上次滑动二指的距离
218
+ const preOffX = touchPositions[0].x - touchPositions[1].x;
219
+ const preOffY = touchPositions[0].y - touchPositions[1].y;
220
+ const preDis = Math.sqrt(preOffX * preOffX + preOffY * preOffY);
221
+ //当次滑动二指的距离
222
+ const curOffX = evt.touches[0].x - evt.touches[1].x;
223
+ const curOffY = evt.touches[0].y - evt.touches[1].y;
224
+ const curDis = Math.sqrt(curOffX * curOffX + curOffY * curOffY);
225
+
226
+ //const disx = Math.abs(preOffX - curOffX);//x轴滑行的距离
227
+ //const disy = Math.abs(preOffY - curOffY);//y轴滑行的距离
228
+
229
+ const offset = curDis - preDis;
230
+
231
+ this.reset(0, 0, offset, offset);
232
+ }
233
+ });
234
+ // 结束滑动
235
+ this.on('touchend touchcancel', (evt) => {
236
+ touchPositions = null;
237
+ });*/
238
+ }
239
+
240
+ /**
241
+ * 按移动偏移量重置当前对象,并触发大小和位置改变事件
242
+ * @method reset
243
+ * @param {number} px 位置X轴偏移
244
+ * @param {number} py 位置y轴偏移
245
+ * @param {number} dx 大小x轴偏移
246
+ * @param {number} dy 大小y轴偏移
247
+ */
248
+ reset(px, py, dx, dy) {
249
+ const minWidth = typeof this.style.minWidth=='undefined'?5:this.style.minWidth;
250
+ const minHeight = typeof this.style.minHeight=='undefined'?5:this.style.minHeight;
251
+
252
+ const location = this.getLocation();
253
+ if(dx != 0 || dy != 0) {
254
+ const w = location.width + dx;
255
+ const h = location.height + dy;
256
+ if(w >= minWidth || h >= minHeight) {
257
+ if(w >= minWidth) {
258
+ this.width = w;
259
+ }
260
+ else {
261
+ px = 0;
262
+ dx = 0;
263
+ }
264
+ if(h >= minHeight) {
265
+ this.height = h;
266
+ }
267
+ else {
268
+ py = 0;
269
+ dy = 0;
270
+ }
271
+ //如果当前控件能移动才能改变其位置
272
+ if(this.movable !== false && (px||py)) {
273
+ const p = this.position;
274
+ p.x = location.left + px;
275
+ p.y = location.top + py;
276
+ this.position = p;
277
+ }
278
+ //触发大小改变事件
279
+ this.emit('resize',px,py,dx,dy);
280
+ }
281
+ }
282
+
283
+ const newLocation = this.getLocation();
284
+ for(let i in this.resizeRects) {
285
+ const r = this.resizeRects[i];
286
+ switch(r.index) {
287
+ case 0: {
288
+ r.position.x = -r.width / 2;
289
+ r.position.y = (newLocation.height - r.height) / 2;
290
+ break;
291
+ }
292
+ case 1: {
293
+ r.position.x = -r.width / 2;
294
+ r.position.y = -r.height / 2;
295
+ break;
296
+ }
297
+ case 2: {
298
+ r.position.x = (newLocation.width - r.width) / 2;
299
+ r.position.y = -r.height / 2;
300
+ break;
301
+ }
302
+ case 3: {
303
+ r.position.x = newLocation.width - r.width / 2;
304
+ r.position.y = -r.height / 2;
305
+ break;
306
+ }
307
+ case 4: {
308
+ r.position.x = newLocation.width - r.width / 2;
309
+ r.position.y = (newLocation.height - r.height) / 2;
310
+ break;
311
+ }
312
+ case 5: {
313
+ r.position.x = newLocation.width - r.width / 2;
314
+ r.position.y = newLocation.height - r.height /2;
315
+ break;
316
+ }
317
+ case 6: {
318
+ r.position.x = (newLocation.width - r.height) / 2;
319
+ r.position.y = newLocation.height - r.height / 2;
320
+ break;
321
+ }
322
+ case 7: {
323
+ r.position.x = -r.width / 2;
324
+ r.position.y = newLocation.height - r.height / 2;
325
+ break;
326
+ }
327
+ }
328
+ r.needUpdate = true;
329
+ }
330
+ }
331
+ }
332
+
331
333
  export { jmResize };