1
+ import lazyLoadMathJax from '../utils/LazyLoader/mathjax' ;
1
2
import React , { Component } from 'react' ;
2
3
// /build/withPolyfill for IE11 support - https://github.com/maslianok/react-resize-detector/issues/144
3
4
import ResizeDetector from 'react-resize-detector/build/withPolyfill' ;
@@ -144,15 +145,15 @@ class PlotlyGraph extends Component {
144
145
145
146
plot ( props ) {
146
147
let { figure, config} = props ;
147
- const { animate, animation_options, responsive} = props ;
148
+ const { animate, animation_options, responsive, mathjax } = props ;
148
149
149
150
const gd = this . gd . current ;
150
151
figure = props . _dashprivate_transformFigure ( figure , gd ) ;
151
152
config = props . _dashprivate_transformConfig ( config , gd ) ;
152
153
153
154
const configClone = this . getConfig ( config , responsive ) ;
154
155
// add typesetMath | not exposed to the dash API
155
- configClone . typesetMath = this . props . mathjax ;
156
+ configClone . typesetMath = mathjax ;
156
157
157
158
const figureClone = {
158
159
data : figure . data ,
@@ -180,32 +181,34 @@ class PlotlyGraph extends Component {
180
181
181
182
gd . classList . add ( 'dash-graph--pending' ) ;
182
183
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 ;
185
188
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
+ }
190
193
191
- gd . classList . remove ( 'dash-graph--pending' ) ;
194
+ gd . classList . remove ( 'dash-graph--pending' ) ;
192
195
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 ;
198
203
}
199
- this . _hasPlotted = false ;
200
- }
201
204
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
+ } ) ;
209
212
}
210
213
211
214
mergeTraces ( props , dataKey , plotlyFnKey ) {
@@ -430,6 +433,7 @@ class PlotlyGraph extends Component {
430
433
return ;
431
434
}
432
435
if (
436
+ this . props . mathjax !== nextProps . mathjax ||
433
437
this . props . figure !== nextProps . figure ||
434
438
this . props . _dashprivate_transformConfig !==
435
439
nextProps . _dashprivate_transformConfig ||
@@ -453,7 +457,10 @@ class PlotlyGraph extends Component {
453
457
}
454
458
455
459
componentDidUpdate ( prevProps ) {
456
- if ( prevProps . id !== this . props . id ) {
460
+ if (
461
+ prevProps . id !== this . props . id ||
462
+ prevProps . mathjax !== this . props . mathjax
463
+ ) {
457
464
this . plot ( this . props ) ;
458
465
}
459
466
}
0 commit comments