Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network/NetworkTimelineColumn.js

Issue 2470523003: [Devtools] Fixed dividers in new network canvas timeline (Closed)
Patch Set: Merge branch 'master' into NETWORK_TIMELINE_FIX_DIVIDERS Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.VBox} 7 * @extends {WebInspector.VBox}
8 * @param {number} rowHeight 8 * @param {number} rowHeight
9 * @param {!WebInspector.NetworkTimeCalculator} calculator 9 * @param {!WebInspector.NetworkTimeCalculator} calculator
10 */ 10 */
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 { 231 {
232 WebInspector.VBox.prototype.onResize.call(this); 232 WebInspector.VBox.prototype.onResize.call(this);
233 this._calculateCanvasSize(); 233 this._calculateCanvasSize();
234 this.scheduleDraw(); 234 this.scheduleDraw();
235 }, 235 },
236 236
237 _calculateCanvasSize: function() 237 _calculateCanvasSize: function()
238 { 238 {
239 this._offsetWidth = this.contentElement.offsetWidth - this._rightPadding ; 239 this._offsetWidth = this.contentElement.offsetWidth - this._rightPadding ;
240 this._offsetHeight = this.contentElement.offsetHeight; 240 this._offsetHeight = this.contentElement.offsetHeight;
241 this._calculator.setDisplayWindow(this._offsetWidth);
241 this._canvasPosition = this._canvas.getBoundingClientRect(); 242 this._canvasPosition = this._canvas.getBoundingClientRect();
242 }, 243 },
243 244
244 /** 245 /**
245 * @param {!WebInspector.RequestTimeRangeNames} type 246 * @param {!WebInspector.RequestTimeRangeNames} type
246 * @return {string} 247 * @return {string}
247 */ 248 */
248 _colorForType: function(type) 249 _colorForType: function(type)
249 { 250 {
250 var types = WebInspector.RequestTimeRangeNames; 251 var types = WebInspector.RequestTimeRangeNames;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel); 287 return Math.floor(this._leftPadding + (time - this._startTime) * timeToP ixel);
287 }, 288 },
288 289
289 _draw: function() 290 _draw: function()
290 { 291 {
291 var useTimingBars = !WebInspector.moduleSetting("networkColorCodeResourc eTypes").get() && !this._calculator.startAtZero; 292 var useTimingBars = !WebInspector.moduleSetting("networkColorCodeResourc eTypes").get() && !this._calculator.startAtZero;
292 var requests = this._requestData; 293 var requests = this._requestData;
293 var context = this._canvas.getContext("2d"); 294 var context = this._canvas.getContext("2d");
294 context.save(); 295 context.save();
295 context.scale(window.devicePixelRatio, window.devicePixelRatio); 296 context.scale(window.devicePixelRatio, window.devicePixelRatio);
296 context.save();
297 context.translate(0, this._headerHeight); 297 context.translate(0, this._headerHeight);
298 context.rect(0, 0, this._offsetWidth, this._offsetHeight); 298 context.rect(0, 0, this._offsetWidth, this._offsetHeight);
299 context.clip(); 299 context.clip();
300 var firstRequestIndex = Math.floor(this._scrollTop / this._rowHeight); 300 var firstRequestIndex = Math.floor(this._scrollTop / this._rowHeight);
301 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight)); 301 var lastRequestIndex = Math.min(requests.length, firstRequestIndex + Mat h.ceil(this._offsetHeight / this._rowHeight));
302 for (var i = firstRequestIndex; i < lastRequestIndex; i++) { 302 for (var i = firstRequestIndex; i < lastRequestIndex; i++) {
303 var rowOffset = this._rowHeight * i; 303 var rowOffset = this._rowHeight * i;
304 var request = requests[i]; 304 var request = requests[i];
305 this._decorateRow(context, request, i, rowOffset - this._scrollTop); 305 this._decorateRow(context, request, i, rowOffset - this._scrollTop);
306 if (useTimingBars) 306 if (useTimingBars)
307 this._drawTimingBars(context, request, rowOffset - this._scrollT op); 307 this._drawTimingBars(context, request, rowOffset - this._scrollT op);
308 else 308 else
309 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop); 309 this._drawSimplifiedBars(context, request, rowOffset - this._scr ollTop);
310 } 310 }
311 this._drawEventDividers(context); 311 this._drawEventDividers(context);
312 context.restore(); 312 context.restore();
313 // This is outside of the save/restore above because it must draw in hea der. 313
314 this._drawDividers(context); 314 const freeZoneAtLeft = 75;
315 context.restore(); 315 WebInspector.TimelineGrid.drawCanvasGrid(context, this._calculator, this ._fontSize, freeZoneAtLeft);
316 }, 316 },
317 317
318 /** 318 /**
319 * @param {!CanvasRenderingContext2D} context 319 * @param {!CanvasRenderingContext2D} context
320 */ 320 */
321 _drawEventDividers: function(context) 321 _drawEventDividers: function(context)
322 { 322 {
323 context.save(); 323 context.save();
324 context.lineWidth = 1; 324 context.lineWidth = 1;
325 for (var color of this._eventDividers.keys()) { 325 for (var color of this._eventDividers.keys()) {
326 context.strokeStyle = color; 326 context.strokeStyle = color;
327 for (var time of this._eventDividers.get(color)) { 327 for (var time of this._eventDividers.get(color)) {
328 context.beginPath(); 328 context.beginPath();
329 var x = this._timeToPosition(time); 329 var x = this._timeToPosition(time);
330 context.moveTo(x, 0); 330 context.moveTo(x, 0);
331 context.lineTo(x, this._offsetHeight); 331 context.lineTo(x, this._offsetHeight);
332 } 332 }
333 context.stroke(); 333 context.stroke();
334 } 334 }
335 context.restore(); 335 context.restore();
336 }, 336 },
337 337
338 /** 338 /**
339 * @param {!CanvasRenderingContext2D} context
340 */
341 _drawDividers: function(context)
342 {
343 context.save();
344 /** @const */
345 var minGridSlicePx = 64; // minimal distance between grid lines.
346
347 var drawableWidth = this._offsetWidth - this._leftPadding;
348 var timelineDuration = this._timelineDuration();
349 var dividersCount = drawableWidth / minGridSlicePx;
350 var gridSliceTime = timelineDuration / dividersCount;
351 var pixelsPerTime = drawableWidth / timelineDuration;
352
353 // Align gridSliceTime to a nearest round value.
354 // We allow spans that fit into the formula: span = (1|2|5)x10^n,
355 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ...
356 // After a span has been chosen make grid lines at multiples of the span .
357
358 var logGridSliceTime = Math.ceil(Math.log(gridSliceTime) / Math.LN10);
359 gridSliceTime = Math.pow(10, logGridSliceTime);
360 if (gridSliceTime * pixelsPerTime >= 5 * minGridSlicePx)
361 gridSliceTime = gridSliceTime / 5;
362 if (gridSliceTime * pixelsPerTime >= 2 * minGridSlicePx)
363 gridSliceTime = gridSliceTime / 2;
364
365 context.lineWidth = 1;
366 context.strokeStyle = "rgba(0, 0, 0, .1)";
367 context.font = this._fontSize + "px sans-serif";
368 context.fillStyle = "#444";
369 gridSliceTime = gridSliceTime;
370 for (var position = gridSliceTime * pixelsPerTime; position < drawableWi dth; position += gridSliceTime * pixelsPerTime) {
371 // Added .5 because canvas drawing points are between pixels.
372 var drawPosition = Math.floor(position) + this._leftPadding + .5;
373 context.beginPath();
374 context.moveTo(drawPosition, 0);
375 context.lineTo(drawPosition, this._offsetHeight);
376 context.stroke();
377 if (position <= gridSliceTime * pixelsPerTime)
378 continue;
379 var textData = Number.secondsToString(position / pixelsPerTime);
380 context.fillText(textData, drawPosition - context.measureText(textDa ta).width - 2, Math.floor(this._headerHeight - this._fontSize / 2));
381 }
382 context.restore();
383 },
384
385 /**
386 * @return {number} 339 * @return {number}
387 */ 340 */
388 _timelineDuration: function() 341 _timelineDuration: function()
389 { 342 {
390 return this._calculator.maximumBoundary() - this._calculator.minimumBoun dary(); 343 return this._calculator.maximumBoundary() - this._calculator.minimumBoun dary();
391 }, 344 },
392 345
393 /** 346 /**
394 * @param {!WebInspector.RequestTimeRangeNames=} type 347 * @param {!WebInspector.RequestTimeRangeNames=} type
395 * @return {number} 348 * @return {number}
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 color = this._rowNavigationRequestColor; 566 color = this._rowNavigationRequestColor;
614 567
615 context.fillStyle = color; 568 context.fillStyle = color;
616 context.rect(0, y, this._offsetWidth, this._rowHeight); 569 context.rect(0, y, this._offsetWidth, this._rowHeight);
617 context.fill(); 570 context.fill();
618 context.restore(); 571 context.restore();
619 }, 572 },
620 573
621 __proto__: WebInspector.VBox.prototype 574 __proto__: WebInspector.VBox.prototype
622 }; 575 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698