File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 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');
2424 * Note: separated from the rest of templates because otherwise we get circular
2525 * references due to PlotSchema.
2626 *
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
2828 * should contain a trace array `figure.data`
2929 * and a layout object `figure.layout`
3030 * @returns {object } template: the extracted template - can then be used as
3131 * `layout.template` in another figure.
3232 */
3333exports . makeTemplate = function ( figure ) {
34+ figure = Lib . isPlainObject ( figure ) ? figure : Lib . getGraphDiv ( figure ) ;
3435 figure = Lib . extendDeep ( { _context : dfltConfig } , { data : figure . data , layout : figure . layout } ) ;
3536 Plots . supplyDefaults ( figure ) ;
3637 var data = figure . data || [ ] ;
Original file line number Diff line number Diff line change @@ -170,6 +170,40 @@ describe('makeTemplate', function() {
170170 . then ( destroyGraphDiv )
171171 . then ( done ) ;
172172 } ) ;
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+ } ) ;
173207} ) ;
174208
175209// statics of template application are all covered by the template mock
You can’t perform that action at this time.
0 commit comments