@@ -37,6 +37,13 @@ const getStyles = stylesFactory(() => {
3737 display : block;
3838 text-align : center;
3939 ` ,
40+ errorMessage : css `
41+ width : 100% ;
42+ height : 100% ;
43+ display : flex;
44+ justify-content : center;
45+ align-items : center;
46+ ` ,
4047 } ;
4148} ) ;
4249
@@ -86,32 +93,42 @@ class FlameGraphRenderer extends React.Component {
8693 }
8794
8895 componentDidUpdate ( prevProps , prevState ) {
89- const name = this . props . data . series [ this . props . data . series . length - 1 ] . name ;
90- const from = this . props . data ?. timeRange ?. raw . from . valueOf ( ) ;
91- const until = this . props . data ?. timeRange ?. raw . to . valueOf ( ) ;
92- const prevName = prevProps . data . series [ prevProps . data . series . length - 1 ] . name ;
93- const prevFrom = prevProps . data ?. timeRange ?. raw . from . valueOf ( ) ;
94- const prevUntil = prevProps . data ?. timeRange ?. raw . to . valueOf ( ) ;
95- if ( from !== prevFrom || until !== prevUntil || name !== prevName ) {
96- this . updateFlameBearerData ( )
97- }
96+ if ( this . props . data . series && this . props . data . series . length ) {
97+ const name = this . props . data . series [ this . props . data . series . length - 1 ] . name ;
98+ const from = this . props . data ?. timeRange ?. raw . from . valueOf ( ) ;
99+ const until = this . props . data ?. timeRange ?. raw . to . valueOf ( ) ;
100+ const prevName = prevProps . data . series [ prevProps . data . series . length - 1 ] . name ;
101+ const prevFrom = prevProps . data ?. timeRange ?. raw . from . valueOf ( ) ;
102+ const prevUntil = prevProps . data ?. timeRange ?. raw . to . valueOf ( ) ;
103+ if ( from !== prevFrom || until !== prevUntil || name !== prevName ) {
104+ this . updateFlameBearerData ( )
105+ }
98106
99- this . resizeHandler ( ) ;
100- if (
101- this . state . flamebearer &&
102- prevState . flamebearer != this . state . flamebearer
103- ) {
104- this . updateData ( ) ;
107+ this . resizeHandler ( ) ;
108+ if (
109+ this . state . flamebearer &&
110+ prevState . flamebearer != this . state . flamebearer
111+ ) {
112+ this . updateData ( ) ;
113+ }
105114 }
106115 }
107116
108117 updateFlameBearerData ( ) {
109- const flamebearer = this . props . data . series [ this . props . data . series . length - 1 ] . fields [ 0 ] . values . buffer [ 0 ] ;
110- deltaDiff ( flamebearer . levels ) ;
111- this . setState ( { ...this . state , flamebearer } ,
112- ( ) => {
113- this . updateData ( ) ;
114- } )
118+ if ( ! this . props . data . series || ! this . props . data . series . length ) {
119+ this . setState ( { ...this . state , noData : 'No data received: please check datasource plugin settings or connection to pyroscope instance' } ) ;
120+ } else if ( this . props . data . series [ this . props . data . series . length - 1 ] . fields [ 0 ] . values . buffer [ 0 ] . names . length <= 1 ) {
121+ this . setState ( { ...this . state , noData : 'No profiling data received' } ) ;
122+ }
123+ else {
124+ const flamebearer = this . props . data . series [ this . props . data . series . length - 1 ] . fields [ 0 ] . values . buffer [ 0 ] ;
125+ deltaDiff ( flamebearer . levels ) ;
126+ this . setState ( { ...this . state , flamebearer, noData : null } ,
127+ ( ) => {
128+ this . updateData ( ) ;
129+ this . forceUpdate ( ) ;
130+ } )
131+ }
115132 }
116133
117134 paramsToObject ( entries ) {
@@ -466,33 +483,40 @@ class FlameGraphRenderer extends React.Component {
466483
467484 render = ( ) => {
468485 return (
469- < div >
470- < div className = { clsx ( "flamegraph-container panes-wrapper" ) } >
471- < div
472- key = { 'flamegraph-pane' }
473- className = { this . styles . flamegraphPane }
474- >
475- < div className = 'flamegraph-header' >
476- < span className = { this . styles . flamegraphTitle } > Frame width represents { unitsToFlamegraphTitle [ this . state . units ] } </ span >
477- </ div >
478- < canvas
479- height = "0"
480- ref = { this . canvasRef }
481- onClick = { this . clickHandler }
482- onMouseMove = { this . mouseMoveHandler }
483- onMouseOut = { this . mouseOutHandler }
484- />
485- </ div >
486+ < >
487+ { ! this . state . noData ?
488+ < div style = { { height : '100%' } } >
489+ < >
490+ < div className = { clsx ( "flamegraph-container panes-wrapper" ) } >
491+ < div
492+ key = { 'flamegraph-pane' }
493+ className = { this . styles . flamegraphPane }
494+ >
495+ < div className = 'flamegraph-header' >
496+ < span className = { this . styles . flamegraphTitle } > Frame width represents { unitsToFlamegraphTitle [ this . state . units ] } </ span >
497+ </ div >
498+ < canvas
499+ height = "0"
500+ ref = { this . canvasRef }
501+ onClick = { this . clickHandler }
502+ onMouseMove = { this . mouseMoveHandler }
503+ onMouseOut = { this . mouseOutHandler }
504+ />
505+ </ div >
506+ </ div >
507+ < div className = "flamegraph-highlight" style = { this . state . highlightStyle } />
508+ < div
509+ style = { this . state . tooltipStyle }
510+ ref = { this . tooltipRef }
511+ >
512+ < div className = "flamegraph-tooltip-name" > { this . state . tooltipTitle } </ div >
513+ < div > { this . state . tooltipSubtitle } </ div >
514+ </ div >
515+ </ >
486516 </ div >
487- < div className = "flamegraph-highlight" style = { this . state . highlightStyle } />
488- < div
489- style = { this . state . tooltipStyle }
490- ref = { this . tooltipRef }
491- >
492- < div className = "flamegraph-tooltip-name" > { this . state . tooltipTitle } </ div >
493- < div > { this . state . tooltipSubtitle } </ div >
494- </ div >
495- </ div >
517+ : < p className = { this . styles . errorMessage } > { this . state . noData } </ p >
518+ }
519+ </ >
496520 )
497521 }
498522} ;
0 commit comments