forked from hammerlab/pileup.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.js
78 lines (68 loc) · 1.88 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
// 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
}
var colorByStrand = getParameterByName('colorByStrand');
if (colorByStrand) {
sources.forEach(source => {
if (source.viz.options) {
source.viz.options.colorByStrand = true;
}
});
}
var p = pileup.create(document.getElementById('pileup'), {
range: range,
tracks: sources
});
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);