Skip to content

Commit 12d2fc7

Browse files
author
Brian Vaughn
committed
Slight tweaking of UI code
1 parent 19047a9 commit 12d2fc7

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,21 @@ export class ReactMeasuresView extends View {
242242
}
243243

244244
// Render lane labels
245-
const labelRect = {
246-
origin: {
247-
x: visibleArea.origin.x,
248-
y: baseY,
249-
},
250-
size: {
251-
width: visibleArea.size.width,
252-
height: REACT_LANE_HEIGHT,
253-
},
254-
};
255245
const label = this._profilerData.laneToLabelMap.get(lane);
256246
if (label == null) {
257247
console.warn(`Could not find label for lane ${lane}.`);
258248
} else {
249+
const labelRect = {
250+
origin: {
251+
x: visibleArea.origin.x,
252+
y: baseY,
253+
},
254+
size: {
255+
width: visibleArea.size.width,
256+
height: REACT_LANE_HEIGHT,
257+
},
258+
};
259+
259260
drawText(label, context, labelRect, visibleArea, {
260261
fillStyle: COLORS.TEXT_DIM_COLOR,
261262
});

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ import {COLORS, FONT_SIZE, TEXT_PADDING} from '../constants';
1414

1515
const cachedTextWidths = new Map();
1616

17+
export function getTextWidth(
18+
context: CanvasRenderingContext2D,
19+
text: string,
20+
): number {
21+
let measuredWidth = cachedTextWidths.get(text);
22+
if (measuredWidth == null) {
23+
measuredWidth = context.measureText(text).width;
24+
cachedTextWidths.set(text, measuredWidth);
25+
}
26+
27+
return ((measuredWidth: any): number);
28+
}
29+
1730
export function trimText(
1831
context: CanvasRenderingContext2D,
1932
text: string,
@@ -22,13 +35,7 @@ export function trimText(
2235
for (let i = text.length - 1; i >= 0; i--) {
2336
const trimmedText = i === text.length - 1 ? text : text.substr(0, i) + '…';
2437

25-
let measuredWidth = cachedTextWidths.get(trimmedText);
26-
if (measuredWidth == null) {
27-
measuredWidth = context.measureText(trimmedText).width;
28-
cachedTextWidths.set(trimmedText, measuredWidth);
29-
}
30-
31-
if (measuredWidth <= width) {
38+
if (getTextWidth(context, text) <= width) {
3239
return trimmedText;
3340
}
3441
}

0 commit comments

Comments
 (0)