From 3c070bee72fac8c1bc2a73f6e2edee3b62f2f09f Mon Sep 17 00:00:00 2001 From: jihea-park Date: Tue, 7 Jan 2025 15:50:50 +0900 Subject: [PATCH] [#noissue] FlameGraph > fix bug & add zoom in/out button' --- .../src/main/v3/apps/web/tsconfig.json | 1 + .../src/components/FlameGraph/FlameGraph.tsx | 41 +++++++++++++++++++ .../src/components/FlameGraph/FlameNode.tsx | 2 + 3 files changed, 44 insertions(+) diff --git a/web-frontend/src/main/v3/apps/web/tsconfig.json b/web-frontend/src/main/v3/apps/web/tsconfig.json index 7704e0d069d3..dad299ad44dd 100644 --- a/web-frontend/src/main/v3/apps/web/tsconfig.json +++ b/web-frontend/src/main/v3/apps/web/tsconfig.json @@ -22,6 +22,7 @@ "@/routes/*": ["routes/*"], "@/utils/*": ["utils/*"], "@/*": ["*"], + "@pinpoint-fe/ui": ["../../../packages/ui/src"], "@pinpoint-fe/ui/*": ["../../../packages/ui/src/*"] } }, diff --git a/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameGraph.tsx b/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameGraph.tsx index 31657034d922..6237f77359c3 100644 --- a/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameGraph.tsx +++ b/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameGraph.tsx @@ -5,6 +5,9 @@ import { FlameNode, FlameNodeType, FlameNodeProps } from './FlameNode'; import { FlameAxis } from './FlameAxis'; import { FlameGraphConfigContext, flameGraphDefaultConfig } from './FlameGraphConfigContext'; import { FlameTimeline } from './FlameTimeline'; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui'; +import { GoZoomIn, GoZoomOut } from 'react-icons/go'; +import { Button } from '../ui'; export interface FlameGraphProps extends Pick, 'customNodeStyle' | 'customTextStyle' | 'onClickNode'> { @@ -34,6 +37,10 @@ export const FlameGraph = ({ const widthRatio = (containerWidth - config.padding.left - config.padding.right) / widthOffset; const [scrollLeft, setScrollLeft] = React.useState(0); + React.useEffect(() => { + setScrollLeft(0); + }, [data]); + React.useEffect(() => { const handleWheel = (event: WheelEvent) => { if (event.metaKey) { @@ -127,8 +134,42 @@ export const FlameGraph = ({ return MaxDepth; } + function handleZoomClick(type: 'in' | 'out') { + setZoom((prevZoom) => { + if (type === 'in') { + return prevZoom + 1; + } + return Math.max(1, prevZoom - 1); + }); + } + return ( + + + +
+ + +
+
+ Zoom In/Out: Command + Scroll +
+
diff --git a/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameNode.tsx b/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameNode.tsx index fcf15bb11bea..7dd7f5afc76a 100644 --- a/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameNode.tsx +++ b/web-frontend/src/main/v3/packages/ui/src/components/FlameGraph/FlameNode.tsx @@ -138,6 +138,8 @@ export const FlameNode = React.memo(FlameNodeComponent) as ( const getEllipsizedText = (text: string, maxWidth = 1, svgRef?: React.RefObject) => { if (!svgRef?.current) return text; + + if (maxWidth <= 0) return null; else { const svg = svgRef.current; const textElement = document.createElementNS('http://www.w3.org/2000/svg', 'text');