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