fix: NaN on add node
This commit is contained in:
parent
4623dfd2ee
commit
05b52e72a7
@ -1,7 +1,7 @@
|
|||||||
import { MessageIcon } from "@icons/messagIcon";
|
import { MessageIcon } from "@icons/messagIcon";
|
||||||
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
||||||
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
||||||
import TextareaAutosize from "@mui/base/TextareaAutosize";
|
import { TextareaAutosize } from "@mui/base/TextareaAutosize";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
FormControl,
|
FormControl,
|
||||||
|
@ -139,6 +139,7 @@ export const CsComponent = ({
|
|||||||
|
|
||||||
if (Object.keys(targetQuestion).length !== 0 && Object.keys(targetQuestion).length !== 0 && parentNodeContentId && parentNodeChildren !== undefined) {
|
if (Object.keys(targetQuestion).length !== 0 && Object.keys(targetQuestion).length !== 0 && parentNodeContentId && parentNodeChildren !== undefined) {
|
||||||
clearDataAfterAddNode({ parentNodeContentId, targetQuestion, parentNodeChildren })
|
clearDataAfterAddNode({ parentNodeContentId, targetQuestion, parentNodeChildren })
|
||||||
|
cy?.data('changed',true)
|
||||||
cy?.add([
|
cy?.add([
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
@ -152,7 +153,8 @@ export const CsComponent = ({
|
|||||||
target: targetQuestion.content.id
|
target: targetQuestion.content.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]).layout(lyopts).run()
|
])
|
||||||
|
cy?.layout(lyopts).run()
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar("Добавляемый вопрос не найден")
|
enqueueSnackbar("Добавляемый вопрос не найден")
|
||||||
}
|
}
|
||||||
@ -235,6 +237,8 @@ export const CsComponent = ({
|
|||||||
cy?.remove(edge)
|
cy?.remove(edge)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
removeButtons(targetNodeContentId)
|
||||||
|
cy?.data('changed',true)
|
||||||
cy?.layout(lyopts).run()
|
cy?.layout(lyopts).run()
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -277,10 +281,22 @@ export const CsComponent = ({
|
|||||||
|
|
||||||
|
|
||||||
const readyLO = (e) => {
|
const readyLO = (e) => {
|
||||||
|
console.log(e.cy.data('firstNode'),"SKEEER",e.cy.data('changed'))
|
||||||
|
if (e.cy.data('firstNode') === 'nonroot') {
|
||||||
|
e.cy.data('firstNode','root')
|
||||||
|
e.cy.nodes().sort((a,b) => (a.data('root')?1:-1)).layout(lyopts).run()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
e.cy.data('changed', false)
|
e.cy.data('changed', false)
|
||||||
|
e.cy.removeData('firstNode')
|
||||||
|
}
|
||||||
|
|
||||||
//удаляем иконки
|
//удаляем иконки
|
||||||
e.cy.nodes().forEach((ele: any) => {
|
e.cy.nodes().forEach((ele: any) => {
|
||||||
const data = ele.data()
|
const data = ele.data()
|
||||||
|
console.log(data)
|
||||||
data.id && removeButtons(data.id);
|
data.id && removeButtons(data.id);
|
||||||
})
|
})
|
||||||
initialPopperIcons(e)
|
initialPopperIcons(e)
|
||||||
@ -292,29 +308,33 @@ export const CsComponent = ({
|
|||||||
positions: (e) => {
|
positions: (e) => {
|
||||||
console.log('BBBBBBBBBBBBBBB', e.cy().data('changed'))
|
console.log('BBBBBBBBBBBBBBB', e.cy().data('changed'))
|
||||||
if (!e.cy().data('changed')) {
|
if (!e.cy().data('changed')) {
|
||||||
console.log(e.cy().data('changed'))
|
|
||||||
return e.data('oldPos')
|
return e.data('oldPos')
|
||||||
} console.log('POSITIIIIIIIONS')
|
} else {e.removeData('oldPos')}
|
||||||
|
console.log('POSITIIIIIIIONS')
|
||||||
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
|
||||||
e.removeData('lastChild')
|
e.removeData('lastChild')
|
||||||
|
|
||||||
if (incomming.length === 0) {
|
if (incomming.length === 0) {
|
||||||
const children = e.cy().edges(`[source="${id}"]`)
|
if (e.cy().data('firstNode') === undefined)
|
||||||
|
e.cy().data('firstNode','root')
|
||||||
|
e.data('root', true)
|
||||||
|
const children = e.cy().edges(`[source="${id}"]`).targets()
|
||||||
e.data('layer', layer)
|
e.data('layer', layer)
|
||||||
e.data('children', children.targets().length)
|
e.data('children', children.length)
|
||||||
const queue = []
|
const queue = []
|
||||||
children.forEach(n => {
|
children.forEach(n => {
|
||||||
queue.push({ task: n.target(), layer: layer + 1 })
|
queue.push({ task: n, layer: layer + 1 })
|
||||||
})
|
})
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const task = queue.pop()
|
const task = queue.pop()
|
||||||
task.task.data('layer', task.layer)
|
task.task.data('layer', task.layer)
|
||||||
const children = e.cy().edges(`[source="${task.task.id()}"]`)
|
console.log('SAMSHIIIIT',task.layer,task.task.data().layer)
|
||||||
task.task.data('children', children.targets().length)
|
const children = e.cy().edges(`[source="${task.task.id()}"]`).targets()
|
||||||
|
task.task.data('children', children.length)
|
||||||
if (children.length !== 0) {
|
if (children.length !== 0) {
|
||||||
children.forEach(n => queue.push({ task: n.target(), layer: task.layer + 1 }))
|
children.forEach(n => queue.push({ task: n, layer: task.layer + 1 }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queue.push({ parent: e, children: children.targets() })
|
queue.push({ parent: e, children: children.targets() })
|
||||||
@ -337,10 +357,18 @@ export const 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: 200 * e.data('layer'), y: 0 }
|
const pos = { x: 0, y: 0 }
|
||||||
|
console.log(e.data())
|
||||||
e.data('oldPos', pos)
|
e.data('oldPos', pos)
|
||||||
return pos
|
return pos
|
||||||
} else {
|
} else {
|
||||||
|
console.log(e.cy().data('firstNode'))
|
||||||
|
if (e.cy().data('firstNode') !== 'root') {
|
||||||
|
e.cy().data('firstNode','nonroot')
|
||||||
|
return {x:0,y:0}
|
||||||
|
}
|
||||||
|
if (e.cy().data('firstNode') === undefined)
|
||||||
|
e.cy().data('firstNode','nonroot')
|
||||||
const parent = e.cy().edges(`[target="${e.id()}"]`)[0].source()
|
const parent = e.cy().edges(`[target="${e.id()}"]`)[0].source()
|
||||||
const wing = (parent.data('children') === 1) ? 0 : parent.data('subtreeWidth') / 2
|
const wing = (parent.data('children') === 1) ? 0 : parent.data('subtreeWidth') / 2
|
||||||
const lastOffset = parent.data('lastChild')
|
const lastOffset = parent.data('lastChild')
|
||||||
@ -357,7 +385,7 @@ export const CsComponent = ({
|
|||||||
const pos = { x: 250 * e.data('layer'), y: (parent.position().y - wing) }
|
const pos = { x: 250 * e.data('layer'), y: (parent.position().y - wing) }
|
||||||
e.data('oldPos', pos)
|
e.data('oldPos', pos)
|
||||||
return 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user