echartsDrawGanTT.js
39.7 KB
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
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
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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
var echartsDrawGTT = function () {
// 定义图层
var bcdom = document.getElementById("bcContainer");
var chart = echarts.init(bcdom);
var upDowndom = document.getElementById("upDownContainer");
var upDownChart = echarts.init(upDowndom);
// upDowndom.style.height = '200px';
var option,upDownOption,dataZoomStart = 0,dataZoomEnd = 70;//图层对象
var historyData = [],// 保存操作图形后的数据集合(撤销与恢复操作)
_keyIndex = -1,// 记录当前操作步骤 (在撤销与恢复操作时)
dataUp = [],// (上/下)行发车时刻表数据
dataDown = [];
// y坐标
var lpData = []; //var lpData = ['连班_2','连班_1','连班_3'];
var lpDataCount = [];// lpDataCount[路牌名字]=[工时,班次,路牌序号]
// x坐标轴的范围
var time = DateTimeTool.getDateTime("03:00");
var xMax = Date.parse(time);
time.setDate(time.getDate()-1);
var xMin = Date.parse(time);
// 上下行bc颜色
var types = {'relationshipGraph-up': '#ff2949','relationshipGraph-down': '#518fe3'};
// 班次数据源
var bcData = [];
// 班次类型
// var bcType = [bd--早例保;out--出场;normal--正常;cf--吃饭;in--进场;lc--晚例保;major--放站;venting--直放;region--区间]
var bcType = new Map();
bcType['in'] = '到';
bcType['out'] = '离';
bcType['bd'] = '出';
bcType['lc'] = '进';
bcType["normal"] = '正';
bcType["cf"] = '吃';
bcType["major"] = '站';
bcType["venting"] = '直';
bcType["region"] = '区';
// 处理后班次数据
var data = [];
// 单个班次高度
var height;
// 坐标轴位置
var baseTop = 70;
var gridHeight = 60;
$("#bcContainer").bind("contextmenu", function(){
return false;
});
var setLpData = function (data) {
lpData = data;
};
var getLpData = function () {
return lpData;
};
var setLpDataCount = function (data) {
lpDataCount = data;
};
var getLpDataCount = function () {
return lpDataCount;
};
var set_keyIndex = function (indxe) {
_keyIndex = indxe;
};
var get_keyIndex = function () {
return _keyIndex;
};
var getHistoryData = function () {
return historyData;
};
var setHistoryData = function (data) {
historyData = data;
};
// 初始化 newData:数据、isLast:是否第一次、isNewData:是否是新数据(撤销、恢复不是)、newLpData:新路牌
var init = function (newData,isLast,isNewData,newLpData) {
if(isLast){
data = [];
bcData = newData;
echarts.util.each(bcData, function (bcObj, index) {
var fcsj = Date.parse(DateTimeTool.getDateTime(bcObj.fcsj)),
ARRIVALTIME = Date.parse(DateTimeTool.getDateTime(bcObj.ARRIVALTIME)),
colorStr = bcObj.xlDir,
xlDir;
if(bcObj.xlDir == 'relationshipGraph-up')
xlDir = 0;
else if(bcObj.xlDir == 'relationshipGraph-down')
xlDir = 1;
else
xlDir = -1;
data.push({
value: [
bcObj.lpName,//纵坐标
fcsj,//开始时间
ARRIVALTIME,//结束时间
bcObj.bcsj*60000,//横坐标长度(持续时间)
bcObj.lpNo,
bcObj.lpType,
bcObj.bcType,
bcObj.fcno,
xlDir,
bcObj.jhlc,
bcObj.tcc,
bcObj.ttinfo,
bcObj.xl,
bcObj.qdz,
bcObj.zdz,
bcObj.STOPTIME,
bcObj.isfb ? 1:0,
bcObj.qs
//bcObj.isSwitchXl,
//bcObj.bz,
],
itemStyle: {
normal: {
color: types[colorStr]
}
}
});
});
historyData.push(data);
_keyIndex++;
{ // 遍历获取路牌
var lpDataCache=[];
for(var j = 0,len=data.length; j < len; j++) {
lpDataCache.push([data[j].value[0],data[j].value[4]]);
}
lpDataCache.sort(function(a,b){
return b[1]-a[1];
});
$.each(lpDataCache,function () {
lpData.push(this[0]);
});
lpData = unique(lpData);
}
} else if(!isLast && isNewData){
data = newData;
historyData.splice(_keyIndex+1, historyData.length);
historyData.push(data);
_keyIndex++;
} else if(!isLast && !isNewData){
data = newData;
}
if(!newLpData){
for(var j = 0,len=lpData.length; j < len; j++) {
var type = true;
var name = lpData[j];
for(var i = 0,len2=data.length; i < len2; i++) {
if(name == data[i].value[0]) {
if(type){
lpDataCount[name] = [data[i].value[3]/60000+data[i].value[15],1,data[i].value[4]];
type = false;
} else if(data[i].value[6] == 'in' || data[i].value[16] == 1){
lpDataCount[name][0] += data[i].value[3]/60000;
lpDataCount[name][1] += 1;
} else {
lpDataCount[name][0] += (data[i].value[3]/60000+data[i].value[15]);
lpDataCount[name][1] += 1;
}
}
}
}
} else {
lpData = newLpData;// 添加路牌功能
}
// 计算图层高度
bcdom.style.height = (60+lpData.length*60)+'px';
option = {
tooltip: {
borderWidth: 1,
borderRadius: 0,
triggerOn: 'none',
textStyle: {
color: '#000'
},
backgroundColor: '#fff',
borderColor: 'rgba(0, 0, 20, 0.2)',
formatter: function (params) {
//bd--早例保;out--出场;normal--正常;cf--吃饭;in--进场;lc--晚例保;major--放站;venting--直放;region--区间
var bcTypeStr;
if(params.value[6]=='bd')
bcTypeStr='早例保';
else if(params.value[6]=='out')
bcTypeStr='出场';
else if(params.value[6]=='normal')
bcTypeStr='正常';
else if(params.value[6]=='cf')
bcTypeStr='吃饭';
else if(params.value[6]=='in')
bcTypeStr='进场';
else if(params.value[6]=='lc')
bcTypeStr='晚例保';
else if(params.value[6]=='major')
bcTypeStr='放站';
else if(params.value[6]=='venting')
bcTypeStr='直放';
else if(params.value[6]=='region')
bcTypeStr='区间';
var str = '当前路牌:'+params.value[0]
+ '<br> 行驶方向:'+(params.value[8]==0?'上行':'下行')+' <span>'+ params.marker +'</span>'
+'<br> fcno:  '+params.value[7]
+'<br>发车时间:' + getHoursAndMinutes(params.value[1])
+'<br>到站时间:' + getHoursAndMinutes(params.value[2])
+'<br>行驶时间:' + params.value[3]/60000 +'分钟'
+'<br>停休时间:' + params.value[15] +'分钟'
+'<br>班次类型:' + bcTypeStr ;
return str;
}
},
grid: {
top: '0px',
height: gridHeight * lpData.length
},
xAxis: [makeXAxis(0, {
splitLine: {show: true},
axisLine: {onZero: false, lineStyle: {color: '#000'}},
axisLabel: {
show: true,
interval:2,
formatter: function (val) {
return getHoursAndMinutes(val);
}
},
axisPointer: {
triggerTooltip: false,
triggerOn: 'none',
show: true,
label: {
show: true,
formatter: function (val) {
return getHoursAndMinutes(val.value);
}
}
}
})],
yAxis: {
data: lpData,
axisLabel:{
formatter: function (value, index) {
var texts = [
value ,
'{yAxisLeft|总工时:'+(lpDataCount[value][0]==0 ? 0:(lpDataCount[value][0]/60).toFixed(2)) + '}',
'{yAxisLeft|总班次:'+lpDataCount[value][1] + '}'
];
return texts.join('\n');
},
rich: {
yAxisLeft: {
backgroundColor: '#478cf1',
color: '#fff',
height: 20,
width: 80,
borderRadius: 10,
align: 'left',
padding: [0,0,0,5]
}
}
}
},
dataZoom: [{
type: 'slider',
top: gridHeight * (lpData.length) + 30,//+ gridHeight * (2+lpData.length)
filterMode: 'weakFilter',
wDataShadow: false,
borderColor: 'transparent',
backgroundColor: '#e2e2e2',
handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
handleSize: 20,
handleStyle: {
shadowBlur: 6,
shadowOffsetX: 1,
shadowOffsetY: 2,
shadowColor: '#000'
},
start: dataZoomStart,
end: dataZoomEnd
}],
series: [{
type: 'custom',
renderItem: renderItem,
itemStyle: {
normal: {
opacity: 0.8
}
},
encode: {
x: [1, 2],
y: 0
},
label: {
show: true,
position: 'insideTopLeft',
textBorderWidth: -1,
textBorderColor: '#000',
fontWeight: 65,
formatter: function (params) {
var p= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},[params.data.value[1],params.data.value[2]]);
var a = p[1]-p[0];
var type = params.data.value[6],
lastStr = '',// 班次历时
stayStr = '',// 停站时间
timeStr = '',
bcTypeStr = '';
if(type=='bd' || type=='lc' || type=='out' || type=='in')
timeStr = getHoursAndMinutes(params.data.value[1]);
else
timeStr = getHoursAndMinutes(params.data.value[1])+'~'+getHoursAndMinutes(params.data.value[2]);
var last = params.data.value[3] / 60000;
if(last>0) {
if(type=='bd' || type=='lc')
lastStr = "保:" + last;
else if(type=='cf')
lastStr = "吃:" + last;
else
lastStr = "行:" + last;
}
// 除了早晚例保,和进出场班次其余类型班次有停站时间
if(type!='bd' && type!='lc' && type!='out' && type!='in') {
//if(params.data.value[15]>=0)
stayStr = "停:" + params.data.value[15];
}
// 分班显示‘分’
if(params.data.value[16] == 1)
bcTypeStr = "分";
else
bcTypeStr = bcType[type];
var arr = [
'{left|' + timeStr + '}{type|'+ ((dataZoomEnd - dataZoomStart) <= 70 ? bcType[type] : '') +'}',
'{left|' + lastStr + '}{left|' + stayStr + '}'
];
return arr.join('\n');
},
rich: {
left: {
fontSize: 10,
color: '#000',
align: 'left'
},
type: {
fontSize: 13,
color: '#000',
align: 'right'
}
}
},
data: data
}],
// animation : false,
animationThreshold : 0,
animationDurationUpdate : 1500
};
if (option && typeof option === "object") {
chart.setOption(option, true);
}
// 刷新上下行发车时刻表数据
refreshUpDownData();
// 添加可托拽覆盖物
refreshDrag();
// 添加缩放数据适配
chart.on('dataZoom', updatePosition);
chart.resize();
upDownOption = {
tooltip: {
// trigger: 'axis',
borderWidth: 1,
textStyle: {
color: '#000'
},
backgroundColor: '#fff',
borderColor: 'rgba(0, 0, 20, 0.2)',
formatter: function (params) {
var style = 'color: ' + params.color;
var str = '<span style="' + style + '">发车时间:'+getHoursAndMinutes(params.value[1])+
'</br>发车间隔:'+params.value[0]+'分钟'+
'</br>路牌:'+params.value[2]+
'</br>fcno:'+params.value[7]+
'</span>';
return str;
}
},
grid: [
makeGrid(baseTop),
makeGrid(baseTop + gridHeight),
makeGrid(baseTop, {
show: true,
height: gridHeight * 2,
borderColor: '#ccc',
borderWidth: 1,
z: 10
})
],
xAxis: [
makeXAxis(0),
makeXAxis(1),
makeXAxis(2, {
position: 'top',
splitLine: {show: true},
axisLine: {onZero: false, lineStyle: {color: '#000'}},
axisLabel: {
show: true,
interval:2,
formatter: function (val) {
return getHoursAndMinutes(val);
}
},
axisPointer: {
triggerTooltip: false,
show: true,
lineStyle: {
color: '#478cf1',
width: 1.5
},
label: {
show: true,
formatter: function (val) {
return getHoursAndMinutes(val.value);
}
}
}
})
],
yAxis: [
makeYAxis(0, {
name: '上行发车时刻表'
}),
makeYAxis(1, {
name: '下行发车时刻表'
}),
makeYAxis(2)
],
dataZoom: [{
type: 'slider',
xAxisIndex: [0, 1, 2],
top: baseTop - 60,//+ gridHeight * (2+lpData.length)
filterMode: 'weakFilter',
wDataShadow: false,
borderColor: 'transparent',
backgroundColor: '#e2e2e2',
handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
handleSize: 20,
handleStyle: {
shadowBlur: 6,
shadowOffsetX: 1,
shadowOffsetY: 2,
shadowColor: '#000'
},
start: dataZoomStart,
end: dataZoomEnd
}],
visualMap: {
top: 70,
right: 20,
pieces: [{
lte: 8,
color: '#75b228'
},{
gt: 8,
lte: 20,
color: '#ff9933'
},{
gt: 20,
color: '#cc0033'
}],
outOfRange: {
color: '#999'
},
seriesIndex: [0, 1],
dimension: 0
},
series: [{
type: 'line',
itemStyle: {
normal: {
color: '#ff2949'
}
},
data: dataUp,
markLine: {
silent: true,
data: [{
yAxis: 8
}, {
yAxis: 20
}]
},
encode: {
x: 1,
y: 0
}
}, {
type: 'line',
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
normal: {
color: '#518fe3'
}
},
data: dataDown,
markLine: {
silent: true,
data: [{
yAxis: 8
}, {
yAxis: 20
}]
},
encode: {
x: 1,
y: 0
}
}],
//animationEasingUpdate: 'cubicInOut',
animationDurationUpdate: 1500
};
if (upDownOption && typeof upDownOption === "object") {
upDownChart.setOption(upDownOption, true);
}
// 添加缩放数据适配
upDownChart.on('dataZoom', updatePosition);
upDownChart.resize();
};
var renderItem = function (params, api) {
var categoryIndex = api.value(0); //这里使用api.value(0) 取出当前dataItem中第一个维度的数值
var start = api.coord([api.value(1), categoryIndex]);//将数值在当前坐标系中转换成为屏幕上的点的像素值 api.coord(//开始时间,种类),这)里返回是 start[0][1] x 坐标和 y坐标
var end = api.coord([api.value(2), categoryIndex]);//将数值在当前坐标系中转成屏幕上的点的像素值api.crood(开始时间,种类)相当于一个x yige y
height = api.size([0, 1])[1] * 0.6;
return {
type: 'rect',
shape: echarts.graphic.clipRectByRect(
{
x: start[0],//矩形的位置和大小
y: start[1] - height / 2,
width: end[0] - start[0],
height: height
},
{
x: params.coordSys.x,
y: params.coordSys.y,
width: params.coordSys.width,
height: params.coordSys.height
}),
style: api.style()
};
};
// 动作刷新底层班次(缩放条/拖动班次)
var updatePosition = function (e) {
data = $.extend(true, [], data, historyData[_keyIndex]);
dataZoomStart = e.start;
dataZoomEnd = e.end;
chart.setOption({
dataZoom: [{
start: dataZoomStart,
end: dataZoomEnd
}]
});
upDownChart.setOption({
dataZoom: [{
start: dataZoomStart,
end: dataZoomEnd
}]
});
chart.setOption({
series: [{
label: {
normal: {
show: true,
position: 'insideTopLeft',
textBorderWidth: 0,
textBorderColor: '#000',
formatter: function (params) {
var p= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},[params.data.value[1],params.data.value[2]]);
var a = p[1]-p[0];
var type = params.data.value[6],
lastStr = '',// 班次历时
stayStr = '',// 停站时间
timeStr = '';
if(type=='bd' || type=='lc' || type=='out' || type=='in')
timeStr = getHoursAndMinutes(params.data.value[1]);
else
timeStr = getHoursAndMinutes(params.data.value[1])+'~'+getHoursAndMinutes(params.data.value[2]);
var last = params.data.value[3] / 60000;
if(last>0) {
if(type=='bd' || type=='lc')
lastStr = "保:" + last;
else if(type=='cf')
lastStr = "吃:" + last;
else
lastStr = "行:" + last;
}
// 分班显示‘分’
if(params.data.value[16] == 1)
bcTypeStr = "分";
else
bcTypeStr = bcType[type];
if(type == 'normal') {
stayStr = "停:" + params.data.value[15];
}
var arr = [
'{left|' + timeStr + '}{type|'+ ((dataZoomEnd - dataZoomStart) <= 70 ? bcType[type] : '') +'}',
'{left|' + lastStr + '}{left|' + stayStr + '}'
];
return arr.join('\n');
},
rich: {
left: {
fontSize: 10,
//lineHeight: 30,
color: '#000',
align: 'left',
padding: [0, 5, 0, 0]
},
type: {
fontSize: 13,
color: '#000',
align: 'right'
}
}
}
},
data: data
}]
});
chart.setOption({
graphic: echarts.util.map(data, function (item, dataIndex) {
var p = [item.value[1],item.value[0]];
var p2 = [item.value[2],item.value[0]];
var pp= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p);
var pp2= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p2);
return {
position: chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p),
shape: {
width:pp2[0]-pp[0],
height:height
}
};
})
});
// console.log(data);
};
// 刷新可拖动阴影班次
var refreshDrag = function (){
data = historyData[_keyIndex];
chart.setOption({
graphic: echarts.util.map(data, function (item, dataIndex) {
var p = [item.value[1],item.value[0]];
var p2 = [item.value[2],item.value[0]];
var pp= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p);
var pp2= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p2);
var dataSize = data.length;
if(dataIndex<dataSize-1) {
for(var i=0;i<dataSize;i++) {
if(i==dataIndex)
continue;
if(data[dataIndex].value[6] == 'in' || data[dataIndex].value[16] == 1) {
data[dataIndex].value[15] = 0;
break;
}
if(data[dataIndex].value[4] == data[i].value[4] && data[dataIndex].value[7] == (data[i].value[7]-1)) {//同一路牌下的下一个班次的发车时间 - 本班次的到站时间 = 停车时间
data[dataIndex].value[15] = (data[dataIndex+1].value[1] - data[dataIndex].value[2])/60000;
break;
}
}
}
return {
type: 'rect',
borderWidth: 4,
position: chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0}, p),
shape: {
//x: -30,//矩形的位置和大小
width:pp2[0]-pp[0],
height:height,
y: -18
},
style:{
fill: 'rgba(121, 121, 121, 0.2)'
},
//invisible: false,
draggable: true,//是否可拖拽
progressive: true,
// silent : true,
onmousemove: echarts.util.curry(showTooltip, dataIndex),
onmouseout: echarts.util.curry(hideTooltip, dataIndex),
// ondragstart: echarts.util.curry(onPointDragging, dataIndex),
ondragend: echarts.util.curry(onPointDragging, dataIndex),
onmousedown: echarts.util.curry(rightClick, dataIndex),
z: 99
};
})
});
};
// 刷新上下行发车时刻表数据
var refreshUpDownData = function () {
// 清空数据
dataUp=[];
dataDown=[];
data = $.extend(true, [], data, historyData[_keyIndex]);
console.log(_keyIndex);
for(var i = 0,len=data.length; i < len; i++) {
var type = [];
type = $.extend(true, [], type, data[i].value);
if(data[i].value[6] == 'normal') {
if (data[i].value[8] == 0) {
dataUp.push(type);
} else if (data[i].value[8] == 1) {
dataDown.push(type);
}
}
}
dataUp.sort(function(a,b){
return a[1]-b[1];
});
dataDown.sort(function(a,b){
return a[1]-b[1];
});
for(var i = 0,len2=dataUp.length; i < len2; i++) {
dataUp[i][2] = dataUp[i][0];
if(i>0) {
dataUp[i][0] = (dataUp[i][1] - dataUp[i-1][1]) / 60000;
} else {
dataUp[i][0] = 0;
}
}
for(var i = 0,len3=dataDown.length; i < len3; i++) {
dataDown[i][2] = dataDown[i][0];
if(i>0) {
dataDown[i][0] = (dataDown[i][1] - dataDown[i-1][1]) / 60000;
} else {
dataDown[i][0] = 0;
}
}
if (option && typeof option === "object") {
chart.setOption({
series: [{
data: data
}]
});
}
if (upDownOption && typeof upDownOption === "object") {
upDownChart.setOption({
series: [{
xAxisIndex: 0,
yAxisIndex: 0,
data: dataUp
},{
xAxisIndex: 1,
yAxisIndex: 1,
data: dataDown
}]
});
}
};
// 定义班次调整事件可单击
var refreshBC = function (lpName){
data = historyData[_keyIndex];
chart.setOption({
graphic: echarts.util.map(data, function (item, dataIndex) {
var p = [item.value[1],item.value[0]];
var p2 = [item.value[2],item.value[0]];
var pp= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p);
var pp2= chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0},p2);
var dataSize = data.length;
if(dataIndex<dataSize-1) {
for(var i=0;i<dataSize;i++) {
if(i==dataIndex)
continue;
if(data[dataIndex].value[4] == data[i].value[4] && data[dataIndex].value[7] == (data[i].value[7]-1)) {//同一路牌下的下一个班次的发车时间 - 本班次的到站时间 = 停车时间
data[dataIndex].value[15] = (data[dataIndex+1].value[1] - data[dataIndex].value[2])/60000;
break;
}
}
}
return {
type: 'rect',
borderWidth: 4,
position: chart.convertToPixel({xAxisIndex: 0, yAxisIndex:0}, p),
shape: {
//x: -30,//矩形的位置和大小
width:pp2[0]-pp[0],
height:height,
y: -18
},
style:{
fill: 'rgba(121, 121, 121, 0.2)'
},
//invisible: false,
draggable: false,//是否可拖拽
progressive: true,
onclick: echarts.util.curry(bcClick, dataIndex,lpName),
ondragend: null,
onmousedown: null,
z: 999
};
})
});
};
var bcClick = function (dataIndex,lpName) {
var data = $.extend(true, [], data, historyData[_keyIndex]);
if(data[dataIndex].value[0] != lpName){
var a = $("#bcAdjustList").val();
if(a){
a.push(dataIndex);
} else
a = dataIndex;
$("#bcAdjustList").select2('val',a);
} else
layer.msg("不能选择目标路牌的班次!");
};
document.onclick = function(event){
var count=$(".dropdown-context").length;
if(count>0){
$(".dropdown-context").remove();
}
};
// 鼠标右击触发事件
var rightClick = function (dataIndex, e) {
var count=$(".dropdown-context").length;
if(count>0){
$(".dropdown-context").remove();
}
if(e.event.button == 2) {
var data = $.extend(true, [], data, historyData[_keyIndex]);
var s = data[dataIndex];
var htmlStr = template('rightClick_dropdown_menu',{ 'dataIndex': dataIndex, 'style': 'top: '+(e.offsetY+8)+'px; left:'+(e.offsetX-16)+'px; display: block;'});
$("#bcContainer").append(htmlStr);
}
};
// 显示Tooltip
var showTooltip = function (dataIndex,e) {
chart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: dataIndex
});
};
// 隐藏Tooltip
var hideTooltip = function (dataIndex) {
chart.dispatchAction({
type: 'hideTip'
});
};
// 拖动刷新底层班次
var onPointDragging = function (dataIndex,e) {
if(e.event.button == 0 || e.event.button == 1) {
var data = $.extend(true, [], data, historyData[_keyIndex]);
var p = chart.convertFromPixel({xAxisIndex: 0, yAxisIndex: 0}, this.position);
data[dataIndex].value[1] = Math.floor(p[0]/60000)*60000;
//data[dataIndex].value[0] = p[1]; // y轴数据改变(注释时表示只能拖动数据x轴移动)
data[dataIndex].value[2] = data[dataIndex].value[1] + data[dataIndex].value[3];
var flag = true;
for (var i = 0, len = data.length; i < len; i++) {
if (i == dataIndex)
continue;
// 同路牌比较
if (data[dataIndex].value[4] == data[i].value[4] && data[dataIndex].value[7] == (data[i].value[7] - 1)) {// 和后一个班次比较
if (data[dataIndex].value[2] > data[i].value[1]) {// 班次结束时间晚于于下一班次开始时间(处理数据)
data[dataIndex].value[2] = data[i].value[1];
data[dataIndex].value[1] = data[dataIndex].value[2] - data[dataIndex].value[3];
break;
}
}
if (data[dataIndex].value[4] == data[i].value[4] && data[dataIndex].value[7] == (data[i].value[7] + 1)) {// 和前一个班次比较
if (data[dataIndex].value[1] < data[i].value[2]) {// 班次开始时间早于上一班次结束时间(处理数据)
data[dataIndex].value[1] = data[i].value[2];
data[dataIndex].value[2] = data[dataIndex].value[1] + data[dataIndex].value[3];
//flag = false;
break;
}
}
// 阴影拖动外围在xMin-xMax之间
if (data[dataIndex].value[1] < xMin) {
data[dataIndex].value[1] = xMin;
data[dataIndex].value[2] = data[dataIndex].value[1] + data[dataIndex].value[3];
}
if (data[dataIndex].value[2] > xMax) {
data[dataIndex].value[2] = xMax;
data[dataIndex].value[1] = data[dataIndex].value[2] - data[dataIndex].value[3];
}
}
set_keyIndex(++_keyIndex);
historyData[_keyIndex] = $.extend(true, [], historyData[_keyIndex], data);// 历史数组增加一次数据
refreshDrag();
refreshUpDownData();
historyData.splice(_keyIndex + 1, historyData.length);// 数据改变后过后清除多余的历史数据
init(historyData[_keyIndex],false,false);
} else {
refreshDrag();
}
};
var makeXAxis = function(gridIndex, opt) {
return echarts.util.merge({
type: 'time',
gridIndex: gridIndex,
axisLine: {onZero: false, lineStyle: {color: '#ddd'}},
axisTick: {show: false},
axisLabel: {show: false},
splitLine: {show: false, lineStyle: {color: '#ddd'}},
min: xMin,//"2010-01-01 03:30:00"
max: xMax,//"2010-01-02 03:30:00"
scale: true,
axisPointer: {
lineStyle: {color: 'transparent'}
},
maxInterval: 3600000
}, opt || {}, true);
};
var makeYAxis = function (gridIndex, opt) {
return echarts.util.merge({
type: 'value',
gridIndex: gridIndex,
// nameLocation: 'middle',
nameLocation: 'left',
nameTextStyle: {
color: '#333'
},
min: 0,
max: function(value) {
if(value.max < 30)
return 30;
else
return value.max + 5;
},
axisTick: {show: false},
//axisLine: {lineStyle: {color: '#ccc'}},
axisLabel: {show: false},
splitLine: {show: false}
}, opt || {}, true);
};
var makeGrid = function (top, opt) {
return echarts.util.merge({
top: top,
height: gridHeight
}, opt || {}, true);
};
// 窗口大小改变刷新图层
$(window).resize(function() {
resizeChart();
});
// 刷新图层大小
var resizeChart = function () {
chart.resize();
upDownChart.resize();
refreshDrag();
};
// 补齐两位
var swallowTow = function (date) {
return date>=10?date:(date="0"+date);
};
// 时间戳转时间(时间:分钟)
var getHoursAndMinutes = function (timestamp) {
var date = new Date(timestamp);
var Hours = swallowTow(date.getHours());
var Minutes = swallowTow(date.getMinutes());
return Hours+":"+Minutes;
};
/* 数组去重
* 优化遍历数组法
* 思路:获取没重复的最右一值放入新数组
*/
var unique = function (array){
var r = [];
for(var i = 0, l = array.length; i < l; i++) {
for(var j = i + 1; j < l; j++)
if (array[i] === array[j]) j = ++i;
r.push(array[i]);
}
return r;
};
return {
init: init,
setLpData: setLpData,
getLpData: getLpData,
setLpDataCount: setLpDataCount,
getLpDataCount: getLpDataCount,
set_keyIndex: set_keyIndex,
get_keyIndex: get_keyIndex,
setHistoryData: setHistoryData,
getHistoryData: getHistoryData,
refreshDrag: refreshDrag,
refreshUpDownData: refreshUpDownData,
refreshBC: refreshBC,
resizeChart: resizeChart
};
}();