Skip to content

Commit

Permalink
merge fish bone
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Nov 6, 2014
2 parents b1d271c + 9da90ad commit f1cad44
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 80 deletions.
6 changes: 6 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,30 @@
{ 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/layout/fish-bone-slave.js', pack: 'edit|share|m-share' },

/* 连线 */
{ path: 'src/connect/bezier.js', pack: 'edit|share|m-share' },
{ path: 'src/connect/poly.js', pack: 'edit|share|m-share' },
{ path: 'src/connect/arc.js', pack: 'edit|share|m-share' },
{ path: 'src/connect/under.js', pack: 'edit|share|m-share' },
{ path: 'src/connect/l.js', pack: 'edit|share|m-share' },
{ path: 'src/connect/fish-bone-master.js', pack: 'edit|share|m-share' },

/* 皮肤 */
{ path: 'src/theme/default.js', pack: 'edit|share|m-share' },
{ path: 'src/theme/snow.js', pack: 'edit|share|m-share' },
{ path: 'src/theme/fresh.js', pack: 'edit|share|m-share' },
{ path: 'src/theme/fish.js', pack: 'edit|share|m-share' },
{ path: 'src/theme/wire.js', pack: 'edit|share|m-share' },

/* 模板 */
{ path: 'src/template/default.js', pack: 'edit|share|m-share' },
{ 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
5 changes: 4 additions & 1 deletion lang/zh-cn/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ KityMinder.LANG['zh-cn'] = {
'default': '思维导图',
'structure': '组织结构图',
'filetree': '目录组织图',
'right': '逻辑结构图'
'right': '逻辑结构图',
'fish-bone': '鱼骨头图'
},
'theme': {
'classic': '脑图经典',
'snow': '温柔冷光',
'fish': '鱼骨图',
'wire': '线框',
'fresh-red': '清新红',
'fresh-soil': '泥土黄',
'fresh-green': '文艺绿',
Expand Down
2 changes: 1 addition & 1 deletion lib/kity
3 changes: 2 additions & 1 deletion native-support/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
Header ( "Content-Disposition: attachment; filename=" . $downloadName . $T[ $type ] );
}

readfile( $file );
readfile( $file );
unlink( $file );
28 changes: 28 additions & 0 deletions src/connect/fish-bone-master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @fileOverview
*
* 鱼骨头主干连线
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/

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

var pout = parent.getLayoutVertexOut(),
pin = node.getLayoutVertexIn();

var abs = Math.abs;

var dy = abs(pout.y - pin.y),
dx = abs(pout.x - pin.x);

var pathData = [];

pathData.push('M', pout.x, pout.y);
pathData.push('h', dx - dy);
pathData.push('L', pin.x, pin.y);

connection.setMarker(null);
connection.setPathData(pathData);
});
15 changes: 8 additions & 7 deletions src/core/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Utils.extend(KityMinder, {

getLayoutInstance: function(name) {
var LayoutClass = KityMinder._layout[name];
if (!LayoutClass) throw new Error('Missing Layout: ' + name);
var layout = new LayoutClass();
if (!layout) throw new Error('Missing Layout: ' + name);
return layout;
}
});
Expand Down Expand Up @@ -239,27 +239,28 @@ kity.extendClass(Minder, {
node.setLayoutTransform(null);
});

