Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: lib/src/iron-range-behavior/iron-range-behavior.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 <link rel="import" href="../polymer/polymer.html"> 11 <link rel="import" href="../polymer/polymer.html">
12 12
13 <script> 13 <script>
14 14
15 /** 15 /**
16 * `iron-range-behavior` provides the behavior for something with a minimum to m aximum range. 16 * `iron-range-behavior` provides the behavior for something with a minimum to m aximum range.
17 * 17 *
18 * @demo demo/index.html 18 * @demo demo/index.html
19 * @polymerBehavior 19 * @polymerBehavior
20 */ 20 */
21 Polymer.IronRangeBehavior = { 21 Polymer.IronRangeBehavior = {
22 22
23 properties: { 23 properties: {
24 24
25 /** 25 /**
26 * The number that represents the current value. 26 * The number that represents the current value.
27 */ 27 */
28 value: { 28 value: {
29 type: Number, 29 type: Number,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 /** 86 /**
87 * if we calculate the step using 87 * if we calculate the step using
88 * `Math.round(value / step) * step` we may hit a precision point issue 88 * `Math.round(value / step) * step` we may hit a precision point issue
89 * eg. 0.1 * 0.2 = 0.020000000000000004 89 * eg. 0.1 * 0.2 = 0.020000000000000004
90 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 90 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
91 * 91 *
92 * as a work around we can divide by the reciprocal of `step` 92 * as a work around we can divide by the reciprocal of `step`
93 */ 93 */
94 return this.step ? (Math.round(value / this.step) / (1 / this.step)) : value ; 94 // polymer/issues/2493
95 value = parseFloat(value);
96 return this.step ? (Math.round((value + this.min) / this.step) -
97 (this.min / this.step)) / (1 / this.step) : value;
95 }, 98 },
96 99
97 _validateValue: function() { 100 _validateValue: function() {
98 var v = this._clampValue(this.value); 101 var v = this._clampValue(this.value);
99 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; 102 this.value = this.oldValue = isNaN(v) ? this.oldValue : v;
100 return this.value !== v; 103 return this.value !== v;
101 }, 104 },
102 105
103 _update: function() { 106 _update: function() {
104 this._validateValue(); 107 this._validateValue();
105 this._setRatio(this._calcRatio(this.value) * 100); 108 this._setRatio(this._calcRatio(this.value) * 100);
106 } 109 }
107 110
108 }; 111 };
109 </script> 112 </script>
OLDNEW
« no previous file with comments | « lib/src/iron-overlay-behavior/test/iron-overlay-behavior.html ('k') | lib/src/iron-range-behavior/test/basic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698