Commit 2ca6c431 authored by Andrew Cohen's avatar Andrew Cohen

getFeatureExtrema -- for rendering feature data tree

parent f0d2ccc4
......@@ -1141,7 +1141,7 @@ class LeverDB {
var trackOptions=[];
this._lDB.all(sqlCmd,function(err,rows){
if (err)
console.log('getTrackOptions: '+err);
console.error('getTrackOptions: '+err);
else {
trackOptions=rows;
}
......@@ -1149,6 +1149,30 @@ class LeverDB {
});
} // getTrackOptions
getFeatureExtrema(cx,fnCallback)
{
var sqlCmd='select ';
for (var i=0;i<cx.cellFeatures.length;i++) {
if (i>0)
sqlCmd+=',';
sqlCmd+='min('+cx.cellFeatures[i].name+') as min_'+i+',';
sqlCmd+='max('+cx.cellFeatures[i].name+') as max_'+i;
}
sqlCmd+=' FROM tblCellFeatures';
this._lDB.all(sqlCmd,function(err,rows) {
if (err)
console.error('getFeatureExtrema: '+err);
else {
var rgMinMax=[];
for (var i=0;i<cx.cellFeatures.length;i++) {
rgMinMax.push([rows[0]['min_'+i], rows[0]['max_'+i]]);
}
}
fnCallback(rgMinMax);
})
} // getFeatureExtrema
}
// read all the leverfiles in a folder, send one massive response
// unused, since it takes
......
......@@ -10,7 +10,6 @@ var gbLineageTimeDrag=false;
var gLineagePopupTimer=-1;
var gLineageMouseOverEvent;
var gLineagePopupTID=-1;
var gFeatureExtreme; // min,max of each feature
function resetLineagePopup()
{
......@@ -718,11 +717,6 @@ function getCellFeatures(lDB,rowsTracks,fnCallback)
return;
}
var cxFeatures=cxGetCellFeatures(cx);
gFeatureExtreme=[]; // [max,min]
for (var f=0;f<cxFeatures.length;f++) {
gFeatureExtreme.push([Infinity, -Infinity]);
}
for (var i=0;i<rowsTracks.length;i++) {
rowsTracks[i].features=[];
for (var j=0;j<rowFeatures.length;j++) {
......@@ -734,10 +728,6 @@ function getCellFeatures(lDB,rowsTracks,fnCallback)
for (var f=0;f<cxFeatures.length;f++)
cellFeature.push(rowFeatures[j][cxFeatures[f].name]);
rowsTracks[i].features.push(cellFeature);
for (var n=2;n<cellFeature.length;n++) {
gFeatureExtreme[n-2][0]=Math.min(cellFeature[n],gFeatureExtreme[n-2][0]);
gFeatureExtreme[n-2][1]=Math.max(cellFeature[n],gFeatureExtreme[n-2][1]);
}
}
}
......@@ -1024,7 +1014,7 @@ function toggleRenderFeature(nFeature)
for (var i=0;i<CONSTANTS.cellFeatures.length;i++) {
if (i==nFeature)
continue;
CONSTANTS.cellFeatures[nFeature].bRender=false;
CONSTANTS.cellFeatures[i].bRender=false;
document.getElementById('featureRender_'+i).checked=false;
}
}
......@@ -1076,24 +1066,6 @@ function changeFeatureColor(i)
writeViewConstantsToDB(); // see view.js
} // changeFeatureColor
var gFeatureMinMax;
function setFeatureMinMaX(cxFeatures,i)
{
if (undefined===gDB)
return; // don't have one handy -- need the global db for this
var sqlCmd='select min('+cxFeatures[i].name+') as fmin, max('+cxFeatures[i].name+') as fmax from tblCellFeatures';
lDB.all(sqlCmd,function(err,featureMinMax) {
if (err) {
console.error(err.message);
return;
}
else {
gFeatureMinMax[i,0]=featureMinMax.fmin;
gFeatureMinMax[i,0]=featureMinMax.fmax;
}
});
} // setFeatureMinMaX
function lineageShowFeatures(cx)
{
......@@ -1114,7 +1086,6 @@ function lineageShowFeatures(cx)
if (undefined==cxFeatures[i].bShow)
cxFeatures[i].bShow=true;
gFeatureMinMax.push([0,2]); // default value
setFeatureMinMaX(cxFeatures,i);
var newFeature=document.createElement('div');
newFeature.id='cellFeatures_'+i;
var color=standardize_color(cxFeatures[i].color);
......
......@@ -654,6 +654,33 @@ function drawText(tHulls)
}
} // drawText
var gFeatureExtrema;
function getFeatureExtrema()
{
if (gDB===undefined && g_db_path===undefined)
return;
if (!IS_NODE) {
var editReq = new XMLHttpRequest();
editReq.addEventListener("load",function(){
gFeatureExtrema=JSON.parse(this.responseText);
reDraw(false);
});
editReq.open("GET",gServerURL + g_db_path + "/featureExtrema/");
editReq.send();
return;
} // !IS_NODE
else {
const LeverDB=require('./lever.js');
var leverDB=new LeverDB();
leverDB.lDB=gDB;
leverDB.getFeatureExtrema(CONSTANTS,function(rgMinMax){
gFeatureExtrema=rgMinMax;
reDraw(false);
});
}
} // getFeatureExtrema
// Draws the hulls on the image
function drawHulls(tHulls)
{
......@@ -690,6 +717,10 @@ function drawHulls(tHulls)
}
}
}
if (nFeature>=0 && gFeatureExtrema==undefined) {
nFeature=-1; // can't draw this way until the scale arrives
getFeatureExtrema();
}
for (var i = 0; i < tHulls.length; i++) {
......@@ -734,7 +765,13 @@ function drawHulls(tHulls)
// color by feature?
if (nFeature>=0) {
var fval=tHulls[i][CONSTANTS.cellFeatures[0].name]/2;
var fmax=gFeatureExtrema[nFeature][1];
var fmin=gFeatureExtrema[nFeature][0];
// scale so colors go from [0.2,1]
// puts it on [0,1]
var fval=(tHulls[i][CONSTANTS.cellFeatures[0].name] - fmin)/((fmax-fmin));
// now put it on [0.1,1]
fval=0.9*fval+0.1;
color = getHTMLcolor([fval,fval,fval]);
}
context.strokeStyle=color;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment