Commit 6e62b4cc authored by Ryan Herbert's avatar Ryan Herbert
Browse files

Merge branch 'hotfix-c/fix_generic_axis_sort' into dev

parents 0f294f13 af02c410
...@@ -149,7 +149,8 @@ Axes.prototype = { ...@@ -149,7 +149,8 @@ Axes.prototype = {
label: "locus", label: "locus",
axis: new GenericAxis(), axis: new GenericAxis(),
fct: function(clone){return clone.germline}, fct: function(clone){return clone.germline},
pretty: function(system) { return self.m.systemBox(system) } pretty: function(system) { return self.m.systemBox(system) },
sort: true
}, },
"Size" : { "Size" : {
doc: "ratio of the number of reads of each clone to the total number of reads in the selected locus", doc: "ratio of the number of reads of each clone to the total number of reads in the selected locus",
......
...@@ -58,34 +58,30 @@ GenericAxis.prototype = { ...@@ -58,34 +58,30 @@ GenericAxis.prototype = {
} }
} }
this.populateLabels(labels); this.populateLabels(labels, sort);
this.populateValueMapping(); this.populateValueMapping();
if (sort)
this.labels.sort(this.compareLabels);
return this; return this;
}, },
compareLabels: function(lab1, lab2) { compareLabels: function(a, b) {
var a = lab1.text;
var b = lab2.text;
if (typeof a === 'undefined') return (typeof b === 'undefined') ? 0 : -1; if (typeof a === 'undefined') return (typeof b === 'undefined') ? 0 : -1;
if (typeof b === 'undefined') return (typeof a === 'undefined') ? 0 : 1; if (typeof b === 'undefined') return (typeof a === 'undefined') ? 0 : 1;
if (a.constructor === String) { if (a.constructor === String) {
if (b.constructor === String) return va.localeCompare(vb); if (b.constructor === String) return a.localeCompare(b);
if (b.constructor === Number ) return 1 if (b.constructor === Number ) return 1
} }
if (a.constructor === Number) return (b.constructor === Number ) ? (a-b) : -1; if (a.constructor === Number) return (b.constructor === Number ) ? (a-b) : -1;
}, },
populateLabels: function(labels) { populateLabels: function(labels, sort) {
var values = this.values; var values = this.values;
var label_mapping = this.label_mapping; var label_mapping = this.label_mapping;
if (typeof labels === 'undefined') if (typeof labels === 'undefined')
this.computeLabels(values); this.computeLabels(values, sort);
else { else {
for (var i=0; i < values.length; i++) { for (var i=0; i < values.length; i++) {
var value = values[i]; var value = values[i];
...@@ -181,28 +177,29 @@ GenericAxis.prototype = { ...@@ -181,28 +177,29 @@ GenericAxis.prototype = {
return value; return value;
}, },
computeLabels: function(values) { computeLabels: function(values, sort) {
var cursor = 0; var label_list = [];
var labels = {};
var has_undefined; var has_undefined;
for (var i = 0; i < values.length; i++) { for (var i = 0; i < values.length; i++) {
var value = values[i]; var value = values[i];
var key = this.applyConverter(value); var key = this.applyConverter(value);
if (typeof key == 'undefined') { if (typeof key == 'undefined') {
has_undefined = true; has_undefined = true;
} else if (typeof labels[key] === 'undefined') { } else if (label_list.indexOf(key) == -1) {
labels[key] = this.label("line", cursor, key); label_list.push(key);
cursor++;
} }
} }
for (var idx in labels) { if (sort)
var label = labels[idx]; label_list.sort(this.compareLabels);
this.addLabel(label.type, label.text, label.pos/cursor, label.text);
for (var idx = 0; idx < label_list.length; idx++) {
var label = label_list[idx];
this.addLabel("line", label, idx/label_list.length, label);
} }
if (has_undefined) { if (has_undefined) {
if (typeof this.label_mapping["?"] === 'undefined') if (typeof this.label_mapping["?"] === 'undefined')
this.addLabel("line", "?", cursor, "?"); this.addLabel("line", "?", label_list.length + 1, "?");
} }
}, },
......
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