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

Introduce global contexts #2159

Merged
merged 13 commits into from
Nov 28, 2017
Merged

Introduce global contexts #2159

merged 13 commits into from
Nov 28, 2017

Conversation

dy
Copy link
Contributor

@dy dy commented Nov 14, 2017

Excerpt from #1869.
Covers #1993 and #1989.

@dy dy requested a review from etpinard November 14, 2017 20:34
@dy
Copy link
Contributor Author

dy commented Nov 15, 2017

Apparently there are some IE9-related issues with regl.

@@ -42,6 +42,8 @@ var enforceAxisConstraints = axisConstraints.enforce;
var cleanAxisConstraints = axisConstraints.clean;
var axisIds = require('../plots/cartesian/axis_ids');

var createRegl = require('regl');
Copy link
Contributor

@etpinard etpinard Nov 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha. regl must be invoking one or many globals that IE9 doesn't support at runtime.

As this file here plot_api.js is required in all partial bundles (even that gl-less ones), this makes the IE9 test fail.

So, I think the best to solve this would be use a Registry.getComponentMethod-style pattern so that regl is only required in bundles that expose regl traces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard do I get it right that we don't have this safe-require pattern yet? What if I just require regl directly when the regl trace type is detected?

Copy link
Contributor

@etpinard etpinard Nov 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I just require regl directly when the regl trace type is detected?

You mean something like:

if(fullLayout._has('regl')) {
  var createREGL = require('regl')
}

in plot_api.js? That could work, but regl would still get bundled up in all partial bundles.

@@ -2754,7 +2788,7 @@ function makePlotFramework(gd) {
.classed('plotly', true);

// Make the svg container
fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]);
fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([{}]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change [0] to [{}]?

var _module = basePlotModules[i];

if(_module.name === category) return true;
}

// check trace
var modules = this._modules || [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brilliant ✨

x: 0,
y: 0,
width: canvas.width,
height: canvas.height,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely cleanup ❤️

@@ -2765,10 +2799,13 @@ function makePlotFramework(gd) {
// TODO: sort out all the ordering so we don't have to
// explicitly delete anything
fullLayout._glcontainer = fullLayout._paperdiv.selectAll('.gl-container')
.data([0]);
.data([{}]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this one here?

Copy link
Contributor Author

@dy dy Nov 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the way parcoords is doing it's thing: https://github.com/plotly/plotly.js/pull/2159/files#diff-2fad23de82bf8c7625ea8e11436233b7R290
I did not really try to figure out why it is done this and not the another way. Before it used own container for storing this data. If that matters, I can try to keep this object within parcoords use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work ok with data([0])?

Copy link
Contributor Author

@dy dy Nov 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard that is the point that parcoords puts vm property there via extendFlat, that is why it should be an object. Probably it is possible to find a better storage for it, I just did not figure out what.

key: 'pickLayer',
context: false,
pick: true
}]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a key-function here to make sure to not create these canvas nodes on every hard redraw that go through drawFramework.

Sometime like:

fullLayout._glcanvas = fullLayout._glcontainer.selectAll('.gl-canvas').data([{
  /* .. as currently ... */
}], function(d) { return d.key; });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder: we probably don't have sufficient test coverage for Plotly.restyle calls that morph a gl-based trace types into a SVG-based. For example off the regl2d branch we should have:

Plotly.newPlot(gd, [{
  type: 'scattergl',
  // ...
}])
.then(function() {
   d3.selectAll('canvas').size() // => 3

  return Plotly.restyle(gd, 'type', 'scatter')
})
.then(function() {
  d3.selectAll('canvas').size() // => 0
})

As restyling a parcoords traces into any other trace types doesn't make much sense at the moment. You could instead try something like:

Plotly.newPlot(gd, [{
  type: 'parcoords',
  // ...
}])
.then(function() {
   d3.selectAll('canvas').size() // => 3

  return Plotly.deleteTraces(gd, [0])
})
.then(function() {
  d3.selectAll('canvas').size() // => 0
})


if(hadGl && !hasGl) {
if(oldFullLayout._glcontainer !== undefined) {
oldFullLayout._glcontainer.selectAll('.gl-canvas').data([]).exit().remove();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oldFullLayout._glcontainer.selectAll('.gl-canvas').remove()

should suffice.

@etpinard
Copy link
Contributor

@dfcreative Good news the parcoords tests are passing again

Bad news other @noCI tests are failing.

image

Can you try making npm run test-jasmine -- --tags=noCI pass?

@dy
Copy link
Contributor Author

dy commented Nov 28, 2017

@etpinard fixed these four noCI tests, seems that others (mapbox ones) are not related to this PR but are specific to my machine.

@etpinard
Copy link
Contributor

seems that others (mapbox ones) are not related to this PR but are specific to my machine.

Yeah, those mapbox tests are pretty resource-intensive; that doesn't surprise me. Hopefully #2029 will fix those issues.


Great PR. Merge away 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants