@@ -34,35 +34,44 @@ interface IPlotlySpec {
34
34
}
35
35
36
36
export class RenderedPlotly extends Widget implements IRenderMime . IRenderer {
37
+ render_target : HTMLElement ;
37
38
/**
38
39
* Create a new widget for rendering Plotly.
39
40
*/
40
41
constructor ( options : IRenderMime . IRendererOptions ) {
41
42
super ( ) ;
42
- this . addClass ( CSS_CLASS ) ;
43
43
this . _mimeType = options . mimeType ;
44
44
}
45
45
46
46
/**
47
47
* Render Plotly into this widget's node.
48
48
*/
49
49
renderModel ( model : IRenderMime . IMimeModel ) : Promise < void > {
50
- const { data, layout, frames, config } = model . data [ this . _mimeType ] as
51
- | any
52
- | IPlotlySpec ;
50
+ const { data, layout, frames, config, div_id } = model . data [
51
+ this . _mimeType
52
+ ] as any | IPlotlySpec ;
53
53
// const metadata = model.metadata[this._mimeType] as any || {};
54
- return Plotly . react ( this . node , data , layout , config ) . then ( plot => {
54
+ if ( div_id == null ) {
55
+ this . render_target = this . node ;
56
+ this . addClass ( CSS_CLASS ) ;
57
+ } else {
58
+ this . render_target = document . getElementById ( div_id ) ;
59
+ }
60
+ return Plotly . react ( this . render_target , data , layout , config ) . then ( plot => {
55
61
this . update ( ) ;
56
62
if ( frames ) {
57
- Plotly . addFrames ( this . node , frames ) . then ( ( ) => {
58
- Plotly . animate ( this . node ) ;
63
+ Plotly . addFrames ( this . render_target , frames ) . then ( ( ) => {
64
+ Plotly . animate ( this . render_target ) ;
59
65
} ) ;
60
66
}
61
- if ( this . node . offsetWidth > 0 && this . node . offsetHeight > 0 ) {
67
+ if (
68
+ this . render_target . offsetWidth > 0 &&
69
+ this . render_target . offsetHeight > 0
70
+ ) {
62
71
Plotly . toImage ( plot , {
63
72
format : 'png' ,
64
- width : this . node . offsetWidth ,
65
- height : this . node . offsetHeight
73
+ width : this . render_target . offsetWidth ,
74
+ height : this . render_target . offsetHeight
66
75
} ) . then ( ( url : string ) => {
67
76
const imageData = url . split ( ',' ) [ 1 ] ;
68
77
if ( model . data [ 'image/png' ] !== imageData ) {
@@ -97,8 +106,8 @@ export class RenderedPlotly extends Widget implements IRenderMime.IRenderer {
97
106
*/
98
107
protected onUpdateRequest ( msg : Message ) : void {
99
108
if ( this . isVisible ) {
100
- Plotly . redraw ( this . node ) . then ( ( ) => {
101
- Plotly . Plots . resize ( this . node ) ;
109
+ Plotly . redraw ( this . render_target ) . then ( ( ) => {
110
+ Plotly . Plots . resize ( this . render_target ) ;
102
111
} ) ;
103
112
}
104
113
}
0 commit comments