Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Timeline .focus() should also zoom in as well as zoom out. Fix vertical scroll when not using groups or rtl = true #4038

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
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
22 changes: 11 additions & 11 deletions lib/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ Timeline.prototype.focus = function(id, options) {
// The redraw shifted elements, so reset the animation to correct
initialVerticalScroll = verticalScroll;
startPos = me._getScrollTop() * -1;
}
}

var from = startPos;
var to = initialVerticalScroll.scrollOffset;
Expand Down Expand Up @@ -492,13 +492,13 @@ Timeline.prototype.focus = function(id, options) {
// Double check we ended at the proper scroll position
setFinalVerticalPosition();

// Let the redraw settle and finalize the position.
// Let the redraw settle and finalize the position.
setTimeout(setFinalVerticalPosition, 100);
};

// calculate the new middle and interval for the window
var middle = (start + end) / 2;
var interval = Math.max(this.range.end - this.range.start, (end - start) * 1.1);
var interval = (end - start) * 1.1;
Copy link
Author

Choose a reason for hiding this comment

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

Math.max ensured a zoom out, but never a zoom in, which is odd. make the behavior more consistent by just snapping to the item with 5% buffer on each side.


var animation = options && options.animation !== undefined ? options.animation : true;

Expand Down Expand Up @@ -569,14 +569,14 @@ function getItemVerticalScroll(timeline, item) {
return false;
}

var leftHeight = timeline.props.leftContainer.height;
var contentHeight = timeline.props.left.height;
var itemsetHeight = timeline.options.rtl ? timeline.props.rightContainer.height : timeline.props.leftContainer.height;
var contentHeight = timeline.props.center.height;

var group = item.parent;
var offset = group.top;
var shouldScroll = true;
var orientation = timeline.timeAxis.options.orientation.axis;

var itemTop = function () {
if (orientation == "bottom") {
return group.height - item.top - item.height;
Expand All @@ -591,18 +591,18 @@ function getItemVerticalScroll(timeline, item) {
var height = item.height;

if (targetOffset < currentScrollHeight) {
if (offset + leftHeight <= offset + itemTop() + height) {
if (offset + itemsetHeight <= offset + itemTop() + height) {
offset += itemTop() - timeline.itemSet.options.margin.item.vertical;
}
}
else if (targetOffset + height > currentScrollHeight + leftHeight) {
offset += itemTop() + height - leftHeight + timeline.itemSet.options.margin.item.vertical;
else if (targetOffset + height > currentScrollHeight + itemsetHeight) {
offset += itemTop() + height - itemsetHeight + timeline.itemSet.options.margin.item.vertical;
}
else {
shouldScroll = false;
}

offset = Math.min(offset, contentHeight - leftHeight);
offset = Math.min(offset, contentHeight - itemsetHeight);

return { shouldScroll: shouldScroll, scrollOffset: offset, itemTop: targetOffset };
}
Expand Down