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.VBox}
34 * @param {!WebInspector.TimelineModel} model
36 WebInspector.TimelineOverviewPane = function(model)
38 WebInspector.VBox.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.RecordsCleared, this._reset, this);
51 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowChanged, this._onWindowChanged, this);
54 WebInspector.TimelineOverviewPane.Events = {
55 WindowChanged: "WindowChanged"
58 WebInspector.TimelineOverviewPane.prototype = {
70 * @param {!WebInspector.TimelineOverview} overviewControl
72 setOverviewControl: function(overviewControl)
74 if (this._overviewControl === overviewControl)
77 var windowTimes = null;
79 if (this._overviewControl) {
80 windowTimes = this._overviewControl.windowTimes(this._overviewGrid.windowLeft(), this._overviewGrid.windowRight());
81 this._overviewControl.detach();
83 this._overviewControl = overviewControl;
84 this._overviewControl.show(this._overviewGrid.element);
87 this.requestWindowTimes(windowTimes.startTime, windowTimes.endTime);
92 delete this._refreshTimeout;
94 this._overviewCalculator._setWindow(this._model.minimumRecordTime(), this._model.maximumRecordTime());
95 this._overviewCalculator._setDisplayWindow(0, this._overviewGrid.clientWidth());
96 if (this._overviewControl)
97 this._overviewControl.update();
98 this._overviewGrid.updateDividers(this._overviewCalculator);
99 this._updateEventDividers();
100 this._updateWindow();
103 _updateEventDividers: function()
105 var records = this._eventDividers;
106 this._overviewGrid.removeEventDividers();
108 for (var i = 0; i < records.length; ++i) {
109 var record = records[i];
110 var positions = this._overviewCalculator.computeBarGraphPercentages(record);
111 var dividerPosition = Math.round(positions.start * 10);
112 if (dividers[dividerPosition])
114 var divider = WebInspector.TimelineUIUtils.createEventDivider(record.type);
115 divider.style.left = positions.start + "%";
116 dividers[dividerPosition] = divider;
118 this._overviewGrid.addEventDividers(dividers);
122 * @param {!WebInspector.TimelineModel.Record} record
124 addRecord: function(record)
126 var eventDividers = this._eventDividers;
127 function addEventDividers(record)
129 if (WebInspector.TimelineUIUtils.isEventDivider(record))
130 eventDividers.push(record);
132 WebInspector.TimelineModel.forAllRecords([record], addEventDividers);
133 this._scheduleRefresh();
138 this._overviewCalculator.reset();
139 this._overviewGrid.reset();
140 this._overviewGrid.setResizeEnabled(false);
141 this._eventDividers = [];
142 this._overviewGrid.updateDividers(this._overviewCalculator);
143 if (this._overviewControl)
144 this._overviewControl.reset();
149 * @param {!WebInspector.Event} event
151 _onWindowChanged: function(event)
153 if (this._muteOnWindowChanged)
155 var windowTimes = this._overviewControl.windowTimes(this._overviewGrid.windowLeft(), this._overviewGrid.windowRight());
156 this._windowStartTime = windowTimes.startTime;
157 this._windowEndTime = windowTimes.endTime;
158 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged, windowTimes);
162 * @param {number} startTime
163 * @param {number} endTime
165 requestWindowTimes: function(startTime, endTime)
167 if (startTime === this._windowStartTime && endTime === this._windowEndTime)
169 this._windowStartTime = startTime;
170 this._windowEndTime = endTime;
171 this._updateWindow();
172 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged, { startTime: startTime, endTime: endTime });
175 _updateWindow: function()
177 var windowBoundaries = this._overviewControl.windowBoundaries(this._windowStartTime, this._windowEndTime);
178 this._muteOnWindowChanged = true;
179 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.right);
180 this._overviewGrid.setResizeEnabled(!!this._model.records().length);
181 this._muteOnWindowChanged = false;
184 _scheduleRefresh: function()
186 if (this._refreshTimeout)
188 if (!this.isShowing())
190 this._refreshTimeout = setTimeout(this._update.bind(this), 300);
193 __proto__: WebInspector.VBox.prototype
198 * @implements {WebInspector.TimelineGrid.Calculator}
200 WebInspector.TimelineOverviewCalculator = function()
204 WebInspector.TimelineOverviewCalculator.prototype = {
208 paddingLeft: function()
210 return this._paddingLeft;
214 * @param {number} time
217 computePosition: function(time)
219 return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea + this._paddingLeft;
223 * @return {!{start: number, end: number}}
225 computeBarGraphPercentages: function(record)
227 var start = (record.startTime - this._minimumBoundary) / this.boundarySpan() * 100;
228 var end = (record.endTime - this._minimumBoundary) / this.boundarySpan() * 100;
229 return {start: start, end: end};
233 * @param {number=} minimumRecordTime
234 * @param {number=} maximumRecordTime
236 _setWindow: function(minimumRecordTime, maximumRecordTime)
238 this._minimumBoundary = minimumRecordTime;
239 this._maximumBoundary = maximumRecordTime;
243 * @param {number} paddingLeft
244 * @param {number} clientWidth
246 _setDisplayWindow: function(paddingLeft, clientWidth)
248 this._workingArea = clientWidth - paddingLeft;
249 this._paddingLeft = paddingLeft;
254 this._setWindow(0, 1000);
258 * @param {number} value
259 * @param {number=} precision
262 formatTime: function(value, precision)
264 return Number.preciseMillisToString(value - this.zeroTime(), precision);
270 maximumBoundary: function()
272 return this._maximumBoundary;
278 minimumBoundary: function()
280 return this._minimumBoundary;
288 return this._minimumBoundary;
294 boundarySpan: function()
296 return this._maximumBoundary - this._minimumBoundary;
303 WebInspector.TimelineOverview = function(model)
307 WebInspector.TimelineOverview.prototype = {
309 * @param {?Element} parentElement
310 * @param {!Element=} insertBefore
312 show: function(parentElement, insertBefore) { },
314 update: function() { },
316 reset: function() { },
319 * @param {number} windowLeft
320 * @param {number} windowRight
321 * @return {!{startTime: number, endTime: number}}
323 windowTimes: function(windowLeft, windowRight) { },
326 * @param {number} startTime
327 * @param {number} endTime
328 * @return {!{left: number, right: number}}
330 windowBoundaries: function(startTime, endTime) { }
335 * @extends {WebInspector.VBox}
336 * @implements {WebInspector.TimelineOverview}
337 * @param {!WebInspector.TimelineModel} model
339 WebInspector.TimelineOverviewBase = function(model)
341 WebInspector.VBox.call(this);
344 this._canvas = this.element.createChild("canvas", "fill");
345 this._context = this._canvas.getContext("2d");
348 WebInspector.TimelineOverviewBase.prototype = {
358 timelineStarted: function() { },
359 timelineStopped: function() { },
362 * @param {number} windowLeft
363 * @param {number} windowRight
364 * @return {!{startTime: number, endTime: number}}
366 windowTimes: function(windowLeft, windowRight)
368 var absoluteMin = this._model.minimumRecordTime();
369 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
371 startTime: absoluteMin + timeSpan * windowLeft,
372 endTime: absoluteMin + timeSpan * windowRight
377 * @param {number} startTime
378 * @param {number} endTime
379 * @return {!{left: number, right: number}}
381 windowBoundaries: function(startTime, endTime)
383 var absoluteMin = this._model.minimumRecordTime();
384 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
385 var haveRecords = absoluteMin >= 0;
387 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0,
388 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1
392 resetCanvas: function()
394 this._canvas.width = this.element.clientWidth * window.devicePixelRatio;
395 this._canvas.height = this.element.clientHeight * window.devicePixelRatio;
398 __proto__: WebInspector.VBox.prototype