Skip to content

Commit

Permalink
remove unused task fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ANovokmet committed Jul 7, 2024
1 parent 57f41dc commit ac53f76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
26 changes: 16 additions & 10 deletions packages/svelte-gantt/src/core/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,24 @@ function _layoutRow(tasks: SvelteTask[], row: SvelteRow, params: LayoutRowParams
tasks.sort(_byStartThenByLongestSortFn);

const others: { [yPos: number]: SvelteTask[] } = {};
const context: { [taskId: PropertyKey]: { yPos?: number; intersects?: boolean; } } = {};
const ctx = (task: SvelteTask) => context[task.model.id] ?? (context[task.model.id] = {});

let maxYPos = 0;

for (const task of tasks) {
task.yPos = 0;
const c = ctx(task);
c.yPos = 0;
let fits = false;
while (!fits) {
const othersAtYPos = others[task.yPos] || [];
const othersAtYPos = others[c.yPos] || [];
fits = true;
for (const other of othersAtYPos) { // can use binary search to find this iterator
if (_intersects(task, other)) {
task.yPos++;
if (task.yPos > maxYPos) {
maxYPos = task.yPos;
ctx(task).intersects = ctx(other).intersects = true;
c.yPos++;
if (c.yPos > maxYPos) {
maxYPos = c.yPos;
}
fits = false;
break;
Expand All @@ -151,10 +155,10 @@ function _layoutRow(tasks: SvelteTask[], row: SvelteRow, params: LayoutRowParams
}
}

if (!others[task.yPos]) {
others[task.yPos] = [];
if (!others[c.yPos]) {
others[c.yPos] = [];
}
others[task.yPos].push(task);
others[c.yPos].push(task);

}

Expand All @@ -163,16 +167,18 @@ function _layoutRow(tasks: SvelteTask[], row: SvelteRow, params: LayoutRowParams
row.height = contentHeight * (maxYPos + 1) + 2 * params.rowPadding;

for (const task of tasks) {
const c = ctx(task);
task.height = contentHeight;
task.top = row.y + params.rowPadding + (task.height * task.yPos);
task.top = row.y + params.rowPadding + (task.height * c.yPos);
}
} else {
row.height = row.model.height || params.rowHeight;
const contentHeight = row.height - 2 * params.rowPadding;

for (const task of tasks) {
const c = ctx(task);
task.height = contentHeight / (maxYPos + 1);
task.top = row.y + params.rowPadding + (task.height * task.yPos);
task.top = row.y + params.rowPadding + (task.height * c.yPos);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions packages/svelte-gantt/src/core/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ export interface SvelteTask {
reflectedOnParent?: boolean;
reflectedOnChild?: boolean;
originalId?: PropertyKey;

/* pack layout fields */
intersectsWith?: SvelteTask[];
numYSlots?: number;
yPos?: number;
}

type CreateTaskParams = {
Expand Down

0 comments on commit ac53f76

Please sign in to comment.