Commit 468ed3d7 authored by Valentin Hervieu's avatar Valentin Hervieu

Add rtl support

parent f23909fe
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
getTickColor: null, getTickColor: null,
getPointerColor: null, getPointerColor: null,
keyboardSupport: true, keyboardSupport: true,
logScale: false,
scale: 1, scale: 1,
enforceStep: true, enforceStep: true,
enforceRange: false, enforceRange: false,
...@@ -832,6 +833,8 @@ ...@@ -832,6 +833,8 @@
this.precision = +this.options.precision; this.precision = +this.options.precision;
this.minValue = this.options.floor; this.minValue = this.options.floor;
if (this.options.logScale && this.minValue === 0)
throw new Error("Can't use floor=0 with logarithmic scale");
if (this.options.enforceStep) { if (this.options.enforceStep) {
this.lowValue = this.roundStep(this.lowValue); this.lowValue = this.roundStep(this.lowValue);
...@@ -1425,10 +1428,17 @@ ...@@ -1425,10 +1428,17 @@
* @returns {number} * @returns {number}
*/ */
valueToOffset: function(val) { valueToOffset: function(val) {
if (this.options.rightToLeft) { var sanitizedValue = this.sanitizeValue(val),
return (this.maxValue - this.sanitizeValue(val)) * this.maxPos / this.valueRange || 0; minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
} maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
return (this.sanitizeValue(val) - this.minValue) * this.maxPos / this.valueRange || 0; range = maxValue - minValue;
if (this.options.logScale)
sanitizedValue = Math.log(sanitizedValue);
if (this.options.rightToLeft)
return (maxValue - sanitizedValue) * this.maxPos / range || 0;
return (sanitizedValue - minValue) * this.maxPos / range || 0;
}, },
/** /**
...@@ -1448,10 +1458,16 @@ ...@@ -1448,10 +1458,16 @@
* @returns {number} * @returns {number}
*/ */
offsetToValue: function(offset) { offsetToValue: function(offset) {
if (this.options.rightToLeft) { var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
} range = maxValue - minValue,
return (offset / this.maxPos) * this.valueRange + this.minValue; value = 0;
if (this.options.rightToLeft)
value = (1 - offset / this.maxPos) * range + minValue;
else
value = offset / this.maxPos * range + minValue;
return this.options.logScale ? Math.exp(value) : value;
}, },
// Events // Events
......
This diff is collapsed.
...@@ -1432,19 +1432,17 @@ ...@@ -1432,19 +1432,17 @@
* @returns {number} * @returns {number}
*/ */
valueToOffset: function(val) { valueToOffset: function(val) {
var sanitizedValue = this.sanitizeValue(val); var sanitizedValue = this.sanitizeValue(val),
if (!this.options.logScale) { minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
if (this.options.rightToLeft) { maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
return (this.maxValue - sanitizedValue) * this.maxPos / this.valueRange || 0; range = maxValue - minValue;
}
return (sanitizedValue - this.minValue) * this.maxPos / this.valueRange || 0; if (this.options.logScale)
} sanitizedValue = Math.log(sanitizedValue);
else {
var minLog = Math.log(this.minValue), if (this.options.rightToLeft)
maxLog = Math.log(this.maxValue), return (maxValue - sanitizedValue) * this.maxPos / range || 0;
scale = (maxLog - minLog) / (this.maxPos); return (sanitizedValue - minValue) * this.maxPos / range || 0;
return (Math.log(sanitizedValue) - minLog) / scale || 0;
}
}, },
/** /**
...@@ -1464,18 +1462,16 @@ ...@@ -1464,18 +1462,16 @@
* @returns {number} * @returns {number}
*/ */
offsetToValue: function(offset) { offsetToValue: function(offset) {
if (!this.options.logScale) { var minValue = this.options.logScale ? Math.log(this.minValue) : this.minValue,
if (this.options.rightToLeft) { maxValue = this.options.logScale ? Math.log(this.maxValue) : this.maxValue,
return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; range = maxValue - minValue,
} value = 0;
return (offset / this.maxPos) * this.valueRange + this.minValue; if (this.options.rightToLeft)
} value = (1 - offset / this.maxPos) * range + minValue;
else { else
var minLog = Math.log(this.minValue), value = offset / this.maxPos * range + minValue;
maxLog = Math.log(this.maxValue),
scale = (maxLog - minLog) / (this.maxPos); return this.options.logScale ? Math.exp(value) : value;
return Math.exp(minLog + scale * offset);
}
}, },
// Events // Events
......
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