Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots.supplyDeffaults subplot type cache doesn't allow dynamic trace module imports #3428

Closed
dan8f opened this issue Jan 11, 2019 · 3 comments · Fixed by #3448
Closed

Plots.supplyDeffaults subplot type cache doesn't allow dynamic trace module imports #3428

dan8f opened this issue Jan 11, 2019 · 3 comments · Fixed by #3448

Comments

@dan8f
Copy link
Contributor

dan8f commented Jan 11, 2019

Hi team,

collectableSubplotTypes gets cached and this leads to inaccurate subplot lists if new traces are registered dynamically:

var collectableSubplotTypes;
function emptySubplotLists() {
var out = {};
var i, j;
if(!collectableSubplotTypes) {
collectableSubplotTypes = [];
var subplotsRegistry = Registry.subplotsRegistry;
for(var subplotType in subplotsRegistry) {
var subplotModule = subplotsRegistry[subplotType];
var subplotAttr = subplotModule.attr;
if(subplotAttr) {
collectableSubplotTypes.push(subplotType);
// special case, currently just for cartesian:
// we need to enumerate axes, not just subplots
if(Array.isArray(subplotAttr)) {
for(j = 0; j < subplotAttr.length; j++) {
Lib.pushUnique(collectableSubplotTypes, subplotAttr[j]);
}
}
}
}
}
for(i = 0; i < collectableSubplotTypes.length; i++) {
out[collectableSubplotTypes[i]] = [];
}
return out;
}

For example if we load Plotly, plot a graph and later dynamically register mapbox and plot a mapbox it will error since coorect subplotTypes are not passed to handleSubplotDefaults.

Could we simply not cache subplotTypes or reset when we register new traces?

Regards

image

@etpinard
Copy link
Contributor

Thanks for the report!

if new traces are registered dynamically

Could you share a code snippet to help us understand what you're trying to achieve? Thank you very much.

@dan8f
Copy link
Contributor Author

dan8f commented Jan 14, 2019

Hi @etpinard

Imagine we have component Timeseries.js as:

import Plotly from 'plotly.js/lib/core'; export default function() { Plotly.plot(...); }

And component Mapbox.js as:

import Plotly from 'plotly.js/lib/core'; import Mapbox from 'plotly.js/lib/scattermapbox'; Plotly.register(Mapbox); export default function() { Plotly.plot(...); }

And then in our main index.js we dynamically import Timeseries and plot a graph and later on import Mapbox and plot a map.

import("Timeseries").default(); and later...>> import("Mapbox").default();

This will produce an error in handleSubplotDefaults. The subplot types for Mapbox component should include 'Mapbox' but since we have cached subplot types when first rendering the timeseries, then chart we will miss them.

Let me know if this doesn't help to visualize it.

Regards

@etpinard
Copy link
Contributor

That makes perfect sense. Thanks. We'll fix that!

@etpinard etpinard changed the title emptySubplotLists cache in plots.supplyDeffaults Plots.supplyDeffaults subplot type cache doesn't allow dynamic trace module imports Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants