Commit 3f7ded0c authored by Akikonata's avatar Akikonata

dev

parent c4682f0e
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</body> </body>
<script> <script>
minder = new KM.createMinder( document.body, { minder = new KM.createMinder( document.body, {
modules: [ "ExampleModule", "RenderModule", "KeyboardModule" ] modules: [ "ExampleModule","LayoutModule","RenderModule", "KeyboardModule","ConnectModule"]
}); });
minder.importData({ minder.importData({
...@@ -42,19 +42,42 @@ ...@@ -42,19 +42,42 @@
}); });
var minderWidth = document.body.clientWidth; var minderWidth = document.body.clientWidth;
var minderHeight = document.body.clientHeight; var minderHeight = document.body.clientHeight;
var _node = new MinderNode();
console.log(minderWidth,minderHeight); _node.data = {
minder.execCommand( 'rendernode',minder,{
centerX:minderWidth/2, centerX:minderWidth/2,
centerY:minderHeight/2, centerY:minderHeight/2,
radius:10, style:{
fill:"yellow", radius:10,
stroke:"white", fill:"yellow",
color:"black", stroke:"orange",
padding:[10,10,10,10], color:"black",
padding:[10,10,10,10],
fontSize:12
},
text:"node", text:"node",
fontSize:12 };
});
var _childnode = new MinderNode();
_node.insertChild(_childnode);
_childnode.data = {
centerX:minderWidth/2+200,
centerY:minderHeight/2+200,
style:{
radius:10,
fill:"yellow",
stroke:"orange",
color:"black",
padding:[10,10,10,10],
fontSize:12
},
text:"node",
};
console.log(minderWidth,minderHeight);
minder.execCommand("createchildnode",minder,minder.getRoot(),_node);
minder.execCommand("rendernode",minder,_node);
minder.execCommand("rendernode",minder,_childnode);
minder.reset(); minder.reset();
</script> </script>
</html> </html>
\ No newline at end of file
var ConnectModule = KityMinder.registerModule( "ConnectModule", function () { var ConnectModule = KityMinder.registerModule( "ConnectModule", function () {
return { return {
"commands": {
},
"events": { "events": {
"command": function ( e ) {
var command = e;
switch ( command.commandName ) {
case "rendernode":
( function () {
var minder = command.commandArgs[ 0 ];
var node = command.commandArgs[ 1 ];
if ( !node.parent ) {
return false;
} else {
var parent = node.parent;
// var _connect = new kity.Bezier(
// [ new kity.Point( parent.data.centerX, parent.data.centerY ),
// new kity.Point( node.data.centerX, node.data.centerY )
// ] );
_connect.stroke( new Pen( node.data.stroke, node.data.strokeWidth ) );
minder.addShape( _connect );
}
} )();
break;
case "erasenode":
break;
default:
break;
};
}
} }
}; };
} ); } );
\ No newline at end of file
...@@ -3,8 +3,8 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -3,8 +3,8 @@ KityMinder.registerModule( "LayoutModule", function () {
return { return {
base: Command, base: Command,
execute: function ( km, parent ) { execute: function ( km, parent, node ) {
parent.insertChild( node );
} }
} }
} )() ); } )() );
...@@ -12,8 +12,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -12,8 +12,9 @@ KityMinder.registerModule( "LayoutModule", function () {
return { return {
base: Command, base: Command,
execute: function ( km, sibling ) { execute: function ( km, sibling, node ) {
var parent = sibling.getParent();
parent.insertChild( node );
} }
} }
} )() ); } )() );
...@@ -22,7 +23,8 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -22,7 +23,8 @@ KityMinder.registerModule( "LayoutModule", function () {
return { return {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
var parent = sibling.getParent();
parent.removeChild( node );
} }
} }
} )() ); } )() );
......
...@@ -3,14 +3,18 @@ KityMinder.registerModule( "RenderModule", function () { ...@@ -3,14 +3,18 @@ KityMinder.registerModule( "RenderModule", function () {
var node_default = { var node_default = {
centerX: 0, centerX: 0,
centerY: 0, centerY: 0,
radius: 5,
text: "Root", text: "Root",
fill: "#7ecef4", style: {
stroke: "white", fill: "#7ecef4",
padding: 5 stroke: "white",
strokeWidth: 3,
padding: 5,
radius: 5
}
}; };
var renderNode = function ( km, node ) { var renderNode = function ( km, node ) {
var nodeD = Utils.extend( node_default, node ); var nodeD = Utils.extend( node_default, node.data );
var _style = nodeD.style;
var kR = km.getRenderContainer(); var kR = km.getRenderContainer();
var _node = new kity.Group(); var _node = new kity.Group();
var _txt = new kity.Text( nodeD.text || "Node" ); var _txt = new kity.Text( nodeD.text || "Node" );
...@@ -19,13 +23,13 @@ KityMinder.registerModule( "RenderModule", function () { ...@@ -19,13 +23,13 @@ KityMinder.registerModule( "RenderModule", function () {
kR.addShape( _node ); kR.addShape( _node );
var txtWidth = _txt.getWidth(); var txtWidth = _txt.getWidth();
var txtHeight = _txt.getHeight(); var txtHeight = _txt.getHeight();
var _padding = nodeD.padding; var _padding = _style.padding;
var _rectWidth = txtWidth + _padding[ 1 ] + _padding[ 3 ]; var _rectWidth = txtWidth + _padding[ 1 ] + _padding[ 3 ];
var _rectHeight = txtHeight + _padding[ 0 ] + _padding[ 2 ]; var _rectHeight = txtHeight + _padding[ 0 ] + _padding[ 2 ];
console.log( _rectWidth, _rectHeight ); console.log( _rectWidth, _rectHeight );
var _rect = new kity.Rect( _rectWidth, _rectHeight, 0, 0, nodeD.radius ); var _rect = new kity.Rect( _rectWidth, _rectHeight, 0, 0, _style.radius );
_rect.stroke( nodeD.stroke ).fill( nodeD.fill ); _rect.stroke( new kity.Pen( _style.stroke, _style.strokeWidth ) ).fill( _style.fill );
_node.addShape( _rect ).bringTop( _txt ); _node.addShape( _rect ).bringTop( _txt );
_node.translate( nodeD.centerX - _rectWidth / 2, nodeD.centerY - _rectHeight / 2 ); _node.translate( nodeD.centerX - _rectWidth / 2, nodeD.centerY - _rectHeight / 2 );
_txt.setX( _padding[ 3 ] ).setY( _padding[ 0 ] + txtHeight ); _txt.setX( _padding[ 3 ] ).setY( _padding[ 0 ] + txtHeight );
...@@ -33,19 +37,28 @@ KityMinder.registerModule( "RenderModule", function () { ...@@ -33,19 +37,28 @@ KityMinder.registerModule( "RenderModule", function () {
return { return {
base: Command, base: Command,
execute: function ( km, nodeData ) { execute: function ( km, node ) {
renderNode( km, node ); renderNode( km, node );
} }
}; };
} )() ); } )() );
var EraseNodeCommand = kity.createClass( "EraseNodeCommand", ( function () {
return {
base: Command,
execute: function ( km, node ) {
}
}
} )() );
return { return {
"init": function ( config ) { "init": function ( config ) {
}, },
"commands": { "commands": {
//todo:command字典,name-action 键值对模式编写 //todo:command字典,name-action 键值对模式编写
"rendernode": RenderNodeCommand "rendernode": RenderNodeCommand,
"erasenode": EraseNodeCommand
}, },
"events": { "events": {
......
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