-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphs.js
1171 lines (1113 loc) · 46.9 KB
/
Graphs.js
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
//Initialize the saved data objects, and load data/grab from browser if found.
var allSaveData = [];
var graphData = [];
var tmpGraphData = JSON.parse(localStorage.getItem('allSaveData'));
if (tmpGraphData !== null) {
console.log('Got allSaveData. Yay!');
allSaveData = tmpGraphData;
}
//Import the Chart Libraries
var head = document.getElementsByTagName('head')[0];
var chartscript = document.createElement('script');
chartscript.type = 'text/javascript';
chartscript.src = 'https://code.highcharts.com/highcharts.js';
head.appendChild(chartscript);
//Create the graph button and div
var newItem = document.createElement("TD");
newItem.appendChild(document.createTextNode("Graphs"));
newItem.setAttribute("class", "btn btn-default");
newItem.setAttribute("onclick", "autoToggleGraph(); drawGraph();");
var settingbarRow = document.getElementById("settingsTable").firstElementChild.firstElementChild;
settingbarRow.insertBefore(newItem, settingbarRow.childNodes[10]);
document.getElementById("settingsRow").innerHTML += '<div id="graphParent" style="display: none; height: 600px; overflow: auto;"><div id="graph" style="margin-bottom: 10px;margin-top: 5px; height: 530px;"></div>';
document.getElementById("graphParent").innerHTML += '<div id="graphFooter" style="height: 50px;font-size: 1em;"><div id="graphFooterLine1" style="display: -webkit-flex;flex: 0.75;flex-direction: row; height:30px;"></div><div id="graphFooterLine2"></div></div>';
//Create the buttons in the graph Footer:
//Create the dropdown for what graph to show (these correspond to headings in setGraph() and have to match)
var graphList = ['HeliumPerHour', 'Helium', 'HeliumPerHour Instant', 'HeliumPerHour Delta', 'HeHr % / LifetimeHe', 'He % / LifetimeHe', 'Clear Time', 'Cumulative Clear Time', 'Run Time', 'Map Bonus', 'Void Maps', 'Void Map History', 'Loot Sources', 'Coords', 'Gigas', 'UnusedGigas', 'Lastwarp', 'Trimps', 'Nullifium Gained', 'DarkEssence', 'DarkEssencePerHour', 'OverkillCells', 'Magmite'];
var btn = document.createElement("select");
btn.id = 'graphSelection';
//btn.setAttribute("style", "");
btn.setAttribute("onmouseover", 'tooltip(\"Graph\", \"customText\", event, \"What graph would you like to display?\")');
btn.setAttribute("onmouseout", 'tooltip("hide")');
btn.setAttribute("onchange", "setGraphData(document.getElementById('graphSelection').value)");
for (var item in graphList) {
var option = document.createElement("option");
option.value = graphList[item];
option.text = graphList[item];
btn.appendChild(option);
}
document.getElementById('graphFooterLine1').appendChild(btn);
//just write it in HTML instead of a million lines of DOM javascript.
document.getElementById("graphFooterLine1").innerHTML += '\
<div><button onclick="drawGraph()">Refresh</button></div>\
<div style="flex:0 100 5%;"></div>\
<div><input type="checkbox" id="clrChkbox" onclick="toggleClearButton();"></div>\
<div style="margin-left: 0.5vw;"><button id="clrAllDataBtn" onclick="clearData(null,true); drawGraph();" class="btn" disabled="" style="flex:auto; padding: 2px 6px;border: 1px solid white;">Clear All Previous Data</button></div>\
<div style="flex:0 100 5%;"></div>\
<div style="flex:0 2 3.5vw;"><input style="width:100%;min-width: 40px;" id="deleteSpecificTextBox"></div>\
<div style="flex:auto; margin-left: 0.5vw;"><button onclick="deleteSpecific(); drawGraph();">Delete Specific Portal</button></div>\
<div style="flex:0 100 5%;"></div>\
<div style="flex:auto;"><button onclick="GraphsImportExportTooltip(\'ExportGraphs\', null, \'update\')">Export your Graph Database</button></div>\
<div style="float:right; margin-right: 0.5vw;"><button onclick="toggleSpecificGraphs()">Invert Selection</button></div>\
<div style="float:right; margin-right: 1vw;"><button onclick="toggleAllGraphs()">All Off/On</button></div>';
document.getElementById("graphFooterLine2").innerHTML += '\
<span style="float: left;" onmouseover=\'tooltip(\"Tips\", \"customText\", event, \"You can zoom by dragging a box around an area. You can turn portals off by clicking them on the legend. Quickly view the last portal by clicking it off, then Invert Selection. Or by clicking All Off, then clicking the portal on. To delete a portal, Type its portal number in the box and press Delete Specific. Using negative numbers in the Delete Specific box will KEEP that many portals (starting counting backwards from the current one), ie: if you have Portals 1000-1015, typing -10 will keep 1005-1015. Export Graph Database will make a backup of all the graph data (not that useful yet). There is a browser data storage limitation of 10MB, so do not exceed 15 portals-worth of data.\")\'>Tips: Hover for usage tips.</span>\
<input style="height: 20px; float: right; margin-right: 0.5vw;" type="checkbox" id="rememberCB">\
<span style="float: right; margin-right: 0.5vw;">Try to Remember Which Portals are Selected when switching between Graphs:</span>';
//handle the locking mechanism checkbox for the Clear all previous data button:
function toggleClearButton() {
document.getElementById('clrAllDataBtn').disabled=!document.getElementById('clrChkbox').checked;
}
//anonymous self-executing function that runs once on startup to color the graph footer elements Black, unless we are in Dark theme.
(function() {
var items = document.getElementById("graphFooterLine1").children;
for (var i=0,len=items.length; i<len; i++) {
if(game.options.menu.darkTheme.enabled != 2) {
var oldstyle = items[i].getAttribute("style");
if (oldstyle == null) oldstyle="";
items[i].setAttribute("style",oldstyle + "color:black;");
}
}
})();
function GraphsImportExportTooltip(what, isItIn, event) {
if (game.global.lockTooltip)
return;
var elem = document.getElementById("tooltipDiv");
swapClass("tooltipExtra", "tooltipExtraNone", elem);
var ondisplay = null; // if non-null, called after the tooltip is displayed
var tooltipText;
var costText = "";
if (what == "ExportGraphs"){
tooltipText = "This is your GRAPH DATABASE save string. There are many like it but this one is yours. Save this save somewhere safe so you can save time next time. <br/><br/><textarea id='exportArea' style='width: 100%' rows='5'>" + JSON.stringify(allSaveData) + "</textarea>";
costText = "<div class='maxCenter'><div id='confirmTooltipBtn' class='btn btn-info' onclick='cancelTooltip()'>Got it</div>";
if (document.queryCommandSupported('copy')){
costText += "<div id='clipBoardBtn' class='btn btn-success'>Copy to Clipboard</div>";
ondisplay = function(){
document.getElementById('exportArea').select();
document.getElementById('clipBoardBtn').addEventListener('click', function(event) {
document.getElementById('exportArea').select();
try {
document.execCommand('copy');
} catch (err) {
document.getElementById('clipBoardBtn').innerHTML = "Error, not copied";
}
});
};
}
else {
ondisplay = function(){
document.getElementById('exportArea').select();
};
}
costText += "</div>";
}
if (what == "ImportGraphs"){
//runs the loadGraphs() function.
tooltipText = "Replaces your GRAPH DATABASE with this save string! It'll be fine, I promise.<br/><br/><textarea id='importBox' style='width: 100%' rows='5'></textarea>";
costText="<div class='maxCenter'><div id='confirmTooltipBtn' class='btn btn-info' onclick='cancelTooltip(); loadGraphs();'>Import</div><div class='btn btn-info' onclick='cancelTooltip()'>Cancel</div></div>";
ondisplay = function () {
document.getElementById('importBox').focus();
};
}
if (what == "AppendGraphs"){
//runs the appendGraphs() function.
tooltipText = "Appends to your GRAPH DATABASE with this save string (combines them)! It'll be fine, I hope.<br/><br/><textarea id='importBox' style='width: 100%' rows='5'></textarea>";
costText="<div class='maxCenter'><div id='confirmTooltipBtn' class='btn btn-info' onclick='cancelTooltip(); appendGraphs();'>Import</div><div class='btn btn-info' onclick='cancelTooltip()'>Cancel</div></div>";
ondisplay = function () {
document.getElementById('importBox').focus();
};
}
game.global.lockTooltip = true;
elem.style.left = "33.75%";
elem.style.top = "25%";
document.getElementById("tipTitle").innerHTML = what;
document.getElementById("tipText").innerHTML = tooltipText;
document.getElementById("tipCost").innerHTML = costText;
elem.style.display = "block";
if (ondisplay !== null)
ondisplay();
}
//function to take the text string, and use it to load and overwrite your saved data (for graphs)
function loadGraphs() {
var thestring = document.getElementById("importBox").value.replace(/(\r\n|\n|\r|\s)/gm,"");
var tmpset = JSON.parse(thestring);
if (tmpset == null)
return;
//should have done more error checking with at least an error message.
allSaveData = tmpset;
//refresh
drawGraph();
}
//function to take the text string, and use it to load and append your saved data (for graphs) to the old database
function appendGraphs() {
//currently overwrites:
/*
var thestring = document.getElementById("importBox").value.replace(/(\r\n|\n|\r|\s)/gm,"");
var tmpset = JSON.parse(thestring);
if (tmpset == null)
return;
//should have done more error checking with at least an error message.
allSaveData = tmpset;
*/
//refresh
drawGraph();
}
// for rememberCB
var rememberSelectedVisible = [];
function saveSelectedGraphs() {
rememberSelectedVisible = [];
for (var i=0; i < chart1.series.length; i++){
var run = chart1.series[i];
rememberSelectedVisible[i] = run.visible;
}
}
function applyRememberedSelections() {
for (var i=0; i < chart1.series.length; i++){
var run = chart1.series[i];
if (rememberSelectedVisible[i] == false)
run.hide();
}
}
//Invert graph selections
function toggleSpecificGraphs() {
for (var i=0; i < chart1.series.length; i++){
var run = chart1.series[i];
if (run.visible)
run.hide();
else
run.show();
}
}
//Turn all graphs on/off (to the opposite of which one we are closer to)
function toggleAllGraphs() {
var count = 0;
for (var i=0; i < chart1.series.length; i++){
var run = chart1.series[i];
if (run.visible)
count++;
}
for (var i=0; i < chart1.series.length; i++){
var run = chart1.series[i];
if (count > chart1.series.length/2)
run.hide();
else
run.show();
}
}
function clearData(portal,clrall) {
//clear data of runs with portalnumbers prior than X (15) away from current portal number. (or 0 = clear all)
if(!portal)
portal = 0;
if (!clrall) {
while(allSaveData[0].totalPortals < game.global.totalPortals - portal) {
allSaveData.shift();
}
} else {
while(allSaveData[0].totalPortals != game.global.totalPortals) {
allSaveData.shift();
}
}
}
//delete a specific portal number's graphs. use negative numbers to keep that many portals.
function deleteSpecific() {
var txtboxvalue = document.getElementById('deleteSpecificTextBox').value;
if (txtboxvalue == "")
return;
if (parseInt(txtboxvalue) < 0) {
clearData(Math.abs(txtboxvalue));
} else {
for (var i = allSaveData.length-1; i >= 0; i--) {
if (allSaveData[i].totalPortals == txtboxvalue)
allSaveData.splice(i, 1);
}
}
}
function autoToggleGraph() {
if (game.options.displayed) toggleSettingsMenu();
var aset = document.getElementById('autoSettings');
if (aset) {
if (aset.style.display === 'block') aset.style.display = 'none';
}
var item = document.getElementById('graphParent');
if (item.style.display === 'block') item.style.display = 'none';
else {
item.style.display = 'block';
setGraph();
}
}
//unused: hides graph and shows Trimps (not AT) settings menu
function autoPlusGraphMenu() {
var item = document.getElementById('graphParent');
if (item.style.display === 'block') item.style.display = 'none';
toggleSettingsMenu();
}
function escapeATWindows() {
//Turn off "Settings"/"AutoTrimpsSettings"/"Graphs" Menu on escape.
if (game.options.displayed) toggleSettingsMenu();
var aset = document.getElementById('autoSettings');
if (aset.style.display === 'block') aset.style.display = 'none';
var graph = document.getElementById('graphParent');
if (graph.style.display === 'block') graph.style.display = 'none';
}
document.addEventListener("keydown",function (event) {
//Hotkeys have to be enabled, and all these conditions have to be met or else we cant use the hotkey.
if (game.options.menu.hotkeys.enabled == 1 && !game.global.preMapsActive && !game.global.lockTooltip && !ctrlPressed && !heirloomsShown && event.keyCode == 27) //27 == escape
escapeATWindows();
//Turn off "Settings"/"AutoTrimpsSettings"/"Graphs" Menu on escape.
}, true);
var chart1;
function setGraph(title, xTitle, yTitle, valueSuffix, formatter, series, yType) {
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'graph',
zoomType: 'xy',
//move reset button out of the way.
resetZoomButton: {
position: {
align: 'right',
verticalAlign: 'top',
x: -20,
y: 15
},
relativeTo: 'chart'
}
},
title: {
text: title,
x: -20 //center
},
plotOptions: {
series: {
lineWidth: 1,
animation: false,
marker: {
enabled: false
}
}
},
xAxis: {
floor: 1,
title: {
text: xTitle
},
},
yAxis: {
title: {
text: yTitle
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
type: yType,
dateTimeLabelFormats: { //force all formats to be hour:minute:second
second: '%H:%M:%S',
minute: '%H:%M:%S',
hour: '%H:%M:%S',
day: '%H:%M:%S',
week: '%H:%M:%S',
month: '%H:%M:%S',
year: '%H:%M:%S'
}
},
tooltip: {
pointFormatter: formatter,
valueSuffix: valueSuffix
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: series
});
}
function setColor(tmp) {
for (var i in tmp) {
if (i == tmp.length - 1) {
tmp[i].color = '#FF0000'; //Current run is in red
} else {
tmp[i].color = '#90C3D4'; //Old runs are in blue
}
}
return tmp;
}
function getTotalDarkEssenceCount() {
var purchased = 10 * (Math.pow(3, countPurchasedTalents()) - 1) / (3 - 1);
return game.global.essence + purchased;
}
function pushData() {
debug('Starting Zone ' + game.global.world,"general");
//helium/hour % of totalHE, and currentRun/totalLifetime HE
var getPercent = (game.stats.heliumHour.value() / (game.global.totalHeliumEarned - (game.global.heliumLeftover + game.resources.helium.owned)))*100;
var lifetime = (game.resources.helium.owned / (game.global.totalHeliumEarned-game.resources.helium.owned))*100;
allSaveData.push({
totalPortals: game.global.totalPortals,
heliumOwned: game.resources.helium.owned,
currentTime: new Date().getTime(),
portalTime: game.global.portalTime,
world: game.global.world,
challenge: game.global.challengeActive,
voids: game.global.totalVoidMaps,
heirlooms: {"value": game.stats.totalHeirlooms.value, "valueTotal":game.stats.totalHeirlooms.valueTotal},
nullifium: recycleAllExtraHeirlooms(true),
gigas: game.upgrades.Gigastation.done,
gigasleft: game.upgrades.Gigastation.allowed - game.upgrades.Gigastation.done,
trimps: game.resources.trimps.realMax(),
coord: game.upgrades.Coordination.done,
lastwarp: game.global.lastWarp,
essence: getTotalDarkEssenceCount(),
hehr: getPercent.toFixed(4),
helife: lifetime.toFixed(4),
overkill: GraphsVars.OVKcellsInWorld,
zonetime: GraphsVars.ZoneStartTime,
mapbonus: GraphsVars.MapBonus,
magmite: game.global.magmite
});
//only keep 15 portals worth of runs to prevent filling storage
clearData(15);
try {
localStorage.setItem('allSaveData', JSON.stringify(allSaveData));
} catch(e) {
if (e.code == 22) {
// Storage full, maybe notify user or do some clean-up
debug("Error: LocalStorage is full, or error. Attempt to delete some portals from your graph or restart browser.");
}
}
}
function initializeData() {
//initialize fresh with a blank array if needed
if (allSaveData === null) {
allSaveData = [];
}
//fill the array with the first data point
if (allSaveData.length === 0) {
pushData();
}
}
var GraphsVars = {};
function InitGraphsVars() {
GraphsVars.currentPortal = 0;
GraphsVars.OVKcellsInWorld = 0;
GraphsVars.lastOVKcellsInWorld = 0;
GraphsVars.currentworld = 0;
GraphsVars.lastrunworld = 0;
GraphsVars.aWholeNewWorld = false;
GraphsVars.lastZoneStartTime = 0;
GraphsVars.ZoneStartTime = 0;
GraphsVars.MapBonus = 0;
GraphsVars.aWholeNewPortal = 0;
GraphsVars.currentPortal = 0;
}
InitGraphsVars();
//main function of the graphs script - runs every second.
function gatherInfo() {
//dont push updates if the game is paused. fix import on pause Clear Time problem
if (game.options.menu.pauseGame.enabled) return;
//make sure data structures are ready
initializeData();
//Track portal.
GraphsVars.aWholeNewPortal = GraphsVars.currentPortal != game.global.totalPortals;
if (GraphsVars.aWholeNewPortal) {
GraphsVars.currentPortal = game.global.totalPortals;
//clear filtered loot data upon portaling. < 5 check to hopefully throw out bone portal shenanigans
filteredLoot = {
'produced': {metal: 0, wood: 0, food: 0, gems: 0},
'looted': {metal: 0, wood: 0, food: 0, gems: 0}
}
}
//Track zone.
GraphsVars.aWholeNewWorld = GraphsVars.currentworld != game.global.world;
if (GraphsVars.aWholeNewWorld) {
GraphsVars.currentworld = game.global.world;
//if we have reached a new zone, push a new data point (main)
if (allSaveData.length > 0 && allSaveData[allSaveData.length - 1].world != game.global.world) {
pushData();
}
//reset stuff,prepare tracking variables.
GraphsVars.OVKcellsInWorld = 0;
GraphsVars.ZoneStartTime = 0;
GraphsVars.MapBonus = 0;
}
//track how many overkill world cells we have beaten in the current level. (game.stats.cellsOverkilled.value for the entire run)
if (game.options.menu.overkillColor.enabled == 0) toggleSetting('overkillColor'); //make sure the setting is on.
GraphsVars.OVKcellsInWorld = document.getElementById("grid").getElementsByClassName("cellColorOverkill").length;
//track time in each zone for better graphs
GraphsVars.ZoneStartTime = new Date().getTime() - game.global.zoneStarted;
//track mapbonus
GraphsVars.MapBonus = game.global.mapBonus;
}
var dataBase = {}
var databaseIndexEntry = {
Index: 0,
Portal: 0,
Challenge: 0,
World: 0
}
var databaseDirtyEntry = {
State: false,
Reason: "",
Index: -1
}
var portalExistsArray = [];
var portalRunArray = [];
var portalRunIndex = 0;
function chkdsk() {
rebuildDataIndex();
checkIndexConsistency();
checkWorldSequentiality();
if (databaseDirtyEntry.State == true) {
//
}
}
function rebuildDataIndex() {
for (var i = 0; i < allSaveData.length-1; i++) {
//database
dataBase[i] ={
Index: i,
Portal: allSaveData[i].totalPortals,
Challenge: allSaveData[i].challenge,
World: allSaveData[i].world
}
//reverse lookup quickArray
portalRunArray.push({Index: i, Portal: allSaveData[i].totalPortals , Challenge: allSaveData[i].challenge});
if (typeof portalExistsArray[allSaveData[i].totalPortals] == "undefined")
portalExistsArray[allSaveData[i].totalPortals] = {Exists: true, Row: portalRunIndex, Index: i, Challenge: allSaveData[i].challenge};
else {
databaseDirtyFlag.State = true;
databaseDirtyFlag.Reason = 'oreoportal';
databaseDirtyFlag.Index = i;
row = portalExistsArray[allSaveData[i].totalPortals].Row;
}
portalRunIndex++;
}
}
function checkIndexConsistency() {
for (var i = 0; i < dataBase.length-1; i++) {
if (dataBase[i].Index != i) {
databaseDirtyFlag = [true,'index',i];
break;
}
}
}
function checkWorldSequentiality() {
var lastworld,currentworld,nextworld;
for (var i = 1; i < dataBase.length-1; i++) {
lastworldEntry = dataBase[i-1];
currentworldEntry = dataBase[i];
nextworldEntry = dataBase[i+1];
lastworld = lastworldEntry.World;
currentworld = currentworldEntry.World;
nextworld = nextworldEntry.World
if (lastworld > currentworld && currentworld != 1) {
databaseDirtyFlag.State = true;
databaseDirtyFlag.Reason = 'descending';
databaseDirtyFlag.Index = i;
break;
}
if (lastworld > currentworld && currentworld == 1 && lastworld == nextworld) {
databaseDirtyFlag.State = true;
databaseDirtyFlag.Reason = 'badportal';
databaseDirtyFlag.Index = i;
break;
}
}
}
function drawGraph() {
setGraphData(document.getElementById('graphSelection').value);
}
//////////////////////////////////////
//MAIN GRAPHING FUNCTION - the meat.//
//////////////////////////////////////
function setGraphData(graph) {
var title, xTitle, yTitle, yType, valueSuffix, series, formatter;
var precision = 0;
var oldData = JSON.stringify(graphData);
valueSuffix = '';
switch (graph) {
case 'HeliumPerHour Instant':
var currentPortal = -1;
var currentZone = -1;
graphData = [];
var nowhehr=0;var lasthehr=0;
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
graphData.push({
name: 'Portal ' + allSaveData[i].totalPortals + ': ' + allSaveData[i].challenge,
data: []
});
currentPortal = allSaveData[i].totalPortals;
if(allSaveData[i].world == 1 && currentZone != -1 )
graphData[graphData.length -1].data.push(0);
if(currentZone == -1 || allSaveData[i].world != 1) {
var loop = allSaveData[i].world;
while (loop > 0) {
graphData[graphData.length -1].data.push(0);
loop--;
}
}
nowhehr = 0; lasthehr = 0;
}
if(currentZone < allSaveData[i].world && currentZone != -1) {
nowhehr = Math.floor((allSaveData[i].heliumOwned - allSaveData[i-1].heliumOwned) / ((allSaveData[i].currentTime - allSaveData[i-1].currentTime) / 3600000));
graphData[graphData.length - 1].data.push(nowhehr);
}
currentZone = allSaveData[i].world;
}
title = 'Helium/Hour Instantaneous - between current and last zone.';
xTitle = 'Zone';
yTitle = 'Helium/Hour per each zone';
yType = 'Linear';
break;
case 'HeliumPerHour Delta':
var currentPortal = -1;
var currentZone = -1;
graphData = [];
var nowhehr=0;var lasthehr=0;
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
graphData.push({
name: 'Portal ' + allSaveData[i].totalPortals + ': ' + allSaveData[i].challenge,
data: []
});
currentPortal = allSaveData[i].totalPortals;
if(allSaveData[i].world == 1 && currentZone != -1 )
graphData[graphData.length -1].data.push(0);
if(currentZone == -1 || allSaveData[i].world != 1) {
var loop = allSaveData[i].world;
while (loop > 0) {
graphData[graphData.length -1].data.push(0);
loop--;
}
}
nowhehr = 0; lasthehr = 0;
}
if(currentZone < allSaveData[i].world && currentZone != -1) {
nowhehr = Math.floor(allSaveData[i].heliumOwned / ((allSaveData[i].currentTime - allSaveData[i].portalTime) / 3600000));
if (lasthehr == 0)
lasthehr = nowhehr;
graphData[graphData.length - 1].data.push(nowhehr-lasthehr);
}
currentZone = allSaveData[i].world;
lasthehr = nowhehr;
}
title = 'Helium/Hour Delta(Difference) - between current and last zone.';
xTitle = 'Zone';
yTitle = 'Difference in Helium/Hour';
yType = 'Linear';
break;
case 'Run Time':
var currentPortal = -1;
var theChallenge = '';
graphData = [];
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
if(currentPortal == -1) {
theChallenge = allSaveData[i].challenge;
currentPortal = allSaveData[i].totalPortals;
graphData.push({
name: 'Run Time',
data: [],
type: 'column'
});
continue;
}
var theOne = allSaveData[i-1];
var runTime = theOne.currentTime - theOne.portalTime;
graphData[0].data.push([theOne.totalPortals, runTime]);
theChallenge = allSaveData[i].challenge;
currentPortal = allSaveData[i].totalPortals;
}
}
title = 'Total Run Time';
xTitle = 'Portal';
yTitle = 'Time';
yType = 'datetime';
formatter = function () {
var ser = this.series;
return '<span style="color:' + ser.color + '" >●</span> ' +
ser.name + ': <b>' +
Highcharts.dateFormat('%H:%M:%S', this.y) + '</b><br>';
};
break;
case 'Void Maps':
var currentPortal = -1;
var totalVoids = 0;
var theChallenge = '';
graphData = [];
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
if(currentPortal == -1) {
theChallenge = allSaveData[i].challenge;
currentPortal = allSaveData[i].totalPortals;
graphData.push({
name: 'Void Maps',
data: [],
type: 'column'
});
continue;
}
graphData[0].data.push([allSaveData[i-1].totalPortals, totalVoids]);
theChallenge = allSaveData[i].challenge;
totalVoids = 0;
currentPortal = allSaveData[i].totalPortals;
}
if(allSaveData[i].voids > totalVoids) {
totalVoids = allSaveData[i].voids;
}
}
title = 'Void Maps Per Portal';
xTitle = 'Portal';
yTitle = 'Void Maps';
yType = 'Linear';
break;
case 'Nullifium Gained':
var currentPortal = -1;
var totalNull = 0;
var theChallenge = '';
graphData = [];
var averagenulli = 0;
var sumnulli = 0;
var count = 0;
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
if(currentPortal == -1) {
theChallenge = allSaveData[i].challenge;
currentPortal = allSaveData[i].totalPortals;
graphData.push({
name: 'Nullifium Gained',
data: [],
type: 'column'
});
continue;
}
graphData[0].data.push([allSaveData[i-1].totalPortals, totalNull]);
count++;
sumnulli += totalNull;
//console.log("nulli was: " + totalNull + " " + count + " @ " + allSaveData[i].totalPortals); //debug
theChallenge = allSaveData[i].challenge;
totalNull = 0;
currentPortal = allSaveData[i].totalPortals;
}
if(allSaveData[i].nullifium > totalNull) {
totalNull = allSaveData[i].nullifium;
}
}
averagenulli = sumnulli / count;
//console.log("Average nulli was: " + averagenulli);
title = 'Nullifium Gained Per Portal';
if (averagenulli)
title = "Average " + title + " = " + averagenulli;
xTitle = 'Portal';
yTitle = 'Nullifium Gained';
yType = 'Linear';
break;
case 'Loot Sources':
graphData = [];
graphData[0] = {name: 'Metal', data: lootData.metal};
graphData[1] = {name: 'Wood', data: lootData.wood};
graphData[2] = {name: 'Food', data: lootData.food};
graphData[3] = {name: 'Gems', data: lootData.gems};
title = 'Current Loot Sources (of all resources gained) - for the last 15 minutes';
xTitle = 'Time (every 15 seconds)';
yTitle = 'Ratio of looted to gathered';
valueSuffix = '%';
formatter = function () {
return Highcharts.numberFormat(this.y,3);
};
break;
//all use the same function: allPurposeGraph()
case 'Clear Time #2':
graphData = allPurposeGraph('cleartime2',true,null,
function specialCalc(e1,e2) {
return Math.round(e1.zonetime/1000);
});
title = '(#2) Time to Clear Zone';
xTitle = 'Zone';
yTitle = 'Clear Time';
yType = 'Linear';
valueSuffix = ' Seconds';
break;
case 'Clear Time':
graphData = allPurposeGraph('cleartime1',true,null,
function specialCalc(e1,e2) {
return Math.round(((e1.currentTime - e2.currentTime)-(e1.portalTime - e2.portalTime)) / 1000);
});
title = 'Time to clear zone';
xTitle = 'Zone';
yTitle = 'Clear Time';
yType = 'Linear';
valueSuffix = ' Seconds';
break;
case 'Cumulative Clear Time #2':
graphData = allPurposeGraph('cumucleartime2',true,null,
function specialCalc(e1,e2) {
return Math.round(e1.zonetime);
},true);
title = '(#2) Cumulative Time at END of zone#';
xTitle = 'Zone';
yTitle = 'Cumulative Clear Time';
yType = 'datetime';
formatter = function () {
var ser = this.series;
return '<span style="color:' + ser.color + '" >●</span> ' +
ser.name + ': <b>' +
Highcharts.dateFormat('%H:%M:%S', this.y) + '</b><br>';
};
break;
case 'Cumulative Clear Time':
graphData = allPurposeGraph('cumucleartime1',true,null,
function specialCalc(e1,e2) {
return Math.round((e1.currentTime - e2.currentTime)-(e1.portalTime - e2.portalTime));
},true);
title = 'Cumulative Time at END of zone#';
xTitle = 'Zone';
yTitle = 'Cumulative Clear Time';
yType = 'datetime';
formatter = function () {
var ser = this.series;
return '<span style="color:' + ser.color + '" >●</span> ' +
ser.name + ': <b>' +
Highcharts.dateFormat('%H:%M:%S', this.y) + '</b><br>';
};
break;
case 'HeliumPerHour':
graphData = allPurposeGraph('heliumhr',true,null,
function specialCalc(e1,e2) {
return Math.floor(e1.heliumOwned / ((e1.currentTime - e1.portalTime) / 3600000));
});
title = 'Helium/Hour (Cumulative)';
xTitle = 'Zone';
yTitle = 'Helium/Hour';
yType = 'Linear';
break;
case 'Helium':
graphData = allPurposeGraph('heliumOwned',true,null,
function specialCalc(e1,e2) {
return Math.floor(e1.heliumOwned);
});
title = 'Helium (earned)';
xTitle = 'Zone';
yTitle = 'Helium';
yType = 'Linear';
break;
case 'HeHr % / LifetimeHe':
graphData = allPurposeGraph('hehr',true,"string");
title = 'He/Hr % of LifetimeHe';
xTitle = 'Zone';
yTitle = 'He/Hr % of LifetimeHe';
yType = 'Linear';
precision = 4;
break;
case 'He % / LifetimeHe':
graphData = allPurposeGraph('helife',true,"string");
title = 'He % of LifetimeHe';
xTitle = 'Zone';
yTitle = 'He % of LifetimeHe';
yType = 'Linear';
precision = 4;
break;
case 'Void Map History':
graphData = allPurposeGraph('voids',true,"number");
title = 'Void Map History (voids finished during the same level acquired (with RunNewVoids) are not counted/tracked)';
xTitle = 'Zone';
yTitle = 'Number of Void Maps';
yType = 'Linear';
break;
case 'Map Bonus':
graphData = allPurposeGraph('mapbonus',true,"number");
title = 'Map Bonus History';
xTitle = 'Zone';
yTitle = 'Map Bonus Stacks';
yType = 'Linear';
break;
case 'Coords':
graphData = allPurposeGraph('coord',true,"number");
title = 'Coordination History';
xTitle = 'Zone';
yTitle = 'Coordination';
yType = 'Linear';
break;
case 'Gigas':
graphData = allPurposeGraph('gigas',true,"number");
title = 'Gigastation History';
xTitle = 'Zone';
yTitle = 'Number of Gigas';
yType = 'Linear';
break;
case 'UnusedGigas':
graphData = allPurposeGraph('gigasleft',true,"number");
title = 'Unused Gigastations';
xTitle = 'Zone';
yTitle = 'Number of Gigas';
yType = 'Linear';
break;
case 'Lastwarp':
graphData = allPurposeGraph('lastwarp',true,"number");
title = 'Warpstation History';
xTitle = 'Zone';
yTitle = 'Previous Giga\'s Number of Warpstations';
yType = 'Linear';
break;
case 'Trimps':
graphData = allPurposeGraph('trimps',true,"number");
title = 'Total Trimps Owned';
xTitle = 'Zone';
yTitle = 'Cumulative Number of Trimps';
yType = 'Linear';
break;
case 'Magmite':
graphData = allPurposeGraph('magmite',true,"number");
title = 'Total Magmite Owned';
xTitle = 'Zone';
yTitle = 'Magmite';
yType = 'Linear';
break;
case 'DarkEssence':
graphData = allPurposeGraph('essence',true,"number");
title = 'Total Dark Essence Owned';
xTitle = 'Zone';
yTitle = 'Dark Essence';
yType = 'Linear';
break;
case 'DarkEssencePerHour':
var currentPortal = -1;
var currentZone = -1;
var startEssence = 0;
graphData = [];
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
graphData.push({
name: 'Portal ' + allSaveData[i].totalPortals + ': ' + allSaveData[i].challenge,
data: []
});
currentPortal = allSaveData[i].totalPortals;
currentZone = 0;
startEssence = allSaveData[i].essence;
}
//runs extra checks for mid-run imports, and pushes 0's to align to the right zone properly.
if (currentZone != allSaveData[i].world - 1) {
var loop = allSaveData[i].world - 1 - currentZone;
while (loop > 0) {
graphData[graphData.length - 1].data.push(0);
loop--;
}
}
//write datapoint (one of 3 ways)
if (currentZone != 0) {
graphData[graphData.length - 1].data.push(Math.floor((allSaveData[i].essence - startEssence) / ((allSaveData[i].currentTime - allSaveData[i].portalTime) / 3600000)));
}
currentZone = allSaveData[i].world;
}
title = 'Dark Essence/Hour (Cumulative)';
xTitle = 'Zone';
yTitle = 'Dark Essence/Hour';
yType = 'Linear';
break;
case 'OverkillCells':
var currentPortal = -1;
graphData = [];
for (var i in allSaveData) {
if (allSaveData[i].totalPortals != currentPortal) {
graphData.push({
name: 'Portal ' + allSaveData[i].totalPortals + ': ' + allSaveData[i].challenge,
data: []
});
currentPortal = allSaveData[i].totalPortals;
if(allSaveData[i].world == 1 && currentZone != -1 )
graphData[graphData.length -1].data.push(0);
if(currentZone == -1 || allSaveData[i].world != 1) {
var loop = allSaveData[i].world;
while (loop > 0) {
graphData[graphData.length -1].data.push(0);
loop--;
}
}
}
if(currentZone < allSaveData[i].world && currentZone != -1) {
var num;
if (typeof allSaveData[i].overkill == "object")
num = allSaveData[i].overkill[1];
else if (typeof allSaveData[i].overkill == "number")
num = allSaveData[i].overkill;
if (num)
graphData[graphData.length - 1].data.push(num);
}
currentZone = allSaveData[i].world;
}
title = 'Overkilled Cells';
xTitle = 'Zone';
yTitle = 'Overkilled Cells';
yType = 'Linear';
break;
}
//default function used to draw non-specific graphs (and some specific ones)
function allPurposeGraph(item,extraChecks,typeCheck,funcToRun,useAccumulator) {
var currentPortal = -1;
var currentZone = 0;
var accumulator = 0;
graphData = [];