Commit aa2e2dca authored by Mathieu Giraud's avatar Mathieu Giraud

js/generic,numeric_axis , scatterPlot: refactor + simplify , bar use x as grid

Remove computeBarLabel: we use the same regular labels than for MODE_GRID.
See #2700
parent 75644d2d
......@@ -35,6 +35,7 @@ function GenericAxis (reverse, can_undefined) {
this.value_mapping = {};
this.can_undefined = true;
this.MAX_NB_STEPS_IN_AXIS = 8; // Number (max) of labels per numerical axis
this.MAX_NB_BARS_IN_AXIS = 100
this.NB_STEPS_BAR = 18; // Number (max) of labels per numerical axis in histograms
if(typeof can_undefined !== "undefined")
this.can_undefined = can_undefined;
......@@ -212,31 +213,6 @@ GenericAxis.prototype = {
}
},
/**
* add labels for barplot <br>
* @param {Array} tab - barplot descriptor like the one made by Model.computeBarTab()
* */
computeBarLabels : function () {
this.labels = [];
this.label_mapping = {};
var length = Object.keys(this.value_mapping).length;
var step = 1 + Math.floor(length / this.NB_STEPS_BAR)
var text;
var i=1
for (var e in this.value_mapping){
if (i%step === 0 || (e == '?' && this.value_mapping[e].length > 0)){
text = this.getLabelText(e);
if (e == '?')
text = e;
var pos = this.posBarLabel(i, length);
if (this.reverse) pos = 1 - pos;
this.addLabel("line", text, pos, text);
}
i++;
}
},
getLabelText: function(value) {
return value;
......
......@@ -64,6 +64,7 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
this.nb_steps_special = this.can_undefined ? 1 : 0
this.nb_steps_normal = this.nb_steps - this.nb_steps_special
// Sets this.converter
if (typeof fct === 'function') {
this.converter = fct;
} else {
......@@ -71,7 +72,8 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
return elem[fct];
}
}
// Compute min / max
var min = default_min;
var max = default_max;
if (typeof min === 'function') min = min();
......@@ -88,21 +90,7 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
}
}
}
for (var j=min; j<=max; j++){
this.value_mapping[j]=[];
}
} else {
for (var k in labels) {
var val = labels[k];
this.value_mapping[val] = [];
}
}
if(this.can_undefined)
this.value_mapping["?"] = [];
// insert all the values into the valuemapping object
this.insert_values()
if (typeof min == "undefined"){
min = 0;
......@@ -144,7 +132,18 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
.domain([min, max])
.range(range);
}
// Prepare value_mapping
this.value_mapping = {};
if(this.can_undefined)
this.value_mapping["?"] = [];
this.insert_values()
// Set labels
this.computeLabels(min, max, use_log, display_label, this.can_undefined)
}
......@@ -152,6 +151,11 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
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'){
pos = this.sizeScale(value);
}else{
......@@ -165,10 +169,17 @@ NumericalAxis.prototype = Object.create(GenericAxis.prototype);
* This function allow to insert all the values getted into the value_mapping object.
*/
NumericalAxis.prototype.insert_values = function() {
for(var idx in this.clones) {
this.step_bar = nice_1_2_5_ceil((this.max - this.min) / this.MAX_NB_BARS_IN_AXIS)
// Init value_mapping
for (var m = this.min; m < this.max; m += this.step_bar)
this.value_mapping[nice_ceil(m, this.step_bar)] = []
// Fill value_mapping
for (var idx in this.clones) {
var clone = this.clones[idx];
if(!clone.isVirtual()) {
var value = this.applyConverter(clone);
var value = nice_ceil(this.applyConverter(clone), this.step_bar);
if (typeof value == "undefined" || value == undefined || value == "undefined") {
if (this.can_undefined)
this.value_mapping["?"].push(clone);
......
......@@ -668,10 +668,8 @@ ScatterPlot.prototype = {
k=1 ;
for (var i in this.barTab) {
val = this.barTab[i];
var y_pos = 0
var x_pos = this.axisX.posBarLabel(k);
var x_pos = this.axisX.pos_from_value(i).pos
for (var j in this.barTab[i]){
var clone = this.barTab[i][j]
......@@ -695,7 +693,6 @@ ScatterPlot.prototype = {
}
this.axisY.reverse = true;
this.axisY.computeLabels(0, bar_max);
this.axisX.computeBarLabels(this.barTab)
this.initGrid();
this.drawBarTab(500);
......
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