2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.View}
34 * @param {!WebInspector.TimelineModel} model
36 WebInspector.TimelineOverviewPane = function(model)
38 WebInspector.View.call(this);
39 this.element.id = "timeline-overview-pane";
41 this._eventDividers = [];
45 this._overviewGrid = new WebInspector.OverviewGrid("timeline");
46 this.element.appendChild(this._overviewGrid.element);
48 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator();
50 model.addEventListener(WebInspector.TimelineModel.Events.RecordAdded, this._onRecordAdded, this);
51 model.addEventListener(WebInspector.TimelineModel.Events.RecordsCleared, this._reset, this);
52 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowChanged, this._onWindowChanged, this);
55 WebInspector.TimelineOverviewPane.Events = {
56 WindowChanged: "WindowChanged"
59 WebInspector.TimelineOverviewPane.prototype = {
71 * @param {!WebInspector.TimelineOverviewBase} overviewControl
73 setOverviewControl: function(overviewControl)
75 if (this._overviewControl === overviewControl)
77 if (this._overviewControl)
78 this._overviewControl.detach();
79 this._overviewControl = overviewControl;
80 this._overviewControl.show(this._overviewGrid.element);
86 delete this._refreshTimeout;
88 this._overviewCalculator.setWindow(this._model.minimumRecordTime(), this._model.maximumRecordTime());
89 this._overviewCalculator.setDisplayWindow(0, this._overviewGrid.clientWidth());
91 if (this._overviewControl)
92 this._overviewControl.update();
93 this._overviewGrid.updateDividers(this._overviewCalculator);
94 this._updateEventDividers();
97 _updateEventDividers: function()
99 var records = this._eventDividers;
100 this._overviewGrid.removeEventDividers();
102 for (var i = 0; i < records.length; ++i) {
103 var record = records[i];
104 var positions = this._overviewCalculator.computeBarGraphPercentages(record);
105 var dividerPosition = Math.round(positions.start * 10);
106 if (dividers[dividerPosition])
108 var divider = WebInspector.TimelinePresentationModel.createEventDivider(record.type);
109 divider.style.left = positions.start + "%";
110 dividers[dividerPosition] = divider;
112 this._overviewGrid.addEventDividers(dividers);
115 _onRecordAdded: function(event)
117 var record = event.data;
118 var eventDividers = this._eventDividers;
119 function addEventDividers(record)
121 if (WebInspector.TimelinePresentationModel.isEventDivider(record))
122 eventDividers.push(record);
124 WebInspector.TimelinePresentationModel.forAllRecords([record], addEventDividers);
125 this._scheduleRefresh();
130 this._overviewCalculator.reset();
131 this._overviewGrid.reset();
132 this._overviewGrid.setResizeEnabled(false);
133 this._eventDividers = [];
134 this._overviewGrid.updateDividers(this._overviewCalculator);
135 if (this._overviewControl)
136 this._overviewControl.reset();
143 windowLeft: function()
145 return this._overviewGrid.windowLeft();
151 windowRight: function()
153 return this._overviewGrid.windowRight();
156 _onWindowChanged: function()
158 if (this._ignoreWindowChangedEvent)
160 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged);
164 * @param {number} left
165 * @param {number} right
167 setWindow: function(left, right)
169 this._ignoreWindowChangedEvent = true;
170 this._overviewGrid.setWindow(left, right);
171 this._overviewGrid.setResizeEnabled(this._model.records.length);
172 this._ignoreWindowChangedEvent = false;
175 _scheduleRefresh: function()
177 if (this._refreshTimeout)
179 if (!this.isShowing())
181 this._refreshTimeout = setTimeout(this._update.bind(this), 300);
184 __proto__: WebInspector.View.prototype
189 * @implements {WebInspector.TimelineGrid.Calculator}
191 WebInspector.TimelineOverviewCalculator = function()
195 WebInspector.TimelineOverviewCalculator.prototype = {
197 * @param {number} time
200 computePosition: function(time)
202 return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea + this.paddingLeft;
206 * @return {!{start: number, end: number}}
208 computeBarGraphPercentages: function(record)
210 var start = (WebInspector.TimelineModel.startTimeInSeconds(record) - this._minimumBoundary) / this.boundarySpan() * 100;
211 var end = (WebInspector.TimelineModel.endTimeInSeconds(record) - this._minimumBoundary) / this.boundarySpan() * 100;
212 return {start: start, end: end};
216 * @param {number=} minimum
217 * @param {number=} maximum
219 setWindow: function(minimum, maximum)
221 this._minimumBoundary = minimum >= 0 ? minimum : undefined;
222 this._maximumBoundary = maximum >= 0 ? maximum : undefined;
226 * @param {number} paddingLeft
227 * @param {number} clientWidth
229 setDisplayWindow: function(paddingLeft, clientWidth)
231 this._workingArea = clientWidth - paddingLeft;
232 this.paddingLeft = paddingLeft;
241 * @param {number} value
242 * @param {boolean=} hires
245 formatTime: function(value, hires)
247 return Number.secondsToString(value, hires);
253 maximumBoundary: function()
255 return this._maximumBoundary;
261 minimumBoundary: function()
263 return this._minimumBoundary;
271 return this._minimumBoundary;
277 boundarySpan: function()
279 return this._maximumBoundary - this._minimumBoundary;
285 * @extends {WebInspector.View}
286 * @param {!WebInspector.TimelineModel} model
288 WebInspector.TimelineOverviewBase = function(model)
290 WebInspector.View.call(this);
293 this._canvas = this.element.createChild("canvas", "fill");
294 this._context = this._canvas.getContext("2d");
297 WebInspector.TimelineOverviewBase.prototype = {
298 update: function() { },
299 reset: function() { },
302 * @param {number} windowLeft
303 * @param {number} windowRight
304 * @return {!{startTime: number, endTime: number}}
306 windowTimes: function(windowLeft, windowRight)
308 var absoluteMin = this._model.minimumRecordTime();
309 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
311 startTime: absoluteMin + timeSpan * windowLeft,
312 endTime: absoluteMin + timeSpan * windowRight
317 * @param {number} startTime
318 * @param {number} endTime
319 * @return {!{left: number, right: number}}
321 windowBoundaries: function(startTime, endTime)
323 var absoluteMin = this._model.minimumRecordTime();
324 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
325 var haveRecords = absoluteMin >= 0;
327 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0,
328 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1
332 resetCanvas: function()
334 this._canvas.width = this.element.clientWidth * window.devicePixelRatio;
335 this._canvas.height = this.element.clientHeight * window.devicePixelRatio;
338 __proto__: WebInspector.View.prototype