Skip to content

Commit 9899230

Browse files
authored
Merge pull request #3111 from plotly/dom-layout
support dom element as argument to Plotly.makeTemplate
2 parents c922c61 + eb6a2e8 commit 9899230

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/plot_api/template_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var dfltConfig = require('./plot_config');
3131
* `layout.template` in another figure.
3232
*/
3333
exports.makeTemplate = function(figure) {
34-
figure = Lib.extendDeep({_context: dfltConfig}, figure);
34+
figure = Lib.extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout});
3535
Plots.supplyDefaults(figure);
3636
var data = figure.data || [];
3737
var layout = figure.layout || {};

test/jasmine/tests/template_test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ describe('makeTemplate', function() {
141141

142142
expect(template).toEqual(expected);
143143
});
144+
145+
it('works on DOM element', function(done) {
146+
var mock = Lib.extendDeep({}, scatterFillMock);
147+
var gd = createGraphDiv();
148+
149+
Plotly.newPlot(gd, mock)
150+
.then(function() {
151+
var template = Plotly.makeTemplate(gd);
152+
delete(template.layout.xaxis);
153+
delete(template.layout.yaxis);
154+
expect(template).toEqual({
155+
data: {scatter: [
156+
{fill: 'tonext', line: {shape: 'spline'}},
157+
{fill: 'tonext'},
158+
{fill: 'toself'}
159+
] },
160+
layout: {
161+
title: 'Fill toself and tonext',
162+
width: 400,
163+
height: 400
164+
}
165+
});
166+
})
167+
.catch(failTest)
168+
.then(destroyGraphDiv)
169+
.then(done);
170+
});
144171
});
145172

146173
// statics of template application are all covered by the template mock

0 commit comments

Comments
 (0)