@@ -5,7 +5,6 @@ import type { TEdge, TNode } from "./types";
55
66const { formatDuration, formatFileSize } = useFormats ( ) ;
77
8-
98const getColorForCallCount = ( callCount : number ) => {
109 if ( callCount <= 1 ) {
1110 return '#fff' ; // Sky Blue for 1 call
@@ -91,7 +90,7 @@ const invertHexColor = (hexInput: string) => {
9190 return ( yiq >= 128 ) ? '#000' : '#fff' ;
9291}
9392const formatValue = ( value : number , metric : string ) : string | number => {
94- const metricFormatMap : Record < string , ( v : number ) => string | number > = {
93+ const metricFormatMap : Record < string , ( v : number ) => string | number > = {
9594 p_mu : ( a : number ) => `${ a } %` ,
9695 p_pmu : ( a : number ) => `${ a } %` ,
9796 p_cpu : ( a : number ) => `${ a } %` ,
@@ -118,28 +117,22 @@ export const prepareData: (
118117 nodes : TNode [ ] ,
119118 edges : TEdge [ ]
120119} ) =
121- ( edges : ProfilerEdges , metric , threshold = 1 , percent = 10 ) => Object . values ( edges )
120+ ( edges : ProfilerEdges , metric , threshold = 1 , percent = 10 ) => Object . values ( edges )
122121 . reduce ( ( arr , edge : ProfilerEdge , index ) => {
123- let nodeColor = '#fff' ;
124- let nodeTextColor = '#000' ;
125- let edgeColor = '#fff' ;
122+ let nodeColor : string = '#fff' ;
123+ let nodeTextColor : string = '#000' ;
124+ let edgeColor : string = '#fff' ;
126125 let edgeLabel : string = edge . cost . ct > 1 ? `${ edge . cost . ct } x` : '' ;
127126
128- if ( metric === GraphTypes . CALLS ) {
129- const metricKey = `ct` ;
130- const isImportantNode : boolean = edge . cost [ metricKey ] >= percent ;
131- if ( ! isImportantNode ) {
132- return arr
133- }
127+ const metricKey : string = metric === GraphTypes . CALLS ? `ct` : `p_${ metric } ` ;
128+ const isImportantNode : boolean = edge . cost [ metricKey ] >= percent ;
129+ if ( ! isImportantNode && edge . cost [ metricKey ] <= threshold ) {
130+ return arr
131+ }
134132
133+ if ( metric === GraphTypes . CALLS ) {
135134 nodeColor = getColorForCallCount ( edge . cost [ metricKey ] ) ;
136135 } else {
137- const metricKey = `p_${ metric } ` ;
138- const isImportantNode : boolean = edge . cost [ metricKey ] >= percent ;
139- if ( ! isImportantNode && edge . cost [ metricKey ] <= threshold ) {
140- return arr
141- }
142-
143136 nodeColor = isImportantNode ? getColorForPercentCount ( edge . cost [ metricKey ] ) : '#fff' ;
144137 nodeTextColor = isImportantNode ? invertHexColor ( nodeColor ) : '#000' ;
145138
@@ -149,31 +142,23 @@ export const prepareData: (
149142 edgeLabel = `${ formatValue ( edge . cost [ metricKey ] , metricKey ) } ${ postfix } ` ;
150143 }
151144
152- const metricKey = `p_${ metric } ` ;
153-
154- const isImportantNode = edge . cost . p_pmu > 10 ;
155-
156- if ( ! isImportantNode && edge . cost [ metricKey ] <= threshold ) {
157- return arr
158- }
159-
160145 arr . nodes . push ( {
161146 data : {
162- id : edge . callee ,
147+ id : edge . id ,
163148 name : edge . callee as string ,
164149 cost : edge . cost ,
165150 color : nodeColor ,
166151 textColor : nodeTextColor
167152 }
168153 } )
169154
170- const hasNodeSource = arr . nodes . find ( node => node . data . id === edge . caller ) ;
155+ const hasNodeSource = arr . nodes . find ( node => node . data . id === edge . parent ) ;
171156
172157 if ( index > 0 && hasNodeSource ) {
173158 arr . edges . push ( {
174159 data : {
175- source : edge . caller || '' ,
176- target : edge . callee ,
160+ source : edge . parent || '' ,
161+ target : edge . id ,
177162 color : edgeColor ,
178163 label : edgeLabel ,
179164 weight : edge . cost . ct ,
0 commit comments