Skip to content

Commit

Permalink
snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
IbrahimTanyalcin committed Apr 16, 2019
1 parent 82d90b8 commit 8a1618f
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lexiconMonoSeq.v0.17.1.js → lexiconMonoSeq.v0.17.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
##############PROTO############
###############################
*/
_LexiconMonoSeq.prototype.version = "0.17.1";
_LexiconMonoSeq.prototype.version = "0.17.2";
_LexiconMonoSeq.prototype._scrollLeftOffset = 0;
_LexiconMonoSeq.prototype._50spaces = " ";
_LexiconMonoSeq.prototype.set = function(k,v){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"eslint-plugin-standard": "^3.0.1",
"uglify-js": "^3.0.28"
},
"main": "lexiconMonoSeq.v0.17.1.js"
"main": "lexiconMonoSeq.v0.17.2.js"
}
171 changes: 171 additions & 0 deletions snippets/snippet-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@

!function(){
var LexiconMonoSeq = require("lexicon-mono-seq");
var container = document.createElement("div");
container.id = "test";
rootDiv.appendChild(container);
var body = document.body,
styleText = [
'@font-face {font-family: "Consolas";',
'src: url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.eot");',
'src: url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.eot?#iefix") format("embedded-opentype"),',
'url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.woff2") format("woff2"),',
'url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.woff") format("woff"),',
'url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.ttf") format("truetype"),',
'url("//db.onlinewebfonts.com/t/1db29588408eadbd4406aae9238555eb.svg#Consolas") format("svg");',
'}',
'#test {',
'width:75vw;',
'height:25vh;',
'position:absolute;',
'margin:auto;',
'top:0;',
'right:0;',
'bottom:0;',
'left:0;',
'}',
'body {',
'position:relative;',
'margin:0px;',
'width:100vw;',
'height:100vh;',
'}',
'#loading {',
'display:flex;',
'align-items:center;',
'justify-content:center;',
'width:20vw;',
'height:20vh;',
'position:absolute;',
'top:0;',
'right:0;',
'bottom:0;',
'left:0;',
'margin:auto;',
'font-size:16px;',
'font-family:Consolas;',
'text-align:center;',
'border-radius:10px;',
'background:rgba(0,0,0,0.8);',
'color:White;',
'z-index:2;',
'}',
'button {',
'width:40vw;',
'height:10vh;',
'position:absolute;',
'top:5vh;',
'right:0;',
'left:0;',
'margin:auto;',
'font-size:20px;',
'font-family:Consolas;',
'text-align:center;',
'border:0px;',
'padding:0px;',
'border-radius:10px;',
'background:DodgerBlue;',
'color:white;',
'outline:none;',
'transition:background 1s ease;',
'}',
'button.inactive {',
'background:DarkSlateGray !important;',
'}',
'button:hover {',
'background:Teal;',
'}'
],
style = document.createElement("style"),
instance = LexiconMonoSeq(container,{parallelRendering:5}),
watchman = instance.constructor.prototype.watchman,
testNode = document.createElement("div"),
testNodeInitRect,
testNodeStyle = testNode.style;
testNodeStyle.visibility = "hidden";
testNodeStyle.position = "absolute";
testNodeStyle.fontSize = "16px";
testNodeStyle.fontFamily = "inexistentFont";
testNodeStyle.margin = "0px";
testNodeStyle.padding = "0px";
testNode.textContent = "A";
var fontNode = testNode.cloneNode(true),
fontNodeInitRect;
fontNode.style.fontFamily = "Consolas";
body.appendChild(testNode);
body.appendChild(fontNode);
style.textContent = styleText.join("");
document.head.appendChild(style);
var loading = document.createElement("div");
loading.id = "loading";
loading.textContent = "Sit tight! loading..";
body.appendChild(loading);
var button = body.appendChild(document.createElement("button"));
button.textContent = "Load 0-1Mb";

watchman(
{counter:0},
function(){
this.counter++;
return this.counter === 5;
},
function(){
fontNodeInitRect = fontNode.getBoundingClientRect();
testNodeInitRect = testNode.getBoundingClientRect();
watchman(
null,
function(){
var rect = fontNode.getBoundingClientRect();
//console.log("running!");
console.log(rect,testNodeInitRect);
return (rect.width !== testNodeInitRect.width) || (rect.height !== testNodeInitRect.height);
},
function(){
var button = document.getElementsByTagName("button")[0],
loading = document.getElementById("loading"),
fileNames = ["chrX.0M.1M.txt","chrX.1M.2M.txt"],
state = "inactive";
instance.displayPadding = 0.1; //default is 0.2
//Allow sequences to be created, then fire up
var typeAA = instance.caveManCopy(instance.colors.aa),//deep copies the object
typeDNA = instance.caveManCopy(instance.colors.dna);
typeDNA.N = "#333333";
typeDNA.W = "#333333";
typeDNA.S = "#333333";
typeDNA.Y = "#333333";
typeDNA.R = "#333333";
typeAA["?"] = "#333333";
typeAA["X"] = "#333333";
instance.registerType("aa",typeAA);
instance.registerType("dna",typeDNA);
function loadData(fileName){
if (fileName === "chrX.0M.1M.txt") {
button.textContent = "Load 1-2Mb";
} else {
button.textContent = "Load 0-1Mb";
}
fileNames.push(fileNames.shift());
loading.style.visibility = "visible";
button.className = "inactive";
state = "inactive";
var req = new XMLHttpRequest();
req.responseType = "json";
req.open("GET","//distreau.com/lexicon-mono-seq/datasets/" + fileName,true);
req.onload = function(e){
button.className = "";
state = "active";
loading.style.visibility = "hidden";
instance.update(LexiconMonoSeq.createRuler(this.response,true));
};
req.send();
};
button.onclick = function(){
if(state === "inactive"){return}
loadData(fileNames[0]);
};
instance.skipFrames(90).then(function(){loadData(fileNames[0]);});
}
);
}
);
}();

0 comments on commit 8a1618f

Please sign in to comment.