@@ -125,7 +125,10 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
125125 // selection or applying a transform), move the viewport
126126 // vertically so that its offset from the base of the flame graph
127127 // is maintained.
128- if ( prevProps . maxStackDepthPlusOne !== this . props . maxStackDepthPlusOne ) {
128+ if (
129+ ! this . props . isInverted &&
130+ prevProps . maxStackDepthPlusOne !== this . props . maxStackDepthPlusOne
131+ ) {
129132 this . props . viewport . moveViewport (
130133 0 ,
131134 ( prevProps . maxStackDepthPlusOne - this . props . maxStackDepthPlusOne ) *
@@ -151,16 +154,21 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
151154 }
152155
153156 _scrollSelectionIntoView = ( ) => {
154- const { selectedCallNodeIndex, maxStackDepthPlusOne, callNodeInfo } =
155- this . props ;
157+ const {
158+ selectedCallNodeIndex,
159+ maxStackDepthPlusOne,
160+ callNodeInfo,
161+ isInverted,
162+ } = this . props ;
156163
157164 if ( selectedCallNodeIndex === null ) {
158165 return ;
159166 }
160167
161- const callNodeTable = callNodeInfo . getCallNodeTable ( ) ;
162- const depth = callNodeTable . depth [ selectedCallNodeIndex ] ;
163- const y = ( maxStackDepthPlusOne - depth - 1 ) * ROW_HEIGHT ;
168+ const depth = callNodeInfo . depthForNode ( selectedCallNodeIndex ) ;
169+ const y = isInverted
170+ ? depth * ROW_HEIGHT
171+ : ( maxStackDepthPlusOne - depth - 1 ) * ROW_HEIGHT ;
164172
165173 if ( y < this . props . viewport . viewportTop ) {
166174 this . props . viewport . moveViewport ( 0 , this . props . viewport . viewportTop - y ) ;
@@ -192,6 +200,7 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
192200 viewportTop,
193201 viewportBottom,
194202 } ,
203+ isInverted,
195204 } = this . props ;
196205
197206 const { hoveredItem } = hoverInfo ;
@@ -232,14 +241,12 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
232241 fastFillStyle . set ( getBackgroundColor ( ) ) ;
233242 ctx . fillRect ( 0 , 0 , deviceContainerWidth , deviceContainerHeight ) ;
234243
235- const callNodeTable = callNodeInfo . getCallNodeTable ( ) ;
236-
237- const startDepth = Math . floor (
238- maxStackDepthPlusOne - viewportBottom / stackFrameHeight
239- ) ;
240- const endDepth = Math . ceil (
241- maxStackDepthPlusOne - viewportTop / stackFrameHeight
242- ) ;
244+ const startDepth = isInverted
245+ ? Math . floor ( viewportTop / stackFrameHeight )
246+ : Math . floor ( maxStackDepthPlusOne - viewportBottom / stackFrameHeight ) ;
247+ const endDepth = isInverted
248+ ? Math . ceil ( viewportBottom / stackFrameHeight )
249+ : Math . ceil ( maxStackDepthPlusOne - viewportTop / stackFrameHeight ) ;
243250
244251 // Only draw the stack frames that are vertically within view.
245252 // The graph is drawn from bottom to top, in order of increasing depth.
@@ -251,10 +258,12 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
251258 continue ;
252259 }
253260
254- const cssRowTop : CssPixels =
255- ( maxStackDepthPlusOne - depth - 1 ) * ROW_HEIGHT - viewportTop ;
256- const cssRowBottom : CssPixels =
257- ( maxStackDepthPlusOne - depth ) * ROW_HEIGHT - viewportTop ;
261+ const cssRowTop : CssPixels = isInverted
262+ ? depth * ROW_HEIGHT - viewportTop
263+ : ( maxStackDepthPlusOne - depth - 1 ) * ROW_HEIGHT - viewportTop ;
264+ const cssRowBottom : CssPixels = isInverted
265+ ? ( depth + 1 ) * ROW_HEIGHT - viewportTop
266+ : ( maxStackDepthPlusOne - depth ) * ROW_HEIGHT - viewportTop ;
258267 const deviceRowTop : DevicePixels = snap ( cssRowTop * cssToDeviceScale ) ;
259268 const deviceRowBottom : DevicePixels =
260269 snap ( cssRowBottom * cssToDeviceScale ) - 1 ;
@@ -300,7 +309,7 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
300309 i === hoveredItem . flameGraphTimingIndex ;
301310 const isHighlighted = isSelected || isRightClicked || isHovered ;
302311
303- const categoryIndex = callNodeTable . category [ callNodeIndex ] ;
312+ const categoryIndex = callNodeInfo . categoryForNode ( callNodeIndex ) ;
304313 const category = categories [ categoryIndex ] ;
305314 const colorStyles = mapCategoryColorNameToStackChartStyles (
306315 category . color
@@ -322,7 +331,7 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
322331 deviceBoxLeft + deviceHorizontalPadding ;
323332 const deviceTextWidth : DevicePixels = deviceBoxRight - deviceTextLeft ;
324333 if ( deviceTextWidth > textMeasurement . minWidth ) {
325- const funcIndex = callNodeTable . func [ callNodeIndex ] ;
334+ const funcIndex = callNodeInfo . funcForNode ( callNodeIndex ) ;
326335 const funcName = thread . stringTable . getString (
327336 thread . funcTable . name [ funcIndex ]
328337 ) ;
@@ -472,11 +481,12 @@ class FlameGraphCanvasImpl extends React.PureComponent<Props> {
472481 flameGraphTiming,
473482 maxStackDepthPlusOne,
474483 viewport : { viewportTop, containerWidth } ,
484+ isInverted,
475485 } = this . props ;
476486 const pos = x / containerWidth ;
477- const depth = Math . floor (
478- maxStackDepthPlusOne - ( y + viewportTop ) / ROW_HEIGHT
479- ) ;
487+ const depth = isInverted
488+ ? Math . floor ( ( y + viewportTop ) / ROW_HEIGHT )
489+ : Math . floor ( maxStackDepthPlusOne - ( y + viewportTop ) / ROW_HEIGHT ) ;
480490 const stackTiming = flameGraphTiming [ depth ] ;
481491
482492 if ( ! stackTiming ) {
0 commit comments