Skip to content

Commit 3b9188d

Browse files
authored
Merge pull request #3448 from plotly/fix-dynamic-imports
Clear subplotType cache on Plotly.register()
2 parents 741f958 + 8db005d commit 3b9188d

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/plots/plots.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ function getTraceUids(oldFullData, newData) {
579579
* Single-trace subplots (which have no `id`) such as pie, table, etc
580580
* do not need to be collected because we just draw all visible traces.
581581
*/
582-
var collectableSubplotTypes;
583582
function emptySubplotLists() {
583+
var collectableSubplotTypes = Registry.collectableSubplotTypes;
584584
var out = {};
585585
var i, j;
586586

src/registry.js

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ exports.layoutArrayRegexes = [];
3131
exports.traceLayoutAttributes = {};
3232
exports.localeRegistry = {};
3333
exports.apiMethodRegistry = {};
34+
exports.collectableSubplotTypes = null;
3435

3536
/**
3637
* Top-level register routine, exported as Plotly.register
@@ -72,6 +73,8 @@ exports.apiMethodRegistry = {};
7273
*
7374
*/
7475
exports.register = function register(_modules) {
76+
exports.collectableSubplotTypes = null;
77+
7578
if(!_modules) {
7679
throw new Error('No argument passed to Plotly.register.');
7780
} else if(_modules && !Array.isArray(_modules)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var Plotly = require('@lib/core');
2+
3+
var d3 = require('d3');
4+
var createGraphDiv = require('../assets/create_graph_div');
5+
var destroyGraphDiv = require('../assets/destroy_graph_div');
6+
var failTest = require('../assets/fail_test');
7+
8+
describe('Dynamic @lib/ module imports', function() {
9+
var gd;
10+
11+
afterEach(destroyGraphDiv);
12+
13+
it('should work', function(done) {
14+
gd = createGraphDiv();
15+
16+
Plotly.newPlot(gd, [{
17+
y: [1, 2, 1]
18+
}])
19+
.then(function() {
20+
// N.B. from a different subplot type
21+
// more info in:
22+
// https://github.com/plotly/plotly.js/issues/3428
23+
var ScatterPolar = require('@lib/scatterpolar');
24+
Plotly.register(ScatterPolar);
25+
})
26+
.then(function() {
27+
return Plotly.newPlot(gd, [{
28+
type: 'scatterpolar',
29+
r: [1, 2, 1]
30+
}]);
31+
})
32+
.then(function() {
33+
var polarLayer = d3.select('.polarlayer');
34+
expect(polarLayer.size()).toBe(1, 'one polar layer');
35+
expect(polarLayer.selectAll('.trace').size()).toBe(1, 'one scatterpolar trace');
36+
})
37+
.catch(failTest)
38+
.then(done);
39+
});
40+
});

0 commit comments

Comments
 (0)