fix: rewrite graph calculate to calculation on root
This commit is contained in:
parent
5ea76afceb
commit
eec6f18650
19013
package-lock.json
generated
Normal file
19013
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -332,7 +332,7 @@ function CsComponent ({
|
|||||||
positions: (e) => {
|
positions: (e) => {
|
||||||
if (!e.cy().data('changed')) {
|
if (!e.cy().data('changed')) {
|
||||||
return e.data('oldPos')
|
return e.data('oldPos')
|
||||||
} else { e.removeData('oldPos') }
|
}
|
||||||
const id = e.id()
|
const id = e.id()
|
||||||
const incomming = e.cy().edges(`[target="${id}"]`)
|
const incomming = e.cy().edges(`[target="${id}"]`)
|
||||||
const layer = 0
|
const layer = 0
|
||||||
@ -363,7 +363,7 @@ function CsComponent ({
|
|||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const task = queue.pop()
|
const task = queue.pop()
|
||||||
if (task.children.length === 0) {
|
if (task.children.length === 0) {
|
||||||
task.parent.data('subtreeWidth', task.parent.height())
|
task.parent.data('subtreeWidth', task.parent.height()+50)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const unprocessed = task?.children.filter(e => {
|
const unprocessed = task?.children.filter(e => {
|
||||||
@ -379,32 +379,31 @@ function CsComponent ({
|
|||||||
|
|
||||||
task?.parent.data('subtreeWidth', task.children.reduce((p, n) => p + n.data('subtreeWidth'), 0))
|
task?.parent.data('subtreeWidth', task.children.reduce((p, n) => p + n.data('subtreeWidth'), 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
const pos = { x: 0, y: 0 }
|
const pos = { x: 0, y: 0 }
|
||||||
e.data('oldPos', pos)
|
e.data('oldPos', pos)
|
||||||
|
|
||||||
|
queue.push({task: children, parent: e})
|
||||||
|
while (queue.length) {
|
||||||
|
const task = queue.pop()
|
||||||
|
const oldPos = task.parent.data('oldPos')
|
||||||
|
let yoffset = oldPos.y - task.parent.data('subtreeWidth') / 2
|
||||||
|
task.task.forEach(n => {
|
||||||
|
const width = n.data('subtreeWidth')
|
||||||
|
|
||||||
|
console.log('ORORORORO',n.data(), yoffset, width, oldPos, task.parent.data('subtreeWidth'))
|
||||||
|
n.data('oldPos',{x: 250 * n.data('layer'),y: yoffset + width/2})
|
||||||
|
yoffset+=width
|
||||||
|
queue.push({task: n.cy().edges(`[source="${n.id()}"]`).targets(), parent: n})
|
||||||
|
})
|
||||||
|
}
|
||||||
return pos
|
return pos
|
||||||
} else {
|
} else {
|
||||||
if (e.cy().data('firstNode') !== 'root') {
|
|
||||||
e.cy().data('firstNode', 'nonroot')
|
const opos = e.data('oldPos')
|
||||||
return { x: 0, y: 0 }
|
if (opos) {
|
||||||
}
|
return opos
|
||||||
if (e.cy().data('firstNode') === undefined)
|
}
|
||||||
e.cy().data('firstNode', 'nonroot')
|
|
||||||
const parent = e.cy().edges(`[target="${e.id()}"]`)[0].source()
|
|
||||||
const wing = (parent.data('children') === 1) ? 0 : parent.data('subtreeWidth') / 2 + 50
|
|
||||||
const lastOffset = parent.data('lastChild')
|
|
||||||
const step = wing * 2 / (parent.data('children') - 1)
|
|
||||||
//e.removeData('subtreeWidth')
|
|
||||||
if (lastOffset !== undefined) {
|
|
||||||
parent.data('lastChild', lastOffset + step)
|
|
||||||
const pos = { x: 250 * e.data('layer'), y: (lastOffset + step) }
|
|
||||||
e.data('oldPos', pos)
|
|
||||||
return pos
|
|
||||||
} else {
|
|
||||||
parent.data('lastChild', parent.position().y - wing)
|
|
||||||
const pos = { x: 250 * e.data('layer'), y: (parent.position().y - wing) }
|
|
||||||
e.data('oldPos', pos)
|
|
||||||
return pos
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, // map of (node id) => (position obj); or function(node){ return somPos; }
|
}, // map of (node id) => (position obj); or function(node){ return somPos; }
|
||||||
zoom: undefined, // the zoom level to set (prob want fit = false if set)
|
zoom: undefined, // the zoom level to set (prob want fit = false if set)
|
||||||
@ -730,4 +729,4 @@ export default withErrorBoundary(CsComponent, {
|
|||||||
console.log(info)
|
console.log(info)
|
||||||
console.log(error)
|
console.log(error)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user