OLD | NEW |
1 | 1 |
2 | 2 |
3 /** | 3 /** |
4 * `iron-range-behavior` provides the behavior for something with a minimum to m
aximum range. | 4 * `iron-range-behavior` provides the behavior for something with a minimum to m
aximum range. |
5 * | 5 * |
6 * @demo demo/index.html | 6 * @demo demo/index.html |
7 * @polymerBehavior | 7 * @polymerBehavior |
8 */ | 8 */ |
9 Polymer.IronRangeBehavior = { | 9 Polymer.IronRangeBehavior = { |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 _calcRatio: function(value) { | 65 _calcRatio: function(value) { |
66 return (this._clampValue(value) - this.min) / (this.max - this.min); | 66 return (this._clampValue(value) - this.min) / (this.max - this.min); |
67 }, | 67 }, |
68 | 68 |
69 _clampValue: function(value) { | 69 _clampValue: function(value) { |
70 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); | 70 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); |
71 }, | 71 }, |
72 | 72 |
73 _calcStep: function(value) { | 73 _calcStep: function(value) { |
| 74 /** |
| 75 * if we calculate the step using |
| 76 * `Math.round(value / step) * step` we may hit a precision point issue |
| 77 * eg. 0.1 * 0.2 = 0.020000000000000004 |
| 78 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html |
| 79 * |
| 80 * as a work around we can divide by the reciprocal of `step` |
| 81 */ |
74 return this.step ? (Math.round(value / this.step) / (1 / this.step)) : value
; | 82 return this.step ? (Math.round(value / this.step) / (1 / this.step)) : value
; |
75 }, | 83 }, |
76 | 84 |
77 _validateValue: function() { | 85 _validateValue: function() { |
78 var v = this._clampValue(this.value); | 86 var v = this._clampValue(this.value); |
79 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; | 87 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; |
80 return this.value !== v; | 88 return this.value !== v; |
81 }, | 89 }, |
82 | 90 |
83 _update: function() { | 91 _update: function() { |
84 this._validateValue(); | 92 this._validateValue(); |
85 this._setRatio(this._calcRatio(this.value) * 100); | 93 this._setRatio(this._calcRatio(this.value) * 100); |
86 } | 94 } |
87 | 95 |
88 }; | 96 }; |
OLD | NEW |