From 31d11f3bed6122680a94bec250eb3e96a27430ad Mon Sep 17 00:00:00 2001 From: 08draven Date: Sun, 3 Nov 2024 04:32:04 -0500 Subject: [PATCH] fix tree trunaction --- js/app.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/js/app.js b/js/app.js index d5cccb1..ffcf2c0 100644 --- a/js/app.js +++ b/js/app.js @@ -1,5 +1,5 @@ -function genPos(id, fetchData) { +function genPos(id, fetchData, k) { let queue = [id]; let queueHead; @@ -15,7 +15,7 @@ function genPos(id, fetchData) { "date": fetchData[id].datetime_shared, "user": fetchData[id].username, "visible": status, - "x": '0', + "x": k + '', "y": 0, "offbranch": 0, "end": fetchData[id].children.length @@ -94,9 +94,19 @@ function sortPos(a, b) { async function main(fetchData) { - let rootId = fetchData['root_id']; + //let rootId = fetchData['root_id']; + + let pos = []; + + let filteredFetch = Object.keys(fetchData).filter(x => { + let a = fetchData[fetchData[x].parent_id]; + if (a && a.children.length < 1) a.children = [x] + return x != 'root_id' && !a + }).sort((a,b) => a - b); + for (let rootId in filteredFetch) { + pos = [...pos,...genPos(filteredFetch[rootId], fetchData, rootId)]; + } - let pos = genPos(rootId, fetchData); let posX = [];