Commit 9003d6e6 authored by techird's avatar techird

Merge branch 'dev' of https://github.com/kitygraph/kityminder into dev

Conflicts:
	src/module/keyboard.js
parents 4b1bae5e 3256b32c
......@@ -11,86 +11,27 @@
<script>
minder = new KM.createMinder( document.body );
minder.importData({
data: {
x: 50,
y: 50,
text: 'center',
},
children: [{
data: {
x: 200,
y: 50,
text: 'child1'
}
},{
data: {
x: 200,
y: 100,
text: 'child2'
},
children: [{
data: {
x: 350,
y: 100,
text: 'leaf'
}
}]
}]
});
var minderWidth = document.body.clientWidth;
var minderHeight = document.body.clientHeight;
var _node = minder.getRoot();
var _root = minder.getRoot();
_node.data = {
centerX:minderWidth/2,
centerY:minderHeight/2,
_root.setData("data",{
x:minderWidth/2,
y:minderHeight/2,
style:{
radius:10,
fill:"orange",
stroke:"orange",
color:"black",
padding:[10,10,10,10],
fontSize:20
fontSize:20,
align:"center"
},
text:"I am the root",
};
minder.select(_node);
});
// var _childnode = new MinderNode();
// _node.insertChild(_childnode);
// _childnode.data = {
// centerX:minderWidth/2+150,
// centerY:minderHeight/2+100,
// style:{
// radius:10,
// fill:"yellow",
// stroke:"orange",
// strokeWidth:2,
// color:"black",
// padding:[10,10,10,10],
// fontSize:12
// },
// text:"childnode1",
// };
minder.select(_root);
minder.execCommand("rendernode",_root);
// var _childnode2 = new MinderNode();
// _node.insertChild(_childnode2);
// _childnode2.data = {
// centerX:minderWidth/2+250,
// centerY:minderHeight/2+10,
// style:{
// radius:10,
// fill:"yellow",
// stroke:"orange",
// color:"black",
// padding:[10,10,10,10],
// fontSize:12
// },
// text:"childnode2",
// };
minder.execCommand("rendernode",_node);
// minder.execCommand("rendernode",_childnode);
// minder.execCommand("rendernode",_childnode2);
</script>
</html>
\ No newline at end of file
......@@ -26,7 +26,9 @@ kity.extendClass( Minder, {
//command加入命令池子
dealCommands = moduleDeals.commands;
Utils.extend( this._commands, dealCommands );
for ( var name in dealCommands ) {
this._commands[ name.toLowerCase() ] = dealCommands[ name ];
}
//绑定事件
dealEvents = moduleDeals.events;
......
......@@ -145,15 +145,20 @@ var ConnectModule = KityMinder.registerModule( "ConnectModule", function () {
} else {
var parent = node.getParent();
var _connect = new ConnectBezier( parent.getRenderContainer(), node.getRenderContainer() );
_connect.stroke( new kity.Pen( node.data.style.stroke, node.data.style.strokeWidth ) );
node.connect = _connect;
var nodeD = node.getData( "data" );
_connect.stroke( new kity.Pen( nodeD.style.stroke, nodeD.style.strokeWidth ) );
node.setData( "connect", _connect );
console.log( _connect );
minder.getRenderContainer().addShape( _connect );
}
} )();
break;
case "erasenode":
break;
case "removenode":
( function () {
var node = command.commandArgs[ 0 ];
node.getData( "connect" ).remove();
} )();
default:
break;
};
......
......@@ -86,7 +86,7 @@ KityMinder.registerModule( "KeyboardModule", function () {
isRootSelected = this.isNodeSelected( this.getRoot() );
console.log( e.originEvent.keyCode );
e.originEvent.preventDefault();
switch ( e.keyCode ) {
switch ( e.originEvent.keyCode ) {
case 13:
// Enter
......
KityMinder.registerModule( "LayoutModule", function () {
var CreateChildNodeCommand = kity.createClass( "CreateChildNodeCommand", ( function () {
return {
base: Command,
execute: function ( km, parent, node ) {
parent.insertChild( node );
execute: function ( km, parent ) {
console.log( "parentX", parent.getData( "data" ).x );
var _node = new MinderNode();
var _nodeD = {
text: "New Node",
x: parent.getData( "data" ).x + 200,
y: Math.random() * 300 + 100,
align: "left"
};
_node.setData( "data", _nodeD );
console.log( "node", _node );
parent.insertChild( _node );
km.execCommand( 'rendernode', _node );
return _node;
}
}
} )() );
......
KityMinder.registerModule( "RenderModule", function () {
var RenderNodeCommand = kity.createClass( "RenderNodeCommand", ( function () {
var node_default = {
centerX: 0,
centerY: 0,
text: "Root",
style: {
fill: "#7ecef4",
stroke: "white",
strokeWidth: 3,
padding: 5,
radius: 5
var MinderNodeShape = kity.createClass( "MinderNodeShape", ( function () {
return {
constructor: function ( container ) {
this.rect = new kity.Rect();
this.text = new kity.Text();
this.shape = new kity.Group();
this.shape.addShapes( [ this.rect, this.text ] );
container.addShape( this.shape, "nodeShape" );
},
highlight: function () {
this.rect.stroke( new kity.Pen( "white", 3 ) );
},
unhighlight: function () {
this.rect.stroke( this.NormalInfo );
}
}
};
} )() );
var renderNode = function ( km, node ) {
var nodeD = Utils.extend( node_default, node.data );
var _style = nodeD.style;
var node_default = {
x: 0,
y: 0,
text: "Root",
style: {
radius: 10,
fill: "yellow",
stroke: "orange",
color: "black",
padding: [ 5, 5, 5, 5 ],
fontSize: 12,
align: "left"
}
};
var kR = node.getRenderContainer();
var _node = node.shape = new kity.Group();
var _txt = new kity.Text( nodeD.text || "Node" );
_txt.setSize( nodeD.fontSize ).fill( nodeD.color );
_node.addShape( _txt );
kR.addShape( _node );
var txtWidth = _txt.getWidth();
var txtHeight = _txt.getHeight();
var nodeShape = new MinderNodeShape( kR );
var nd = JSON.parse( JSON.stringify( node_default ) );
var nodeD = Utils.extend( nd, node.getData( "data" ) );
node.setData( "data", nodeD );
var _style = nodeD.style;
nodeShape.text
.setContent( nodeD.text || "Node" )
.setSize( nodeD.fontSize )
.fill( nodeD.color );
var txtWidth = nodeShape.text.getWidth();
var txtHeight = nodeShape.text.getHeight();
var _padding = _style.padding;
nodeShape.text
.setX( _padding[ 3 ] ).setY( _padding[ 0 ] + txtHeight );
var _rectWidth = txtWidth + _padding[ 1 ] + _padding[ 3 ];
var _rectHeight = txtHeight + _padding[ 0 ] + _padding[ 2 ];
console.log( _rectWidth, _rectHeight );
var _rect = new kity.Rect( _rectWidth, _rectHeight, 0, 0, _style.radius );
_rect.stroke( new kity.Pen( _style.stroke, _style.strokeWidth ) ).fill( _style.fill );
_node.addShape( _rect ).bringTop( _txt );
_node.translate( nodeD.centerX - _rectWidth / 2, nodeD.centerY - _rectHeight / 2 );
_txt.setX( _padding[ 3 ] ).setY( _padding[ 0 ] + txtHeight );
};
nodeShape.NormalInfo = new kity.Pen( _style.stroke, _style.strokeWidth );
nodeShape.rect.setWidth( _rectWidth ).setHeight( _rectHeight ).stroke( nodeShape.NormalInfo ).fill( _style.fill ).setRadius( _style.radius );
switch ( nodeD.align ) {
case "center":
nodeShape.shape.translate( nodeD.x - _rectWidth / 2, nodeD.y - _rectHeight / 2 );
break;
case "right":
nodeShape.shape.translate( nodeD.x - _rectWidth, nodeD.y - _rectHeight / 2 );
break;
default:
nodeShape.shape.translate( nodeD.x, nodeD.y - _rectHeight / 2 );
break;
}
if ( km.isNodeSelected( node ) ) {
nodeShape.highlight();
}
}
return {
base: Command,
......
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