From 44724a323430ae28029d7a08fe322eb4ac8faebd Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 16 Oct 2018 11:50:16 -0400 Subject: [PATCH 1/2] support dom element as argument to Plotly.makeTemplate --- src/plot_api/template_api.js | 2 +- test/jasmine/tests/template_test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/plot_api/template_api.js b/src/plot_api/template_api.js index a9eaa84b167..98565fbb4ea 100644 --- a/src/plot_api/template_api.js +++ b/src/plot_api/template_api.js @@ -31,7 +31,7 @@ var dfltConfig = require('./plot_config'); * `layout.template` in another figure. */ exports.makeTemplate = function(figure) { - figure = Lib.extendDeep({_context: dfltConfig}, figure); + figure = Lib.extendDeep({_context: dfltConfig}, {data: figure.data, layout: figure.layout}); Plots.supplyDefaults(figure); var data = figure.data || []; var layout = figure.layout || {}; diff --git a/test/jasmine/tests/template_test.js b/test/jasmine/tests/template_test.js index 81ffe8f7e2f..f60ee00472e 100644 --- a/test/jasmine/tests/template_test.js +++ b/test/jasmine/tests/template_test.js @@ -141,6 +141,33 @@ describe('makeTemplate', function() { expect(template).toEqual(expected); }); + + it('works on DOM element', function(done) { + var mock = Lib.extendDeep({}, scatterFillMock); + var gd = createGraphDiv(); + + Plotly.newPlot(gd, mock) + .then(function() { + var template = Plotly.makeTemplate(gd); + delete(template.layout.xaxis); + delete(template.layout.yaxis); + expect(template).toEqual({ + data: {scatter: [ + {fill: 'tonext', line: {shape: 'spline'}}, + {fill: 'tonext'}, + {fill: 'toself'} + ] }, + layout: { + title: 'Fill toself and tonext', + width: 400, + height: 400 + } + }); + }) + .catch(failTest) + .then(destroyGraphDiv) + .then(done); + }); }); // statics of template application are all covered by the template mock From eb6a2e859f6e6ddb11bedb5afc9d8e8cf101ef86 Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 16 Oct 2018 12:54:15 -0400 Subject: [PATCH 2/2] fix lint --- test/jasmine/tests/template_test.js | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/jasmine/tests/template_test.js b/test/jasmine/tests/template_test.js index f60ee00472e..600076ca613 100644 --- a/test/jasmine/tests/template_test.js +++ b/test/jasmine/tests/template_test.js @@ -147,23 +147,23 @@ describe('makeTemplate', function() { var gd = createGraphDiv(); Plotly.newPlot(gd, mock) - .then(function() { - var template = Plotly.makeTemplate(gd); - delete(template.layout.xaxis); - delete(template.layout.yaxis); - expect(template).toEqual({ - data: {scatter: [ - {fill: 'tonext', line: {shape: 'spline'}}, - {fill: 'tonext'}, - {fill: 'toself'} - ] }, - layout: { - title: 'Fill toself and tonext', - width: 400, - height: 400 - } - }); - }) + .then(function() { + var template = Plotly.makeTemplate(gd); + delete(template.layout.xaxis); + delete(template.layout.yaxis); + expect(template).toEqual({ + data: {scatter: [ + {fill: 'tonext', line: {shape: 'spline'}}, + {fill: 'tonext'}, + {fill: 'toself'} + ] }, + layout: { + title: 'Fill toself and tonext', + width: 400, + height: 400 + } + }); + }) .catch(failTest) .then(destroyGraphDiv) .then(done);