This repository was archived by the owner on Jul 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Hide vertically hidden ranged items in groups that are not visible #2062
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f1cb732
Hide vertically hidden ranged items in groups that are not visible
yotamberk f096f27
Fix misspelling
yotamberk bcb1789
Fix examples that do not contain groups
yotamberk 666a221
Merge branch 'vertical-visibility' of https://github.com/yotamberk/vi…
yotamberk 1bd62d4
Add example for vertical hidden ranged items
yotamberk e9bc845
Fix indent format in RangeItem
yotamberk 204ddb0
Fix example
yotamberk 59d98c7
Fix other examples after addition of vertical hiding range items in g…
yotamberk cb55268
Add case of zero margin axis
yotamberk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<html> | ||
<head> | ||
<title>Timeline | A lot of grouped data</title> | ||
|
||
<script src="../../../docs/js/jquery.min.js"></script> | ||
<script src="../../../dist/vis.js"></script> | ||
<link href="../../../dist/vis.css" rel="stylesheet" type="text/css" /> | ||
|
||
<style type="text/css"> | ||
body { | ||
color: #4D4D4D; | ||
font: 10pt arial; | ||
} | ||
</style> | ||
<script src="../../googleAnalytics.js"></script> | ||
</head> | ||
|
||
<body onresize="/*timeline.checkResize();*/"> | ||
<h1>Timeline vertical visibility</h1> | ||
|
||
|
||
<button onclick="showVisibleItems()">Show current visible items</button> | ||
<div> | ||
<h2>visible items:</h2> | ||
<h3 id="visibleItemsContainer"></h3> | ||
</div> | ||
|
||
<div id="mytimeline"></div> | ||
<br> | ||
|
||
<script> | ||
function showVisibleItems() { | ||
var a = timeline.getVisibleItems(); | ||
console.log(a); | ||
document.getElementById("visibleItemsContainer").innerHTML = "" | ||
document.getElementById("visibleItemsContainer").innerHTML += a; | ||
}; | ||
|
||
// get selected item count from url parameter | ||
var count = 1000; | ||
|
||
// create groups | ||
var groups = new vis.DataSet([ | ||
{id: 1, content: 'Truck 1'}, | ||
{id: 2, content: 'Truck 2'}, | ||
{id: 3, content: 'Truck 3'}, | ||
{id: 4, content: 'Truck 4'}, | ||
{id: 5, content: 'Truck 5'}, | ||
{id: 6, content: 'Truck 6'}, | ||
{id: 7, content: 'Truck 7'}, | ||
{id: 8, content: 'Truck 8'}, | ||
{id: 9, content: 'Truck 9'}, | ||
{id: 10, content: 'Truck 10'}, | ||
{id: 11, content: 'Truck 11'}, | ||
{id: 12, content: 'Truck 12'}, | ||
{id: 13, content: 'Truck 13'}, | ||
{id: 14, content: 'Truck 14'}, | ||
{id: 15, content: 'Truck 15'}, | ||
{id: 16, content: 'Truck 16'}, | ||
{id: 17, content: 'Truck 17'}, | ||
{id: 18, content: 'Truck 18'}, | ||
{id: 19, content: 'Truck 19'}, | ||
{id: 20, content: 'Truck 20'}, | ||
{id: 21, content: 'Truck 21'}, | ||
{id: 22, content: 'Truck 22'}, | ||
{id: 23, content: 'Truck 23'}, | ||
{id: 24, content: 'Truck 24'}, | ||
{id: 25, content: 'Truck 25'}, | ||
|
||
]); | ||
|
||
// create items | ||
var items = new vis.DataSet(); | ||
|
||
var order = 1; | ||
var truck = 1; | ||
for (var j = 0; j < 25; j++) { | ||
var date = new Date(); | ||
for (var i = 0; i < count/25; i++) { | ||
date.setHours(date.getHours() + 4 * (Math.random() < 0.2)); | ||
var start = new Date(date); | ||
|
||
date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4)); | ||
var end = new Date(date); | ||
|
||
items.add({ | ||
id: order, | ||
group: truck, | ||
start: start, | ||
end: end, | ||
content: 'Order ' + order | ||
}); | ||
|
||
order++; | ||
} | ||
truck++; | ||
} | ||
|
||
// specify options | ||
var options = { | ||
stack: true, | ||
maxHeight: 400, | ||
start: new Date(), | ||
end: new Date(1000*60*60*24 + (new Date()).valueOf()), | ||
editable: true, | ||
margin: { | ||
item: 10, // minimal margin between items | ||
axis: 5 // minimal margin between items and the axis | ||
}, | ||
orientation: 'top' | ||
}; | ||
|
||
|
||
// create a Timeline | ||
var container = document.getElementById('mytimeline'); | ||
timeline = new vis.Timeline(container, null, options); | ||
timeline.setGroups(groups); | ||
timeline.setItems(items); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,14 @@ RangeItem.prototype.baseClassName = 'vis-item vis-range'; | |
*/ | ||
RangeItem.prototype.isVisible = function(range) { | ||
// determine visibility | ||
return (this.data.start < range.end) && (this.data.end > range.start); | ||
}; | ||
var isVisible = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code formatting is broken here. Please check the indent of this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've fixed it |
||
// determine horizontal visibillity | ||
(this.data.start < range.end) && | ||
(this.data.end > range.start) && | ||
// determine vertical visibillity | ||
(this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && | ||
(this.parent.top + this.parent.height > - range.body.domProps.scrollTop) | ||
return isVisible;}; | ||
|
||
/** | ||
* Repaint the item | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the problem why examples with no groups are no longer working. Please rethink this lines again.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I solved it by add equals in the
Group.prototype._isGroupVisible = function (range) { var isVisible = (this.top <= range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && (this.top + this.height >= - range.body.domProps.scrollTop); return isVisible; }
So that when there are no groups, it will see it as one group with top 0 and we get 0==0 which leads to visible items.
This seems to solve the problem I caused. Examples now work well. Something doesn't sit well with me in this solution...
I think there should be a calculation of the initial group height and it should not be 0. It should calculate the height as if all the groups' items in the horizontal range are visible initially and then remove them if they aren't in the vertical range.
I'm working on a more elegant solution then the one supplied in this merge request.