1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
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
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
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
775
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
| import Diagram from './index'
| import eleGroupImage from './images/elegroup.png'
| import loaderImage from './images/load.png'
| import screenImage from './images/screen.png'
| import lightDangerImage from './images/light-danger.png'
| import lightSuccessImage from './images/light-success.png'
| import chargeSuccessImage from './images/charge-success.png'
| import chargeDangerImage from './images/charge-danger.png'
| const textFont = 20;
|
| function loadCircuitDiagram(stc, flush) {
| let diagram = new Diagram();
| diagram.setCanvas(stc, flush);
| let start = [280, 40]
|
| // 虚线1
| let dashPoints1 = diagram.dashLine({
| strokeStyle: '#50cef5',
| points: [
| start,
| [950, start[1]],
| ]
| });
| // 虚线2
| let dashPoints2 = diagram.dashLine({
| strokeStyle: '#50cef5',
| points: [
| dashPoints1[1],
| [dashPoints1[1][0], diagram.height-start[1]],
| ]
| });
| // 虚线3
| let dashPoints3 = diagram.dashLine({
| strokeStyle: '#50cef5',
| points: [
| dashPoints2[1],
| [start[0], dashPoints2[1][1]],
| ]
| });
|
| // 虚线4
| let dashPoints4 = diagram.dashLine({
| strokeStyle: '#50cef5',
| points: [
| dashPoints3[1],
| start,
| ],
| });
|
| // 充放电单元配置项
| let options = {
| top: start,
| bottom: dashPoints3[0],
| start: [start[0]+15, diagram.height/3]
| };
|
| // 绘制充放电单元
| let chargeAndDischarge = drawChargeAndDischarge(diagram, options);
|
| // 绘制蓄电池组单元
| let battGroup = drawBattGroup(diagram, chargeAndDischarge);
|
| // 绘制负载模块
| loaderMoudle(diagram, battGroup);
|
| // 设置页面中的文本
| setDiagramTexts(diagram);
| return diagram;
| }
|
| // 充放电单元
| function drawChargeAndDischarge(diagram, options) {
| let start = options.start;
| // 对角边界
| let top = options.top;
| let bottom = options.bottom;
| // 基础配置
| let springGreen = "#50cef5";
| let red = '#b370fe';
| let lineWidth = 3;
|
| // 线条1
| let line1 = diagram.line({
| id: 'line1-3',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| hide: true,
| points: [
| start,
| [start[0]+40, start[1]]
| ]
| });
|
| // 充放电单元
| let chargeAndDischarge = diagram.chargeAndDischarge({
| hide: true,
| point: line1[1]
| });
|
| // 放电单元状态
| let dischargeState = diagram.drawImage({
| id: 'dischargeState',
| flush: true,
| hide: true,
| url: lightSuccessImage,
| point: [chargeAndDischarge[0][0] - 50, chargeAndDischarge[0][1]+50],
| // width: 24,
| // height: 24*469/471
| width: 22,
| height: 46
| });
|
| // 放电单元文本
| let disCharge_text = diagram.text({
| text: '放电单元',
| baseline: 'middle',
| fontSize: 16,
| hide: true,
| point: [dischargeState.right[0]+4, dischargeState.right[1]]
| });
|
| // 充电单元状态
| let chargeState = diagram.drawImage({
| id: 'chargeState',
| flush: true,
| hide: true,
| url: chargeSuccessImage,
| point: [chargeAndDischarge[1][0] - 50, chargeAndDischarge[1][1]+50],
| width: dischargeState.width,
| height: dischargeState.height
| });
|
| // 充电单元文本
| let charge_text = diagram.text({
| text: '充电单元',
| baseline: 'middle',
| fontSize: 16,
| hide: true,
| point: [chargeState.right[0]+4, chargeState.right[1]]
| });
|
| // 线条2
| let line2 = diagram.line({
| id: 'line1',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| chargeAndDischarge[0],
| [chargeAndDischarge[0][0], top[1]+30]
| ]
| });
|
| // 线的高度
| let lineHt = line2[0][1] - line2[1][1];
|
| // 线条3
| let line3 = diagram.line({
| id: 'line2',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| line2[1],
| [chargeAndDischarge[1][0], line2[1][1]]
| ]
| });
|
| // 线条4
| let line4 = diagram.line({
| id: 'line3',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| line3[1],
| [chargeAndDischarge[1][0], chargeAndDischarge[1][1]]
| ]
| });
|
| // 线条5
| let line5 = diagram.line({
| id: 'line4',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| chargeAndDischarge[2],
| [chargeAndDischarge[2][0], chargeAndDischarge[2][1]+lineHt]
| ]
| });
|
| // 线条6
| let line6 = diagram.line({
| id: 'line5',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| line5[1],
| [chargeAndDischarge[3][0], line5[1][1]]
| ]
| });
|
| // 线条7
| let line7 = diagram.line({
| id: 'line6',
| strokeStyle: red,
| lineWidth: lineWidth,
| hide: true,
| points: [
| line6[1],
| [chargeAndDischarge[3][0], chargeAndDischarge[3][1]]
| ]
| });
|
| // 线条8
| let line8 = diagram.line({
| id: 'line7',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line6[0],
| [line6[0][0]+120, line6[0][1]]
| ]
| });
|
| // 线条9
| let line9 = diagram.line({
| id: "line1-1",
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| hide: true,
| points: [
| [line8[1][0], bottom[1]-80],
| [line1[0][0], bottom[1]-80]
| ]
| });
|
| // 线条10
| let line10 = diagram.line({
| id: "line1-2",
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| hide: true,
| points: [
| line9[1],
| line1[0]
| ]
| });
|
| let onOff1 = diagram.onOff({
| id: 'km2',
| point: line8[1],
| direction: 'right',
| state: false,
| flush: true,
| });;
|
| // 设置km2的文本
| let middle = (onOff1.arc2.bottom[0] - onOff1.arc1.bottom[0])/2;
| let onOff1_text1 = diagram.text({
| text: 'k2',
| align: 'center',
| fontSize: 16,
| point: [onOff1.arc1.bottom[0]+middle, onOff1.arc1.bottom[1]+8]
| });
|
| let onOff2 = diagram.onOff({
| id: 'km3',
| point: line9[0],
| direction: 'right',
| state: false,
| flush: true
| });
|
| let onOff2_text1 = diagram.text({
| text: 'k3',
| align: 'center',
| fontSize: 16,
| point: [onOff2.arc1.bottom[0]+middle, onOff2.arc1.bottom[1]+8]
| });
|
| // 充电电源模块
| let chargeRect = diagram.drawRect({
| point: [start[0], start[1]-60],
| });
|
| // 充电单元状态
| let chargeStateRect = diagram.drawImage({
| id: 'chargeStateRect',
| flush: true,
| url: chargeSuccessImage,
| point: [chargeRect.top[0] - 50, chargeRect.top[1]+40],
| width: dischargeState.width,
| height: dischargeState.height
| });
|
| // 充电单元文本
| let chargeRectText = diagram.text({
| text: '充电单元',
| baseline: 'middle',
| fontSize: 16,
| point: [chargeStateRect.right[0]+4, chargeStateRect.right[1]]
| });
|
| let line12 = diagram.line({
| id: "line12-1",
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| chargeRect.top,
| [chargeRect.top[0], line3[0][1]]
| ]
| });
|
| let line13 = diagram.line({
| id: "line13-1",
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| chargeRect.bottom,
| [chargeRect.bottom[0], line6[0][1]]
| ]
| });
|
| let line15 = diagram.line({
| id: "line15-1",
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line13[1],
| [line6[0][0], line13[1][1]]
| ]
| });
|
| let line14 = diagram.line({
| id: "line14-1",
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line12[1],
| [line3[1][0], line12[1][1]]
| ]
| });
|
| // 充电电源模块
| let loaderRect = diagram.drawRect({
| point: [line13[1][0]-60, line13[1][1]+40],
| });
|
| // 充电单元状态
| let loaderStateRect = diagram.drawImage({
| id: 'loaderStateRect',
| flush: true,
| url: chargeSuccessImage,
| point: [loaderRect.top[0] - 50, loaderRect.top[1]+40],
| width: dischargeState.width,
| height: dischargeState.height
| });
|
| // 充电单元文本
| let loaderRectText = diagram.text({
| text: '假负载模块',
| baseline: 'middle',
| fontSize: 16,
| point: [loaderStateRect.right[0]+4, loaderStateRect.right[1]]
| });
|
| let line16 = diagram.line({
| id: "line16-1",
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line13[1],
| loaderRect.top
| ]
| });
| let line17 = diagram.line({
| id: "line17-1",
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| loaderRect.bottom,
| [loaderRect.bottom[0], line9[0][1]]
| ]
| });
|
| let line18 = diagram.line({
| id: "line18-1",
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| line9[0],
| [loaderRect.bottom[0], line9[0][1]]
| ]
| });
|
| return {
| top: top,
| bottom: bottom,
| springGreen: springGreen,
| red: red,
| line3: line3,
| onOff1: onOff1,
| onOff2: onOff2,
| }
| }
|
| // 蓄电池组单元
| function drawBattGroup(diagram, options) {
| let start = options.line3[1];
| // 对角边界
| let top = options.top;
| let bottom = options.bottom;
| // 基础配置
| let springGreen = options.springGreen;
| let red = options.red;
| let lineWidth = 3;
|
| // BAT1
| let bat1 = diagram.bat({
| strokeStyle: springGreen,
| point: [bottom[0], start[1]]
| });
|
| // 线条1
| let line1 = diagram.line({
| id: 'line8',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| start,
| bat1.left,
| ]
| });
|
| // BAT2
| let bat2 = diagram.bat({
| strokeStyle: springGreen,
| point: [bottom[0], options.onOff1.arc2.right[1]]
| });
|
| // 线条2
| let line2 = diagram.line({
| id: 'line9',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| options.onOff1.arc2.right,
| bat2.left,
| ]
| });
|
| // BAT3
| let bat3 = diagram.bat({
| fillStyle: '#000000',
| strokeStyle: springGreen,
| point: [bottom[0], options.onOff2.arc2.right[1]]
| });
|
| // 线条3
| let line3 = diagram.line({
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| options.onOff2.arc2.right,
| bat3.left,
| ]
| });
|
| // 线条4
| let line4 = diagram.line({
| id: 'line10',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| bat2.right,
| [bat2.right[0]+60, bat2.right[1]],
| ]
| });
|
| // 线条5
| let line5 = diagram.line({
| id: 'line11',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line4[1],
| [line4[1][0], line4[1][1]+30],
| ]
| });
|
| // 绘制电池组1
| // let width1 = 70;
| let width1 = 37;
| let height1 = 61;
| let eleGroup1 = diagram.drawImage({
| id: 'eleGroup1',
| point: [line5[1][0]-width1/2, line5[1][1]],
| url: eleGroupImage,
| width: width1,
| // height: width1*25/61,
| height: height1,
| });
| // 绘制虚线
| let dashLine1 = diagram.dashLine({
| strokeStyle: springGreen,
| lineWidth: 4,
| points: [
| eleGroup1.bottom,
| [eleGroup1.bottom[0], eleGroup1.bottom[1]+20]
| ],
| });
| // 电池组2
| let eleGroup2 = diagram.drawImage({
| id: 'eleGroup2',
| point: [dashLine1[1][0]-width1/2, dashLine1[1][1]],
| url: eleGroupImage,
| width: eleGroup1.width,
| height: eleGroup1.height,
| });
|
| // 绘制电池组的文本
| let group_text1 = diagram.text({
| text: '电&池&组',
| point: [eleGroup1.right[0]+6, eleGroup1.right[1]+4],
| fontSize: 16,
| });
|
| // 线条6
| let line6 = diagram.line({
| id: 'line12',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| eleGroup2.bottom,
| [eleGroup2.bottom[0], bat3.right[1]],
| ]
| });
| // 线条7
| let line7 = diagram.line({
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| bat3.right,
| line6[1],
| ]
| });
|
| // 线条8
| let left1 = 80;
| let line8 = diagram.line({
| id: 'line13',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| [line2[0][0]+left1, line1[0][1]],
| [line2[0][0]+left1, line1[0][1]+160],
| ]
| });
|
| // km1
| let onOff3 = diagram.onOff({
| id: 'km1',
| point: line8[1],
| direction: 'bottom',
| state: false,
| flush: true
| });
|
| // km1文本
| let onOFF3_text = diagram.text({
| text: 'k1',
| align: 'end',
| fontSize: 16,
| point: [onOff3.arc1.left[0]-8,onOff3.arc1.left[1]+10]
| });
|
| // lin9
| let line9 = diagram.line({
| id: 'line14',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| onOff3.arc2.bottom,
| [onOff3.arc2.bottom[0], line2[0][1]]
| ]
| });
|
| // line131
| let line131y = line8[0][1]+(line8[1][1]-line8[0][1])/2;
| let diodeOffsetX = 100;
| let line131 = diagram.line({
| id: 'line131',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| [line8[0][0], line131y],
| [line8[0][0]+diodeOffsetX, line131y],
| ]
| });
|
| // line132
| let line132 = diagram.line({
| id: 'line132',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line131[1],
| [line131[1][0], line131[1][1]+70]
| ]
| });
|
| // 绘制二极管
| let diode = diagram.diode({
| point: line132[1],
| });
|
| // line141
| let line141y = line9[0][1]+(line9[1][1]-line9[0][1])/2;
| let line141 = diagram.line({
| id: 'line141',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| [line9[0][0], line141y],
| [line9[0][0]+diodeOffsetX, line141y],
| ]
| });
|
| // line142
| let line142 = diagram.line({
| id: 'line142',
| strokeStyle: red,
| lineWidth: lineWidth,
| points:[
| diode.bottom,
| line141[1]
| ]
| });
| return {
| bat1: bat1,
| line6: line6,
| springGreen: springGreen,
| red: red,
| lineWidth: lineWidth
| };
| }
|
| // 负载单元
| function loaderMoudle(diagram, options) {
| // 基础配置
| let right = 80;
| let start = options.bat1.right;
| let springGreen = options.springGreen;
| let lineWidth = options.lineWidth;
| let red = options.red;
| let end = options.line6[1];
| let middle = (diagram.width-right-start[0])/2;
|
| // 绘制线1
| let line1 = diagram.line({
| id: 'line15',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| start,
| [start[0]+middle, start[1]]
| ]
| });
|
| // 绘制线2
| let line2 = diagram.line({
| id: 'line16',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line1[1],
| [diagram.width-right, line1[1][1]]
| ]
| });
| let lineHeight = 220;
|
| // 绘制线3
| let line3 = diagram.line({
| id: 'line17',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line2[1],
| [line2[1][0], line2[1][1]+lineHeight],
| ]
| });
|
| // 绘制负载
| let loaderWidth = 86;
| let loader = diagram.drawImage({
| url: loaderImage,
| point: [line3[1][0]-loaderWidth/2, line3[1][1]-3],
| width: loaderWidth,
| height: loaderWidth*248/136
| });
|
| // 负载文本
| let loader_text1 = diagram.text({
| text: "用&电&负&载",
| fontSize: 16,
| point: [loader.right[0]+4, loader.right[1]-30],
| });
|
| // 绘制线4
| let line4 = diagram.line({
| id: 'line18',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| loader.bottom,
| [loader.bottom[0], end[1]],
| ]
| });
|
| // 绘制线5
| let line5 = diagram.line({
| id: 'line19',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| line4[1],
| [line1[1][0], line4[1][1]],
| ]
| });
|
| // 绘制线6
| let line6 = diagram.line({
| id: 'line20',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| line5[1],
| end,
| ]
| });
|
| // 绘制线7
| let line7 = diagram.line({
| id: 'line21',
| strokeStyle: red,
| lineWidth: lineWidth,
| points: [
| line1[1],
| [line1[1][0], line1[1][1]+lineHeight],,
| ]
| });
|
| // 绘制整流器
| let screen = diagram.drawImage({
| url: screenImage,
| point: [line7[1][0]-loaderWidth/2, line7[1][1]-3],
| width: loaderWidth,
| height: loaderWidth*248/151
| });
|
| // 整流器文本
| let screen_text1 = diagram.text({
| text: "整&流&器",
| fontSize: 16,
| point: [screen.right[0]+4, screen.right[1]-20],
| });
|
| // 绘制线8
| let line8 = diagram.line({
| id: 'line22',
| strokeStyle: springGreen,
| lineWidth: lineWidth,
| points: [
| screen.bottom,
| line5[1],
| ]
| });
| }
|
| function setDiagramTexts(diagram) {
| // 设备温度
| let line3 = diagram.getOption('line3').points;
| let line13 = diagram.getOption('line13').points;
| let offset1 = (line13[0][0] - line3[0][0])/2;
| diagram.text({
| id: 'devTemp',
| flush: true,
| baseline: 'top',
| align: 'center',
| fontSize: textFont,
| point: [line3[0][0]+offset1, line3[0][1]+16],
| text: '设备温度:0℃'
| });
|
| // 电流
| let line15 = diagram.getOption('line15').points;
| let offset2 = (line15[1][0] - line15[0][0])/2;
| diagram.text({
| id: 'battCurr',
| flush: true,
| baseline: 'top',
| align: 'center',
| fontSize: textFont,
| point: [line15[0][0]+offset2, line15[0][1]+16],
| text: '0.00A'
| });
|
| // 在线电压
| let line16 = diagram.getOption('line16').points;
| let offset3 = (line16[1][0] - line16[0][0])/2;
| diagram.text({
| id: 'onlineVol',
| flush: true,
| baseline: 'top',
| align: 'center',
| fontSize: textFont,
| point: [line16[0][0]+offset3, line16[0][1]+16],
| text: '0.00V'
| });
|
| // 组端电压
| let line11 = diagram.getOption('line11').points;
| diagram.text({
| id: 'groupVol',
| flush: true,
| baseline: 'bottom',
| align: 'left',
| fontSize: textFont,
| point: [line11[1][0]+8,line11[1][1]-4],
| text: '0.00V'
| });
|
| // 设置电路图类型
| diagram.text({
| id: 'type',
| flush: true,
| fontSize: textFont,
| align: 'center',
| point: [diagram.width/2, 10],
| text: '设备未连接',
| });
| }
| export default loadCircuitDiagram;
|
|