Skip to content

Commit

Permalink
添加鱼骨图布局 - Kick Off
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Oct 27, 2014
1 parent d8823e4 commit 16a0038
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
{ path: 'src/layout/mind.js', pack: 'edit|share|m-share' },
{ path: 'src/layout/filetree.js', pack: 'edit|share|m-share' },
{ path: 'src/layout/btree.js', pack: 'edit|share|m-share' },
{ path: 'src/layout/fish-bone-master.js', pack: 'edit|share|m-share' },

/* 连线 */
{ path: 'src/connect/bezier.js', pack: 'edit|share|m-share' },
Expand All @@ -78,6 +79,7 @@
{ path: 'src/template/structure.js', pack: 'edit|share|m-share' },
{ path: 'src/template/filetree.js', pack: 'edit|share|m-share' },
{ path: 'src/template/right.js', pack: 'edit|share|m-share' },
{ path: 'src/template/fish-bone.js', pack: 'edit|share|m-share' },

/* 模块 */
{ path: 'src/module/node.js', pack: 'edit|share|m-share' },
Expand Down
12 changes: 12 additions & 0 deletions src/connect/fish-bone-master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @fileOverview
*
* 鱼骨头主干连线
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/

KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, connection) {

});
57 changes: 57 additions & 0 deletions src/layout/fish-bone-master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @fileOverview
*
* 鱼骨图主骨架布局
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
/* global Layout:true */
KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
base: Layout,

doLayout: function(parent, children) {
var upPart = [],
downPart = [];

var child = children[0];
var pBox = parent.getContentBox();

parent.setVertexOut(new kity.Point(pBox.right, pBox.cy));
parent.setLayoutVectorOut(new kity.Vector(1, 0));

if (!child) return;

var pMarginRight = parent.getStyle('margin-right');
var cMarginLeft = child.getStyle('margin-left');
var cMarginTop = child.getStyle('margin-top');
var cMarginBottom = child.getStyle('margin-bottom');

children.forEach(function(child, index) {
child.setLayoutTransform(new kity.Matrix());
var cBox = child.getContentBox();

if (index % 2) {
downPart.push(child);
child.setVertexIn(new kity.Point(cBox.left, cBox.top));
child.setLayoutVectorIn(new kity.Vector(cMarginLeft, cMarginTop));
}
else {
upPart.push(child);
child.setVertexIn(new kity.Point(cBox.left, cBox.bottom));
child.setLayoutVectorIn(new kity.Vector(1, -1));
}

});

this.stack(upPart, 'x');
this.stack(downPart, 'x');

this.align(upPart, 'bottom');
this.align(downPart, 'top');

this.move(upPart, pMarginRight + cMarginLeft, -cMarginBottom);
this.move(downPart, pMarginRight + cMarginLeft + cMarginLeft, +cMarginTop);

}
}));
35 changes: 35 additions & 0 deletions src/template/fish-bone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @fileOverview
*
* 默认模板 - 鱼骨头模板
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/

KityMinder.registerTemplate('fish-bone', {

getLayout: function(node) {

if (node.getData('layout')) return node.getData('layout');

var level = node.getLevel();

// 根节点
if (level === 0) {
return 'fish-bone-master';
}

// 一级节点
if (level === 1) {
return 'right';
}

return node.parent.getLayout();
},

// getConnect: function(node) {
// if (node.getLevel() == 1) return 'arc';
// return 'under';
// }
});

0 comments on commit 16a0038

Please sign in to comment.