Commit 64bd6a7c authored by Akikonata's avatar Akikonata

fixed update bug

parent 4823c4c0
...@@ -42,13 +42,13 @@ ...@@ -42,13 +42,13 @@
minder.execCommand("rendernode",_root); minder.execCommand("rendernode",_root);
//模拟生成一个初始图 //模拟生成一个初始图
// for(var j=0;j<20;j++){ for(var j=0;j<20;j++){
// var appendSide = Math.random()>0.5?"left":"right"; var appendSide = Math.random()>0.5?"left":"right";
// var layerArray = _root.getData("layer"+appendSide); var layerArray = _root.getData("layer"+appendSide);
// var layer = parseInt(Math.random()*layerArray.length); var layer = parseInt(Math.random()*layerArray.length);
// var layerData = layerArray[layer]; var layerData = layerArray[layer];
// var root = layerData[parseInt(Math.random()*layerData.length)] var root = layerData[parseInt(Math.random()*layerData.length)]
// minder.execCommand("createchildnode",root); minder.execCommand("createchildnode",root);
// } }
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -19,7 +19,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -19,7 +19,6 @@ KityMinder.registerModule( "LayoutModule", function () {
node.setData( "branchheight", defaultHeight + 10 ); node.setData( "branchheight", defaultHeight + 10 );
if ( isAdd ) { if ( isAdd ) {
var add = ( ( siblings.length === 1 && node.getParent() !== root ) ? 0 : ( defaultHeight + 10 ) ); var add = ( ( siblings.length === 1 && node.getParent() !== root ) ? 0 : ( defaultHeight + 10 ) );
console.log( add );
while ( parent || ( parent === root ) ) { while ( parent || ( parent === root ) ) {
var branchheight = parent.getData( appendSide + "Height" ) || parent.getData( "branchheight" ) || 0; var branchheight = parent.getData( appendSide + "Height" ) || parent.getData( "branchheight" ) || 0;
if ( parent === root ) { if ( parent === root ) {
...@@ -71,8 +70,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -71,8 +70,9 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
}; };
var getX = function ( node ) { var setX = function ( node ) {
var parent = node.getParent(); var parent = node.getParent();
if ( !parent ) return false;
var parentX = parent.getData( "x" ); var parentX = parent.getData( "x" );
var parentWidth = parent.getRenderContainer().getWidth(); var parentWidth = parent.getRenderContainer().getWidth();
var side = node.getData( "appendside" ); var side = node.getData( "appendside" );
...@@ -158,7 +158,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -158,7 +158,6 @@ KityMinder.registerModule( "LayoutModule", function () {
var rightCount = parent.getData( "layerright" ); var rightCount = parent.getData( "layerright" );
leftCount = leftCount[ 1 ] ? leftCount[ 1 ].length : 0; leftCount = leftCount[ 1 ] ? leftCount[ 1 ].length : 0;
rightCount = rightCount[ 1 ] ? rightCount[ 1 ].length : 0; rightCount = rightCount[ 1 ] ? rightCount[ 1 ].length : 0;
console.log( leftCount, rightCount );
if ( rightCount > leftCount && rightCount > 1 ) { if ( rightCount > leftCount && rightCount > 1 ) {
parent.setData( "appendside", "left" ); parent.setData( "appendside", "left" );
} else { } else {
...@@ -225,7 +224,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -225,7 +224,6 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
} }
var reAnal = updateBranchHeight( nodes[ i ], appendSide, root, false, parent ); var reAnal = updateBranchHeight( nodes[ i ], appendSide, root, false, parent );
console.log( layerArray );
if ( reAnal ) { if ( reAnal ) {
reAnalyze( km, layerArray, appendSide ); reAnalyze( km, layerArray, appendSide );
} }
...@@ -251,18 +249,21 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -251,18 +249,21 @@ KityMinder.registerModule( "LayoutModule", function () {
var root = km.getRoot(); var root = km.getRoot();
var rerender = false; var rerender = false;
for ( var key in feature ) { for ( var key in feature ) {
node.setData( "key", feature[ key ] ); node.setData( key, feature[ key ] );
if ( key === "text" ) { if ( key === "text" ) {
rerender = true; rerender = true;
} }
} }
if ( rerender && node !== root ) {
km.execCommand( "rendernode", node ); if ( rerender ) {
node.preTraverse( function ( subnode ) { node.preTraverse( function ( subnode ) {
subnode.setData( "x", getX( subnode ) ); setX( subnode );
km.execCommand( "rendernode", subnode ); km.execCommand( "rendernode", subnode );
} ); } );
} else {
km.execCommand( "rendernode", node );
} }
return node;
} }
}; };
} )() ); } )() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment