OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 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/color_scheme.html"> | 8 <link rel="import" href="/tracing/base/color_scheme.html"> |
9 <link rel="import" href="/tracing/base/math/sorted_array_utils.html"> | 9 <link rel="import" href="/tracing/base/math/sorted_array_utils.html"> |
10 <link rel="import" href="/tracing/model/proxy_selectable_item.html"> | 10 <link rel="import" href="/tracing/model/proxy_selectable_item.html"> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 set height(height) { | 74 set height(height) { |
75 this.style.height = height; | 75 this.style.height = height; |
76 }, | 76 }, |
77 | 77 |
78 get dumpRadiusView() { | 78 get dumpRadiusView() { |
79 return 7 * (window.devicePixelRatio || 1); | 79 return 7 * (window.devicePixelRatio || 1); |
80 }, | 80 }, |
81 | 81 |
82 draw: function(type, viewLWorld, viewRWorld) { | 82 draw: function(type, viewLWorld, viewRWorld) { |
83 if (this.items_ === undefined) | 83 if (this.items_ === undefined) return; |
84 return; | 84 |
85 switch (type) { | 85 switch (type) { |
86 case tr.ui.tracks.DrawType.GENERAL_EVENT: | 86 case tr.ui.tracks.DrawType.GENERAL_EVENT: |
87 this.drawLetterDots_(viewLWorld, viewRWorld); | 87 this.drawLetterDots_(viewLWorld, viewRWorld); |
88 break; | 88 break; |
89 } | 89 } |
90 }, | 90 }, |
91 | 91 |
92 drawLetterDots_: function(viewLWorld, viewRWorld) { | 92 drawLetterDots_: function(viewLWorld, viewRWorld) { |
93 var ctx = this.context(); | 93 var ctx = this.context(); |
94 var pixelRatio = window.devicePixelRatio || 1; | 94 var pixelRatio = window.devicePixelRatio || 1; |
(...skipping 18 matching lines...) Expand all Loading... |
113 var oldFont = ctx.font; | 113 var oldFont = ctx.font; |
114 ctx.font = '400 ' + Math.floor(9 * pixelRatio) + 'px Arial'; | 114 ctx.font = '400 ' + Math.floor(9 * pixelRatio) + 'px Arial'; |
115 ctx.strokeStyle = 'rgb(0,0,0)'; | 115 ctx.strokeStyle = 'rgb(0,0,0)'; |
116 ctx.textBaseline = 'middle'; | 116 ctx.textBaseline = 'middle'; |
117 ctx.textAlign = 'center'; | 117 ctx.textAlign = 'center'; |
118 | 118 |
119 var drawItems = function(selected) { | 119 var drawItems = function(selected) { |
120 for (var i = loI; i < items.length; ++i) { | 120 for (var i = loI; i < items.length; ++i) { |
121 var item = items[i]; | 121 var item = items[i]; |
122 var x = item.start; | 122 var x = item.start; |
123 if (x - itemRadiusWorld > viewRWorld) | 123 if (x - itemRadiusWorld > viewRWorld) break; |
124 break; | 124 |
125 if (item.selected !== selected) | 125 if (item.selected !== selected) continue; |
126 continue; | 126 |
127 var xView = dt.xWorldToView(x); | 127 var xView = dt.xWorldToView(x); |
128 | 128 |
129 ctx.fillStyle = EventPresenter.getSelectableItemColorAsString(item); | 129 ctx.fillStyle = EventPresenter.getSelectableItemColorAsString(item); |
130 ctx.beginPath(); | 130 ctx.beginPath(); |
131 ctx.arc(xView, halfHeight, dumpRadiusView + 0.5, 0, twoPi); | 131 ctx.arc(xView, halfHeight, dumpRadiusView + 0.5, 0, twoPi); |
132 ctx.fill(); | 132 ctx.fill(); |
133 if (item.selected) { | 133 if (item.selected) { |
134 ctx.lineWidth = 3; | 134 ctx.lineWidth = 3; |
135 ctx.strokeStyle = 'rgb(100,100,0)'; | 135 ctx.strokeStyle = 'rgb(100,100,0)'; |
136 ctx.stroke(); | 136 ctx.stroke(); |
(...skipping 17 matching lines...) Expand all Loading... |
154 // Draw unselected items first to make sure they don't occlude selected | 154 // Draw unselected items first to make sure they don't occlude selected |
155 // items. | 155 // items. |
156 drawItems(false); | 156 drawItems(false); |
157 drawItems(true); | 157 drawItems(true); |
158 | 158 |
159 ctx.lineWidth = 1; | 159 ctx.lineWidth = 1; |
160 ctx.font = oldFont; | 160 ctx.font = oldFont; |
161 }, | 161 }, |
162 | 162 |
163 addEventsToTrackMap: function(eventToTrackMap) { | 163 addEventsToTrackMap: function(eventToTrackMap) { |
164 if (this.items_ === undefined) | 164 if (this.items_ === undefined) return; |
165 return; | |
166 | 165 |
167 this.items_.forEach(function(item) { | 166 this.items_.forEach(function(item) { |
168 item.addToTrackMap(eventToTrackMap, this); | 167 item.addToTrackMap(eventToTrackMap, this); |
169 }, this); | 168 }, this); |
170 }, | 169 }, |
171 | 170 |
172 addIntersectingEventsInRangeToSelectionInWorldSpace: function( | 171 addIntersectingEventsInRangeToSelectionInWorldSpace: function( |
173 loWX, hiWX, viewPixWidthWorld, selection) { | 172 loWX, hiWX, viewPixWidthWorld, selection) { |
174 if (this.items_ === undefined) | 173 if (this.items_ === undefined) return; |
175 return; | |
176 | 174 |
177 var itemRadiusWorld = viewPixWidthWorld * this.dumpRadiusView; | 175 var itemRadiusWorld = viewPixWidthWorld * this.dumpRadiusView; |
178 tr.b.math.iterateOverIntersectingIntervals( | 176 tr.b.math.iterateOverIntersectingIntervals( |
179 this.items_, | 177 this.items_, |
180 function(x) { return x.start - itemRadiusWorld; }, | 178 function(x) { return x.start - itemRadiusWorld; }, |
181 function(x) { return 2 * itemRadiusWorld; }, | 179 function(x) { return 2 * itemRadiusWorld; }, |
182 loWX, hiWX, | 180 loWX, hiWX, |
183 function(item) { | 181 function(item) { |
184 item.addToSelection(selection); | 182 item.addToSelection(selection); |
185 }.bind(this)); | 183 }.bind(this)); |
186 }, | 184 }, |
187 | 185 |
188 /** | 186 /** |
189 * Add the item to the left or right of the provided event, if any, to the | 187 * Add the item to the left or right of the provided event, if any, to the |
190 * selection. | 188 * selection. |
191 * @param {event} The current event item. | 189 * @param {event} The current event item. |
192 * @param {Number} offset Number of slices away from the event to look. | 190 * @param {Number} offset Number of slices away from the event to look. |
193 * @param {Selection} selection The selection to add an event to, | 191 * @param {Selection} selection The selection to add an event to, |
194 * if found. | 192 * if found. |
195 * @return {boolean} Whether an event was found. | 193 * @return {boolean} Whether an event was found. |
196 * @private | 194 * @private |
197 */ | 195 */ |
198 addEventNearToProvidedEventToSelection: function(event, offset, selection) { | 196 addEventNearToProvidedEventToSelection: function(event, offset, selection) { |
199 if (this.items_ === undefined) | 197 if (this.items_ === undefined) return; |
200 return; | |
201 | 198 |
202 var items = this.items_; | 199 var items = this.items_; |
203 var index = tr.b.findFirstIndexInArray(items, function(item) { | 200 var index = tr.b.findFirstIndexInArray(items, function(item) { |
204 return item.modelItem === event; | 201 return item.modelItem === event; |
205 }); | 202 }); |
206 if (index === -1) | 203 if (index === -1) return false; |
207 return false; | |
208 | 204 |
209 var newIndex = index + offset; | 205 var newIndex = index + offset; |
210 if (newIndex >= 0 && newIndex < items.length) { | 206 if (newIndex >= 0 && newIndex < items.length) { |
211 items[newIndex].addToSelection(selection); | 207 items[newIndex].addToSelection(selection); |
212 return true; | 208 return true; |
213 } | 209 } |
214 return false; | 210 return false; |
215 }, | 211 }, |
216 | 212 |
217 addAllEventsMatchingFilterToSelection: function(filter, selection) { | 213 addAllEventsMatchingFilterToSelection: function(filter, selection) { |
218 }, | 214 }, |
219 | 215 |
220 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY, | 216 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY, |
221 selection) { | 217 selection) { |
222 if (this.items_ === undefined) | 218 if (this.items_ === undefined) return; |
223 return; | |
224 | 219 |
225 var item = tr.b.math.findClosestElementInSortedArray( | 220 var item = tr.b.math.findClosestElementInSortedArray( |
226 this.items_, | 221 this.items_, |
227 function(x) { return x.start; }, | 222 function(x) { return x.start; }, |
228 worldX, | 223 worldX, |
229 worldMaxDist); | 224 worldMaxDist); |
230 | 225 |
231 if (!item) | 226 if (!item) return; |
232 return; | |
233 | 227 |
234 item.addToSelection(selection); | 228 item.addToSelection(selection); |
235 } | 229 } |
236 }; | 230 }; |
237 | 231 |
238 /** | 232 /** |
239 * A filled dot with a letter inside it. | 233 * A filled dot with a letter inside it. |
240 * | 234 * |
241 * @constructor | 235 * @constructor |
242 * @extends {ProxySelectableItem} | 236 * @extends {ProxySelectableItem} |
243 */ | 237 */ |
244 function LetterDot(modelItem, dotLetter, colorId, start) { | 238 function LetterDot(modelItem, dotLetter, colorId, start) { |
245 tr.model.ProxySelectableItem.call(this, modelItem); | 239 tr.model.ProxySelectableItem.call(this, modelItem); |
246 this.dotLetter = dotLetter; | 240 this.dotLetter = dotLetter; |
247 this.colorId = colorId; | 241 this.colorId = colorId; |
248 this.start = start; | 242 this.start = start; |
249 } | 243 } |
250 | 244 |
251 LetterDot.prototype = { | 245 LetterDot.prototype = { |
252 __proto__: tr.model.ProxySelectableItem.prototype | 246 __proto__: tr.model.ProxySelectableItem.prototype |
253 }; | 247 }; |
254 | 248 |
255 return { | 249 return { |
256 LetterDotTrack, | 250 LetterDotTrack, |
257 LetterDot, | 251 LetterDot, |
258 }; | 252 }; |
259 }); | 253 }); |
260 </script> | 254 </script> |
OLD | NEW |