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

Side by Side Diff: tracing/tracing/base/range.html

Issue 1300433003: Add range toJSON and fromDict (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « no previous file | tracing/tracing/base/range_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/tracing/base/base.html"> 8 <link rel="import" href="/tracing/base/base.html">
9 9
10 <script> 10 <script>
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (this.isEmpty || range.isEmpty) 125 if (this.isEmpty || range.isEmpty)
126 return new Range(); 126 return new Range();
127 127
128 var min = Math.max(this.min, range.min); 128 var min = Math.max(this.min, range.min);
129 var max = Math.min(this.max, range.max); 129 var max = Math.min(this.max, range.max);
130 130
131 if (max < min) 131 if (max < min)
132 return new Range(); 132 return new Range();
133 133
134 return Range.fromExplicitRange(min, max); 134 return Range.fromExplicitRange(min, max);
135 },
136
137 toJSON: function() {
138 if (this.isEmpty_)
139 return {isEmpty: true};
140 return {
141 isEmpty: false,
142 max: this.max,
143 min: this.min
144 };
135 } 145 }
136 }; 146 };
137 147
148 Range.fromDict = function(d) {
149 if (d.isEmpty === true) {
150 return new Range();
151 } else if (d.isEmpty === false) {
152 var range = new Range();
153 range.min = d.min;
154 range.max = d.max;
155 return range;
156 } else {
157 throw new Error('Not a range');
158 }
159 };
160
138 Range.fromExplicitRange = function(min, max) { 161 Range.fromExplicitRange = function(min, max) {
139 var range = new Range(); 162 var range = new Range();
140 range.min = min; 163 range.min = min;
141 range.max = max; 164 range.max = max;
142 return range; 165 return range;
143 }; 166 };
144 167
145 Range.compareByMinTimes = function(a, b) { 168 Range.compareByMinTimes = function(a, b) {
146 if (!a.isEmpty && !b.isEmpty) 169 if (!a.isEmpty && !b.isEmpty)
147 return a.min_ - b.min_; 170 return a.min_ - b.min_;
148 171
149 if (a.isEmpty && !b.isEmpty) 172 if (a.isEmpty && !b.isEmpty)
150 return -1; 173 return -1;
151 174
152 if (!a.isEmpty && b.isEmpty) 175 if (!a.isEmpty && b.isEmpty)
153 return 1; 176 return 1;
154 177
155 return 0; 178 return 0;
156 }; 179 };
157 180
158 return { 181 return {
159 Range: Range 182 Range: Range
160 }; 183 };
161 }); 184 });
162 </script> 185 </script>
OLDNEW
« no previous file with comments | « no previous file | tracing/tracing/base/range_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698