Skip to content

Commit

Permalink
fixed error with default function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bhofmei committed Jun 23, 2017
1 parent e4013b3 commit 3e1f761
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions js/View/ColorHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define('NucleotideDensityPlugin/View/ColorHandler',[
define('NucleotideDensityPlugin/View/ColorHandler', [
'dojo/_base/declare',
'dojo/_base/array',
'dojo/_base/lang',
Expand All @@ -12,25 +12,13 @@ function(

){
/*
Utility class dealing with degenerate nucleotide sequences
Utility class dealing the various ways to specify colors
*/
var ColorHandler;

ColorHandler = {

generateRandomColors: function( labels ){
// take in list of labels and return object with equidistant colors
var rColors = this.generateNColors(labels.length);
var colors ={};
var i;
for(i=0; i<labels.length; i++){
colors[labels[i]] = rColors[i];
}
return colors;
},

generateNColors: function(n){
var thisB = this;
var s=100, l=65, sep=360/n;
var hs=[];
var i;
Expand All @@ -44,6 +32,17 @@ ColorHandler = {
return out;
},

generateRandomColors: function( labels ){
// take in list of labels and return object with equidistant colors
var rColors = ColorHandler.generateNColors(labels.length);
var colors ={};
var i;
for(i=0; i<labels.length; i++){
colors[labels[i]] = rColors[i];
}
return colors;
},

getFontColor: function(color){
// from http:https://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color
//var bg = new dojoColor(color);
Expand All @@ -57,22 +56,37 @@ ColorHandler = {
return '#010101';
},

contextToColorFromList: function(seqCtx, contextList, colorList, repeatable){
var k = 0;
for(k=0; k<contextList.length; k++)
if(contextList[k]===seqCtx)
break;
return ColorHandler.intToColorFromList(k, colorList, repeatable);
},

intToColorFromList: function(n, colorList, repeatable){
if(n >= colorList.length && !repeatable)
return undefined;
n %= colorList.length;
return colorList[n];
},

getConfigColor: function( seqCtx, contextConfig, colorConfig, randomColors ){
// random
if(colorConfig === 'random')
return randomColors[seqCtx]
return randomColors[seqCtx];
// other string
else if(typeof colorConfig === 'string')
return colorConfig
return colorConfig;
// array
else if(Array.isArray(colorConfig)){
return this.contextToColorFromList(seqCtx, contextConfig, colorConfig, true);
return ColorHandler.contextToColorFromList(seqCtx, contextConfig, colorConfig, true);
}
// object
else if(colorConfig.hasOwnProperty(seqCtx))
return colorConfig[seqCtx]
return colorConfig[seqCtx];
else
return randomColors[seqCtx]
return randomColors[seqCtx];
},

getColorType: function( colorConfig ){
Expand All @@ -83,22 +97,7 @@ ColorHandler = {
return 'single';
else
return 'individual';
},

contextToColorFromList: function(seqCtx, contextList, colorList, repeatable=true){
var k = 0;
for(k=0; k<contextList.length; k++)
if(contextList[k]===seqCtx)
break;
return this.intToColorFromList(k, colorList, repeatable);
},

intToColorFromList: function(n, colorList, repeatable){
if(n >= colorList.length && !repeatable)
return undefined;
n %= colorList.length;
return colorList[n];
}
}
}
return ColorHandler;
});

0 comments on commit 3e1f761

Please sign in to comment.