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 23, 2015
1 parent 113ac81 commit e4e1487
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 26 deletions.
2 changes: 2 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

/* 布局 */
{ path: 'src/layout/mind.js', pack: 'edit|share|m-share' },
{ path: 'src/layout/tianpan.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' },
Expand All @@ -82,6 +83,7 @@

/* 皮肤 */
{ path: 'src/theme/default.js', pack: 'edit|share|m-share' },
{ path: 'src/theme/tianpan.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' },
Expand Down
3 changes: 2 additions & 1 deletion lang/zh-cn/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ KityMinder.LANG['zh-cn'] = {
'fresh-green-compat': '紧凑绿',
'fresh-blue-compat': '紧凑蓝',
'fresh-purple-compat': '紧凑紫',
'fresh-pink-compat': '紧凑粉'
'fresh-pink-compat': '紧凑粉',
'tianpan':'经典天盘'
},
'maintopic': '中心主题',
'topic': '分支主题',
Expand Down
2 changes: 1 addition & 1 deletion src/connect/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ KityMinder.registerConnectProvider('arc', function(node, parent, connection, wid

vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0 , (vector.x * vector.y > 0 ? 0 : 1), end);

connection.setMarker(connectMarker);
connectMarker.dot.fill(color);
Expand Down
5 changes: 4 additions & 1 deletion src/core/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ kity.extendClass(Minder, (function() {
// 更新渲染图形
latestBox = renderer.update(renderer.getRenderShape(), node, node._contentBox);

if (typeof(latestBox) == 'function') latestBox = latestBox();
if (typeof(latestBox) == 'function'){
latestBox = latestBox();
}


// 合并渲染区域
if (latestBox) {
Expand Down
7 changes: 5 additions & 2 deletions src/layout/fish-bone-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLa
var child = children[0];
var pBox = parent.getContentBox();

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


if (!child) return;

Expand Down
1 change: 1 addition & 0 deletions src/layout/fish-bone-slave.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayo

doLayout: function (parent, children, round) {

//debugger
var layout = this;
var abs = Math.abs;
var GOLD_CUT = 1 - 0.618;
Expand Down
65 changes: 65 additions & 0 deletions src/layout/tianpan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Created with JetBrains WebStorm.
* User: chenbaolong
* Date: 15-3-20
* Time: 上午11:04
* To change this template use File | Settings | File Templates.
*/
/* global Layout:true */
KityMinder.registerLayout('tianpan', kity.createClass({
base: Layout,

doLayout: function(node, children) {
//debugger
var layout = this;
var half = Math.ceil(node.children.length / 2);
var right = [];
var left = [];

children.forEach(function(child) {
if (child.getIndex() < half) right.push(child);
else left.push(child);
});

var leftLayout = KityMinder.getLayoutInstance('left');
var rightLayout = KityMinder.getLayoutInstance('right');

leftLayout.doLayout(node, left);
rightLayout.doLayout(node, right);

var box = node.getContentBox();
node.setVertexOut(new kity.Point(box.cx, box.cy));
node.setLayoutVectorOut(new kity.Vector(0, 0));
},

getOrderHint: function(node) {
var hint = [];
var box = node.getLayoutBox();
var offset = 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;
}
}));
70 changes: 63 additions & 7 deletions src/module/outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', {
},

update: function(outline, node, box) {

var shape = node.getStyle('shape');
if(shape){
if(shape=='circle'){
return updateCircle(outline, node, box);
}
}
var paddingLeft = node.getStyle('padding-left'),
paddingRight = node.getStyle('padding-right'),
paddingTop = node.getStyle('padding-top'),
Expand All @@ -30,8 +35,7 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', {

var prefix = node.isSelected() ? 'selected-' : '';

outline
.setPosition(outlineBox.x, outlineBox.y)
outline.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height)
.setRadius(node.getStyle('radius'))
.fill(node.getData('background') || node.getStyle(prefix + 'background') || node.getStyle('background'))
Expand All @@ -42,6 +46,49 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', {
}
});


//圆
function updateCircle(outline, node, box){

var paddingLeft = node.getStyle('padding-left'),
paddingRight = node.getStyle('padding-right'),
paddingTop = node.getStyle('padding-top'),
paddingBottom = node.getStyle('padding-bottom');

var width= Math.max(box.width,box.height);

var outlineBox = {
x: box.x - paddingLeft,
y: box.y - paddingTop,
width: width + paddingLeft + paddingRight,
height: width + paddingTop + paddingBottom
};

var prefix = node.isSelected() ? 'selected-' : '';

width= Math.max(outlineBox.width,outlineBox.height);

outline.setPosition(outlineBox.x, outlineBox.y)
.setSize(width, width)
.setRadius(width/2)
.fill(node.getData('background') || node.getStyle(prefix + 'background') || node.getStyle('background'))
.stroke(node.getStyle(prefix + 'stroke' || node.getStyle('stroke')),
node.getStyle(prefix + 'stroke-width'));
return new kity.Box(outlineBox);
}













var ShadowRenderer = kity.createClass('ShadowRenderer', {
base: Renderer,

Expand All @@ -55,13 +102,22 @@ var ShadowRenderer = kity.createClass('ShadowRenderer', {
},

update: function(shadow, node, box) {
shadow.setPosition(box.x + 4, box.y + 5)
.setSize(box.width, box.height)
.fill(node.getStyle('shadow'))
.setRadius(node.getStyle('radius'));
shadow.setPosition(box.x + 4, box.y + 5).fill(node.getStyle('shadow'));

var shape = node.getStyle('shape');
if(!shape){
shadow.setSize(box.width, box.height)
shadow.setRadius(node.getStyle('radius'));

}else if(shape=='circle'){
var width= Math.max(box.width,box.height);
shadow.setSize(width, width)
shadow.setRadius(width/2);
}
}
});


var marker = new kity.Marker();

marker.setWidth(10);
Expand Down
20 changes: 13 additions & 7 deletions src/module/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
},

update: function(textGroup, node) {

function s(name) {
function style(name) {
return node.getData(name) || node.getStyle(name);
}

var textArr = node.getText(true);

var lineHeight = node.getStyle('line-height');

var fontSize = s('font-size');
var fontFamily = s('font-family') || 'default';
var fontSize = style('font-size');
var fontFamily = style('font-family') || 'default';

var height = (lineHeight * fontSize) * textArr.length - (lineHeight - 1) * fontSize;
var yStart = -height / 2;
Expand Down Expand Up @@ -68,9 +67,10 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {

this.setTextStyle(node, textGroup);

var textHash = node.getText() + [s('font-size'), s('font-name'), s('font-weight'), s('font-style')].join('/');
var textHash = node.getText() + [style('font-size'), style('font-name'), style('font-weight'), style('font-style')].join('/');

if (node._currentTextHash == textHash && node._currentTextGroupBox) return node._currentTextGroupBox;
if (node._currentTextHash == textHash && node._currentTextGroupBox)
return node._currentTextGroupBox;

node._currentTextHash = textHash;

Expand All @@ -83,7 +83,13 @@ var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
rBox = rBox.merge(new kity.Box(0, y, textShape.getBoundaryBox().width || 1, fontSize));
});

var nBox = new kity.Box(r(rBox.x), r(rBox.y), r(rBox.width), r(rBox.height));
//为了让文字在圆中垂直居中
var w = 0;
var shape = node.getStyle('shape');
if(shape && shape=='circle'){
w = Math.max(rBox.width,rBox.height)/2-rBox.height/2;
}
var nBox = new kity.Box(r(rBox.x), r(rBox.y-w), r(rBox.width), r(rBox.height));

node._currentTextGroupBox = nBox;
return nBox;
Expand Down
16 changes: 9 additions & 7 deletions src/template/tianpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
*
* 天盘模板
*
* @author: techird
* @copyright: Baidu FEX, 2014
* @author: along
* @copyright: [email protected], 2015
*/

KityMinder.registerTemplate('tianpan', {

getLayout: function(node) {
console.log(node)

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

var level = node.getLevel();

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

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

return node.parent.getLayout();
},

getConnect: function(node) {
if (node.getLevel() == 1) return 'arc';
return 'bezier';
return null;
//if (node.getLevel() == 1) return 'arc';
//return 'arc';
}
});
65 changes: 65 additions & 0 deletions src/theme/tianpan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
['tianpan', 'tianpan-compact'].forEach(function(name) {
var compact = name == 'tianpan-compact';

KityMinder.registerTheme(name, {
'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',

'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': '#e9df98',
'root-font-size': 25,
'root-padding': compact ? [10, 25] : 25,
'root-margin': compact ? [15, 25] : 100,
'root-radius': 30,
'root-space': 10,
'root-shadow': 'rgba(0, 0, 0, .25)',
'root-shape':'circle',

'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-radius': 10,
'main-space': 5,
'main-shadow': 'rgba(0, 0, 0, .25)',
'main-shape':'circle',

'sub-color': '#333',
'sub-background': '#99ca6a',
'sub-stroke': '#a4c5c0',
'sub-font-size': 13,
'sub-padding': 20,
'sub-margin': compact ? [5, 10] : 20,
'sub-tree-margin': 30,
'sub-radius': 5,
'sub-space': 5,
'sub-shadow': 'rgba(0, 0, 0, .25)',
'sub-shape':'circle',

'connect-color': 'white',
'connect-width': 2,
'main-connect-width': 3,
'connect-radius': 5,

'selected-background': 'rgb(254, 219, 0)',
'selected-stroke': 'rgb(254, 219, 0)',
'selected-color': 'black',

'marquee-background': 'rgba(255,255,255,.3)',
'marquee-stroke': 'white',

'drop-hint-color': 'yellow',
'sub-drop-hint-width': 2,
'main-drop-hint-width': 4,
'root-drop-hint-width': 4,

'order-hint-area-color': 'rgba(0, 255, 0, .5)',
'order-hint-path-color': '#0f0',
'order-hint-path-width': 1,

'text-selection-color': 'rgb(27,171,255)',
'line-height':1.4
});
});

0 comments on commit e4e1487

Please sign in to comment.