@@ -43,6 +43,8 @@ const getStyles = stylesFactory(() => {
4343 display : flex;
4444 justify-content : center;
4545 align-items : center;
46+ position : absolute;
47+ top : 0 ;
4648 ` ,
4749 } ;
4850} ) ;
@@ -77,8 +79,6 @@ class FlameGraphRenderer extends React.Component {
7779 this . rangeMax = 1 ;
7880 this . query = "" ;
7981 this . panelContainer = document . querySelector ( '.flamegraph-wrapper' ) ?. closest ( '.panel-wrapper' ) ;
80- // const panelContanerResizeObserver = new ResizeObserver(this.resizeHandler);
81- // panelContanerResizeObserver.observe(panelContainer);
8282 window . addEventListener ( "focus" , this . focusHandler ) ;
8383
8484 if ( this . props . shortcut ) {
@@ -89,7 +89,8 @@ class FlameGraphRenderer extends React.Component {
8989 "Reset Flamegraph View"
9090 ) ;
9191 }
92- this . updateFlameBearerData ( )
92+ this . updateFlameBearerData ( ) ;
93+ this . renderCanvas ( ) ;
9394 }
9495
9596 componentDidUpdate ( prevProps , prevState ) {
@@ -126,7 +127,7 @@ class FlameGraphRenderer extends React.Component {
126127 this . setState ( { ...this . state , flamebearer, noData : null } ,
127128 ( ) => {
128129 this . updateData ( ) ;
129- this . forceUpdate ( ) ;
130+ this . renderCanvas ( ) ;
130131 } )
131132 }
132133 }
@@ -252,14 +253,16 @@ class FlameGraphRenderer extends React.Component {
252253 // this is here to debounce resize events (see: https://css-tricks.com/debouncing-throttling-explained-examples/)
253254 // because rendering is expensive
254255 clearTimeout ( this . resizeFinish ) ;
255- let responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . state . flamebearer . levels . length ;
256- this . levelsToShow = this . state . flamebearer . levels . length ;
257- while ( responsiveHeight < 14 ) {
258- this . levelsToShow -= 1 ;
259- responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . levelsToShow ;
256+ if ( this . state . flamebearer ) {
257+ let responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . state . flamebearer . levels . length ;
258+ this . levelsToShow = this . state . flamebearer . levels . length ;
259+ while ( responsiveHeight < 14 ) {
260+ this . levelsToShow -= 1 ;
261+ responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . levelsToShow ;
262+ }
263+ this . pxPerLevel = responsiveHeight > 20 ? 20 : responsiveHeight ;
264+ this . resizeFinish = setTimeout ( this . renderCanvas , 50 ) ;
260265 }
261- this . pxPerLevel = responsiveHeight > 20 ? 20 : responsiveHeight ;
262- this . resizeFinish = setTimeout ( this . renderCanvas , 50 ) ;
263266 } ;
264267
265268 focusHandler = ( ) => {
@@ -288,13 +291,12 @@ class FlameGraphRenderer extends React.Component {
288291 }
289292
290293 const { names, levels, numTicks, sampleRate, units } = this . state ;
291-
292294 this . graphWidth = this . canvas . offsetWidth ;
293295 this . pxPerTick =
294296 this . graphWidth / numTicks / ( this . rangeMax - this . rangeMin ) ;
295297 this . canvas . height = this . pxPerLevel * ( levels . length - this . topLevel ) ;
296298 this . canvas . style . width = '100%' ;
297- this . canvas . style . height = '100 %' ;
299+ this . canvas . style . height = '93 %' ;
298300 this . canvas . width = this . props . width ;
299301 this . canvas . height = this . props . height ;
300302 if ( devicePixelRatio > 1 ) {
@@ -484,10 +486,9 @@ class FlameGraphRenderer extends React.Component {
484486 render = ( ) => {
485487 return (
486488 < >
487- { ! this . state . noData ?
488- < div style = { { height : '100%' } } >
489+ < div style = { { height : '100%' , opacity : this . state . noData ? 0 : 1 } } >
489490 < >
490- < div className = { clsx ( "flamegraph-container panes-wrapper" ) } >
491+ < div className = { clsx ( "flamegraph-container panes-wrapper" ) } style = { { height : '100%' } } >
491492 < div
492493 key = { 'flamegraph-pane' }
493494 className = { this . styles . flamegraphPane }
@@ -496,7 +497,6 @@ class FlameGraphRenderer extends React.Component {
496497 < span className = { this . styles . flamegraphTitle } > Frame width represents { unitsToFlamegraphTitle [ this . state . units ] } </ span >
497498 </ div >
498499 < canvas
499- height = "0"
500500 ref = { this . canvasRef }
501501 onClick = { this . clickHandler }
502502 onMouseMove = { this . mouseMoveHandler }
@@ -514,8 +514,7 @@ class FlameGraphRenderer extends React.Component {
514514 </ div >
515515 </ >
516516 </ div >
517- : < p className = { this . styles . errorMessage } > { this . state . noData } </ p >
518- }
517+ { this . state . noData && < p className = { this . styles . errorMessage } > { this . state . noData } </ p > }
519518 </ >
520519 )
521520 }
0 commit comments