Skip to content

fix responsive figures with WebGL #3486

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

Closed
wants to merge 3 commits into from
Closed

Conversation

antoinerg
Copy link
Contributor

@antoinerg antoinerg commented Jan 25, 2019

Closes #3485

Commit 16e1f4f simply adds scattergl in the responsive test suite and fails. Commit f8c959d makes the tests pass.

@@ -244,8 +244,6 @@ exports.plot = function(gd, data, layout, config) {
'position': 'absolute',
'top': 0,
'left': 0,
'width': '100%',
'height': '100%',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think those two lines were ever needed since a few lines later we set the size of the canvas via its attributes anyway:

fullLayout._glcanvas
.attr('width', fullLayout.width)
.attr('height', fullLayout.height);

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice find!

.then(testResponsive)
.then(done);
});
it('@flaky should resize when the viewport width/height changes', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the traceType value inside these its so that if the scatter or the scattergl cases fail, we'll know which one did. For example,

it('@flaky should resize when the viewport width/height changes (case ' + traceType + ')', function(done) {
// ...

@antoinerg antoinerg changed the base branch from improve-responsive-tests to master January 25, 2019 17:16
document.body.removeChild(parent);
viewport.reset();
});
['scatter', 'scattergl'].forEach(function(traceType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should add the traceType value inside these its so that if the scatter or the scattergl cases fail, we'll know which one did. For example,

I think this line allows to clearly identify which case fails. Am I mistaken?

cc @etpinard

Copy link
Contributor

Choose a reason for hiding this comment

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

Nop, that won't appear in the logs. Try it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running npm run test-jasmine -- config will a failing test gives me:
screenshot_2019-01-25_12-35-18

What am I missing?

Thank you @etpinard

Copy link
Contributor

Choose a reason for hiding this comment

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

scatter or scattergl.

Copy link
Contributor Author

@antoinerg antoinerg Jan 25, 2019

Choose a reason for hiding this comment

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

Maybe it's not prominent enough but it's already there (scattergl is underlined in yellow):
screenshot_2019-01-25_12-35-18

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops. It's in the describe block:

describe('responsive ' + traceType + ' trace', function() {

My bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad also: I should have highlighted this describe line for clarity. Anyway, thanks for the review :)

@antoinerg
Copy link
Contributor Author

Codepen showing the fix: https://codepen.io/anon/pen/NoxBRy

Note that the modebar is also misbehaving: it does not fill vertical space properly. The problem is similar to the one affecting canvas: modebar has height: 100% but its parent container has no height. Removing position: relative on the parent container may solve both issues at the same time.

@antoinerg antoinerg added the bug something broken label Jan 26, 2019
@etpinard
Copy link
Contributor

Note that the modebar is also misbehaving

Thanks for the info. Are you planning on trying to fix that in this PR?

@antoinerg
Copy link
Contributor Author

@etpinard Yes, I think I should clean up that CSS and fix this here.

@antoinerg
Copy link
Contributor Author

antoinerg commented Jan 29, 2019

In commit 751f716, I move the CSS directive position: relative to the outermost container. It fixes positioning/sizing of the vertical modebar and passes all our autosize and responsive tests for both SVG and WebGL figures.

@plotly/plotly_js

@@ -105,7 +105,8 @@ exports.plot = function(gd, data, layout, config) {

// hook class for plots main container (in case of plotly.js
// this won't be #embedded-graph or .js-tab-contents)
d3.select(gd).classed('js-plotly-plot', true);
d3.select(gd).classed('js-plotly-plot', true)
.style('position', 'relative');
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I'll call that a breaking change.

We could turn this on just when responsive is set to true. But then again, are there any other solutions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's certainly a breaking change and it breaks a lot of tests anyway.

I have another branch in which I fix the responsive issues for both WebGL #3485 and the modebar #3499 that doesn't rely on modifying the parent. I will submit a new separate PR with a cleaner commit history and I will close the current one.

@antoinerg
Copy link
Contributor Author

Closing in favor of #3486

@antoinerg antoinerg closed this Jan 31, 2019
@antoinerg antoinerg deleted the fix-responsive-gl branch January 31, 2019 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants