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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui_lazy/TimelineGrid.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 | « third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
4 * Copyright (C) 2009 Google Inc. All rights reserved. 4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 this.element.appendChild(this._gridHeaderElement); 45 this.element.appendChild(this._gridHeaderElement);
46 }; 46 };
47 47
48 /** 48 /**
49 * @param {!WebInspector.TimelineGrid.Calculator} calculator 49 * @param {!WebInspector.TimelineGrid.Calculator} calculator
50 * @param {number=} freeZoneAtLeft 50 * @param {number=} freeZoneAtLeft
51 * @return {!{offsets: !Array.<number>, precision: number}} 51 * @return {!{offsets: !Array.<number>, precision: number}}
52 */ 52 */
53 WebInspector.TimelineGrid.calculateDividerOffsets = function(calculator, freeZon eAtLeft) 53 WebInspector.TimelineGrid.calculateDividerOffsets = function(calculator, freeZon eAtLeft)
54 { 54 {
55 // TODO(allada) Remove this code out when timeline canvas experiment is over .
56 /** @const */ var minGridSlicePx = 64; // minimal distance between grid line s. 55 /** @const */ var minGridSlicePx = 64; // minimal distance between grid line s.
57 56
58 var clientWidth = calculator.computePosition(calculator.maximumBoundary()); 57 var clientWidth = calculator.computePosition(calculator.maximumBoundary());
59 var dividersCount = clientWidth / minGridSlicePx; 58 var dividersCount = clientWidth / minGridSlicePx;
60 var gridSliceTime = calculator.boundarySpan() / dividersCount; 59 var gridSliceTime = calculator.boundarySpan() / dividersCount;
61 var pixelsPerTime = clientWidth / calculator.boundarySpan(); 60 var pixelsPerTime = clientWidth / calculator.boundarySpan();
62 61
63 // Align gridSliceTime to a nearest round value. 62 // Align gridSliceTime to a nearest round value.
64 // We allow spans that fit into the formula: span = (1|2|5)x10^n, 63 // We allow spans that fit into the formula: span = (1|2|5)x10^n,
65 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ... 64 // e.g.: ... .1 .2 .5 1 2 5 10 20 50 ...
(...skipping 22 matching lines...) Expand all
88 var time = firstDividerTime + gridSliceTime * i; 87 var time = firstDividerTime + gridSliceTime * i;
89 if (calculator.computePosition(time) < freeZoneAtLeft) 88 if (calculator.computePosition(time) < freeZoneAtLeft)
90 continue; 89 continue;
91 offsets.push(time); 90 offsets.push(time);
92 } 91 }
93 92
94 return {offsets: offsets, precision: Math.max(0, -Math.floor(Math.log(gridSl iceTime * 1.01) / Math.LN10))}; 93 return {offsets: offsets, precision: Math.max(0, -Math.floor(Math.log(gridSl iceTime * 1.01) / Math.LN10))};
95 }; 94 };
96 95
97 /** 96 /**
98 * @param {!HTMLCanvasElement} canvas 97 * @param {!CanvasRenderingContext2D} context
99 * @param {!WebInspector.TimelineGrid.Calculator} calculator 98 * @param {!WebInspector.TimelineGrid.Calculator} calculator
99 * @param {number} paddingTop
100 * @param {number=} freeZoneAtLeft
100 */ 101 */
101 WebInspector.TimelineGrid.drawCanvasGrid = function(canvas, calculator) 102 WebInspector.TimelineGrid.drawCanvasGrid = function(context, calculator, padding Top, freeZoneAtLeft)
102 { 103 {
103 var context = canvas.getContext("2d");
104 context.save(); 104 context.save();
105 var ratio = window.devicePixelRatio; 105 var ratio = window.devicePixelRatio;
106 context.scale(ratio, ratio); 106 context.scale(ratio, ratio);
107 var width = canvas.width / window.devicePixelRatio; 107 var width = context.canvas.width / window.devicePixelRatio;
108 var height = canvas.height / window.devicePixelRatio; 108 var height = context.canvas.height / window.devicePixelRatio;
109 var dividersData = WebInspector.TimelineGrid.calculateDividerOffsets(calcula tor); 109 var dividersData = WebInspector.TimelineGrid.calculateDividerOffsets(calcula tor);
110 var dividerOffsets = dividersData.offsets; 110 var dividerOffsets = dividersData.offsets;
111 var precision = dividersData.precision; 111 var precision = dividersData.precision;
112 112
113 context.fillStyle = "rgba(255, 255, 255, 0.5)"; 113 context.fillStyle = "rgba(255, 255, 255, 0.5)";
114 context.fillRect(0, 0, width, 15); 114 context.fillRect(0, 0, width, 15);
115 115
116 context.fillStyle = "#333"; 116 context.fillStyle = "#333";
117 context.strokeStyle = "rgba(0, 0, 0, 0.1)"; 117 context.strokeStyle = "rgba(0, 0, 0, 0.1)";
118 context.textBaseline = "hanging"; 118 context.textBaseline = "hanging";
119 context.font = "11px " + WebInspector.fontFamily(); 119 context.font = "11px " + WebInspector.fontFamily();
120 context.lineWidth = 1; 120 context.lineWidth = 1;
121 121
122 context.translate(0.5, 0.5); 122 context.translate(0.5, 0.5);
123 const paddingRight = 4; 123 const paddingRight = 4;
124 const paddingTop = 3; 124 freeZoneAtLeft = freeZoneAtLeft || 0;
125 for (var i = 0; i < dividerOffsets.length; ++i) { 125 for (var i = 0; i < dividerOffsets.length; ++i) {
126 var time = dividerOffsets[i]; 126 var time = dividerOffsets[i];
127 var position = calculator.computePosition(time); 127 var position = calculator.computePosition(time);
128 var text = calculator.formatValue(time, precision); 128 var text = calculator.formatValue(time, precision);
129 var textWidth = context.measureText(text).width; 129 var textWidth = context.measureText(text).width;
130 var textPosition = position - textWidth - paddingRight; 130 var textPosition = position - textWidth - paddingRight;
131 context.fillText(text, textPosition, paddingTop); 131 if (freeZoneAtLeft < textPosition)
132 context.fillText(text, textPosition, paddingTop);
132 context.moveTo(position, 0); 133 context.moveTo(position, 0);
133 context.lineTo(position, height); 134 context.lineTo(position, height);
134 } 135 }
135 context.stroke(); 136 context.stroke();
136 context.restore(); 137 context.restore();
137 }; 138 };
138 139
139 WebInspector.TimelineGrid.prototype = { 140 WebInspector.TimelineGrid.prototype = {
140 get dividersElement() 141 get dividersElement()
141 { 142 {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 295
295 /** @return {number} */ 296 /** @return {number} */
296 zeroTime: function() { }, 297 zeroTime: function() { },
297 298
298 /** @return {number} */ 299 /** @return {number} */
299 maximumBoundary: function() { }, 300 maximumBoundary: function() { },
300 301
301 /** @return {number} */ 302 /** @return {number} */
302 boundarySpan: function() { } 303 boundarySpan: function() { }
303 }; 304 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui_lazy/FlameChart.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698