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);
52 this._overviewControls = [];
55 WebInspector.TimelineOverviewPane.Events = {
56 WindowChanged: "WindowChanged"
59 WebInspector.TimelineOverviewPane.prototype = {
71 * @param {!Array.<!WebInspector.TimelineOverview>} overviewControls
73 setOverviewControls: function(overviewControls)
75 for (var i = 0; i < this._overviewControls.length; ++i) {
76 var overviewControl = this._overviewControls[i];
77 overviewControl.detach();
78 overviewControl.dispose();
81 for (var i = 0; i < overviewControls.length; ++i) {
82 overviewControls[i].setOverviewGrid(this._overviewGrid);
83 overviewControls[i].show(this._overviewGrid.element);
85 this._overviewControls = overviewControls;
91 delete this._refreshTimeout;
93 this._overviewCalculator._setWindow(this._model.minimumRecordTime(), this._model.maximumRecordTime());
94 this._overviewCalculator._setDisplayWindow(0, this._overviewGrid.clientWidth());
95 for (var i = 0; i < this._overviewControls.length; ++i)
96 this._overviewControls[i].update();
97 this._overviewGrid.updateDividers(this._overviewCalculator);
98 this._updateEventDividers();
102 _updateEventDividers: function()
104 var records = this._eventDividers;
105 this._overviewGrid.removeEventDividers();
107 for (var i = 0; i < records.length; ++i) {
108 var record = records[i];
109 var positions = this._overviewCalculator.computeBarGraphPercentages(record);
110 var dividerPosition = Math.round(positions.start * 10);
111 if (dividers[dividerPosition])
113 var divider = WebInspector.TimelineUIUtils.createEventDivider(record.type());
114 divider.style.left = positions.start + "%";
115 dividers[dividerPosition] = divider;
117 this._overviewGrid.addEventDividers(dividers);
121 * @param {!WebInspector.TimelineModel.Record} record
123 addRecord: function(record)
125 var eventDividers = this._eventDividers;
126 function addEventDividers(record)
128 if (WebInspector.TimelineUIUtils.isEventDivider(record))
129 eventDividers.push(record);
131 WebInspector.TimelineModel.forAllRecords([record], addEventDividers);
132 this._scheduleRefresh();
137 this._overviewCalculator.reset();
138 this._overviewGrid.reset();
139 this._overviewGrid.setResizeEnabled(false);
140 this._eventDividers = [];
141 this._overviewGrid.updateDividers(this._overviewCalculator);
142 for (var i = 0; i < this._overviewControls.length; ++i)
143 this._overviewControls[i].reset();
148 * @param {!WebInspector.Event} event
150 _onWindowChanged: function(event)
152 if (this._muteOnWindowChanged)
154 // Always use first control as a time converter.
155 if (!this._overviewControls.length)
157 var windowTimes = this._overviewControls[0].windowTimes(this._overviewGrid.windowLeft(), this._overviewGrid.windowRight());
158 this._windowStartTime = windowTimes.startTime;
159 this._windowEndTime = windowTimes.endTime;
160 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged, windowTimes);
164 * @param {number} startTime
165 * @param {number} endTime
167 requestWindowTimes: function(startTime, endTime)
169 if (startTime === this._windowStartTime && endTime === this._windowEndTime)
171 this._windowStartTime = startTime;
172 this._windowEndTime = endTime;
173 this._updateWindow();
174 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged, { startTime: startTime, endTime: endTime });
177 _updateWindow: function()
179 if (!this._overviewControls.length)
181 var windowBoundaries = this._overviewControls[0].windowBoundaries(this._windowStartTime, this._windowEndTime);
182 this._muteOnWindowChanged = true;
183 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.right);
184 this._overviewGrid.setResizeEnabled(!!this._model.records().length);
185 this._muteOnWindowChanged = false;
188 _scheduleRefresh: function()
190 if (this._refreshTimeout)
192 if (!this.isShowing())
194 this._refreshTimeout = setTimeout(this.update.bind(this), 300);
197 __proto__: WebInspector.VBox.prototype
202 * @implements {WebInspector.TimelineGrid.Calculator}
204 WebInspector.TimelineOverviewCalculator = function()
208 WebInspector.TimelineOverviewCalculator.prototype = {
212 paddingLeft: function()
214 return this._paddingLeft;
218 * @param {number} time
221 computePosition: function(time)
223 return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea + this._paddingLeft;
227 * @return {!{start: number, end: number}}
229 computeBarGraphPercentages: function(record)
231 var start = (record.startTime() - this._minimumBoundary) / this.boundarySpan() * 100;
232 var end = (record.endTime() - this._minimumBoundary) / this.boundarySpan() * 100;
233 return {start: start, end: end};
237 * @param {number=} minimumRecordTime
238 * @param {number=} maximumRecordTime
240 _setWindow: function(minimumRecordTime, maximumRecordTime)
242 this._minimumBoundary = minimumRecordTime;
243 this._maximumBoundary = maximumRecordTime;
247 * @param {number} paddingLeft
248 * @param {number} clientWidth
250 _setDisplayWindow: function(paddingLeft, clientWidth)
252 this._workingArea = clientWidth - paddingLeft;
253 this._paddingLeft = paddingLeft;
258 this._setWindow(0, 1000);
262 * @param {number} value
263 * @param {number=} precision
266 formatTime: function(value, precision)
268 return Number.preciseMillisToString(value - this.zeroTime(), precision);
274 maximumBoundary: function()
276 return this._maximumBoundary;
282 minimumBoundary: function()
284 return this._minimumBoundary;
292 return this._minimumBoundary;
298 boundarySpan: function()
300 return this._maximumBoundary - this._minimumBoundary;
307 WebInspector.TimelineOverview = function(model)
311 WebInspector.TimelineOverview.prototype = {
313 * @param {?Element} parentElement
314 * @param {!Element=} insertBefore
316 show: function(parentElement, insertBefore) { },
319 * @param {!WebInspector.OverviewGrid} grid
321 setOverviewGrid: function(grid) { },
323 update: function() { },
325 dispose: function() { },
327 reset: function() { },
330 * @param {number} windowLeft
331 * @param {number} windowRight
332 * @return {!{startTime: number, endTime: number}}
334 windowTimes: function(windowLeft, windowRight) { },
337 * @param {number} startTime
338 * @param {number} endTime
339 * @return {!{left: number, right: number}}
341 windowBoundaries: function(startTime, endTime) { },
346 * @extends {WebInspector.VBox}
347 * @implements {WebInspector.TimelineOverview}
348 * @param {!WebInspector.TimelineModel} model
350 WebInspector.TimelineOverviewBase = function(model)
352 WebInspector.VBox.call(this);
355 this._canvas = this.element.createChild("canvas", "fill");
356 this._context = this._canvas.getContext("2d");
359 WebInspector.TimelineOverviewBase.prototype = {
361 * @param {!WebInspector.OverviewGrid} grid
363 setOverviewGrid: function(grid)
380 timelineStarted: function()
384 timelineStopped: function()
389 * @param {number} windowLeft
390 * @param {number} windowRight
391 * @return {!{startTime: number, endTime: number}}
393 windowTimes: function(windowLeft, windowRight)
395 var absoluteMin = this._model.minimumRecordTime();
396 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
398 startTime: absoluteMin + timeSpan * windowLeft,
399 endTime: absoluteMin + timeSpan * windowRight
404 * @param {number} startTime
405 * @param {number} endTime
406 * @return {!{left: number, right: number}}
408 windowBoundaries: function(startTime, endTime)
410 var absoluteMin = this._model.minimumRecordTime();
411 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
412 var haveRecords = absoluteMin >= 0;
414 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0,
415 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1
419 resetCanvas: function()
421 this._canvas.width = this.element.clientWidth * window.devicePixelRatio;
422 this._canvas.height = this.element.clientHeight * window.devicePixelRatio;
425 __proto__: WebInspector.VBox.prototype