Skip to content

Commit 216f4cd

Browse files
author
Brian Vaughn
committed
Resize bars show labels now when collapsed
1 parent 16088f2 commit 216f4cd

File tree

5 files changed

+175
-66
lines changed

5 files changed

+175
-66
lines changed

packages/react-devtools-scheduling-profiler/src/CanvasPage.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
157157

158158
function createViewHelper(
159159
view: View,
160+
resizeLabel: string = '',
160161
shouldScrollVertically: boolean = false,
161162
shouldResizeVertically: boolean = false,
162163
): View {
@@ -186,6 +187,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
186187
defaultFrame,
187188
horizontalPanAndZoomView,
188189
canvasRef,
190+
resizeLabel,
189191
);
190192
}
191193

@@ -215,6 +217,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
215217
nativeEventsViewRef.current = nativeEventsView;
216218
const nativeEventsViewWrapper = createViewHelper(
217219
nativeEventsView,
220+
'events',
218221
true,
219222
true,
220223
);
@@ -235,6 +238,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
235238
suspenseEventsViewRef.current = suspenseEventsView;
236239
const suspenseEventsViewWrapper = createViewHelper(
237240
suspenseEventsView,
241+
'suspense',
238242
true,
239243
true,
240244
);
@@ -247,6 +251,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
247251
reactMeasuresViewRef.current = reactMeasuresView;
248252
const reactMeasuresViewWrapper = createViewHelper(
249253
reactMeasuresView,
254+
'react',
250255
true,
251256
true,
252257
);
@@ -258,7 +263,12 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
258263
data.duration,
259264
);
260265
flamechartViewRef.current = flamechartView;
261-
const flamechartViewWrapper = createViewHelper(flamechartView, true, true);
266+
const flamechartViewWrapper = createViewHelper(
267+
flamechartView,
268+
'flamechart',
269+
true,
270+
true,
271+
);
262272

263273
// Root view contains all of the sub views defined above.
264274
// The order we add them below determines their vertical position.

packages/react-devtools-scheduling-profiler/src/content-views/utils/text.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ export function drawText(
4242
fullRect: Rect,
4343
drawableRect: Rect,
4444
availableWidth: number,
45+
textAlign: 'left' | 'center' = 'left',
46+
fillStyle: string = COLORS.TEXT_COLOR,
4547
): void {
4648
if (availableWidth > TEXT_PADDING * 2) {
47-
context.textAlign = 'left';
49+
context.textAlign = textAlign;
4850
context.textBaseline = 'middle';
4951
context.font = `${FONT_SIZE}px sans-serif`;
5052

@@ -57,7 +59,7 @@ export function drawText(
5759
);
5860

5961
if (trimmedName !== null) {
60-
context.fillStyle = COLORS.TEXT_COLOR;
62+
context.fillStyle = fillStyle;
6163

6264
// Prevent text from visibly overflowing its container when clipped.
6365
const textOverflowsViewableArea = !rectEqualToRect(
@@ -77,11 +79,16 @@ export function drawText(
7779
context.clip();
7880
}
7981

80-
context.fillText(
81-
trimmedName,
82-
x + TEXT_PADDING - (x < 0 ? x : 0),
83-
y + fullRect.size.height / 2,
84-
);
82+
let textX;
83+
if (textAlign === 'center') {
84+
textX = x + availableWidth / 2 + TEXT_PADDING - (x < 0 ? x : 0);
85+
} else {
86+
textX = x + TEXT_PADDING - (x < 0 ? x : 0);
87+
}
88+
89+
const textY = y + fullRect.size.height / 2;
90+
91+
context.fillText(trimmedName, textX, textY);
8592

8693
if (textOverflowsViewableArea) {
8794
context.restore();

0 commit comments

Comments
 (0)