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)
78 var windowTimes = null;
80 if (this._overviewControl) {
81 windowTimes = this._overviewControl.windowTimes(this._overviewGrid.windowLeft(), this._overviewGrid.windowRight());
82 this._overviewControl.detach();
84 this._overviewControl = overviewControl;
85 this._overviewControl.show(this._overviewGrid.element);
88 this.setWindowTimes(windowTimes.startTime, windowTimes.endTime);
93 delete this._refreshTimeout;
95 this._overviewCalculator.setWindow(this._model.minimumRecordTime(), this._model.maximumRecordTime());
96 this._overviewCalculator.setDisplayWindow(0, this._overviewGrid.clientWidth());
98 if (this._overviewControl)
99 this._overviewControl.update();
100 this._overviewGrid.updateDividers(this._overviewCalculator);
101 this._updateEventDividers();
104 _updateEventDividers: function()
106 var records = this._eventDividers;
107 this._overviewGrid.removeEventDividers();
109 for (var i = 0; i < records.length; ++i) {
110 var record = records[i];
111 var positions = this._overviewCalculator.computeBarGraphPercentages(record);
112 var dividerPosition = Math.round(positions.start * 10);
113 if (dividers[dividerPosition])
115 var divider = WebInspector.TimelinePresentationModel.createEventDivider(record.type);
116 divider.style.left = positions.start + "%";
117 dividers[dividerPosition] = divider;
119 this._overviewGrid.addEventDividers(dividers);
122 _onRecordAdded: function(event)
124 var record = event.data;
125 var eventDividers = this._eventDividers;
126 function addEventDividers(record)
128 if (WebInspector.TimelinePresentationModel.isEventDivider(record))
129 eventDividers.push(record);
131 WebInspector.TimelinePresentationModel.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 if (this._overviewControl)
143 this._overviewControl.reset();
148 * @param {!WebInspector.Event} event
150 _onWindowChanged: function(event)
152 if (this._ignoreWindowChangedEvent)
154 var windowTimes = this._overviewControl.windowTimes(this._overviewGrid.windowLeft(), this._overviewGrid.windowRight());
155 this._windowStartTime = windowTimes.startTime;
156 this._windowEndTime = windowTimes.endTime;
157 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.WindowChanged, windowTimes);
161 * @param {number} startTime
162 * @param {number} endTime
164 setWindowTimes: function(startTime, endTime)
166 this._windowStartTime = startTime;
167 this._windowEndTime = endTime;
168 this._updateWindow();
171 _updateWindow: function()
173 var windowBoundaries = this._overviewControl.windowBoundaries(this._windowStartTime, this._windowEndTime);
174 this._ignoreWindowChangedEvent = true;
175 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.right);
176 this._overviewGrid.setResizeEnabled(this._model.records.length);
177 this._ignoreWindowChangedEvent = false;
180 _scheduleRefresh: function()
182 if (this._refreshTimeout)
184 if (!this.isShowing())
186 this._refreshTimeout = setTimeout(this._update.bind(this), 300);
189 __proto__: WebInspector.View.prototype
194 * @implements {WebInspector.TimelineGrid.Calculator}
196 WebInspector.TimelineOverviewCalculator = function()
200 WebInspector.TimelineOverviewCalculator.prototype = {
202 * @param {number} time
205 computePosition: function(time)
207 return (time - this._minimumBoundary) / this.boundarySpan() * this._workingArea + this.paddingLeft;
211 * @return {!{start: number, end: number}}
213 computeBarGraphPercentages: function(record)
215 var start = (WebInspector.TimelineModel.startTimeInSeconds(record) - this._minimumBoundary) / this.boundarySpan() * 100;
216 var end = (WebInspector.TimelineModel.endTimeInSeconds(record) - this._minimumBoundary) / this.boundarySpan() * 100;
217 return {start: start, end: end};
221 * @param {number=} minimum
222 * @param {number=} maximum
224 setWindow: function(minimum, maximum)
226 this._minimumBoundary = minimum >= 0 ? minimum : undefined;
227 this._maximumBoundary = maximum >= 0 ? maximum : undefined;
231 * @param {number} paddingLeft
232 * @param {number} clientWidth
234 setDisplayWindow: function(paddingLeft, clientWidth)
236 this._workingArea = clientWidth - paddingLeft;
237 this.paddingLeft = paddingLeft;
246 * @param {number} value
247 * @param {boolean=} hires
250 formatTime: function(value, hires)
252 return Number.secondsToString(value, hires);
258 maximumBoundary: function()
260 return this._maximumBoundary;
266 minimumBoundary: function()
268 return this._minimumBoundary;
276 return this._minimumBoundary;
282 boundarySpan: function()
284 return this._maximumBoundary - this._minimumBoundary;
290 * @extends {WebInspector.View}
291 * @param {!WebInspector.TimelineModel} model
293 WebInspector.TimelineOverviewBase = function(model)
295 WebInspector.View.call(this);
298 this._canvas = this.element.createChild("canvas", "fill");
299 this._context = this._canvas.getContext("2d");
302 WebInspector.TimelineOverviewBase.prototype = {
303 update: function() { },
304 reset: function() { },
307 * @param {number} windowLeft
308 * @param {number} windowRight
309 * @return {!{startTime: number, endTime: number}}
311 windowTimes: function(windowLeft, windowRight)
313 var absoluteMin = this._model.minimumRecordTime();
314 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
316 startTime: absoluteMin + timeSpan * windowLeft,
317 endTime: absoluteMin + timeSpan * windowRight
322 * @param {number} startTime
323 * @param {number} endTime
324 * @return {!{left: number, right: number}}
326 windowBoundaries: function(startTime, endTime)
328 var absoluteMin = this._model.minimumRecordTime();
329 var timeSpan = this._model.maximumRecordTime() - absoluteMin;
330 var haveRecords = absoluteMin >= 0;
332 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0,
333 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1
337 resetCanvas: function()
339 this._canvas.width = this.element.clientWidth * window.devicePixelRatio;
340 this._canvas.height = this.element.clientHeight * window.devicePixelRatio;
343 __proto__: WebInspector.View.prototype