@@ -32,6 +32,11 @@ const getStyles = stylesFactory(() => {
3232 margin : 0 6px ;
3333 width : 100% ;
3434 ` ,
35+ flamegraphTitle : css `
36+ width : 100% ;
37+ display : block;
38+ text-align : center;
39+ ` ,
3540 } ;
3641} ) ;
3742
@@ -64,9 +69,9 @@ class FlameGraphRenderer extends React.Component {
6469 this . rangeMin = 0 ;
6570 this . rangeMax = 1 ;
6671 this . query = "" ;
67- const panelContainer = document . querySelector ( '.flamegraph-wrapper' ) ?. closest ( '.panel-wrapper' ) ;
68- const panelContanerResizeObserver = new ResizeObserver ( this . resizeHandler ) ;
69- panelContanerResizeObserver . observe ( panelContainer ) ;
72+ this . panelContainer = document . querySelector ( '.flamegraph-wrapper' ) ?. closest ( '.panel-wrapper' ) ;
73+ // const panelContanerResizeObserver = new ResizeObserver(this.resizeHandler);
74+ // panelContanerResizeObserver.observe(panelContainer);
7075 window . addEventListener ( "focus" , this . focusHandler ) ;
7176
7277 if ( this . props . shortcut ) {
@@ -81,14 +86,17 @@ class FlameGraphRenderer extends React.Component {
8186 }
8287
8388 componentDidUpdate ( prevProps , prevState ) {
89+ const name = this . props . data . series [ this . props . data . series . length - 1 ] . name ;
8490 const from = this . props . data ?. timeRange ?. raw . from . valueOf ( ) ;
8591 const until = this . props . data ?. timeRange ?. raw . to . valueOf ( ) ;
92+ const prevName = prevProps . data . series [ prevProps . data . series . length - 1 ] . name ;
8693 const prevFrom = prevProps . data ?. timeRange ?. raw . from . valueOf ( ) ;
8794 const prevUntil = prevProps . data ?. timeRange ?. raw . to . valueOf ( ) ;
88- if ( from !== prevFrom || until !== prevUntil ) {
95+ if ( from !== prevFrom || until !== prevUntil || name !== prevName ) {
8996 this . updateFlameBearerData ( )
9097 }
9198
99+ this . resizeHandler ( ) ;
92100 if (
93101 this . state . flamebearer &&
94102 prevState . flamebearer != this . state . flamebearer
@@ -227,7 +235,12 @@ class FlameGraphRenderer extends React.Component {
227235 // this is here to debounce resize events (see: https://css-tricks.com/debouncing-throttling-explained-examples/)
228236 // because rendering is expensive
229237 clearTimeout ( this . resizeFinish ) ;
230- const responsiveHeight = ( el [ 0 ] . contentRect . height - 60 ) / this . state . flamebearer . levels . length ;
238+ let responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . state . flamebearer . levels . length ;
239+ this . levelsToShow = this . state . flamebearer . levels . length ;
240+ while ( responsiveHeight < 14 ) {
241+ this . levelsToShow -= 1 ;
242+ responsiveHeight = ( this . panelContainer . getClientRects ( ) [ 0 ] . height - 60 ) / this . levelsToShow ;
243+ }
231244 this . pxPerLevel = responsiveHeight > 20 ? 20 : responsiveHeight ;
232245 this . resizeFinish = setTimeout ( this . renderCanvas , 50 ) ;
233246 } ;
@@ -265,8 +278,8 @@ class FlameGraphRenderer extends React.Component {
265278 this . canvas . height = this . pxPerLevel * ( levels . length - this . topLevel ) ;
266279 this . canvas . style . width = '100%' ;
267280 this . canvas . style . height = '100%' ;
268- this . canvas . width = this . canvas . offsetWidth ;
269- this . canvas . height = this . canvas . offsetHeight ;
281+ this . canvas . width = this . props . width ;
282+ this . canvas . height = this . props . height ;
270283 if ( devicePixelRatio > 1 ) {
271284 this . canvas . width *= 2 ;
272285 this . canvas . height *= 2 ;
@@ -279,7 +292,7 @@ class FlameGraphRenderer extends React.Component {
279292
280293 const formatter = this . createFormatter ( ) ;
281294 // i = level
282- for ( let i = 0 ; i < levels . length - this . topLevel ; i ++ ) {
295+ for ( let i = 0 ; i < this . levelsToShow - this . topLevel ; i ++ ) {
283296 const level = levels [ this . topLevel + i ] ;
284297 for ( let j = 0 ; j < level . length ; j += 4 ) {
285298 // j = 0: x start of bar
@@ -460,8 +473,7 @@ class FlameGraphRenderer extends React.Component {
460473 className = { this . styles . flamegraphPane }
461474 >
462475 < div className = 'flamegraph-header' >
463- < span > </ span >
464- < span > Frame width represents { unitsToFlamegraphTitle [ this . state . units ] } </ span >
476+ < span className = { this . styles . flamegraphTitle } > Frame width represents { unitsToFlamegraphTitle [ this . state . units ] } </ span >
465477 </ div >
466478 < canvas
467479 height = "0"
0 commit comments