Commit 730566aa authored by techird's avatar techird

stash

parent df4b9823
......@@ -25,6 +25,8 @@
'core/theme.js',
'layout/default.js',
'theme/default.js',
'module/node.js',
'module/text.js',
'module/outline.js',
'module/geometry.js',
'module/history.js',
......
Subproject commit 093f66727667709bbf9054670c9b0cb20bb31998
Subproject commit 62a846c829a0306ba7493885b44c38d68cd3d232
var Layout = kity.createClass('Layout', {
doLayout: function(node) {
throw new Error('Not Implement: Layout.doLayout()');
},
getBranchBox: function(nodes) {
var box = {
x: 0,
y: 0,
height: 0,
width: 0
};
var g = KityMinder.Geometry;
var i, node, matrix, contentBox;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
contentBox = node.getContentBox();
box = g.mergeBox(box, matrix.transformBox(contentBox));
}
return box;
},
getTreeBox: function(nodes) {
var box = {
x: 0,
y: 0,
height: 0,
width: 0
};
var g = KityMinder.Geometry;
var i, node, matrix, treeBox;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
matrix = node.getLayoutTransform();
treeBox = node.getContentBox();
if (node.children.length) {
treeBox = g.mergeBox(treeBox, this.getTreeBox(node.children));
}
box = g.mergeBox(box, matrix.transformBox(treeBox));
}
return box;
}
});
......@@ -24,31 +67,101 @@ kity.extendClass(MinderNode, {
return layout;
},
applyLayoutResult: function (parentX, parentY) {
var myX = parentX + this.layoutX,
myY = parentY + this.layoutY;
this.getRenderContainer().fxTranslate(myX, myY);
this.getChildren().forEach(function(node) {
node.applyLayoutResult(myX, myY);
});
setLayoutTransform: function(matrix) {
this._layoutTransform = matrix;
},
layout: function(name) {
getLayoutTransform: function() {
return this._layoutTransform || new kity.Matrix();
},
getLayoutRoot: function() {
if (this.isLayoutRoot()) {
return this;
}
return this.parent.getLayoutRoot();
},
isLayoutRoot: function() {
return this.getData('layout') || this.isRoot();
},
layout: function(name, duration) {
if (name) {
if (name == 'inherit') {
this.setData('layout');
} else {
this.setData('layout', name);
}
var LayoutClass = KityMinder._layout[this.getLayout()];
var layout = new LayoutClass();
layout.doLayout(this);
this.applyLayoutResult(0, 0);
}
this.getMinder().layout(duration);
return this;
},
}
});
getTreeBox: function() {
var box = this.getContentBox();
this.getChildren().forEach(function(child) {
box = KityMinder.Geometry.mergeBox(child.getTreeBox(), box);
kity.extendClass(Minder, {
layout: function(duration) {
this.getRoot().traverse(function(node) {
node.setLayoutTransform(null);
});
return box;
function layoutNode(node) {
// layout all children first
node.children.forEach(function(child) {
layoutNode(child);
});
var LayoutClass = KityMinder._layout[node.getLayout()];
var layout = new LayoutClass();
layout.doLayout(node);
}
layoutNode(this.getRoot());
return this.applyLayoutResult(duration);
},
applyLayoutResult: function(duration) {
var root = this.getRoot();
function apply(node, pMatrix) {
var matrix = node.getLayoutTransform().merge(pMatrix);
var lastMatrix = node._lastLayoutTransform || new kity.Matrix();
if (!matrix.equals(lastMatrix)) {
// 如果当前有动画,停止动画
if (node._layoutTimeline) {
node._layoutTimeline.stop();
delete node._layoutTimeline;
}
// 如果要求以动画形式来更新,创建动画
if (duration > 0) {
node._layoutTimeline = new kity.Animator(lastMatrix, matrix, function(rc, value) {
rc.setMatrix(node._lastLayoutTransform = value);
}).start(node.getRenderContainer(), duration, 'ease');
}
// 否则直接更新
else {
node.getRenderContainer().setMatrix(matrix);
node._lastLayoutTransform = matrix;
}
}
for (var i = 0; i < node.children.length; i++) {
apply(node.children[i], matrix);
}
}
apply(root, new kity.Matrix());
return this;
},
});
\ No newline at end of file
......@@ -26,7 +26,12 @@ kity.extendClass(Minder, {
if (!modulesPool[name]) continue;
// 执行模块初始化,抛出后续处理对象
if (typeof(modulesPool[name]) == 'function') {
moduleDeals = modulesPool[name].call(me);
} else {
moduleDeals = modulesPool[name];
}
this._modules[name] = moduleDeals;
if (moduleDeals.init) {
......
......@@ -32,8 +32,8 @@ kity.extendClass(Minder, {
this.renderChangedSelection(nodes);
return this;
},
select: function(nodes, isToggleSelect) {
if (isToggleSelect) {
select: function(nodes, isSingleSelect) {
if (isSingleSelect) {
this.removeAllSelectedNodes();
}
var me = this;
......
......@@ -93,7 +93,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
* @param {String} text 文本数据
*/
setText: function(text) {
this.setData('text', text);
return this.setData('text', text);
},
/**
......@@ -207,6 +207,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
this.data[name] = value;
}
}
return this;
},
getRenderContainer: function() {
......
......@@ -88,10 +88,10 @@ kity.extendClass(Minder, {
if (item in theme) {
value = theme[item];
if (!isNaN(value)) return value;
if (Utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
return matcher(value);
}
if (!isNaN(value)) return value;
}
return null;
......
......@@ -3,18 +3,89 @@
KityMinder.registerLayout('default', kity.createClass({
base: Layout,
getSide: function(node) {
while (!node.parent.isLayoutRoot()) {
node = node.parent;
}
var mainIndex = node.getIndex();
return {
0: 'right',
1: 'right',
2: 'left',
3: 'left'
}[mainIndex] || (mainIndex % 2 ? 'right' : 'left');
},
doLayout: function(node) {
node.getChildren().forEach(function(childNode) {
childNode.layout();
var layout = this;
function arrange(node, children, side) {
//if (!children.length) return;
var height = 0;
var childBoxes = children.map(function(node, index, children) {
var box = layout.getTreeBox([node]);
height += box.height;
if (index > 0) {
height += children[index - 1].getStyle('margin-bottom');
height += node.getStyle('margin-top');
}
return box;
});
var y = 0;
node.getChildren().forEach(function(childNode) {
childNode.layoutX = node.getContentBox().right - childNode.getContentBox().x + node.getStyle('margin-right');
childNode.layoutY = y;
y += 50;
console.log(childNode.layoutX, childNode.layoutY);
var contentBox = node.getContentBox();
var x, y = -height / 2;
for (var i = 0; i < children.length; i++) {
if (side == 'right') {
x = contentBox.x + contentBox.width - children[i].getContentBox().x;
x += node.getStyle('margin-right') + node.children[i].getStyle('margin-left');
} else {
x = contentBox.x - children[i].getContentBox().width - children[i].getContentBox().x;
x -= node.getStyle('margin-left') + node.children[i].getStyle('margin-right');
}
y += childBoxes[i].height / 2;
if (i > 0) {
y += children[i].getStyle('margin-top');
}
children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
y += childBoxes[i].height / 2 + children[i].getStyle('margin-bottom');
}
var branchBox = layout.getBranchBox(children);
var dy = (branchBox.y + branchBox.height / 2) - (contentBox.y + contentBox.height / 2);
for (i = 0; i < children.length; i++) {
children[i].getLayoutTransform().translate(0, -dy);
}
}
function layoutRoot(node) {
var mains = node.getChildren();
var group = {
left: [],
right: []
};
mains.forEach(function(main) {
group[layout.getSide(main)].push(main);
});
node.layoutX = 0;
node.layoutY = 0;
arrange(node, group.left, 'left');
arrange(node, group.right, 'right');
}
if (node.isLayoutRoot()) {
layoutRoot(node);
} else {
arrange(node, node.children, layout.getSide(node));
}
}
}));
\ No newline at end of file
KityMinder.registerModule("basestylemodule", function() {
KityMinder.registerModule('basestylemodule', function() {
var km = this;
return {
"commands": {
"bold": kity.createClass("boldCommand", {
'commands': {
'bold': kity.createClass('boldCommand', {
base: Command,
execute: function() {
execute: function(km) {
var nodes = km.getSelectedNodes();
if (this.queryState('bold') == 1) {
utils.each(nodes, function(i, n) {
n.setData('bold');
n.getTextShape().setAttr('font-weight');
km.updateLayout(n);
n.setData('font-weight').render();
});
} else {
utils.each(nodes, function(i, n) {
n.setData('bold', true);
n.getTextShape().setAttr('font-weight', 'bold');
km.updateLayout(n);
n.setData('font-weight', 'bold').render();
});
}
km.layout();
},
queryState: function() {
var nodes = km.getSelectedNodes(),
......@@ -29,7 +26,7 @@ KityMinder.registerModule("basestylemodule", function() {
return -1;
}
utils.each(nodes, function(i, n) {
if (n && n.getData('bold')) {
if (n && n.getData('font-weight')) {
result = 1;
return false;
}
......@@ -37,25 +34,23 @@ KityMinder.registerModule("basestylemodule", function() {
return result;
}
}),
"italic": kity.createClass("italicCommand", {
'italic': kity.createClass('italicCommand', {
base: Command,
execute: function() {
execute: function(km) {
var nodes = km.getSelectedNodes();
if (this.queryState('italic') == 1) {
utils.each(nodes, function(i, n) {
n.setData('italic');
n.getTextShape().setAttr('font-style');
km.updateLayout(n);
n.setData('font-style').render();
});
} else {
utils.each(nodes, function(i, n) {
n.setData('italic', true);
n.getTextShape().setAttr('font-style', 'italic');
km.updateLayout(n);
n.setData('font-style', 'italic').render();
});
}
km.layout();
},
queryState: function() {
var nodes = km.getSelectedNodes(),
......@@ -64,7 +59,7 @@ KityMinder.registerModule("basestylemodule", function() {
return -1;
}
utils.each(nodes, function(i, n) {
if (n && n.getData('italic')) {
if (n && n.getData('font-style')) {
result = 1;
return false;
}
......@@ -74,20 +69,8 @@ KityMinder.registerModule("basestylemodule", function() {
})
},
addShortcutKeys: {
"bold": "ctrl+b", //bold
"italic": "ctrl+i" //italic
},
"events": {
"afterrendernodecenter": function(e) {
//加粗
if (e.node.getData('bold')) {
e.node.getTextShape().setAttr('font-weight', 'bold');
}
if (e.node.getData('italic')) {
e.node.getTextShape().setAttr('font-style', 'italic');
}
}
'bold': 'ctrl+b', //bold
'italic': 'ctrl+i' //italic
}
};
});
\ No newline at end of file
This diff is collapsed.
......@@ -345,32 +345,6 @@ KityMinder.registerModule('TextEditModule', function() {
'textedit.mousewheel': function() {
receiver.setContainerStyle();
}
},
'renderers': {
center: kity.createClass('TextRenderer', {
base: Renderer,
create: function(node) {
var textShape = new kity.Text()
.setVerticalAlign('middle')
.setId(KityMinder.uuid('node_text'));
node.getRenderContainer().addShape(textShape);
node.getTextShape = function() {
return textShape;
};
},
update: function(node) {
return node.getTextShape()
.setContent(node.getText())
.setFont({
family: node.getStyle('font-family'),
size: node.getStyle('font-size')
})
.fill(node.getData('color') || node.getStyle('color'))
.getBoundaryBox();
}
})
}
};
});
\ No newline at end of file
KityMinder.registerModule( "Expand", function () {
KityMinder.registerModule('Expand', function() {
var minder = this;
var EXPAND_STATE_DATA = 'expandState',
STATE_EXPAND = 'expand',
STATE_COLLAPSE = 'collapse';
var layerTravel = function ( root, fn ) {
var _buffer = [ root ];
while ( _buffer.length !== 0 ) {
fn( _buffer[ 0 ] );
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
var layerTravel = function(root, fn) {
var _buffer = [root];
while (_buffer.length !== 0) {
fn(_buffer[0]);
_buffer = _buffer.concat(_buffer[0].getChildren());
_buffer.shift();
}
}
};
//获取选中的最上层节点
var filterDuplicate = function ( nodes ) {
var _buffer = ( [] ).concat( nodes );
var filterDuplicate = function(nodes) {
var _buffer = ([]).concat(nodes);
var resultSet = [];
for ( var i = 0; i < _buffer.length; i++ ) {
var parent = _buffer[ i ].getParent();
if ( !parent ) {
resultSet = [ _buffer[ i ] ];
for (var i = 0; i < _buffer.length; i++) {
var parent = _buffer[i].getParent();
if (!parent) {
resultSet = [_buffer[i]];
break;
} else {
//筛选
while ( parent ) {
if ( _buffer.indexOf( parent ) !== -1 ) {
_buffer[ i ] = null;
while (parent) {
if (_buffer.indexOf(parent) !== -1) {
_buffer[i] = null;
break;
}
parent = parent.getParent();
}
if ( _buffer[ i ] ) resultSet.push( _buffer[ i ] );
if (_buffer[i]) resultSet.push(_buffer[i]);
}
}
return resultSet;
}
};
var expandAll = function ( km, deal ) {
var expandAll = function(km, deal) {
var selectedNodes = km.getSelectedNodes();
var topNodes = filterDuplicate( selectedNodes );
if ( selectedNodes.length === 0 || selectedNodes[ 0 ].getType() === 'root' || topNodes[ 0 ].getType() === 'root' ) {
layerTravel( km.getRoot(), function ( n ) {
if ( deal === 'expand' ) n.expand();
var topNodes = filterDuplicate(selectedNodes);
if (selectedNodes.length === 0 || selectedNodes[0].getType() === 'root' || topNodes[0].getType() === 'root') {
layerTravel(km.getRoot(), function(n) {
if (deal === 'expand') n.expand();
else n.collapse();
} );
});
km.initStyle();
} else {
for ( var i = 0; i < topNodes.length; i++ ) {
var node = topNodes[ i ];
for (var i = 0; i < topNodes.length; i++) {
var node = topNodes[i];
var children = node.getChildren();
if ( children.length === 0 ) {
if (children.length === 0) {
continue;
} else {
layerTravel( node, function ( n ) {
if ( n !== node ) {
if ( deal === 'expand' ) n.expand();
layerTravel(node, function(n) {
if (n !== node) {
if (deal === 'expand') n.expand();
else n.collapse();
}
} );
});
var judge_val;
if ( deal === 'expand' ) {
if (deal === 'expand') {
judge_val = !node.isExpanded();
} else {
judge_val = node.isExpanded();
}
if ( judge_val ) {
km.expandNode( node );
if (judge_val) {
km.expandNode(node);
} else {
km.expandNode( node );
km.expandNode( node );
km.expandNode(node);
km.expandNode(node);
}
}
}
}
for ( var j = 0; j < selectedNodes.length; j++ ) {
km.highlightNode( selectedNodes[ j ] );
for (var j = 0; j < selectedNodes.length; j++) {
km.highlightNode(selectedNodes[j]);
}
}
......@@ -103,23 +104,23 @@ KityMinder.registerModule( "Expand", function () {
* @param {int} deep_level 指定的层数
* @param {Function} policy_after_level 超过的层数执行的策略
*/
function generateDeepPolicy( deep_level, policy_after_level ) {
function generateDeepPolicy(deep_level, policy_after_level) {
return function ( node, state, policy, level ) {
return function(node, state, policy, level) {
var children, child, i;
node.setData( EXPAND_STATE_DATA, state );
node.setData(EXPAND_STATE_DATA, state);
level = level || 1;
children = node.getChildren();
for ( i = 0; i < children.length; i++ ) {
child = children[ i ];
for (i = 0; i < children.length; i++) {
child = children[i];
if ( level <= deep_level ) {
policy( child, state, policy, level + 1 );
} else if ( policy_after_level ) {
policy_after_level( child, state, policy, level + 1 );
if (level <= deep_level) {
policy(child, state, policy, level + 1);
} else if (policy_after_level) {
policy_after_level(child, state, policy, level + 1);
}
}
......@@ -140,8 +141,8 @@ KityMinder.registerModule( "Expand", function () {
/**
* 策略 1:只修改当前节点的状态,不递归子节点的状态
*/
KEEP_STATE: function ( node, state, policy ) {
node.setData( EXPAND_STATE_DATA, state );
KEEP_STATE: function(node, state, policy) {
node.setData(EXPAND_STATE_DATA, state);
},
generateDeepPolicy: generateDeepPolicy,
......@@ -149,24 +150,24 @@ KityMinder.registerModule( "Expand", function () {
/**
* 策略 2:把操作进行到儿子
*/
DEEP_TO_CHILD: generateDeepPolicy( 1 ),
DEEP_TO_CHILD: generateDeepPolicy(1),
/**
* 策略 3:把操作进行到叶子
*/
DEEP_TO_LEAF: generateDeepPolicy( Number.MAX_VALUE )
DEEP_TO_LEAF: generateDeepPolicy(Number.MAX_VALUE)
};
// 将展开的操作和状态读取接口拓展到 MinderNode 上
kity.extendClass( MinderNode, {
kity.extendClass(MinderNode, {
/**
* 使用指定的策略展开节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
expand: function ( policy ) {
expand: function(policy) {
policy = policy || EXPAND_POLICY.KEEP_STATE;
policy( this, STATE_EXPAND, policy );
policy(this, STATE_EXPAND, policy);
return this;
},
......@@ -174,44 +175,44 @@ KityMinder.registerModule( "Expand", function () {
* 使用指定的策略收起节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
collapse: function ( policy ) {
collapse: function(policy) {
policy = policy || EXPAND_POLICY.KEEP_STATE;
policy( this, STATE_COLLAPSE, policy );
policy(this, STATE_COLLAPSE, policy);
return this;
},
/**
* 判断节点当前的状态是否为展开
*/
isExpanded: function () {
return this.getData( EXPAND_STATE_DATA ) === STATE_EXPAND;
isExpanded: function() {
return this.getData(EXPAND_STATE_DATA) === STATE_EXPAND;
}
} );
var ExpandNodeCommand = kity.createClass( "ExpandNodeCommand", ( function () {
});
var ExpandNodeCommand = kity.createClass("ExpandNodeCommand", (function() {
return {
base: Command,
execute: function ( km ) {
expandAll( km, 'expand' );
execute: function(km) {
expandAll(km, 'expand');
},
queryState: function ( km ) {
queryState: function(km) {
return 0;
}
};
} )() );
var CollapseNodeCommand = kity.createClass( "CollapseNodeCommand", ( function () {
})());
var CollapseNodeCommand = kity.createClass("CollapseNodeCommand", (function() {
return {
base: Command,
execute: function ( km ) {
expandAll( km, 'collapse' );
execute: function(km) {
expandAll(km, 'collapse');
},
queryState: function ( km ) {
queryState: function(km) {
return 0;
}
};
} )() );
})());
return {
'events': {
'beforeimport': function ( e ) {
'beforeimport': function(e) {
// var _root = this.getRoot();
// var options = this.getOptions();
// var defaultExpand = options.defaultExpand;
......@@ -228,4 +229,4 @@ KityMinder.registerModule( "Expand", function () {
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
KityMinder.registerModule( "fontmodule", function () {
KityMinder.registerModule("fontmodule", function() {
return {
defaultOptions: {
'fontfamily': [ {
'fontfamily': [{
name: 'songti',
val: '宋体,SimSun'
}, {
......@@ -38,100 +38,82 @@ KityMinder.registerModule( "fontmodule", function () {
}, {
name: 'sans-serif',
val: 'sans-serif'
} ],
'fontsize': [ 10, 12, 16, 18, 24, 32, 48 ]
}],
'fontsize': [10, 12, 16, 18, 24, 32, 48]
},
"commands": {
"forecolor": kity.createClass( "fontcolorCommand", {
"forecolor": kity.createClass("fontcolorCommand", {
base: Command,
execute: function ( km, color ) {
execute: function(km, color) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'fontcolor', color );
n.getTextShape().fill( color )
} )
utils.each(nodes, function(i, n) {
n.setData('color', color);
n.render();
});
},
queryState:function(km){
queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0
},
queryValue: function(km) {
if (km.getSelectedNodes().length == 1) {
return km.getSelectedNodes()[0].getData('fontcolor');
return km.getSelectedNodes()[0].getData('color');
}
return 'mixed';
}
} ),
"backgroundcolor": kity.createClass( "backgroudcolorCommand", {
}),
"backgroundcolor": kity.createClass("backgroudcolorCommand", {
base: Command,
execute: function ( km, color ) {
execute: function(km, color) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'backgroundcolor', color );
n.getLayout().bgRect.fill( color );
} );
utils.each(nodes, function(i, n) {
n.setData('background', color);
n.render();
});
},
queryState:function(km){
queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0
},
queryValue: function (km) {
queryValue: function(km) {
if (km.getSelectedNodes().length == 1) {
return km.getSelectedNodes()[0].getData('backgroundcolor');
return km.getSelectedNodes()[0].getData('background');
}
return 'mixed';
}
} ),
"fontfamily": kity.createClass( "fontfamilyCommand", {
}),
"fontfamily": kity.createClass("fontfamilyCommand", {
base: Command,
execute: function ( km, family ) {
execute: function(km, family) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'fontfamily', family );
n.getTextShape().setAttr( 'font-family', family );
km.updateLayout( n )
} )
utils.each(nodes, function(i, n) {
n.setData('font-family', family);
n.render();
km.layout();
});
},
queryState:function(km){
queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0
}
} ),
"fontsize": kity.createClass( "fontsizeCommand", {
}),
"fontsize": kity.createClass("fontsizeCommand", {
base: Command,
execute: function ( km, size ) {
execute: function(km, size) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'fontsize', size );
n.getTextShape().setSize( size );
km.updateLayout( n )
} )
utils.each(nodes, function(i, n) {
n.setData('font-size', size);
n.render();
km.layout(300);
});
},
queryState:function(km){
queryState: function(km) {
return km.getSelectedNodes().length == 0 ? -1 : 0
}
} )
},
"events": {
"afterrendernodecenter": function ( e ) {
var val;
if ( val = e.node.getData( 'fontfamily' ) ) {
e.node.getTextShape().setAttr( 'font-family', val );
}
if ( val = e.node.getData( 'fontcolor' ) ) {
e.node.getTextShape().fill( val );
}
if ( val = e.node.getData( 'backgroundcolor' ) ) {
e.node.getLayout().bgRect.fill( val );
}
if ( val = e.node.getData( 'fontsize' ) ) {
e.node.getTextShape().setSize( val );
}
}
})
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -127,6 +127,7 @@ KityMinder.registerModule("KeyboardModule", function() {
km.select(nextNode, true);
}
}
return {
'events': {
......@@ -137,26 +138,27 @@ KityMinder.registerModule("KeyboardModule", function() {
var keys = KityMinder.keymap;
var node = e.getTargetNode();
var lang = this.getLang();
this.receiver.keydownNode = node;
switch (e.originEvent.keyCode) {
case keys.Enter:
this.execCommand('appendSiblingNode', new MinderNode(this, this.getLang().topic));
this.execCommand('AppendSiblingNode', lang.topic);
e.preventDefault();
break;
case keys.Tab:
this.execCommand('appendChildNode', new MinderNode(this, this.getLang().topic));
this.execCommand('AppendChildNode', lang.topic);
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
e.preventDefault();
this.execCommand('removenode');
this.execCommand('RemoveNode');
break;
case keys.F2:
e.preventDefault();
this.execCommand('editnode');
this.execCommand('EditNode');
break;
case keys.Left:
......
kity.extendClass(Minder, {
appendChildNode: function(parent, node, index) {
},
appendSiblingNode: function(sibling, node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node);
},
});
var AppendChildCommand = kity.createClass('AppendChildCommand', {
base: Command,
execute: function(km, text) {
var parent = km.getSelectedNode();
var node = km.createNode(text);
if (!parent) {
return null;
}
//parent.expand();
parent.appendChild(node);
km.select(node, true);
node.render();
km.layout(300);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1;
}
});
var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
base: Command,
execute: function(km, text) {
var sibling = km.getSelectedNode();
var parent = sibling.parent;
var node = km.createNode(text);
if (!parent) {
return null;
}
parent.insertChild(node, sibling.getIndex() + 1);
km.select(node, true);
node.render();
km.layout(300);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1;
}
});
var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
base: Command,
execute: function(km, text) {
var nodes = km.getSelectedNodes();
var ancestor = km.getSelectedAncestors()[0];
nodes.forEach(function(node) {
km.removeNode(node);
});
km.select(ancestor, true);
km.layout(300);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
return selectedNode ? 0 : -1;
}
});
KityMinder.registerModule('NodeModule', function() {
return {
commands: {
'AppendChildNode': AppendChildCommand,
'AppendSiblingNode': AppendSiblingCommand,
'RemoveNode': RemoveNodeCommand
}
};
});
\ No newline at end of file
/* global Renderer: true */
var wireframe = true;
KityMinder.registerModule('OutlineModule', function() {
return {
renderers: {
......@@ -9,6 +11,12 @@ KityMinder.registerModule('OutlineModule', function() {
create: function(node) {
var outline = this.outline = new kity.Rect().setId(KityMinder.uuid('node_outline'));
node.getRenderContainer().prependShape(outline);
if (wireframe) {
var oxy = this.oxy = new kity.Path().stroke('white').setPathData('M0,-50L0,50M-50,0L50,0').setOpacity(0.5);
var box = this.wireframe = new kity.Rect().stroke('lightgreen');
node.getRenderContainer().addShapes([oxy, box]);
}
},
update: function(node) {
......@@ -30,6 +38,10 @@ KityMinder.registerModule('OutlineModule', function() {
.fill(node.isSelected() ?
node.getStyle('selected-background') :
node.getStyle('background'));
if (wireframe) {
this.wireframe.setPosition(outlineBox.x, outlineBox.y).setSize(outlineBox.width, outlineBox.height);
}
return outlineBox;
}
})
......
/* global Renderer: true */
kity.extendClass(MinderNode, {
getTextShape: function() {
return this._textShape;
}
});
KityMinder.registerModule('text', {
'renderers': {
center: kity.createClass('TextRenderer', {
base: Renderer,
create: function(node) {
var textShape = new kity.Text().setId(KityMinder.uuid('node_text'));
node.getRenderContainer().addShape(textShape);
node._textShape = textShape;
},
update: function(node) {
function dataOrStyle(name) {
return node.getData(name) || node.getStyle(name);
}
return node.getTextShape()
.setContent(node.getText())
.setFont({
family: dataOrStyle('font-family'),
size: dataOrStyle('font-size'),
weight: dataOrStyle('font-weight'),
style: dataOrStyle('font-style')
})
.setVerticalAlign('middle')
.fill(node.getData('color') || node.getStyle('color'))
.getBoundaryBox();
}
})
}
});
\ No newline at end of file
......@@ -4,7 +4,7 @@ KityMinder.registerTheme('default', {
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 0,
'root-margin': 30,
'root-radius': 30,
'root-space': 10,
......@@ -13,7 +13,7 @@ KityMinder.registerTheme('default', {
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [0, 10, 30, 50],
'main-margin': [15, 10],
'main-radius': 10,
'main-space': 5,
......@@ -22,8 +22,8 @@ KityMinder.registerTheme('default', {
'sub-stroke': 'white',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [0, 10, 20, 6],
'sub-radius': 0,
'sub-margin': [5, 10],
'sub-radius': 5,
'sub-space': 5,
'selected-background': 'rgb(254, 219, 0)'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment