Skip to content

Commit f1cad44

Browse files
committed
merge fish bone
2 parents b1d271c + 9da90ad commit f1cad44

File tree

19 files changed

+437
-80
lines changed

19 files changed

+437
-80
lines changed

import.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,30 @@
6060
{ path: 'src/layout/mind.js', pack: 'edit|share|m-share' },
6161
{ path: 'src/layout/filetree.js', pack: 'edit|share|m-share' },
6262
{ path: 'src/layout/btree.js', pack: 'edit|share|m-share' },
63+
{ path: 'src/layout/fish-bone-master.js', pack: 'edit|share|m-share' },
64+
{ path: 'src/layout/fish-bone-slave.js', pack: 'edit|share|m-share' },
6365

6466
/* 连线 */
6567
{ path: 'src/connect/bezier.js', pack: 'edit|share|m-share' },
6668
{ path: 'src/connect/poly.js', pack: 'edit|share|m-share' },
6769
{ path: 'src/connect/arc.js', pack: 'edit|share|m-share' },
6870
{ path: 'src/connect/under.js', pack: 'edit|share|m-share' },
6971
{ path: 'src/connect/l.js', pack: 'edit|share|m-share' },
72+
{ path: 'src/connect/fish-bone-master.js', pack: 'edit|share|m-share' },
7073

7174
/* 皮肤 */
7275
{ path: 'src/theme/default.js', pack: 'edit|share|m-share' },
7376
{ path: 'src/theme/snow.js', pack: 'edit|share|m-share' },
7477
{ path: 'src/theme/fresh.js', pack: 'edit|share|m-share' },
78+
{ path: 'src/theme/fish.js', pack: 'edit|share|m-share' },
79+
{ path: 'src/theme/wire.js', pack: 'edit|share|m-share' },
7580

7681
/* 模板 */
7782
{ path: 'src/template/default.js', pack: 'edit|share|m-share' },
7883
{ path: 'src/template/structure.js', pack: 'edit|share|m-share' },
7984
{ path: 'src/template/filetree.js', pack: 'edit|share|m-share' },
8085
{ path: 'src/template/right.js', pack: 'edit|share|m-share' },
86+
{ path: 'src/template/fish-bone.js', pack: 'edit|share|m-share' },
8187

8288
/* 模块 */
8389
{ path: 'src/module/node.js', pack: 'edit|share|m-share' },

lang/zh-cn/zh-cn.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ KityMinder.LANG['zh-cn'] = {
33
'default': '思维导图',
44
'structure': '组织结构图',
55
'filetree': '目录组织图',
6-
'right': '逻辑结构图'
6+
'right': '逻辑结构图',
7+
'fish-bone': '鱼骨头图'
78
},
89
'theme': {
910
'classic': '脑图经典',
1011
'snow': '温柔冷光',
12+
'fish': '鱼骨图',
13+
'wire': '线框',
1114
'fresh-red': '清新红',
1215
'fresh-soil': '泥土黄',
1316
'fresh-green': '文艺绿',

native-support/export.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@
3131
Header ( "Content-Disposition: attachment; filename=" . $downloadName . $T[ $type ] );
3232
}
3333

34-
readfile( $file );
34+
readfile( $file );
35+
unlink( $file );

src/connect/fish-bone-master.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @fileOverview
3+
*
4+
* 鱼骨头主干连线
5+
*
6+
* @author: techird
7+
* @copyright: Baidu FEX, 2014
8+
*/
9+
10+
KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, connection) {
11+
12+
var pout = parent.getLayoutVertexOut(),
13+
pin = node.getLayoutVertexIn();
14+
15+
var abs = Math.abs;
16+
17+
var dy = abs(pout.y - pin.y),
18+
dx = abs(pout.x - pin.x);
19+
20+
var pathData = [];
21+
22+
pathData.push('M', pout.x, pout.y);
23+
pathData.push('h', dx - dy);
24+
pathData.push('L', pin.x, pin.y);
25+
26+
connection.setMarker(null);
27+
connection.setPathData(pathData);
28+
});

src/core/layout.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Utils.extend(KityMinder, {
1717

1818
getLayoutInstance: function(name) {
1919
var LayoutClass = KityMinder._layout[name];
20+
if (!LayoutClass) throw new Error('Missing Layout: ' + name);
2021
var layout = new LayoutClass();
21-
if (!layout) throw new Error('Missing Layout: ' + name);
2222
return layout;
2323
}
2424
});
@@ -239,27 +239,28 @@ kity.extendClass(Minder, {
239239
node.setLayoutTransform(null);
240240
});
241241

