8000 Fix/legend resize by timelyportfolio · Pull Request #356 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content
8000

Fix/legend resize #356

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
Closed
Changes from 1 commit
Commits
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
Next Next commit
incremental progress toward working scrolling legend after resize
  • Loading branch information
etpinard authored and timelyportfolio committed Mar 23, 2016
commit 52f1a3c686daea20e3ebd798a84416201d7808b2
53 changes: 31 additions & 22 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ module.exports = function draw(gd) {
});

var clipPath = fullLayout._topdefs.selectAll('#' + clipId)
.data([0])
.enter().append('clipPath')
.data([0]);

clipPath.enter().append('clipPath')
.attr('id', clipId)
.append('rect');

Expand Down Expand Up @@ -210,7 +211,7 @@ module.exports = function draw(gd) {

legend.attr('transform', 'translate(' + lx + ',' + ly + ')');

clipPath.attr({
clipPath.select('rect').attr({
width: opts.width,
height: scrollheight,
x: 0,
Expand All @@ -220,49 +221,57 @@ module.exports = function draw(gd) {
legend.call(Drawing.setClipUrl, clipId);

// If scrollbar should be shown.
if(gd.firstRender && opts.height - scrollheight > 0 && !gd._context.staticPlot) {
if(opts.height - scrollheight > 0 && !gd._context.staticPlot) {

bg.attr({
width: opts.width - 2 * opts.borderwidth + constants.scrollBarWidth
});

clipPath.attr({
width: opts.width + constants.scrollBarWidth
});


// Move scrollbar to starting position
scrollBar.call(
Drawing.setRect,
opts.width - (constants.scrollBarWidth + constants.scrollBarMargin),
constants.scrollBarMargin,
constants.scrollBarWidth,
constants.scrollBarHeight
);

legend.on('wheel',null);

legend.node().addEventListener('wheel', function(e) {
legend.on('wheel', function(){
var e = d3.event;
e.preventDefault();
scrollHandler(e.deltaY / 20);
});
scrollHandler(e.deltaY / 20, scrollheight);
})

scrollBar.on('mousedown',null);

scrollBar.node().addEventListener('mousedown', function(e) {
scrollBar.on('mousedown', function(){
var e = d3.event;
e.preventDefault();

function mMove(e) {
if(e.buttons === 1) {
scrollHandler(e.movementY);
scrollHandler(e.movementY, scrollheight);
}
}

function mUp() {
scrollBar.node().removeEventListener('mousemove', mMove);
window.removeEventListener('mouseup', mUp);
}

window.addEventListener('mousemove', mMove);
window.addEventListener('mouseup', mUp);
});

// Move scrollbar to starting position on the first render
scrollBar.call(
Drawing.setRect,
opts.width - (constants.scrollBarWidth + constants.scrollBarMargin),
constants.scrollBarMargin,
constants.scrollBarWidth,
constants.scrollBarHeight
);
}

function scrollHandler(delta) {
function scrollHandler(delta, scrollheight) {

var scrollBarTrack = scrollheight - constants.scrollBarHeight - 2 * constants.scrollBarMargin,
translateY = scrollBox.attr('data-scroll'),
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0