text.js — react Source File
Architecture documentation for text.js, a javascript file in the react codebase. 2 imports, 7 dependents.
Entity Profile
Dependency Diagram
graph LR 36e23dd7_66ee_74db_1d21_bd0f6eda6351["text.js"] 36e0b331_071d_f14c_1fcc_f0063f6da983["index.js"] 36e23dd7_66ee_74db_1d21_bd0f6eda6351 --> 36e0b331_071d_f14c_1fcc_f0063f6da983 db8b8c96_2cb0_74c3_5863_d0666b28c1f2["constants.js"] 36e23dd7_66ee_74db_1d21_bd0f6eda6351 --> db8b8c96_2cb0_74c3_5863_d0666b28c1f2 7a4811d6_4b12_7e36_64a9_585730c0828a["ComponentMeasuresView.js"] 7a4811d6_4b12_7e36_64a9_585730c0828a --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 1fd6049a_c1a9_88a4_5bc4_ffd26a1b735e["FlamechartView.js"] 1fd6049a_c1a9_88a4_5bc4_ffd26a1b735e --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 168c843f_890f_e881_897f_e7a67afa5d27["NativeEventsView.js"] 168c843f_890f_e881_897f_e7a67afa5d27 --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 0a39a699_8643_0a05_812c_531dd63ee2bd["NetworkMeasuresView.js"] 0a39a699_8643_0a05_812c_531dd63ee2bd --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 ef46acf2_d2bf_7c9f_667a_fdc38c843172["ReactMeasuresView.js"] ef46acf2_d2bf_7c9f_667a_fdc38c843172 --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 64ef9e57_42f1_9ba8_c1bd_b39287b19153["SuspenseEventsView.js"] 64ef9e57_42f1_9ba8_c1bd_b39287b19153 --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 5962a119_fd3e_a8b3_2797_f538b83a1f40["ResizeBarView.js"] 5962a119_fd3e_a8b3_2797_f538b83a1f40 --> 36e23dd7_66ee_74db_1d21_bd0f6eda6351 style 36e23dd7_66ee_74db_1d21_bd0f6eda6351 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {Rect} from '../../view-base';
import {rectEqualToRect} from '../../view-base';
import {COLORS, FONT_SIZE, TEXT_PADDING} from '../constants';
const cachedTextWidths = new Map<string, number>();
export function getTextWidth(
context: CanvasRenderingContext2D,
text: string,
): number {
let measuredWidth = cachedTextWidths.get(text);
if (measuredWidth == null) {
measuredWidth = context.measureText(text).width;
cachedTextWidths.set(text, measuredWidth);
}
return ((measuredWidth: any): number);
}
export function trimText(
context: CanvasRenderingContext2D,
text: string,
width: number,
): string | null {
const maxIndex = text.length - 1;
let startIndex = 0;
let stopIndex = maxIndex;
let longestValidIndex = 0;
let longestValidText = null;
// Trimming long text could be really slow if we decrease only 1 character at a time.
// Trimming with more of a binary search approach is faster in the worst cases.
while (startIndex <= stopIndex) {
const currentIndex = Math.floor((startIndex + stopIndex) / 2);
const trimmedText =
currentIndex === maxIndex ? text : text.slice(0, currentIndex) + '…';
if (getTextWidth(context, trimmedText) <= width) {
if (longestValidIndex < currentIndex) {
longestValidIndex = currentIndex;
longestValidText = trimmedText;
}
startIndex = currentIndex + 1;
} else {
stopIndex = currentIndex - 1;
}
}
// ... (75 more lines)
Domain
Subdomains
Functions
Dependencies
Imported By
- packages/react-devtools-timeline/src/content-views/ComponentMeasuresView.js
- packages/react-devtools-timeline/src/content-views/FlamechartView.js
- packages/react-devtools-timeline/src/content-views/NativeEventsView.js
- packages/react-devtools-timeline/src/content-views/NetworkMeasuresView.js
- packages/react-devtools-timeline/src/content-views/ReactMeasuresView.js
- packages/react-devtools-timeline/src/view-base/resizable/ResizeBarView.js
- packages/react-devtools-timeline/src/content-views/SuspenseEventsView.js
Source
Frequently Asked Questions
What does text.js do?
text.js is a source file in the react codebase, written in javascript. It belongs to the CompilerCore domain, Suppression subdomain.
What functions are defined in text.js?
text.js defines 3 function(s): drawText, getTextWidth, trimText.
What does text.js depend on?
text.js imports 2 module(s): constants.js, index.js.
What files import text.js?
text.js is imported by 7 file(s): ComponentMeasuresView.js, FlamechartView.js, NativeEventsView.js, NetworkMeasuresView.js, ReactMeasuresView.js, ResizeBarView.js, SuspenseEventsView.js.
Where is text.js in the architecture?
text.js is located at packages/react-devtools-timeline/src/content-views/utils/text.js (domain: CompilerCore, subdomain: Suppression, directory: packages/react-devtools-timeline/src/content-views/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free