Commit c20aca36 authored by Akikonata's avatar Akikonata

test

parent 7eae9ddd
Subproject commit b8fb560558e1100936211e4823063eeae1ad1c83 Subproject commit 8b33f729a570f3501769d16ad4c329c0e7f4e08d
...@@ -22,10 +22,10 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -22,10 +22,10 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return this.getData( 'point' ); return this.getData( 'point' );
}, },
setType: function ( type ) { setType: function ( type ) {
this._type = type;
}, },
getType: function ( type ) { getType: function ( type ) {
return this._type;
}, },
setText: function ( text ) { setText: function ( text ) {
this.setData( 'text', text ); this.setData( 'text', text );
......
...@@ -13,75 +13,74 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -13,75 +13,74 @@ KityMinder.registerModule( "LayoutDefault", function () {
//以某个节点为seed对整体高度进行更改计算 //以某个节点为seed对整体高度进行更改计算
var updateLayoutVertical = function ( node, parent, action ) { var updateLayoutVertical = function ( node, parent, action ) {
var effectSet = [ node ]; //用于返回受影响的节点集 var effectSet = [ node ]; //用于返回受影响的节点集
if ( !parent ) { node.getData( "layout" ).y = Math.random() * 400 + 300;
return effectSet; // if ( !parent ) {
} // return effectSet;
var Layout = node.getData( "layout" ); // }
var _style = Layout.style; // var Layout = node.getData( "layout" );
var marginTop = _style.margin[ 0 ], // var marginTop = Layout.margin[ 0 ],
marginBottom = _style.margin[ 2 ]; // marginBottom = Layout.margin[ 2 ];
var appendside = Layout.appendside; // var appendside = Layout.appendside;
var branchheight = Layout.branchheight || node.getRenderContainer().getHeight() + marginTop + marginBottom; // var branchheight = Layout.branchheight || node.getRenderContainer().getHeight() + marginTop + marginBottom;
var countY = function ( node, appendside ) { // var countY = function ( node, appendside ) {
var nodeLayout = node.getData( "layout" ); // var nodeLayout = node.getData( "layout" );
var centerY = nodeLayout.y; // var centerY = nodeLayout.y;
var nodeBranchHeight = nodeLayout[ appendside + "Height" ] || nodeLayout.branchheight; // var nodeBranchHeight = nodeLayout[ appendside + "Height" ] || nodeLayout.branchheight;
var nodeChildren = nodeLayout[ appendside + "List" ] || node.getChildren(); // var nodeChildren = nodeLayout[ appendside + "List" ] || node.getChildren();
var sY = centerY - nodeBranchHeight / 2; // var sY = centerY - nodeBranchHeight / 2;
if ( nodeChildren.length === 1 ) { // if ( nodeChildren.length === 1 ) {
var childrenLayout = nodeChildren[ 0 ].getData( "layout" ); // var childrenLayout = nodeChildren[ 0 ].getData( "layout" );
childrenLayout.y = centerY; // childrenLayout.y = centerY;
} else { // } else {
for ( var i = 0; i < nodeChildren.length; i++ ) { // for ( var i = 0; i < nodeChildren.length; i++ ) {
var childrenLayout1 = nodeChildren[ i ].getData( "layout" ); // var childrenLayout1 = nodeChildren[ i ].getData( "layout" );
if ( !childrenLayout1.shape ) break; // if ( !childrenLayout1.shape ) break;
var childBranchHeight = childrenLayout1.branchheight; // var childBranchHeight = childrenLayout1.branchheight;
childrenLayout1.y = sY + marginTop + childBranchHeight / 2; // childrenLayout1.y = sY + marginTop + childBranchHeight / 2;
sY += childBranchHeight; // sY += childBranchHeight;
} // }
} // }
return nodeChildren; // return nodeChildren;
}; // };
Layout.branchheight = branchheight; // Layout.branchheight = branchheight;
var parentLayout = parent.getData( "layout" ); // var parentLayout = parent.getData( "layout" );
var siblings = parentLayout[ appendside + "List" ] || parent.getChildren(); // var siblings = parentLayout[ appendside + "List" ] || parent.getChildren();
var getChildHeight = function ( node, appendside ) { // var getChildHeight = function ( node, appendside ) {
var sum = 0; // var sum = 0;
var nodeLayout = node.getData( "layout" ); // var nodeLayout = node.getData( "layout" );
var children = nodeLayout[ appendside + "List" ] || node.getChildren(); // var children = nodeLayout[ appendside + "List" ] || node.getChildren();
for ( var i = 0; i < children.length; i++ ) { // for ( var i = 0; i < children.length; i++ ) {
var childLayout = children[ i ].getData( "layout" ); // var childLayout = children[ i ].getData( "layout" );
if ( childLayout.shape ) sum += childLayout.branchheight; // if ( childLayout.shape ) sum += childLayout.branchheight;
} // }
return sum; // return sum;
}; // };
//方案: // //方案:
//增加节点时:1.节点和大于1 // //增加节点时:1.节点和大于1
//删除节点时:1.剩余节点和大于等于1 // //删除节点时:1.剩余节点和大于等于1
//更新branchheight // //更新branchheight
var prt = parent; // var prt = parent;
do { // do {
var minH = prt.getRenderContainer().getHeight() + marginTop + marginBottom; // var minH = prt.getRenderContainer().getHeight() + marginTop + marginBottom;
var childH = getChildHeight( prt, appendside ); // var childH = getChildHeight( prt, appendside );
var branchH = ( minH > childH ? minH : childH ); // var branchH = ( minH > childH ? minH : childH );
var prtLayout = prt.getData( "layout" ); // var prtLayout = prt.getData( "layout" );
if ( prt.getParent() ) {
prtLayout.branchheight = branchH;
} else {
prtLayout[ appendside + "Height" ] = branchH;
}
prt = prt.getParent();
} while ( prt );
//遍历
var _buffer = [ minder.getRoot() ];
while ( _buffer.length !== 0 ) {
_buffer = _buffer.concat( countY( _buffer[ 0 ], appendside ) );
effectSet.push( _buffer[ 0 ] );
_buffer.shift();
}
// if ( prt.getParent() ) {
// prtLayout.branchheight = branchH;
// } else {
// prtLayout[ appendside + "Height" ] = branchH;
// }
// prt = prt.getParent();
// } while ( prt );
// //遍历
// var _buffer = [ minder.getRoot() ];
// while ( _buffer.length !== 0 ) {
// _buffer = _buffer.concat( countY( _buffer[ 0 ], appendside ) );
// effectSet.push( _buffer[ 0 ] );
// _buffer.shift();
// }
return effectSet; return effectSet;
}; };
...@@ -92,41 +91,22 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -92,41 +91,22 @@ KityMinder.registerModule( "LayoutDefault", function () {
var parent = node.getParent(); var parent = node.getParent();
var appendside = nodeLayout.appendside; var appendside = nodeLayout.appendside;
var selfWidth = node.getRenderContainer().getWidth(); var selfWidth = node.getRenderContainer().getWidth();
if ( parent ) {
var parentLayout = parent.getData( "layout" );
var parentWidth = parent.getRenderContainer().getWidth();
if ( parentLayout.align === "center" ) parentWidth = parentWidth / 2;
var countX = function ( n ) { var parentX = parentLayout.x;
var nLayout = n.getData( "layout" ); switch ( appendside ) {
var prt = n.getParent();
var prtLayout = prt.getData( "layout" );
var parentX = prtLayout.x;
var parentWidth = prt.getRenderContainer().getWidth();
var parentAlign = prtLayout.align;
var selfAppendSide = nLayout.appendside;
if ( parentAlign === "center" ) parentWidth = parentWidth / 2;
var _style = nLayout.style;
var marginLeft = _style.margin[ 3 ];
var marginRight = _style.margin[ 1 ];
switch ( selfAppendSide ) {
case "left": case "left":
nLayout.x = parentX - parentWidth - marginLeft - marginRight; nodeLayout.x = parentX - parentWidth;
break; break;
case "right": case "right":
nLayout.x = parentX + parentWidth + marginLeft + marginRight; nodeLayout.x = parentX + parentWidth;
break; break;
default: default:
break; break;
} }
};
//判断根据父节点位置定位还是自身已经带有位置属性
if ( parent ) {
countX( node );
}
//判断是否存在已绘制的孩子并对孩子位置进行调整(用于外部调用renderNode,如文本编时)
var _buffer = node.getChildren();
while ( _buffer.length !== 0 ) {
countX( _buffer[ 0 ] );
effectSet.push( _buffer[ 0 ] );
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift();
} }
return effectSet; return effectSet;
}; };
...@@ -136,8 +116,8 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -136,8 +116,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var Layout = node.getData( "layout" ); var Layout = node.getData( "layout" );
var align = Layout.align; var align = Layout.align;
var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth(); var _rectWidth = nodeShape.getWidth();
var _rectHeight = nodeShape.getHeight();
switch ( align ) { switch ( align ) {
case "right": case "right":
nodeShape.setTransform( new kity.Matrix().translate( Layout.x - _rectWidth, Layout.y - _rectHeight / 2 ) ); nodeShape.setTransform( new kity.Matrix().translate( Layout.x - _rectWidth, Layout.y - _rectHeight / 2 ) );
...@@ -156,25 +136,46 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -156,25 +136,46 @@ KityMinder.registerModule( "LayoutDefault", function () {
var MainBranch = kity.createClass( "DefaultMainBranch", ( function () { var MainBranch = kity.createClass( "DefaultMainBranch", ( function () {
return { return {
constructor: function ( node ) { constructor: function ( node ) {
this._node = node;
var container = node.getRenderContainer(); var container = node.getRenderContainer();
var txt = this._txt = new kity.Text(); var txt = this._txt = new kity.Text();
var rect = this._rect = new kity.Rect(); var rect = this._rect = new kity.Rect();
container.addShapes( [ rect, txt ] );
var connect = this._connect = new kity.Bezier(); var connect = this._connect = new kity.Bezier();
var Layout = { var Layout = {
radius: 10, radius: 10,
fill: "skyblue", fill: "gray",
stroke: "white", stroke: new kity.Pen( "white", 1 ),
strokeWidth: 1, strokeWidth: 1,
color: "black", color: "black",
padding: [ 5, 10, 5, 10 ], padding: [ 5.5, 10, 5.5, 10 ],
fontSize: 20, fontSize: 20,
margin: [ 0, 10, 10, 50 ] margin: [ 0, 10, 10, 50 ],
shape: this,
align: ( "leftright" ).replace( node.getData( "layout" ).appendside, "" ),
appendside: node.getData( "layout" ).appendside
}; };
node.setData( "layout", Layout ); node.setData( "layout", Layout );
txt.translate( Layout.padding[ 3 ], Layout.padding[ 0 ] + 15 );
}, },
update: function ( node ) { update: function () {
var txt = this._txt;
var rect = this._rect;
var connect = this._connect;
var node = this._node;
var Layout = node.getData( "layout" );
txt.setContent( node.getData( "text" ) ).fill( Layout.color );
var _txtWidth = txt.getWidth();
var _txtHeight = txt.getHeight();
var _rectWidth = _txtWidth + Layout.padding[ 1 ] + Layout.padding[ 3 ];
var _rectHeight = _txtHeight + Layout.padding[ 0 ] + Layout.padding[ 2 ];
rect.setWidth( _rectWidth ).setHeight( _rectHeight ).fill( Layout.fill ).stroke( node.getData( "highlight" ) ? new kity.Pen( "white", 3 ) : Layout.stroke ).setRadius( Layout.radius );
var parentShape = node.getParent().getRenderContainer();
var pBox = parentShape.getRenderBox();
},
clear: function () {
this._node.getRenderContainer().clear();
this._connect.remove();
} }
}; };
} )() ); } )() );
...@@ -220,13 +221,13 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -220,13 +221,13 @@ KityMinder.registerModule( "LayoutDefault", function () {
x: minderWidth / 2, x: minderWidth / 2,
y: minderHeight / 2, y: minderHeight / 2,
align: "center", align: "center",
appendside: "right", appendside: node.getData( "layout" ).appendside || "right",
leftList: [], leftList: [],
rightList: [], rightList: [],
color: "white", color: "white",
fontSize: 20, fontSize: 20,
background: "burlywood", fill: "burlywood",
stroke: "white", stroke: new kity.Pen( "white", 1 ),
padding: [ 10.5, 20, 10.5, 20 ], padding: [ 10.5, 20, 10.5, 20 ],
radius: 15 radius: 15
}; };
...@@ -246,7 +247,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -246,7 +247,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var _txtHeight = txt.getHeight(); var _txtHeight = txt.getHeight();
var _rectWidth = _txtWidth + Layout.padding[ 1 ] + Layout.padding[ 3 ]; var _rectWidth = _txtWidth + Layout.padding[ 1 ] + Layout.padding[ 3 ];
var _rectHeight = _txtHeight + Layout.padding[ 0 ] + Layout.padding[ 2 ]; var _rectHeight = _txtHeight + Layout.padding[ 0 ] + Layout.padding[ 2 ];
rect.setWidth( _rectWidth ).setHeight( _rectHeight ).fill( Layout.background ).stroke( node.getData( "highlight" ) ? Layout.stroke : new kity.Pen( "white", 3 ) ).setRadius( Layout.radius ); rect.setWidth( _rectWidth ).setHeight( _rectHeight ).fill( Layout.fill ).stroke( node.getData( "highlight" ) ? new kity.Pen( "white", 3 ) : Layout.stroke ).setRadius( Layout.radius );
}, },
clear: function () { clear: function () {
this._node.getRenderContainer().clear(); this._node.getRenderContainer().clear();
...@@ -277,6 +278,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -277,6 +278,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
_root.setPoint( box.x, box.y ); _root.setPoint( box.x, box.y );
var _buffer = _root.getChildren(); var _buffer = _root.getChildren();
var Layout = _root.getData( "layout" ); var Layout = _root.getData( "layout" );
//根据保存的xy值初始化左右子树
if ( _buffer.length !== 0 ) { if ( _buffer.length !== 0 ) {
for ( var i = 0; i < _buffer.length; i++ ) { for ( var i = 0; i < _buffer.length; i++ ) {
var point = _buffer[ i ].getPoint(); var point = _buffer[ i ].getPoint();
...@@ -302,58 +304,42 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -302,58 +304,42 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, index ) {
minder.handelNodeInsert( node );
var _root = this.getRoot(); var _root = this.getRoot();
var childbranch; var childbranch;
if ( !node.getData( "layout" ) ) node.setData( "layout", {} );
if ( parent.getChildren().indexOf( node ) === -1 ) {
if ( !index ) parent.appendChild( node );
else parent.insertChild( node, index );
}
var parentLayout = parent.getData( "layout" );
var Layout = node.getData( "layout" );
if ( parent.getType() === "root" ) { if ( parent.getType() === "root" ) {
node.setType( "main" );
var leftList = parentLayout.leftList;
var rightList = parentLayout.rightList;
var sibling = parent.getChildren();
var aside = Layout.appendside;
if ( !aside ) {
if ( rightList.length > 1 && rightList.length > leftList.length ) {
aside = "left";
} else {
aside = "right";
}
Layout.appendside = aside;
}
if ( leftList.indexOf( node ) !== -1 ) {
Layout.appendside = "left";
} else if ( rightList.indexOf( node ) !== -1 ) {
Layout.appendside = "right";
} else {
parentLayout.appendside = aside;
parentLayout[ aside + "List" ].push( node );
}
childbranch = new MainBranch( node ); childbranch = new MainBranch( node );
} else { } else {
childbranch = new SubBranch( node ); childbranch = new SubBranch( node );
} }
// if ( !node.getData( "layout" ) ) node.setData( "layout", {} );
// var Layout = node.getData( "layout" );
// var parentLayout = parent.getData( "layout" );
// var minder = this;
// if ( parent.getChildren().indexOf( node ) === -1 ) {
// if ( !index ) parent.appendChild( node );
// else parent.insertChild( node, index );
// }
// minder.handelNodeInsert( node );
// if ( parent === _root ) {
// node.setType( "main" );
// var leftList = parentLayout.leftList;
// var rightList = parentLayout.rightList;
// var sibling = parent.getChildren();
// var aside = Layout.appendside;
// if ( !aside ) {
// if ( rightList.length > 1 && rightList.length > leftList.length ) {
// aside = "left";
// } else {
// aside = "right";
// }
// Layout.appendside = aside;
// }
// if ( leftList.indexOf( node ) !== -1 ) {
// Layout.appendside = "left";
// } else if ( rightList.indexOf( node ) !== -1 ) {
// Layout.appendside = "right";
// } else {
// parentLayout.appendside = aside;
// parentLayout[ aside + "List" ].push( node );
// }
// } else {
// node.setType( "sub" );
// }
// var appendside = Layout.appendside || parentLayout.appendside;
// Layout.appendside = appendside;
// if ( appendside === "left" ) {
// Layout.align = "right";
// } else {
// Layout.align = "left";
// }
// drawNode( node );
// var set1 = updateLayoutVertical( node, parent, "append" ); // var set1 = updateLayoutVertical( node, parent, "append" );
// var set2 = updateLayoutHorizon( node ); // var set2 = updateLayoutHorizon( node );
// var set = uSet( set1, set2 ); // var set = uSet( set1, set2 );
...@@ -363,13 +349,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -363,13 +349,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
// set[ i ].setPoint( box.x, box.y ); // set[ i ].setPoint( box.x, box.y );
// } // }
}, },
updateLayout: function ( node ) {
drawNode( node );
var set = updateLayoutHorizon( node );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
}
},
appendSiblingNode: function ( sibling, node ) { appendSiblingNode: function ( sibling, node ) {
var siblingLayout = sibling.getData( "layout" ); var siblingLayout = sibling.getData( "layout" );
if ( !node.getData( "layout" ) ) { if ( !node.getData( "layout" ) ) {
...@@ -384,7 +363,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -384,7 +363,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
var root = this.getRoot(); var root = this.getRoot();
var minder = this;
for ( var i = 0; i < nodes.length; i++ ) { for ( var i = 0; i < nodes.length; i++ ) {
var parent = nodes[ i ].getParent(); var parent = nodes[ i ].getParent();
if ( parent ) { if ( parent ) {
...@@ -392,6 +370,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -392,6 +370,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var parentLayout = parent.getData( "layout" ); var parentLayout = parent.getData( "layout" );
while ( _buffer.length !== 0 ) { while ( _buffer.length !== 0 ) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer[ 0 ].getData( "layout" ).shape.clear();
_buffer[ 0 ].getRenderContainer().remove(); _buffer[ 0 ].getRenderContainer().remove();
var prt = _buffer[ 0 ].getParent(); var prt = _buffer[ 0 ].getParent();
prt.removeChild( _buffer[ 0 ] ); prt.removeChild( _buffer[ 0 ] );
......
...@@ -96,8 +96,10 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -96,8 +96,10 @@ KityMinder.registerModule( "LayoutModule", function () {
execute: function ( km, node ) { execute: function ( km, node ) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( selectedNode.isRoot() ) { if ( selectedNode.isRoot() ) {
node.setType( "main" );
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node );
} else { } else {
node.setType( "sub" );
km.appendSiblingNode( selectedNode, node ); km.appendSiblingNode( selectedNode, node );
} }
km.select( node, true ); km.select( node, true );
......
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