Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WIP: Legend Scrolling #243

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 28 commits into from
Feb 22, 2016
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32fa3cd
Remove some plotly dependency
mdtusz Jan 25, 2016
b55b501
Add legend type attribute
mdtusz Jan 25, 2016
7cfec79
Add scrollbox (not yet set to be active though)
mdtusz Feb 5, 2016
a4dc092
Add sensible default
mdtusz Feb 5, 2016
b4e2796
Remove legend type attribute
mdtusz Feb 5, 2016
91a68b5
Add scrollbar
mdtusz Feb 8, 2016
61fa606
Remove some plotly dependency
mdtusz Jan 25, 2016
c3ba270
Add legend type attribute
mdtusz Jan 25, 2016
803e797
Add scrollbox (not yet set to be active though)
mdtusz Feb 5, 2016
c24b29b
Add sensible default
mdtusz Feb 5, 2016
23f6073
Remove legend type attribute
mdtusz Feb 5, 2016
b45e846
Add scrollbar
mdtusz Feb 8, 2016
811f925
Add drag scroll, move scroll code to `draw`, fix weird width bug
mdtusz Feb 10, 2016
e66ab81
Change svg element to g
mdtusz Feb 11, 2016
36c3a69
Add tests for scrolling
mdtusz Feb 11, 2016
81cf841
Change bg style changes to attrs for ff compatiblity
mdtusz Feb 11, 2016
44fb3c7
Update image baselines
tarzzz Feb 12, 2016
d7124f4
Add final drawing step
mdtusz Feb 16, 2016
4e752fb
Add data-bb removal code to svg_text_utils
mdtusz Feb 16, 2016
20fbf18
:space_invader: fix sloppy mistake
mdtusz Feb 16, 2016
82dbfcc
Update scroll test to work in ff and chrome
mdtusz Feb 17, 2016
a170ec7
Add comment explaining finalDraw function
mdtusz Feb 17, 2016
ff92f21
Add box-sizing to legend background
mdtusz Feb 17, 2016
8ddf644
Add crisp rendering and gutter for scollbar
mdtusz Feb 18, 2016
fee87db
update baselines
etpinard Feb 19, 2016
0a3ebd9
Merge branch 'master' into dropdown-filter
etpinard Feb 22, 2016
f1bdea0
update plot_types mock (due to sub-pixel legend modifs)
etpinard Feb 22, 2016
1df89c5
add tolerance of 1e-6 to pixel comparison tests
etpinard Feb 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add scrollbox (not yet set to be active though)
  • Loading branch information
mdtusz committed Feb 5, 2016
commit 7cfec792f445be9187d30307c94c3ee6c7db920f
59 changes: 46 additions & 13 deletions 59 src/components/legend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,22 +444,28 @@ legend.draw = function(td) {

var legendsvg = fullLayout._infolayer.selectAll('svg.legend')
.data([0]);
legendsvg.enter(0).append('svg')
.attr('class','legend');
legendsvg.enter().append('svg')
.attr('class','legend')
.attr('pointer-events', 'all');

var bgRect = legendsvg.selectAll('rect.bg')
var bg = legendsvg.selectAll('rect.bg')
.data([0]);
bgRect.enter(0).append('rect')
.attr('class','bg');
bgRect
bg.enter().append('rect')
.attr('class','bg')
.call(Color.stroke, opts.bordercolor)
.call(Color.fill, opts.bgcolor)
.style('stroke-width', opts.borderwidth+'px');
.style('stroke-width', opts.borderwidth + 'px');

var groups = legendsvg.selectAll('g.groups')
.data(legendData);
var scrollBox = legendsvg.selectAll('svg.scrollbox')
.data([0]);
scrollBox.enter().append('svg')
.attr('class', 'scrollbox');
scrollBox.exit().remove();

groups.enter().append('g').attr('class', 'groups');
var groups = scrollBox.selectAll('g.groups')
.data(legendData);
groups.enter().append('g')
.attr('class', 'groups');
groups.exit().remove();

if(isGrouped(opts)) {
Expand Down Expand Up @@ -530,6 +536,7 @@ legend.draw = function(td) {
});
});

// Position and size the legend
legend.repositionLegend(td, traces);

if(td._context.editable) {
Expand Down Expand Up @@ -672,11 +679,37 @@ legend.repositionLegend = function(td, traces){
lx = Math.round(lx);
ly = Math.round(ly);

// Add scroll functionality
var legendsvg = fullLayout._infolayer.selectAll('svg.legend'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section should likely be moved to the draw step, but everything is highly coupled right now and the order of drawing/sizing/positioning is very scattered.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mdtusz Any reason for putting this section in repostionLegend in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly for ease of development. The scroll handler requires the final height of the legend to calculate the viewbox offset and at the time, I was still trying to wrap my head around the control flow in here.

It will be moved out into draw before we merge though

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the info. 👍

scrollBox = fullLayout._infolayer.selectAll('svg.legend .scrollbox'),
scrollheight = Math.min(80, legendheight);

scrollBox.attr('viewBox', '0 0 ' + legendwidth + ' ' + scrollheight);
legendsvg.node().addEventListener('wheel', scrollHandler);

function scrollHandler(e){
e.preventDefault();

var scroll = scrollBox.attr('viewBox').split(' ');
scroll[1] = constrain(0, Math.max(legendheight - scrollheight, 0), +scroll[1] + e.deltaY);

scrollBox.attr('viewBox', scroll.join(' '));
}

function constrain(min, max, c){
Copy link
Contributor

Choose a reason for hiding this comment

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

Lib.constrain will do just that.

if(c <= max && c >= min){
return c;
}else if(c > max){
return max;
}else{
return min;
}
}

fullLayout._infolayer.selectAll('svg.legend')
.call(Drawing.setRect, lx, ly, legendwidth, legendheight);
.call(Drawing.setRect, lx, ly, legendwidth, scrollheight);
fullLayout._infolayer.selectAll('svg.legend .bg')
.call(Drawing.setRect, borderwidth/2, borderwidth/2,
legendwidth-borderwidth, legendheight-borderwidth);
.style({ width: legendwidth, height: scrollheight });

// lastly check if the margin auto-expand has changed
Plots.autoMargin(td,'legend',{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.