|
65 | 65 | getTickColor: null,
|
66 | 66 | getPointerColor: null,
|
67 | 67 | keyboardSupport: true,
|
| 68 | + logScale: false, |
68 | 69 | scale: 1,
|
69 | 70 | enforceStep: true,
|
70 | 71 | enforceRange: false,
|
|
835 | 836 | this.precision = +this.options.precision;
|
836 | 837 |
|
837 | 838 | this.minValue = this.options.floor;
|
| 839 | + if (this.options.logScale && this.minValue === 0) |
| 840 | + throw new Error("Can't use floor=0 with logarithmic scale"); |
838 | 841 |
|
839 | 842 | if (this.options.enforceStep) {
|
840 | 843 | this.lowValue = this.roundStep(this.lowValue);
|
|
1411 | 1414 | * @returns {number}
|
1412 | 1415 | */
|
1413 | 1416 | valueToOffset: function(val) {
|
1414 |
| - if (this.options.rightToLeft) { |
1415 |
| - return (this.maxValue - this.sanitizeValue(val)) * this.maxPos / this.valueRange || 0; |
| 1417 | + var sanitizedValue = this.sanitizeValue(val); |
| 1418 | + if (!this.options.logScale) { |
| 1419 | + if (this.options.rightToLeft) { |
| 1420 | + return (this.maxValue - sanitizedValue) * this.maxPos / this.valueRange || 0; |
| 1421 | + } |
| 1422 | + return (sanitizedValue - this.minValue) * this.maxPos / this.valueRange || 0; |
| 1423 | + } |
| 1424 | + else { |
| 1425 | + var minLog = Math.log(this.minValue), |
| 1426 | + maxLog = Math.log(this.maxValue), |
| 1427 | + scale = (maxLog - minLog) / (this.maxPos); |
| 1428 | + return (Math.log(sanitizedValue) - minLog) / scale || 0; |
1416 | 1429 | }
|
1417 |
| - return (this.sanitizeValue(val) - this.minValue) * this.maxPos / this.valueRange || 0; |
1418 | 1430 | },
|
1419 | 1431 |
|
1420 | 1432 | /**
|
|
1434 | 1446 | * @returns {number}
|
1435 | 1447 | */
|
1436 | 1448 | offsetToValue: function(offset) {
|
1437 |
| - if (this.options.rightToLeft) { |
1438 |
| - return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; |
| 1449 | + if (!this.options.logScale) { |
| 1450 | + if (this.options.rightToLeft) { |
| 1451 | + return (1 - (offset / this.maxPos)) * this.valueRange + this.minValue; |
| 1452 | + } |
| 1453 | + return (offset / this.maxPos) * this.valueRange + this.minValue; |
| 1454 | + } |
| 1455 | + else { |
| 1456 | + var minLog = Math.log(this.minValue), |
| 1457 | + maxLog = Math.log(this.maxValue), |
| 1458 | + scale = (maxLog - minLog) / (this.maxPos); |
| 1459 | + return Math.exp(minLog + scale * offset); |
1439 | 1460 | }
|
1440 |
| - return (offset / this.maxPos) * this.valueRange + this.minValue; |
1441 | 1461 | },
|
1442 | 1462 |
|
1443 | 1463 | // Events
|
|
0 commit comments