Commit 501b821c authored by techird's avatar techird

dev

parent 9f0ab629
...@@ -27,7 +27,7 @@ module.exports = function (grunt) { ...@@ -27,7 +27,7 @@ module.exports = function (grunt) {
var getPath = function (readFile) { var getPath = function (readFile) {
var sources = require("fs").readFileSync(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[1].replace(/\/\/.*\n/g, '\n').replace(/'|"|\n|\t|\s/g, '');
sources = sources.split(","); sources = sources.split(",");
sources.forEach(function (filepath, index) { sources.forEach(function (filepath, index) {
...@@ -65,7 +65,6 @@ module.exports = function (grunt) { ...@@ -65,7 +65,6 @@ module.exports = function (grunt) {
files: (function () { files: (function () {
var files = {}; var files = {};
files[distPath + 'kityminder.all.min.js'] = distPath + 'kityminder.all.js'; files[distPath + 'kityminder.all.min.js'] = distPath + 'kityminder.all.js';
console.log(files);
return files; return files;
})() })()
} }
...@@ -101,7 +100,7 @@ module.exports = function (grunt) { ...@@ -101,7 +100,7 @@ module.exports = function (grunt) {
overwrite: true, overwrite: true,
replacements: [{ replacements: [{
from: /kity\/dist\/kity\.js/ig, from: /kity\/dist\/kity\.js/ig,
to: 'lib/kitygraph.all.min.js' to: 'lib/kity.min.js'
}, { }, {
from: /import\.js/, from: /import\.js/,
to: 'kityminder.all.min.js' to: 'kityminder.all.min.js'
...@@ -154,13 +153,15 @@ module.exports = function (grunt) { ...@@ -154,13 +153,15 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-text-replace');
// Build task(s).
grunt.registerTask('default', ['concat', 'uglify', 'copy', 'replace']);
/* [liverload plugin & task ] ------------------------------------*/ /* [liverload plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-regarde'); grunt.loadNpmTasks('grunt-regarde');
grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-livereload'); grunt.loadNpmTasks('grunt-contrib-livereload');
// Build task(s).
grunt.registerTask('default', ['concat', 'uglify', 'copy', 'replace']);
grunt.registerTask('live', ['livereload-start', 'connect', 'regarde']); grunt.registerTask('live', ['livereload-start', 'connect', 'regarde']);
}; };
\ No newline at end of file
Subproject commit 7c5ee097334581f51ae994ff3c5d51f96d5ac260 Subproject commit 5382742eb5b1764af2bb4fdf4fa7565318bfbb78
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "kityminder", "name": "kityminder",
"title": "kityminder", "title": "kityminder",
"description": "Kity Minder", "description": "Kity Minder",
"version": "1.1.3.1", "version": "1.1.3",
"homepage": "https://github.com/fex-team/kityminder", "homepage": "https://github.com/fex-team/kityminder",
"author": { "author": {
"name": "f-cube @ FEX", "name": "f-cube @ FEX",
......
...@@ -128,7 +128,7 @@ kity.extendClass(MinderNode, { ...@@ -128,7 +128,7 @@ kity.extendClass(MinderNode, {
} }
} }
this.getMinder().layout(this, duration); this.getMinder().layout(duration);
return this; return this;
}, },
...@@ -140,18 +140,11 @@ kity.extendClass(MinderNode, { ...@@ -140,18 +140,11 @@ kity.extendClass(MinderNode, {
kity.extendClass(Minder, { kity.extendClass(Minder, {
layout: function(root, duration) { layout: function(duration) {
if (+root === root) {
duration = root;
root = null;
}
root = root || this.getRoot();
// traverse without root this.getRoot().traverse(function(node) {
root.traverse(function(node) {
node.setLayoutTransform(null); node.setLayoutTransform(null);
}, true); });
function layoutNode(node) { function layoutNode(node) {
...@@ -167,9 +160,9 @@ kity.extendClass(Minder, { ...@@ -167,9 +160,9 @@ kity.extendClass(Minder, {
layout.doLayout(node); layout.doLayout(node);
} }
layoutNode(root); layoutNode(this.getRoot());
this.applyLayoutResult(root, duration); this.applyLayoutResult(this.getRoot(), duration);
return this.fire('layout'); return this.fire('layout');
}, },
......
...@@ -37,6 +37,13 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -37,6 +37,13 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
return this.root === this; return this.root === this;
}, },
/**
* 判断节点是否叶子
*/
isLeaf: function() {
return this.children.length === 0;
},
/** /**
* 获取节点的根节点 * 获取节点的根节点
*/ */
...@@ -65,11 +72,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -65,11 +72,14 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
}, },
/** /**
* 获得节点的复杂度 * 获得节点的复杂度(即子树中节点的数量)
* @return {[type]} [description]
*/ */
getComplex: function() { getComplex: function() {
var complex = 0;
this.traverse(function() {
complex++;
});
return complex;
}, },
/** /**
......
...@@ -75,7 +75,7 @@ KityMinder.registerModule('Expand', function() { ...@@ -75,7 +75,7 @@ KityMinder.registerModule('Expand', function() {
node.traverse(function(node) { node.traverse(function(node) {
node.render(); node.render();
}); });
node.getMinder().layout(null, 200); node.getMinder().layout(200);
} }
// 将展开的操作和状态读取接口拓展到 MinderNode 上 // 将展开的操作和状态读取接口拓展到 MinderNode 上
......
...@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', { ...@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
km.select(node, true); km.select(node, true);
node.render(); node.render();
node._lastLayoutTransform = sibling._lastLayoutTransform; node._lastLayoutTransform = sibling._lastLayoutTransform;
km.layout(3000); km.layout(300);
}, },
queryState: function(km) { queryState: function(km) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
......
/* global Renderer: true */ /* global Renderer: true */
var wireframe = /wire/.test(window.location.href);
var OutlineRenderer = kity.createClass('OutlineRenderer', { var OutlineRenderer = kity.createClass('OutlineRenderer', {
base: Renderer, base: Renderer,
create: function(node) { 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')); .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; this.bringToBack = true;
return group;
return outline;
}, },
update: function(created, node) { update: function(outline, node, box) {
var contentBox = node.getContentBox();
var paddingLeft = node.getStyle('padding-left'), var paddingLeft = node.getStyle('padding-left'),
paddingRight = node.getStyle('padding-right'), paddingRight = node.getStyle('padding-right'),
...@@ -40,51 +22,78 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', { ...@@ -40,51 +22,78 @@ var OutlineRenderer = kity.createClass('OutlineRenderer', {
paddingBottom = node.getStyle('padding-bottom'); paddingBottom = node.getStyle('padding-bottom');
var outlineBox = { var outlineBox = {
x: contentBox.x - paddingLeft, x: box.x - paddingLeft,
y: contentBox.y - paddingTop, y: box.y - paddingTop,
width: contentBox.width + paddingLeft + paddingRight, width: box.width + paddingLeft + paddingRight,
height: contentBox.height + paddingTop + paddingBottom 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-' : ''; var prefix = node.isSelected() ? 'selected-' : '';
this.outline.fill(node.getStyle(prefix + 'background')); outline
this.outline.stroke(node.getStyle(prefix + 'stroke'), .setPosition(outlineBox.x, outlineBox.y)
node.getStyle(prefix + 'stroke-width')); .setSize(outlineBox.width, outlineBox.height)
.setRadius(node.getStyle('radius'))
if (node.getStyle('shadow')) { .fill(node.getStyle(prefix + 'background'))
this.shadow .stroke(node.getStyle(prefix + 'stroke'),
.setVisible(true) node.getStyle(prefix + 'stroke-width'));
.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);
}
if (wireframe) {
this.wireframe
.setPosition(outlineBox.x, outlineBox.y)
.setSize(outlineBox.width, outlineBox.height);
}
return outlineBox; return outlineBox;
} }
}); });
var ShadowRenderer = kity.createClass('ShadowRenderer', { 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() { KityMinder.registerModule('OutlineModule', function() {
return { return {
renderers: { renderers: {
outline: OutlineRenderer outline: OutlineRenderer,
outside: [ShadowRenderer, WireframeRenderer]
} }
}; };
}); });
\ No newline at end of file
...@@ -26,7 +26,7 @@ KityMinder.registerModule('Select', function() { ...@@ -26,7 +26,7 @@ KityMinder.registerModule('Select', function() {
return this.selectEnd(); return this.selectEnd();
} }
startPosition = g.snapToSharp(e.getPosition()); startPosition = g.snapToSharp(e.getPosition('paper'));
}, },
selectMove: function(e) { selectMove: function(e) {
if (minder.isTextEditStatus()) { if (minder.isTextEditStatus()) {
...@@ -35,7 +35,9 @@ KityMinder.registerModule('Select', function() { ...@@ -35,7 +35,9 @@ KityMinder.registerModule('Select', function() {
if (!startPosition) return; if (!startPosition) return;
var p1 = startPosition, var p1 = startPosition,
p2 = e.getPosition(); p2 = e.getPosition('paper');
console.log(e.kityEvent.targetShape);
// 检测是否要进入选区模式 // 检测是否要进入选区模式
if (!marqueeMode) { if (!marqueeMode) {
......
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