Skip to content

Commit

Permalink
add tianpan test
Browse files Browse the repository at this point in the history
  • Loading branch information
baipgydx729 committed Mar 27, 2015
1 parent e4e1487 commit 4c16313
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 19 deletions.
1 change: 1 addition & 0 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
{ 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/arc_tp.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' },
Expand Down
52 changes: 52 additions & 0 deletions src/connect/arc_tp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @fileOverview
*
* 圆弧连线
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/

var connectMarker = new kity.Marker().pipe(function() {
var r = 7;
var dot = new kity.Circle(r - 1);
this.addShape(dot);
this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
this.dot = dot;
this.node.setAttribute('markerUnits', 'userSpaceOnUse');
});

KityMinder.registerConnectProvider('arc_tp', function(node, parent, connection, width, color) {
var end_box = node.getLayoutBox(),
start_box = parent.getLayoutBox();


if(node.getIndex()>0){
var index = node.getIndex();
start_box = parent.getChildren()[index-1].getLayoutBox();
}


var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = end_box.x > start_box.x ? 'right' : 'left';

node.getMinder().getPaper().addResource(connectMarker);

start = new kity.Point(start_box.cx, start_box.cy);
end = new kity.Point(end_box.cx, end_box.cy);

var jl = Math.sqrt(Math.abs(start.x -end.x) * Math.abs(start.x - end.x) + Math.abs(start.y -end.y) * Math.abs(start.y -end.y)); //两圆中心点距离

jl = node.getIndex()==0 ? jl *0.4 : jl;

vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', jl, jl, 0, 0 , 1, end);

connection.setMarker(connectMarker);
connectMarker.dot.fill(color);

connection.setPathData(pathData);
});
4 changes: 3 additions & 1 deletion src/layout/fish-bone-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa
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();
Expand All @@ -46,9 +47,10 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa
child.setVertexIn(new kity.Point(cBox.left, cBox.bottom));
child.setLayoutVectorIn(new kity.Vector(1, -1));
}

});



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

Expand Down
48 changes: 48 additions & 0 deletions src/layout/tianpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@ KityMinder.registerLayout('tianpan', kity.createClass({
base: Layout,

doLayout: function(node, children) {
var child = children[0];
if (!child) return;

//console.log(node)
var layout = this;
var pbox = node.getContentBox();

var x,y;
var _theta = 5;
var _r = pbox.width / Math.PI /1.5;

console.log('a')
children.forEach(function(child, index) {
x = (_r) * (Math.cos(_theta) + Math.sin(_theta) * _theta);
y = (_r) * (Math.sin(_theta) - Math.cos(_theta) * _theta);

child.setLayoutTransform(new kity.Matrix());
// child.setLayoutVectorIn(
// new kity.Vector(1, 0));
// child.setVertexIn(new kity.Point(cBox.left, cBox.cy));

child.getLayoutTransform().translate(x, y);
_theta += 0.9;//+(-index*0.02);
});
return;


children.forEach(function(child) {
x = (_r) * (Math.cos(_theta) + Math.sin(_theta) * _theta);
y = (_r) * (Math.sin(_theta) - Math.cos(_theta) * _theta);


var m = child.getLayoutTransform();
var cbox = child.getContentBox();
var pin = m.transformPoint(new kity.Point(cbox.left, 0));
layout.move([child], pbox.left, pbox.right);

//layout.move([child], x, y);

// child.getLayoutTransform().translate(110, 100);
// child.setLayoutTransform(new kity.Matrix());
});


return null;

//debugger
var layout = this;
var half = Math.ceil(node.children.length / 2);
Expand All @@ -33,6 +79,8 @@ KityMinder.registerLayout('tianpan', kity.createClass({
},

getOrderHint: function(node) {


var hint = [];
var box = node.getLayoutBox();
var offset = 5;
Expand Down
1 change: 1 addition & 0 deletions src/module/dragtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
} else {
this._minder.fire('savescene');
}

this._minder.layout(300);
this._leaveDragMode();
this._minder.fire('contentchange');
Expand Down
14 changes: 2 additions & 12 deletions src/template/tianpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,20 @@
*/

KityMinder.registerTemplate('tianpan', {

getLayout: function(node) {

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

var level = node.getLevel();

// 根节点
if (level === 0) {
return 'tianpan';
}

// 一级节点
if (level === 1) {
return 'tianpan';
// return node.getLayoutPointPreview().x > 0 ? 'right': 'left';
}

return node.parent.getLayout();
},

getConnect: function(node) {
return null;
//if (node.getLevel() == 1) return 'arc';
//return 'arc';
if (node.getLevel() == 1) return 'arc_tp';
return 'arc_tp';
}
});
12 changes: 6 additions & 6 deletions src/theme/tianpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'root-background': '#e9df98',
'root-stroke': '#e9df98',
'root-font-size': 25,
'root-padding': compact ? [10, 25] : 25,
'root-padding': compact ? 15 : 20,
'root-margin': compact ? [15, 25] : 100,
'root-radius': 30,
'root-space': 10,
Expand All @@ -18,9 +18,9 @@
'main-color': '#333',
'main-background': '#a4c5c0',
'main-stroke': '#a4c5c0',
'main-font-size': 16,
'main-padding': compact ? [5, 15] : 20,
'main-margin': compact ? [5, 10] : 20,
'main-font-size': 15,
'main-padding': compact ? 10 : 12,
'main-margin': compact ? 10 : 12,
'main-radius': 10,
'main-space': 5,
'main-shadow': 'rgba(0, 0, 0, .25)',
Expand All @@ -30,8 +30,8 @@
'sub-background': '#99ca6a',
'sub-stroke': '#a4c5c0',
'sub-font-size': 13,
'sub-padding': 20,
'sub-margin': compact ? [5, 10] : 20,
'sub-padding': 5,
'sub-margin': compact ? 6 : 10,
'sub-tree-margin': 30,
'sub-radius': 5,
'sub-space': 5,
Expand Down

0 comments on commit 4c16313

Please sign in to comment.