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

Add order field to item #2

Merged
merged 4 commits into from
Jul 1, 2023
Merged
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
27 changes: 22 additions & 5 deletions lib/timeline/Stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ const EPSILON = 0.001; // used when checking collisions, to prevent round-off er
* @param {Item[]} items
*/
export function orderByStart(items) {
items.sort((a, b) => a.data.start - b.data.start);
items.sort((a, b) => {
if (a.data.order !== b.data.order) {
return a.data.order - b.data.order;
}

return a.data.start - b.data.start;
});
}

/**
Expand All @@ -16,6 +22,10 @@ export function orderByStart(items) {
*/
export function orderByEnd(items) {
items.sort((a, b) => {
if (a.data.order !== b.data.order) {
return a.data.order - b.data.order;
}

const aTime = ('end' in a.data) ? a.data.end : a.data.start;
const bTime = ('end' in b.data) ? b.data.end : b.data.start;

Expand Down Expand Up @@ -311,15 +321,22 @@ function performStacking(items, margins, compareTimes, shouldStack, shouldOthers
const horizontallyCollidingItems = itemsAlreadyPositioned
.slice(horizontalOverlapStartIndex, horizontalOverlapEndIndex)
.filter(i => itemStart < getItemEnd(i) - EPSILON && itemEnd - EPSILON > getItemStart(i))
.sort((a, b) => a.top - b.top);
.sort((a, b) => {
if (a.data.order !== b.data.order) {
return a.data.order - b.data.order;
}

return a.top - b.top;
});

// Keep moving the item down until it stops colliding with any other items
for(let i2 = 0; i2 < horizontallyCollidingItems.length; i2++) {
const otherItem = horizontallyCollidingItems[i2];

if(checkVerticalSpatialCollision(item, otherItem, margins)) {

// We won't check vertical collisions because don't want to share lanes with previous items.
//if(checkVerticalSpatialCollision(item, otherItem, margins)) {
item.top = otherItem.top + otherItem.height + margins.vertical;
}
//}
}

if(shouldOthersStack(item)) {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metrica-sports/vis-timeline",
"version": "1.0.0",
"version": "1.1.0",
"description": "Create a fully customizable, interactive timeline with items and ranges.",
"homepage": "https://visjs.github.io/vis-timeline/",
"license": "(Apache-2.0 OR MIT)",
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface LegendOptions {
export interface DataItem {
className?: string;
content: string;
order: number;
end?: DateType;
group?: any;
id?: IdType;
Expand Down