Skip to content

Commit

Permalink
Add order field to items
Browse files Browse the repository at this point in the history
  • Loading branch information
FranCarrascosaMS committed Jul 1, 2023
1 parent 3c060fd commit 05ddfdb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 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,7 +321,13 @@ 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++) {
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

0 comments on commit 05ddfdb

Please sign in to comment.