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

Add visible attribute to layout container items. #1110

Merged
merged 11 commits into from
Nov 7, 2016

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Nov 3, 2016

that is annotations, shapes and images items should get a visible attribute just like updatemenus and slider already have.

This should make setting mobile-friendly annotations-less frames much easier. Related: #1081 (comment)

cc @rreusser @alexcjohnson

Unverified

This user has not yet uploaded their public signing key.
- so that all array containers (not just gd.data) can use it.
- previously all relayout calls with leading `annotations` or
  `shapes` and value `null` were replaced with value `'remove'`
- now make sure that only `annotations/shapes[i]: null` are
  replaced with `'remove'`
- so that the visibility of a given annotations can
  be turned off w/o having to remove to item
  or (in a hack) set 'opacity' to 0.
@etpinard etpinard added bug something broken feature something new status: in progress labels Nov 3, 2016
@etpinard etpinard added this to the v1.20.0 milestone Nov 3, 2016
@etpinard
Copy link
Contributor Author

etpinard commented Nov 3, 2016

TODO:

  • implement visible for shapes
  • implement visible for images

- ... and make sure that
  layout.images.length === fullLayout.image.length always,
  i.e. item with no source are coerced to { visible: false }
  and skipped during the draw step.
@@ -17,6 +17,7 @@
{"text":"right bottom","showarrow":false,"xref":"paper","yref":"paper","xanchor":"right","yanchor":"bottom","x":0.5,"y":1},
{"text":"move with page","xref":"paper","yref":"paper","x":0.75,"y":1},
{"text":"opacity","opacity":0.5,"x":5,"y":5},
{"text":"not-visible", "visible": false},
Copy link
Collaborator

Choose a reason for hiding this comment

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

This mock is not autoranged... do you want to also include an invisible annotation in annotations-autorange.json, positioned to verify that it doesn't contribute? Same for shapes.

I guess images currently don't contribute to autorange at all - is that on purpose or should I consider it a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want to also include an invisible annotation in annotations-autorange.json

done in a2dd634

Same for shapes.

the shape_below_traces is autoranged, so that's a ✅ already

I guess images currently don't contribute to autorange at all - is that on purpose or should I consider it a bug?

I'd say that's a 🐛

Copy link
Collaborator

Choose a reason for hiding this comment

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

the shape_below_traces is autoranged, so that's a ✅ already

but the shape you added there just says {visible: false} so it will get auto coordinates too, which are going to be within the range chosen by autorange anyway, ie including it in autorange wouldn't make any difference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(actually that's true of a2dd634 too right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexcjohnson good 👁️

I chose to revert a2dd634 and test annotations and shapes autorange using jasmine tests in 5e62c08

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome, the new tests look great. Definitely better to do this with jasmine and relayout.

return Plotly.relayout(gd, 'shapes[' + index + ']', 'remove');
})
.then(function() {
expect(countShapePathsInUpperLayer()).toEqual(pathCount);
expect(countShapes(gd)).toEqual(index);

return Plotly.relayout(gd, 'shapes[' + 1 + ']', null);
return Plotly.relayout(gd, 'shapes[' + 2 + '].visible', false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

'shapes[2].visible'? I guess this is to match 'shapes[' + index + ']' above but it looks a little funny...


return Plotly.relayout(gd, 'images[1].visible', true);
})
.then(function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@alexcjohnson
Copy link
Collaborator

Really nice generalization of the visible attribute! 💃 from me after those couple of comments on the tests.

// xaxis2 need a bit more tolerance to pass on CI
// this most likely due to the different text bounding box values
// on headfull vs headless browsers.
var PREC2 = 0.1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused - isn't this less tolerance?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I guess precision is supposed to be a number of digits, like the built-in toBeCloseTo... in which case I guess coercePosition shouldn't really treat 0 as special, 0 is just +/- 0.5... but that's an issue for another time. 💃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I guess precision is supposed to be a number of digits, like the built-in toBeCloseTo.

Exactly. Maybe we should add an array version of toBeWithin down the road too.

@etpinard etpinard merged commit 38aa4b3 into master Nov 7, 2016
@etpinard etpinard deleted the annotations-shape-visible branch November 7, 2016 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants