Commit bb1ce915 authored by campaign's avatar campaign

merge

parents 7f3a4b42 eb7518f8
KityMinder.registerModule( "LayoutDefault", function () { KityMinder.registerModule("LayoutDefault", function () {
var _target = this.getRenderTarget(); var _target = this.getRenderTarget();
function getMinderSize() { function getMinderSize() {
...@@ -9,41 +9,41 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -9,41 +9,41 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
var minder = this; var minder = this;
//收缩-展开子树的节点 //收缩-展开子树的节点
var ShIcon = kity.createClass( "DefaultshIcon", ( function () { var ShIcon = kity.createClass("DefaultshIcon", (function () {
return { return {
constructor: function ( node ) { constructor: function (node) {
this._show = false; this._show = false;
this._node = node; this._node = node;
var iconShape = this.shape = new kity.Group(); var iconShape = this.shape = new kity.Group();
iconShape.class = "shicon"; iconShape.class = "shicon";
iconShape.icon = this; iconShape.icon = this;
var circle = this._circle = new kity.Circle().fill( "white" ).stroke( "gray" ).setRadius( 5 ); var circle = this._circle = new kity.Circle().fill("white").stroke("gray").setRadius(5);
var plus = this._plus = new kity.Path(); var plus = this._plus = new kity.Path();
plus.getDrawer() plus.getDrawer()
.moveTo( -3, 0 ) .moveTo(-3, 0)
.lineTo( 3, 0 ) .lineTo(3, 0)
.moveTo( 0, -3 ) .moveTo(0, -3)
.lineTo( 0, 3 ); .lineTo(0, 3);
plus.stroke( "gray" ); plus.stroke("gray");
var dec = this._dec = new kity.Path(); var dec = this._dec = new kity.Path();
dec.getDrawer() dec.getDrawer()
.moveTo( -3, 0 ) .moveTo(-3, 0)
.lineTo( 3, 0 ); .lineTo(3, 0);
dec.stroke( "gray" ); dec.stroke("gray");
minder.getRenderContainer().addShape( iconShape ); minder.getRenderContainer().addShape(iconShape);
iconShape.addShapes( [ circle, plus, dec ] ); iconShape.addShapes([circle, plus, dec]);
this.update(); this.update();
}, },
switchState: function ( val ) { switchState: function (val) {
if ( val === true || val === false ) if (val === true || val === false)
this._show = !val; this._show = !val;
if ( !this._show ) { if (!this._show) {
this._plus.setOpacity( 0 ); this._plus.setOpacity(0);
this._dec.setOpacity( 1 ); this._dec.setOpacity(1);
this._show = true; this._show = true;
} else { } else {
this._plus.setOpacity( 1 ); this._plus.setOpacity(1);
this._dec.setOpacity( 0 ); this._dec.setOpacity(0);
this._show = false; this._show = false;
} }
return this._show; return this._show;
...@@ -52,29 +52,29 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -52,29 +52,29 @@ KityMinder.registerModule( "LayoutDefault", function () {
var node = this._node; var node = this._node;
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var nodeX, nodeY = ( node.getType() === "main" ? Layout.y : ( Layout.y + nodeShape.getHeight() / 2 - 5 ) ); var nodeX, nodeY = (node.getType() === "main" ? Layout.y : (Layout.y + nodeShape.getHeight() / 2 - 5));
if ( Layout.appendside === "left" ) { if (Layout.appendside === "left") {
nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x - 5; nodeX = nodeShape.getRenderBox().closurePoints[1].x - 5;
} else { } else {
nodeX = nodeShape.getRenderBox().closurePoints[ 0 ].x + 6; nodeX = nodeShape.getRenderBox().closurePoints[0].x + 6;
if ( node.getType() === "main" ) nodeX -= 3; if (node.getType() === "main") nodeX -= 3;
} }
this.shape.setTranslate( nodeX, nodeY ); this.shape.setTranslate(nodeX, nodeY);
}, },
remove: function () { remove: function () {
this.shape.remove(); this.shape.remove();
} }
}; };
} )() ); })());
//求并集 //求并集
var uSet = function ( a, b ) { var uSet = function (a, b) {
for ( var i = 0; i < a.length; i++ ) { for (var i = 0; i < a.length; i++) {
var idx = b.indexOf( a[ i ] ); var idx = b.indexOf(a[i]);
if ( idx !== -1 ) { if (idx !== -1) {
b.splice( idx, 1 ); b.splice(idx, 1);
} }
} }
return a.concat( b ); return a.concat(b);
}; };
//样式的配置(包括颜色、字号等) //样式的配置(包括颜色、字号等)
var nodeStyles = { var nodeStyles = {
...@@ -82,8 +82,8 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -82,8 +82,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
color: '#430', color: '#430',
fill: '#e9df98', fill: '#e9df98',
fontSize: 24, fontSize: 24,
padding: [ 15.5, 25.5, 15.5, 25.5 ], padding: [15.5, 25.5, 15.5, 25.5],
margin: [ 0, 0, 0, 0 ], margin: [0, 0, 0, 0],
radius: 30, radius: 30,
highlight: 'rgb(254, 219, 0)', highlight: 'rgb(254, 219, 0)',
spaceLeft: 3, spaceLeft: 3,
...@@ -92,12 +92,12 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -92,12 +92,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
spaceBottom: 3 spaceBottom: 3
}, },
"main": { "main": {
stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ), stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
fill: '#A4c5c0', fill: '#A4c5c0',
color: "#333", color: "#333",
padding: [ 6.5, 20, 6.5, 20 ], padding: [6.5, 20, 6.5, 20],
fontSize: 16, fontSize: 16,
margin: [ 0, 10, 30, 50 ], margin: [0, 10, 30, 50],
radius: 10, radius: 10,
highlight: 'rgb(254, 219, 0)', highlight: 'rgb(254, 219, 0)',
spaceLeft: 5, spaceLeft: 5,
...@@ -107,11 +107,11 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -107,11 +107,11 @@ KityMinder.registerModule( "LayoutDefault", function () {
}, },
"sub": { "sub": {
stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ), stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
color: "white", color: "white",
fontSize: 12, fontSize: 12,
margin: [ 0, 10, 20, 6 ], margin: [0, 10, 20, 6],
padding: [ 5, 10, 5.5, 10 ], padding: [5, 10, 5.5, 10],
highlight: 'rgb(254, 219, 0)', highlight: 'rgb(254, 219, 0)',
spaceLeft: 4, spaceLeft: 4,
spaceRight: 0, spaceRight: 0,
...@@ -120,36 +120,36 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -120,36 +120,36 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
}; };
//更新背景 //更新背景
var updateBg = function ( node ) { var updateBg = function (node) {
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( node.getType() ) { switch (node.getType()) {
case "root": case "root":
case "main": case "main":
var bg = node.getBgRc().clear(); var bg = node.getBgRc().clear();
bg.addShape( Layout.bgShadow = new kity.Rect() ); bg.addShape(Layout.bgShadow = new kity.Rect());
bg.addShape( Layout.bgRect = new kity.Rect() ); bg.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill( nodeStyle.fill ).setRadius( nodeStyle.radius ); Layout.bgRect.fill(nodeStyle.fill).setRadius(nodeStyle.radius);
Layout.bgShadow.fill( 'black' ).setOpacity( 0.2 ).setRadius( nodeStyle.radius ).translate( 3, 5 ); Layout.bgShadow.fill('black').setOpacity(0.2).setRadius(nodeStyle.radius).translate(3, 5);
break; break;
case "sub": case "sub":
var underline = Layout.underline = new kity.Path(); var underline = Layout.underline = new kity.Path();
var highlightshape = Layout.highlightshape = new kity.Rect().setRadius( 4 ); var highlightshape = Layout.highlightshape = new kity.Rect().setRadius(4);
node.getBgRc().clear().addShapes( [ Layout.bgRect = new kity.Rect().setRadius( 4 ), highlightshape, underline ] ); node.getBgRc().clear().addShapes([Layout.bgRect = new kity.Rect().setRadius(4), highlightshape, underline]);
break; break;
default: default:
break; break;
} }
}; };
//初始化样式 //初始化样式
var initLayout = function ( node ) { var initLayout = function (node) {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
//var txtShape = node.getTextShape(); //var txtShape = node.getTextShape();
//txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 ); //txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if ( nodeType === "root" ) { if (nodeType === "root") {
Layout.leftList = []; Layout.leftList = [];
Layout.rightList = []; Layout.rightList = [];
Layout.leftHeight = 0; Layout.leftHeight = 0;
...@@ -157,213 +157,217 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -157,213 +157,217 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
}; };
//根据内容调整节点尺寸 //根据内容调整节点尺寸
var updateShapeByCont = function ( node ) { var updateShapeByCont = function (node) {
var contRc = node.getContRc(); var contRc = node.getContRc();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var _contRCWidth = contRc.getWidth(); var _contRCWidth = contRc.getWidth();
var _contRCHeight = contRc.getHeight(); var _contRCHeight = contRc.getHeight();
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( nodeType ) { switch (nodeType) {
case "root": case "root":
case "main": case "main":
var width = _contRCWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], var width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3],
height = _contRCHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ]; height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth( width ).setHeight( height ); Layout.bgRect.setWidth(width).setHeight(height);
Layout.bgShadow.setWidth( width ).setHeight( height ); Layout.bgShadow.setWidth(width).setHeight(height);
break; break;
case "sub": case "sub":
var _contWidth = contRc.getWidth(); var _contWidth = contRc.getWidth();
var _contHeight = contRc.getHeight(); var _contHeight = contRc.getHeight();
width = _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ]; width = _contWidth + nodeStyle.padding[1] + nodeStyle.padding[3];
height = _contHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ]; height = _contHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.underline.getDrawer() Layout.underline.getDrawer()
.clear() .clear()
.moveTo( 0, _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] ) .moveTo(0, _contHeight + nodeStyle.padding[2] + nodeStyle.padding[0])
.lineTo( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] ); .lineTo(_contWidth + nodeStyle.padding[1] + nodeStyle.padding[3], _contHeight + nodeStyle.padding[2] + nodeStyle.padding[0]);
Layout.underline.stroke( nodeStyle.stroke ); Layout.underline.stroke(nodeStyle.stroke);
Layout.highlightshape Layout.highlightshape
.setWidth( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ] ) .setWidth(_contWidth + nodeStyle.padding[1] + nodeStyle.padding[3])
.setHeight( _contHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ] ); .setHeight(_contHeight + nodeStyle.padding[0] + nodeStyle.padding[2]);
Layout.bgRect.setWidth( width ).setHeight( height ); Layout.bgRect.setWidth(width).setHeight(height);
break; break;
default: default:
break; break;
} }
contRc.setTranslate( nodeStyle.padding[ 3 ], nodeStyle.padding[ 0 ] + _contRCHeight / 2 ); var rBox = contRc.getRenderBox();
// contRc.setTranslate(nodeStyle.padding[3], nodeStyle.padding[0] - rBox.top);
// Todo:很坑的改法,不知为何就对了,需要处理
contRc.setTranslate(nodeStyle.padding[3], 0);
contRc.translate(0, nodeStyle.padding[0] - rBox.top);
}; };
//计算节点在垂直方向的位置 //计算节点在垂直方向的位置
var updateLayoutVertical = function ( node, parent, action ) { var updateLayoutVertical = function (node, parent, action) {
var root = minder.getRoot(); var root = minder.getRoot();
var effectSet = [ node ]; var effectSet = [node];
if ( action === "remove" ) { if (action === "remove") {
effectSet = []; effectSet = [];
} }
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var appendside = Layout.appendside; var appendside = Layout.appendside;
var countBranchHeight = function ( node, side ) { var countBranchHeight = function (node, side) {
var nodeStyle = nodeStyles[ node.getType() ]; var nodeStyle = nodeStyles[node.getType()];
var selfHeight = node.getRenderContainer().getHeight() + nodeStyle.margin[ 0 ] + nodeStyle.margin[ 2 ]; var selfHeight = node.getRenderContainer().getHeight() + nodeStyle.margin[0] + nodeStyle.margin[2];
var childHeight = ( function () { var childHeight = (function () {
var sum = 0; var sum = 0;
var children; var children;
if ( !side ) { if (!side) {
children = node.getChildren(); children = node.getChildren();
} else { } else {
children = node.getLayout()[ side + "List" ]; children = node.getLayout()[side + "List"];
} }
for ( var i = 0; i < children.length; i++ ) { for (var i = 0; i < children.length; i++) {
var childLayout = children[ i ].getLayout(); var childLayout = children[i].getLayout();
if ( children[ i ].getRenderContainer().getPaper() && children[ i ].getRenderContainer().getHeight() !== 0 ) if (children[i].getRenderContainer().getPaper() && children[i].getRenderContainer().getHeight() !== 0)
sum += childLayout.branchheight; sum += childLayout.branchheight;
} }
return sum; return sum;
} )(); })();
if ( side ) { if (side) {
return childHeight; return childHeight;
} else { } else {
return ( selfHeight > childHeight ? selfHeight : childHeight ); return (selfHeight > childHeight ? selfHeight : childHeight);
} }
}; };
if ( nodeType === "root" ) { if (nodeType === "root") {
Layout.y = getMinderSize().height / 2; Layout.y = getMinderSize().height / 2;
effectSet.push( node ); effectSet.push(node);
} else { } else {
if ( action === "append" || action === "contract" ) { if (action === "append" || action === "contract") {
var nodeHeight = node.getRenderContainer().getHeight() || ( node.getContRc().getHeight() + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ] ); var nodeHeight = node.getRenderContainer().getHeight() || (node.getContRc().getHeight() + nodeStyle.padding[0] + nodeStyle.padding[2]);
Layout.branchheight = nodeHeight + nodeStyle.margin[ 0 ] + nodeStyle.margin[ 2 ]; Layout.branchheight = nodeHeight + nodeStyle.margin[0] + nodeStyle.margin[2];
} else if ( action === "change" ) { } else if (action === "change") {
Layout.branchheight = countBranchHeight( node ); Layout.branchheight = countBranchHeight(node);
} }
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var parentShape = parent.getRenderContainer(); var parentShape = parent.getRenderContainer();
var prt = node.getParent() || parent; var prt = node.getParent() || parent;
//自底向上更新祖先元素的branchheight值 //自底向上更新祖先元素的branchheight值
while ( prt ) { while (prt) {
var prtLayout = prt.getLayout(); var prtLayout = prt.getLayout();
if ( prt.getType() === "root" ) { if (prt.getType() === "root") {
prtLayout[ appendside + "Height" ] = countBranchHeight( prt, appendside ); prtLayout[appendside + "Height"] = countBranchHeight(prt, appendside);
} else { } else {
prtLayout.branchheight = countBranchHeight( prt ); prtLayout.branchheight = countBranchHeight(prt);
} }
prt = prt.getParent(); prt = prt.getParent();
} }
} }
//自顶向下更新受影响一侧的y值 //自顶向下更新受影响一侧的y值
var updateSide = function ( appendside ) { var updateSide = function (appendside) {
var _buffer = [ root ]; var _buffer = [root];
while ( _buffer.length > 0 ) { while (_buffer.length > 0) {
var _buffer0Layout = _buffer[ 0 ].getLayout(); var _buffer0Layout = _buffer[0].getLayout();
var children = _buffer0Layout[ appendside + "List" ] || _buffer[ 0 ].getChildren(); var children = _buffer0Layout[appendside + "List"] || _buffer[0].getChildren();
var children = ( function () { var children = (function () {
var result = []; var result = [];
for ( var len = 0; len < children.length; len++ ) { for (var len = 0; len < children.length; len++) {
var l = children[ len ].getLayout(); var l = children[len].getLayout();
if ( l.added ) { if (l.added) {
result.push( children[ len ] ); result.push(children[len]);
} }
} }
return result; return result;
} )(); })();
_buffer = _buffer.concat( children ); _buffer = _buffer.concat(children);
var sY = _buffer0Layout.y - ( _buffer0Layout[ appendside + "Height" ] || _buffer0Layout.branchheight ) / 2; var sY = _buffer0Layout.y - (_buffer0Layout[appendside + "Height"] || _buffer0Layout.branchheight) / 2;
for ( var i = 0; i < children.length; i++ ) { for (var i = 0; i < children.length; i++) {
var childLayout = children[ i ].getLayout(); var childLayout = children[i].getLayout();
childLayout.y = sY + childLayout.branchheight / 2; childLayout.y = sY + childLayout.branchheight / 2;
sY += childLayout.branchheight; sY += childLayout.branchheight;
} }
if ( _buffer[ 0 ] !== root && _buffer[ 0 ].getLayout().added ) effectSet.push( _buffer[ 0 ] ); if (_buffer[0] !== root && _buffer[0].getLayout().added) effectSet.push(_buffer[0]);
_buffer.shift(); _buffer.shift();
} }
}; };
var sideList; var sideList;
if ( appendside ) { if (appendside) {
updateSide( appendside ); updateSide(appendside);
} else { } else {
updateSide( "left" ); updateSide("left");
updateSide( "right" ); updateSide("right");
} }
return effectSet; return effectSet;
}; };
//计算节点在水平方向的位置 //计算节点在水平方向的位置
var updateLayoutHorizon = function ( node ) { var updateLayoutHorizon = function (node) {
var nodeType = node.getType(); var nodeType = node.getType();
var parent = node.getParent(); var parent = node.getParent();
var effectSet = [ node ]; var effectSet = [node];
var Layout = node.getLayout(); var Layout = node.getLayout();
var _buffer = [ node ]; var _buffer = [node];
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
var prt = _buffer[ 0 ].getParent(); var prt = _buffer[0].getParent();
var children = _buffer[ 0 ].getChildren(); var children = _buffer[0].getChildren();
children = ( function () { children = (function () {
var result = []; var result = [];
for ( var len = 0; len < children.length; len++ ) { for (var len = 0; len < children.length; len++) {
var l = children[ len ].getLayout(); var l = children[len].getLayout();
if ( l.added ) { if (l.added) {
result.push( children[ len ] ); result.push(children[len]);
} }
} }
return result; return result;
} )(); })();
_buffer = _buffer.concat( children ); _buffer = _buffer.concat(children);
if ( !prt ) { if (!prt) {
Layout.x = getMinderSize().width / 2; Layout.x = getMinderSize().width / 2;
_buffer.shift(); _buffer.shift();
continue; continue;
} }
var parentLayout = prt.getLayout(); var parentLayout = prt.getLayout();
var parentWidth = prt.getRenderContainer().getWidth(); var parentWidth = prt.getRenderContainer().getWidth();
var parentStyle = nodeStyles[ prt.getType() ]; var parentStyle = nodeStyles[prt.getType()];
var childLayout = _buffer[ 0 ].getLayout(); var childLayout = _buffer[0].getLayout();
var childStyle = nodeStyles[ _buffer[ 0 ].getType() ]; var childStyle = nodeStyles[_buffer[0].getType()];
if ( parentLayout.align === "center" ) { if (parentLayout.align === "center") {
parentWidth = parentWidth / 2; parentWidth = parentWidth / 2;
} }
if ( childLayout.appendside === "left" ) { if (childLayout.appendside === "left") {
childLayout.x = parentLayout.x - parentWidth - parentStyle.margin[ 1 ] - childStyle.margin[ 3 ]; childLayout.x = parentLayout.x - parentWidth - parentStyle.margin[1] - childStyle.margin[3];
} else { } else {
childLayout.x = parentLayout.x + parentWidth + parentStyle.margin[ 1 ] + childStyle.margin[ 3 ]; childLayout.x = parentLayout.x + parentWidth + parentStyle.margin[1] + childStyle.margin[3];
} }
effectSet.push( _buffer[ 0 ] ); effectSet.push(_buffer[0]);
_buffer.shift(); _buffer.shift();
} }
return effectSet; return effectSet;
}; };
var translateNode = function ( node ) { var translateNode = function (node) {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var align = Layout.align; var align = Layout.align;
var _rectHeight = nodeShape.getHeight(); var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth(); var _rectWidth = nodeShape.getWidth();
switch ( align ) { switch (align) {
case "right": case "right":
nodeShape.setTranslate( Layout.x - _rectWidth, Layout.y - _rectHeight / 2 ); nodeShape.setTranslate(Layout.x - _rectWidth, Layout.y - _rectHeight / 2);
break; break;
case "center": case "center":
nodeShape.setTranslate( Layout.x - _rectWidth / 2, Layout.y - _rectHeight / 2 ); nodeShape.setTranslate(Layout.x - _rectWidth / 2, Layout.y - _rectHeight / 2);
break; break;
default: default:
nodeShape.setTranslate( Layout.x, Layout.y - _rectHeight / 2 ); nodeShape.setTranslate(Layout.x, Layout.y - _rectHeight / 2);
break; break;
} }
node.setPoint( Layout.x, Layout.y ); node.setPoint(Layout.x, Layout.y);
}; };
var updateConnectAndshIcon = function ( node ) { var updateConnectAndshIcon = function (node) {
var nodeType = node.getType(); var nodeType = node.getType();
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeStyle = nodeStyles[ node.getType() ]; var nodeStyle = nodeStyles[node.getType()];
var connect; var connect;
//更新连线 //更新连线
if ( nodeType === "main" ) { if (nodeType === "main") {
if ( !Layout.connect ) { if (!Layout.connect) {
connect = Layout.connect = new kity.Group(); connect = Layout.connect = new kity.Group();
var bezier = Layout.connect.bezier = new kity.Bezier(); var bezier = Layout.connect.bezier = new kity.Bezier();
var circle = Layout.connect.circle = new kity.Circle(); var circle = Layout.connect.circle = new kity.Circle();
connect.addShapes( [ bezier, circle ] ); connect.addShapes([bezier, circle]);
minder.getRenderContainer().addShape( connect ); minder.getRenderContainer().addShape(connect);
minder.getRoot().getRenderContainer().bringTop(); minder.getRoot().getRenderContainer().bringTop();
} }
var parent = minder.getRoot(); var parent = minder.getRoot();
...@@ -374,186 +378,172 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -374,186 +378,172 @@ KityMinder.registerModule( "LayoutDefault", function () {
var nodeClosurePoints = nodeShape.getRenderBox().closurePoints; var nodeClosurePoints = nodeShape.getRenderBox().closurePoints;
var sPos; var sPos;
var endPos; var endPos;
if ( Layout.appendside === "left" ) { if (Layout.appendside === "left") {
sPos = new kity.BezierPoint( rootX - 30, nodeClosurePoints[ 2 ].y + nodeShape.getHeight() / 2 ); sPos = new kity.BezierPoint(rootX - 30, nodeClosurePoints[2].y + nodeShape.getHeight() / 2);
endPos = new kity.BezierPoint( nodeClosurePoints[ 2 ].x + 3, nodeClosurePoints[ 2 ].y + nodeShape.getHeight() / 2 ); endPos = new kity.BezierPoint(nodeClosurePoints[2].x + 3, nodeClosurePoints[2].y + nodeShape.getHeight() / 2);
} else { } else {
sPos = new kity.BezierPoint( rootX + 30, nodeClosurePoints[ 3 ].y + nodeShape.getHeight() / 2 ); sPos = new kity.BezierPoint(rootX + 30, nodeClosurePoints[3].y + nodeShape.getHeight() / 2);
endPos = new kity.BezierPoint( nodeClosurePoints[ 3 ].x - 3, nodeClosurePoints[ 3 ].y + nodeShape.getHeight() / 2 ); endPos = new kity.BezierPoint(nodeClosurePoints[3].x - 3, nodeClosurePoints[3].y + nodeShape.getHeight() / 2);
} }
var sPosV = sPos.getVertex(); var sPosV = sPos.getVertex();
var endPosV = endPos.getVertex(); var endPosV = endPos.getVertex();
sPos.setVertex( rootX, rootY ); sPos.setVertex(rootX, rootY);
connect.bezier.setPoints( [ sPos, endPos ] ).stroke( nodeStyle.stroke ); connect.bezier.setPoints([sPos, endPos]).stroke(nodeStyle.stroke);
connect.circle.setCenter( endPosV.x + ( Layout.appendside === "left" ? -0.5 : -1.5 ), endPosV.y ).fill( "white" ).setRadius( 4 ); connect.circle.setCenter(endPosV.x + (Layout.appendside === "left" ? -0.5 : -1.5), endPosV.y).fill("white").setRadius(4);
} else if ( nodeType === "sub" ) { } else if (nodeType === "sub") {
if ( !Layout.connect ) { if (!Layout.connect) {
connect = Layout.connect = new kity.Path(); connect = Layout.connect = new kity.Path();
minder.getRenderContainer().addShape( connect ); minder.getRenderContainer().addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var parentShape = node.getParent().getRenderContainer(); var parentShape = node.getParent().getRenderContainer();
var parentBox = parentShape.getRenderBox(); var parentBox = parentShape.getRenderBox();
var parentLayout = node.getParent().getLayout(); var parentLayout = node.getParent().getLayout();
var parentStyle = nodeStyles[ node.getParent().getType() ]; var parentStyle = nodeStyles[node.getParent().getType()];
var Shape = node.getRenderContainer(); var Shape = node.getRenderContainer();
var sX, sY = parentLayout.y; var sX, sY = parentLayout.y;
var nodeX, nodeY = Shape.getRenderBox().closurePoints[ 1 ].y; var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y;
if ( Layout.appendside === "left" ) { if (Layout.appendside === "left") {
sX = parentBox.closurePoints[ 1 ].x - parentStyle.margin[ 1 ]; sX = parentBox.closurePoints[1].x - parentStyle.margin[1];
nodeX = Shape.getRenderBox().closurePoints[ 0 ].x; nodeX = Shape.getRenderBox().closurePoints[0].x;
connect.getDrawer() connect.getDrawer()
.clear() .clear()
.moveTo( sX, sY ) .moveTo(sX, sY)
.lineTo( sX, nodeY > sY ? ( nodeY - nodeStyle.margin[ 3 ] ) : ( nodeY + nodeStyle.margin[ 3 ] ) ); .lineTo(sX, nodeY > sY ? (nodeY - nodeStyle.margin[3]) : (nodeY + nodeStyle.margin[3]));
if ( nodeY > sY ) connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], 0, 1, nodeX, nodeY ); if (nodeY > sY) connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 1, nodeX, nodeY);
else connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], 0, 0, nodeX, nodeY ); else connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 0, nodeX, nodeY);
connect.stroke( nodeStyle.stroke ); connect.stroke(nodeStyle.stroke);
} else { } else {
sX = parentBox.closurePoints[ 0 ].x + parentStyle.margin[ 1 ]; sX = parentBox.closurePoints[0].x + parentStyle.margin[1];
nodeX = Shape.getRenderBox().closurePoints[ 1 ].x + 1; nodeX = Shape.getRenderBox().closurePoints[1].x + 1;
connect.getDrawer() connect.getDrawer()
.clear() .clear()
.moveTo( sX, sY ) .moveTo(sX, sY)
.lineTo( sX, nodeY > sY ? ( nodeY - nodeStyle.margin[ 3 ] ) : ( nodeY + nodeStyle.margin[ 3 ] ) ); .lineTo(sX, nodeY > sY ? (nodeY - nodeStyle.margin[3]) : (nodeY + nodeStyle.margin[3]));
if ( nodeY > sY ) connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], 0, 0, nodeX, nodeY ); if (nodeY > sY) connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 0, nodeX, nodeY);
else connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], 0, 1, nodeX, nodeY ); else connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 1, nodeX, nodeY);
connect.stroke( nodeStyle.stroke ); connect.stroke(nodeStyle.stroke);
} }
} }
//更新收放icon //更新收放icon
if ( nodeType !== "root" && node.getChildren().length !== 0 ) { if (nodeType !== "root" && node.getChildren().length !== 0) {
if ( !Layout.shicon ) { if (!Layout.shicon) {
Layout.shicon = new ShIcon( node ); Layout.shicon = new ShIcon(node);
} }
Layout.shicon.update(); Layout.shicon.update();
} }
}; };
// var showNodeInView = function ( node ) {
// // var padding = 5;
// // var viewport = minder.getPaper().getViewPort();
// // var offset = node.getRenderContainer().getRenderBox( minder.getRenderContainer() );
// // var tmpX = viewport.center.x * 2 - ( offset.x + offset.width );
// // var tmpY = viewport.center.y * 2 - ( offset.y + offset.height );
// // var dx = offset.x < 0 ? -offset.x : Math.min( tmpX, 0 );
// // var dy = offset.y < 0 ? -offset.y : Math.min( tmpY, 0 );
// // minder.getRenderContainer().fxTranslate( dx, dy, 100, "easeOutQuint" );
// };
var _style = { var _style = {
getCurrentLayoutStyle: function () { getCurrentLayoutStyle: function () {
return nodeStyles; return nodeStyles;
}, },
highlightNode: function ( node ) { highlightNode: function (node) {
var highlight = node.isHighlight(); var highlight = node.isHighlight();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( nodeType ) { switch (nodeType) {
case "root": case "root":
case "main": case "main":
if ( highlight ) { if (highlight) {
Layout.bgRect.fill( nodeStyle.highlight ); Layout.bgRect.fill(nodeStyle.highlight);
} else { } else {
Layout.bgRect.fill( nodeStyle.fill ); Layout.bgRect.fill(nodeStyle.fill);
} }
break; break;
case "sub": case "sub":
if ( highlight ) { if (highlight) {
Layout.highlightshape.fill( nodeStyle.highlight ).setOpacity( 1 ); Layout.highlightshape.fill(nodeStyle.highlight).setOpacity(1);
node.getTextShape().fill( node.getData( 'fontcolor' ) || 'black' ); node.getTextShape().fill(node.getData('fontcolor') || 'black');
} else { } else {
Layout.highlightshape.setOpacity( 0 ); Layout.highlightshape.setOpacity(0);
node.getTextShape().fill( node.getData( 'fontcolor' ) || 'white' ); node.getTextShape().fill(node.getData('fontcolor') || 'white');
} }
break; break;
default: default:
break; break;
} }
}, },
updateLayout: function ( node ) { updateLayout: function (node) {
node.getContRc().clear(); node.getContRc().clear();
this._firePharse( new MinderEvent( "RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNode", { this._firePharse(new MinderEvent("RenderNode", {
node: node node: node
}, false ) ); }, false));
updateShapeByCont( node ); updateShapeByCont(node);
var set1 = updateLayoutHorizon( node ); var set1 = updateLayoutHorizon(node);
var set2 = updateLayoutVertical( node, node.getParent(), "change" ); var set2 = updateLayoutVertical(node, node.getParent(), "change");
var set = uSet( set1, set2 ); var set = uSet(set1, set2);
for ( var i = 0; i < set.length; i++ ) { for (var i = 0; i < set.length; i++) {
translateNode( set[ i ] ); translateNode(set [i]);
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon(set [i]);
} }
if ( this.isNodeSelected( node ) ) { if (this.isNodeSelected(node)) {
this.highlightNode( node ) this.highlightNode(node)
} }
}, },
initStyle: function () { initStyle: function () {
//渲染根节点 //渲染根节点
var _root = minder.getRoot(); var _root = minder.getRoot();
var historyPoint = _root.getPoint(); var historyPoint = _root.getPoint();
if ( historyPoint ) historyPoint = JSON.parse( JSON.stringify( historyPoint ) ); if (historyPoint) historyPoint = JSON.parse(JSON.stringify(historyPoint));
minder.handelNodeInsert( _root ); minder.handelNodeInsert(_root);
//设置root的align //设置root的align
_root.getLayout().align = "center"; _root.getLayout().align = "center";
updateBg( _root ); updateBg(_root);
initLayout( _root ); initLayout(_root);
_root.getContRc().clear(); _root.getContRc().clear();
this._firePharse( new MinderEvent( "RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeCenter", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNode", { this._firePharse(new MinderEvent("RenderNode", {
node: _root node: _root
}, false ) ); }, false));
updateShapeByCont( _root ); updateShapeByCont(_root);
updateLayoutHorizon( _root ); updateLayoutHorizon(_root);
updateLayoutVertical( _root ); updateLayoutVertical(_root);
translateNode( _root ); translateNode(_root);
if ( historyPoint ) _root.setPoint( historyPoint.x, historyPoint.y ); if (historyPoint) _root.setPoint(historyPoint.x, historyPoint.y);
//渲染首层节点 //渲染首层节点
var mains = _root.getChildren(); var mains = _root.getChildren();
for ( var i = 0; i < mains.length; i++ ) { for (var i = 0; i < mains.length; i++) {
this.appendChildNode( _root, mains[ i ] ); this.appendChildNode(_root, mains[i]);
if ( mains[ i ].isExpanded() && ( mains[ i ].getChildren().length > 0 ) ) { if (mains[i].isExpanded() && (mains[i].getChildren().length > 0)) {
minder.expandNode( mains[ i ] ); minder.expandNode(mains[i]);
} }
} }
_root.setPoint( _root.getLayout().x, _root.getLayout().y ); _root.setPoint(_root.getLayout().x, _root.getLayout().y);
}, },
expandNode: function ( ico ) { expandNode: function (ico) {
var isExpand, node; var isExpand, node;
if ( ico instanceof MinderNode ) { if (ico instanceof MinderNode) {
node = ico; node = ico;
isExpand = node.getLayout().shicon.switchState(); isExpand = node.getLayout().shicon.switchState();
} else { } else {
...@@ -561,17 +551,17 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -561,17 +551,17 @@ KityMinder.registerModule( "LayoutDefault", function () {
node = ico.icon._node; node = ico.icon._node;
} }
var _buffer; var _buffer;
if ( isExpand ) { if (isExpand) {
node.expand(); node.expand();
//遍历子树展开需要展开的节点 //遍历子树展开需要展开的节点
_buffer = [ node ]; _buffer = [node];
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
var c = _buffer[ 0 ].getChildren(); var c = _buffer[0].getChildren();
if ( _buffer[ 0 ].isExpanded() && c.length !== 0 ) { if (_buffer[0].isExpanded() && c.length !== 0) {
for ( var x = 0; x < c.length; x++ ) { for (var x = 0; x < c.length; x++) {
minder.appendChildNode( _buffer[ 0 ], c[ x ] ); minder.appendChildNode(_buffer[0], c[x]);
} }
_buffer = _buffer.concat( c ); _buffer = _buffer.concat(c);
} }
_buffer.shift(); _buffer.shift();
} }
...@@ -579,26 +569,26 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -579,26 +569,26 @@ KityMinder.registerModule( "LayoutDefault", function () {
node.collapse(); node.collapse();
//遍历子树移除需要移除的节点 //遍历子树移除需要移除的节点
_buffer = node.getChildren(); _buffer = node.getChildren();
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
var Layout = _buffer[ 0 ].getLayout(); var Layout = _buffer[0].getLayout();
if ( Layout.added ) { if (Layout.added) {
Layout.added = false; Layout.added = false;
_buffer[ 0 ].getRenderContainer().remove(); _buffer[0].getRenderContainer().remove();
Layout.connect.remove(); Layout.connect.remove();
if ( Layout.shicon ) Layout.shicon.remove(); if (Layout.shicon) Layout.shicon.remove();
} }
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat(_buffer[0].getChildren());
_buffer.shift(); _buffer.shift();
} }
var set = updateLayoutVertical( node, node.getParent(), "contract" ); var set = updateLayoutVertical(node, node.getParent(), "contract");
for ( var i = 0; i < set.length; i++ ) { for (var i = 0; i < set.length; i++) {
translateNode( set[ i ] ); translateNode(set [i]);
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon(set [i]);
} }
} }
}, },
appendChildNode: function ( parent, node, focus, sibling ) { appendChildNode: function (parent, node, focus, sibling) {
minder.handelNodeInsert( node ); minder.handelNodeInsert(node);
var Layout = node.getLayout(); var Layout = node.getLayout();
node.clearLayout(); node.clearLayout();
node.getContRc().clear(); node.getContRc().clear();
...@@ -606,17 +596,17 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -606,17 +596,17 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.added = true; Layout.added = true;
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var children = parent.getChildren(); var children = parent.getChildren();
var exist = ( children.indexOf( node ) !== -1 ); var exist = (children.indexOf(node) !== -1);
if ( sibling ) { if (sibling) {
if ( !exist ) parent.insertChild( node, sibling.getIndex() + 1 ); if (!exist) parent.insertChild(node, sibling.getIndex() + 1);
var siblingLayout = sibling.getLayout(); var siblingLayout = sibling.getLayout();
Layout.appendside = siblingLayout.appendside; Layout.appendside = siblingLayout.appendside;
Layout.align = siblingLayout.align; Layout.align = siblingLayout.align;
if ( parent.getType() === "root" ) { if (parent.getType() === "root") {
minder.handelNodeInsert( node ); minder.handelNodeInsert(node);
var len = children.length; var len = children.length;
if ( len < 7 ) { if (len < 7) {
if ( len % 2 ) { if (len % 2) {
Layout.appendside = "right"; Layout.appendside = "right";
Layout.align = "left"; Layout.align = "left";
} else { } else {
...@@ -624,20 +614,20 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -624,20 +614,20 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.align = "right"; Layout.align = "right";
} }
} }
var sideList = parentLayout[ Layout.appendside + "List" ]; var sideList = parentLayout[Layout.appendside + "List"];
var idx = sideList.indexOf( sibling ); var idx = sideList.indexOf(sibling);
sideList.splice( idx + 1, 0, node ); sideList.splice(idx + 1, 0, node);
} }
} else { } else {
if ( parent.getType() !== "root" ) { if (parent.getType() !== "root") {
var prtLayout = parent.getLayout(); var prtLayout = parent.getLayout();
Layout.appendside = prtLayout.appendside; Layout.appendside = prtLayout.appendside;
Layout.align = prtLayout.align; Layout.align = prtLayout.align;
if ( !exist ) parent.appendChild( node ); if (!exist) parent.appendChild(node);
} else { } else {
var nodeP = node.getPoint(); var nodeP = node.getPoint();
if ( nodeP && nodeP.x && nodeP.y ) { if (nodeP && nodeP.x && nodeP.y) {
if ( nodeP.x > parent.getPoint().x ) { if (nodeP.x > parent.getPoint().x) {
Layout.appendside = "right"; Layout.appendside = "right";
Layout.align = "left"; Layout.align = "left";
} else { } else {
...@@ -645,7 +635,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -645,7 +635,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.align = "right"; Layout.align = "right";
} }
} else { } else {
if ( parentLayout.rightList.length > 1 && parentLayout.rightList.length > parentLayout.leftList.length ) { if (parentLayout.rightList.length > 1 && parentLayout.rightList.length > parentLayout.leftList.length) {
Layout.appendside = "left"; Layout.appendside = "left";
Layout.align = "right"; Layout.align = "right";
} else { } else {
...@@ -653,51 +643,51 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -653,51 +643,51 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.align = "left"; Layout.align = "left";
} }
} }
var sideList1 = parentLayout[ Layout.appendside + "List" ]; var sideList1 = parentLayout[Layout.appendside + "List"];
sideList1.push( node ); sideList1.push(node);
var idx1; var idx1;
if ( Layout.appendside === "right" ) { if (Layout.appendside === "right") {
idx1 = sideList1.length; idx1 = sideList1.length;
} else { } else {
idx1 = parent.getChildren().length; idx1 = parent.getChildren().length;
} }
if ( !exist ) parent.insertChild( node, idx1 ); if (!exist) parent.insertChild(node, idx1);
} }
} }
//设置分支类型 //设置分支类型
if ( parent.getType() === "root" ) { if (parent.getType() === "root") {
node.setType( "main" ); node.setType("main");
} else { } else {
node.setType( "sub" ); node.setType("sub");
} }
//计算位置等流程 //计算位置等流程
updateBg( node ); updateBg(node);
initLayout( node ); initLayout(node);
this._firePharse( new MinderEvent( "RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNode", { this._firePharse(new MinderEvent("RenderNode", {
node: node node: node
}, false ) ); }, false));
updateShapeByCont( node ); updateShapeByCont(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);
for ( var i = 0; i < set.length; i++ ) { for (var i = 0; i < set.length; i++) {
translateNode( set[ i ] ); translateNode(set [i]);
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon(set [i]);
} }
// if ( focus ) { // if ( focus ) {
...@@ -705,58 +695,58 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -705,58 +695,58 @@ KityMinder.registerModule( "LayoutDefault", function () {
// } // }
parent.expand(); parent.expand();
var shicon = parent.getLayout().shicon; var shicon = parent.getLayout().shicon;
if ( shicon ) shicon.switchState( true ); if (shicon) shicon.switchState(true);
}, },
appendSiblingNode: function ( sibling, node, focus ) { appendSiblingNode: function (sibling, node, focus) {
var parent = sibling.getParent(); var parent = sibling.getParent();
this.appendChildNode( parent, node, focus, sibling ); this.appendChildNode(parent, node, focus, sibling);
}, },
removeNode: function ( nodes ) { removeNode: function (nodes) {
nodes = utils.isArray(nodes) ? nodes : [nodes]; nodes = utils.isArray(nodes) ? nodes : [nodes];
while ( nodes.length !== 0 ) { while (nodes.length !== 0) {
var parent = nodes[ 0 ].getParent(); var parent = nodes[0].getParent();
if ( !parent ) { if (!parent) {
nodes.splice( 0, 1 ); nodes.splice(0, 1);
return false; return false;
} }
var nodeLayout = nodes[ 0 ].getLayout(); var nodeLayout = nodes[0].getLayout();
if ( parent.getType() === "root" ) { if (parent.getType() === "root") {
var sideList = parent.getLayout()[ nodeLayout.appendside + "List" ]; var sideList = parent.getLayout()[nodeLayout.appendside + "List"];
var index = sideList.indexOf( nodes[ 0 ] ); var index = sideList.indexOf(nodes[0]);
sideList.splice( index, 1 ); sideList.splice(index, 1);
} }
parent.removeChild( nodes[ 0 ] ); parent.removeChild(nodes[0]);
if ( parent.getType() !== "root" && parent.getChildren().length === 0 ) { if (parent.getType() !== "root" && parent.getChildren().length === 0) {
var prtLayout = parent.getLayout(); var prtLayout = parent.getLayout();
prtLayout.shicon.remove(); prtLayout.shicon.remove();
prtLayout.shicon = null; prtLayout.shicon = null;
} }
var set = updateLayoutVertical( nodes[ 0 ], parent, "remove" ); var set = updateLayoutVertical(nodes[0], parent, "remove");
for ( var j = 0; j < set.length; j++ ) { for (var j = 0; j < set.length; j++) {
translateNode( set[ j ] ); translateNode(set [j]);
updateConnectAndshIcon( set[ j ] ); updateConnectAndshIcon(set [j]);
} }
var _buffer = [ nodes[ 0 ] ]; var _buffer = [nodes[0]];
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat(_buffer[0].getChildren());
try { try {
_buffer[ 0 ].getRenderContainer().remove(); _buffer[0].getRenderContainer().remove();
var Layout = _buffer[ 0 ].getLayout(); var Layout = _buffer[0].getLayout();
Layout.connect.remove(); Layout.connect.remove();
Layout.shicon.remove(); Layout.shicon.remove();
} catch ( error ) { } catch (error) {
console.log( "isRemoved" ); console.log("isRemoved");
} }
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除 //检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf( _buffer[ 0 ] ); var idx = nodes.indexOf(_buffer[0]);
if ( idx !== -1 ) { if (idx !== -1) {
nodes.splice( idx, 1 ); nodes.splice(idx, 1);
} }
_buffer.shift(); _buffer.shift();
} }
} }
} }
}; };
this.addLayoutStyle( "default", _style ); this.addLayoutStyle("default", _style);
return {}; return {};
} ); });
\ No newline at end of file \ No newline at end of file
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