Commit 730566aa authored by techird's avatar techird

stash

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