1
- import uFuzzy from '@leeoniya/ufuzzy' ;
2
1
import { RefObject , useCallback , useEffect , useMemo , useState } from 'react' ;
3
2
import color from 'tinycolor2' ;
4
3
@@ -22,8 +21,6 @@ import { ClickedItemData, ColorScheme, ColorSchemeDiff, TextAlign } from '../typ
22
21
import { getBarColorByDiff , getBarColorByPackage , getBarColorByValue } from './colors' ;
23
22
import { CollapseConfig , CollapsedMap , FlameGraphDataContainer , LevelItem } from './dataTransform' ;
24
23
25
- const ufuzzy = new uFuzzy ( ) ;
26
-
27
24
type RenderOptions = {
28
25
canvasRef : RefObject < HTMLCanvasElement > ;
29
26
data : FlameGraphDataContainer ;
@@ -38,7 +35,7 @@ type RenderOptions = {
38
35
rangeMin : number ;
39
36
rangeMax : number ;
40
37
41
- search : string ;
38
+ matchedLabels : Set < string > | undefined ;
42
39
textAlign : TextAlign ;
43
40
44
41
// Total ticks that will be used for sizing
@@ -63,7 +60,7 @@ export function useFlameRender(options: RenderOptions) {
63
60
wrapperWidth,
64
61
rangeMin,
65
62
rangeMax,
66
- search ,
63
+ matchedLabels ,
67
64
textAlign,
68
65
totalViewTicks,
69
66
totalColorTicks,
@@ -72,7 +69,6 @@ export function useFlameRender(options: RenderOptions) {
72
69
focusedItemData,
73
70
collapsedMap,
74
71
} = options ;
75
- const foundLabels = useFoundLabels ( search , data ) ;
76
72
const ctx = useSetupCanvas ( canvasRef , wrapperWidth , depth ) ;
77
73
const theme = useTheme2 ( ) ;
78
74
@@ -92,7 +88,7 @@ export function useFlameRender(options: RenderOptions) {
92
88
mutedColor ,
93
89
rangeMin ,
94
90
rangeMax ,
95
- foundLabels ,
91
+ matchedLabels ,
96
92
focusedItemData ? focusedItemData . item . level : 0
97
93
) ;
98
94
@@ -338,28 +334,6 @@ export function walkTree(
338
334
}
339
335
}
340
336
341
- /**
342
- * Based on the search string it does a fuzzy search over all the unique labels so we can highlight them later.
343
- */
344
- function useFoundLabels ( search : string | undefined , data : FlameGraphDataContainer ) : Set < string > | undefined {
345
- return useMemo ( ( ) => {
346
- if ( search ) {
347
- const foundLabels = new Set < string > ( ) ;
348
- let idxs = ufuzzy . filter ( data . getUniqueLabels ( ) , search ) ;
349
-
350
- if ( idxs ) {
351
- for ( let idx of idxs ) {
352
- foundLabels . add ( data . getUniqueLabels ( ) [ idx ] ) ;
353
- }
354
- }
355
-
356
- return foundLabels ;
357
- }
358
- // In this case undefined means there was no search so no attempt to highlighting anything should be made.
359
- return undefined ;
360
- } , [ search , data ] ) ;
361
- }
362
-
363
337
function useColorFunction (
364
338
totalTicks : number ,
365
339
totalTicksRight : number | undefined ,
@@ -368,13 +342,13 @@ function useColorFunction(
368
342
mutedColor : string ,
369
343
rangeMin : number ,
370
344
rangeMax : number ,
371
- foundNames : Set < string > | undefined ,
345
+ matchedLabels : Set < string > | undefined ,
372
346
topLevel : number
373
347
) {
374
348
return useCallback (
375
349
function getColor ( item : LevelItem , label : string , muted : boolean ) {
376
350
// If collapsed and no search we can quickly return the muted color
377
- if ( muted && ! foundNames ) {
351
+ if ( muted && ! matchedLabels ) {
378
352
// Collapsed are always grayed
379
353
return mutedColor ;
380
354
}
@@ -387,15 +361,15 @@ function useColorFunction(
387
361
? getBarColorByValue ( item . value , totalTicks , rangeMin , rangeMax )
388
362
: getBarColorByPackage ( label , theme ) ;
389
363
390
- if ( foundNames ) {
364
+ if ( matchedLabels ) {
391
365
// Means we are searching, we use color for matches and gray the rest
392
- return foundNames . has ( label ) ? barColor . toHslString ( ) : mutedColor ;
366
+ return matchedLabels . has ( label ) ? barColor . toHslString ( ) : mutedColor ;
393
367
}
394
368
395
369
// Mute if we are above the focused symbol
396
370
return item . level > topLevel - 1 ? barColor . toHslString ( ) : barColor . lighten ( 15 ) . toHslString ( ) ;
397
371
} ,
398
- [ totalTicks , totalTicksRight , colorScheme , theme , rangeMin , rangeMax , foundNames , topLevel , mutedColor ]
372
+ [ totalTicks , totalTicksRight , colorScheme , theme , rangeMin , rangeMax , matchedLabels , topLevel , mutedColor ]
399
373
) ;
400
374
}
401
375
0 commit comments