@@ -457,27 +457,6 @@ class PlotlyGraph extends Component {
457457 } ) ;
458458 }
459459
460- getStyle ( ) {
461- const { responsive} = this . props ;
462- let { style} = this . props ;
463-
464- // When there is no forced responsive style, return the original style property
465- if ( ! responsive ) {
466- return style ;
467- }
468-
469- // Otherwise, if the height is not set, we make the graph size equal to the parent one
470- if ( ! style ) {
471- style = { } ;
472- }
473-
474- if ( ! style . height ) {
475- return Object . assign ( { height : '100%' } , style ) ;
476- }
477-
478- return style ;
479- }
480-
481460 componentDidMount ( ) {
482461 const p = this . plot ( this . props ) ;
483462 this . _queue = this . amendTraces ( p , { } , this . props ) ;
@@ -536,46 +515,33 @@ class PlotlyGraph extends Component {
536515 }
537516
538517 render ( ) {
539- const { className, id, loading_state} = this . props ;
540- const style = this . getStyle ( ) ;
541-
542- if ( window . dash_component_api ) {
543- return (
544- < LoadingElement
545- id = { id }
546- key = { id }
547- className = { className }
548- style = { style }
549- ref = { this . parentElement }
550- >
551- < ResizeDetector
552- onResize = { this . graphResize }
553- targets = { [ this . parentElement , this . gd ] }
554- />
555- < div
556- ref = { this . gd }
557- style = { { height : '100%' , width : '100%' } }
558- />
559- </ LoadingElement >
560- ) ;
518+ const { className, id, loading_state, style = { } } = this . props ;
519+ if ( this . isResponsive ( this . props ) ) {
520+ style . height ||= '100%' ;
561521 }
522+
523+ let Container = LoadingElement ;
524+ const containerProps = {
525+ className,
526+ id,
527+ key : id ,
528+ ref : this . parentElement ,
529+ style,
530+ } ;
531+ if ( ! window . dash_component_api ) {
532+ Container = 'div' ;
533+ containerProps [ 'data-dash-is-loading' ] =
534+ loading_state ?. is_loading || undefined ;
535+ }
536+
562537 return (
563- < div
564- id = { id }
565- key = { id }
566- className = { className }
567- style = { style }
568- ref = { this . parentElement }
569- data-dash-is-loading = {
570- ( loading_state && loading_state . is_loading ) || undefined
571- }
572- >
538+ < Container { ...containerProps } >
573539 < ResizeDetector
574540 onResize = { this . graphResize }
575541 targets = { [ this . parentElement , this . gd ] }
576542 />
577543 < div ref = { this . gd } style = { { height : '100%' , width : '100%' } } />
578- </ div >
544+ </ Container >
579545 ) ;
580546 }
581547}
0 commit comments