Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Sep 27, 2019
1 parent 5b855a0 commit cea0cb4
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ export default {
if (!currentPosition) {
return null
}
const survivingParent = node.ancestors().find(({id}) => currentPosition.has(id))
return survivingParent ? currentPosition.get(survivingParent.id) : null
const visibleParent = node.ancestors().find(({id}) => currentPosition.has(id))
return visibleParent ? currentPosition.get(visibleParent.id) : null
}
const currentNodesById = new Map()
const getExitingParentIfAny = (node) => {
const survivingParent = node.ancestors().find(a => currentNodesById.has(a.id))
if (!survivingParent) {
const visibleParent = node.ancestors().find(a => currentNodesById.has(a.id))
if (!visibleParent) {
return {x: correctedSource.x, y: correctedSource.y}
}
return currentNodesById.get(survivingParent.id)
return currentNodesById.get(visibleParent.id)
}
const origin = currentPosition ? currentPosition.get(correctedSource.id) : {x: correctedSource.x0, y: correctedSource.y0}
const originBuilder = d => {
Expand All @@ -355,8 +355,8 @@ export default {
const newLinks = links.enter().append('path').attr('class', 'linktree').lower()
const nodes = this.internaldata.g.selectAll('.nodetree').data(root.descendants(), d => d.id)
const newNodes = nodes.enter().append('g').attr('class', d => `nodetree node-rank-${d.depth}`)
const allNodes = newNodes.merge(nodes).each(n => {
currentNodesById.set(n.id, n)
const allNodes = newNodes.merge(nodes).each(({id, x, y}) => {
currentNodesById.set(id, {x, y})
})
const { strokeWidth, layout, duration, drawLink } = this
Expand Down Expand Up @@ -432,11 +432,7 @@ export default {
.attr('text-anchor', d => d.layoutInfo.anchor)
.attr('transform', d => `rotate(${d.layoutInfo.textRotate})`)
const newPosition = new Map()
allNodes.each(({id, x, y}) => {
newPosition.set(id, {x, y})
})
this.currentPosition = newPosition
this.currentPosition = currentNodesById
const exitingNodes = nodes.exit()
exitingNodes.select('.node').transition().duration(transitionDuration)
Expand Down

0 comments on commit cea0cb4

Please sign in to comment.