242-
function layoutNode(node) {
242+
function layoutNode(node, round) {
243243

244244
// layout all children first
245245
// 剪枝:收起的节点无需计算
246246
if (node.isExpanded() || true) {
247247
node.children.forEach(function(child) {
248-
layoutNode(child);
248+
layoutNode(child, round);
249249
});
250250
}
251251

252252
var layout = node.getLayoutInstance();
253-
layout.doLayout(node, node.getChildren().filter(function(child) {
253+
var childrenInFlow = node.getChildren().filter(function(child) {
254254
return !child.hasLayoutOffset();
255-
}));
255+
});
256+
layout.doLayout(node, childrenInFlow, round);
256257
}
257258

258259
// 第一轮布局
259-
layoutNode(this.getRoot());
260+
layoutNode(this.getRoot(), 1);
260261

261262
// 第二轮布局
262-
layoutNode(this.getRoot());
263+
layoutNode(this.getRoot(), 2);
263264

264265
duration = duration ? 300 : 0;
265266

src/layout/filetree.js

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,83 @@
11
/* global Layout:true */
2-
KityMinder.registerLayout('filetree', kity.createClass({
3-
base: Layout,
4-
5-
doLayout: function(parent, children) {
6-
var pBox = parent.getContentBox();
7-
var indent = 20;
8-
9-
parent.setVertexOut(new kity.Point(pBox.left + indent, pBox.bottom));
10-
parent.setLayoutVectorOut(new kity.Vector(0, 1));
11-
12-
if (!children.length) return;
13-
14-
children.forEach(function(child) {
15-
var cbox = child.getContentBox();
16-
child.setLayoutTransform(new kity.Matrix());
17-
18-
child.setVertexIn(new kity.Point(cbox.left, cbox.cy));
19-
child.setLayoutVectorIn(new kity.Vector(1, 0));
20-
});
21-
22-
this.align(children, 'left');
23-
this.stack(children, 'y');
24-
25-
var xAdjust = 0;
26-
xAdjust += pBox.left;
27-
xAdjust += indent;
28-
xAdjust += children[0].getStyle('margin-left');
29-
var yAdjust = 0;
30-
yAdjust += pBox.bottom;
31-
yAdjust += parent.getStyle('margin-bottom');
32-
yAdjust += children[0].getStyle('margin-top');
33-
34-
this.move(children, xAdjust, yAdjust);
35-
36-
},
37-
38-
getOrderHint: function(node) {
39-
var hint = [];
40-
var box = node.getLayoutBox();
41-
var offset = node.getLevel() > 1 ? 3 : 5;
42-
43-
hint.push({
44-
type: 'up',
45-
node: node,
46-
area: {
47-
x: box.x,
48-
y: box.top - node.getStyle('margin-top') - offset,
49-
width: box.width,
50-
height: node.getStyle('margin-top')
51-
},
52-
path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
53-
});
54-
55-
hint.push({
56-
type: 'down',
57-
node: node,
58-
area: {
59-
x: box.x,
60-
y: box.bottom + offset,
61-
width: box.width,
62-
height: node.getStyle('margin-bottom')
63-
},
64-
path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
65-
});
66-
return hint;
67-
}
68-
}));
2+
3+
[-1, 1].forEach(function (dir) {
4+
var name = 'filetree-' + (dir > 0 ? 'down' : 'up');
5+
6+
KityMinder.registerLayout(name, kity.createClass({
7+
base: Layout,
8+
9+
doLayout: function(parent, children, round) {
10+
var pBox = parent.getContentBox();
11+
var indent = 20;
12+
13+
parent.setVertexOut(new kity.Point(pBox.left + indent, dir > 0 ? pBox.bottom : pBox.top));
14+
parent.setLayoutVectorOut(new kity.Vector(0, dir));
15+
16+
if (!children.length) return;
17+
18+
children.forEach(function(child) {
19+
var cbox = child.getContentBox();
20+
child.setLayoutTransform(new kity.Matrix());
21+
22+
child.setVertexIn(new kity.Point(cbox.left, cbox.cy));
23+
child.setLayoutVectorIn(new kity.Vector(1, 0));
24+
});
25+
26+
this.align(children, 'left');
27+
this.stack(children, 'y');
28+
29+
var xAdjust = 0;
30+
xAdjust += pBox.left;
31+
xAdjust += indent;
32+
xAdjust += children[0].getStyle('margin-left');
33+
34+
var yAdjust = 0;
35+
36+
if (dir > 0) {
37+
yAdjust += pBox.bottom;
38+
yAdjust += parent.getStyle('margin-bottom');
39+
yAdjust += children[0].getStyle('margin-top');
40+
} else {
41+
yAdjust -= this.getTreeBox(children).bottom;
42+
yAdjust += pBox.top;
43+
yAdjust -= parent.getStyle('margin-top');
44+
yAdjust -= children[0].getStyle('margin-bottom');
45+
}
46+
47+
this.move(children, xAdjust, yAdjust);
48+
49+
},
50+
51+
getOrderHint: function(node) {
52+
var hint = [];
53+
var box = node.getLayoutBox();
54+
var offset = node.getLevel() > 1 ? 3 : 5;
55+
56+
hint.push({
57+
type: 'up',
58+
node: node,
59+
area: {
60+
x: box.x,
61+
y: box.top - node.getStyle('margin-top') - offset,
62+
width: box.width,
63+
height: node.getStyle('margin-top')
64+
},
65+
path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
66+
});
67+
68+
hint.push({
69+
type: 'down',
70+
node: node,
71+
area: {
72+
x: box.x,
73+
y: box.bottom + offset,
74+
width: box.width,
75+
height: node.getStyle('margin-bottom')
76+
},
77+
path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
78+
});
79+
return hint;
80+
}
81+
}));
82+
83+
});

src/layout/fish-bone-master.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @fileOverview
3+
*
4+
* 鱼骨图主骨架布局
5+
*
6+
* @author: techird
7+
* @copyright: Baidu FEX, 2014
8+
*/
9+
/* global Layout:true */
10+
KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
11+
base: Layout,
12+
13+
doLayout: function(parent, children, round) {
14+
15+
var upPart = [],
16+
downPart = [];
17+
18+
var child = children[0];
19+
var pBox = parent.getContentBox();
20+
21+
parent.setVertexOut(new kity.Point(pBox.right, pBox.cy));
22+
parent.setLayoutVectorOut(new kity.Vector(1, 0));
23+
24+
if (!child) return;
25+
26+
var cBox = child.getContentBox();
27+
var pMarginRight = parent.getStyle('margin-right');
28+
var cMarginLeft = child.getStyle('margin-left');
29+
var cMarginTop = child.getStyle('margin-top');
30+
var cMarginBottom = child.getStyle('margin-bottom');
31+
32+
children.forEach(function(child, index) {
33+
child.setLayoutTransform(new kity.Matrix());
34+
var cBox = child.getContentBox();
35+
36+
if (index % 2) {
37+
downPart.push(child);
38+
child.setVertexIn(new kity.Point(cBox.left, cBox.top));
39+
child.setLayoutVectorIn(new kity.Vector(1, 1));
40+
}
41+
else {
42+
upPart.push(child);
43+
child.setVertexIn(new kity.Point(cBox.left, cBox.bottom));
44+
child.setLayoutVectorIn(new kity.Vector(1, -1));
45+
}
46+
47+
});
48+
49+
this.stack(upPart, 'x');
50+
this.stack(downPart, 'x');
51+
52+
this.align(upPart, 'bottom');
53+
this.align(downPart, 'top');
54+
55+
var xAdjust = pBox.right + pMarginRight + cMarginLeft;
56+
var yAdjustUp = pBox.cy - cMarginBottom - parent.getStyle('margin-top');
57+
var yAdjustDown = pBox.cy + cMarginTop + parent.getStyle('margin-bottom');
58+
59+
this.move(upPart, xAdjust, yAdjustUp);
60+
this.move(downPart, xAdjust + cMarginLeft, yAdjustDown);
61+
62+
// children.forEach(function(child, index) {
63+
// var matrix = child.getLayoutTransform();
64+
// var dx, dy;
65+
// dx = matrix.getMatrix().e;
66+
// dy = matrix.getMatrix().f;
67+
// matrix.translate(-dx, -dy);
68+
// matrix.rotate(index % 2 ? 45 : -45);
69+
// matrix.translate(dx, dy);
70+
// });
71+
72+
}
73+
}));

0 commit comments

Comments
 (0)