forked from de-vnull/vnstat-on-merlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvnstat-ui.asp
2234 lines (2104 loc) · 70.7 KB
/
vnstat-ui.asp
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="icon" href="images/favicon.png">
<title>dn-vnstat</title>
<link rel="stylesheet" type="text/css" href="index_style.css">
<link rel="stylesheet" type="text/css" href="form_style.css">
<style>
p{font-weight:bolder}thead.collapsible-jquery{color:#fff;padding:0;width:100%;border:none;text-align:left;outline:none;cursor:pointer}.SettingsTable{text-align:left}.SettingsTable input{text-align:left;margin-left:3px!important}.SettingsTable input.savebutton{text-align:center;margin-top:5px;margin-bottom:5px;border-right:solid 1px #000;border-left:solid 1px #000;border-bottom:solid 1px #000}.SettingsTable td.savebutton{border-right:solid 1px #000;border-left:solid 1px #000;border-bottom:solid 1px #000;background-color:#4d595d}.SettingsTable .cronbutton{text-align:center;min-width:50px;width:50px;height:23px;vertical-align:middle}.SettingsTable select{margin-left:3px!important}.SettingsTable label{margin-right:10px!important;vertical-align:top!important}.SettingsTable th{background-color:#1F2D35!important;background:#2F3A3E!important;border-bottom:none!important;border-top:none!important;font-size:12px!important;color:#fff!important;padding:4px!important;font-weight:bolder!important;padding:0!important}.SettingsTable th.sectionheader{padding-left:10px!important;border-right:solid 1px #000!important;border-left:solid 1px #000!important}.SettingsTable td{word-wrap:break-word!important;overflow-wrap:break-word!important;border-right:none;border-left:none}.SettingsTable span.settingname{background-color:#1F2D35!important;background:#2F3A3E!important}.SettingsTable td.settingname{border-right:solid 1px #000;border-left:solid 1px #000;background-color:#1F2D35!important;background:#2F3A3E!important;width:35%!important}.SettingsTable td.settingvalue{text-align:left!important;border-right:solid 1px #000}.SettingsTable th:first-child{border-left:none}.SettingsTable th:last-child{border-right:none}.SettingsTable .invalid{background-color:#8b0000!important}.SettingsTable .disabled{background-color:#CCC!important;color:#888!important}.removespacing{padding-left:0!important;margin-left:0!important;margin-bottom:5px!important;text-align:center!important}.usagehint{color:#FF0!important}div.vnstat{background-repeat:no-repeat!important;background-position:center!important}
</style>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/jquery.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/moment.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/chart.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/hammerjs.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/chartjs-plugin-zoom.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/chartjs-plugin-annotation.js"></script>
<script language="JavaScript" type="text/javascript" src="ext/shared-jy/chartjs-plugin-trendline.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/d3.js"></script>
<script language="JavaScript" type="text/javascript" src="/state.js"></script>
<script language="JavaScript" type="text/javascript" src="/general.js"></script>
<script language="JavaScript" type="text/javascript" src="/popup.js"></script>
<script language="JavaScript" type="text/javascript" src="/help.js"></script>
<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/detect.js"></script>
<script language="JavaScript" type="text/javascript" src="/tmhist.js"></script>
<script language="JavaScript" type="text/javascript" src="/tmmenu.js"></script>
<script language="JavaScript" type="text/javascript" src="/client_function.js"></script>
<script language="JavaScript" type="text/javascript" src="/validator.js"></script>
<script>
var custom_settings;
function LoadCustomSettings(){
custom_settings = <% get_custom_settings(); %>;
for (var prop in custom_settings){
if(Object.prototype.hasOwnProperty.call(custom_settings, prop)){
if(prop.indexOf('dnvnstat') != -1 && prop.indexOf('dnvnstat_version') == -1){
eval('delete custom_settings.'+prop)
}
}
}
}
var $j = jQuery.noConflict(); //avoid conflicts on John's fork (state.js)
var maxNoCharts = 12;
var currentNoCharts = 0;
var ShowTrendlines = GetCookie('ShowTrendlines','string');
if(ShowTrendlines == ''){
ShowTrendlines='0';
}
var ShowLines = GetCookie('ShowLines','string');
var ShowFill = GetCookie('ShowFill','string');
if(ShowFill == ''){
ShowFill = 'origin';
}
var DragZoom = true;
var ChartPan = false;
Chart.defaults.global.defaultFontColor = '#CCC';
Chart.Tooltip.positioners.cursor = function(chartElements,coordinates){
return coordinates;
};
var dataintervallist = ['fiveminute','hour','day'];
var chartlist = ['daily','weekly','monthly'];
var timeunitlist = ['hour','day','day'];
var intervallist = [24,7,30];
var bordercolourlist= ['#c5c5ce','#0ec009','#956222','#38959d'];
var backgroundcolourlist = ['rgba(197,197,206,0.5)','rgba(14,192,9,0.5)','rgba(149,98,34,0.5)','rgba(56,149,157,0.5)'];
var trendcolourlist = ['rgba(197,197,206,'+ShowTrendlines+')','rgba(14,192,9,'+ShowTrendlines+')','rgba(149,98,34,'+ShowTrendlines+')','rgba(56,149,157,'+ShowTrendlines+')'];
var chartobjlist = ['Chart_DataUsage','Chart_CompareUsage'];
function keyHandler(e){
if(e.keyCode == 82){
$j(document).off('keydown');
ResetZoom();
}
else if(e.keyCode == 68){
$j(document).off('keydown');
ToggleDragZoom(document.form.btnDragZoom);
}
else if(e.keyCode == 70){
$j(document).off('keydown');
ToggleFill();
}
else if(e.keyCode == 76){
$j(document).off('keydown');
ToggleLines();
}
}
$j(document).keydown(function(e){keyHandler(e);});
$j(document).keyup(function(e){
$j(document).keydown(function(e){
keyHandler(e);
});
});
function UsageHint(){
var tag_name= document.getElementsByTagName('a');
for(var i = 0; i<tag_name.length; i++){
tag_name[i].onmouseout=nd;
}
hinttext=thresholdstring;
return overlib(hinttext,0,0);
}
function Validate_AllowanceStartDay(forminput){
var inputname = forminput.name;
var inputvalue = forminput.value*1;
if(inputvalue > 28 || inputvalue < 1){
$j(forminput).addClass('invalid');
return false;
}
else{
$j(forminput).removeClass('invalid');
return true;
}
}
function Validate_DataAllowance(forminput){
var inputname = forminput.name;
var inputvalue = forminput.value*1;
if(inputvalue < 0 || forminput.value.length == 0 || inputvalue == NaN || forminput.value == '.'){
$j(forminput).addClass('invalid');
return false;
}
else{
$j(forminput).removeClass('invalid');
return true;
}
}
function Format_DataAllowance(forminput){
var inputname = forminput.name;
var inputvalue = forminput.value*1;
if(inputvalue < 0 || forminput.value.length == 0 || inputvalue == NaN || forminput.value == '.'){
return false;
}
else{
forminput.value=parseFloat(forminput.value).toFixed(2);
return true;
}
}
function ScaleDataAllowance(){
if(document.form.dnvnstat_allowanceunit.value == 'T'){
document.form.dnvnstat_dataallowance.value = document.form.dnvnstat_dataallowance.value*1 / 1000;
}
else if(document.form.dnvnstat_allowanceunit.value == 'G'){
document.form.dnvnstat_dataallowance.value = document.form.dnvnstat_dataallowance.value*1 * 1000;
}
Format_DataAllowance(document.form.dnvnstat_dataallowance);
}
function GetCookie(cookiename,returntype){
if(cookie.get('cookie_'+cookiename) != null){
return cookie.get('cookie_'+cookiename);
}
else{
if(returntype == 'string'){
return '';
}
else if(returntype == 'number'){
return 0;
}
}
}
function SetCookie(cookiename,cookievalue){
cookie.set('cookie_'+cookiename,cookievalue,10 * 365);
}
function ScriptUpdateLayout(){
var localver = GetVersionNumber('local');
var serverver = GetVersionNumber('server');
$j('#dnvnstat_version_local').text(localver);
if(localver != serverver && serverver != 'N/A'){
$j('#dnvnstat_version_server').text('Updated version available: '+serverver);
showhide('btnChkUpdate',false);
showhide('dnvnstat_version_server',true);
showhide('btnDoUpdate',true);
}
}
function update_status(){
$j.ajax({
url: '/ext/dn-vnstat/detect_update.js',
dataType: 'script',
error: function(xhr){
setTimeout(update_status,1000);
},
success: function(){
if(updatestatus == 'InProgress'){
setTimeout(update_status,1000);
}
else{
document.getElementById('imgChkUpdate').style.display = 'none';
showhide('dnvnstat_version_server',true);
if(updatestatus != 'None'){
$j('#dnvnstat_version_server').text('Updated version available: '+updatestatus);
showhide('btnChkUpdate',false);
showhide('btnDoUpdate',true);
}
else{
$j('#dnvnstat_version_server').text('No update available');
showhide('btnChkUpdate',true);
showhide('btnDoUpdate',false);
}
}
}
});
}
function CheckUpdate(){
showhide('btnChkUpdate',false);
document.formScriptActions.action_script.value = 'start_dn-vnstatcheckupdate';
document.formScriptActions.submit();
document.getElementById('imgChkUpdate').style.display = '';
setTimeout(update_status,2000);
}
function DoUpdate(){
document.form.action_script.value = 'start_dn-vnstatdoupdate';
document.form.action_wait.value = 15;
showLoading();
document.form.submit();
}
function GetVersionNumber(versiontype){
var versionprop;
if(versiontype == 'local'){
versionprop = custom_settings.dnvnstat_version_local;
}
else if(versiontype == 'server'){
versionprop = custom_settings.dnvnstat_version_server;
}
if(typeof versionprop == 'undefined' || versionprop == null){
return 'N/A';
}
else{
return versionprop;
}
}
$j.fn.serializeObject = function(){
var o = custom_settings;
var a = this.serializeArray();
$j.each(a,function(){
if (o[this.name] !== undefined && this.name.indexOf('dnvnstat') != -1 && this.name.indexOf('version') == -1){
if (!o[this.name].push){
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else if (this.name.indexOf('dnvnstat') != -1 && this.name.indexOf('version') == -1){
o[this.name] = this.value || '';
}
});
return o;
};
function SaveConfig(){
document.getElementById('amng_custom').value = JSON.stringify($j('form').serializeObject());
document.form.action_script.value = 'start_dn-vnstatconfig';
document.form.action_wait.value = 15;
showLoading();
document.form.submit();
}
function get_conf_file(){
$j.ajax({
url: '/ext/dn-vnstat/config.htm',
dataType: 'text',
error: function(xhr){
setTimeout(get_conf_file,1000);
},
success: function(data){
var configdata=data.split('\n');
configdata = configdata.filter(Boolean);
for (var i = 0; i < configdata.length; i++){
if(configdata[i].split('=')[0]=="ENFORCEALLOWANCE"){continue;}
eval('document.form.dnvnstat_'+configdata[i].split('=')[0].toLowerCase()).value = configdata[i].split('=')[1].replace(/(\r\n|\n|\r)/gm,'');
}
get_vnstatconf_file();
}
});
}
function get_vnstatconf_file(){
$j.ajax({
url: '/ext/dn-vnstat/vnstatconf.htm',
dataType: 'text',
error: function(xhr){
setTimeout(get_vnstatconf_file,1000);
},
success: function(data){
var configdata=data.split('\n');
configdata = configdata.filter(Boolean);
for (var i = 0; i < configdata.length; i++){
if(configdata[i].startsWith('MonthRotate ')){
eval('document.form.dnvnstat_'+configdata[i].split(' ')[0].toLowerCase()).value = configdata[i].split(' ')[1].replace(/(\r\n|\n|\r)/gm,'');
}
}
}
});
}
function loadVnStatOutput(){
$j.ajax({
url: '/ext/dn-vnstat/vnstatoutput.htm',
dataType: 'text',
error: function(xhr){
setTimeout(loadVnStatOutput,5000);
},
success: function(data){
document.getElementById('VnStatOuput').innerHTML=data;
}
});
}
function get_vnstatusage_file(){
$j.ajax({
url: '/ext/dn-vnstat/vnstatusage.js',
dataType: 'script',
error: function(xhr){
setTimeout(get_vnstatusage_file,1000);
},
success: function(){
UpdateText();
}
});
}
function ShowHideDataUsageWarning(showusage){
if(showusage){
document.getElementById('datausagewarning').style.display = '';
document.getElementById('scripttitle').style.marginLeft = '166px';
}
else{
document.getElementById('datausagewarning').style.display = 'none';
document.getElementById('scripttitle').style.marginLeft = '0px';
}
}
function UpdateText(){
$j('#statstitle').html('The statistics and graphs on this page were last refreshed at: '+daterefeshed);
$j('#spandatausage').html(usagestring);
ShowHideDataUsageWarning(usagethreshold);
}
function UpdateImages(){
var images=['s','hg','d','t','m'];
var datestring = new Date().getTime();
for(var index = 0; index < images.length; index++){
document.getElementById('img_'+images[index]).style.backgroundImage='url(/ext/dn-vnstat/images/.vnstat_'+images[index]+'.htm?cachebuster='+datestring+')';
}
}
function UpdateStats(){
showhide('btnUpdateStats',false);
document.formScriptActions.action_script.value='start_dn-vnstat';
document.formScriptActions.submit();
document.getElementById('vnstatupdate_text').innerHTML = 'Updating bandwidth usage and vnstat data...';
showhide('imgVnStatUpdate',true);
showhide('vnstatupdate_text',true);
setTimeout(update_vnstat,5000);
}
function update_vnstat(){
$j.ajax({
url: '/ext/dn-vnstat/detect_vnstat.js',
dataType: 'script',
error: function(xhr){
setTimeout(update_vnstat,1000);
},
success: function(){
if(vnstatstatus == 'InProgress'){
setTimeout(update_vnstat,1000);
}
else if(vnstatstatus == 'LOCKED'){
document.getElementById('vnstatupdate_text').innerHTML = 'vnstat update already in progress';
showhide('imgVnStatUpdate',false);
showhide('vnstatupdate_text',true);
showhide('btnUpdateStats',true);
}
else if(vnstatstatus == 'Done'){
get_vnstatusage_file();
UpdateImages();
loadVnStatOutput();
currentNoCharts = 0;
RedrawAllCharts();
document.getElementById('vnstatupdate_text').innerHTML = '';
showhide('imgVnStatUpdate',false);
showhide('vnstatupdate_text',false);
showhide('btnUpdateStats',true);
}
}
});
}
function AddEventHandlers(){
$j('.collapsible-jquery').off('click').on('click',function(){
$j(this).siblings().toggle('fast',function(){
if($j(this).css('display') == 'none'){
SetCookie($j(this).siblings()[0].id,'collapsed');
}
else{
SetCookie($j(this).siblings()[0].id,'expanded');
}
})
});
$j('.collapsible-jquery').each(function(index,element){
if(GetCookie($j(this)[0].id,'string') == 'collapsed'){
$j(this).siblings().toggle(false);
}
else{
$j(this).siblings().toggle(true);
}
});
}
function SetCurrentPage(){
document.form.next_page.value = window.location.pathname.substring(1);
document.form.current_page.value = window.location.pathname.substring(1);
}
function initial(){
SetCurrentPage();
LoadCustomSettings();
ScriptUpdateLayout();
show_menu();
get_conf_file();
AddEventHandlers();
get_vnstatusage_file();
UpdateImages();
loadVnStatOutput();
$j('#Time_Format').val(GetCookie('Time_Format','number'));
RedrawAllCharts();
}
function reload(){
location.reload(true);
}
function Draw_Chart_NoData(txtchartname,texttodisplay){
document.getElementById('divChart_'+txtchartname).width='730';
document.getElementById('divChart_'+txtchartname).height='500';
document.getElementById('divChart_'+txtchartname).style.width='730px';
document.getElementById('divChart_'+txtchartname).style.height='500px';
var ctx = document.getElementById('divChart_'+txtchartname).getContext('2d');
ctx.save();
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = 'normal normal bolder 48px Arial';
ctx.fillStyle = 'white';
ctx.fillText(texttodisplay,365,250);
ctx.restore();
}
function Draw_Chart(txtchartname){
var txtunity = $j('#'+txtchartname+'_Unit option:selected').text();
var txttitle = 'Data Usage';
var metric0 = 'Received';
var metric1 = 'Sent';
var decimals = 2;
if(txtunity == 'B' || txtunity == 'KB'){
decimals = 0;
}
var chartperiod = getChartPeriod($j('#'+txtchartname+'_Period option:selected').val());
var chartinterval = getChartInterval($j('#'+txtchartname+'_Interval option:selected').val());
var chartunitmultiplier = getChartUnitMultiplier($j('#'+txtchartname+'_Unit option:selected').val());
var txtunitx = timeunitlist[$j('#'+txtchartname+'_Period option:selected').val()];
var numunitx = intervallist[$j('#'+txtchartname+'_Period option:selected').val()];
var zoompanxaxismax = moment();
var chartxaxismax = null;
var chartxaxismin = moment().startOf('hour').subtract(numunitx,txtunitx+'s').subtract(30,'minutes');
var charttype = 'bar';
var dataobject = window[txtchartname+'_'+chartinterval+'_'+chartperiod];
if(typeof dataobject === 'undefined' || dataobject === null){ Draw_Chart_NoData(txtchartname,'No data to display'); return; }
if(dataobject.length == 0){ Draw_Chart_NoData(txtchartname,'No data to display'); return; }
var unique = [];
var chartTrafficTypes = [];
for(let i = 0; i < dataobject.length; i++){
if(!unique[dataobject[i].Metric]){
chartTrafficTypes.push(dataobject[i].Metric);
unique[dataobject[i].Metric] = 1;
}
}
var chartData0 = dataobject.filter(function(item){
return item.Metric == metric0;
}).map(function(d){return {x: d.Time,y: (d.Value/chartunitmultiplier)}});
var chartData1 = dataobject.filter(function(item){
return item.Metric == metric1;
}).map(function(d){return {x: d.Time,y: (d.Value/chartunitmultiplier)}});
var objchartname=window['Chart_'+txtchartname];
var timeaxisformat = getTimeFormat($j('#Time_Format option:selected').val(),'axis');
var timetooltipformat = getTimeFormat($j('#Time_Format option:selected').val(),'tooltip');
if(chartinterval == 'fiveminute'){
charttype = 'line';
}
if(chartinterval == 'hour'){
chartxaxismax = moment().startOf('hour').add(1,'hours');
zoompanxaxismax = chartxaxismax;
}
if(chartinterval == 'day'){
chartxaxismax = moment().endOf('day').subtract(9,'hours');
chartxaxismin = moment().startOf('day').subtract(numunitx-1,txtunitx+'s').subtract(12,'hours');
zoompanxaxismax = chartxaxismax;
}
if(chartperiod == 'daily' && chartinterval == 'day'){
txtunitx = 'day';
numunitx = 1;
chartxaxismax = moment().endOf('day').subtract(9,'hours');
chartxaxismin = moment().startOf('day').subtract(12,'hours');
zoompanxaxismax = chartxaxismax;
}
if(objchartname != undefined) objchartname.destroy();
var ctx = document.getElementById('divChart_'+txtchartname).getContext('2d');
var chartOptions = {
segmentShowStroke : false,
segmentStrokeColor : '#000',
animationEasing : 'easeOutQuart',
animationSteps : 100,
maintainAspectRatio: false,
animateScale : true,
hover: { mode: 'point' },
legend: {
display: true,
position: 'top',
reverse: false,
onClick: function (e,legendItem){
var index = legendItem.datasetIndex;
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
if(ShowLines == 'line'){
var annotationline = '';
if(meta.hidden != true){
annotationline = 'line';
}
if(ci.data.datasets[index].label == 'Received'){
for(aindex = 0; aindex < 3; aindex++){
ci.options.annotation.annotations[aindex].type=annotationline;
}
}
else if(ci.data.datasets[index].label == 'Sent'){
for(aindex = 3; aindex < 6; aindex++){
ci.options.annotation.annotations[aindex].type=annotationline;
}
}
}
ci.update();
}
},
title: { display: true,text: txttitle },
tooltips: {
callbacks: {
title: function (tooltipItem,data){
if(chartinterval == 'day'){
return moment(tooltipItem[0].xLabel,'X').format('YYYY-MM-DD');
}
else{
return moment(tooltipItem[0].xLabel,'X').format(timetooltipformat);
}
},
label: function (tooltipItem,data){var txtunitytip=txtunity;return round(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y,decimals).toFixed(decimals)+' '+txtunitytip;}
},
itemSort: function(a,b){
return b.datasetIndex - a.datasetIndex;
},
mode: 'point',
position: 'cursor',
intersect: true
},
scales: {
xAxes: [{
type: 'time',
gridLines: { display: true,color: '#282828' },
ticks: {
min: chartxaxismin,
max: chartxaxismax,
display: true
},
time: {
parser: 'X',
unit: txtunitx,
stepSize: 1,
displayFormats: timeaxisformat
}
}],
yAxes: [{
type: getChartScale($j('#'+txtchartname+'_Scale option:selected').val()),
gridLines: { display: false,color: '#282828' },
scaleLabel: { display: false,labelString: txtunity },
id: 'left-y-axis',
position: 'left',
ticks: {
display: true,
beginAtZero: true,
labels: {
index: ['min','max'],
removeEmptyLines: true,
},
userCallback: LogarithmicFormatter
},
}]
},
plugins: {
zoom: {
pan: {
enabled: ChartPan,
mode: 'xy',
rangeMin: {
x: chartxaxismin,
y: 0
},
rangeMax: {
x: zoompanxaxismax//,
//y: getLimit(chartData,'y','max',false)+getLimit(chartData,'y','max',false)*0.1
},
},
zoom: {
enabled: true,
drag: DragZoom,
mode: 'xy',
rangeMin: {
x: chartxaxismin,
y: 0
},
rangeMax: {
x: zoompanxaxismax//,
//y: getLimit(chartData,'y','max',false)+getLimit(chartData,'y','max',false)*0.1
},
speed: 0.1
},
},
},
annotation: {
drawTime: 'afterDatasetsDraw',
annotations: [{
//id: 'avgline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getAverage(chartData0),
borderColor: bordercolourlist[0],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'center',
enabled: true,
xAdjust: 0,
yAdjust: 0,
content: 'Avg. '+metric0+'='+round(getAverage(chartData0),decimals).toFixed(decimals)+txtunity,
}
},
{
//id: 'maxline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getLimit(chartData0,'y','max',true),
borderColor: bordercolourlist[0],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'right',
enabled: true,
xAdjust: 15,
yAdjust: 0,
content: 'Max. '+metric0+'='+round(getLimit(chartData0,'y','max',true),decimals).toFixed(decimals)+txtunity,
}
},
{
//id: 'minline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getLimit(chartData0,'y','min',true),
borderColor: bordercolourlist[0],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'left',
enabled: true,
xAdjust: 15,
yAdjust: 0,
content: 'Min. '+metric0+'='+round(getLimit(chartData0,'y','min',true),decimals).toFixed(decimals)+txtunity,
}
},
{
//id: 'avgline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getAverage(chartData1),
borderColor: bordercolourlist[1],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'center',
enabled: true,
xAdjust: 0,
yAdjust: 0,
content: 'Avg. '+metric1+'='+round(getAverage(chartData1),decimals).toFixed(decimals)+txtunity,
}
},
{
//id: 'maxline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getLimit(chartData1,'y','max',true),
borderColor: bordercolourlist[1],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'right',
enabled: true,
xAdjust: 15,
yAdjust: 0,
content: 'Max. '+metric1+'='+round(getLimit(chartData1,'y','max',true),decimals).toFixed(decimals)+txtunity,
}
},
{
//id: 'minline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getLimit(chartData1,'y','min',true),
borderColor: bordercolourlist[1],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,
cornerRadius: 6,
position: 'left',
enabled: true,
xAdjust: 15,
yAdjust: 0,
content: 'Min. '+metric1+'='+round(getLimit(chartData1,'y','min',true),decimals).toFixed(decimals)+txtunity,
}
}
]}
};
var chartDataset = {
datasets: getDataSets(dataobject,chartTrafficTypes,chartunitmultiplier)
};
objchartname = new Chart(ctx,{
type: charttype,
options: chartOptions,
data: chartDataset
});
window['Chart_'+txtchartname]=objchartname;
}
function Draw_Chart_Summary(txtchartname){
var txtunity = $j('#'+txtchartname+'_Unit option:selected').text();
var txttitle = 'Summary Usage';
var metric0 = 'Received';
var metric1 = 'Sent';
var decimals = 2;
if(txtunity == 'B' || txtunity == 'KB'){
decimals = 0;
}
var chartunitmultiplier = getChartUnitMultiplier($j('#'+txtchartname+'_Unit option:selected').val());
var charttype = 'bar';
var dataobject0 = window[txtchartname+'_WeekSummary'];
if(typeof dataobject0 === 'undefined' || dataobject0 === null){ Draw_Chart_NoData(txtchartname,'No data to display'); return; }
if(dataobject0.length == 0){ Draw_Chart_NoData(txtchartname,'No data to display'); return; }
var unique = [];
var chartTrafficTypes = [];
for(let i = 0; i < dataobject0.length; i++){
if(!unique[dataobject0[i].Metric]){
chartTrafficTypes.push(dataobject0[i].Metric);
unique[dataobject0[i].Metric] = 1;
}
}
var chartData0 = dataobject0.filter(function(item){
return item.Metric == metric0;
}).map(function(d){return d.Value/chartunitmultiplier});
var chartData1 = dataobject0.filter(function(item){
return item.Metric == metric1;
}).map(function(d){return d.Value/chartunitmultiplier});
chartData0.reverse();
chartData1.reverse();
unique = [];
var chartLabels = [];
for(let i = 0; i < dataobject0.length; i++){
if(!unique[dataobject0[i].Time]){
chartLabels.push(dataobject0[i].Time);
unique[dataobject0[i].Time] = 1;
}
}
chartLabels.reverse();
var objchartname=window['Chart_'+txtchartname];
if(objchartname != undefined) objchartname.destroy();
var ctx = document.getElementById('divChart_'+txtchartname).getContext('2d');
var chartOptions = {
segmentShowStroke : false,
segmentStrokeColor : '#000',
animationEasing : 'easeOutQuart',
animationSteps : 100,
maintainAspectRatio: false,
animateScale : true,
hover: { mode: 'point' },
legend: {
display: true,
position: 'top',
reverse: false,
onClick: function (e,legendItem){
var index = legendItem.datasetIndex;
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
if(ShowLines == 'line'){
var annotationline = '';
if(meta.hidden != true){
annotationline = 'line';
}
if(ci.data.datasets[index].label == 'Received'){
for(aindex = 0; aindex < 3; aindex++){
ci.options.annotation.annotations[aindex].type=annotationline;
}
}
else if(ci.data.datasets[index].label == 'Sent'){
for(aindex = 3; aindex < 6; aindex++){
ci.options.annotation.annotations[aindex].type=annotationline;
}
}
}
ci.update();
}
},
title: { display: true,text: txttitle },
tooltips: {
callbacks: {
title: function (tooltipItem,data){
return data.datasets[tooltipItem[0].datasetIndex].label;
},
label: function (tooltipItem,data){var txtunitytip=txtunity;return round(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index].y,decimals).toFixed(decimals)+' '+txtunitytip;}
},
itemSort: function(a,b){
return b.datasetIndex - a.datasetIndex;
},
mode: 'point',
position: 'cursor',
intersect: true
},
scales: {
xAxes: [{
type: 'category',
gridLines: { display: true,color: '#282828' },
ticks: {
display: true
}
}],
yAxes: [{
type: getChartScale($j('#'+txtchartname+'_Scale option:selected').val()),
gridLines: { display: false,color: '#282828' },
scaleLabel: { display: false,labelString: txtunity },
id: 'left-y-axis',
position: 'left',
ticks: {
display: true,
beginAtZero: true,
labels: {
index: ['min','max'],
removeEmptyLines: true,
},
userCallback: LogarithmicFormatter
},
}]
},
plugins: {
zoom: {
pan: {
enabled: ChartPan,
mode: 'xy',
rangeMin: {
y: 0
}
},
zoom: {
enabled: true,
drag: DragZoom,
mode: 'xy',
rangeMin: {
y: 0
},
speed: 0.1
}
},
},
annotation: {
drawTime: 'afterDatasetsDraw',
annotations: [{
//id: 'avgline',
type: ShowLines,
mode: 'horizontal',
scaleID: 'left-y-axis',
value: getAverage(chartData0),
borderColor: bordercolourlist[0],
borderWidth: 1,
borderDash: [5,5],
label: {
backgroundColor: 'rgba(0,0,0,0.3)',
fontFamily: 'sans-serif',
fontSize: 10,
fontStyle: 'bold',
fontColor: '#fff',
xPadding: 6,
yPadding: 6,