3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="stylesheet" href="/tracing/tracks/rect_track.css">
10 <link rel="import" href="/tracing/tracks/heading_track.html">
11 <link rel="import" href="/tracing/fast_rect_renderer.html">
12 <link rel="import" href="/tracing/draw_helpers.html">
13 <link rel="import" href="/base/sorted_array_utils.html">
14 <link rel="import" href="/base/ui.html">
19 tv.exportTo('tracing.tracks', function() {
22 * A track that displays an array of Rect objects.
24 * @extends {HeadingTrack}
26 var RectTrack = tv.ui.define(
27 'rect-track', tracing.tracks.HeadingTrack);
29 RectTrack.prototype = {
31 __proto__: tracing.tracks.HeadingTrack.prototype,
33 decorate: function(viewport) {
34 tracing.tracks.HeadingTrack.prototype.decorate.call(this, viewport);
35 this.classList.add('rect-track');
36 this.asyncStyle_ = false;
41 return this.asyncStyle_;
45 this.asyncStyle_ = !!v;
53 this.rects_ = rects || [];
54 this.invalidateDrawingContainer();
58 return window.getComputedStyle(this).height;
62 this.style.height = height;
63 this.invalidateDrawingContainer();
66 get hasVisibleContent() {
67 return this.rects_.length > 0;
70 addRectToSelection: function(rect, selection) {
71 throw new Error('Not implemented.');
74 draw: function(type, viewLWorld, viewRWorld) {
76 case tracing.tracks.DrawType.SLICE:
77 this.drawRects_(viewLWorld, viewRWorld);
82 drawRects_: function(viewLWorld, viewRWorld) {
83 var ctx = this.context();
86 var bounds = this.getBoundingClientRect();
89 this.viewport.currentDisplayTransform,
97 if (bounds.height <= 6)
100 var fontSize, yOffset;
101 if (bounds.height < 15) {
110 this.viewport.currentDisplayTransform,
119 addEventsToTrackMap: function(eventToTrackMap) {
120 if (this.rects_ === undefined || this.rects_ === null)
123 this.rects_.forEach(function(rect) {
124 eventToTrackMap.addEvent(rect, this);
128 addIntersectingItemsInRangeToSelectionInWorldSpace: function(
129 loWX, hiWX, viewPixWidthWorld, selection) {
130 function onRect(rect) {
131 this.addRectToSelection(rect, selection);
133 onRect = onRect.bind(this);
134 tv.iterateOverIntersectingIntervals(this.rects_,
135 function(x) { return x.start; },
136 function(x) { return x.duration; },
142 * Find the index for the given rect.
143 * @return {index} Index of the given rect, or undefined.
146 indexOfRect_: function(rect) {
147 var index = tv.findLowIndexInSortedArray(this.rects_,
148 function(x) { return x.start; },
150 while (index < this.rects_.length &&
151 rect.start == this.rects_[index].start &&
152 rect.colorId != this.rects_[index].colorId) {
155 return index < this.rects_.length ? index : undefined;
159 * Add the item to the left or right of the provided event, if any, to the
161 * @param {rect} The current rect.
162 * @param {Number} offset Number of rects away from the event to look.
163 * @param {Selection} selection The selection to add an event to,
165 * @return {boolean} Whether an event was found.
168 addItemNearToProvidedEventToSelection: function(event, offset, selection) {
169 var index = this.indexOfRect_(event);
170 if (index === undefined)
173 var newIndex = index + offset;
174 if (newIndex < 0 || newIndex >= this.rects_.length)
177 this.addRectToSelection(this.rects_[newIndex], selection);
181 addAllObjectsMatchingFilterToSelection: function(filter, selection) {
182 for (var i = 0; i < this.rects_.length; ++i) {
183 if (filter.matchSlice(this.rects_[i]))
184 this.addRectToSelection(this.rects_[i], selection);
188 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY,
190 var rect = tv.findClosestIntervalInSortedIntervals(
192 function(x) { return x.start; },
193 function(x) { return x.end; },
198 this.addRectToSelection(rect, selection);