Commit 104a05e7 authored by campaign's avatar campaign

Merge branch 'dev' of https://github.com/fex-team/kityminder into dev

parents 41ecad4f f44593c4
dialogs/markers/images/iconpriority.png

3.74 KB | W: | H:

dialogs/markers/images/iconpriority.png

4.44 KB | W: | H:

dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
  • 2-up
  • Swipe
  • Onion skin
dialogs/markers/images/iconprogress.png

3.74 KB | W: | H:

dialogs/markers/images/iconprogress.png

5.06 KB | W: | H:

dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -7,20 +7,39 @@ ...@@ -7,20 +7,39 @@
".kmui-dialog-<%= container %> .icon.p3{background-position: -40px 0}" + ".kmui-dialog-<%= container %> .icon.p3{background-position: -40px 0}" +
".kmui-dialog-<%= container %> .icon.p4{background-position: -60px 0}" + ".kmui-dialog-<%= container %> .icon.p4{background-position: -60px 0}" +
".kmui-dialog-<%= container %> .icon.p5{background-position: -80px 0}" + ".kmui-dialog-<%= container %> .icon.p5{background-position: -80px 0}" +
".kmui-dialog-<%= container %> .icon.p6{background-position: -100px 0}" +
".kmui-dialog-<%= container %> .icon.p7{background-position: -120px 0}" +
".kmui-dialog-<%= container %> .icon.p8{background-position: -140px 0}" +
".kmui-dialog-<%= container %> .icon.p9{background-position: -160px 0}" +
".kmui-dialog-<%= container %> .icon.p0{background-position: -180px 0}" +
".kmui-dialog-<%= container %> ul li{width:40%;display:inline-block}" +
".kmui-dialog-<%= container %> h4{padding:5px 10px; margin:0; background:#eee}" +
"</style>" + "</style>" +
"<h4><%= priority %></h3>" +
"<ul class='icon-list priority'>" + "<ul class='icon-list priority'>" +
"<li value='1' type='priority'><span class='icon p1'></span><span><%= priority %>1</span></li>" + "<li value='1' type='priority'><span class='icon p1'></span><span><%= priority %>1</span></li>" +
"<li value='2' type='priority'><span class='icon p2'></span><span><%= priority %>2</span></li>" + "<li value='2' type='priority'><span class='icon p2'></span><span><%= priority %>2</span></li>" +
"<li value='3' type='priority'><span class='icon p3'></span><span><%= priority %>3</span></li>" + "<li value='3' type='priority'><span class='icon p3'></span><span><%= priority %>3</span></li>" +
"<li value='4' type='priority'><span class='icon p4'></span><span><%= priority %>4</span></li>" + "<li value='4' type='priority'><span class='icon p4'></span><span><%= priority %>4</span></li>" +
"<li value='5' type='priority'><span class='icon p5'></span><span><%= priority %>5</span></li>" + "<li value='5' type='priority'><span class='icon p5'></span><span><%= priority %>5</span></li>" +
"<li value='6' type='priority'><span class='icon p6'></span><span><%= priority %>6</span></li>" +
"<li value='7' type='priority'><span class='icon p7'></span><span><%= priority %>7</span></li>" +
"<li value='8' type='priority'><span class='icon p8'></span><span><%= priority %>8</span></li>" +
"<li value='9' type='priority'><span class='icon p9'></span><span><%= priority %>9</span></li>" +
"<li value='0' type='priority'><span class='icon p0'></span><span><%= none %></span></li>" +
"</ul>" + "</ul>" +
"<h4><%= progress.title %></h4>" +
"<ul class='icon-list progress'>" + "<ul class='icon-list progress'>" +
"<li value='1' type='progress'><span class='icon p1'></span><span><%= progress.notdone %></span></li>" + "<li value='1' type='progress'><span class='icon p1'></span><span><%= progress.notdone %></span></li>" +
"<li value='2' type='progress'><span class='icon p2'></span><span><%= progress.quarterdone %></span></li>" + "<li value='2' type='progress'><span class='icon p2'></span><span><%= progress.done1 %></span></li>" +
"<li value='3' type='progress'><span class='icon p3'></span><span><%= progress.halfdone %></span></li>" + "<li value='3' type='progress'><span class='icon p3'></span><span><%= progress.done2 %></span></li>" +
"<li value='4' type='progress'><span class='icon p4'></span><span><%= progress.threequartersdone %></span></li>" + "<li value='4' type='progress'><span class='icon p4'></span><span><%= progress.done3 %></span></li>" +
"<li value='5' type='progress'><span class='icon p5'></span><span><%= progress.done %></span></li>" + "<li value='5' type='progress'><span class='icon p5'></span><span><%= progress.done4 %></span></li>" +
"<li value='6' type='progress'><span class='icon p6'></span><span><%= progress.done5 %></span></li>" +
"<li value='7' type='progress'><span class='icon p7'></span><span><%= progress.done6 %></span></li>" +
"<li value='8' type='progress'><span class='icon p8'></span><span><%= progress.done7 %></span></li>" +
"<li value='9' type='progress'><span class='icon p9'></span><span><%= progress.done %></span></li>" +
"<li value='0' type='progress'><span class='icon p0'></span><span><%= none %></span></li>" +
"</ul>", "</ul>",
initContent: function (km, $w) { initContent: function (km, $w) {
var lang = km.getLang('dialogs.markers'); var lang = km.getLang('dialogs.markers');
...@@ -30,8 +49,8 @@ ...@@ -30,8 +49,8 @@
}, lang)); }, lang));
} }
this.root().html(html); this.root().html(html);
var valPri = km.queryCommandValue("priority"); var valPri = km.queryCommandValue("priority") || 0;
var valPro = km.queryCommandValue("progress"); var valPro = km.queryCommandValue("progress") || 0;
$w.find("li[type='priority']").removeClass("active"); $w.find("li[type='priority']").removeClass("active");
$w.find("li[type='priority'][value='" + valPri + "']").addClass("active"); $w.find("li[type='priority'][value='" + valPri + "']").addClass("active");
$w.find("li[type='progress']").removeClass("active"); $w.find("li[type='progress']").removeClass("active");
...@@ -41,11 +60,7 @@ ...@@ -41,11 +60,7 @@
$w.on("click", "li", function () { $w.on("click", "li", function () {
var $this = $(this); var $this = $(this);
$this.siblings().removeClass("active"); $this.siblings().removeClass("active");
$this.toggleClass("active");
var val = $this.val(); var val = $this.val();
if (!$this.hasClass("active")) {
val = null;
}
var type = $this.attr("type"); var type = $this.attr("type");
km.execCommand(type, val); km.execCommand(type, val);
}); });
......
( function () { (function () {
function getKMBasePath( docUrl, confUrl ) { function getKMBasePath(docUrl, confUrl) {
return getBasePath( docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath() ); return getBasePath(docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath());
} }
function getConfigFilePath() { function getConfigFilePath() {
var configPath = document.getElementsByTagName( 'script' ); var configPath = document.getElementsByTagName('script');
return configPath[ configPath.length - 1 ].src; return configPath[configPath.length - 1].src;
} }
function getBasePath( docUrl, confUrl ) { function getBasePath(docUrl, confUrl) {
var basePath = confUrl; var basePath = confUrl;
if ( /^(\/|\\\\)/.test( confUrl ) ) { if (/^(\/|\\\\)/.test(confUrl)) {
basePath = /^.+?\w(\/|\\\\)/.exec( docUrl )[ 0 ] + confUrl.replace( /^(\/|\\\\)/, '' ); basePath = /^.+?\w(\/|\\\\)/.exec(docUrl)[0] + confUrl.replace(/^(\/|\\\\)/, '');
} else if ( !/^[a-z]+:/i.test( confUrl ) ) { } else if (!/^[a-z]+:/i.test(confUrl)) {
docUrl = docUrl.split( "#" )[ 0 ].split( "?" )[ 0 ].replace( /[^\\\/]+$/, '' ); docUrl = docUrl.split("#")[0].split("?")[0].replace(/[^\\\/]+$/, '');
basePath = docUrl + "" + confUrl; basePath = docUrl + "" + confUrl;
} }
return optimizationPath( basePath ); return optimizationPath(basePath);
} }
function optimizationPath( path ) { function optimizationPath(path) {
var protocol = /^[a-z]+:\/\//.exec( path )[ 0 ], var protocol = /^[a-z]+:\/\//.exec(path)[0],
tmp = null, tmp = null,
res = []; res = [];
path = path.replace( protocol, "" ).split( "?" )[ 0 ].split( "#" )[ 0 ]; path = path.replace(protocol, "").split("?")[0].split("#")[0];
path = path.replace( /\\/g, '/' ).split( /\// ); path = path.replace(/\\/g, '/').split(/\//);
path[ path.length - 1 ] = ""; path[path.length - 1] = "";
while ( path.length ) { while (path.length) {
if ( ( tmp = path.shift() ) === ".." ) { if ((tmp = path.shift()) === "..") {
res.pop(); res.pop();
} else if ( tmp !== "." ) { } else if (tmp !== ".") {
res.push( tmp ); res.push(tmp);
} }
} }
return protocol + res.join( "/" ); return protocol + res.join("/");
} }
window.KITYMINDER_CONFIG = { window.KITYMINDER_CONFIG = {
'KITYMINDER_HOME_URL': getKMBasePath(), 'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏 //定义工具栏
toolbars: [ toolbars: [
'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | hyperlink unhyperlink image removeimage | markers resource | node | help' 'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | switchlayout | hyperlink unhyperlink image removeimage | markers resource | node | help'
] ]
//只读模式,默认是false //只读模式,默认是false
//readOnly: true //readOnly: true
...@@ -95,4 +95,4 @@ ...@@ -95,4 +95,4 @@
//,maxImageHeight: 200 //,maxImageHeight: 200
// //
}; };
} )(); })();
\ No newline at end of file \ No newline at end of file
KityMinder.LANG[ 'zh-cn' ] = { KityMinder.LANG['zh-cn'] = {
'maintopic': '中心主题', 'maintopic': '中心主题',
'topic': '分支主题', 'topic': '分支主题',
'tooltips': { 'tooltips': {
...@@ -39,11 +39,17 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -39,11 +39,17 @@ KityMinder.LANG[ 'zh-cn' ] = {
'lang_input_target': '是否在新窗口打开:' 'lang_input_target': '是否在新窗口打开:'
}, },
'priority': '优先级', 'priority': '优先级',
'none': '无',
'progress': { 'progress': {
'title': '进度',
'notdone': "未完成", 'notdone': "未完成",
'quarterdone': '完成1/4', 'done1': '完成1/8',
'halfdone': '完成1/2', 'done2': '完成1/4',
'threequartersdone': '完成3/4', 'done3': '完成3/8',
'done4': '完成1/2',
'done5': '完成5/8',
'done6': '完成3/4',
'done7': '完成7/8',
'done': '已完成' 'done': '已完成'
} }
}, },
...@@ -52,8 +58,7 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -52,8 +58,7 @@ KityMinder.LANG[ 'zh-cn' ] = {
}, },
'hyperlink': {}, 'hyperlink': {},
'image': {}, 'image': {},
'resource': { 'resource': {}
}
}, },
'node': { 'node': {
'appendsiblingnode': '插入同级节点', 'appendsiblingnode': '插入同级节点',
...@@ -65,11 +70,11 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -65,11 +70,11 @@ KityMinder.LANG[ 'zh-cn' ] = {
'default': '左右展开', 'default': '左右展开',
'bottom': '向下展开' 'bottom': '向下展开'
}, },
'hyperlink':{ 'hyperlink': {
'hyperlink':'插入超链接', 'hyperlink': '插入超链接',
'unhyperlink':"取消超链接" 'unhyperlink': "取消超链接"
}, },
'image':{ 'image': {
'image': '插入图片', 'image': '插入图片',
'removeimage': '删除图片' 'removeimage': '删除图片'
} }
......
KM.registerToolbarUI( 'switchlayout', function ( name ) { KM.registerToolbarUI('switchlayout', function (name) {
var me = this, var me = this,
label = me.getLang( 'tooltips.' + name ), label = me.getLang('tooltips.' + name),
options = { options = {
label: label, label: label,
title: label, title: label,
...@@ -13,54 +12,55 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) { ...@@ -13,54 +12,55 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
enabledRecord: false enabledRecord: false
}, },
$combox = null; $combox = null;
if ( options.items.length == 0 ) { if (options.items.length == 0) {
return null; return null;
} }
utils.each( options.items, function ( i, item ) { utils.each(options.items, function (i, item) {
options.items[ i ] = me.getLang( 'layout' )[ item ]; options.items[i] = me.getLang('layout')[item];
} ); });
//实例化 //实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 ); $combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
var comboboxWidget = $combox.kmui(); var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on('comboboxselect', function (evt, res) {
me.execCommand( name, res.value ); me.execCommand(name, res.value);
} ).on( "beforeshow", function () { me.initStyle();
if ( $combox.parent().length === 0 ) { }).on("beforeshow", function () {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
} }
} ); });
//状态反射 //状态反射
me.on( 'interactchange', function () { me.on('interactchange', function () {
var state = this.queryCommandState( name ), var state = this.queryCommandState(name),
value = this.queryCommandValue( name ); value = this.queryCommandValue(name);
//设置按钮状态 //设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 ); comboboxWidget.button().kmui().disabled(state == -1).active(state == 1);
if ( value ) { if (value) {
//设置label //设置label
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ ); value = value.replace(/['"]/g, '').toLowerCase().split(/['|"]?\s*,\s*[\1]?/);
comboboxWidget.selectItemByLabel( value ); comboboxWidget.selectItemByLabel(value);
} }
} ); });
var data = []; var data = [];
utils.each( me.getLayoutStyleItems(), function ( i, v ) { utils.each(me.getLayoutStyleItems(), function (i, v) {
data.push( { data.push({
label: me.getLang( 'tooltips.' + name ) + ' ' + v, label: me.getLang('tooltips.' + name) + ' ' + v,
cmdName: 'switchlayout', cmdName: 'switchlayout',
exec: function () { exec: function () {
me.execCommand( 'switchlayout', v ); me.execCommand('switchlayout', v);
} }
} ) })
} ); });
data.push( { data.push({
divider: 1 divider: 1
} ); });
me.addContextmenu( data ); me.addContextmenu(data);
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass('kmui-combobox');
} ); });
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "IconModule", function () { KityMinder.registerModule("IconModule", function () {
var minder = this; var minder = this;
var renderPriorityIcon = function ( node, val ) { var renderPriorityIcon = function (node, val) {
var colors = [ "", "#A92E24", "#29A6BD", "#1E8D54", "#eb6100", "#876DDA" ]; var colors = ["", "#A92E24", "#29A6BD", "#1E8D54", "#eb6100", "#876DDA", "#828282", "#828282", "#828282", "#828282"];
var _bg = new kity.Rect().fill( colors[ val ] ).setRadius( 3 ).setWidth( 20 ).setHeight( 20 ); var bgcolor = colors[val];
var _number = new kity.Text().setContent( val ).fill( "white" ).setSize( 12 ); var _bg = new kity.Rect().fill(colors[val]).setRadius(3).setWidth(20).setHeight(20);
var _number = new kity.Text().setContent(val).fill("white").setSize(12);
var _rc = new kity.Group(); var _rc = new kity.Group();
_rc.addShapes( [ _bg, _number ] ); _rc.addShapes([_bg, _number]);
node.getContRc().addShape( _rc ); node.getContRc().addShape(_rc);
_number.setTranslate( 6, 15 ); _number.setTranslate(6, 15);
var rcHeight = _rc.getHeight(); var rcHeight = _rc.getHeight();
_rc.setTranslate( 0, -rcHeight / 2 ); _rc.setTranslate(0, -rcHeight / 2);
}; };
var renderProgressIcon = function ( node, val ) { var renderProgressIcon = function (node, val) {
var _rc = new kity.Group(); var _rc = new kity.Group();
var _contRc = node.getContRc(); var _contRc = node.getContRc();
var _bg = new kity.Circle().setRadius( 8 ).fill( "white" ).stroke( new kity.Pen( "#29A6BD", 2 ) ); var _bg = new kity.Circle().setRadius(8).fill("white").stroke(new kity.Pen("#29A6BD", 2));
var _percent, d; var _percent, d;
if ( val < 5 ) { if (val < 9) {
_percent = new kity.Path(); _percent = new kity.Path();
d = _percent.getDrawer(); d = _percent.getDrawer();
d.moveTo( 0, 0 ).lineTo( 6, 0 ); d.moveTo(0, 0).lineTo(0, -6);
} else _percent = new kity.Group(); } else _percent = new kity.Group();
_rc.addShapes( [ _bg, _percent ] ); _rc.addShapes([_bg, _percent]);
_contRc.addShape( _rc ); _contRc.addShape(_rc);
switch ( val ) { //r, laf, sf, x, y
//large-arc-flag 为1 表示大角度弧线,0 代表小角度弧线。
//sweep-flag 为1代表从起点到终点弧线绕中心顺时针方向,0 代表逆时针方向。
switch (val) {
case 1: case 1:
break; break;
case 2: case 2:
d.carcTo( 6, 0, 0, 0, -6 ); d.carcTo(6, 0, 1, 6 * Math.cos(2 * Math.PI / 8), -6 * Math.sin(2 * Math.PI / 8));
break; break;
case 3: case 3:
d.carcTo( 6, 0, 0, -6, 0 ); d.carcTo(6, 0, 1, 6, 0);
break; break;
case 4: case 4:
d.carcTo( 6, 1, 0, 0, 6 ); d.carcTo(6, 0, 1, 6 * Math.cos(2 * Math.PI / 8), 6 * Math.sin(2 * Math.PI / 8));
break; break;
case 5: case 5:
d.carcTo(6, 0, 1, 0, 6);
break;
case 6:
d.carcTo(6, 1, 1, -6 * Math.cos(2 * Math.PI / 8), 6 * Math.sin(2 * Math.PI / 8));
break;
case 7:
d.carcTo(6, 1, 1, -6, 0);
break;
case 8:
d.carcTo(6, 1, 1, -6 * Math.cos(2 * Math.PI / 8), -6 * Math.sin(2 * Math.PI / 8));
break;
case 9:
var check = new kity.Path(); var check = new kity.Path();
_percent.addShapes( [ new kity.Circle().setRadius( 6 ).fill( "#29A6BD" ), check ] ); _percent.addShapes([new kity.Circle().setRadius(6).fill("#29A6BD"), check]);
check.getDrawer().moveTo( -3, 0 ).lineTo( -1, 3 ).lineTo( 3, -2 ); check.getDrawer().moveTo(-3, 0).lineTo(-1, 3).lineTo(3, -2);
check.stroke( new kity.Pen( "white", 2 ).setLineCap( "round" ) ); check.stroke(new kity.Pen("white", 2).setLineCap("round"));
break; break;
} }
if ( val < 5 ) d.close(); if (val && val < 8) d.close();
_percent.fill( "#29A6BD" ); _percent.fill("#29A6BD");
var pre = node.getData( "PriorityIcon" ); var pre = node.getData("PriorityIcon");
var style = minder.getCurrentLayoutStyle()[ node.getType() ]; var style = minder.getCurrentLayoutStyle()[node.getType()];
if ( !pre ) _rc.setTranslate( _rc.getWidth() / 2, 0 ); if (!pre) _rc.setTranslate(_rc.getWidth() / 2, 0);
else _rc.setTranslate( _contRc.getWidth() + style.spaceLeft, 0 ); else _rc.setTranslate(_contRc.getWidth() + style.spaceLeft, 0);
}; };
var setPriorityCommand = kity.createClass( "SetPriorityCommand", ( function () { var setPriorityCommand = kity.createClass("SetPriorityCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, value ) { execute: function (km, value) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
nodes[ i ].setData( "PriorityIcon", value ); nodes[i].setData("PriorityIcon", value);
km.updateLayout( nodes[ i ] ); km.updateLayout(nodes[i]);
} }
}, },
queryValue: function ( km ) { queryValue: function (km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
var val; var val;
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
val = nodes[ i ].getData( "PriorityIcon" ); val = nodes[i].getData("PriorityIcon");
if ( val ) break; if (val) break;
} }
return val; return val;
} }
}; };
} )() ); })());
var setProgressCommand = kity.createClass( "SetProgressCommand", ( function () { var setProgressCommand = kity.createClass("SetProgressCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, value ) { execute: function (km, value) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
nodes[ i ].setData( "ProgressIcon", value ); nodes[i].setData("ProgressIcon", value);
km.updateLayout( nodes[ i ] ); km.updateLayout(nodes[i]);
} }
}, },
queryValue: function ( km ) { queryValue: function (km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
var val; var val;
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
val = nodes[ i ].getData( "ProgressIcon" ); val = nodes[i].getData("ProgressIcon");
if ( val ) break; if (val) break;
} }
return val; return val;
} }
}; };
} )() ); })());
return { return {
"commands": { "commands": {
"priority": setPriorityCommand, "priority": setPriorityCommand,
"progress": setProgressCommand "progress": setProgressCommand
}, },
"events": { "events": {
"RenderNodeLeft": function ( e ) { "RenderNodeLeft": function (e) {
var node = e.node; var node = e.node;
var PriorityIconVal = node.getData( "PriorityIcon" ); var PriorityIconVal = node.getData("PriorityIcon");
var ProgressIconVal = node.getData( "ProgressIcon" ); var ProgressIconVal = node.getData("ProgressIcon");
var contRc = node.getContRc(); var contRc = node.getContRc();
if ( PriorityIconVal ) { if (PriorityIconVal) {
renderPriorityIcon( node, PriorityIconVal ); renderPriorityIcon(node, PriorityIconVal);
} }
if ( ProgressIconVal ) { if (ProgressIconVal) {
renderProgressIcon( node, ProgressIconVal ); renderProgressIcon(node, ProgressIconVal);
} }
} }
} }
}; };
} ); });
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "KeyboardModule", function () { KityMinder.registerModule("KeyboardModule", function () {
var min = Math.min, var min = Math.min,
max = Math.max, max = Math.max,
abs = Math.abs, abs = Math.abs,
sqrt = Math.sqrt, sqrt = Math.sqrt,
exp = Math.exp; exp = Math.exp;
function buildPositionNetwork( root ) { function buildPositionNetwork(root) {
var pointIndexes = [], var pointIndexes = [],
p; p;
root.traverse( function ( node ) { root.traverse(function (node) {
p = node.getRenderContainer().getRenderBox( 'top' ); p = node.getRenderContainer().getRenderBox('top');
// bugfix: 不应导航到收起的节点(判断其尺寸是否存在) // bugfix: 不应导航到收起的节点(判断其尺寸是否存在)
if ( p.width && p.height ) { if (p.width && p.height) {
pointIndexes.push( { pointIndexes.push({
left: p.x, left: p.x,
top: p.y, top: p.y,
right: p.x + p.width, right: p.x + p.width,
...@@ -22,30 +22,30 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -22,30 +22,30 @@ KityMinder.registerModule( "KeyboardModule", function () {
height: p.height, height: p.height,
node: node, node: node,
text: node.getText() text: node.getText()
} ); });
} }
} ); });
for ( var i = 0; i < pointIndexes.length; i++ ) { for (var i = 0; i < pointIndexes.length; i++) {
findClosestPointsFor( pointIndexes, i ); findClosestPointsFor(pointIndexes, i);
} }
} }
// 这是金泉的点子,赞! // 这是金泉的点子,赞!
// 求两个不相交矩形的最近距离 // 求两个不相交矩形的最近距离
function getCoefedDistance( box1, box2 ) { function getCoefedDistance(box1, box2) {
var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy; var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
xMin = min( box1.left, box2.left ); xMin = min(box1.left, box2.left);
xMax = max( box1.right, box2.right ); xMax = max(box1.right, box2.right);
yMin = min( box1.top, box2.top ); yMin = min(box1.top, box2.top);
yMax = max( box1.bottom, box2.bottom ); yMax = max(box1.bottom, box2.bottom);
xDist = xMax - xMin - box1.width - box2.width; xDist = xMax - xMin - box1.width - box2.width;
yDist = yMax - yMin - box1.height - box2.height; yDist = yMax - yMin - box1.height - box2.height;
if ( xDist < 0 ) dist = yDist; if (xDist < 0) dist = yDist;
else if ( yDist < 0 ) dist = xDist; else if (yDist < 0) dist = xDist;
else dist = sqrt( xDist * xDist + yDist * yDist ); else dist = sqrt(xDist * xDist + yDist * yDist);
return { return {
cx: dist, cx: dist,
...@@ -53,21 +53,22 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -53,21 +53,22 @@ KityMinder.registerModule( "KeyboardModule", function () {
}; };
} }
function findClosestPointsFor( pointIndexes, iFind ) { function findClosestPointsFor(pointIndexes, iFind) {
var find = pointIndexes[ iFind ]; var find = pointIndexes[iFind];
var most = {}, quad; var most = {},
quad;
var current, dist; var current, dist;
for ( var i = 0; i < pointIndexes.length; i++ ) { for (var i = 0; i < pointIndexes.length; i++) {
if ( i == iFind ) continue; if (i == iFind) continue;
current = pointIndexes[ i ]; current = pointIndexes[i];
dist = getCoefedDistance( current, find ); dist = getCoefedDistance(current, find);
// left check // left check
if ( current.right < find.left ) { if (current.right < find.left) {
if ( !most.left || dist.cx < most.left.dist ) { if (!most.left || dist.cx < most.left.dist) {
most.left = { most.left = {
dist: dist.cx, dist: dist.cx,
node: current.node node: current.node
...@@ -76,8 +77,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -76,8 +77,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// right check // right check
if ( current.left > find.right ) { if (current.left > find.right) {
if ( !most.right || dist.cx < most.right.dist ) { if (!most.right || dist.cx < most.right.dist) {
most.right = { most.right = {
dist: dist.cx, dist: dist.cx,
node: current.node node: current.node
...@@ -86,8 +87,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -86,8 +87,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// top check // top check
if ( current.bottom < find.top ) { if (current.bottom < find.top) {
if ( !most.top || dist.cy < most.top.dist ) { if (!most.top || dist.cy < most.top.dist) {
most.top = { most.top = {
dist: dist.cy, dist: dist.cy,
node: current.node node: current.node
...@@ -96,8 +97,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -96,8 +97,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// bottom check // bottom check
if ( current.top > find.bottom ) { if (current.top > find.bottom) {
if ( !most.down || dist.cy < most.down.dist ) { if (!most.down || dist.cy < most.down.dist) {
most.down = { most.down = {
dist: dist.cy, dist: dist.cy,
node: current.node node: current.node
...@@ -114,63 +115,63 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -114,63 +115,63 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
function navigateTo( km, direction ) { function navigateTo(km, direction) {
var referNode = km.getSelectedNode(); var referNode = km.getSelectedNode();
if ( !referNode ) { if (!referNode) {
km.select( km.getRoot() ); km.select(km.getRoot());
buildPositionNetwork( km.getRoot() ); buildPositionNetwork(km.getRoot());
return; return;
} }
var nextNode = referNode._nearestNodes[ direction ]; var nextNode = referNode._nearestNodes[direction];
if ( nextNode ) { if (nextNode) {
km.select( nextNode, true ); km.select(nextNode, true);
} }
} }
return { return {
"events": { "events": {
contentchange: function () { contentchange: function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork(this.getRoot());
}, },
"normal.keydown": function ( e ) { "normal.keydown": function (e) {
var keys = KityMinder.keymap; var keys = KityMinder.keymap;
var node = e.getTargetNode(); var node = e.getTargetNode();
this.receiver.keydownNode = node; this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) { switch (e.originEvent.keyCode) {
case keys.Enter: case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ), true ); this.execCommand('appendSiblingNode', new MinderNode(this.getLang().topic));
e.preventDefault(); e.preventDefault();
break; break;
case keys.Tab: case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ), true ); this.execCommand('appendChildNode', new MinderNode(this.getLang().topic));
e.preventDefault(); e.preventDefault();
break; break;
case keys.Backspace: case keys.Backspace:
case keys.Del: case keys.Del:
e.preventDefault(); e.preventDefault();
this.execCommand( 'removenode' ); this.execCommand('removenode');
break; break;
case keys.F2: case keys.F2:
e.preventDefault(); e.preventDefault();
this.execCommand( 'editnode' ); this.execCommand('editnode');
break; break;
case keys.Left: case keys.Left:
navigateTo( this, 'left' ); navigateTo(this, 'left');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Up: case keys.Up:
navigateTo( this, 'top' ); navigateTo(this, 'top');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Right: case keys.Right:
navigateTo( this, 'right' ); navigateTo(this, 'right');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Down: case keys.Down:
navigateTo( this, 'down' ); navigateTo(this, 'down');
e.preventDefault(); e.preventDefault();
break; break;
} }
...@@ -178,4 +179,4 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -178,4 +179,4 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
} }
}; };
} ); });
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "LayoutBottom", function () { KityMinder.registerModule("LayoutBottom", function () {
var _target = this.getRenderTarget(); var _target = this.getRenderTarget();
function getMinderSize() { function getMinderSize() {
...@@ -9,43 +9,43 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -9,43 +9,43 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
var minder = this; var minder = this;
//收缩-展开子树的节点 //收缩-展开子树的节点
var ShIcon = kity.createClass( "DefaultshIcon", ( function () { var ShIcon = kity.createClass("DefaultshIcon", (function () {
return { return {
constructor: function ( node ) { constructor: function (node) {
this._show = false; this._show = false;
this._node = node; this._node = node;
var iconShape = this.shape = new kity.Group(); var iconShape = this.shape = new kity.Group();
iconShape.class = "shicon"; iconShape.class = "shicon";
iconShape.icon = this; iconShape.icon = this;
var rect = this._rect = new kity.Rect().fill( "white" ).stroke( "gray" ).setRadius( 2 ).setWidth( 10 ).setHeight( 10 ); var rect = this._rect = new kity.Rect().fill("white").stroke("gray").setRadius(2).setWidth(10).setHeight(10);
var plus = this._plus = new kity.Path(); var plus = this._plus = new kity.Path();
plus.getDrawer() plus.getDrawer()
.moveTo( 2, 5 ) .moveTo(2, 5)
.lineTo( 8, 5 ) .lineTo(8, 5)
.moveTo( 5, 2 ) .moveTo(5, 2)
.lineTo( 5, 8 ); .lineTo(5, 8);
plus.stroke( "gray" ); plus.stroke("gray");
var dec = this._dec = new kity.Path(); var dec = this._dec = new kity.Path();
dec.getDrawer() dec.getDrawer()
.moveTo( 2, 5 ) .moveTo(2, 5)
.lineTo( 8, 5 ); .lineTo(8, 5);
dec.stroke( "gray" ); dec.stroke("gray");
if ( node.getType() === "main" ) minder.getRenderContainer().addShape( iconShape ); if (node.getType() === "main") minder.getRenderContainer().addShape(iconShape);
else { else {
node.getLayout().subgroup.addShape( iconShape ); node.getLayout().subgroup.addShape(iconShape);
} }
iconShape.addShapes( [ rect, plus, dec ] ); iconShape.addShapes([rect, plus, dec]);
this.update(); this.update();
this.switchState(); this.switchState();
}, },
switchState: function () { switchState: function () {
if ( !this._show ) { if (!this._show) {
this._plus.setOpacity( 0 ); this._plus.setOpacity(0);
this._dec.setOpacity( 1 ); this._dec.setOpacity(1);
this._show = true; this._show = true;
} else { } else {
this._plus.setOpacity( 1 ); this._plus.setOpacity(1);
this._dec.setOpacity( 0 ); this._dec.setOpacity(0);
this._show = false; this._show = false;
} }
return this._show; return this._show;
...@@ -55,259 +55,282 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -55,259 +55,282 @@ KityMinder.registerModule( "LayoutBottom", function () {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x + 5; var nodeX = nodeShape.getRenderBox().closurePoints[1].x + 5;
var nodeY = nodeShape.getRenderBox().closurePoints[ 0 ].y; var nodeY = nodeShape.getRenderBox().closurePoints[0].y;
this.shape.setTranslate( nodeX, nodeY ); this.shape.setTranslate(nodeX, nodeY);
}, },
remove: function () { remove: function () {
this.shape.remove(); this.shape.remove();
} }
}; };
} )() ); })());
//样式的配置(包括颜色、字号等) //样式的配置(包括颜色、字号等)
var nodeStyles = { var nodeStyles = {
"root": { "root": {
color: '#430', color: '#430',
fill: '#e9df98', fill: '#e9df98',
fontSize: 24, fontSize: 24,
padding: [ 15.5, 25.5, 15.5, 25.5 ], padding: [15.5, 25.5, 15.5, 25.5],
margin: [ 0, 0, 20, 0 ], margin: [0, 0, 20, 0],
radius: 0, radius: 0,
highlight: 'rgb(254, 219, 0)' highlight: 'rgb(254, 219, 0)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
}, },
"main": { "main": {
stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ), stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
fill: '#A4c5c0', fill: '#A4c5c0',
color: "#333", color: "#333",
padding: [ 6.5, 20, 6.5, 20 ], padding: [6.5, 20, 6.5, 20],
fontSize: 16, fontSize: 16,
margin: [ 20, 20, 10, 10 ], margin: [20, 20, 10, 10],
radius: 0, radius: 0,
highlight: 'rgb(254, 219, 0)' highlight: 'rgb(254, 219, 0)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
}, },
"sub": { "sub": {
stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ), stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
color: "#333", color: "#333",
fontSize: 12, fontSize: 12,
margin: [ 10, 10, 10, 30 ], margin: [10, 10, 10, 30],
padding: [ 5, 10, 5.5, 10 ], padding: [5, 10, 5.5, 10],
highlight: 'rgb(254, 219, 0)', highlight: 'rgb(254, 219, 0)',
fill: 'rgb(231, 243, 255)' fill: 'rgb(231, 243, 255)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
} }
}; };
//更新背景 //更新背景
var updateBg = function ( node ) { var updateBg = function (node) {
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( node.getType() ) { switch (node.getType()) {
case "root": case "root":
case "main": case "main":
var bg = node.getBgRc().clear(); var bg = node.getBgRc().clear();
bg.addShape( Layout.bgShadow = new kity.Rect() ); bg.addShape(Layout.bgShadow = new kity.Rect());
bg.addShape( Layout.bgRect = new kity.Rect() ); bg.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill( nodeStyle.fill ).setRadius( nodeStyle.radius ); Layout.bgRect.fill(nodeStyle.fill).setRadius(nodeStyle.radius);
Layout.bgShadow.fill( 'black' ).setOpacity( 0.2 ).setRadius( nodeStyle.radius ).translate( 3, 5 ); Layout.bgShadow.fill('black').setOpacity(0.2).setRadius(nodeStyle.radius).translate(3, 5);
break; break;
case "sub": case "sub":
var bgRc = node.getBgRc().clear(); var bgRc = node.getBgRc().clear();
bgRc.addShape( Layout.bgRect = new kity.Rect() ); bgRc.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill( nodeStyle.fill ); Layout.bgRect.fill(nodeStyle.fill);
break; break;
default: default:
break; break;
} }
}; };
//初始化样式 //初始化样式
var initLayout = function ( node ) { var initLayout = function (node) {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
// var txtShape = node.getTextShape(); // var txtShape = node.getTextShape();
// txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 ); // txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if ( nodeType === "main" ) { if (nodeType === "main") {
var subgroup = Layout.subgroup = new kity.Group(); var subgroup = Layout.subgroup = new kity.Group();
minder.getRenderContainer().addShape( subgroup ); minder.getRenderContainer().addShape(subgroup);
} }
}; };
//根据内容调整节点尺寸 //根据内容调整节点尺寸
var updateShapeByCont = function ( node ) { var updateShapeByCont = function (node) {
var contRc = node.getContRc(); var contRc = node.getContRc();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var _contRCWidth = contRc.getWidth(); var _contRCWidth = contRc.getWidth();
var _contRCHeight = contRc.getHeight(); var _contRCHeight = contRc.getHeight();
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( nodeType ) { switch (nodeType) {
case "root": case "root":
case "main": case "main":
var width = _contRCWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], var width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3],
height = _contRCHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ]; height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth( width ).setHeight( height ); Layout.bgRect.setWidth(width).setHeight(height);
Layout.bgShadow.setWidth( width ).setHeight( height ); Layout.bgShadow.setWidth(width).setHeight(height);
break; break;
case "sub": case "sub":
width = _contRCWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ]; width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3];
height = _contRCHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ]; height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth( width ).setHeight( height ); Layout.bgRect.setWidth(width).setHeight(height);
break; break;
default: default:
break; break;
} }
contRc.setTranslate( nodeStyle.padding[ 3 ], nodeStyle.padding[ 0 ] + _contRCHeight / 2 ); var rBox = contRc.getRenderBox();
// Todo:很坑的改法,不知为何就对了,需要处理
contRc.setTranslate(nodeStyle.padding[3], 0);
contRc.translate(0, nodeStyle.padding[0] - rBox.top);
}; };
var updateLayoutMain = function () { var updateLayoutMain = function () {
var _root = minder.getRoot(); var _root = minder.getRoot();
var mainnodes = _root.getChildren(); var mainnodes = (function () {
var countMainWidth = function ( node ) { var main_added = [];
var children = _root.getChildren();
for (var i = 0; i < children.length; i++) {
if (children[i].getLayout().added) main_added.push(children[i]);
}
return main_added;
})();
var countMainWidth = function (node) {
var nLayout = node.getLayout(); var nLayout = node.getLayout();
var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[ 1 ] + nodeStyles.main.margin[ 3 ]; var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[1] + nodeStyles.main.margin[3];
var childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[ 1 ] + nodeStyles.sub.margin[ 3 ]; var childwidth = 0;
var branchwidth = nLayout.branchwidth = ( selfwidth > childwidth ? selfwidth : childwidth ); if (nLayout.added) childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[1] + nodeStyles.sub.margin[3];
var branchwidth = nLayout.branchwidth = (selfwidth > childwidth ? selfwidth : childwidth);
return branchwidth; return branchwidth;
}; };
var rootLayout = _root.getLayout(); var rootLayout = _root.getLayout();
var rootbranchwidth = 0; var rootbranchwidth = 0;
for ( var j = 0; j < mainnodes.length; j++ ) { for (var j = 0; j < mainnodes.length; j++) {
rootbranchwidth += countMainWidth( mainnodes[ j ] ); rootbranchwidth += countMainWidth(mainnodes[j]);
} }
var sX = rootLayout.x - rootbranchwidth / 2; var sX = rootLayout.x - rootbranchwidth / 2;
for ( var k = 0; k < mainnodes.length; k++ ) { for (var k = 0; k < mainnodes.length; k++) {
var mLayout = mainnodes[ k ].getLayout(); var mLayout = mainnodes[k].getLayout();
mLayout.x = sX + nodeStyles.main.margin[ 3 ] + 5; mLayout.x = sX + nodeStyles.main.margin[3] + 5;
sX += mLayout.branchwidth; sX += mLayout.branchwidth;
} }
return mainnodes; return mainnodes;
}; };
var updateLayoutAll = function ( node, parent, action ) { var updateLayoutAll = function (node, parent, action) {
var effectSet = []; var effectSet = [];
var nodeType = node.getType(); var nodeType = node.getType();
var Layout = node.getLayout(); var Layout = node.getLayout();
var _root = minder.getRoot(); var _root = minder.getRoot();
var rootLayout = _root.getLayout(); var rootLayout = _root.getLayout();
if ( nodeType === "root" ) { if (nodeType === "root") {
Layout.x = getMinderSize().width / 2; Layout.x = getMinderSize().width / 2;
Layout.y = 100; Layout.y = 100;
Layout.align = "center"; Layout.align = "center";
effectSet.push( node ); effectSet.push(node);
var children = node.getChildren(); var children = node.getChildren();
for ( var i = 0; i < children.length; i++ ) { for (var i = 0; i < children.length; i++) {
var childLayout = children[ i ].getLayout(); var childLayout = children[i].getLayout();
childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[ 2 ] + nodeStyles.main.margin[ 0 ]; childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0];
} }
effectSet = effectSet.concat( children ); effectSet = effectSet.concat(children);
} else if ( nodeType === "main" ) { } else if (nodeType === "main") {
Layout.align = "left"; Layout.align = "left";
if ( action === "append" || action === "contract" ) { if (action === "append" || action === "contract") {
Layout.y = rootLayout.y + _root.getRenderContainer().getHeight() + nodeStyles.root.margin[ 2 ] + nodeStyles.main.margin[ 0 ]; Layout.y = rootLayout.y + _root.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0];
} }
effectSet = updateLayoutMain(); effectSet = updateLayoutMain();
} else { } else {
Layout.align = "left"; Layout.align = "left";
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
if ( action === "append" ) { if (action === "append") {
if ( parent.getType() === "main" ) { if (parent.getType() === "main") {
Layout.x = nodeStyles.sub.margin[ 3 ]; Layout.x = nodeStyles.sub.margin[3];
} else { } else {
Layout.x = parentLayout.x + nodeStyles.sub.margin[ 3 ]; Layout.x = parentLayout.x + nodeStyles.sub.margin[3];
} }
} }
if ( action === "append" || action === "contract" ) { if (action === "append" || action === "contract") {
Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyles.sub.margin[ 0 ] + nodeStyles.sub.margin[ 2 ]; Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2];
} }
var prt = parent; var prt = parent;
if ( action === "change" ) { if (action === "change") {
prt = node; prt = node;
} }
//自底向上更新branchheight //自底向上更新branchheight
while ( prt.getType() !== "main" ) { while (prt.getType() !== "main") {
var c = prt.getChildren(); var c = prt.getChildren();
var prtLayout = prt.getLayout(); var prtLayout = prt.getLayout();
var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[ 0 ] + nodeStyles.sub.margin[ 2 ]; var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2];
for ( var i1 = 0; i1 < c.length; i1++ ) { for (var i1 = 0; i1 < c.length; i1++) {
branchHeight += c[ i1 ].getLayout().branchheight; branchHeight += c[i1].getLayout().branchheight;
} }
prtLayout.branchheight = branchHeight; prtLayout.branchheight = branchHeight;
prt = prt.getParent(); prt = prt.getParent();
} }
//自顶向下更新y //自顶向下更新y
var _buffer = [ prt ]; var _buffer = [prt];
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
var childrenC = _buffer[ 0 ].getChildren(); var childrenC = _buffer[0].getChildren();
_buffer = _buffer.concat( childrenC ); _buffer = _buffer.concat(childrenC);
var _buffer0Layout = _buffer[ 0 ].getLayout(); var _buffer0Layout = _buffer[0].getLayout();
var _buffer0Style = nodeStyles[ _buffer[ 0 ].getType() ]; var _buffer0Style = nodeStyles[_buffer[0].getType()];
var sY; var sY;
if ( _buffer[ 0 ].getType() === "main" ) sY = 0; if (_buffer[0].getType() === "main") sY = 0;
else sY = _buffer0Layout.y + _buffer[ 0 ].getRenderContainer().getHeight() + _buffer0Style.margin[ 2 ]; else sY = _buffer0Layout.y + _buffer[0].getRenderContainer().getHeight() + _buffer0Style.margin[2];
for ( var s = 0; s < childrenC.length; s++ ) { for (var s = 0; s < childrenC.length; s++) {
var childLayoutC = childrenC[ s ].getLayout(); var childLayoutC = childrenC[s].getLayout();
var childStyleC = nodeStyles[ childrenC[ s ].getType() ]; var childStyleC = nodeStyles[childrenC[s].getType()];
childLayoutC.y = sY + childStyleC.margin[ 0 ]; childLayoutC.y = sY + childStyleC.margin[0];
sY += childLayoutC.branchheight; sY += childLayoutC.branchheight;
} }
effectSet.push( _buffer[ 0 ] ); effectSet.push(_buffer[0]);
_buffer.shift(); _buffer.shift();
} }
} }
return effectSet; return effectSet;
}; };
var translateNode = function ( node ) { var translateNode = function (node) {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var align = Layout.align; var align = Layout.align;
var _rectHeight = nodeShape.getHeight(); var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth(); var _rectWidth = nodeShape.getWidth();
switch ( align ) { switch (align) {
case "right": case "right":
nodeShape.setTranslate( Layout.x - _rectWidth, Layout.y ); nodeShape.setTranslate(Layout.x - _rectWidth, Layout.y);
break; break;
case "center": case "center":
nodeShape.setTranslate( Layout.x - _rectWidth / 2, Layout.y ); nodeShape.setTranslate(Layout.x - _rectWidth / 2, Layout.y);
break; break;
default: default:
nodeShape.setTranslate( Layout.x, Layout.y ); nodeShape.setTranslate(Layout.x, Layout.y);
break; break;
} }
if ( node.getType() === "main" ) { if (node.getType() === "main") {
Layout.subgroup.setTranslate( Layout.x, Layout.y + node.getRenderContainer().getHeight() ); Layout.subgroup.setTranslate(Layout.x, Layout.y + node.getRenderContainer().getHeight());
} }
node.setPoint( Layout.x, Layout.y ); node.setPoint(Layout.x, Layout.y);
}; };
var updateConnectAndshIcon = function ( node ) { var updateConnectAndshIcon = function (node) {
var nodeType = node.getType(); var nodeType = node.getType();
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeStyle = nodeStyles[ node.getType() ]; var nodeStyle = nodeStyles[node.getType()];
var connect; var connect;
var _root = minder.getRoot(); var _root = minder.getRoot();
var _rootLayout = _root.getLayout(); var _rootLayout = _root.getLayout();
//更新连线 //更新连线
if ( nodeType === "main" ) { if (nodeType === "main") {
if ( !Layout.connect ) { if (!Layout.connect) {
connect = Layout.connect = new kity.Path(); connect = Layout.connect = new kity.Path();
minder.getRenderContainer().addShape( connect ); minder.getRenderContainer().addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var sX = _rootLayout.x; var sX = _rootLayout.x;
var sY = _rootLayout.y + _root.getRenderContainer().getHeight(); var sY = _rootLayout.y + _root.getRenderContainer().getHeight();
var transX = Layout.x + node.getRenderContainer().getWidth() / 2; var transX = Layout.x + node.getRenderContainer().getWidth() / 2;
var transY = sY + nodeStyles.root.margin[ 2 ]; var transY = sY + nodeStyles.root.margin[2];
connect.getDrawer().clear() connect.getDrawer().clear()
.moveTo( sX, sY ) .moveTo(sX, sY)
.lineTo( sX, transY ) .lineTo(sX, transY)
.lineTo( transX, transY ) .lineTo(transX, transY)
.lineTo( transX, Layout.y ); .lineTo(transX, Layout.y);
connect.stroke( nodeStyles.main.stroke ); connect.stroke(nodeStyles.main.stroke);
} else if ( nodeType === "sub" ) { } else if (nodeType === "sub") {
var parent = node.getParent(); var parent = node.getParent();
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
if ( !Layout.connect ) { if (!Layout.connect) {
connect = Layout.connect = new kity.Path(); connect = Layout.connect = new kity.Path();
Layout.subgroup.addShape( connect ); Layout.subgroup.addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var ssX, ssY; var ssX, ssY;
if ( parent.getType() === "main" ) { if (parent.getType() === "main") {
ssX = 10; ssX = 10;
ssY = 0; ssY = 0;
} else { } else {
...@@ -316,15 +339,15 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -316,15 +339,15 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
var transsY = Layout.y + node.getRenderContainer().getHeight() / 2; var transsY = Layout.y + node.getRenderContainer().getHeight() / 2;
connect.getDrawer().clear() connect.getDrawer().clear()
.moveTo( ssX, ssY ) .moveTo(ssX, ssY)
.lineTo( ssX, transsY ) .lineTo(ssX, transsY)
.lineTo( Layout.x, transsY ); .lineTo(Layout.x, transsY);
connect.stroke( nodeStyles.sub.stroke ); connect.stroke(nodeStyles.sub.stroke);
} }
//更新收放icon //更新收放icon
if ( nodeType !== "root" && node.getChildren().length !== 0 ) { if (nodeType !== "root" && node.getChildren().length !== 0) {
if ( !Layout.shicon ) { if (!Layout.shicon) {
Layout.shicon = new ShIcon( node ); Layout.shicon = new ShIcon(node);
} }
Layout.shicon.update(); Layout.shicon.update();
} }
...@@ -333,253 +356,264 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -333,253 +356,264 @@ KityMinder.registerModule( "LayoutBottom", function () {
getCurrentLayoutStyle: function () { getCurrentLayoutStyle: function () {
return nodeStyles; return nodeStyles;
}, },
highlightNode: function ( node ) { highlightNode: function (node) {
var highlight = node.isHighlight(); var highlight = node.isHighlight();
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout(); var Layout = node.getLayout();
switch ( nodeType ) { switch (nodeType) {
case "root": case "root":
case "main": case "main":
case "sub": case "sub":
if ( highlight ) { if (highlight) {
Layout.bgRect.fill( nodeStyle.highlight ); Layout.bgRect.fill(nodeStyle.highlight);
} else { } else {
Layout.bgRect.fill( nodeStyle.fill ); Layout.bgRect.fill(nodeStyle.fill);
} }
break; break;
default: default:
break; break;
} }
}, },
updateLayout: function ( node ) { updateLayout: function (node) {
node.getContRc().clear(); node.getContRc().clear();
this._firePharse( new MinderEvent( "RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNode", {
node: node node: node
}, false ) ); }, false));
updateShapeByCont( node ); updateShapeByCont(node);
var set = updateLayoutAll( node, node.getParent(), "change" ); var set = updateLayoutAll(node, node.getParent(), "change");
for ( var i = 0; i < set.length; i++ ) { for (var i = 0; i < set.length; i++) {
translateNode( set[ i ] ); translateNode(set [i]);
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon(set [i]);
} }
if ( node.getType() === "sub" ) { if (node.getType() === "sub") {
var set1 = updateLayoutMain(); var set1 = updateLayoutMain();
for ( var j = 0; j < set1.length; j++ ) { for (var j = 0; j < set1.length; j++) {
translateNode( set1[ j ] ); translateNode(set1[j]);
updateConnectAndshIcon( set1[ j ] ); updateConnectAndshIcon(set1[j]);
} }
} }
}, },
initStyle: function () { initStyle: function () {
var _root = minder.getRoot(); var _root = minder.getRoot();
minder.handelNodeInsert( _root ); minder.handelNodeInsert(_root);
//设置root的align //设置root的align
_root.getLayout().align = "center"; _root.getLayout().align = "center";
updateBg( _root ); updateBg(_root);
initLayout( _root ); initLayout(_root);
_root.getContRc().clear(); _root.getContRc().clear();
this._firePharse( new MinderEvent( "RenderNodeLeft", { this._firePharse(new MinderEvent("RenderNodeLeft", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeCenter", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: _root node: _root
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: _root node: _root
}, false ) ); }, false));
updateShapeByCont( _root ); this._firePharse(new MinderEvent("RenderNode", {
updateLayoutAll( _root ); node: _root
translateNode( _root ); }, false));
var _buffer = [ _root ]; updateShapeByCont(_root);
updateLayoutAll(_root);
translateNode(_root);
var _buffer = [_root];
var _cleanbuffer = []; var _cleanbuffer = [];
//打散结构
while ( _buffer.length !== 0 ) { var mains = _root.getChildren();
var children = _buffer[ 0 ].getChildren(); for (var i = 0; i < mains.length; i++) {
_buffer = _buffer.concat( children ); this.appendChildNode(_root, mains[i]);
for ( var i = 0; i < children.length; i++ ) {
children[ i ].getLayout().parent = _buffer[ 0 ];
}
_buffer[ 0 ].clearChildren();
if ( _buffer[ 0 ] !== _root ) _cleanbuffer.push( _buffer[ 0 ] );
_buffer.shift();
}
//重组结构
for ( var j = 0; j < _cleanbuffer.length; j++ ) {
this.appendChildNode( _cleanbuffer[ j ].getLayout().parent, _cleanbuffer[ j ] );
} }
//打散结构
// while (_buffer.length !== 0) {
// var children = _buffer[0].getChildren();
// _buffer = _buffer.concat(children);
// for (var i = 0; i < children.length; i++) {
// children[i].getLayout().parent = _buffer[0];
// }
// _buffer[0].clearChildren();
// if (_buffer[0] !== _root) _cleanbuffer.push(_buffer[0]);
// _buffer.shift();
// }
// //重组结构
// for (var j = 0; j < _cleanbuffer.length; j++) {
// this.appendChildNode(_cleanbuffer[j].getLayout().parent, _cleanbuffer[j]);
// }
}, },
appendChildNode: function ( parent, node, focus, sibling ) { appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node);
node.clearLayout(); node.clearLayout();
node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout();
Layout.added = true;
initLayout(node);
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var expand = parent.getData( "expand" );
//设置分支类型 //设置分支类型
if ( parent.getType() === "root" ) { if (parent.getType() === "root") {
node.setType( "main" ); node.setType("main");
node.setData( "expand", true ); node.setData("expand", true);
minder.handelNodeInsert( node );
} else { } else {
node.setType( "sub" ); node.setType("sub");
//将节点加入到main分支的subgroup中 //将节点加入到main分支的subgroup中
parentLayout.subgroup.addShape( node.getRenderContainer() ); parentLayout.subgroup.addShape(node.getRenderContainer());
node.getLayout().subgroup = parentLayout.subgroup; node.getLayout().subgroup = parentLayout.subgroup;
} }
if ( sibling ) { if (sibling) {
parent.insertChild( node, sibling.getIndex() + 1 ); parent.insertChild(node, sibling.getIndex() + 1);
} else { } else {
parent.appendChild( node ); parent.appendChild(node);
} }
//计算位置等流程 //计算位置等流程
updateBg( node ); this._firePharse(new MinderEvent("RenderNodeLeft", {
initLayout( node );
// this._fire( new MinderEvent( "beforeRenderNode", {
// node: node
// }, false ) );
// this._fire( new MinderEvent( "RenderNode", {
// node: node
// }, false ) );
node.getRenderContainer().clear();
this._firePharse( new MinderEvent( "RenderNodeLeft", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeCenter", { this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeRight", { this._firePharse(new MinderEvent("RenderNodeRight", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeBottom", { this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node node: node
}, false ) ); }, false));
this._firePharse( new MinderEvent( "RenderNodeTop", { this._firePharse(new MinderEvent("RenderNodeTop", {
node: node node: node
}, false ) ); }, false));
updateShapeByCont( node ); this._firePharse(new MinderEvent("RenderNode", {
var set = updateLayoutAll( node, parent, "append" ); node: node
for ( var i = 0; i < set.length; i++ ) { }, false));
translateNode( set[ i ] ); updateBg(node);
updateConnectAndshIcon( set[ i ] ); updateShapeByCont(node);
} var set = updateLayoutAll(node, parent, "append");
if ( node.getType() === "sub" ) { for (var i = 0; i < set.length; i++) {
var set1 = updateLayoutMain(); translateNode(set [i]);
for ( var j = 0; j < set1.length; j++ ) { updateConnectAndshIcon(set [i]);
translateNode( set1[ j ] );
updateConnectAndshIcon( set1[ j ] );
}
} }
// if (node.getType() === "sub") {
// var set1 = updateLayoutMain();
// for (var j = 0; j < set1.length; j++) {
// translateNode(set1[j]);
// updateConnectAndshIcon(set1[j]);
// }
// }
}, },
appendSiblingNode: function ( sibling, node ) { appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent(); var parent = sibling.getParent();
this.appendChildNode( parent, node, sibling ); this.appendChildNode(parent, node, sibling);
}, },
removeNode: function ( nodes ) { removeNode: function (nodes) {
while ( nodes.length !== 0 ) { while (nodes.length !== 0) {
var parent = nodes[ 0 ].getParent(); var parent = nodes[0].getParent();
if ( !parent ) { if (!parent) {
nodes.splice( 0, 1 ); nodes.splice(0, 1);
return false; return false;
} }
var nodeLayout = nodes[ 0 ].getLayout(); var nodeLayout = nodes[0].getLayout();
parent.removeChild( nodes[ 0 ] ); parent.removeChild(nodes[0]);
if ( parent.getType() !== "root" && parent.getChildren().length === 0 ) { if (parent.getType() !== "root" && parent.getChildren().length === 0) {
var prtLayout = parent.getLayout(); var prtLayout = parent.getLayout();
prtLayout.shicon.remove(); prtLayout.shicon.remove();
prtLayout.shicon = null; prtLayout.shicon = null;
} }
var set = updateLayoutAll( nodes[ 0 ], parent, "remove" ); var set = updateLayoutAll(nodes[0], parent, "remove");
for ( var j = 0; j < set.length; j++ ) { for (var j = 0; j < set.length; j++) {
translateNode( set[ j ] ); translateNode(set [j]);
updateConnectAndshIcon( set[ j ] ); updateConnectAndshIcon(set [j]);
} }
var set1 = updateLayoutMain(); var set1 = updateLayoutMain();
for ( var k = 0; k < set1.length; k++ ) { for (var k = 0; k < set1.length; k++) {
translateNode( set1[ k ] ); translateNode(set1[k]);
updateConnectAndshIcon( set1[ k ] ); updateConnectAndshIcon(set1[k]);
} }
var _buffer = [ nodes[ 0 ] ]; var _buffer = [nodes[0]];
while ( _buffer.length !== 0 ) { while (_buffer.length !== 0) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); _buffer = _buffer.concat(_buffer[0].getChildren());
try { try {
_buffer[ 0 ].getRenderContainer().remove(); _buffer[0].getRenderContainer().remove();
var Layout = _buffer[ 0 ].getLayout(); var Layout = _buffer[0].getLayout();
Layout.connect.remove(); Layout.connect.remove();
Layout.shicon.remove(); Layout.shicon.remove();
} catch ( error ) { } catch (error) {
console.log( "isRemoved" ); console.log("isRemoved");
} }
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除 //检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf( _buffer[ 0 ] ); var idx = nodes.indexOf(_buffer[0]);
if ( idx !== -1 ) { if (idx !== -1) {
nodes.splice( idx, 1 ); nodes.splice(idx, 1);
} }
_buffer.shift(); _buffer.shift();
} }
} }
}, },
expandNode: function ( ico ) { expandNode: function (ico) {
var isExpand, node; var isExpand, node;
if ( ico instanceof MinderNode ) { if (ico instanceof MinderNode) {
node = ico; node = ico;
isExpand = node.getLayout().shicon.switchState(); isExpand = node.getLayout().shicon.switchState();
} else { } else {
isExpand = ico.icon.switchState(); isExpand = ico.icon.switchState();
node = ico.icon._node; node = ico.icon._node;
} }
node.setData( "expand", isExpand ); var _buffer;
var _buffer = node.getChildren(); if (isExpand) {
var _cleanbuffer = []; node.expand();
//遍历子树展开需要展开的节点
while ( _buffer.length !== 0 ) { _buffer = [node];
var Layout = _buffer[ 0 ].getLayout(); while (_buffer.length !== 0) {
if ( isExpand ) { var c = _buffer[0].getChildren();
var parent = _buffer[ 0 ].getParent(); if (_buffer[0].isExpanded() && c.length !== 0) {
Layout.parent = parent; for (var x = 0; x < c.length; x++) {
_cleanbuffer.push( _buffer[ 0 ] ); minder.appendChildNode(_buffer[0], c[x]);
Layout.connect = null; }
Layout.shicon = null; _buffer = _buffer.concat(c);
} else { }
try { _buffer.shift();
_buffer[ 0 ].getRenderContainer().remove(); }
} else {
node.collapse();
//遍历子树移除需要移除的节点
_buffer = node.getChildren();
while (_buffer.length !== 0) {
var Layout = _buffer[0].getLayout();
if (Layout.added) {
Layout.added = false;
_buffer[0].getRenderContainer().remove();
Layout.connect.remove(); Layout.connect.remove();
if ( Layout.shicon ) Layout.shicon.remove(); if (Layout.shicon) Layout.shicon.remove();
} catch ( error ) {} }
_buffer = _buffer.concat(_buffer[0].getChildren());
_buffer.shift();
} }
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); var set = updateLayoutVertical(node, node.getParent(), "contract");
_buffer.shift(); for (var i = 0; i < set.length; i++) {
} translateNode(set [i]);
if ( isExpand ) { updateConnectAndshIcon(set [i]);
node.clearChildren();
for ( var j = 0; j < _cleanbuffer.length; j++ ) {
_cleanbuffer[ j ].clearChildren();
minder.appendChildNode( _cleanbuffer[ j ].getLayout().parent, _cleanbuffer[ j ] );
} }
} }
var set = [];
if ( !isExpand ) set = updateLayoutAll( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
}
} }
}; };
this.addLayoutStyle( "bottom", _style ); this.addLayoutStyle("bottom", _style);
return {}; return {};
} ); });
\ No newline at end of file \ No newline at end of file
...@@ -396,12 +396,16 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -396,12 +396,16 @@ KityMinder.registerModule("LayoutDefault", function () {
minder.getRenderContainer().addShape(connect); minder.getRenderContainer().addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var parentShape = node.getParent().getRenderContainer(); var parent = node.getParent();
var parentShape = parent.getRenderContainer();
var parentBox = parentShape.getRenderBox(); var parentBox = parentShape.getRenderBox();
var parentLayout = node.getParent().getLayout(); var parentLayout = parent.getLayout();
var parentStyle = nodeStyles[node.getParent().getType()]; var parentStyle = nodeStyles[node.getParent().getType()];
var Shape = node.getRenderContainer(); var Shape = node.getRenderContainer();
var sX, sY = parentLayout.y; var sX, sY = parentBox.bottom - 5;
if (parent.getType() === 'main') {
sY = (parentBox.top + parentBox.bottom) / 2
}
var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y; var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y;
if (Layout.appendside === "left") { if (Layout.appendside === "left") {
sX = parentBox.closurePoints[1].x - parentStyle.margin[1]; sX = parentBox.closurePoints[1].x - parentStyle.margin[1];
...@@ -587,11 +591,11 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -587,11 +591,11 @@ KityMinder.registerModule("LayoutDefault", function () {
} }
} }
}, },
appendChildNode: function (parent, node, focus, sibling) { appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node); minder.handelNodeInsert(node);
var Layout = node.getLayout();
node.clearLayout(); node.clearLayout();
node.getContRc().clear(); node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout(); Layout = node.getLayout();
Layout.added = true; Layout.added = true;
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
...@@ -690,16 +694,13 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -690,16 +694,13 @@ KityMinder.registerModule("LayoutDefault", function () {
updateConnectAndshIcon(set [i]); updateConnectAndshIcon(set [i]);
} }
// if ( focus ) {
// showNodeInView( node );
// }
parent.expand(); parent.expand();
var shicon = parent.getLayout().shicon; var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true); if (shicon) shicon.switchState(true);
}, },
appendSiblingNode: function (sibling, node, focus) { appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent(); var parent = sibling.getParent();
this.appendChildNode(parent, node, focus, sibling); this.appendChildNode(parent, node, sibling);
}, },
removeNode: function (nodes) { removeNode: function (nodes) {
nodes = utils.isArray(nodes) ? nodes : [nodes]; nodes = utils.isArray(nodes) ? nodes : [nodes];
......
KityMinder.registerModule( "LayoutModule", function () { KityMinder.registerModule("LayoutModule", function () {
var me = this; var me = this;
var clearPaper = function () { var clearPaper = function () {
me._rc.remove(); me._rc.remove();
me._rc = new kity.Group(); me._rc = new kity.Group();
me._paper.addShape( this._rc ); me._paper.addShape(this._rc);
}; };
kity.extendClass( Minder, { kity.extendClass(Minder, {
addLayoutStyle: function ( name, style ) { addLayoutStyle: function (name, style) {
if ( !this._layoutStyles ) this._layoutStyles = {}; if (!this._layoutStyles) this._layoutStyles = {};
this._layoutStyles[ name ] = style; this._layoutStyles[name] = style;
}, },
getLayoutStyle: function ( name ) { getLayoutStyle: function (name) {
return this._layoutStyles[ name ]; return this._layoutStyles[name];
}, },
getLayoutStyleItems: function () { getLayoutStyleItems: function () {
var items = []; var items = [];
for ( var key in this._layoutStyles ) { for (var key in this._layoutStyles) {
items.push( key ); items.push(key);
} }
return items; return items;
}, },
getCurrentStyle: function () { getCurrentStyle: function () {
var _root = this.getRoot(); var _root = this.getRoot();
return "default"; //_root.getData( "currentstyle" ); return _root.getData("currentstyle");
}, },
setCurrentStyle: function ( name ) { setCurrentStyle: function (name) {
var _root = this.getRoot(); var _root = this.getRoot();
_root.setData( "currentstyle", name ); _root.setData("currentstyle", name);
return name; return name;
}, },
getCurrentLayoutStyle: function () { getCurrentLayoutStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
return this.getLayoutStyle( curStyle ).getCurrentLayoutStyle.call( this ); return this.getLayoutStyle(curStyle).getCurrentLayoutStyle.call(this);
}, },
highlightNode: function ( node ) { highlightNode: function (node) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).highlightNode.call( this, node ); this.getLayoutStyle(curStyle).highlightNode.call(this, node);
}, },
initStyle: function () { initStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this._rc.remove(); this._rc.remove();
var transform = this._rc.transform; var transform = this._rc.transform;
this._rc = new kity.Group(); this._rc = new kity.Group();
this._paper.addShape( this._rc ); this._paper.addShape(this._rc);
this._rc.transform = transform; this._rc.transform = transform;
this._rc._applyTransform(); this._rc._applyTransform();
var _root = this.getRoot(); var _root = this.getRoot();
_root.preTraverse( function ( n ) { _root.preTraverse(function (n) {
n.clearLayout(); n.clearLayout();
} ); });
this.getLayoutStyle( curStyle ).initStyle.call( this ); this.getLayoutStyle(curStyle).initStyle.call(this);
this.fire( 'afterinitstyle' ); this.fire('afterinitstyle');
}, },
appendChildNode: function ( parent, node, focus, index ) { appendChildNode: function (parent, node, index) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, focus, index ); this.getLayoutStyle(curStyle).appendChildNode.call(this, parent, node, index);
}, },
appendSiblingNode: function ( sibling, node, focus ) { appendSiblingNode: function (sibling, node) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendSiblingNode.call( this, sibling, node, focus ); this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node);
}, },
removeNode: function ( nodes ) { removeNode: function (nodes) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).removeNode.call( this, nodes ); this.getLayoutStyle(curStyle).removeNode.call(this, nodes);
}, },
updateLayout: function ( node ) { updateLayout: function (node) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).updateLayout.call( this, node ); this.getLayoutStyle(curStyle).updateLayout.call(this, node);
}, },
expandNode: function ( ico ) { expandNode: function (ico) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).expandNode.call( this, ico ); this.getLayoutStyle(curStyle).expandNode.call(this, ico);
} }
} ); });
kity.extendClass( MinderNode, { kity.extendClass(MinderNode, {
setLayout: function ( k, v ) { setLayout: function (k, v) {
if ( this._layout === undefined ) { if (this._layout === undefined) {
this._layout = {}; this._layout = {};
} }
var _pros = this.getLayout(); var _pros = this.getLayout();
Utils.extend( _pros, { Utils.extend(_pros, {
k: v k: v
} ); });
this._layout = _pros; this._layout = _pros;
}, },
getLayout: function ( k ) { getLayout: function (k) {
if ( k === undefined ) { if (k === undefined) {
return this._layout; return this._layout;
} }
return this._layout[ k ]; return this._layout[k];
}, },
clearLayout: function () { clearLayout: function () {
this._layout = {}; this._layout = {};
} }
} ); });
var switchLayout = function ( km, style ) { var switchLayout = function (km, style) {
var _root = km.getRoot(); var _root = km.getRoot();
_root.preTraverse( function ( n ) { _root.preTraverse(function (n) {
n.setPoint(); n.setPoint();
n.getBgRc().clear(); n.getBgRc().clear();
} ); });
km.setCurrentStyle( style ); km.setCurrentStyle(style);
//km.initStyle(); //km.initStyle();
return style; return style;
}; };
var SwitchLayoutCommand = kity.createClass( "SwitchLayoutCommand", ( function () { var SwitchLayoutCommand = kity.createClass("SwitchLayoutCommand", (function () {
return { return {
base: Command, base: Command,
execute: switchLayout, execute: switchLayout,
queryValue: function ( km ) { queryValue: function (km) {
return km.getCurrentStyle(); return km.getCurrentStyle();
} }
}; };
} )() ); })());
var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () { var AppendChildNodeCommand = kity.createClass("AppendChildNodeCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, node, focus, silbling ) { execute: function (km, node, silbling) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if ( !parent ) { if (!parent) {
return null; return null;
} }
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && !parent.isExpanded() ) { if (parent.getType() !== "root" && parent.getChildren().length !== 0 && !parent.isExpanded()) {
km.expandNode( parent ); km.expandNode(parent);
} }
parent.expand(); parent.expand();
km.appendChildNode( parent, node, focus, silbling ); km.appendChildNode(parent, node, silbling);
km.select( node, true ); km.select(node, true);
return node; return node;
}, },
queryState: function ( km ) { queryState: function (km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) { if (!selectedNode) {
return -1; return -1;
} else { } else {
return 0; return 0;
} }
} }
}; };
} )() ); })());
var AppendSiblingNodeCommand = kity.createClass( "AppendSiblingNodeCommand", ( function () { var AppendSiblingNodeCommand = kity.createClass("AppendSiblingNodeCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, node, focus ) { execute: function (km, node) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) { if (!selectedNode) {
return null; return null;
} }
if ( selectedNode.isRoot() ) { if (selectedNode.isRoot()) {
node.setType( "main" ); node.setType("main");
km.appendChildNode( selectedNode, node, focus ); km.appendChildNode(selectedNode, node);
} else { } else {
km.appendSiblingNode( selectedNode, node, focus ); km.appendSiblingNode(selectedNode, node);
} }
km.select( node, true ); km.select(node, true);
return node; return node;
}, },
queryState: function ( km ) { queryState: function (km) {
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
//没选中节点和单选root的时候返回不可执行 //没选中节点和单选root的时候返回不可执行
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) { if (selectedNodes.length === 0 || (selectedNodes.length === 1 && selectedNodes[0] === km.getRoot())) {
return -1; return -1;
} else { } else {
return 0; return 0;
} }
} }
}; };
} )() ); })());
var RemoveNodeCommand = kity.createClass( "RemoveNodeCommand", ( function () { var RemoveNodeCommand = kity.createClass("RemoveNodeCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km ) { execute: function (km) {
if ( km.getRoot().children.length == 0 ) { if (km.getRoot().children.length == 0) {
return; return;
} }
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot(); var _root = km.getRoot();
var _buffer = []; var _buffer = [];
for ( var i = 0; i < selectedNodes.length; i++ ) { for (var i = 0; i < selectedNodes.length; i++) {
_buffer.push( selectedNodes[ i ] ); _buffer.push(selectedNodes[i]);
} }
do { do {
var parent = _buffer[ 0 ].getParent(); var parent = _buffer[0].getParent();
if ( parent && _buffer.indexOf( parent ) === -1 ) _buffer.push( parent ); if (parent && _buffer.indexOf(parent) === -1) _buffer.push(parent);
_buffer.shift(); _buffer.shift();
} while ( _buffer.length > 1 ); } while (_buffer.length > 1);
km.removeNode( selectedNodes ); km.removeNode(selectedNodes);
km.select( _buffer[ 0 ] ); km.select(_buffer[0]);
}, },
queryState: function ( km ) { queryState: function (km) {
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) { if (selectedNodes.length === 0 || (selectedNodes.length === 1 && selectedNodes[0] === km.getRoot())) {
return -1; return -1;
} else { } else {
return 0; return 0;
} }
} }
}; };
} )() ); })());
var EditNodeCommand = kity.createClass( "EditNodeCommand", ( function () { var EditNodeCommand = kity.createClass("EditNodeCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km ) { execute: function (km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) { if (!selectedNode) {
return null; return null;
} }
km.select( selectedNode, true ); km.select(selectedNode, true);
km.textEditNode( selectedNode ); km.textEditNode(selectedNode);
}, },
queryState: function ( km ) { queryState: function (km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) { if (!selectedNode) {
return -1; return -1;
} else { } else {
return 0; return 0;
...@@ -228,7 +228,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -228,7 +228,7 @@ KityMinder.registerModule( "LayoutModule", function () {
return false; return false;
} }
}; };
} )() ); })());
return { return {
"commands": { "commands": {
...@@ -240,47 +240,46 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -240,47 +240,46 @@ KityMinder.registerModule( "LayoutModule", function () {
}, },
"events": { "events": {
"ready": function () { "ready": function () {
this.setDefaultOptions( 'layoutstyle', this.getLayoutStyleItems() ); this.setDefaultOptions('layoutstyle', this.getLayoutStyleItems());
switchLayout( this, this.getOptions( 'defaultlayoutstyle' ) ); switchLayout(this, this.getOptions('defaultlayoutstyle'));
}, },
"click": function ( e ) { "click": function (e) {
var ico = e.kityEvent.targetShape && e.kityEvent.targetShape.container; var ico = e.kityEvent.targetShape && e.kityEvent.targetShape.container;
if ( ico && ico.class === "shicon" ) { if (ico && ico.class === "shicon") {
this.expandNode( ico ); this.expandNode(ico);
this.fire( 'contentchange' ); this.fire('contentchange');
} }
}, },
"resize": function ( e ) { "resize": function (e) {
clearTimeout( this._lastStyleResetTimeout ); clearTimeout(this._lastStyleResetTimeout);
this._lastStyleResetTimeout = setTimeout( function () { this._lastStyleResetTimeout = setTimeout(function () {
this.updateLayout( this.getRoot() ); this.updateLayout(this.getRoot());
}.bind( this ), 100 ); }.bind(this), 100);
}, },
"import": function ( e ) { "import": function (e) {
this.initStyle(); this.initStyle();
} }
}, },
'contextmenu': [ { 'contextmenu': [{
label: this.getLang( 'node.appendsiblingnode' ), label: this.getLang('node.appendsiblingnode'),
exec: function () { exec: function () {
this.execCommand( 'appendsiblingnode', new MinderNode( this.getLang( 'topic' ) ) ) this.execCommand('appendsiblingnode', new MinderNode(this.getLang('topic')))
}, },
cmdName: 'appendsiblingnode' cmdName: 'appendsiblingnode'
}, { }, {
label: this.getLang( 'node.appendchildnode' ), label: this.getLang('node.appendchildnode'),
exec: function () { exec: function () {
this.execCommand( 'appendchildnode', new MinderNode( this.getLang( 'topic' ) ) ) this.execCommand('appendchildnode', new MinderNode(this.getLang('topic')))
}, },
cmdName: 'appendchildnode' cmdName: 'appendchildnode'
}, { }, {
label: this.getLang( 'node.editnode' ), label: this.getLang('node.editnode'),
exec: function () { exec: function () {
this.execCommand( 'editnode', null ); this.execCommand('editnode', null);
}, },
cmdName: 'editnode' cmdName: 'editnode'
}, { }, {
label: this.getLang( 'node.removenode' ), label: this.getLang('node.removenode'),
cmdName: 'removenode' cmdName: 'removenode'
}, { }, {
divider: 1 divider: 1
...@@ -301,4 +300,4 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -301,4 +300,4 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
} }
}; };
} ); });
\ No newline at end of file \ No newline at end of file
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