| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 @license | 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> | 9 --> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 _calcRatio: function(value) { | 77 _calcRatio: function(value) { |
| 78 return (this._clampValue(value) - this.min) / (this.max - this.min); | 78 return (this._clampValue(value) - this.min) / (this.max - this.min); |
| 79 }, | 79 }, |
| 80 | 80 |
| 81 _clampValue: function(value) { | 81 _clampValue: function(value) { |
| 82 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); | 82 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 _calcStep: function(value) { | 85 _calcStep: function(value) { |
| 86 /** | |
| 87 * if we calculate the step using | |
| 88 * `Math.round(value / step) * step` we may hit a precision point issue | |
| 89 * eg. 0.1 * 0.2 = 0.020000000000000004 | |
| 90 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html | |
| 91 * | |
| 92 * as a work around we can divide by the reciprocal of `step` | |
| 93 */ | |
| 94 // polymer/issues/2493 | 86 // polymer/issues/2493 |
| 95 value = parseFloat(value); | 87 value = parseFloat(value); |
| 96 return this.step ? (Math.round((value + this.min) / this.step) - | 88 |
| 97 (this.min / this.step)) / (1 / this.step) : value; | 89 if (!this.step) { |
| 90 return value; |
| 91 } |
| 92 |
| 93 var numSteps = Math.round((value - this.min) / this.step); |
| 94 if (this.step < 1) { |
| 95 /** |
| 96 * For small values of this.step, if we calculate the step using |
| 97 * `Math.round(value / step) * step` we may hit a precision point issue |
| 98 * eg. 0.1 * 0.2 = 0.020000000000000004 |
| 99 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html |
| 100 * |
| 101 * as a work around we can divide by the reciprocal of `step` |
| 102 */ |
| 103 return numSteps / (1 / this.step) + this.min; |
| 104 } else { |
| 105 return numSteps * this.step + this.min; |
| 106 } |
| 98 }, | 107 }, |
| 99 | 108 |
| 100 _validateValue: function() { | 109 _validateValue: function() { |
| 101 var v = this._clampValue(this.value); | 110 var v = this._clampValue(this.value); |
| 102 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; | 111 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; |
| 103 return this.value !== v; | 112 return this.value !== v; |
| 104 }, | 113 }, |
| 105 | 114 |
| 106 _update: function() { | 115 _update: function() { |
| 107 this._validateValue(); | 116 this._validateValue(); |
| 108 this._setRatio(this._calcRatio(this.value) * 100); | 117 this._setRatio(this._calcRatio(this.value) * 100); |
| 109 } | 118 } |
| 110 | 119 |
| 111 }; | 120 }; |
| 112 </script> | 121 </script> |
| OLD | NEW |