function layoutNode(node) {
function layoutNode(node, round) {

// layout all children first
// 剪枝:收起的节点无需计算
if (node.isExpanded() || true) {
node.children.forEach(function(child) {
layoutNode(child);
layoutNode(child, round);
});
}

var layout = node.getLayoutInstance();
layout.doLayout(node, node.getChildren().filter(function(child) {
var childrenInFlow = node.getChildren().filter(function(child) {
return !child.hasLayoutOffset();
}));
});
layout.doLayout(node, childrenInFlow, round);
}

// 第一轮布局
layoutNode(this.getRoot());
layoutNode(this.getRoot(), 1);

// 第二轮布局
layoutNode(this.getRoot());
layoutNode(this.getRoot(), 2);

duration = duration ? 300 : 0;

Expand Down
149 changes: 82 additions & 67 deletions src/layout/filetree.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,83 @@
/* global Layout:true */
KityMinder.registerLayout('filetree', kity.createClass({
base: Layout,

doLayout: function(parent, children) {
var pBox = parent.getContentBox();
var indent = 20;

parent.setVertexOut(new kity.Point(pBox.left + indent, pBox.bottom));
parent.setLayoutVectorOut(new kity.Vector(0, 1));

if (!children.length) return;

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

child.setVertexIn(new kity.Point(cbox.left, cbox.cy));
child.setLayoutVectorIn(new kity.Vector(1, 0));
});

this.align(children, 'left');
this.stack(children, 'y');

var xAdjust = 0;
xAdjust += pBox.left;
xAdjust += indent;
xAdjust += children[0].getStyle('margin-left');
var yAdjust = 0;
yAdjust += pBox.bottom;
yAdjust += parent.getStyle('margin-bottom');
yAdjust += children[0].getStyle('margin-top');

this.move(children, xAdjust, yAdjust);

},

getOrderHint: function(node) {
var hint = [];
var box = node.getLayoutBox();
var offset = node.getLevel() > 1 ? 3 : 5;

hint.push({
type: 'up',
node: node,
area: {
x: box.x,
y: box.top - node.getStyle('margin-top') - offset,
width: box.width,
height: node.getStyle('margin-top')
},
path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
});

hint.push({
type: 'down',
node: node,
area: {
x: box.x,
y: box.bottom + offset,
width: box.width,
height: node.getStyle('margin-bottom')
},
path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
});
return hint;
}
}));

[-1, 1].forEach(function (dir) {
var name = 'filetree-' + (dir > 0 ? 'down' : 'up');

KityMinder.registerLayout(name, kity.createClass({
base: Layout,

doLayout: function(parent, children, round) {
var pBox = parent.getContentBox();
var indent = 20;

parent.setVertexOut(new kity.Point(pBox.left + indent, dir > 0 ? pBox.bottom : pBox.top));
parent.setLayoutVectorOut(new kity.Vector(0, dir));

if (!children.length) return;

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

child.setVertexIn(new kity.Point(cbox.left, cbox.cy));
child.setLayoutVectorIn(new kity.Vector(1, 0));
});

this.align(children, 'left');
this.stack(children, 'y');

var xAdjust = 0;
xAdjust += pBox.left;
xAdjust += indent;
xAdjust += children[0].getStyle('margin-left');

var yAdjust = 0;

if (dir > 0) {
yAdjust += pBox.bottom;
yAdjust += parent.getStyle('margin-bottom');
yAdjust += children[0].getStyle('margin-top');
} else {
yAdjust -= this.getTreeBox(children).bottom;
yAdjust += pBox.top;
yAdjust -= parent.getStyle('margin-top');
yAdjust -= children[0].getStyle('margin-bottom');
}

this.move(children, xAdjust, yAdjust);

},

getOrderHint: function(node) {
var hint = [];
var box = node.getLayoutBox();
var offset = node.getLevel() > 1 ? 3 : 5;

hint.push({
type: 'up',
node: node,
area: {
x: box.x,
y: box.top - node.getStyle('margin-top') - offset,
width: box.width,
height: node.getStyle('margin-top')
},
path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
});

hint.push({
type: 'down',
node: node,
area: {
x: box.x,
y: box.bottom + offset,
width: box.width,
height: node.getStyle('margin-bottom')
},
path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
});
return hint;
}
}));

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

doLayout: function(parent, children, round) {

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 cBox = child.getContentBox();
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(1, 1));
}
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');

var xAdjust = pBox.right + pMarginRight + cMarginLeft;
var yAdjustUp = pBox.cy - cMarginBottom - parent.getStyle('margin-top');
var yAdjustDown = pBox.cy + cMarginTop + parent.getStyle('margin-bottom');

this.move(upPart, xAdjust, yAdjustUp);
this.move(downPart, xAdjust + cMarginLeft, yAdjustDown);

// children.forEach(function(child, index) {
// var matrix = child.getLayoutTransform();
// var dx, dy;
// dx = matrix.getMatrix().e;
// dy = matrix.getMatrix().f;
// matrix.translate(-dx, -dy);
// matrix.rotate(index % 2 ? 45 : -45);
// matrix.translate(dx, dy);
// });

}
}));
Loading

0 comments on commit f1cad44

Please sign in to comment.