forked from hammerlab/pileup.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayground.js
90 lines (80 loc) · 2.57 KB
/
playground.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
// Try to read a range out of the URL. This is helpful for testing.
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var pos = getParameterByName('pos');
if (pos) {
var m = /(.*):([0-9,]+)-([0-9,]+)/.exec(pos);
if (!m) { throw 'Invalid range: ' + pos; }
var makeNum = function(x) { return Number(x.replace(/,/g, '')); };
range = {contig: m[1], start: makeNum(m[2]), stop: makeNum(m[3])};
} else {
// use default range from, e.g. data.js
}
// this adds the feature that if you add a url parameter colorByStrand
// and set it to some value (looks like pretty much any value
// counts as true at this point), this causes the gene "strands"
// displayed to be colored red and blue; I'm not sure what it signifies;
// update this if you figure it out
var colorByStrand = getParameterByName('colorByStrand');
if (colorByStrand) {
sources.forEach(source => {
if (source.viz.options) {
source.viz.options.colorByStrand = true;
}
});
}
// here a pileup element is created and added to the document in the
// #pileup div; see /src/main/pileup.js for more information
var p = pileup.create(document.getElementById('pileup'), { //'pileup' object is elOrId
range: range,
tracks: sources
});
// it looks like the rest of this file is this "jiggling" stuff
// which basically just does some simple test for the FPS
// with which the website is rendering; it does this by
// "jiggling" the genome displayed.
// not relevant beyond testing
function jiggle() {
var r = p.getRange();
if (r.start % 10 == 0) {
r.start -= 9;
r.stop -= 9;
} else {
r.start += 1;
r.stop += 1;
}
p.setRange(r);
}
var isJiggling = false;
document.getElementById('jiggle').onclick = function() {
if (isJiggling) {
isJiggling = false;
this.innerHTML = 'FPS test';
return;
}
var repeatedlyJiggle = function() {
jiggle();
if (isJiggling) {
window.requestAnimationFrame(repeatedlyJiggle);
}
};
isJiggling = true;
this.innerHTML = 'Stop!';
repeatedlyJiggle();
};
// Measure the frame rate. Chrome devtools can do this, but having the devtools
// open has a dramatic effect on frame rates.
var stats = new Stats();
stats.setMode(0); // 0: fps, 1: ms
document.body.appendChild(stats.domElement);
var update = function() {
stats.end();
stats.begin();
requestAnimationFrame(update);
};
stats.begin();
requestAnimationFrame(update);