mirror of
https://github.com/clearml/clearml-web
synced 2025-01-31 06:26:57 +00:00
bottom-up design instead of top-down
This commit is contained in:
parent
93851b7a96
commit
af11a875bc
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {DagManagerService, DagModelItem} from '@ngneat/dag';
|
import { DagManagerService, DagModelItem } from '@ngneat/dag';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -7,35 +7,49 @@ import {DagManagerService, DagModelItem} from '@ngneat/dag';
|
|||||||
export class DagManagerUnsortedService<T extends DagModelItem> extends DagManagerService<T> {
|
export class DagManagerUnsortedService<T extends DagModelItem> extends DagManagerService<T> {
|
||||||
|
|
||||||
override convertArrayToDagModel(itemsArray: Array<T>): Array<Array<T>> {
|
override convertArrayToDagModel(itemsArray: Array<T>): Array<Array<T>> {
|
||||||
const result = [];
|
const result: Array<Array<T>> = [];
|
||||||
const levels = {};
|
const nodeLevels = new Map<number, number>();
|
||||||
|
const nodeChildren = new Map<number, number[]>();
|
||||||
|
|
||||||
const modify = (data, pid = 0, level = 0) =>
|
// Initialize nodeChildren
|
||||||
data
|
itemsArray.forEach(item => {
|
||||||
.filter(({ parentIds, stepId }) => {
|
item.parentIds.forEach(pid => {
|
||||||
if (levels[level] && levels[level].includes(stepId)) {
|
if (!nodeChildren.has(pid)) {
|
||||||
return false;
|
nodeChildren.set(pid, []);
|
||||||
}
|
}
|
||||||
return parentIds.includes(pid);
|
nodeChildren.get(pid).push(item.stepId);
|
||||||
})
|
});
|
||||||
.forEach((e) => {
|
});
|
||||||
if (!levels[level]) {
|
|
||||||
levels[level] = [];
|
|
||||||
}
|
|
||||||
levels[level].push(e.stepId);
|
|
||||||
|
|
||||||
if (this.findInDoubleArray(e.stepId, result) === -1) {
|
// Function to assign levels
|
||||||
if (!result[level]) {
|
const assignLevels = (item, currentLevel) => {
|
||||||
result[level] = [e];
|
const existingLevel = nodeLevels.get(item.stepId);
|
||||||
} else {
|
if (existingLevel === undefined || existingLevel < currentLevel) {
|
||||||
result[level].push(e);
|
nodeLevels.set(item.stepId, currentLevel);
|
||||||
}
|
const parents = itemsArray.filter(i => item.parentIds.includes(i.stepId));
|
||||||
}
|
parents.forEach(parent => {
|
||||||
|
assignLevels(parent, currentLevel + 1);
|
||||||
modify(data, e.stepId, level + 1);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Start from leaf nodes and work upwards
|
||||||
|
itemsArray.forEach(item => {
|
||||||
|
if (!nodeChildren.has(item.stepId)) {
|
||||||
|
assignLevels(item, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sort nodes by level and position them
|
||||||
|
const maxLevel = Math.max(...nodeLevels.values());
|
||||||
|
itemsArray.forEach(item => {
|
||||||
|
const level = maxLevel - nodeLevels.get(item.stepId);
|
||||||
|
if (!result[level]) {
|
||||||
|
result[level] = [];
|
||||||
|
}
|
||||||
|
result[level].push(item);
|
||||||
|
});
|
||||||
|
|
||||||
modify(itemsArray);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user