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
|
var itemsToShow = new Array(); //list of indexes to all dives to view
var items = new Array();
var start; //index of first element viewed in itemsToShow
var sizeofpage; //size of viewed page
var numberofwords = 0; //just for stats
var olditemstoshow; //to reference the indexes to all dives if changed
//////////////////////////////////
// //
// View Model //
// //
//////////////////////////////////
/**
*This Method view all items
*View N pages each of sizeofpage size items.
*starting from zero
*/
function showAllDives()
{
for (var i = 0; i < items.length; i++) {
itemsToShow.push(i);
}
olditemstoshow = itemsToShow;
start = 0;
viewInPage();
}
/**
*This function view the 'itemstoshow' in pages.
*It start from 'start' variable.
*It showes N pages each of sizeofpage size.
*/
function viewInPage()
{
var end = start + sizeofpage - 1;
if (end >= itemsToShow.length)
end = itemsToShow.length - 1;
updateView(start, end);
}
/**
*addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML
*/
function updateView(start, end)
{
var divelist = document.getElementById('diveslist');
divelist.innerHTML = "";
for (var i = start; i <= end; i++) {
divelist.innerHTML += '<ul id="' + itemsToShow[i] + '" onclick="toggleExpantion(this)"</ul>';
expand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = true;
};
view_pagging(start, end);
}
/**
*addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML
*/
function addHTML(indexes)
{
var divelist = document.getElementById('diveslist');
divelist.innerHTML = "";
for (var i = 0; i < indexes.length; i++) {
divelist.innerHTML += '<ul id="' + indexes[i] + '" onclick="toggleExpantion(this)"</ul>';
expand(document.getElementById(indexes[i]));
itemsToShow[indexes[i]].expanded = true;
};
}
/**
*This Method shows items in a range [start,end]
*@param {integer} start start from this index
*@param {integer} finish at this index.
*/
function view_in_range(start, end)
{
var ind = new Array();
if (end >= itemsToShow.length)
end = itemsToShow.length - 1;
for (var i = start; i <= end; i++) {
ind.push(i);
}
addHTML(ind);
view_pagging(start, end);
}
/**
*Show the previous page, Will do nothing if no previous pages
*/
function prev_page()
{
var end = start + sizeofpage - 1;
if (start - sizeofpage > 0) {
start -= sizeofpage;
} else {
start = 0;
}
if (end - sizeofpage > 0) {
end -= sizeofpage;
}
if (end >= itemsToShow.length) {
end = itemsToShow.length - 1;
}
updateView(start, end)
}
/**
*Show the next page, Will do nothing if no next pages
*/
function next_page()
{
var end = start + sizeofpage - 1;
if (end + sizeofpage < itemsToShow.length) {
end += sizeofpage;
} else {
end = itemsToShow.length - 1;
}
if (start + sizeofpage < itemsToShow.length) {
start += sizeofpage;
}
updateView(start, end)
}
function view_pagging(start, end)
{
var page = document.getElementById("pagging");
page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + ' dives';
}
/**
*Expand all dives in the view.
*/
function expandAll()
{
for (var i = start; i < start + sizeofpage; i++) {
if (i >= itemsToShow.length)
break;
unexpand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = false;
}
}
/**
*Collapse all dives in the view.
*/
function collapseAll()
{
for (var i = start; i < start + sizeofpage; i++) {
if (i >= itemsToShow.length)
break;
expand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = true;
}
}
function setNumberOfDives(e)
{
var value = e.options[e.selectedIndex].value;
sizeofpage = parseInt(value, 10);
var end = start + sizeofpage - 1;
view_in_range(start, end);
}
function toggleExpantion(ul)
{
if (!items[ul.id].expanded) {
expand(ul);
items[ul.id].expanded = true;
} else {
unexpand(ul);
items[ul.id].expanded = false;
}
}
function expand(ul)
{
ul.innerHTML = getlimited(items[ul.id]);
ul.style.padding = '2px 10px 2px 10px';
}
function unexpand(ul)
{
ul.innerHTML = getExpanded(items[ul.id]);
ul.style.padding = '3px 10px 3px 10px';
}
///////////////////////////////////////
//
// Dive Model
//
//////////////////////////////////////
function getlimited(dive)
{
return '<div style="height:20px"><div class="item">' + (settings.subsurfaceNumbers === '0' ? dive.number + 1 : dive.subsurface_number) + '</div>' +
'<div class="item">' + dive.date + '</div>' +
'<div class="item">' + dive.time + '</div>' +
'<div class="item_large">' + dive.location + '</div>' +
'<div class="item">' + dive.temperature.air + '</div>' +
'<div class="item">' + dive.temperature.water + '</div></div>';
};
function getExpanded(dive)
{
var res = '<table><tr><td class="words">Date: </td><td>' + dive.date +
'</td><td class="words">     Time: </td><td>' + dive.time +
'</td><td class="words">     Location: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' +
dive.location + '</a>' +
'</td></tr></table><table><tr><td class="words">Rating:</td><td>' + putRating(dive.rating) +
'</td><td class="words">   Visibilty:</td><td>' + putRating(dive.visibility) +
'</td></tr></table>' +
'<table><tr><td class="words">Air temp: </td><td>' + dive.temperature.air +
'</td><td class="words">    Water temp: </td><td>' + dive.temperature.water +
'</td></tr></table><table><tr><td class="words">DiveMaster: </td><td>' + dive.divemaster +
'</td></tr><tr><td class="words"><p>Buddy: </p></td><td>' + dive.buddy +
'</td></tr><tr><td class="words">Suit: </td><td>' + dive.suit +
'</td></tr><tr><td class="words">Tags: </td><td>' + putTags(dive.tags) +
'</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>';
if (settings.listOnly === '0') {
res += '<center><a onclick="showDiveDetails(' + dive.number + ')">show more details</a></center>';
}
return res;
};
function putTags(tags)
{
var result = "";
for (var i in tags) {
result += '<a onclick=\"Search_list_Modules(\'' + tags[i] + '\')\">' + tags[i] + '</a>';
if (i < tags.length - 1)
result += ', ';
}
return result;
}
/**
*@param {integer} rate out of 5
*return HTML string of stars
*/
function putRating(rating)
{
var result;
result = '<div>';
for (var i = 0; i < rating; i++)
result += ' ★ ';
for (var i = rating; i < 5; i++)
result += ' ☆ ';
result += '</div>';
return result;
}
///////////////////////////////////////
//
// Sorting
//
/////////////////////////////////////
/*
this variables keep the state of
each col. sorted asc or des
*/
var number = false;
var time = true;
var date = true;
var air = true;
var water = true;
var locat = true;
function list_sort(sortOn)
{
switch (sortOn) {
case '1': //number
if (number) {
sort_it(sortOn, cmpNumAsc);
number = 1 - number;
} else {
sort_it(sortOn, cmpNumDes);
number = 1 - number;
}
break;
case '2': //date
if (date) {
sort_it(sortOn, cmpDateAsc);
date = 1 - date;
} else {
sort_it(sortOn, cmpDateDes);
date = 1 - date;
}
break;
case '3': //time
if (time) {
sort_it(sortOn, cmpTimeDes);
time = 1 - time;
} else {
sort_it(sortOn, cmpTimeAsc);
time = 1 - time;
}
break;
case '4': //Air temp
if (air) {
sort_it(sortOn, cmpAtempDes);
air = 1 - air;
} else {
sort_it(sortOn, cmpAtempAsc);
air = 1 - air;
}
break;
case '5': //Water temp
if (water) {
sort_it(sortOn, cmpWtempDes);
water = 1 - water;
} else {
sort_it(sortOn, cmpWtempAsc);
water = 1 - water;
}
break;
case '6': //Water temp
if (locat) {
sort_it(sortOn, cmpLocationDes);
locat = 1 - locat;
} else {
sort_it(sortOn, cmpLocationAsc);
locat = 1 - locat;
}
break;
}
}
/*
*sorting interface for different coloumns
*/
function cmpLocationAsc(j, iSmaller)
{
return items[j].location < items[iSmaller].location;
}
function cmpLocationDes(j, iSmaller)
{
return items[j].location > items[iSmaller].location;
}
function cmpNumAsc(j, iSmaller)
{
return items[j].subsurface_number < items[iSmaller].subsurface_number;
}
function cmpNumDes(j, iSmaller)
{
return items[j].subsurface_number > items[iSmaller].subsurface_number;
}
function cmpTimeAsc(j, iSmaller)
{
return items[j].time < items[iSmaller].time;
}
function cmpTimeDes(j, iSmaller)
{
return items[j].time > items[iSmaller].time;
}
function cmpDateAsc(j, iSmaller)
{
return items[j].date < items[iSmaller].date;
}
function cmpDateDes(j, iSmaller)
{
return items[j].date > items[iSmaller].date;
}
function cmpAtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10);
}
function cmpAtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10);
}
function cmpWtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10);
}
function cmpWtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10);
}
function sort_it(sortOn, function_)
{
var res = new Array();
var visited = new Array(itemsToShow.length);
for (var j = 0; j < itemsToShow.length; j++) {
visited[j] = false;
}
for (var i = 0; i < itemsToShow.length; i++) {
for (var j = 0; j < itemsToShow.length; j++)
if (visited[j] === false)
var iSmaller = j;
for (var j = 0; j < itemsToShow.length; j++) {
if (function_(itemsToShow[j], itemsToShow[iSmaller])) {
if (visited[j] === false) {
iSmaller = j;
}
}
}
visited[iSmaller] = true;
res.push(itemsToShow[iSmaller]);
}
itemsToShow = res;
start = 0;
viewInPage();
}
///////////////////////////////////////
//
// Searching
//
//////////////////////////////////////
function Set()
{
this.keys = new Array();
}
Set.prototype.contains = function(key)
{
return (this.keys.indexOf(key) >= 0) ? true : false;
}
Set.prototype.push = function(key)
{
if (!this.contains(key)) {
this.keys.push(key);
}
};
Set.prototype.isEmpty = function()
{
return this.keys.length <= 0 ? true : false;
};
Set.prototype.forEach = function(do_) {
this.keys.forEach (do_);
};
Set.prototype.Union = function(another_set)
{
if (another_set === null) {
return;
}
for (var i = 0; i < another_set.keys.length; i++) {
this.push(another_set.keys[i]);
};
};
function Node(value)
{
this.children = new Array();
this.value = value;
this.key = new Set();
}
function Search_list_Modules(searchfor)
{
document.getElementById("search_input").value = searchfor;
SearchModules(searchfor);
}
function SearchModules(searchfor)
{
var resultKeys = new Set(); //set
if (searchfor.length <= 0) {
//exit searching mode
document.getElementById("search_input").style.borderColor = "initial";
start = 0;
itemsToShow = olditemstoshow;
viewInPage();
return;
}
searchingModules.forEach (function(x) {
resultKeys.Union(x.search(searchfor));
});
if (searchingModules["location"].enabled === true)
resultKeys.Union(searchingModules["location"].search(searchfor));
if (searchingModules["divemaster"].enabled === true)
resultKeys.Union(searchingModules["divemaster"].search(searchfor));
if (searchingModules["buddy"].enabled === true)
resultKeys.Union(searchingModules["buddy"].search(searchfor));
if (searchingModules["notes"].enabled === true)
resultKeys.Union(searchingModules["notes"].search(searchfor));
if (searchingModules["tags"].enabled === true)
resultKeys.Union(searchingModules["tags"].search(searchfor));
if (resultKeys.isEmpty()) {
//didn't find keys
document.getElementById("search_input").style.borderColor = "red";
itemsToShow = [];
viewInPage();
return;
}
//found keys
document.getElementById("search_input").style.borderColor = "initial";
itemsToShow = resultKeys.keys;
start = 0;
viewInPage();
}
///////////////////////////////////////
function SearchModule(enabled)
{
this.head = new Node();
this.enabled = enabled;
}
SearchModule.prototype.Enter_search_string = function(str, diveno)
{
if (str == "" || !str)
return;
var res = str.toLowerCase().split(" ");
for (var i = 0; i < res.length; i++) {
insertIn(res[i], diveno, this.head);
numberofwords++;
}
}
SearchModule.prototype.Enter_search_tag = function(tags, diveno)
{
if (!tags)
return;
for (var i = 0; i < tags.length; i++) {
insertIn(tags[i], diveno, this.head);
numberofwords++;
}
}
SearchModule.prototype.search = function(x)
{
return searchin(x.toLowerCase(), this.head);
}
////////////////////////////////////////
function insertIn(value, key, node)
{
node.key.push(key);
if (value.length <= 0)
return;
var this_char = value[0];
value = value.substring(1, value.length);
var i;
for (i = 0; i < node.children.length; i++) {
if (node.children[i].value == this_char) {
return insertIn(value, key, node.children[i]);
}
}
node.children[i] = new Node(this_char);
insertIn(value, key, node.children[i]);
}
function searchin(value, node)
{
if (value.length <= 0 || node.children.length <= 0)
return node.key;
var this_char = value[0];
value = value.substring(1, value.length);
for (var i = 0; i < node.children.length; i++) {
if (node.children[i].value[0] == this_char) {
return searchin(value, node.children[i]);
}
}
return null;
}
//trips
var tripsShown;
/**
*This is the main function called to show/hide trips
*/
function toggleTrips()
{
var trip_button = document.getElementById('trip_button');
if (tripsShown) {
tripsShown = false;
trip_button.style.backgroundColor = "#dfdfdf";
viewInPage();
} else {
showtrips();
trip_button.style.backgroundColor = "#5f7f8f";
tripsShown = true;
}
}
function showtrips()
{
var divelist = document.getElementById('diveslist');
divelist.innerHTML = "";
for (var i = 0; i < trips.length; i++) {
divelist.innerHTML += '<ul id="trip_' + i + '" class="trips" onclick="toggle_trip_expansion(' + i + ')">' +
trips[i].name + ' ( ' + trips[i].dives.length + ' dives)' + '</ul>' + '<div id="trip_dive_list_' + i + '"></div>';
};
for (var i = 0; i < trips.length; i++) {
unexpand_trip(i);
}
}
function toggle_trip_expansion(trip)
{
if (trips[trip].expanded === true) {
unexpand_trip(trip);
} else {
expand_trip(trip);
}
}
function expand_trip(trip)
{
trips[trip].expanded = true;
var d = document.getElementById("trip_dive_list_" + trip);
for (var j in trips[trip].dives) {
d.innerHTML += '<ul id="' + trips[trip].dives[j].number + '" onclick="toggleExpantion(this)" onmouseover="highlight(this)"' +
' onmouseout="unhighlight(this)">' + getlimited(trips[trip].dives[j]) + '</ul>';
}
}
function unexpand_trip(trip)
{
trips[trip].expanded = false;
var d = document.getElementById("trip_dive_list_" + trip);
d.innerHTML = '';
}
function getItems()
{
var count = 0;
for (var i in trips) {
for (var j in trips[i].dives) {
items[count++] = trips[i].dives[j];
}
}
}
////////////////////////canvas///////////////////
/*
Some Global variables that hold the current shown dive data.
*/
var dive_id; //current shown ID
var points; //reference to the samples array of the shown dive.
var ZERO_C_IN_MKELVIN = 273150;
var plot1;
/**
*Return the HTML string for a dive cylinder entry in the table.
*/
function get_cylinder_HTML(cylinder)
{
return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' +
'<td class="Cyl">' + cylinder.SPressure + '</td><td class="Cyl">' + cylinder.EPressure + '</td><td class="Cyl">' + cylinder.O2 + '</td></tr>';
}
/**
*Return HTML table of cylinders of a dive.
*/
function get_cylinders_HTML(dive)
{
var result = "";
result += '<h2 class="det_hed">Dive equipments</h2><table><tr><td class="words">Type</td><td class="words">Size</td><td class="words">Work Pressure</td><td class="words">Start Pressure</td><td class="words">End Pressure</td><td class="words">O2</td></tr>';
for (var i in dive.Cylinders) {
result += get_cylinder_HTML(dive.Cylinders[i]);
}
result += '</table>';
return result;
}
/**
Return the HTML string for a bookmark entry in the table.
*/
function get_bookmark_HTML(event)
{
return '<tr><td class="Cyl">' + event.name + '</td><td class="Cyl">' + int_to_time(event.time) + '</td></tr>';
}
/**
*Return HTML table of bookmarks of a dive.
*/
function get_bookmarks_HTML(dive)
{
var result = "";
result += '<h2 class="det_hed">Events</h2><table><tr><td class="words">Name</td><td class="words">Time</td></tr>';
for (var i in dive.events) {
result += get_bookmark_HTML(dive.events[i]);
}
result += '</table>';
return result;
}
/**
*Return HTML main data of a dive
*/
function get_dive_HTML(dive)
{
return '<h2 class="det_hed">Dive Information</h2><table><tr><td class="words">Date: </td><td>' + dive.date +
'</td><td class="words">     Time: </td><td>' + dive.time +
'</td><td class="words">     Location: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' +
dive.location + '</a>' +
'</td></tr></table><table><tr><td class="words">Rating:</td><td>' + putRating(dive.rating) +
'</td><td class="words">   Visibilty:</td><td>' + putRating(dive.visibility) +
'</td></tr></table>' +
'<table><tr><td class="words">Air temp: </td><td>' + dive.temperature.air +
'</td><td class="words">    Water temp: </td><td>' + dive.temperature.water +
'</td></tr></table><table><tr><td class="words">DiveMaster: </td><td>' + dive.divemaster +
'</td></tr><tr><td class="words"><p>Buddy: </p></td><td>' + dive.buddy +
'</td></tr><tr><td class="words">Suit: </td><td>' + dive.suit +
'</td></tr><tr><td class="words">Tags: </td><td>' + putTags(dive.tags) +
'</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes + '</div>';
};
function mkelvin_to_C(mkelvin)
{
return (mkelvin - ZERO_C_IN_MKELVIN) / 1000.0;
}
function mbar_to_bar(mbar)
{
return mbar / 1000;
}
function mm_to_meter(mm)
{
return mm / (1000);
}
function format_two_digit(n)
{
return n > 9 ? "" + n : "0" + n;
}
function int_to_time(n)
{
return Math.floor((n) / 60) + ":" + format_two_digit((n) % (60)) + " min";
}
/**
*Main canvas draw function
*this calls the axis and grid initialization functions.
*/
function canvas_draw()
{
document.getElementById("chart1").innerHTML = "";
var d1 = new Array(); //depth
var d2 = new Array(); //pressure
var d3 = new Array(); //events
var d4 = new Array(); //temperature
var last = 0;
for (var i = 0; i < items[dive_id].samples.length; i++) {
d1.push([
items[dive_id].samples[i][0] / 60,
-1 * mm_to_meter(items[dive_id].samples[i][1])
]);
if (items[dive_id].samples[i][2] != 0) {
d2.push([
items[dive_id].samples[i][0] / 60,
mbar_to_bar(items[dive_id].samples[i][2])
]);
}
if (items[dive_id].samples[i][3] != 0) {
d4.push([
items[dive_id].samples[i][0] / 60,
mkelvin_to_C(items[dive_id].samples[i][3]),
]);
last = items[dive_id].samples[i][3];
} else {
if (last != 0) {
d4.push([
items[dive_id].samples[i][0] / 60,
mkelvin_to_C(last),
]);
}
}
}
for (var i = 0; i < items[dive_id].events.length; i++) {
//var x = get_sample(items[dive_id].events[i].time);
d3.push([
items[dive_id].events[i].time / 60,
0,
]);
}
plot1 = $.jqplot('chart1', [
d1,
d2,
d3,
d4,
],
{
grid : {
drawBorder : true,
shadow : false,
background : 'rgba(0,0,0,0)'
},
highlighter : {
show : true,
tooltipContentEditor: function(str, seriesIndex, pointIndex, jqPlot) {
if(seriesIndex===2)
return items[dive_id].events[pointIndex].name;
else
return str;
}
},
seriesDefaults : {
shadowAlpha : 0.1,
shadowDepth : 2,
fillToZero : true
},
series :[
{
color : 'rgba(35,58,58,.6)',
negativeColor : 'rgba(35,58,58,.6)',
showMarker : true,
showLine : true,
fill : true,
yaxis : 'yaxis',
},
{
color : 'rgba(44, 190, 160, 0.7)',
showMarker : false,
rendererOptions : {
smooth : true,
},
yaxis : 'y2axis',
},
{
showLine:false,
markerOptions: { size: 10, style:"o" },
pointLabels: { show:false, } ,
},
{
showLine:true,
showMarker : false,
pointLabels: { show:false, } ,
yaxis : 'y3axis',
},
],
axes : {
xaxis : {
pad : 1.0,
tickRenderer : $.jqplot.CanvasAxisTickRenderer,
tickOptions : {
showGridline : false,
formatString : '%i min',
angle : -30
}
},
yaxis : {
max : 0,
tickRenderer : $.jqplot.CanvasAxisTickRenderer,
tickOptions : {
formatString : '%.2f'
},
pad : 2.05
},
y2axis : {
tickRenderer : $.jqplot.CanvasAxisTickRenderer,
tickOptions : {
formatString : '%ibar'
},
pad : 3.05
},
y3axis : {
padMax : 3.05,
tickOptions: {
showGridline: false,
showMark: false,
showLabel: false,
shadow: false,
},
},
}
});
}
/**
*Initialize the detailed view,
*set the global variables
*Fill the dive data
*Hide the list and show the canvas view.
*this is called to view the dive details.
*/
function showDiveDetails(dive)
{
//set global variables
dive_id = dive;
points = items[dive_id].samples;
//draw the canvas and initialize the view
document.getElementById("diveinfo").innerHTML = get_dive_HTML(items[dive_id]);
document.getElementById("dive_equipments").innerHTML = get_cylinders_HTML(items[dive_id]);
document.getElementById("bookmarks").innerHTML = get_bookmarks_HTML(items[dive_id]);
setDiveTitle(items[dive_id]);
//hide the list of dives and show the canvas.
document.getElementById("diveListPanel").style.display = 'none';
document.getElementById("divePanel").style.display = 'block';
canvas_draw();
}
function setDiveTitle(dive)
{
document.getElementById("dive_no").innerHTML = "Dive No. " + (settings.subsurfaceNumbers === '0' ?
dive.number + 1 : dive.subsurface_number);
document.getElementById("dive_location").innerHTML = dive.location;
}
/**
*Show the list view and hide the detailed list view.
*this function have to clear any data saved by showDiveDetails
*/
function unshowDiveDetails(dive)
{
start = dive_id;
viewInPage();
plot1 = null;
document.getElementById("diveListPanel").style.display = 'block';
document.getElementById("divePanel").style.display = 'none';
}
function nextDetailedDive()
{
if (dive_id < items.length) {
showDiveDetails(++dive_id);
}
}
function prevDetailedDive()
{
if (dive_id > 0) {
showDiveDetails(--dive_id);
}
}
/**
*This function handles keyboard events
*shift to next/prev dives by keyboard arrows.
*/
function switchDives(e)
{
if (document.getElementById("divePanel").style.display == 'block') {
e = e || window.event;
if (e.keyCode == '37') {
prevDetailedDive();
} else if (e.keyCode == '39') {
nextDetailedDive();
}
}
}
|