Commit f412e49f authored by Mathieu Giraud's avatar Mathieu Giraud

js/{generic,numeric}_axis.js: use the same mechanism, pos/pos_from_value,...

js/{generic,numeric}_axis.js: use the same mechanism, pos/pos_from_value, re-factor pos into generic_axis

Make converge populateValues().
See #2700 and #2905.
parent aa2e2dca
......@@ -115,24 +115,18 @@ GenericAxis.prototype = {
},
populateValueMapping: function() {
var values = this.values;
var value_mapping = this.value_mapping;
var label_mapping = this.label_mapping;
var label_array = Object.keys(label_mapping);
for (var i = 0; i < values.length; i++) {
var value = values[i];
for (var idx in this.values) {
var value = this.values[idx];
var convert = this.applyConverter(value);
if (typeof label_mapping[convert] !== 'undefined') {
var index = label_array.indexOf(convert);
if (typeof value_mapping[index] === 'undefined') {
value_mapping[index] = [];
}
value_mapping[index].push(value);
if (typeof convert !== 'undefined') {
this.value_mapping[convert] = this.value_mapping[convert] || []
this.value_mapping[convert].push(value);
} else if (this.can_undefined){
if (typeof value_mapping["?"] === 'undefined')
value_mapping["?"] = [];
value_mapping["?"].push(value);
if (typeof this.value_mapping["?"] === 'undefined')
this.value_mapping["?"] = [];
this.value_mapping["?"].push(value);
}
}
},
......@@ -181,10 +175,19 @@ GenericAxis.prototype = {
},
pos: function(element) {
var value = this.label_mapping[this.applyConverter(element)];
if (typeof value === 'undefined')
value = this.label_mapping["?"];
return value;
value = this.applyConverter(element);
return this.pos_from_value(value)
},
pos_from_value: function(value) {
var pos = this.label_mapping[value]
if (typeof pos === 'undefined')
pos = this.label_mapping["?"];
return pos ;
},
computeLabels: function(values, sort) {
......
......@@ -147,13 +147,6 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
this.computeLabels(min, max, use_log, display_label, this.can_undefined)
}
NumericalAxis.prototype.pos = function(clone) {
var value, pos;
value = this.applyConverter(clone);
return this.pos_from_value(value)
}
NumericalAxis.prototype.pos_from_value = function(value) {
if (typeof value != "undefined" && value != 'undefined'){
......
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