|
@@ -1,4 +1,4 @@
|
|
|
-import * as React from 'react';
|
|
|
+import {useLayoutEffect, useMemo, useRef, useState} from 'react';
|
|
|
import styled from '@emotion/styled';
|
|
|
import {mat3, vec2} from 'gl-matrix';
|
|
|
|
|
@@ -7,14 +7,14 @@ import {getContext, measureText, Rect} from 'sentry/utils/profiling/gl/utils';
|
|
|
import {useDevicePixelRatio} from 'sentry/utils/useDevicePixelRatio';
|
|
|
|
|
|
const useCachedMeasure = (string: string, font: string): Rect => {
|
|
|
- const cache = React.useRef<Record<string, Rect>>({});
|
|
|
- const ctx = React.useMemo(() => {
|
|
|
+ const cache = useRef<Record<string, Rect>>({});
|
|
|
+ const ctx = useMemo(() => {
|
|
|
const context = getContext(document.createElement('canvas'), '2d');
|
|
|
context.font = font;
|
|
|
return context;
|
|
|
}, []);
|
|
|
|
|
|
- return React.useMemo(() => {
|
|
|
+ return useMemo(() => {
|
|
|
if (cache.current[string]) {
|
|
|
return cache.current[string];
|
|
|
}
|
|
@@ -43,7 +43,7 @@ function BoundTooltip({
|
|
|
cursor,
|
|
|
children,
|
|
|
}: BoundTooltipProps): React.ReactElement | null {
|
|
|
- const tooltipRef = React.useRef<HTMLDivElement>(null);
|
|
|
+ const tooltipRef = useRef<HTMLDivElement>(null);
|
|
|
const flamegraphTheme = useFlamegraphTheme();
|
|
|
const tooltipRect = useCachedMeasure(
|
|
|
tooltipRef.current?.textContent ?? '',
|
|
@@ -51,7 +51,7 @@ function BoundTooltip({
|
|
|
);
|
|
|
const devicePixelRatio = useDevicePixelRatio();
|
|
|
|
|
|
- const physicalToLogicalSpace = React.useMemo(
|
|
|
+ const physicalToLogicalSpace = useMemo(
|
|
|
() =>
|
|
|
mat3.fromScaling(
|
|
|
mat3.create(),
|
|
@@ -60,9 +60,9 @@ function BoundTooltip({
|
|
|
[devicePixelRatio]
|
|
|
);
|
|
|
|
|
|
- const [tooltipBounds, setTooltipBounds] = React.useState<Rect>(Rect.Empty());
|
|
|
+ const [tooltipBounds, setTooltipBounds] = useState<Rect>(Rect.Empty());
|
|
|
|
|
|
- React.useLayoutEffect(() => {
|
|
|
+ useLayoutEffect(() => {
|
|
|
if (!children || bounds.isEmpty() || !tooltipRef.current) {
|
|
|
setTooltipBounds(Rect.Empty());
|
|
|
return;
|