Skip to content

Commit 8f3430d

Browse files
committed
scroll correctly for reverse flamegraphs
commit_hash:230e3533185c184110a3f2608ab3caec9fe8c98a
1 parent 85a4ebb commit 8f3430d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

perforator/ui/packages/flamegraph/lib/components/Flamegraph/Flamegraph.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const Flamegraph: React.FC<FlamegraphProps> = ({
103103
const isDiffSwitchingSupported = profileData.meta.version > 1;
104104
const [shouldTrim, setShouldTrim] = React.useState(false);
105105
const shouldOmitHighlight = React.useRef(true);
106-
106+
const shouldScroll = React.useRef(false);
107107
const setQuery = React.useCallback<SetStateFromQuery<QueryKeys>>((q) => {
108108
outerSetQuery(q);
109109
shouldOmitHighlight.current = true;
@@ -187,6 +187,7 @@ export const Flamegraph: React.FC<FlamegraphProps> = ({
187187
// by default, we show highlight, e.g. after clicks
188188
// and don't show it only on first render
189189
disableHighlightRender: shouldOmitHighlight.current,
190+
shouldScroll: shouldScroll.current,
190191
scrollParent: useSelfAsScrollParent ? flamegraphContainer.current : document.documentElement,
191192
};
192193

@@ -197,6 +198,9 @@ export const Flamegraph: React.FC<FlamegraphProps> = ({
197198
shouldOmitHighlight.current = false;
198199
}
199200

201+
if (!shouldScroll.current) {
202+
shouldScroll.current = true;
203+
}
200204
return () => {
201205
destructor();
202206
shouldOmitHighlight.current = true;

perforator/ui/packages/flamegraph/lib/renderer.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type RenderFlamegraphOptions = {
6363
reverse: boolean;
6464
keepOnlyFound: boolean;
6565
disableHighlightRender: boolean;
66+
shouldScroll: boolean;
6667
scrollParent: HTMLElement;
6768
}
6869

@@ -481,7 +482,20 @@ export const renderFlamegraph: RenderFlamegraphType = (
481482
flamegraphContainer,
482483
profileData,
483484
fg,
484-
{ getState, setState, theme, isDiff, onFinishRendering, shortenFrameTexts, excludeSearchPattern, searchPattern, reverse, keepOnlyFound, disableHighlightRender, scrollParent },
485+
{
486+
getState, setState,
487+
theme,
488+
isDiff,
489+
onFinishRendering,
490+
shortenFrameTexts,
491+
excludeSearchPattern,
492+
searchPattern,
493+
reverse,
494+
keepOnlyFound,
495+
disableHighlightRender,
496+
scrollParent,
497+
shouldScroll,
498+
},
485499
) => {
486500
const shouldSwapDiff = getState('flameBase') === 'diff';
487501

@@ -902,7 +916,7 @@ export const renderFlamegraph: RenderFlamegraphType = (
902916

903917
{
904918
const layerCount = fg.prerenderOffsets(canvasWidth!, [h, pos], omittedStacks, foundCoords, shouldSwapDiff);
905-
initCanvasVertical(layerCount, !reverse && !disableHighlightRender, scrollParent);
919+
initCanvasVertical(layerCount, !reverse && shouldScroll, scrollParent);
906920
}
907921
render({ pattern: searchPattern });
908922
if (!disableHighlightRender) {

0 commit comments

Comments
 (0)