Commit c007c290 authored by techird's avatar techird

重构基本完成

parent 730566aa
......@@ -50,6 +50,7 @@
'module/nodetext.js',
'module/hyperlink.js',
'module/expand.js',
'module/connect.js',
'ui/jquery-ui-1.10.4.custom.min.js',
'ui/widget.js',
'ui/button.js',
......
Subproject commit 62a846c829a0306ba7493885b44c38d68cd3d232
Subproject commit f62ec70beb8198072693e1b7f1748cca46b685fb
(function () {
(function() {
function getKMBasePath(docUrl, confUrl) {
return getBasePath(docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath());
......@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'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'
'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | hyperlink unhyperlink image removeimage | markers resource | node | help'
]
//只读模式,默认是false
//readOnly: true
......
KM.registerToolbarUI( 'node', function ( name ) {
KM.registerToolbarUI('node', function(name) {
var shortcutKeys = {
"appendsiblingnode": "enter",
"appendchildnode": "tab",
"removenode": "del|backspace",
"editnode": "F2"
'appendsiblingnode': 'enter',
'appendchildnode': 'tab',
'removenode': 'del|backspace',
'editnode': 'F2'
};
var me = this,
msg = me.getLang( 'node' ),
label = me.getLang( 'tooltips.' + name ),
msg = me.getLang('node'),
label = me.getLang('tooltips.' + name),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getOptions( name ) || [],
items: {
'appendsiblingnode': 'appendsiblingnode',
'appendchildnode': 'appendchildnode',
'editnode': 'editnode',
'removenode': 'removenode'
},
itemStyles: [],
value: [],
autowidthitem: [],
......@@ -21,62 +26,63 @@ KM.registerToolbarUI( 'node', function ( name ) {
enabledSelected: false
},
$combox = null;
if ( options.items.length == 0 ) {
if (options.items.length === 0) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
$combox = $.kmuibuttoncombobox(transForInserttopic(options)).css('zIndex', me.getOptions('zIndex') + 1);
var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ), true );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
comboboxWidget.on('comboboxselect', function(evt, res) {
me.execCommand(res.value, me.getLang().topic);
}).on('beforeshow', function() {
if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
}
var combox = $combox.kmui();
combox.traverseItems( function ( label, value ) {
if ( me.queryCommandState( value ) == -1 ) {
combox.disableItemByLabel( label )
combox.traverseItems(function(label, value) {
if (me.queryCommandState(value) == -1) {
combox.disableItemByLabel(label);
} else {
combox.enableItemByLabel( label )
combox.enableItemByLabel(label);
}
} )
} );
});
});
//状态反射
me.on( 'interactchange', function () {
me.on('interactchange', function() {
var state = 0;
utils.each( shortcutKeys, function ( k ) {
state = me.queryCommandState( k );
if ( state != -1 ) {
utils.each(shortcutKeys, function(k) {
state = me.queryCommandState(k);
if (state != -1) {
return false;
}
} );
});
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
comboboxWidget.button().kmui().disabled(state == -1).active(state == 1);
} );
});
//comboboxWidget.button().kmui().disabled(-1);
return comboboxWidget.button().addClass( 'kmui-combobox' );
return comboboxWidget.button().addClass('kmui-combobox');
function transForInserttopic( options ) {
function transForInserttopic(options) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( v );
utils.each(options.items, function(k, v) {
options.value.push(v);
tempItems.push( ( msg[ k ] || k ) + '(' + shortcutKeys[ v ].toUpperCase() + ')' );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
tempItems.push((msg[k] || k) + '(' + shortcutKeys[v].toUpperCase() + ')');
options.autowidthitem.push($.wordCountAdaptive(tempItems[tempItems.length - 1]));
});
options.items = tempItems;
return options;
}
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -75,6 +75,29 @@ kity.extendClass(MinderNode, {
return this._layoutTransform || new kity.Matrix();
},
getLayoutBox: function() {
var matrix = this._lastLayoutTransform || new kity.Matrix();
return matrix.transformBox(this.getContentBox());
},
getLayoutPoint: function() {
var matrix = this._lastLayoutTransform || new kity.Matrix();
return matrix.transformPoint(new kity.Point());
},
getLayoutOffset: function() {
var data = this.getData('layoutOffset');
if (data) return new kity.Point(data.x, data.y);
return new kity.Point();
},
setLayoutOffset: function(p) {
this.setData('layoutOffset', {
x: p.x,
y: p.y
});
},
getLayoutRoot: function() {
if (this.isLayoutRoot()) {
return this;
......@@ -129,12 +152,13 @@ kity.extendClass(Minder, {
applyLayoutResult: function(duration) {
var root = this.getRoot();
var me = this;
function apply(node, pMatrix) {
var matrix = node.getLayoutTransform().merge(pMatrix);
var lastMatrix = node._lastLayoutTransform || new kity.Matrix();
if (!matrix.equals(lastMatrix)) {
if (!matrix.equals(lastMatrix) || true) {
// 如果当前有动画,停止动画
if (node._layoutTimeline) {
......@@ -144,15 +168,23 @@ kity.extendClass(Minder, {
// 如果要求以动画形式来更新,创建动画
if (duration > 0) {
node._layoutTimeline = new kity.Animator(lastMatrix, matrix, function(rc, value) {
rc.setMatrix(node._lastLayoutTransform = value);
}).start(node.getRenderContainer(), duration, 'ease');
node._layoutTimeline = new kity.Animator(lastMatrix, matrix, function(node, value) {
node.getRenderContainer().setMatrix(node._lastLayoutTransform = value);
me.fire('layoutapply', {
node: node,
matrix: value
});
}).start(node, duration, 'ease');
}
// 否则直接更新
else {
node.getRenderContainer().setMatrix(matrix);
node._lastLayoutTransform = matrix;
me.fire('layoutapply', {
node: node,
matrix: matrix
});
}
}
......@@ -162,6 +194,7 @@ kity.extendClass(Minder, {
}
apply(root, new kity.Matrix());
this.fire('layout');
return this;
},
});
\ No newline at end of file
......@@ -43,12 +43,10 @@ function importNode(node, json, km) {
}
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()]));
node.render();
var childrenTreeData = json.children;
if (!childrenTreeData) return;
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode();
node.appendChild(childNode);
var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km);
}
return node;
......@@ -126,6 +124,9 @@ kity.extendClass(Minder, {
}
importNode(this._root, json, this);
this._root.preTraverse(function(node) {
node.render();
});
this._root.layout();
this.fire('beforeimport', params);
......
......@@ -13,7 +13,8 @@ kity.extendClass(Minder, {
right: [],
top: [],
bottom: [],
outline: []
outline: [],
outside: []
};
var i, name, type, module, moduleDeals,
......
......@@ -9,9 +9,14 @@ kity.extendClass(Minder, {
root.minder = this;
},
createNode: function(unknown) {
createNode: function(unknown, parent, index) {
var node = new MinderNode(unknown);
if (parent) parent.insertChild(node, index);
this.handelNodeCreate(node);
this.fire('nodecreate', {
node: node
});
return node;
},
......@@ -19,6 +24,9 @@ kity.extendClass(Minder, {
if (node.parent) {
node.parent.removeChild(node);
this.handelNodeRemove(node);
this.fire('noderemove', {
node: node
});
}
},
......
......@@ -68,9 +68,6 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
* 获得节点的类型(root|main|sub)
*/
getType: function(type) {
if (this.type) {
return this.type;
}
this.type = ['root', 'main', 'sub'][Math.min(this.getLevel(), 2)];
return this.type;
},
......
var Renderer = kity.createClass('Renderer', {
create: function(node) {
constructor: function(node) {
this.node = node;
},
create: function() {
throw new Error('Not implement: Renderer.create()');
},
update: function(node) {
update: function() {
throw new Error('Not implement: Renderer.update()');
}
});
......@@ -25,9 +29,10 @@ kity.extendClass(Minder, {
renderers = renderers.concat(registered.top);
renderers = renderers.concat(registered.bottom);
renderers = renderers.concat(registered.outline);
renderers = renderers.concat(registered.outside);
node._renderers = renderers.map(function(Renderer) {
var renderer = new Renderer();
var renderer = new Renderer(node);
renderer.create(node);
return renderer;
});
......@@ -49,11 +54,15 @@ kity.extendClass(Minder, {
}
for (i = 0; i < node._renderers.length; i++) {
latestBox = node._renderers[i].update(node);
latestBox = node._renderers[i].update(node, latestBox);
if (latestBox) {
node._contentBox = contentBox = g.mergeBox(contentBox, latestBox);
}
}
this.fire('noderender', {
node: node
});
}
});
......@@ -62,7 +71,25 @@ kity.extendClass(MinderNode, {
this.getMinder().renderNode(this);
return this;
},
getRenderer: function(type) {
var rs = this._renderers;
for (var i = 0; i < rs.length; i++) {
if (rs[i] instanceof type) return rs[i];
}
return null;
},
getContentBox: function() {
return this._contentBox;
return this.parent && this.parent.isCollapsed() ? {
x: 0,
y: 0,
width: 0,
height: 0,
left: 0,
top: 0,
bottom: 0,
right: 0,
cx: 0,
cy: 0
} : this._contentBox;
}
});
\ No newline at end of file
/* global Layout:true */
window.layoutSwitch = true;
KityMinder.registerLayout('default', kity.createClass({
base: Layout,
doLayout: function(node) {
var layout = this;
if (node.isLayoutRoot()) {
this.doLayoutRoot(node);
} else {
this.arrange(node, node.children, layout.getSide(node));
}
},
getSide: function(node) {
while (!node.parent.isLayoutRoot()) {
node = node.parent;
......@@ -16,76 +26,85 @@ KityMinder.registerLayout('default', kity.createClass({
}[mainIndex] || (mainIndex % 2 ? 'right' : 'left');
},
doLayout: function(node) {
var layout = this;
doLayoutRoot: function(root) {
var mains = root.getChildren();
var group = {
left: [],
right: []
};
var _this = this;
function arrange(node, children, side) {
//if (!children.length) return;
mains.forEach(function(main) {
group[_this.getSide(main)].push(main);
});
var height = 0;
this.arrange(root, group.left, 'left');
this.arrange(root, group.right, 'right');
},
var childBoxes = children.map(function(node, index, children) {
var box = layout.getTreeBox([node]);
height += box.height;
if (index > 0) {
height += children[index - 1].getStyle('margin-bottom');
height += node.getStyle('margin-top');
}
return box;
});
arrange: function(parent, children, side) {
if (!children.length) return;
var _this = this;
var contentBox = node.getContentBox();
var x, y = -height / 2;
// children 所占的总树高
var totalTreeHeight = 0;
for (var i = 0; i < children.length; i++) {
// 计算每个 child 的树所占的矩形区域
var childTreeBoxes = children.map(function(node, index, children) {
var box = _this.getTreeBox([node]);
if (side == 'right') {
x = contentBox.x + contentBox.width - children[i].getContentBox().x;
x += node.getStyle('margin-right') + node.children[i].getStyle('margin-left');
} else {
x = contentBox.x - children[i].getContentBox().width - children[i].getContentBox().x;
x -= node.getStyle('margin-left') + node.children[i].getStyle('margin-right');
}
// 计算总树高,需要把竖直方向上的 margin 加入计算
totalTreeHeight += box.height;
y += childBoxes[i].height / 2;
if (index > 0) {
totalTreeHeight += children[index - 1].getStyle('margin-bottom');
totalTreeHeight += node.getStyle('margin-top');
}
if (i > 0) {
y += children[i].getStyle('margin-top');
}
return box;
});
children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
var nodeContentBox = parent.getContentBox();
var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix();
y += childBoxes[i].height / 2 + children[i].getStyle('margin-bottom');
}
y = -totalTreeHeight / 2;
var branchBox = layout.getBranchBox(children);
var dy = (branchBox.y + branchBox.height / 2) - (contentBox.y + contentBox.height / 2);
for (i = 0; i < children.length; i++) {
child = children[i];
childTreeBox = childTreeBoxes[i];
childContentBox = child.getContentBox();
for (i = 0; i < children.length; i++) {
children[i].getLayoutTransform().translate(0, -dy);
if (!childContentBox.height) continue;
// 水平方向上的布局
if (side == 'right') {
x = nodeContentBox.right - childContentBox.left;
x += parent.getStyle('margin-right') + child.getStyle('margin-left');
} else {
x = nodeContentBox.left - childContentBox.right;
x -= parent.getStyle('margin-left') + child.getStyle('margin-right');
}
}
// 竖直方向上的布局
y += childTreeBox.height / 2;
function layoutRoot(node) {
var mains = node.getChildren();
var group = {
left: [],
right: []
};
if (i > 0) {
y += children[i].getStyle('margin-top');
}
mains.forEach(function(main) {
group[layout.getSide(main)].push(main);
});
children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
arrange(node, group.left, 'left');
arrange(node, group.right, 'right');
y += childTreeBox.height / 2 + children[i].getStyle('margin-bottom');
}
if (node.isLayoutRoot()) {
layoutRoot(node);
} else {
arrange(node, node.children, layout.getSide(node));
if (parent.isRoot()) {
var branchBox = this.getBranchBox(children);
var dy = branchBox.cy - nodeContentBox.cy;
children.forEach(function(child) {
child.getLayoutTransform().translate(0, -dy);
});
}
}
}));
\ No newline at end of file
/* global Renderer: true */
KityMinder.registerModule('Connect', function() {
return {
events: {
'nodecreate': function(e) {
var node = e.node;
if (node.isRoot()) return;
var connection = new kity.Path()
.stroke(node.getStyle('connect-color') || 'white', node.getStyle('connect-width') || 2);
node._connection = connection;
this.getRenderContainer().prependShape(connection);
},
'noderemove': function(e) {
var node = e.node;
var me = this;
node.traverse(function(node) {
me.getRenderContainer().removeShape(node._connection);
});
},
'layoutapply noderender': function(e) {
var node = e.node;
var connection = node._connection;
var parent = node.parent;
if (!parent) return;
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.cx > pBox.cx ? 'right' : 'left';
if (parent.isCollapsed()) {
connection.setVisible(false);
return;
}
connection.setVisible(true);
switch (node.getType()) {
case 'main':
start = new kity.Point(pBox.cx, pBox.cy);
end = side == 'left' ?
new kity.Point(box.right, box.cy) :
new kity.Point(box.left, box.cy);
vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
break;
case 'sub':
var radius = node.getStyle('connect-radius');
if (side == 'right') {
start = new kity.Point(box.left - node.getStyle('margin-left') / 2, pBox.cy);
end = new kity.Point(box.right + node.getStyle('margin-right') / 2, box.bottom);
} else {
start = new kity.Point(box.right + node.getStyle('margin-right') / 2, pBox.cy);
end = new kity.Point(box.left - node.getStyle('margin-left') / 2, box.bottom);
}
var isTop = parent.children.length > 1 && node.getIndex() === 0;
pathData.push('M', start);
pathData.push('L', start.x, isTop ? (end.y + radius) : (end.y - radius));
var sf = +(side == 'right' && isTop || side == 'left' && !isTop);
var ex = side == 'right' ? (start.x + radius) : (start.x - radius);
pathData.push('A', radius, radius, 0, 0, sf, ex, end.y);
pathData.push('L', end);
}
connection.setPathData(pathData);
}
}
};
});
\ No newline at end of file
var GM = KityMinder.Geometry;
// 矩形的变形动画定义
var AreaAnimator = kity.createClass("AreaAnimator", {
var AreaAnimator = kity.createClass('AreaAnimator', {
base: kity.Animator,
constructor: function(startArea, endArea) {
startArea.opacity = 0;
......@@ -18,26 +18,22 @@ var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
base: Command,
execute: function(minder, nodes, parent) {
var node;
if ((!parent.isExpanded()) && (parent.getChildren().length > 0) && (parent.getType() !== 'root')) {
minder.expandNode(parent);
}
for (var i = nodes.length - 1; i >= 0; i--) {
node = nodes[i];
if (node.getParent()) {
minder.removeNode([node]);
minder.appendChildNode(parent, node);
if (node.isExpanded() && node.getChildren().length !== 0) {
minder.expandNode(node);
}
if (node.parent) {
node.parent.removeChild(node);
parent.appendChild(node);
node.render();
}
}
parent.expand();
minder.select(nodes, true);
}
});
function boxMapper(node) {
return node.getRenderContainer().getRenderBox('top');
return node.getLayoutBox();
}
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
......@@ -138,7 +134,7 @@ var DragBox = kity.createClass('DragBox', {
_drawForDragMode: function() {
this._text.setContent(this._dragSources.length + ' items');
this._text.setPosition(this._startPosition.x, this._startPosition.y + 5);
this._minder.getPaper().addShape(this);
this._minder.getRenderContainer().addShape(this);
},
_shrink: function() {
// 合并所有拖放源图形的矩形即可
......@@ -238,6 +234,11 @@ var DragBox = kity.createClass('DragBox', {
}
var movement = kity.Vector.fromPoints(this._startPosition, this._dragPosition);
// var minder = this._minder;
// this._dragSources.forEach(function(source) {
// source.setLayoutOffset(movement);
// minder.layout();
// });
this.setTranslate(movement);
......@@ -258,7 +259,7 @@ var DragBox = kity.createClass('DragBox', {
});
KityMinder.registerModule("DragTree", function() {
KityMinder.registerModule('DragTree', function() {
var dragStartPosition, dragBox, dragTargets, dropTargets, dragTargetBoxes, dropTarget;
return {
......@@ -269,11 +270,11 @@ KityMinder.registerModule("DragTree", function() {
mousedown: function(e) {
// 单选中根节点也不触发拖拽
if (e.getTargetNode() && e.getTargetNode() != this.getRoot()) {
this._dragBox.dragStart(e.getPosition());
this._dragBox.dragStart(e.getPosition(this.getRenderContainer()));
}
},
'mousemove': function(e) {
this._dragBox.dragMove(e.getPosition());
this._dragBox.dragMove(e.getPosition(this.getRenderContainer()));
},
'mouseup': function(e) {
this._dragBox.dragEnd();
......
This diff is collapsed.
......@@ -18,6 +18,8 @@ KityMinder.Geometry = (function() {
box.height = box.bottom - box.top;
box.x = box.left;
box.y = box.top;
box.cx = box.x + box.width / 2;
box.cy = box.y + box.height / 2;
return box;
}
......
KityMinder.registerModule("HistoryModule", function () {
KityMinder.registerModule("HistoryModule", function() {
var km = this;
var Scene = kity.createClass('Scene', {
constructor: function (root) {
constructor: function(root) {
this.data = root.clone();
},
getData: function () {
getData: function() {
return this.data;
},
cloneData: function () {
cloneData: function() {
return this.getData().clone();
},
equals: function (scene) {
equals: function(scene) {
return this.getData().equals(scene.getData())
}
});
var HistoryManager = kity.createClass('HistoryManager', {
constructor: function (km) {
constructor: function(km) {
this.list = [];
this.index = 0;
this.hasUndo = false;
this.hasRedo = false;
this.km = km;
},
undo: function () {
undo: function() {
if (this.hasUndo) {
// if(this.km.getStatus() == 'textedit'){
// return this.restore(this.index);
......@@ -42,7 +42,7 @@ KityMinder.registerModule("HistoryModule", function () {
this.restore(--this.index);
}
},
redo: function () {
redo: function() {
if (this.hasRedo) {
while (this.list[this.index].equals(this.list[this.index + 1])) {
this.index++;
......@@ -53,7 +53,7 @@ KityMinder.registerModule("HistoryModule", function () {
this.restore(++this.index);
}
},
partialRenewal: function (target) {
partialRenewal: function(target) {
function compareNode(source, target) {
if (source.getText() != target.getText()) {
return false;
......@@ -68,54 +68,55 @@ KityMinder.registerModule("HistoryModule", function () {
}
function appendChildNode(parent, child) {
km.appendChildNode(parent, child);
parent.appendChild(child);
for (var i = 0, ci; ci = child.children[i++];) {
appendChildNode(child, ci)
appendChildNode(child, ci);
}
}
function traverseNode(srcNode, tagNode) {
if (compareNode(srcNode, tagNode) === false) {
km.updateLayout(srcNode.setValue(tagNode));
srcNode.setValue(tagNode);
if (srcNode.isSelected()) {
km.select(srcNode)
km.select(srcNode);
} else {
km.removeSelectedNodes(srcNode)
km.removeSelectedNodes(srcNode);
}
}
for (var i = 0, j = 0, si, tj;
(si = srcNode.children[i], tj = tagNode.children[j], si || tj); i++, j++) {
if (si && !tj) {
i--;
km.removeNode(si)
km.removeNode(si);
} else if (!si && tj) {
j--;
appendChildNode(srcNode, tj)
appendChildNode(srcNode, tj);
} else {
traverseNode(si, tj)
traverseNode(si, tj);
}
}
}
traverseNode(km.getRoot(), target)
traverseNode(km.getRoot(), target);
km.layout();
},
restore: function () {
restore: function() {
var scene = this.list[this.index];
this.partialRenewal(scene.cloneData());
this.update();
this.km.fire('restoreScene');
this.km.fire('contentChange');
},
getScene: function () {
return new Scene(this.km.getRoot())
getScene: function() {
return new Scene(this.km.getRoot());
},
saveScene: function () {
saveScene: function() {
var currentScene = this.getScene();
var lastScene = this.list[this.index];
if (lastScene && lastScene.equals(currentScene)) {
return
return;
}
this.list = this.list.slice(0, this.index + 1);
this.list.push(currentScene);
......@@ -127,11 +128,11 @@ KityMinder.registerModule("HistoryModule", function () {
//跟新undo/redo状态
this.update();
},
update: function () {
update: function() {
this.hasRedo = !!this.list[this.index + 1];
this.hasUndo = !!this.list[this.index - 1] //|| this.km.getStatus() == 'textedit';
this.hasUndo = !!this.list[this.index - 1]; //|| this.km.getStatus() == 'textedit';
},
reset: function () {
reset: function() {
this.list = [];
this.index = 0;
this.hasUndo = false;
......@@ -167,29 +168,29 @@ KityMinder.registerModule("HistoryModule", function () {
"undo": kity.createClass("UndoCommand", {
base: Command,
execute: function (km) {
execute: function(km) {
km.historyManager.undo()
},
queryState: function (km) {
queryState: function(km) {
return km.historyManager.hasUndo ? 0 : -1;
},
isNeedUndo: function () {
isNeedUndo: function() {
return false;
}
}),
"redo": kity.createClass("RedoCommand", {
base: Command,
execute: function (km) {
execute: function(km) {
km.historyManager.redo()
},
queryState: function (km) {
queryState: function(km) {
return km.historyManager.hasRedo ? 0 : -1;
},
isNeedUndo: function () {
isNeedUndo: function() {
return false;
}
})
......@@ -199,10 +200,10 @@ KityMinder.registerModule("HistoryModule", function () {
"Redo": "ctrl+y" //redo
},
"events": {
"saveScene": function (e) {
"saveScene": function(e) {
this.historyManager.saveScene();
},
'renderNode': function (e) {
'renderNode': function(e) {
var node = e.node;
if (node.isSelected()) {
this.select(node)
......@@ -230,7 +231,7 @@ KityMinder.registerModule("HistoryModule", function () {
// }
// }
// },
"import": function () {
"import": function() {
this.historyManager.reset()
}
}
......
This diff is collapsed.
kity.extendClass(Minder, {
appendChildNode: function(parent, node, index) {
},
appendSiblingNode: function(sibling, node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node);
},
});
var AppendChildCommand = kity.createClass('AppendChildCommand', {
base: Command,
execute: function(km, text) {
var parent = km.getSelectedNode();
var node = km.createNode(text);
if (!parent) {
return null;
}
//parent.expand();
parent.appendChild(node);
parent.expand();
var node = km.createNode(text, parent);
km.select(node, true);
node.render();
node._lastLayoutTransform = parent._lastLayoutTransform;
km.layout(300);
},
queryState: function(km) {
......@@ -33,13 +23,13 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
execute: function(km, text) {
var sibling = km.getSelectedNode();
var parent = sibling.parent;
var node = km.createNode(text);
if (!parent) {
return null;
}
parent.insertChild(node, sibling.getIndex() + 1);
var node = km.createNode(text, parent, sibling.getIndex() + 1);
km.select(node, true);
node.render();
node._lastLayoutTransform = sibling._lastLayoutTransform;
km.layout(300);
},
queryState: function(km) {
......
/* global Renderer: true */
var wireframe = true;
var wireframe = /wire/.test(window.location.href);
KityMinder.registerModule('OutlineModule', function() {
return {
......@@ -9,12 +9,27 @@ KityMinder.registerModule('OutlineModule', function() {
base: Renderer,
create: function(node) {
var outline = this.outline = new kity.Rect().setId(KityMinder.uuid('node_outline'));
node.getRenderContainer().prependShape(outline);
var outline = this.outline = new kity.Rect()
.setId(KityMinder.uuid('node_outline'));
var bg = this.bg = new kity.Rect()
.setId(KityMinder.uuid('node_shadow'))
.fill('black')
.setOpacity(0.2);
node.getRenderContainer()
.prependShape(outline)
.prependShape(bg);
if (wireframe) {
var oxy = this.oxy = new kity.Path().stroke('white').setPathData('M0,-50L0,50M-50,0L50,0').setOpacity(0.5);
var box = this.wireframe = new kity.Rect().stroke('lightgreen');
var oxy = this.oxy = new kity.Path()
.stroke('#f6f')
.setPathData('M0,-50L0,50M-50,0L50,0');
var box = this.wireframe = new kity.Rect()
.stroke('lightgreen');
node.getRenderContainer().addShapes([oxy, box]);
}
},
......@@ -39,8 +54,20 @@ KityMinder.registerModule('OutlineModule', function() {
node.getStyle('selected-background') :
node.getStyle('background'));
if (node.getLevel() < 2) {
this.bg
.setVisible(true)
.setPosition(outlineBox.x + 3, outlineBox.y + 4)
.setSize(outlineBox.width, outlineBox.height)
.setRadius(node.getStyle('radius'));
} else {
this.bg.setVisible(false);
}
if (wireframe) {
this.wireframe.setPosition(outlineBox.x, outlineBox.y).setSize(outlineBox.width, outlineBox.height);
this.wireframe
.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height);
}
return outlineBox;
}
......
KityMinder.registerModule('Resource', function () {
KityMinder.registerModule('Resource', function() {
/**
* 自动使用的颜色序列
*/
var RESOURCE_COLOR_SERIES = [200, 51, 303, 75, 157, 0, 26, 254].map(function (h) {
var RESOURCE_COLOR_SERIES = [200, 51, 303, 75, 157, 0, 26, 254].map(function(h) {
return kity.Color.createHSL(h, 100, 85);
});
......@@ -24,7 +24,7 @@ KityMinder.registerModule('Resource', function () {
* @param {String} resource 资源名称
* @return {Color}
*/
getResourceColor: function (resource) {
getResourceColor: function(resource) {
var colorMapping = this._getResourceColorIndexMapping();
var nextIndex;
......@@ -43,7 +43,7 @@ KityMinder.registerModule('Resource', function () {
*
* @return {Array}
*/
getUsedResource: function () {
getUsedResource: function() {
var mapping = this._getResourceColorIndexMapping();
var used = [],
resource;
......@@ -62,7 +62,7 @@ KityMinder.registerModule('Resource', function () {
*
* @return {int}
*/
_getNextResourceColorIndex: function () {
_getNextResourceColorIndex: function() {
// 获取现有颜色映射
// resource => color_index
var colorMapping = this._getResourceColorIndexMapping();
......@@ -89,7 +89,7 @@ KityMinder.registerModule('Resource', function () {
// 获取现有颜色映射
// resource => color_index
_getResourceColorIndexMapping: function () {
_getResourceColorIndexMapping: function() {
return this._resourceColorMapping || (this._resourceColorMapping = {});
}
......@@ -116,29 +116,30 @@ KityMinder.registerModule('Resource', function () {
base: Command,
execute: function (minder, resource) {
execute: function(minder, resource) {
var nodes = minder.getSelectedNodes();
if (typeof (resource) == 'string') {
if (typeof(resource) == 'string') {
resource = [resource];
}
nodes.forEach(function (node) {
node.setData('resource', resource);
minder.updateLayout(node);
nodes.forEach(function(node) {
node.setData('resource', resource).render();
});
minder.layout(200);
},
queryValue: function (minder) {
queryValue: function(minder) {
var nodes = minder.getSelectedNodes();
var resource = [];
nodes.forEach(function (node) {
nodes.forEach(function(node) {
var nodeResource = node.getData('resource');
if (!nodeResource) return;
nodeResource.forEach(function (name) {
nodeResource.forEach(function(name) {
if (!~resource.indexOf(name)) {
resource.push(name);
}
......@@ -148,7 +149,7 @@ KityMinder.registerModule('Resource', function () {
return resource;
},
queryState: function () {
queryState: function() {
return 0;
}
});
......@@ -161,7 +162,7 @@ KityMinder.registerModule('Resource', function () {
var ResourceOverlay = kity.createClass('ResourceOverlay', {
base: kity.Group,
constructor: function (container, resourceName, color) {
constructor: function(container, resourceName, color) {
this.callBase();
var paddingX = 8,
......@@ -203,7 +204,7 @@ KityMinder.registerModule('Resource', function () {
},
events: {
'RenderNodeRight': function (e) {
'RenderNodeRight': function(e) {
var node = e.node;
var resource = node.getData('resource');
var content = node.getContRc();
......@@ -211,7 +212,7 @@ KityMinder.registerModule('Resource', function () {
var minder = this;
if (resource && resource.length) {
resource.forEach(function (name) {
resource.forEach(function(name) {
var overlay = new ResourceOverlay(content, name, minder.getResourceColor(name));
var box = content.getBoundaryBox();
overlay.setTranslate(box.width + margin, 0);
......
......@@ -4,7 +4,7 @@ KityMinder.registerTheme('default', {
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 30,
'root-margin': 100,
'root-radius': 30,
'root-space': 10,
......@@ -13,7 +13,7 @@ KityMinder.registerTheme('default', {
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [15, 10],
'main-margin': [20, 7],
'main-radius': 10,
'main-space': 5,
......@@ -22,9 +22,13 @@ KityMinder.registerTheme('default', {
'sub-stroke': 'white',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [5, 10],
'sub-margin': [5, 12],
'sub-radius': 5,
'sub-space': 5,
'connect-color': 'white',
'connect-width': 2,
'connect-radius': 5,
'selected-background': 'rgb(254, 219, 0)'
});
\ 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