Skip to content

Commit

Permalink
Automate style fixes as part of linting
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Jan 8, 2017
1 parent 1832696 commit dbacd6e
Show file tree
Hide file tree
Showing 21 changed files with 1,074 additions and 1,413 deletions.
1,231 changes: 528 additions & 703 deletions dist/js/ideogram.js
100755 → 100644

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/js/ideogram.min.js
100755 → 100644

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/ideogram.min.js.map

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ var flatten = require('gulp-flatten');
var ignore = require('gulp-ignore');
var order = require('gulp-order');
var eslint = require('gulp-eslint');
var gulpIf = require('gulp-if');
var sourcemaps = require('gulp-sourcemaps');

var paths = {
scripts: 'src/js/**/*.js',
styles: 'src/css/**/*.css'
}

function isFixed(file) {
// Has ESLint fixed the file contents?
return file.eslint != null && file.eslint.fixed;
}

gulp.task('default', function () {

gulp
Expand All @@ -29,8 +35,12 @@ gulp.task('default', function () {

gulp.task('lint', function() {
return gulp.src([paths.scripts, '!src/js/lib.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint({
fix: true
}))
.pipe(eslint.format()) // write style issues to stdout
// if fixed, write the file to dest
.pipe(gulpIf(isFixed, gulp.dest('src/js')));
});

gulp.task('dist', function() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"gulp-concat": "^2.6.0",
"gulp-eslint": "^3.0.1",
"gulp-flatten": "^0.3.1",
"gulp-if": "^2.0.2",
"gulp-ignore": "^2.0.1",
"gulp-mocha": "*",
"gulp-mocha-phantomjs": "^0.11",
Expand Down
48 changes: 21 additions & 27 deletions src/js/color.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
function Color(config) {
// Ideogram config
this._config = config;
this._ploidy = new Ploidy(this._config);
this._config = config;
this._ploidy = new Ploidy(this._config);
}


Color.prototype.getArmColor = function(chrSetNumber, chrNmber, armNumber) {

if (this._config.armColors) {
return this._config.armColors[armNumber];
} else if (this._config.ancestors) {
return this._getPolyploidArmColor(chrSetNumber, chrNmber, armNumber);
} else {
return null;
}
if (this._config.armColors) {
return this._config.armColors[armNumber];
} else if (this._config.ancestors) {
return this._getPolyploidArmColor(chrSetNumber, chrNmber, armNumber);
} else {
return null;
}
};


Color.prototype.getBorderColor = function(chrSetNumber, chrNmber, armNumber) {

if (chrNmber < this._config.ploidy) {
return '#000';
} else if (this._ploidy.isExists(chrSetNumber, chrNmber, armNumber)) {
return '#000';
} else {
return '#fff';
}
if (chrNmber < this._config.ploidy) {
return '#000';
} else if (this._ploidy.isExists(chrSetNumber, chrNmber, armNumber)) {
return '#000';
} else {
return '#fff';
}
};


Color.prototype._getPolyploidArmColor = function(chrSetNumber, chrNmber, armNumber) {

if (! this._ploidy.isExists(chrSetNumber, chrNmber, armNumber)) {
return 'transparent';
} else {
return this._config.ancestors[this._ploidy.getAncestor(chrSetNumber, chrNmber, armNumber)];
}
if (!this._ploidy.isExists(chrSetNumber, chrNmber, armNumber)) {
return 'transparent';
} else {
return this._config.ancestors[this._ploidy.getAncestor(chrSetNumber, chrNmber, armNumber)];
}
};
54 changes: 34 additions & 20 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var Ideogram = function(config) {
if (!this.config.chrWidth) {
var chrWidth = 10,
chrHeight = this.config.chrHeight;
if (900 > chrHeight && chrHeight > 500) {
if (chrHeight < 900 && chrHeight > 500) {
chrWidth = Math.round(chrHeight / 40);
} else if (chrHeight >= 900) {
chrWidth = Math.round(chrHeight / 45);
Expand Down Expand Up @@ -494,7 +494,6 @@ Ideogram.prototype.drawChromosomeLabels = function() {
* Stalks are small lines that visually connect labels to their bands.
*/
Ideogram.prototype.drawBandLabels = function(chromosomes) {

var i, chr, chrs, taxid, ideo, chrModel;

ideo = this;
Expand Down Expand Up @@ -538,29 +537,35 @@ Ideogram.prototype.drawBandLabels = function(chromosomes) {
.data(chrModel.bands)
.enter()
.append("g")
.attr("class", function(d, i) { return "bandLabel bsbsl-" + i; })
.attr("class", function(d, i) {
return "bandLabel bsbsl-" + i;
})
.attr("transform", function(d) {
var transform = ideo._layout.getChromosomeBandLabelTranslate(d, i);

var x = transform.x;
//var y = transform.y;
// var y = transform.y;

textOffsets[chrModel.id].push(x + 13);

return transform.translate;
})
.append("text")
.attr('text-anchor', ideo._layout.getChromosomeBandLabelAnchor(i))
.text(function(d) { return d.name; });
.text(function(d) {
return d.name;
});

//var adapter = ModelAdapter.getInstance(ideo.chromosomesArray[i]);
//var view = Chromosome.getInstance(adapter, ideo.config, ideo);
// var adapter = ModelAdapter.getInstance(ideo.chromosomesArray[i]);
// var view = Chromosome.getInstance(adapter, ideo.config, ideo);

chr.selectAll("line.bandLabelStalk")
.data(chrModel.bands)
.enter()
.append("g")
.attr("class", function(d, i) { return "bandLabelStalk bsbsl-" + i; })
.attr("class", function(d, i) {
return "bandLabelStalk bsbsl-" + i;
})
.attr("transform", function(d) {
var x, y;

Expand Down Expand Up @@ -671,7 +676,6 @@ Ideogram.prototype.rotateChromosomeLabels = function(chr, chrIndex, orientation,
}

if (orientation === "vertical" || orientation === "") {

var ci = chrIndex - 1;

if (numAnnotTracks > 1 || orientation === "") {
Expand Down Expand Up @@ -706,12 +710,12 @@ Ideogram.prototype.rotateChromosomeLabels = function(chr, chrIndex, orientation,

tracksHeight = ideo.config.annotTracksHeight;
if (ideo.config.annotationsLayout !== "overlay") {
tracksHeight = tracksHeight * 2;
tracksHeight *= 2;
}

chrMargin = ideo.config.chrMargin * chrIndex;
x = -(chrMargin + chrMargin2) + 3 + tracksHeight;
x = x / scale.x;
x /= scale.x;

chr.selectAll("text.chrLabel")
.attr("transform", "rotate(-90)" + scaleSvg)
Expand Down Expand Up @@ -991,8 +995,8 @@ Ideogram.prototype.drawSynteny = function(syntenicRegions) {
* Initializes various annotation settings. Constructor help function.
*/
Ideogram.prototype.initAnnotSettings = function() {
if (this.config.annotationsPath || this.config.localAnnotationsPath
|| this.annots || this.config.annotations) {
if (this.config.annotationsPath || this.config.localAnnotationsPath ||
this.annots || this.config.annotations) {
if (!this.config.annotationHeight) {
var annotHeight = Math.round(this.config.chrHeight / 100);
this.config.annotationHeight = annotHeight;
Expand Down Expand Up @@ -1305,7 +1309,9 @@ Ideogram.prototype.drawProcessedAnnots = function(annots) {
if (layout === "tracks") {
chrAnnot
.append("g")
.attr("id", function(d) { return d.id; })
.attr("id", function(d) {
return d.id;
})
.attr("class", "annot")
.attr("transform", function(d) {
var y = ideo.config.chrWidth + (d.trackIndex * annotHeight * 2);
Expand All @@ -1319,12 +1325,16 @@ Ideogram.prototype.drawProcessedAnnots = function(annots) {
return circle;
}
})
.attr("fill", function(d) { return d.color; });
.attr("fill", function(d) {
return d.color;
});
} else if (layout === "overlay") {
// Overlaid annotations appear directly on chromosomes

chrAnnot.append("polygon")
.attr("id", function(d) { return d.id; })
.attr("id", function(d) {
return d.id;
})
.attr("class", "annot")
.attr("points", function(d) {
x1 = d.px - 0.5;
Expand All @@ -1339,7 +1349,9 @@ Ideogram.prototype.drawProcessedAnnots = function(annots) {
x1 + "," + y2
);
})
.attr("fill", function(d) { return d.color; });
.attr("fill", function(d) {
return d.color;
});
} else if (layout === "histogram") {
chrAnnot.append("polygon")
// .attr("id", function(d, i) { return d.id; })
Expand All @@ -1363,7 +1375,9 @@ Ideogram.prototype.drawProcessedAnnots = function(annots) {
x1 + "," + y2
);
})
.attr("fill", function(d) { return d.color; });
.attr("fill", function(d) {
return d.color;
});
}

if (ideo.onDrawAnnotsCallback) {
Expand Down Expand Up @@ -1638,8 +1652,8 @@ Ideogram.prototype.sortChromosomes = function(a, b) {
bIsCP = b.type === "chloroplast",
aIsMT = a.type === "mitochondrion",
bIsMT = b.type === "mitochondrion";
//aIsPlastid = aIsMT && a.name !== "MT", // e.g. B1 in rice genome GCF_001433935.1
//bIsPlastid = bIsMT && b.name !== "MT";
// aIsPlastid = aIsMT && a.name !== "MT", // e.g. B1 in rice genome GCF_001433935.1
// bIsPlastid = bIsMT && b.name !== "MT";

if (aIsNuclear && bIsNuclear) {
return naturalSort(a.name, b.name);
Expand Down
31 changes: 13 additions & 18 deletions src/js/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ This method flattens that structure to e.g.
See also: packAnnots
*/
Ideogram.prototype.unpackAnnots = function() {

var chr, annots, i,
unpackedAnnots = [],
ideo = this,
chrs = ideo.annots;
unpackedAnnots = [],
ideo = this,
chrs = ideo.annots;

for (i = 0; i < chrs.length; i++) {
chr = chrs[i];
Expand All @@ -27,21 +26,19 @@ Ideogram.prototype.unpackAnnots = function() {
}

return unpackedAnnots;

};

/*
Compresses annots back to default state. Inverse of unpackAnnots.
*/
Ideogram.prototype.packAnnots = function(unpackedAnnots) {

var chr, annot, i,
annots = [],
ideo = this,
chrs = ideo.annots;
annots = [],
ideo = this,
chrs = ideo.annots;

for (chr in chrs) {
annots.push({'chr': chrs[chr].chr, annots: []});
annots.push({chr: chrs[chr].chr, annots: []});
}

for (i = 0; i < unpackedAnnots.length; i++) {
Expand All @@ -50,7 +47,6 @@ Ideogram.prototype.packAnnots = function(unpackedAnnots) {
}

return annots;

};

/*
Expand All @@ -59,8 +55,8 @@ Ideogram.prototype.packAnnots = function(unpackedAnnots) {
*/
Ideogram.prototype.initCrossFilter = function() {
var ideo = this,
keys = ideo.rawAnnots.keys,
i, facet;
keys = ideo.rawAnnots.keys,
i, facet;

ideo.unpackedAnnots = ideo.unpackAnnots();
ideo.crossfilter = crossfilter(ideo.unpackedAnnots);
Expand Down Expand Up @@ -103,14 +99,13 @@ Ideogram.prototype.initCrossFilter = function() {
* Integrate server-side filtering for very large datasets
*/
Ideogram.prototype.filterAnnots = function(selections) {

var t0 = Date.now();

var i, facet,
prevFacet = null,
results, fn,
counts = {},
ideo = this;
prevFacet = null,
results, fn,
counts = {},
ideo = this;

if (Object.keys(selections).length === 0) {
results = ideo.unpackedAnnots;
Expand Down
Loading

0 comments on commit dbacd6e

Please sign in to comment.