Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Jun 25, 2014
1 parent 9f0ab62 commit 501b821
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 79 deletions.
11 changes: 6 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (grunt) {
var getPath = function (readFile) {

var sources = require("fs").readFileSync(readFile);
sources = /Array\(([^)]+)\)/.exec(sources);
sources = /paths\s=\s\[([\s\S]*?)\]/ig.exec(sources);
sources = sources[1].replace(/\/\/.*\n/g, '\n').replace(/'|"|\n|\t|\s/g, '');
sources = sources.split(",");
sources.forEach(function (filepath, index) {
Expand Down Expand Up @@ -65,7 +65,6 @@ module.exports = function (grunt) {
files: (function () {
var files = {};
files[distPath + 'kityminder.all.min.js'] = distPath + 'kityminder.all.js';
console.log(files);
return files;
})()
}
Expand Down Expand Up @@ -101,7 +100,7 @@ module.exports = function (grunt) {
overwrite: true,
replacements: [{
from: /kity\/dist\/kity\.js/ig,
to: 'lib/kitygraph.all.min.js'
to: 'lib/kity.min.js'
}, {
from: /import\.js/,
to: 'kityminder.all.min.js'
Expand Down Expand Up @@ -154,13 +153,15 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace');
// Build task(s).
grunt.registerTask('default', ['concat', 'uglify', 'copy', 'replace']);


/* [liverload plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-regarde');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-livereload');

// Build task(s).
grunt.registerTask('default', ['concat', 'uglify', 'copy', 'replace']);
grunt.registerTask('live', ['livereload-start', 'connect', 'regarde']);

};
2 changes: 1 addition & 1 deletion kity
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "kityminder",
"title": "kityminder",
"description": "Kity Minder",
"version": "1.1.3.1",
"version": "1.1.3",
"homepage": "https://github.com/fex-team/kityminder",
"author": {
"name": "f-cube @ FEX",
Expand Down
19 changes: 6 additions & 13 deletions src/core/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ kity.extendClass(MinderNode, {
}
}

this.getMinder().layout(this, duration);
this.getMinder().layout(duration);

return this;
},
Expand All @@ -140,18 +140,11 @@ kity.extendClass(MinderNode, {

kity.extendClass(Minder, {

layout: function(root, duration) {
if (+root === root) {
duration = root;
root = null;
}

root = root || this.getRoot();
layout: function(duration) {

// traverse without root
root.traverse(function(node) {
this.getRoot().traverse(function(node) {
node.setLayoutTransform(null);
}, true);
});

function layoutNode(node) {

Expand All @@ -167,9 +160,9 @@ kity.extendClass(Minder, {
layout.doLayout(node);
}

layoutNode(root);
layoutNode(this.getRoot());

this.applyLayoutResult(root, duration);
this.applyLayoutResult(this.getRoot(), duration);

return this.fire('layout');
},
Expand Down
16 changes: 13 additions & 3 deletions src/core/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
return this.root === this;
},

/**
* 判断节点是否叶子
*/
isLeaf: function() {
return this.children.length === 0;
},

/**
* 获取节点的根节点
*/
Expand Down Expand Up @@ -65,11 +72,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
},

/**
* 获得节点的复杂度
* @return {[type]} [description]
* 获得节点的复杂度(即子树中节点的数量)
*/
getComplex: function() {

var complex = 0;
this.traverse(function() {
complex++;
});
return complex;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/module/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ KityMinder.registerModule('Expand', function() {
node.traverse(function(node) {
node.render();
});
node.getMinder().layout(null, 200);
node.getMinder().layout(200);
}

// 将展开的操作和状态读取接口拓展到 MinderNode 上
Expand Down
2 changes: 1 addition & 1 deletion src/module/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
km.select(node, true);
node.render();
node._lastLayoutTransform = sibling._lastLayoutTransform;
km.layout(3000);
km.layout(300);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
Expand Down
113 changes: 61 additions & 52 deletions src/module/outline.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,99 @@
/* global Renderer: true */

var wireframe = /wire/.test(window.location.href);

var OutlineRenderer = kity.createClass('OutlineRenderer', {
base: Renderer,

create: function(node) {
var group = new kity.Group();

var outline = this.outline = new kity.Rect()
var outline = new kity.Rect()
.setId(KityMinder.uuid('node_outline'));

var shadow = this.shadow = new kity.Rect()
.setId(KityMinder.uuid('node_shadow'));

group.addShapes([shadow, outline]);

if (wireframe) {
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');

group.addShapes([oxy, box]);
}

this.bringToBack = true;
return group;

return outline;
},

update: function(created, node) {
var contentBox = node.getContentBox();
update: function(outline, node, box) {

var paddingLeft = node.getStyle('padding-left'),
paddingRight = node.getStyle('padding-right'),
paddingTop = node.getStyle('padding-top'),
paddingBottom = node.getStyle('padding-bottom');

var outlineBox = {
x: contentBox.x - paddingLeft,
y: contentBox.y - paddingTop,
width: contentBox.width + paddingLeft + paddingRight,
height: contentBox.height + paddingTop + paddingBottom
x: box.x - paddingLeft,
y: box.y - paddingTop,
width: box.width + paddingLeft + paddingRight,
height: box.height + paddingTop + paddingBottom
};

this.outline
.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height)
.setRadius(node.getStyle('radius'));

var prefix = node.isSelected() ? 'selected-' : '';

this.outline.fill(node.getStyle(prefix + 'background'));
this.outline.stroke(node.getStyle(prefix + 'stroke'),
node.getStyle(prefix + 'stroke-width'));

if (node.getStyle('shadow')) {
this.shadow
.setVisible(true)
.setPosition(outlineBox.x + 4, outlineBox.y + 5)
.setSize(outlineBox.width, outlineBox.height)
.fill(node.getStyle('shadow'))
.setRadius(node.getStyle('radius'));
} else {
this.shadow.setVisible(false);
}
outline
.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height)
.setRadius(node.getStyle('radius'))
.fill(node.getStyle(prefix + 'background'))
.stroke(node.getStyle(prefix + 'stroke'),
node.getStyle(prefix + 'stroke-width'));

if (wireframe) {
this.wireframe
.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height);
}
return outlineBox;
}
});

var ShadowRenderer = kity.createClass('ShadowRenderer', {

base: Renderer,

create: function(node) {
this.bringToBack = true;
return new kity.Rect();
},

shouldRender: function(node) {
return node.getStyle('shadow');
},

update: function(shadow, node, box) {
shadow.setPosition(box.x + 4, box.y + 5)
.setSize(box.width, box.height)
.fill(node.getStyle('shadow'))
.setRadius(node.getStyle('radius'));
}
});

var wireframeOption = /wire/.test(window.location.href);
var WireframeRenderer = kity.createClass('WireframeRenderer', {
base: Renderer,

create: function() {
var wireframe = new kity.Group();
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');

return wireframe.addShapes([oxy, box]);
},

shouldRender: function() {
return wireframeOption;
},

update: function(created, node, box) {
this.wireframe
.setPosition(box.x, box.y)
.setSize(box.width, box.height);
}
});

KityMinder.registerModule('OutlineModule', function() {
return {
renderers: {
outline: OutlineRenderer
outline: OutlineRenderer,
outside: [ShadowRenderer, WireframeRenderer]
}
};
});
6 changes: 4 additions & 2 deletions src/module/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ KityMinder.registerModule('Select', function() {
return this.selectEnd();
}

startPosition = g.snapToSharp(e.getPosition());
startPosition = g.snapToSharp(e.getPosition('paper'));
},
selectMove: function(e) {
if (minder.isTextEditStatus()) {
Expand All @@ -35,7 +35,9 @@ KityMinder.registerModule('Select', function() {
if (!startPosition) return;

var p1 = startPosition,
p2 = e.getPosition();
p2 = e.getPosition('paper');

console.log(e.kityEvent.targetShape);

// 检测是否要进入选区模式
if (!marqueeMode) {
Expand Down

0 comments on commit 501b821

Please sign in to comment.