Skip to content

Commit

Permalink
Merge pull request #3448 from plotly/fix-dynamic-imports
Browse files Browse the repository at this point in the history
Clear subplotType cache on Plotly.register()
  • Loading branch information
etpinard committed Jan 22, 2019
2 parents 741f958 + 8db005d commit 3b9188d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ function getTraceUids(oldFullData, newData) {
* Single-trace subplots (which have no `id`) such as pie, table, etc
* do not need to be collected because we just draw all visible traces.
*/
var collectableSubplotTypes;
function emptySubplotLists() {
var collectableSubplotTypes = Registry.collectableSubplotTypes;
var out = {};
var i, j;

Expand Down
3 changes: 3 additions & 0 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports.layoutArrayRegexes = [];
exports.traceLayoutAttributes = {};
exports.localeRegistry = {};
exports.apiMethodRegistry = {};
exports.collectableSubplotTypes = null;

/**
* Top-level register routine, exported as Plotly.register
Expand Down Expand Up @@ -72,6 +73,8 @@ exports.apiMethodRegistry = {};
*
*/
exports.register = function register(_modules) {
exports.collectableSubplotTypes = null;

if(!_modules) {
throw new Error('No argument passed to Plotly.register.');
} else if(_modules && !Array.isArray(_modules)) {
Expand Down
40 changes: 40 additions & 0 deletions test/jasmine/bundle_tests/dynamic_import_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var Plotly = require('@lib/core');

var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');

describe('Dynamic @lib/ module imports', function() {
var gd;

afterEach(destroyGraphDiv);

it('should work', function(done) {
gd = createGraphDiv();

Plotly.newPlot(gd, [{
y: [1, 2, 1]
}])
.then(function() {
// N.B. from a different subplot type
// more info in:
// https://github.com/plotly/plotly.js/issues/3428
var ScatterPolar = require('@lib/scatterpolar');
Plotly.register(ScatterPolar);
})
.then(function() {
return Plotly.newPlot(gd, [{
type: 'scatterpolar',
r: [1, 2, 1]
}]);
})
.then(function() {
var polarLayer = d3.select('.polarlayer');
expect(polarLayer.size()).toBe(1, 'one polar layer');
expect(polarLayer.selectAll('.trace').size()).toBe(1, 'one scatterpolar trace');
})
.catch(failTest)
.then(done);
});
});

0 comments on commit 3b9188d

Please sign in to comment.