File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,14 @@ var dfltConfig = require('./plot_config');
24
24
* Note: separated from the rest of templates because otherwise we get circular
25
25
* references due to PlotSchema.
26
26
*
27
- * @param {object|DOM element } figure: The figure to base the template on
27
+ * @param {object|DOM element|string } figure: The figure to base the template on
28
28
* should contain a trace array `figure.data`
29
29
* and a layout object `figure.layout`
30
30
* @returns {object } template: the extracted template - can then be used as
31
31
* `layout.template` in another figure.
32
32
*/
33
33
exports . makeTemplate = function ( figure ) {
34
+ figure = Lib . isPlainObject ( figure ) ? figure : Lib . getGraphDiv ( figure ) ;
34
35
figure = Lib . extendDeep ( { _context : dfltConfig } , { data : figure . data , layout : figure . layout } ) ;
35
36
Plots . supplyDefaults ( figure ) ;
36
37
var data = figure . data || [ ] ;
Original file line number Diff line number Diff line change @@ -170,6 +170,40 @@ describe('makeTemplate', function() {
170
170
. then ( destroyGraphDiv )
171
171
. then ( done ) ;
172
172
} ) ;
173
+
174
+ it ( 'works with div id' , function ( done ) {
175
+ var mock = Lib . extendDeep ( { } , scatterFillMock ) ;
176
+
177
+ var gd = document . createElement ( 'div' ) ;
178
+ gd . id = 'myDiv' ;
179
+ document . body . appendChild ( gd ) ;
180
+
181
+ Plotly . newPlot ( 'myDiv' , mock )
182
+ . then ( function ( ) {
183
+ var template = Plotly . makeTemplate ( 'myDiv' ) ;
184
+ delete ( template . layout . xaxis ) ;
185
+ delete ( template . layout . yaxis ) ;
186
+ expect ( template ) . toEqual ( {
187
+ data : { scatter : [
188
+ { fill : 'tonext' , line : { shape : 'spline' } } ,
189
+ { fill : 'tonext' } ,
190
+ { fill : 'toself' }
191
+ ] } ,
192
+ layout : {
193
+ title : {
194
+ text : 'Fill toself and tonext'
195
+ } ,
196
+ width : 400 ,
197
+ height : 400
198
+ }
199
+ } ) ;
200
+ } )
201
+ . catch ( failTest )
202
+ . then ( function ( ) {
203
+ document . body . removeChild ( gd ) ;
204
+ } )
205
+ . then ( done ) ;
206
+ } ) ;
173
207
} ) ;
174
208
175
209
// statics of template application are all covered by the template mock
You can’t perform that action at this time.
0 commit comments