1+ import lazyLoadMathJax from '../utils/LazyLoader/mathjax' ;
12import React , { Component } from 'react' ;
23// /build/withPolyfill for IE11 support - https://github.com/maslianok/react-resize-detector/issues/144
34import ResizeDetector from 'react-resize-detector/build/withPolyfill' ;
@@ -144,15 +145,15 @@ class PlotlyGraph extends Component {
144145
145146 plot ( props ) {
146147 let { figure, config} = props ;
147- const { animate, animation_options, responsive} = props ;
148+ const { animate, animation_options, responsive, mathjax } = props ;
148149
149150 const gd = this . gd . current ;
150151 figure = props . _dashprivate_transformFigure ( figure , gd ) ;
151152 config = props . _dashprivate_transformConfig ( config , gd ) ;
152153
153154 const configClone = this . getConfig ( config , responsive ) ;
154155 // add typesetMath | not exposed to the dash API
155- configClone . typesetMath = this . props . mathjax ;
156+ configClone . typesetMath = mathjax ;
156157
157158 const figureClone = {
158159 data : figure . data ,
@@ -180,32 +181,34 @@ class PlotlyGraph extends Component {
180181
181182 gd . classList . add ( 'dash-graph--pending' ) ;
182183
183- return Plotly . react ( gd , figureClone ) . then ( ( ) => {
184- const gd = this . gd . current ;
184+ return lazyLoadMathJax ( mathjax )
185+ . then ( ( ) => Plotly . react ( gd , figureClone ) )
186+ . then ( ( ) => {
187+ const gd = this . gd . current ;
185188
186- // double-check gd hasn't been unmounted
187- if ( ! gd ) {
188- return ;
189- }
189+ // double-check gd hasn't been unmounted
190+ if ( ! gd ) {
191+ return ;
192+ }
190193
191- gd . classList . remove ( 'dash-graph--pending' ) ;
194+ gd . classList . remove ( 'dash-graph--pending' ) ;
192195
193- // in case we've made a new DOM element, transfer events
194- if ( this . _hasPlotted && gd !== this . _prevGd ) {
195- if ( this . _prevGd && this . _prevGd . removeAllListeners ) {
196- this . _prevGd . removeAllListeners ( ) ;
197- Plotly . purge ( this . _prevGd ) ;
196+ // in case we've made a new DOM element, transfer events
197+ if ( this . _hasPlotted && gd !== this . _prevGd ) {
198+ if ( this . _prevGd && this . _prevGd . removeAllListeners ) {
199+ this . _prevGd . removeAllListeners ( ) ;
200+ Plotly . purge ( this . _prevGd ) ;
201+ }
202+ this . _hasPlotted = false ;
198203 }
199- this . _hasPlotted = false ;
200- }
201204
202- if ( ! this . _hasPlotted ) {
203- this . bindEvents ( ) ;
204- this . graphResize ( true ) ;
205- this . _hasPlotted = true ;
206- this . _prevGd = gd ;
207- }
208- } ) ;
205+ if ( ! this . _hasPlotted ) {
206+ this . bindEvents ( ) ;
207+ this . graphResize ( true ) ;
208+ this . _hasPlotted = true ;
209+ this . _prevGd = gd ;
210+ }
211+ } ) ;
209212 }
210213
211214 mergeTraces ( props , dataKey , plotlyFnKey ) {
@@ -430,6 +433,7 @@ class PlotlyGraph extends Component {
430433 return ;
431434 }
432435 if (
436+ this . props . mathjax !== nextProps . mathjax ||
433437 this . props . figure !== nextProps . figure ||
434438 this . props . _dashprivate_transformConfig !==
435439 nextProps . _dashprivate_transformConfig ||
@@ -453,7 +457,10 @@ class PlotlyGraph extends Component {
453457 }
454458
455459 componentDidUpdate ( prevProps ) {
456- if ( prevProps . id !== this . props . id ) {
460+ if (
461+ prevProps . id !== this . props . id ||
462+ prevProps . mathjax !== this . props . mathjax
463+ ) {
457464 this . plot ( this . props ) ;
458465 }
459466 }
0 commit comments