Skip to content

Break up legend module #329

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

Merged
merged 22 commits into from
Mar 16, 2016
Merged

Break up legend module #329

merged 22 commits into from
Mar 16, 2016

Conversation

etpinard
Copy link
Contributor

@mdtusz - in preparation for range selectors.

This PR:

  • replaces the nested legend <svg> by a <g clip-path="">
  • breaks up the legend defaults, draw and style step into separate files.
  • adds a helpers module
  • adds an anchor_utils module (to handle e.g. the xanchor: 'auto' positioning case) which will be reuse in the range selector module.
  • adds tests for the legend helpers and anchor_utils
  • adds in-house getBBox test asset (which considers the clip-path)

};

function styleLines(d) {
var trace = d[0].trace,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these should really be methods of the corresponding trace module, but that will be for a future PR.

etpinard added 10 commits March 15, 2016 12:41
- the exit selection will always be empty
  as the joined data is always [0].
- append <defs> to toppaper in make-framework step
- use fullLayout._uid in legend <clipPath> id to avoid
  conflict on DOM queries.
- needed to determine bounding box of clipped element,
  as the stock SVG getBBox method does not take clip path
  into consideration
- use it legend scroll test to determine the height of the legend
- to ensure that they are properly removed when
  'showlegend' is relayout'ed to false.
- sub-pixel diff due to legend clipping
@@ -2585,6 +2585,9 @@ function makePlotFramework(gd) {
fullLayout._defs = fullLayout._paper.append('defs')
.attr('id', 'defs-' + fullLayout._uid);

fullLayout._topdefs = fullLayout._toppaper.append('defs')
.attr('id', 'defs-' + fullLayout._uid);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdtusz I opted for a similar pattern for <defs> in the top paper <svg> as is currently done in the (bottom) paper <svg>

Then the clipPath should remain positioned relative to the element it's applied to?

After a few quick Google searches, I didn't find anything arguments for or against relative clipPath locations.

I think that having one <defs> node per <svg> does make things a bit clearer. But, above all, I chose this route for consistency with what's currently done in the (bottom) <svg>.

- getBBox fails when call on a clipPath node in FF
- use DOM attributes as fallback to grab the bounding box

try {
// this line throws an error in FF (38 and 45 at least)
clipBBox = clipPath.node().getBBox();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdtusz are you ok with this?

@mdtusz
Copy link
Contributor

mdtusz commented Mar 16, 2016

Ok I think this looks pretty good to go after the few minor little nits.

💃

- that way ids remain unique on page
- rm special <defs> merge block in to-svg step
- as childNodes prop gets mutated in top-group loop
@@ -2586,7 +2586,7 @@ function makePlotFramework(gd) {
.attr('id', 'defs-' + fullLayout._uid);

fullLayout._topdefs = fullLayout._toppaper.append('defs')
.attr('id', 'defs-' + fullLayout._uid);
.attr('id', 'topdefs-' + fullLayout._uid);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @mdtusz I changed my mind.

We should make sure that our ids are unique on the page at all times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

svg ids are treated as regular DOM ids. They are not scoped to one particular <svg>:

http://codepen.io/etpinard/pen/ONWVaL

- use it in legend text
- rm now useless user-select purge step in to-svg
'user-select': 'none'
})
.style('text-anchor', 'start')
.classed('user-select-none', true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdtusz cleaner, right?

I'm going to use .user-select-none in the range selector buttons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yep much better. We can add that to axes values as well - when sliding the range-slider they sometimes get highlighted.

etpinard added a commit that referenced this pull request Mar 16, 2016
@etpinard etpinard merged commit a27d62c into master Mar 16, 2016
@etpinard etpinard deleted the break-up-legend branch March 16, 2016 18:54
@etpinard etpinard mentioned this pull request Mar 17, 2016
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