Commit a2d8eff1 authored by Akikonata's avatar Akikonata

layout.bottom.js

parent f44593c4
describe( "protocal/plain", function () { describe("protocal/plain", function () {
var json, local, protocal; var json, local, protocal;
beforeEach( function () { beforeEach(function () {
protocal = KM.findProtocal( 'plain' ); protocal = KM.findProtocal('plain');
} ); });
it( '协议存在', function () { it('协议存在', function () {
expect( protocal ).toBeDefined(); expect(protocal).toBeDefined();
} ); });
it( '正确 encode', function () { it('正确 encode', function () {
json = { json = {
data: { data: {
text: 'root', text: 'root',
anyway: 'omg' anyway: 'omg'
}, },
children: [ { children: [{
data: { data: {
text: 'l1c1' text: 'l1c1'
} }
...@@ -22,7 +22,7 @@ describe( "protocal/plain", function () { ...@@ -22,7 +22,7 @@ describe( "protocal/plain", function () {
data: { data: {
text: 'l1c2' text: 'l1c2'
}, },
children: [ { children: [{
data: { data: {
text: 'l2c1' text: 'l2c1'
} }
...@@ -30,15 +30,15 @@ describe( "protocal/plain", function () { ...@@ -30,15 +30,15 @@ describe( "protocal/plain", function () {
data: { data: {
text: 'l2c2' text: 'l2c2'
} }
} ] }]
}, { }, {
data: { data: {
text: 'l1c3' text: 'l1c3'
} }
} ] }]
}; };
local = protocal.encode( json ); local = protocal.encode(json);
expect( local ).toBe( expect(local).toBe(
'root\n' + 'root\n' +
'\tl1c1\n' + '\tl1c1\n' +
'\tl1c2\n' + '\tl1c2\n' +
...@@ -46,5 +46,5 @@ describe( "protocal/plain", function () { ...@@ -46,5 +46,5 @@ describe( "protocal/plain", function () {
'\t\tl2c2\n' + '\t\tl2c2\n' +
'\tl1c3\n' '\tl1c3\n'
); );
} ); });
} ); });
\ No newline at end of file \ No newline at end of file
...@@ -36,9 +36,11 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -36,9 +36,11 @@ KityMinder.registerModule("LayoutBottom", function () {
} }
iconShape.addShapes([rect, plus, dec]); iconShape.addShapes([rect, plus, dec]);
this.update(); this.update();
this.switchState(); //this.switchState();
}, },
switchState: function () { switchState: function (val) {
if (val === true || val === false)
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);
...@@ -135,8 +137,6 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -135,8 +137,6 @@ KityMinder.registerModule("LayoutBottom", function () {
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();
// txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if (nodeType === "main") { if (nodeType === "main") {
var subgroup = Layout.subgroup = new kity.Group(); var subgroup = Layout.subgroup = new kity.Group();
minder.getRenderContainer().addShape(subgroup); minder.getRenderContainer().addShape(subgroup);
...@@ -185,7 +185,9 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -185,7 +185,9 @@ KityMinder.registerModule("LayoutBottom", function () {
var nLayout = node.getLayout(); var nLayout = node.getLayout();
var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[1] + nodeStyles.main.margin[3]; var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[1] + nodeStyles.main.margin[3];
var childwidth = 0; var childwidth = 0;
if (nLayout.added) childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[1] + nodeStyles.sub.margin[3]; if (nLayout.added) {
childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[1] + nodeStyles.sub.margin[3];
}
var branchwidth = nLayout.branchwidth = (selfwidth > childwidth ? selfwidth : childwidth); var branchwidth = nLayout.branchwidth = (selfwidth > childwidth ? selfwidth : childwidth);
return branchwidth; return branchwidth;
}; };
...@@ -218,7 +220,7 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -218,7 +220,7 @@ KityMinder.registerModule("LayoutBottom", function () {
var childLayout = children[i].getLayout(); var childLayout = children[i].getLayout();
childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0]; childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0];
} }
effectSet = effectSet.concat(children); effectSet = [_root];
} else if (nodeType === "main") { } else if (nodeType === "main") {
Layout.align = "left"; Layout.align = "left";
if (action === "append" || action === "contract") { if (action === "append" || action === "contract") {
...@@ -248,7 +250,7 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -248,7 +250,7 @@ KityMinder.registerModule("LayoutBottom", function () {
var prtLayout = prt.getLayout(); var prtLayout = prt.getLayout();
var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2]; var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2];
for (var i1 = 0; i1 < c.length; i1++) { for (var i1 = 0; i1 < c.length; i1++) {
branchHeight += c[i1].getLayout().branchheight; if (c[i1].getLayout().added) branchHeight += c[i1].getLayout().branchheight;
} }
prtLayout.branchheight = branchHeight; prtLayout.branchheight = branchHeight;
prt = prt.getParent(); prt = prt.getParent();
...@@ -257,6 +259,16 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -257,6 +259,16 @@ KityMinder.registerModule("LayoutBottom", function () {
var _buffer = [prt]; var _buffer = [prt];
while (_buffer.length !== 0) { while (_buffer.length !== 0) {
var childrenC = _buffer[0].getChildren(); var childrenC = _buffer[0].getChildren();
childrenC = (function () {
var result = [];
for (var len = 0; len < childrenC.length; len++) {
var l = childrenC[len].getLayout();
if (l.added) {
result.push(childrenC[len]);
}
}
return result;
})();
_buffer = _buffer.concat(childrenC); _buffer = _buffer.concat(childrenC);
var _buffer0Layout = _buffer[0].getLayout(); var _buffer0Layout = _buffer[0].getLayout();
var _buffer0Style = nodeStyles[_buffer[0].getType()]; var _buffer0Style = nodeStyles[_buffer[0].getType()];
...@@ -269,7 +281,7 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -269,7 +281,7 @@ KityMinder.registerModule("LayoutBottom", function () {
childLayoutC.y = sY + childStyleC.margin[0]; childLayoutC.y = sY + childStyleC.margin[0];
sY += childLayoutC.branchheight; sY += childLayoutC.branchheight;
} }
effectSet.push(_buffer[0]); if (_buffer[0] !== _root && _buffer[0].getLayout().added) effectSet.push(_buffer[0]);
_buffer.shift(); _buffer.shift();
} }
} }
...@@ -326,7 +338,7 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -326,7 +338,7 @@ KityMinder.registerModule("LayoutBottom", function () {
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
if (!Layout.connect) { if (!Layout.connect) {
connect = Layout.connect = new kity.Path(); connect = Layout.connect = new kity.Path();
Layout.subgroup.addShape(connect); parentLayout.subgroup.addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var ssX, ssY; var ssX, ssY;
...@@ -438,52 +450,39 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -438,52 +450,39 @@ KityMinder.registerModule("LayoutBottom", function () {
updateShapeByCont(_root); updateShapeByCont(_root);
updateLayoutAll(_root); updateLayoutAll(_root);
translateNode(_root); translateNode(_root);
var _buffer = [_root];
var _cleanbuffer = [];
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)) {
minder.expandNode(mains[i]);
}
} }
//打散结构
// while (_buffer.length !== 0) {
// var children = _buffer[0].getChildren();
// _buffer = _buffer.concat(children);
// for (var i = 0; i < children.length; i++) {
// children[i].getLayout().parent = _buffer[0];
// }
// _buffer[0].clearChildren();
// if (_buffer[0] !== _root) _cleanbuffer.push(_buffer[0]);
// _buffer.shift();
// }
// //重组结构
// for (var j = 0; j < _cleanbuffer.length; j++) {
// this.appendChildNode(_cleanbuffer[j].getLayout().parent, _cleanbuffer[j]);
// }
}, },
appendChildNode: function (parent, node, sibling) { appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node);
node.clearLayout(); node.clearLayout();
node.getContRc().clear(); node.getContRc().clear();
var Layout = node.getLayout(); var Layout = node.getLayout();
Layout = node.getLayout(); Layout = node.getLayout();
if (!Layout.added) minder.handelNodeInsert(node);
Layout.added = true; Layout.added = true;
initLayout(node);
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var children = parent.getChildren();
var exist = (children.indexOf(node) !== -1);
//设置分支类型 //设置分支类型
if (parent.getType() === "root") { if (parent.getType() === "root") {
node.setType("main"); node.setType("main");
node.setData("expand", true);
} else { } else {
node.setType("sub"); node.setType("sub");
//将节点加入到main分支的subgroup中 //将节点加入到main分支的subgroup中
parentLayout.subgroup.addShape(node.getRenderContainer()); parentLayout.subgroup.addShape(node.getRenderContainer());
node.getLayout().subgroup = parentLayout.subgroup; node.getLayout().subgroup = parentLayout.subgroup;
} }
initLayout(node);
if (sibling) { if (sibling) {
parent.insertChild(node, sibling.getIndex() + 1); if (!exist) parent.insertChild(node, sibling.getIndex() + 1);
} else { } else {
parent.appendChild(node); if (!exist) parent.appendChild(node);
} }
//计算位置等流程 //计算位置等流程
this._firePharse(new MinderEvent("RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
...@@ -511,13 +510,17 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -511,13 +510,17 @@ KityMinder.registerModule("LayoutBottom", function () {
translateNode(set [i]); translateNode(set [i]);
updateConnectAndshIcon(set [i]); updateConnectAndshIcon(set [i]);
} }
// if (node.getType() === "sub") { if (node.getType() === "sub") {
// var set1 = updateLayoutMain(); var set1 = updateLayoutMain();
// for (var j = 0; j < set1.length; j++) { for (var j = 0; j < set1.length; j++) {
// translateNode(set1[j]); translateNode(set1[j]);
// updateConnectAndshIcon(set1[j]); updateConnectAndshIcon(set1[j]);
// } }
// } }
parent.expand();
var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true);
}, },
appendSiblingNode: function (sibling, node) { appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent(); var parent = sibling.getParent();
...@@ -606,7 +609,7 @@ KityMinder.registerModule("LayoutBottom", function () { ...@@ -606,7 +609,7 @@ KityMinder.registerModule("LayoutBottom", function () {
_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 = updateLayoutAll(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]);
......
...@@ -262,7 +262,7 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -262,7 +262,7 @@ KityMinder.registerModule("LayoutDefault", function () {
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 () { 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();
......
...@@ -119,7 +119,7 @@ KityMinder.registerModule("LayoutModule", function () { ...@@ -119,7 +119,7 @@ KityMinder.registerModule("LayoutModule", function () {
var AppendChildNodeCommand = kity.createClass("AppendChildNodeCommand", (function () { var AppendChildNodeCommand = kity.createClass("AppendChildNodeCommand", (function () {
return { return {
base: Command, base: Command,
execute: function (km, node, silbling) { execute: function (km, node) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if (!parent) { if (!parent) {
...@@ -129,7 +129,7 @@ KityMinder.registerModule("LayoutModule", function () { ...@@ -129,7 +129,7 @@ KityMinder.registerModule("LayoutModule", function () {
km.expandNode(parent); km.expandNode(parent);
} }
parent.expand(); parent.expand();
km.appendChildNode(parent, node, silbling); km.appendChildNode(parent, node);
km.select(node, true); km.select(node, true);
return 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