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
package/src/core/jmControl.js
CHANGED
|
@@ -1,1532 +1,1377 @@
|
|
|
1
|
-
|
|
2
|
-
import {jmUtils} from "./jmUtils.js";
|
|
3
|
-
import {jmList} from "./jmList.js";
|
|
4
|
-
import {jmGradient} from "./jmGradient.js";
|
|
5
|
-
import {jmShadow} from "./jmShadow.js";
|
|
6
|
-
import {jmProperty} from "./jmProperty.js";
|
|
7
|
-
import WebglPath from "../lib/webgl/path.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'shadow.
|
|
15
|
-
'shadow.
|
|
16
|
-
'shadow.
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
params
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
get
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
get
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if(this.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if(
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
y
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
local.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
if(this.
|
|
775
|
-
this.
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
this
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
/**
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
* @
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
if(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
if(
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
return this.parent.findParent(type);
|
|
1378
|
-
}
|
|
1379
|
-
return null;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
/**
|
|
1383
|
-
* 设定是否可以移动
|
|
1384
|
-
* 此方法需指定jmgraph或在控件添加到jmgraph后再调用才能生效。
|
|
1385
|
-
*
|
|
1386
|
-
* @method canMove
|
|
1387
|
-
* @param {boolean} m true=可以移动,false=不可移动或清除移动。
|
|
1388
|
-
* @param {jmGraph} [graph] 当前画布,如果为空的话必需是已加入画布的控件,否则得指定画布。
|
|
1389
|
-
*/
|
|
1390
|
-
canMove(m, graph) {
|
|
1391
|
-
if(!this.__mvMonitor) {
|
|
1392
|
-
/**
|
|
1393
|
-
* 控制控件移动对象
|
|
1394
|
-
*
|
|
1395
|
-
* @property __mvMonitor
|
|
1396
|
-
* @private
|
|
1397
|
-
*/
|
|
1398
|
-
this.__mvMonitor = {};
|
|
1399
|
-
this.__mvMonitor.mouseDown = false;
|
|
1400
|
-
this.__mvMonitor.curposition={x:0,y:0};
|
|
1401
|
-
var self = this;
|
|
1402
|
-
/**
|
|
1403
|
-
* 控件移动鼠标事件
|
|
1404
|
-
*
|
|
1405
|
-
* @method mv
|
|
1406
|
-
* @private
|
|
1407
|
-
*/
|
|
1408
|
-
this.__mvMonitor.mv = function(evt) {
|
|
1409
|
-
let _this = self;
|
|
1410
|
-
//如果鼠标经过当前可移动控件,则显示可移动指针
|
|
1411
|
-
//if(evt.path && evt.path.indexOf(_this)>-1) {
|
|
1412
|
-
// _this.cursor('move');
|
|
1413
|
-
//}
|
|
1414
|
-
|
|
1415
|
-
if(_this.__mvMonitor.mouseDown) {
|
|
1416
|
-
_this.parent.bounds = null;
|
|
1417
|
-
//let parentbounds = _this.parent.getAbsoluteBounds();
|
|
1418
|
-
let offsetx = evt.position.offsetX - _this.__mvMonitor.curposition.x;
|
|
1419
|
-
let offsety = evt.position.offsetY - _this.__mvMonitor.curposition.y;
|
|
1420
|
-
//console.log(offsetx + ',' + offsety);
|
|
1421
|
-
//如果锁定边界
|
|
1422
|
-
if(_this.option.lockSide) {
|
|
1423
|
-
let thisbounds = _this.bounds || _this.getAbsoluteBounds();
|
|
1424
|
-
//检查边界出界
|
|
1425
|
-
let outside = jmUtils.checkOutSide(_this.option.lockSide, thisbounds, { x: offsetx, y: offsety });
|
|
1426
|
-
if(outside.left < 0 && offsetx < 0) {
|
|
1427
|
-
//offsetx -= outside.left;
|
|
1428
|
-
offsetx = 0;
|
|
1429
|
-
}
|
|
1430
|
-
else if(outside.right > 0 && offsetx > 0) {
|
|
1431
|
-
//offsetx -= outside.right;
|
|
1432
|
-
offsetx = 0;
|
|
1433
|
-
}
|
|
1434
|
-
if(outside.top < 0 && offsety < 0) {
|
|
1435
|
-
//offsety -= outside.top;
|
|
1436
|
-
offsety = 0;
|
|
1437
|
-
}
|
|
1438
|
-
else if(outside.bottom > 0 && offsety > 0) {
|
|
1439
|
-
//offsety -= outside.bottom;
|
|
1440
|
-
offsety = 0;
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
if(offsetx || offsety) {
|
|
1445
|
-
_this.offset(offsetx, offsety, true, evt);
|
|
1446
|
-
if(offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
|
|
1447
|
-
if(offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY;
|
|
1448
|
-
//console.log(offsetx + '.' + offsety);
|
|
1449
|
-
}
|
|
1450
|
-
return false;
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* 控件移动鼠标松开事件
|
|
1455
|
-
*
|
|
1456
|
-
* @method mu
|
|
1457
|
-
* @private
|
|
1458
|
-
*/
|
|
1459
|
-
this.__mvMonitor.mu = function(evt) {
|
|
1460
|
-
let _this = self;
|
|
1461
|
-
if(_this.__mvMonitor.mouseDown) {
|
|
1462
|
-
_this.__mvMonitor.mouseDown = false;
|
|
1463
|
-
//_this.cursor('default');
|
|
1464
|
-
_this.emit('moveend',{position:_this.__mvMonitor.curposition});
|
|
1465
|
-
//return false;
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* 控件移动鼠标离开事件
|
|
1470
|
-
*
|
|
1471
|
-
* @method ml
|
|
1472
|
-
* @private
|
|
1473
|
-
*/
|
|
1474
|
-
this.__mvMonitor.ml = function() {
|
|
1475
|
-
let _this = self;
|
|
1476
|
-
if(_this.__mvMonitor.mouseDown) {
|
|
1477
|
-
_this.__mvMonitor.mouseDown = false;
|
|
1478
|
-
//_this.cursor('default');
|
|
1479
|
-
_this.emit('moveend',{position:_this.__mvMonitor.curposition});
|
|
1480
|
-
return false;
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
/**
|
|
1484
|
-
* 控件移动鼠标按下事件
|
|
1485
|
-
*
|
|
1486
|
-
* @method md
|
|
1487
|
-
* @private
|
|
1488
|
-
*/
|
|
1489
|
-
this.__mvMonitor.md = function(evt) {
|
|
1490
|
-
|
|
1491
|
-
if(this.__mvMonitor.mouseDown) return;
|
|
1492
|
-
if(evt.button == 0 || evt.button == 1) {
|
|
1493
|
-
this.__mvMonitor.mouseDown = true;
|
|
1494
|
-
//this.cursor('move');
|
|
1495
|
-
//var parentbounds = this.parent.absoluteBounds || this.parent.getAbsoluteBounds();
|
|
1496
|
-
this.__mvMonitor.curposition.x = evt.position.offsetX;//evt.position.x + parentbounds.left;
|
|
1497
|
-
this.__mvMonitor.curposition.y = evt.position.offsetY;//evt.position.y + parentbounds.top;
|
|
1498
|
-
//触发控件移动事件
|
|
1499
|
-
this.emit('movestart',{position:this.__mvMonitor.curposition});
|
|
1500
|
-
|
|
1501
|
-
evt.cancel = true;
|
|
1502
|
-
return false;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
graph = graph || this.graph ;//获取最顶级元素画布
|
|
1507
|
-
|
|
1508
|
-
if(m !== false) {
|
|
1509
|
-
graph.bind('mousemove',this.__mvMonitor.mv);
|
|
1510
|
-
graph.bind('mouseup',this.__mvMonitor.mu);
|
|
1511
|
-
graph.bind('mouseleave',this.__mvMonitor.ml);
|
|
1512
|
-
this.bind('mousedown',this.__mvMonitor.md);
|
|
1513
|
-
graph.bind('touchmove',this.__mvMonitor.mv);
|
|
1514
|
-
graph.bind('touchend',this.__mvMonitor.mu);
|
|
1515
|
-
this.bind('touchstart',this.__mvMonitor.md);
|
|
1516
|
-
}
|
|
1517
|
-
else {
|
|
1518
|
-
graph.unbind('mousemove',this.__mvMonitor.mv);
|
|
1519
|
-
graph.unbind('mouseup',this.__mvMonitor.mu);
|
|
1520
|
-
graph.unbind('mouseleave',this.__mvMonitor.ml);
|
|
1521
|
-
this.unbind('mousedown',this.__mvMonitor.md);
|
|
1522
|
-
graph.unbind('touchmove',this.__mvMonitor.mv);
|
|
1523
|
-
graph.unbind('touchend',this.__mvMonitor.mu);
|
|
1524
|
-
this.unbind('touchstart',this.__mvMonitor.md);
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
this.interactive = true;// 如果可以移动,则响应事件
|
|
1528
|
-
return this;
|
|
1529
|
-
}
|
|
1530
|
-
};
|
|
1531
|
-
|
|
1
|
+
|
|
2
|
+
import {jmUtils} from "./jmUtils.js";
|
|
3
|
+
import {jmList} from "./jmList.js";
|
|
4
|
+
import {jmGradient} from "./jmGradient.js";
|
|
5
|
+
import {jmShadow} from "./jmShadow.js";
|
|
6
|
+
import {jmProperty} from "./jmProperty.js";
|
|
7
|
+
import WebglPath from "../lib/webgl/path.js";
|
|
8
|
+
|
|
9
|
+
const jmStyleMap = {
|
|
10
|
+
'fill':'fillStyle',
|
|
11
|
+
'fillImage':'fillImage',
|
|
12
|
+
'stroke':'strokeStyle',
|
|
13
|
+
'shadow.blur':'shadowBlur',
|
|
14
|
+
'shadow.x':'shadowOffsetX',
|
|
15
|
+
'shadow.y':'shadowOffsetY',
|
|
16
|
+
'shadow.color':'shadowColor',
|
|
17
|
+
'lineWidth' : 'lineWidth',
|
|
18
|
+
'miterLimit': 'miterLimit',
|
|
19
|
+
'fillStyle' : 'fillStyle',
|
|
20
|
+
'strokeStyle' : 'strokeStyle',
|
|
21
|
+
'font' : 'font',
|
|
22
|
+
'opacity' : 'globalAlpha',
|
|
23
|
+
'textAlign' : 'textAlign',
|
|
24
|
+
'textBaseline' : 'textBaseline',
|
|
25
|
+
'shadowBlur' : 'shadowBlur',
|
|
26
|
+
'shadowOffsetX' : 'shadowOffsetX',
|
|
27
|
+
'shadowOffsetY' : 'shadowOffsetY',
|
|
28
|
+
'shadowColor' : 'shadowColor',
|
|
29
|
+
'lineJoin': 'lineJoin',
|
|
30
|
+
'lineCap':'lineCap'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default class jmControl extends jmProperty {
|
|
34
|
+
|
|
35
|
+
constructor(params, t) {
|
|
36
|
+
params = params||{};
|
|
37
|
+
super(params);
|
|
38
|
+
this.property('type', t || new.target.name);
|
|
39
|
+
this.style = params && params.style ? params.style : {};
|
|
40
|
+
this.width = params.width || 0;
|
|
41
|
+
this.height = params.height || 0;
|
|
42
|
+
this.hitArea = params.hitArea || null;
|
|
43
|
+
|
|
44
|
+
if(params.position) {
|
|
45
|
+
this.position = params.position;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.graph = params.graph || null;
|
|
49
|
+
this.zIndex = params.zIndex || 0;
|
|
50
|
+
this.interactive = typeof params.interactive == 'undefined'? false : params.interactive;
|
|
51
|
+
|
|
52
|
+
if(this.mode === 'webgl') {
|
|
53
|
+
this.webglControl = new WebglPath(this.graph, {
|
|
54
|
+
style: this.style,
|
|
55
|
+
control: this,
|
|
56
|
+
isRegular: params.isRegular,
|
|
57
|
+
needCut: params.needCut
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.initializing();
|
|
62
|
+
|
|
63
|
+
this.on = this.bind;
|
|
64
|
+
|
|
65
|
+
this.option = params;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get type() {
|
|
69
|
+
return this.property('type');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get context() {
|
|
73
|
+
let s = this.property('context');
|
|
74
|
+
if(s) return s;
|
|
75
|
+
else if(this.is('jmGraph') && this.canvas && this.canvas.getContext) {
|
|
76
|
+
return this.context = this.canvas.getContext(this.mode || '2d');
|
|
77
|
+
}
|
|
78
|
+
const g = this.graph;
|
|
79
|
+
if(g) return g.context;
|
|
80
|
+
return g.canvas.getContext(this.mode || '2d');
|
|
81
|
+
}
|
|
82
|
+
set context(v) {
|
|
83
|
+
return this.property('context', v);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get style() {
|
|
87
|
+
let s = this.property('style');
|
|
88
|
+
if(!s) s = this.property('style', {});
|
|
89
|
+
return s;
|
|
90
|
+
}
|
|
91
|
+
set style(v) {
|
|
92
|
+
this.needUpdate = true;
|
|
93
|
+
return this.property('style', v);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get visible() {
|
|
97
|
+
let s = this.property('visible');
|
|
98
|
+
if(typeof s == 'undefined') s = this.property('visible', true);
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
set visible(v) {
|
|
102
|
+
this.needUpdate = true;
|
|
103
|
+
return this.property('visible', v);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get interactive() {
|
|
107
|
+
const s = this.property('interactive');
|
|
108
|
+
return s;
|
|
109
|
+
}
|
|
110
|
+
set interactive(v) {
|
|
111
|
+
return this.property('interactive', v);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get hitArea() {
|
|
115
|
+
const s = this.property('hitArea');
|
|
116
|
+
return s;
|
|
117
|
+
}
|
|
118
|
+
set hitArea(v) {
|
|
119
|
+
return this.property('hitArea', v);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get children() {
|
|
123
|
+
let s = this.property('children');
|
|
124
|
+
if(!s) s = this.property('children', new jmList());
|
|
125
|
+
return s;
|
|
126
|
+
}
|
|
127
|
+
set children(v) {
|
|
128
|
+
this.needUpdate = true;
|
|
129
|
+
return this.property('children', v);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
get width() {
|
|
133
|
+
let s = this.property('width');
|
|
134
|
+
if(typeof s == 'undefined') s = this.property('width', 0);
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
set width(v) {
|
|
138
|
+
this.needUpdate = true;
|
|
139
|
+
return this.property('width', v);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get height() {
|
|
143
|
+
let s = this.property('height');
|
|
144
|
+
if(typeof s == 'undefined') s = this.property('height', 0);
|
|
145
|
+
return s;
|
|
146
|
+
}
|
|
147
|
+
set height(v) {
|
|
148
|
+
this.needUpdate = true;
|
|
149
|
+
return this.property('height', v);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get zIndex() {
|
|
153
|
+
let s = this.property('zIndex');
|
|
154
|
+
if(!s) s = this.property('zIndex', 0);
|
|
155
|
+
return s;
|
|
156
|
+
}
|
|
157
|
+
set zIndex(v) {
|
|
158
|
+
this.property('zIndex', v);
|
|
159
|
+
this.children.sort();
|
|
160
|
+
this.needUpdate = true;
|
|
161
|
+
return v;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
set cursor(cur) {
|
|
165
|
+
const graph = this.graph;
|
|
166
|
+
if(graph) {
|
|
167
|
+
graph.css('cursor',cur);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
get cursor() {
|
|
171
|
+
const graph = this.graph;
|
|
172
|
+
if(graph) {
|
|
173
|
+
return graph.css('cursor');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
initializing() {
|
|
178
|
+
|
|
179
|
+
const self = this;
|
|
180
|
+
this.children = this.children || new jmList();
|
|
181
|
+
const oadd = this.children.add;
|
|
182
|
+
|
|
183
|
+
this.children.add = function(obj) {
|
|
184
|
+
if(typeof obj === 'object') {
|
|
185
|
+
if(obj.parent && obj.parent != self && obj.parent.children) {
|
|
186
|
+
obj.parent.children.remove(obj);
|
|
187
|
+
}
|
|
188
|
+
obj.parent = self;
|
|
189
|
+
if(this.contain(obj)) {
|
|
190
|
+
this.oremove(obj);
|
|
191
|
+
}
|
|
192
|
+
oadd.call(this, obj);
|
|
193
|
+
obj.emit('add', obj);
|
|
194
|
+
|
|
195
|
+
self.needUpdate = true;
|
|
196
|
+
if(self.graph) obj.graph = self.graph;
|
|
197
|
+
this.sort();
|
|
198
|
+
return obj;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
this.children.oremove= this.children.remove;
|
|
202
|
+
|
|
203
|
+
this.children.remove = function(obj) {
|
|
204
|
+
if(typeof obj === 'object') {
|
|
205
|
+
obj.parent = null;
|
|
206
|
+
obj.graph = null;
|
|
207
|
+
obj.remove(true);
|
|
208
|
+
this.oremove(obj);
|
|
209
|
+
self.needUpdate = true;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
this.children.sort = function() {
|
|
214
|
+
const levelItems = {};
|
|
215
|
+
this.each(function(i, obj) {
|
|
216
|
+
if(!obj) return;
|
|
217
|
+
let zindex = obj.zIndex;
|
|
218
|
+
if(!zindex && obj.style && obj.style.zIndex) {
|
|
219
|
+
zindex = Number(obj.style.zIndex);
|
|
220
|
+
if(isNaN(zindex)) zindex=obj.style.zIndex||0;
|
|
221
|
+
}
|
|
222
|
+
let items = levelItems[zindex] || (levelItems[zindex] = []);
|
|
223
|
+
items.push(obj);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
this.splice(0, this.length);
|
|
227
|
+
|
|
228
|
+
for(let index in levelItems) {
|
|
229
|
+
oadd.call(this, levelItems[index]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
this.children.clear = function() {
|
|
233
|
+
this.each(function(i,obj) {
|
|
234
|
+
this.remove(obj);
|
|
235
|
+
},true);
|
|
236
|
+
}
|
|
237
|
+
this.needUpdate = true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
setStyle(style) {
|
|
241
|
+
style = style || jmUtils.clone(this.style, true);
|
|
242
|
+
if(!style) return;
|
|
243
|
+
|
|
244
|
+
const __setStyle = (style, name, mpkey) => {
|
|
245
|
+
if(style) {
|
|
246
|
+
let styleValue = style;
|
|
247
|
+
if(typeof styleValue === 'function') {
|
|
248
|
+
try {
|
|
249
|
+
styleValue = styleValue.call(this);
|
|
250
|
+
}
|
|
251
|
+
catch(e) {
|
|
252
|
+
console.warn(e);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let t = typeof styleValue;
|
|
257
|
+
let mpname = jmStyleMap[mpkey || name];
|
|
258
|
+
|
|
259
|
+
if((styleValue instanceof jmGradient) || (t == 'string' && styleValue.indexOf('-gradient') > -1)) {
|
|
260
|
+
if(t == 'string' && styleValue.indexOf('-gradient') > -1) {
|
|
261
|
+
styleValue = new jmGradient(styleValue);
|
|
262
|
+
}
|
|
263
|
+
__setStyle(styleValue.toGradient(this), mpname||name);
|
|
264
|
+
}
|
|
265
|
+
else if(mpname) {
|
|
266
|
+
if(this.webglControl) {
|
|
267
|
+
this.webglControl.setStyle(mpname, styleValue);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
if(t == 'string' && ['fillStyle', 'strokeStyle', 'shadowColor'].indexOf(mpname) > -1) {
|
|
271
|
+
styleValue = jmUtils.toColor(styleValue);
|
|
272
|
+
}
|
|
273
|
+
this.context[mpname] = styleValue;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
switch(name) {
|
|
278
|
+
case 'shadow' : {
|
|
279
|
+
if(t == 'string') {
|
|
280
|
+
__setStyle(new jmShadow(styleValue), name);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
for(let k in styleValue) {
|
|
284
|
+
__setStyle(styleValue[k], k, name + '.' + k);
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case 'translate' : {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
case 'rotation' : {
|
|
292
|
+
if(typeof styleValue.angle === 'undefined' || isNaN(styleValue.angle)) break;
|
|
293
|
+
styleValue = this.getRotation(styleValue);
|
|
294
|
+
|
|
295
|
+
this.__translateAbsolutePosition = this.toAbsolutePoint({
|
|
296
|
+
x: styleValue.x,
|
|
297
|
+
y: styleValue.y
|
|
298
|
+
});
|
|
299
|
+
this.context.translate && this.context.translate(this.__translateAbsolutePosition.x, this.__translateAbsolutePosition.y);
|
|
300
|
+
this.context.rotate && this.context.rotate(styleValue.angle);
|
|
301
|
+
this.context.translate && this.context.translate(-this.__translateAbsolutePosition.x, -this.__translateAbsolutePosition.y);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case 'transform' : {
|
|
305
|
+
if(!this.context.transform) break;
|
|
306
|
+
if(Array.isArray(styleValue)) {
|
|
307
|
+
this.context.transform.apply(this.context, styleValue);
|
|
308
|
+
}
|
|
309
|
+
else if(typeof styleValue == 'object') {
|
|
310
|
+
this.context.transform(
|
|
311
|
+
styleValue.scaleX || 1,
|
|
312
|
+
styleValue.skewX || 0,
|
|
313
|
+
styleValue.skewY || 0,
|
|
314
|
+
styleValue.scaleY || 1,
|
|
315
|
+
styleValue.offsetX || 0,
|
|
316
|
+
styleValue.offsetY || 0
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case 'cursor' : {
|
|
322
|
+
this.cursor = styleValue;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if(this.translate) {
|
|
331
|
+
__setStyle(this.translate, 'translate');
|
|
332
|
+
}
|
|
333
|
+
if(this.transform) {
|
|
334
|
+
__setStyle(this.transform, 'transform');
|
|
335
|
+
}
|
|
336
|
+
for(let k in style) {
|
|
337
|
+
if(k === 'constructor') continue;
|
|
338
|
+
let t = typeof style[k];
|
|
339
|
+
if(t == 'string' && style[k].indexOf('-gradient') > -1) {
|
|
340
|
+
style[k] = new jmGradient(style[k]);
|
|
341
|
+
}
|
|
342
|
+
else if(t == 'string' && k == 'shadow') {
|
|
343
|
+
style[k] = new jmShadow(style[k]);
|
|
344
|
+
}
|
|
345
|
+
__setStyle(style[k], k);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 获取当前控件的边界
|
|
351
|
+
* 通过分析控件的描点或位置加宽高得到为方形的边界
|
|
352
|
+
*
|
|
353
|
+
* @method getBounds
|
|
354
|
+
* @for jmControl
|
|
355
|
+
* @param {boolean} [isReset=false] 是否强制重新计算
|
|
356
|
+
* @return {object} 控件的边界描述对象(left,top,right,bottom,width,height)
|
|
357
|
+
*/
|
|
358
|
+
getBounds(isReset) {
|
|
359
|
+
//如果当次计算过,则不重复计算
|
|
360
|
+
if(this.bounds && !isReset) return this.bounds;
|
|
361
|
+
|
|
362
|
+
const rect = {}; // left top
|
|
363
|
+
//jmGraph,特殊处理
|
|
364
|
+
if(this.type == 'jmGraph' && this.canvas) {
|
|
365
|
+
if(typeof this.canvas.width === 'function') {
|
|
366
|
+
rect.right = this.canvas.width();
|
|
367
|
+
}
|
|
368
|
+
else if(this.width) {
|
|
369
|
+
rect.right = this.width;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if(typeof this.canvas.height === 'function') {
|
|
373
|
+
rect.bottom = this.canvas.height();
|
|
374
|
+
}
|
|
375
|
+
else if(this.height) {
|
|
376
|
+
rect.bottom = this.height;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else if(this.points && this.points.length > 0) {
|
|
380
|
+
for(const p of this.points) {
|
|
381
|
+
if(typeof rect.left === 'undefined' || rect.left > p.x) {
|
|
382
|
+
rect.left = p.x;
|
|
383
|
+
}
|
|
384
|
+
if(typeof rect.top === 'undefined' || rect.top > p.y) {
|
|
385
|
+
rect.top = p.y;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if(typeof rect.right === 'undefined' || rect.right < p.x) {
|
|
389
|
+
rect.right = p.x;
|
|
390
|
+
}
|
|
391
|
+
if(typeof rect.bottom === 'undefined' || rect.bottom < p.y) {
|
|
392
|
+
rect.bottom = p.y;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else if(this.getLocation) {
|
|
397
|
+
let p = this.getLocation();
|
|
398
|
+
if(p) {
|
|
399
|
+
rect.left = p.left;
|
|
400
|
+
rect.top = p.top;
|
|
401
|
+
rect.right = p.left + p.width;
|
|
402
|
+
rect.bottom = p.top + p.height;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if(!rect.left) rect.left = 0;
|
|
406
|
+
if(!rect.top) rect.top = 0;
|
|
407
|
+
if(!rect.right) rect.right = 0;
|
|
408
|
+
if(!rect.bottom) rect.bottom = 0;
|
|
409
|
+
rect.width = rect.right - rect.left;
|
|
410
|
+
rect.height = rect.bottom - rect.top;
|
|
411
|
+
|
|
412
|
+
return this.bounds=rect;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* 获取被旋转后的边界
|
|
417
|
+
*/
|
|
418
|
+
getRotationBounds(rotation=null) {
|
|
419
|
+
rotation = rotation || this.getRotation();
|
|
420
|
+
const bounds = this.getBounds();
|
|
421
|
+
if(!rotation || !rotation.angle) return bounds;
|
|
422
|
+
|
|
423
|
+
const rect = {
|
|
424
|
+
width: 0,
|
|
425
|
+
height: 0,
|
|
426
|
+
oldBounds: bounds
|
|
427
|
+
}; // left top
|
|
428
|
+
let points = [];
|
|
429
|
+
if(this.points && this.points.length > 0) {
|
|
430
|
+
points = jmUtils.clone(this.points, true); // 深度拷贝
|
|
431
|
+
}
|
|
432
|
+
else if(this.getLocation) {
|
|
433
|
+
const local = this.getLocation();
|
|
434
|
+
if(local) {
|
|
435
|
+
points.push({
|
|
436
|
+
x: local.left,
|
|
437
|
+
y: local.top
|
|
438
|
+
},{
|
|
439
|
+
x: local.left + local.width,
|
|
440
|
+
y: local.top
|
|
441
|
+
},{
|
|
442
|
+
x: local.left + local.width,
|
|
443
|
+
y: local.top + local.height
|
|
444
|
+
},{
|
|
445
|
+
x: local.left,
|
|
446
|
+
y: local.top + local.height
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
points = jmUtils.rotatePoints(points, {
|
|
451
|
+
x: rotation.x + bounds.left,
|
|
452
|
+
y: rotation.y + bounds.top
|
|
453
|
+
}, rotation.angle);// 对现在点进行旋转
|
|
454
|
+
|
|
455
|
+
for(const p of points) {
|
|
456
|
+
if(typeof rect.left === 'undefined' || rect.left > p.x) {
|
|
457
|
+
rect.left = p.x;
|
|
458
|
+
}
|
|
459
|
+
if(typeof rect.top === 'undefined' || rect.top > p.y) {
|
|
460
|
+
rect.top = p.y;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if(typeof rect.right === 'undefined' || rect.right < p.x) {
|
|
464
|
+
rect.right = p.x;
|
|
465
|
+
}
|
|
466
|
+
if(typeof rect.bottom === 'undefined' || rect.bottom < p.y) {
|
|
467
|
+
rect.bottom = p.y;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if(!rect.left) rect.left = 0;
|
|
472
|
+
if(!rect.top) rect.top = 0;
|
|
473
|
+
if(!rect.right) rect.right = 0;
|
|
474
|
+
if(!rect.bottom) rect.bottom = 0;
|
|
475
|
+
|
|
476
|
+
rect.width = rect.right - rect.left;
|
|
477
|
+
rect.height = rect.bottom - rect.top;
|
|
478
|
+
|
|
479
|
+
return rect;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* 获取当前控件的位置相关参数
|
|
484
|
+
* 解析百分比和margin参数
|
|
485
|
+
*
|
|
486
|
+
* @method getLocation
|
|
487
|
+
* @return {object} 当前控件位置参数,包括中心点坐标,右上角坐标,宽高
|
|
488
|
+
*/
|
|
489
|
+
getLocation(clone=true) {
|
|
490
|
+
//如果已经计算过则直接返回
|
|
491
|
+
//在开画之前会清空此对象
|
|
492
|
+
//if(reset !== true && this.location) return this.location;
|
|
493
|
+
|
|
494
|
+
let local = this.location = {left: 0,top: 0,width: 0,height: 0};
|
|
495
|
+
local.position = typeof this.position == 'function'? this.position(): jmUtils.clone(this.position);
|
|
496
|
+
local.center = this.center && typeof this.center === 'function'?this.center(): jmUtils.clone(this.center);//中心
|
|
497
|
+
local.start = this.start && typeof this.start === 'function'?this.start(): jmUtils.clone(this.start);//起点
|
|
498
|
+
local.end = this.end && typeof this.end === 'function'?this.end(): jmUtils.clone(this.end);//起点
|
|
499
|
+
local.radius = this.radius;//半径
|
|
500
|
+
local.width = this.width;
|
|
501
|
+
local.height = this.height;
|
|
502
|
+
|
|
503
|
+
const margin = jmUtils.clone(this.style.margin, {});
|
|
504
|
+
margin.left = (margin.left || 0);
|
|
505
|
+
margin.top = (margin.top || 0);
|
|
506
|
+
margin.right = (margin.right || 0);
|
|
507
|
+
margin.bottom = (margin.bottom || 0);
|
|
508
|
+
|
|
509
|
+
//如果没有指定位置,但指定了margin。则位置取margin偏移量
|
|
510
|
+
if(local.position) {
|
|
511
|
+
local.left = local.position.x;
|
|
512
|
+
local.top = local.position.y;
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
local.left = margin.left;
|
|
516
|
+
local.top = margin.top;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if(this.parent) {
|
|
520
|
+
const parentBounds = this.parent.getBounds();
|
|
521
|
+
|
|
522
|
+
//处理百分比参数
|
|
523
|
+
if(jmUtils.checkPercent(local.left)) {
|
|
524
|
+
local.left = jmUtils.percentToNumber(local.left) * parentBounds.width;
|
|
525
|
+
}
|
|
526
|
+
if(jmUtils.checkPercent(local.top)) {
|
|
527
|
+
local.top = jmUtils.percentToNumber(local.top) * parentBounds.height;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
//如果没有指定宽度或高度,则按百分之百计算其父宽度或高度
|
|
531
|
+
if(jmUtils.checkPercent(local.width)) {
|
|
532
|
+
local.width = jmUtils.percentToNumber(local.width) * parentBounds.width;
|
|
533
|
+
}
|
|
534
|
+
if(jmUtils.checkPercent(local.height)) {
|
|
535
|
+
local.height = jmUtils.percentToNumber(local.height) * parentBounds.height;
|
|
536
|
+
}
|
|
537
|
+
//处理中心点
|
|
538
|
+
if(local.center) {
|
|
539
|
+
//处理百分比参数
|
|
540
|
+
if(jmUtils.checkPercent(local.center.x)) {
|
|
541
|
+
local.center.x = jmUtils.percentToNumber(local.center.x) * parentBounds.width;
|
|
542
|
+
}
|
|
543
|
+
if(jmUtils.checkPercent(local.center.y)) {
|
|
544
|
+
local.center.y = jmUtils.percentToNumber(local.center.y) * parentBounds.height;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if(local.radius) {
|
|
548
|
+
//处理百分比参数
|
|
549
|
+
if(jmUtils.checkPercent(local.radius)) {
|
|
550
|
+
local.radius = jmUtils.percentToNumber(local.radius) * Math.min(parentBounds.width, parentBounds.height);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return local;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* 获取当前控制的旋转信息
|
|
559
|
+
* @returns {object} 旋转中心和角度
|
|
560
|
+
*/
|
|
561
|
+
getRotation(rotation, bounds = null) {
|
|
562
|
+
rotation = rotation || jmUtils.clone(this.style.rotation);
|
|
563
|
+
|
|
564
|
+
if(!rotation) {
|
|
565
|
+
//如果本身没有,则可以继承父级的
|
|
566
|
+
rotation = this.parent && this.parent.getRotation?this.parent.getRotation():null;
|
|
567
|
+
//如果父级有旋转,则把坐标转换为当前控件区域
|
|
568
|
+
if(rotation) {
|
|
569
|
+
bounds = bounds || this.getBounds();
|
|
570
|
+
rotation.x -= bounds.left;
|
|
571
|
+
rotation.y -= bounds.top;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
bounds = bounds || this.getBounds();
|
|
576
|
+
if(typeof rotation.x === 'undefined') rotation.x = '50%';
|
|
577
|
+
if(typeof rotation.y === 'undefined') rotation.y = '50%';
|
|
578
|
+
if(jmUtils.checkPercent(rotation.x)) {
|
|
579
|
+
rotation.x = jmUtils.percentToNumber(rotation.x) * bounds.width;
|
|
580
|
+
}
|
|
581
|
+
if(jmUtils.checkPercent(rotation.y)) {
|
|
582
|
+
rotation.y = jmUtils.percentToNumber(rotation.y) * bounds.height;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
...rotation,
|
|
587
|
+
bounds
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// 计算位移偏移量
|
|
593
|
+
getTranslate(translate, bounds = null) {
|
|
594
|
+
translate = translate || this.style.translate;
|
|
595
|
+
if(!translate) return {x: 0, y: 0};
|
|
596
|
+
const result = {
|
|
597
|
+
x: translate.x || 0,
|
|
598
|
+
y: translate.y || 0
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if(jmUtils.checkPercent(result.x)) {
|
|
602
|
+
if(!bounds && this.parent) bounds = this.parent.getBounds();
|
|
603
|
+
result.x = jmUtils.percentToNumber(result.x) * bounds.width;
|
|
604
|
+
}
|
|
605
|
+
if(jmUtils.checkPercent(result.y)) {
|
|
606
|
+
if(!bounds && this.parent) bounds = this.parent.getBounds();
|
|
607
|
+
result.y = jmUtils.percentToNumber(result.y) * bounds.height;
|
|
608
|
+
}
|
|
609
|
+
return result;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* 移除当前控件
|
|
614
|
+
* 如果是VML元素,则调用其删除元素
|
|
615
|
+
*
|
|
616
|
+
* @method remove
|
|
617
|
+
*/
|
|
618
|
+
remove() {
|
|
619
|
+
if(this.parent) {
|
|
620
|
+
this.parent.children.remove(this);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* 对控件进行平移
|
|
626
|
+
* 遍历控件所有描点或位置,设置其偏移量。
|
|
627
|
+
*
|
|
628
|
+
* @method offset
|
|
629
|
+
* @param {number} x x轴偏移量
|
|
630
|
+
* @param {number} y y轴偏移量
|
|
631
|
+
* @param {boolean} [trans] 是否传递,监听者可以通过此属性是否决定是否响应移动事件,默认=true
|
|
632
|
+
* @param {object} [evt] 如果是事件触发,则传递move事件参数
|
|
633
|
+
*/
|
|
634
|
+
offset(x, y, trans, evt) {
|
|
635
|
+
trans = trans === false?false:true;
|
|
636
|
+
let local = this.getLocation(true);
|
|
637
|
+
let offseted = false;
|
|
638
|
+
|
|
639
|
+
if(local.position) {
|
|
640
|
+
local.left += x;
|
|
641
|
+
local.top += y;
|
|
642
|
+
// 由于local是clone出来的对象,为了保留位移,则要修改原属性
|
|
643
|
+
this.position.x = local.left;
|
|
644
|
+
this.position.y = local.top;
|
|
645
|
+
offseted = true;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if(local.center) {
|
|
649
|
+
this.center.x = local.center.x + x;
|
|
650
|
+
this.center.y = local.center.y + y;
|
|
651
|
+
offseted = true;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if(local.start && typeof local.start == 'object') {
|
|
655
|
+
this.start.x = local.start.x + x;
|
|
656
|
+
this.start.y = local.start.y + y;
|
|
657
|
+
offseted = true;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if(local.end && typeof local.end == 'object') {
|
|
661
|
+
this.end.x = local.end.x + x;
|
|
662
|
+
this.end.y = local.end.y + y;
|
|
663
|
+
offseted = true;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
if(offseted == false && this.cpoints) {
|
|
668
|
+
let p = typeof this.cpoints == 'function'?this.cpoints:this.cpoints;
|
|
669
|
+
if(p) {
|
|
670
|
+
let len = p.length;
|
|
671
|
+
for(let i=0; i < len;i++) {
|
|
672
|
+
p[i].x += x;
|
|
673
|
+
p[i].y += y;
|
|
674
|
+
}
|
|
675
|
+
offseted = true;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
if(offseted == false && this.points) {
|
|
680
|
+
let len = this.points.length;
|
|
681
|
+
for(let i=0; i < len;i++) {
|
|
682
|
+
this.points[i].x += x;
|
|
683
|
+
this.points[i].y += y;
|
|
684
|
+
}
|
|
685
|
+
offseted = true;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
//触发控件移动事件
|
|
689
|
+
this.emit('move',{
|
|
690
|
+
offsetX: x,
|
|
691
|
+
offsetY: y,
|
|
692
|
+
trans: trans,
|
|
693
|
+
evt: evt
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
this.needUpdate = true;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* 获取控件相对于画布的绝对边界,
|
|
701
|
+
* 与getBounds不同的是:getBounds获取的是相对于父容器的边界.
|
|
702
|
+
*
|
|
703
|
+
* @method getAbsoluteBounds
|
|
704
|
+
* @return {object} 边界对象(left,top,right,bottom,width,height)
|
|
705
|
+
*/
|
|
706
|
+
getAbsoluteBounds() {
|
|
707
|
+
//当前控件的边界,
|
|
708
|
+
let rec = this.getBounds();
|
|
709
|
+
if(this.parent && this.parent.absoluteBounds) {
|
|
710
|
+
//父容器的绝对边界
|
|
711
|
+
let prec = this.parent.absoluteBounds || this.parent.getAbsoluteBounds();
|
|
712
|
+
|
|
713
|
+
return {
|
|
714
|
+
left : prec.left + rec.left,
|
|
715
|
+
top : prec.top + rec.top,
|
|
716
|
+
right : prec.left + rec.right,
|
|
717
|
+
bottom : prec.top + rec.bottom,
|
|
718
|
+
width : rec.width,
|
|
719
|
+
height : rec.height
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
return rec;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* 把当前控制内部坐标转为canvas绝对定位坐标
|
|
727
|
+
*
|
|
728
|
+
* @method toAbsolutePoint
|
|
729
|
+
* @param {x: number, y: number} 内部坐标
|
|
730
|
+
*/
|
|
731
|
+
toAbsolutePoint(point) {
|
|
732
|
+
if(point.x || point.y) {
|
|
733
|
+
const bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
|
|
734
|
+
|
|
735
|
+
point.x = (point.x||0) + bounds.left;
|
|
736
|
+
point.y = (point.y||0) + bounds.top;
|
|
737
|
+
}
|
|
738
|
+
return point;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* 把绝对定位坐标转为当前控件坐标系内
|
|
743
|
+
* @param {*} point
|
|
744
|
+
*/
|
|
745
|
+
toLocalPosition(point) {
|
|
746
|
+
|
|
747
|
+
const bounds = this.absoluteBounds?this.absoluteBounds:this.getAbsoluteBounds();
|
|
748
|
+
if(!bounds) return false;
|
|
749
|
+
return {
|
|
750
|
+
x: point.x - bounds.left,
|
|
751
|
+
y: point.y - bounds.top
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* 画控件前初始化
|
|
757
|
+
* 执行beginPath开始控件的绘制
|
|
758
|
+
*
|
|
759
|
+
* @method beginDraw
|
|
760
|
+
*/
|
|
761
|
+
beginDraw() {
|
|
762
|
+
this.getLocation(true);//重置位置信息
|
|
763
|
+
this.context.beginPath && this.context.beginPath();
|
|
764
|
+
if(this.webglControl && this.webglControl.beginDraw) this.webglControl.beginDraw();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* 结束控件绘制
|
|
769
|
+
*
|
|
770
|
+
* @method endDraw
|
|
771
|
+
*/
|
|
772
|
+
endDraw() {
|
|
773
|
+
//如果当前为封闭路径
|
|
774
|
+
if(this.style.close) {
|
|
775
|
+
if(this.webglControl) this.webglControl.closePath();
|
|
776
|
+
this.context.closePath && this.context.closePath();
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
const fill = this.style['fill'] || this.style['fillStyle'];
|
|
780
|
+
if(fill) {
|
|
781
|
+
if(this.webglControl) {
|
|
782
|
+
const bounds = this.getBounds();
|
|
783
|
+
this.webglControl.fill(bounds);
|
|
784
|
+
}
|
|
785
|
+
this.context.fill && this.context.fill();
|
|
786
|
+
}
|
|
787
|
+
if(this.style['stroke'] || (!fill && !this.is('jmGraph'))) {
|
|
788
|
+
if(this.webglControl) this.webglControl.stroke();
|
|
789
|
+
this.context.stroke && this.context.stroke();
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if(this.webglControl && this.webglControl.endDraw) this.webglControl.endDraw();
|
|
793
|
+
|
|
794
|
+
this.needUpdate = false;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* 绘制控件
|
|
799
|
+
* 在画布上描点
|
|
800
|
+
*
|
|
801
|
+
* @method draw
|
|
802
|
+
*/
|
|
803
|
+
draw() {
|
|
804
|
+
if(this.points && this.points.length > 0) {
|
|
805
|
+
//获取当前控件的绝对位置
|
|
806
|
+
const bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
|
|
807
|
+
if(this.webglControl) {
|
|
808
|
+
this.webglControl.setParentBounds(bounds);
|
|
809
|
+
this.webglControl.draw([
|
|
810
|
+
...this.points
|
|
811
|
+
]);
|
|
812
|
+
}
|
|
813
|
+
else if(this.context && this.context.moveTo) {
|
|
814
|
+
this.context.moveTo(this.points[0].x + bounds.left,this.points[0].y + bounds.top);
|
|
815
|
+
let len = this.points.length;
|
|
816
|
+
for(let i=1; i < len;i++) {
|
|
817
|
+
let p = this.points[i];
|
|
818
|
+
//移至当前坐标
|
|
819
|
+
if(p.m) {
|
|
820
|
+
this.context.moveTo(p.x + bounds.left,p.y + bounds.top);
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
this.context.lineTo(p.x+ bounds.left,p.y + bounds.top);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* 绘制当前控件
|
|
832
|
+
* 协调控件的绘制,先从其子控件开始绘制,再往上冒。
|
|
833
|
+
*
|
|
834
|
+
* @method paint
|
|
835
|
+
*/
|
|
836
|
+
paint(v) {
|
|
837
|
+
if(v !== false && this.visible !== false) {
|
|
838
|
+
if(this.initPoints) this.initPoints();
|
|
839
|
+
//计算当前边界
|
|
840
|
+
this.bounds = null;
|
|
841
|
+
this.absoluteBounds = this.getAbsoluteBounds();
|
|
842
|
+
let needDraw = true;//是否需要绘制
|
|
843
|
+
if(!this.is('jmGraph') && this.graph) {
|
|
844
|
+
if(this.absoluteBounds.left >= this.graph.width) needDraw = false;
|
|
845
|
+
else if(this.absoluteBounds.top >= this.graph.height) needDraw = false;
|
|
846
|
+
else if(this.absoluteBounds.right <= 0) needDraw = false;
|
|
847
|
+
else if(this.absoluteBounds.bottom <= 0) needDraw = false;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
this.context.save && this.context.save();
|
|
851
|
+
|
|
852
|
+
this.emit('beginDraw', this);
|
|
853
|
+
|
|
854
|
+
this.setStyle();//设定样式
|
|
855
|
+
|
|
856
|
+
if(needDraw && this.beginDraw) this.beginDraw();
|
|
857
|
+
if(needDraw && this.draw) this.draw();
|
|
858
|
+
if(needDraw && this.endDraw) this.endDraw();
|
|
859
|
+
|
|
860
|
+
if(this.children) {
|
|
861
|
+
this.children.each(function(i,item) {
|
|
862
|
+
if(item && item.paint) item.paint();
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
this.emit('endDraw',this);
|
|
867
|
+
this.context.restore && this.context.restore();
|
|
868
|
+
|
|
869
|
+
this.needUpdate = false;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* 获取指定事件的集合
|
|
875
|
+
* 比如mousedown,mouseup等
|
|
876
|
+
*
|
|
877
|
+
* @method getEvent
|
|
878
|
+
* @param {string} name 事件名称
|
|
879
|
+
* @return {list} 事件委托的集合
|
|
880
|
+
*/
|
|
881
|
+
getEvent(name) {
|
|
882
|
+
return this.__events?this.__events[name]:null;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* 绑定控件的事件
|
|
887
|
+
*
|
|
888
|
+
* @method bind
|
|
889
|
+
* @param {string} name 事件名称
|
|
890
|
+
* @param {function} handle 事件委托
|
|
891
|
+
*/
|
|
892
|
+
bind(name, handle) {
|
|
893
|
+
if(name && name.indexOf(' ') > -1) {
|
|
894
|
+
name = name.split(' ');
|
|
895
|
+
for(let n of name) {
|
|
896
|
+
n && this.bind(n, handle);
|
|
897
|
+
}
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* 添加事件的集合
|
|
902
|
+
*
|
|
903
|
+
* @method _setEvent
|
|
904
|
+
* @private
|
|
905
|
+
*/
|
|
906
|
+
function _setEvent(name, events) {
|
|
907
|
+
if(!this.__events) this.__events = {};
|
|
908
|
+
return this.__events[name] = events;
|
|
909
|
+
}
|
|
910
|
+
let eventCollection = this.getEvent(name) || _setEvent.call(this, name, new jmList());
|
|
911
|
+
if(!eventCollection.contain(handle)) {
|
|
912
|
+
eventCollection.add(handle);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* 移除控件的事件
|
|
918
|
+
*
|
|
919
|
+
* @method unbind
|
|
920
|
+
* @param {string} name 事件名称
|
|
921
|
+
* @param {function} handle 从控件中移除事件的委托
|
|
922
|
+
*/
|
|
923
|
+
unbind(name, handle) {
|
|
924
|
+
if(name && name.indexOf(' ') > -1) {
|
|
925
|
+
name = name.split(' ');
|
|
926
|
+
for(let n of name) {
|
|
927
|
+
n && this.unbind(n, handle);
|
|
928
|
+
}
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
let eventCollection = this.getEvent(name) ;
|
|
932
|
+
if(eventCollection) {
|
|
933
|
+
if(handle) eventCollection.remove(handle);
|
|
934
|
+
else eventCollection.clear();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* 执行监听回调
|
|
941
|
+
*
|
|
942
|
+
* @method emit
|
|
943
|
+
* @for jmControl
|
|
944
|
+
* @param {string} name 触发事件的名称
|
|
945
|
+
* @param {array} args 事件参数数组
|
|
946
|
+
*/
|
|
947
|
+
emit(...args) {
|
|
948
|
+
this.runEventHandle(args[0], args.slice(1));
|
|
949
|
+
return this;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* 独立执行事件委托
|
|
954
|
+
*
|
|
955
|
+
* @method runEventHandle
|
|
956
|
+
* @param {string} 将执行的事件名称
|
|
957
|
+
* @param {object} 事件执行的参数,包括触发事件的对象和位置
|
|
958
|
+
*/
|
|
959
|
+
runEventHandle(name, args) {
|
|
960
|
+
let events = this.getEvent(name);
|
|
961
|
+
if(events) {
|
|
962
|
+
var self = this;
|
|
963
|
+
if(!Array.isArray(args)) args = [args];
|
|
964
|
+
events.each(function(i, handle) {
|
|
965
|
+
//只要有一个事件被阻止,则不再处理同级事件,并设置冒泡被阻断
|
|
966
|
+
if(false === handle.apply(self, args)) {
|
|
967
|
+
args.cancel = true;
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
return args.cancel;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* 检 查坐标是否落在当前控件区域中..true=在区域内
|
|
976
|
+
*
|
|
977
|
+
* @method checkPoint
|
|
978
|
+
* @param {point} p 位置参数
|
|
979
|
+
* @param {number} [pad] 可选参数,表示线条多远内都算在线上
|
|
980
|
+
* @return {boolean} 当前位置如果在区域内则为true,否则为false。
|
|
981
|
+
*/
|
|
982
|
+
checkPoint(p, pad) {
|
|
983
|
+
//jmGraph 需要判断dom位置
|
|
984
|
+
if(this.type == 'jmGraph') {
|
|
985
|
+
//获取dom位置
|
|
986
|
+
let position = this.getPosition();
|
|
987
|
+
// 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
|
|
988
|
+
const right = position.left + this.width;
|
|
989
|
+
const bottom = position.top + this.height;
|
|
990
|
+
if(p.x > right || p.x < position.left) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
if(p.y > bottom || p.y < position.top) {
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
const bounds = this.getBounds();
|
|
1000
|
+
// 如果指定了合中区域,则以命中区域为准
|
|
1001
|
+
if(this.hitArea) {
|
|
1002
|
+
const hitArea = {
|
|
1003
|
+
left: this.hitArea.x + bounds.left,
|
|
1004
|
+
top: this.hitArea.y + bounds.top,
|
|
1005
|
+
right: this.hitArea.width + bounds.left,
|
|
1006
|
+
bottom: this.hitArea.height + bounds.top,
|
|
1007
|
+
};
|
|
1008
|
+
if(p.x > hitArea.right || p.x < hitArea.left) {
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
1011
|
+
if(p.y > hitArea.bottom || p.y < hitArea.top) {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
let ps = this.points;
|
|
1018
|
+
//如果不是路径组成,则采用边界做为顶点
|
|
1019
|
+
if(!ps || !ps.length) {
|
|
1020
|
+
ps = [];
|
|
1021
|
+
ps.push({x: bounds.left, y: bounds.top}); //左上角
|
|
1022
|
+
ps.push({x: bounds.right, y: bounds.top});//右上角
|
|
1023
|
+
ps.push({x: bounds.right, y: bounds.bottom});//右下角
|
|
1024
|
+
ps.push({x: bounds.left, y: bounds.bottom}); //左下
|
|
1025
|
+
ps.push({x: bounds.left, y: bounds.top}); //左上角 //闭合
|
|
1026
|
+
}
|
|
1027
|
+
//如果有指定padding 表示接受区域加宽,命中更易
|
|
1028
|
+
pad = Number(pad || this.style['touchPadding'] || this.style['lineWidth'] || 1);
|
|
1029
|
+
if(ps && ps.length) {
|
|
1030
|
+
const rotation = this.getRotation(null, bounds);//获取当前旋转参数
|
|
1031
|
+
//如果有旋转参数,则需要转换坐标再处理
|
|
1032
|
+
if(rotation && rotation.angle) {
|
|
1033
|
+
ps = jmUtils.clone(ps, true);//拷贝一份数据
|
|
1034
|
+
//rotateX ,rotateY 是相对当前控件的位置
|
|
1035
|
+
ps = jmUtils.rotatePoints(ps, {
|
|
1036
|
+
x: rotation.x + bounds.left,
|
|
1037
|
+
y: rotation.y + bounds.top
|
|
1038
|
+
}, rotation.angle || 0);
|
|
1039
|
+
}
|
|
1040
|
+
//如果当前路径不是实心的
|
|
1041
|
+
//就只用判断点是否在边上即可
|
|
1042
|
+
if(ps.length > 2 && (!this.style['fill'] || this.style['stroke'])) {
|
|
1043
|
+
let i = 0;
|
|
1044
|
+
const count = ps.length;
|
|
1045
|
+
for(let j = i+1; j <= count; j = (++i + 1)) {
|
|
1046
|
+
//如果j超出最后一个
|
|
1047
|
+
//则当为封闭图形时跟第一点连线处理.否则直接返回false
|
|
1048
|
+
if(j == count) {
|
|
1049
|
+
if(this.style.close) {
|
|
1050
|
+
const r = jmUtils.pointInPolygon(p,[ps[i],ps[0]], pad);
|
|
1051
|
+
if(r) return true;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
//判断是否在点i,j连成的线上
|
|
1056
|
+
const s = jmUtils.pointInPolygon(p,[ps[i],ps[j]], pad);
|
|
1057
|
+
if(s) return true;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
//不是封闭的图形,则直接返回
|
|
1061
|
+
if(!this.style['fill']) return false;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
const r = jmUtils.pointInPolygon(p,ps, pad);
|
|
1065
|
+
return r;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if(p.x > bounds.right || p.x < bounds.left) {
|
|
1069
|
+
return false;
|
|
1070
|
+
}
|
|
1071
|
+
if(p.y > bounds.bottom || p.y < bounds.top) {
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* 触发控件事件,组合参数并按控件层级关系执行事件冒泡。
|
|
1081
|
+
*
|
|
1082
|
+
* @method raiseEvent
|
|
1083
|
+
* @param {string} name 事件名称
|
|
1084
|
+
* @param {object} args 事件执行参数
|
|
1085
|
+
* @return {boolean} 如果事件被组止冒泡则返回false,否则返回true
|
|
1086
|
+
*/
|
|
1087
|
+
raiseEvent(name, args) {
|
|
1088
|
+
if(this.visible === false) return ;//如果不显示则不响应事件
|
|
1089
|
+
if(!args.position) {
|
|
1090
|
+
const graph = this.graph;
|
|
1091
|
+
args.isWXMiniApp = graph.isWXMiniApp;
|
|
1092
|
+
|
|
1093
|
+
const srcElement = args.srcElement || args.target;
|
|
1094
|
+
|
|
1095
|
+
const position = jmUtils.getEventPosition(args);//初始化事件位置
|
|
1096
|
+
|
|
1097
|
+
args = {
|
|
1098
|
+
position: position,
|
|
1099
|
+
button: args.button == 0 || position.isTouch? 1: args.button,
|
|
1100
|
+
keyCode: args.keyCode || args.charCode || args.which,
|
|
1101
|
+
ctrlKey: args.ctrlKey,
|
|
1102
|
+
cancel : false,
|
|
1103
|
+
event: args, // 原生事件
|
|
1104
|
+
srcElement : srcElement,
|
|
1105
|
+
isWXMiniApp: graph.isWXMiniApp,
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
args.path = args.path||[]; //事件冒泡路径
|
|
1109
|
+
|
|
1110
|
+
//先执行子元素事件,如果事件没有被阻断,则向上冒泡
|
|
1111
|
+
let stoped = false;
|
|
1112
|
+
if(this.children) {
|
|
1113
|
+
this.children.each(function(j, el) {
|
|
1114
|
+
//未被阻止才执行
|
|
1115
|
+
if(args.cancel !== true) {
|
|
1116
|
+
//如果被阻止冒泡,
|
|
1117
|
+
stoped = el.raiseEvent(name, args) === false? true: stoped;
|
|
1118
|
+
// 不再响应其它元素
|
|
1119
|
+
if(stoped) return false;
|
|
1120
|
+
}
|
|
1121
|
+
}, true);//按逆序处理
|
|
1122
|
+
}
|
|
1123
|
+
// 如果已被阻止,不再响应上级事件
|
|
1124
|
+
if(stoped) return false;
|
|
1125
|
+
|
|
1126
|
+
//获取当前对象的父元素绝对位置
|
|
1127
|
+
//生成当前坐标对应的父级元素的相对位置
|
|
1128
|
+
let abounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds : this.absoluteBounds;
|
|
1129
|
+
if(!abounds) return false;
|
|
1130
|
+
//args = jmUtils.clone(args);//参数副本
|
|
1131
|
+
args.position.x = args.position.offsetX - abounds.left;
|
|
1132
|
+
args.position.y = args.position.offsetY - abounds.top;
|
|
1133
|
+
|
|
1134
|
+
// 是否在当前控件内操作
|
|
1135
|
+
const inpos = this.interactive !== false && this.checkPoint(args.position);
|
|
1136
|
+
|
|
1137
|
+
//事件发生在边界内或健盘事件发生在画布中才触发
|
|
1138
|
+
if(inpos) {
|
|
1139
|
+
//如果没有指定触发对象,则认为当前为第一触发对象
|
|
1140
|
+
if(!args.target) {
|
|
1141
|
+
args.target = this;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
this.runEventAndPopEvent(name, args);
|
|
1145
|
+
|
|
1146
|
+
if(!this.focused && (name === 'mousemove' || name === 'touchmove')) {
|
|
1147
|
+
this.focused = true;//表明当前焦点在此控件中
|
|
1148
|
+
this.raiseEvent(name === 'mousemove'? 'mouseover': 'touchover', args);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
else {
|
|
1152
|
+
//如果焦点不在,且原焦点在,则触发mouseleave事件
|
|
1153
|
+
if(this.interactive !== false && !inpos &&
|
|
1154
|
+
this.focused &&
|
|
1155
|
+
(name === 'mousemove' || name === 'touchmove')) {
|
|
1156
|
+
|
|
1157
|
+
this.focused = false;//表明当前焦点离开
|
|
1158
|
+
this.runEventHandle(name === 'mousemove'? 'mouseleave' : 'touchleave', args);//执行事件
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
return args.cancel === false;//如果被阻止则返回false,否则返回true
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* 执行事件,并进行冒泡
|
|
1167
|
+
* @param {string} name 事件名称
|
|
1168
|
+
* @param {object} args 事件参数
|
|
1169
|
+
*/
|
|
1170
|
+
runEventAndPopEvent(name, args) {
|
|
1171
|
+
|
|
1172
|
+
if(args.cancel !== true) {
|
|
1173
|
+
// 添加到触发路径
|
|
1174
|
+
args.path.push(this);
|
|
1175
|
+
|
|
1176
|
+
//如果返回true则阻断冒泡
|
|
1177
|
+
this.runEventHandle(name, args);//执行事件
|
|
1178
|
+
|
|
1179
|
+
// // 向父节点冒泡事件
|
|
1180
|
+
// if(args.cancel !== true && this.parent && this.parent.runEventAndPopEvent) {
|
|
1181
|
+
// // 相对位置需要改为父节点的
|
|
1182
|
+
// if(args.position) {
|
|
1183
|
+
// let bounds = this.parent.getBounds();
|
|
1184
|
+
// args.position.x += bounds.left;
|
|
1185
|
+
// args.position.y += bounds.top;
|
|
1186
|
+
// }
|
|
1187
|
+
// this.parent.runEventAndPopEvent(name, args);
|
|
1188
|
+
// }
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* 清空控件指定事件
|
|
1194
|
+
*
|
|
1195
|
+
* @method clearEvents
|
|
1196
|
+
* @param {string} name 需要清除的事件名称
|
|
1197
|
+
*/
|
|
1198
|
+
clearEvents(name) {
|
|
1199
|
+
var eventCollection = this.getEvent(name) ;
|
|
1200
|
+
if(eventCollection) {
|
|
1201
|
+
eventCollection.clear;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* 查找其父级类型为type的元素,直到找到指定的对象或到最顶级控件后返回空。
|
|
1207
|
+
*
|
|
1208
|
+
* @method findParent
|
|
1209
|
+
* @param {object} 类型名称或类型对象
|
|
1210
|
+
* @return {object} 指定类型的实例
|
|
1211
|
+
*/
|
|
1212
|
+
findParent(type) {
|
|
1213
|
+
//如果为类型名称,则返回名称相同的类型对象
|
|
1214
|
+
if(typeof type === 'string') {
|
|
1215
|
+
if(this.type == type)
|
|
1216
|
+
return this;
|
|
1217
|
+
}
|
|
1218
|
+
else if(this.is(type)) {
|
|
1219
|
+
return this;
|
|
1220
|
+
}
|
|
1221
|
+
if(this.parent) {
|
|
1222
|
+
return this.parent.findParent(type);
|
|
1223
|
+
}
|
|
1224
|
+
return null;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* 设定是否可以移动
|
|
1229
|
+
* 此方法需指定jmgraph或在控件添加到jmgraph后再调用才能生效。
|
|
1230
|
+
*
|
|
1231
|
+
* @method canMove
|
|
1232
|
+
* @param {boolean} m true=可以移动,false=不可移动或清除移动。
|
|
1233
|
+
* @param {jmGraph} [graph] 当前画布,如果为空的话必需是已加入画布的控件,否则得指定画布。
|
|
1234
|
+
*/
|
|
1235
|
+
canMove(m, graph) {
|
|
1236
|
+
if(!this.__mvMonitor) {
|
|
1237
|
+
/**
|
|
1238
|
+
* 控制控件移动对象
|
|
1239
|
+
*
|
|
1240
|
+
* @property __mvMonitor
|
|
1241
|
+
* @private
|
|
1242
|
+
*/
|
|
1243
|
+
this.__mvMonitor = {};
|
|
1244
|
+
this.__mvMonitor.mouseDown = false;
|
|
1245
|
+
this.__mvMonitor.curposition={x:0,y:0};
|
|
1246
|
+
var self = this;
|
|
1247
|
+
/**
|
|
1248
|
+
* 控件移动鼠标事件
|
|
1249
|
+
*
|
|
1250
|
+
* @method mv
|
|
1251
|
+
* @private
|
|
1252
|
+
*/
|
|
1253
|
+
this.__mvMonitor.mv = function(evt) {
|
|
1254
|
+
let _this = self;
|
|
1255
|
+
//如果鼠标经过当前可移动控件,则显示可移动指针
|
|
1256
|
+
//if(evt.path && evt.path.indexOf(_this)>-1) {
|
|
1257
|
+
// _this.cursor('move');
|
|
1258
|
+
//}
|
|
1259
|
+
|
|
1260
|
+
if(_this.__mvMonitor.mouseDown) {
|
|
1261
|
+
_this.parent.bounds = null;
|
|
1262
|
+
//let parentbounds = _this.parent.getAbsoluteBounds();
|
|
1263
|
+
let offsetx = evt.position.offsetX - _this.__mvMonitor.curposition.x;
|
|
1264
|
+
let offsety = evt.position.offsetY - _this.__mvMonitor.curposition.y;
|
|
1265
|
+
//console.log(offsetx + ',' + offsety);
|
|
1266
|
+
//如果锁定边界
|
|
1267
|
+
if(_this.option.lockSide) {
|
|
1268
|
+
let thisbounds = _this.bounds || _this.getAbsoluteBounds();
|
|
1269
|
+
//检查边界出界
|
|
1270
|
+
let outside = jmUtils.checkOutSide(_this.option.lockSide, thisbounds, { x: offsetx, y: offsety });
|
|
1271
|
+
if(outside.left < 0 && offsetx < 0) {
|
|
1272
|
+
//offsetx -= outside.left;
|
|
1273
|
+
offsetx = 0;
|
|
1274
|
+
}
|
|
1275
|
+
else if(outside.right > 0 && offsetx > 0) {
|
|
1276
|
+
//offsetx -= outside.right;
|
|
1277
|
+
offsetx = 0;
|
|
1278
|
+
}
|
|
1279
|
+
if(outside.top < 0 && offsety < 0) {
|
|
1280
|
+
//offsety -= outside.top;
|
|
1281
|
+
offsety = 0;
|
|
1282
|
+
}
|
|
1283
|
+
else if(outside.bottom > 0 && offsety > 0) {
|
|
1284
|
+
//offsety -= outside.bottom;
|
|
1285
|
+
offsety = 0;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
if(offsetx || offsety) {
|
|
1290
|
+
_this.offset(offsetx, offsety, true, evt);
|
|
1291
|
+
if(offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
|
|
1292
|
+
if(offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY;
|
|
1293
|
+
//console.log(offsetx + '.' + offsety);
|
|
1294
|
+
}
|
|
1295
|
+
return false;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* 控件移动鼠标松开事件
|
|
1300
|
+
*
|
|
1301
|
+
* @method mu
|
|
1302
|
+
* @private
|
|
1303
|
+
*/
|
|
1304
|
+
this.__mvMonitor.mu = function(evt) {
|
|
1305
|
+
let _this = self;
|
|
1306
|
+
if(_this.__mvMonitor.mouseDown) {
|
|
1307
|
+
_this.__mvMonitor.mouseDown = false;
|
|
1308
|
+
//_this.cursor('default');
|
|
1309
|
+
_this.emit('moveend',{position:_this.__mvMonitor.curposition});
|
|
1310
|
+
//return false;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* 控件移动鼠标离开事件
|
|
1315
|
+
*
|
|
1316
|
+
* @method ml
|
|
1317
|
+
* @private
|
|
1318
|
+
*/
|
|
1319
|
+
this.__mvMonitor.ml = function() {
|
|
1320
|
+
let _this = self;
|
|
1321
|
+
if(_this.__mvMonitor.mouseDown) {
|
|
1322
|
+
_this.__mvMonitor.mouseDown = false;
|
|
1323
|
+
//_this.cursor('default');
|
|
1324
|
+
_this.emit('moveend',{position:_this.__mvMonitor.curposition});
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* 控件移动鼠标按下事件
|
|
1330
|
+
*
|
|
1331
|
+
* @method md
|
|
1332
|
+
* @private
|
|
1333
|
+
*/
|
|
1334
|
+
this.__mvMonitor.md = function(evt) {
|
|
1335
|
+
|
|
1336
|
+
if(this.__mvMonitor.mouseDown) return;
|
|
1337
|
+
if(evt.button == 0 || evt.button == 1) {
|
|
1338
|
+
this.__mvMonitor.mouseDown = true;
|
|
1339
|
+
//this.cursor('move');
|
|
1340
|
+
//var parentbounds = this.parent.absoluteBounds || this.parent.getAbsoluteBounds();
|
|
1341
|
+
this.__mvMonitor.curposition.x = evt.position.offsetX;//evt.position.x + parentbounds.left;
|
|
1342
|
+
this.__mvMonitor.curposition.y = evt.position.offsetY;//evt.position.y + parentbounds.top;
|
|
1343
|
+
//触发控件移动事件
|
|
1344
|
+
this.emit('movestart',{position:this.__mvMonitor.curposition});
|
|
1345
|
+
|
|
1346
|
+
evt.cancel = true;
|
|
1347
|
+
return false;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
graph = graph || this.graph ;//获取最顶级元素画布
|
|
1352
|
+
|
|
1353
|
+
if(m !== false) {
|
|
1354
|
+
graph.bind('mousemove',this.__mvMonitor.mv);
|
|
1355
|
+
graph.bind('mouseup',this.__mvMonitor.mu);
|
|
1356
|
+
graph.bind('mouseleave',this.__mvMonitor.ml);
|
|
1357
|
+
this.bind('mousedown',this.__mvMonitor.md);
|
|
1358
|
+
graph.bind('touchmove',this.__mvMonitor.mv);
|
|
1359
|
+
graph.bind('touchend',this.__mvMonitor.mu);
|
|
1360
|
+
this.bind('touchstart',this.__mvMonitor.md);
|
|
1361
|
+
}
|
|
1362
|
+
else {
|
|
1363
|
+
graph.unbind('mousemove',this.__mvMonitor.mv);
|
|
1364
|
+
graph.unbind('mouseup',this.__mvMonitor.mu);
|
|
1365
|
+
graph.unbind('mouseleave',this.__mvMonitor.ml);
|
|
1366
|
+
this.unbind('mousedown',this.__mvMonitor.md);
|
|
1367
|
+
graph.unbind('touchmove',this.__mvMonitor.mv);
|
|
1368
|
+
graph.unbind('touchend',this.__mvMonitor.mu);
|
|
1369
|
+
this.unbind('touchstart',this.__mvMonitor.md);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
this.interactive = true;// 如果可以移动,则响应事件
|
|
1373
|
+
return this;
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1532
1377
|
export { jmControl };
|