Skip to content
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

Added mouseclick functionality + documentation #286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion js/src/timeline/doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,17 @@ <h2 id="Events">Events</h2>
</ul>
</td>
</tr>

<tr>
<td>timeselected</td>
<td>The custom time bar has been changed. Fired once after the user has mouse-clicked
anywhere on the timeline in order to select that time. The new custom time can be
retrieved by calling <code>getCustomTime</code> method.</td>
<td>
<ul>
<li><code>time</code>: Date. The new custom time.</li>
</ul>
</td>
</tr>
</table>

<h2 id="Styles">Styles</h2>
Expand Down
90 changes: 52 additions & 38 deletions js/src/timeline/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,14 @@ links.Timeline.prototype.onMouseUp = function (event) {
if (!params.moved && !params.zoomed) {
// mouse did not move -> user has selected an item

// Added functionality to obtain the timestamp for
// the time that was clicked, and fire off a 'timeselected' event.
mouseX = links.Timeline.getPageX(event);
var x = params.mouseX - links.Timeline.getAbsoluteLeft(this.dom.content);
var xstart = this.screenToTime(x);
this.eventParams.selectedTime = xstart;
this.trigger('timeselected');

if (params.target === this.dom.items.deleteButton) {
// delete item
if (this.selection) {
Expand Down Expand Up @@ -4329,13 +4337,13 @@ links.Timeline.ItemFloatingRange.prototype.isVisible = function (start, end) {
return false;
}

// NH check for no end value
if (this.end && this.start) {
return (this.end > start)
&& (this.start < end);
} else if (this.start) {
return (this.start < end);
} else if (this.end) {
// NH check for no end value
if (this.end && this.start) {
return (this.end > start)
&& (this.start < end);
} else if (this.start) {
return (this.start < end);
} else if (this.end) {
return (this.end > start);
} else {return true;}
};
Expand Down Expand Up @@ -4366,11 +4374,11 @@ links.Timeline.ItemFloatingRange.prototype.setPosition = function (left, right)
*/
links.Timeline.ItemFloatingRange.prototype.getLeft = function (timeline) {
// NH check for no start value
if (this.start) {
return timeline.timeToScreen(this.start);
} else {
return 0;
}
if (this.start) {
return timeline.timeToScreen(this.start);
} else {
return 0;
}
};

/**
Expand All @@ -4381,11 +4389,11 @@ links.Timeline.ItemFloatingRange.prototype.getLeft = function (timeline) {
*/
links.Timeline.ItemFloatingRange.prototype.getRight = function (timeline) {
// NH check for no end value
if (this.end) {
return timeline.timeToScreen(this.end);
} else {
return timeline.size.contentWidth;
}
if (this.end) {
return timeline.timeToScreen(this.end);
} else {
return timeline.size.contentWidth;
}
};

/**
Expand Down Expand Up @@ -4871,17 +4879,17 @@ links.Timeline.prototype.getGroup = function (groupName) {
groups.push(groupObj);
// sort the groups
if (this.options.groupsOrder == true) {
groups = groups.sort(function (a, b) {
if (a.content > b.content) {
return 1;
}
if (a.content < b.content) {
return -1;
}
return 0;
});
groups = groups.sort(function (a, b) {
if (a.content > b.content) {
return 1;
}
if (a.content < b.content) {
return -1;
}
return 0;
});
} else if (typeof(this.options.groupsOrder) == "function") {
groups = groups.sort(this.options.groupsOrder)
groups = groups.sort(this.options.groupsOrder)
}

// rebuilt the groupIndexes
Expand Down Expand Up @@ -5256,17 +5264,17 @@ links.Timeline.prototype.finalItemsPosition = function(items, groupBase, group)
}
} while (collidingItem);
}
if (group) {
if (axisOnTop) {
group.itemsHeight = (group.itemsHeight)
? Math.max(group.itemsHeight, finalItem.bottom - groupBase)
: finalItem.height + eventMargin;
} else {
group.itemsHeight = (group.itemsHeight)
? Math.max(group.itemsHeight, groupBase - finalItem.top)
: finalItem.height + eventMargin;
}
}
if (group) {
if (axisOnTop) {
group.itemsHeight = (group.itemsHeight)
? Math.max(group.itemsHeight, finalItem.bottom - groupBase)
: finalItem.height + eventMargin;
} else {
group.itemsHeight = (group.itemsHeight)
? Math.max(group.itemsHeight, groupBase - finalItem.top)
: finalItem.height + eventMargin;
}
}
}

return groupFinalItems;
Expand Down Expand Up @@ -5450,6 +5458,12 @@ links.Timeline.prototype.trigger = function (event) {
'time': new Date(this.customTime.valueOf())
};
break;
case 'timeselected':
properties = {
'time': new Date(this.eventParams.selectedTime.valueOf())
};
this.customTime = properties.time;
break;
}

// trigger the links event bus
Expand Down