Skip to content

Fix issue #384 (invisible legends when y is negative) #417

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

Conversation

n-riesco
Copy link
Contributor

This a new solution to fix #384 that only touches Legend.draw()

ly -= opts.height / 2;
}

//lx = Math.round(lx);
//ly = Math.round(ly);

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've commented out these two lines only to reproduce the baseline images, but I think they should be brought back.

@mdtusz
Copy link
Contributor

mdtusz commented Apr 12, 2016

This looks pretty good so far - could you elaborate on the commented out lx ly for the image baselines?

I'm going to continue testing to see if there's any issues but I haven't found anything yet.

@n-riesco
Copy link
Contributor Author

The baseline images have been generated using lx and ly without rounding off.

When lx and ly are rounded off, many of the image tests (~75) fail with differences that are only 1 pixel.

Before introducing scrollbars, lx and ly were rounded off, and rounding off lx and ly makes it easier to reproduce plots in machines with different precisions.

@n-riesco
Copy link
Contributor Author

  • I noticed an issue in plots with many traces (~25). With these plots, when I drag the legend scrollbar, the mouse moves much faster than the bar. And the mouse wheel hardly scrolls the legend. With commit c96581c I've fixed both issues. This commit requires updating the wheel test.
  • I've also noticed that this PR makes the margins of one of my mocks larger. I need to investigate this further.
  • Another thing to look at is how the space for the scrollbars is allocated (is it hard-coded here?). But I want to do this last, just in case it affects any of the baseline images.

@n-riesco n-riesco force-pushed the issue-384-legend-negative-y-no-strict-margins branch from 699b496 to ab15b52 Compare April 13, 2016 00:45
@n-riesco n-riesco force-pushed the issue-384-legend-negative-y-no-strict-margins branch from ab15b52 to 8baac47 Compare April 13, 2016 09:35
@n-riesco
Copy link
Contributor Author

Commit 8baac47 adds a nice tweak to legends. Previously, the margins were expanded using the legend size, no matter whether the legend would fit or not. But since legends that don't fit are forced to fit into the plot height, there is no need to expand the vertical margin and make the plot box unnecessarily smaller.

Before this PR (i.e. using dist/plotly.js):
before

After (using build/plotly.js):
after

* Now drag events make the scrollbar follow the mouse position.

* Now wheel events move the scrollbar position as fast as drag events.
@n-riesco n-riesco force-pushed the issue-384-legend-negative-y-no-strict-margins branch from 151b29d to c96581c Compare April 13, 2016 12:18
@n-riesco n-riesco force-pushed the issue-384-legend-negative-y-no-strict-margins branch from d8e8c38 to e1effce Compare April 14, 2016 00:23
@n-riesco
Copy link
Contributor Author

@mdtusz @etpinard I had to revert my last commit because of merge conflicts. I'd like to merge this PR before trying to rebase my last commit. Is that OK?

@mdtusz
Copy link
Contributor

mdtusz commented Apr 14, 2016

Looks great! Let's either remove these entirely or uncomment them (it seems like they may not be necessary?), then 💃 and we can merge it in!

@n-riesco
Copy link
Contributor Author

@mdtusz Done.

I have a commit that splits Legend.draw() into smaller functions. It conflicts with master. Shall I try to rebase it?

While playing with the scrollbar I noticed that the top and bottom traces in the legend may overlap with the legend border. I've thought of two possible solutions:

  1. move the clippath from legend to scrollbox (this implies updating the clippath position along with that of the scrollbox on drag and wheel events),
  2. apply the clippath to a new <g> and make the scrollbox a child of this new <g>.

Option 2 involves less coding (but adds one more layer). Which option do you prefer?

@mdtusz
Copy link
Contributor

mdtusz commented Apr 14, 2016

I'd prefer to keep the layers as minimal as we can - can we just alter the clippath to be "padded" - i.e. reduce it's height by x pixels and translate down by x/2 pixels?

Or perhaps I'm misunderstanding the issue.

@n-riesco
Copy link
Contributor Author

This is a screenshot showing the problem:

border

The clippath is applied to legend and legend contains both rect.bg and scrollbox. If we shrink the clippath, then both rect.bg and scrollbox will be affected.

@mdtusz
Copy link
Contributor

mdtusz commented Apr 15, 2016

Ah ok got it. I'd prefer if we went with option 1, but I'll leave it to your judgement.

@mdtusz
Copy link
Contributor

mdtusz commented Apr 18, 2016

Thanks Nico. This looks good to go.

💃

@mdtusz mdtusz merged commit b9a1705 into plotly:master Apr 18, 2016
@n-riesco n-riesco deleted the issue-384-legend-negative-y-no-strict-margins branch April 20, 2016 16:10
@etpinard etpinard added the bug something broken label Apr 25, 2016
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.

Negative y value for legend causes error and invisible legend
3 participants