4 * `iron-range-behavior` provides the behavior for something with a minimum to maximum range.
6 * @demo demo/index.html
9 Polymer.IronRangeBehavior = {
14 * The number that represents the current value.
20 reflectToAttribute: true
24 * The number that indicates the minimum value of the range.
33 * The number that indicates the maximum value of the range.
42 * Specifies the value granularity of the range's value.
51 * Returns the ratio of the value.
62 '_update(value, min, max, step)'
65 _calcRatio: function(value) {
66 return (this._clampValue(value) - this.min) / (this.max - this.min);
69 _clampValue: function(value) {
70 return Math.min(this.max, Math.max(this.min, this._calcStep(value)));
73 _calcStep: function(value) {
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
80 * as a work around we can divide by the reciprocal of `step`
82 return this.step ? (Math.round(value / this.step) / (1 / this.step)) : value;
85 _validateValue: function() {
86 var v = this._clampValue(this.value);
87 this.value = this.oldValue = isNaN(v) ? this.oldValue : v;
88 return this.value !== v;
92 this._validateValue();
93 this._setRatio(this._calcRatio(this.value) * 100);