Commit 1fbea29d authored by campaign's avatar campaign

Merge remote-tracking branch 'origin/dev' into dev

parents dd8bb74c c1aa09cd
...@@ -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
...@@ -2,17 +2,19 @@ Kity Minder ...@@ -2,17 +2,19 @@ Kity Minder
========== ==========
## 简介 ## 简介
KityMinder 是百度 FEX 团队的 f-cube 小组(原UEditor小组)的又一力作。作为一款在线的脑图编辑工具,它有着很多Native编辑工具的交互体验。KM与UE有着一样的宗旨,就是注重最终用户的使用体验。同时,它充分发挥了Web云存储的优势,可以直接将编辑中的脑图同步到云端。此外,借由独创的 “云盘分享”功能,用户可以一键将当前编辑的脑图直接生成在线链接共享给其他用户,实现无缝沟通。
KityMinder 是百度 FEX 团队的 f-cube 小组(原 UEditor 小组)的又一力作。作为一款在线的脑图编辑工具,它有着不亚于 native 脑图工具的交互体验。同时,它充分发挥了 Web 云存储的优势,可以直接将编辑中的脑图同步到云端。此外,借由独创的 “云盘分享”功能,用户可以一键将当前编辑的脑图直接生成在线链接共享给其他用户,实现无缝沟通。
![KityMinder](summary.jpg "KityMinder 界面") ![KityMinder](summary.jpg "KityMinder 界面")
KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的主流浏览器。 KityMinder 基于 SVG 技术实现,支持绝大多数的主流浏览器,包括:
支持列表如下
1. Chrome 1. Chrome
2. Firefox 2. Firefox
3. Safari 3. Safari
4. IE9+ 4. IE9+<sup>*</sup>
*: IE9 不支持部分导出功能。
## 线上版本 ## 线上版本
...@@ -34,9 +36,9 @@ KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的 ...@@ -34,9 +36,9 @@ KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的
## 依赖说明 ## 依赖说明
KityMinder 依赖 Kity 库。刚下载的压缩包或者刚从 github 拉下来的代码会有一个空的 kity 目录。要运行调试,必须加载 Kity 的依赖: KityMinder 依赖 Kity 库。刚下载的压缩包或者刚从 github 拉下来的代码会有一个空的 Kity 目录。要运行调试,必须加载 Kity 的依赖:
1. 如果你下载的是 KityMinder 的压缩包,那么需要手动下载 [Kity](http://kitygraph.github.io/kityminder/kity/dist/kitygraph.all.js) 库到 kity/dist/kitygraph.all.js 1. 如果你下载的是 KityMinder 的压缩包,那么需要手动下载 [Kity](http://fex.baidu.com/kityminder/kity/dist/kity.js) 库到 kity/dist/kity.js
2. 如果你是从 github 上拉源代码下来的,那么可以更新一下子模块: 2. 如果你是从 github 上拉源代码下来的,那么可以更新一下子模块:
...@@ -47,5 +49,6 @@ git submodule update ...@@ -47,5 +49,6 @@ git submodule update
``` ```
## 联系我们 ## 联系我们
邮件: kity@baidu.com
邮件组: kity@baidu.com
讨论群: 374918234 讨论群: 374918234
( function ( utils ) { (function(utils) {
var content = '<div class="image-content" style="padding:20px;width:360px;">'; var content = '<div class="image-content" style="padding:20px;width:360px;">';
content += '<style>'; content += '<style>';
content += '.kmui-dialog-<%= container %> input{'; content += '.kmui-dialog-<%= container %> input{';
...@@ -36,39 +36,39 @@ ...@@ -36,39 +36,39 @@
KM.registerWidget( 'image', { KM.registerWidget('image', {
tpl: content, tpl: content,
initContent: function ( km ) { initContent: function(km) {
var lang = km.getLang( 'dialogs.image' ), var lang = km.getLang('dialogs.image'),
html; html;
if ( lang ) { if (lang) {
html = $.parseTmpl( this.tpl, utils.extend( { html = $.parseTmpl(this.tpl, utils.extend({
'container': 'image' 'container': 'image'
}, lang ) ); }, lang));
} }
this.root().html( html ); this.root().html(html);
}, },
initEvent: function ( km, $w ) { initEvent: function(km, $w) {
$w.find( '#image_insert' ).on( 'click', function () { $w.find('#image_insert').on('click', function() {
km.execCommand( 'image', $w.find( '#image_href' ).val() ); km.execCommand('image', $w.find('#image_href').val());
$w.kmui().hide(); $w.kmui().hide();
} ); });
$w.find( '#image_href' ).on( 'keydown', function ( e ) { $w.find('#image_href').on('keydown', function(e) {
if ( e.keyCode === 13 ) { if (e.keyCode === 13) {
km.execCommand( 'image', $w.find( '#image_href' ).val() ); km.execCommand('image', $w.find('#image_href').val());
$w.kmui().hide(); $w.kmui().hide();
} }
} ).on('input', function() { }).on('input', function() {
$w.find('#image_preview').attr('src', $w.find( '#image_href' ).val()); $w.find('#image_preview').attr('src', $w.find('#image_href').val());
}); });
var url = km.queryCommandValue( 'image' ); var url = km.queryCommandValue('image');
var $input = $w.find( '#image_href' ); var $input = $w.find('#image_href');
$input.val( url || 'http://' ); $input.val(url || 'http://');
if(url) $w.find('#image_preview').attr('src', url); if (url) $w.find('#image_preview').attr('src', url);
setTimeout( function () { setTimeout(function() {
$input.focus(); $input.focus();
} ); });
}, },
width: 400 width: 400
} ); });
} )( KM.Utils ); })(KM.Utils);
\ No newline at end of file \ No newline at end of file
(function (utils) { (function(utils) {
KM.registerWidget('resource', { KM.registerWidget('resource', {
tpl: tpl: '<div class="resource-container">' +
'<div class="resource-container">' + '<div class="add-resource">' +
'<div class="add-resource">' + '<input type="text" /><button class="button">添加</button>' +
'<input type="text" /><button class="button">添加</button>' + '<ul class="global-resource"></ul>' +
'<ul class="global-resource"></ul>' + '</div>' +
'</div>' +
'</div>' + '</div>' +
'<div class="no-selected">未选中节点</div>', '<div class="no-selected">未选中节点</div>',
initContent: function (km, $w) { initContent: function(km, $w) {
var lang = km.getLang('dialogs.resource'), var lang = km.getLang('dialogs.resource'),
html = $.parseTmpl(this.tpl, lang); html = $.parseTmpl(this.tpl, lang);
this.root().html(html); this.root().html(html);
}, },
initEvent: function (km, $w) { initEvent: function(km, $w) {
var $container = $w.find('.resource-container'); var $container = $w.find('.resource-container');
var $noSelected = $w.find('.no-selected'); var $noSelected = $w.find('.no-selected');
var $current = $w.find('.current-resource').hide(); var $current = $w.find('.current-resource').hide();
...@@ -43,7 +42,7 @@ ...@@ -43,7 +42,7 @@
$addInput.val(null); $addInput.val(null);
} }
$addInput.on('keydown', function (e) { $addInput.on('keydown', function(e) {
if (e.keyCode == 13) addResource(); if (e.keyCode == 13) addResource();
}); });
...@@ -51,25 +50,25 @@ ...@@ -51,25 +50,25 @@
switchDisplay(); switchDisplay();
$global.delegate('input[type=checkbox]', 'change', function () { $global.delegate('input[type=checkbox]', 'change', function() {
km.execCommand('resource', $global.find('input[type=checkbox]:checked').map(function (index, chk) { km.execCommand('resource', $global.find('input[type=checkbox]:checked').map(function(index, chk) {
return $(chk).data('resource'); return $(chk).data('resource');
}).toArray()); }).toArray());
}); });
km.on('interactchange', function (e) { km.on('interactchange', function(e) {
var resource = this.queryCommandValue("resource"); var resource = this.queryCommandValue("resource");
var used = this.getUsedResource(); var used = this.getUsedResource();
switchDisplay(); switchDisplay();
$global.empty().append(used.map(function (name) { $global.empty().append(used.map(function(name) {
var $li = $('<li></li>'), var $li = $('<li></li>'),
$label = $('<label></label>').appendTo($li), $label = $('<label></label>').appendTo($li),
$chk = $('<input type="checkbox" />') $chk = $('<input type="checkbox" />')
.data('resource', name) .data('resource', name)
.prop('checked', ~resource.indexOf(name)) .prop('checked', ~resource.indexOf(name))
.appendTo($label); .appendTo($label);
$label.append(name); $label.append(name);
var color = km.getResourceColor(name); var color = km.getResourceColor(name);
return $li.css({ return $li.css({
......
...@@ -7,26 +7,26 @@ ...@@ -7,26 +7,26 @@
<meta name="description" content="百度脑图,便捷的脑图编辑工具。让您在线上直接创建、保存并分享你的思路。"> <meta name="description" content="百度脑图,便捷的脑图编辑工具。让您在线上直接创建、保存并分享你的思路。">
<script src="lib/jquery-2.1.0.min.js?_=1401256332199" charset="utf-8"></script> <script src="lib/jquery-2.1.0.min.js?_=1403688582922" charset="utf-8"></script>
<script src="lib/ZeroClipboard.min.js?_=1401256332199" charset="utf-8"></script> <script src="lib/ZeroClipboard.min.js?_=1403688582922" charset="utf-8"></script>
<script type="text/javascript"> <script type="text/javascript">
ZeroClipboard.setDefaults( { moviePath: 'lib/ZeroClipboard.swf' } ); ZeroClipboard.setDefaults( { moviePath: 'lib/ZeroClipboard.swf' } );
</script> </script>
<script src="lib/kitygraph.all.min.js?_=1401256332199" charset="utf-8"></script> <script src="lib/kity.min.js?_=1403688582922" charset="utf-8"></script>
<script src="kityminder.all.min.js?_=1401256332199" charset="utf-8"></script> <script src="kityminder.all.min.js?_=1403688582922" charset="utf-8"></script>
<script src="kityminder.config.js?_=1401256332199" charset="utf-8"></script> <script src="kityminder.config.js?_=1403688582922" charset="utf-8"></script>
<script src="lang/zh-cn/zh-cn.js?_=1401256332199" charset="utf-8"></script> <script src="lang/zh-cn/zh-cn.js?_=1403688582922" charset="utf-8"></script>
<script src="lib/zip.js?_=1401256332199" charset="utf-8"></script> <script src="lib/zip.js?_=1403688582922" charset="utf-8"></script>
<script> <script>
zip.inflateJSPath = 'lib/inflate.js'; zip.inflateJSPath = 'lib/inflate.js';
</script> </script>
<script src="lib/jquery.xml2json.js?_=1401256332199" charset="utf-8"></script> <script src="lib/jquery.xml2json.js?_=1403688582922" charset="utf-8"></script>
<script src="lib/baidu-frontia-js-full-1.0.0.js?_=1401256332199" charset="utf-8"></script> <script src="lib/baidu-frontia-js-full-1.0.0.js?_=1403688582922" charset="utf-8"></script>
<script src="social/draftmanager.js?_=1401256332199" charset="utf-8"></script> <script src="social/draftmanager.js?_=1403688582922" charset="utf-8"></script>
<script src="social/social.js?_=1401256332199" charset="utf-8"></script> <script src="social/social.js?_=1403688582922" charset="utf-8"></script>
<link href="social/social.css" rel="stylesheet"> <link href="social/social.css" rel="stylesheet">
<link href="themes/default/css/import.css" type="text/css" rel="stylesheet" /> <link href="themes/default/css/import.css" type="text/css" rel="stylesheet" />
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
</body> </body>
<script> <script>
// create km instance // create km instance
window.km = KM.getKityMinder('kityminder'); km = KM.getKityMinder('kityminder');
// New Version Notify // New Version Notify
$(function() { $(function() {
...@@ -75,6 +75,18 @@ ...@@ -75,6 +75,18 @@
localStorage.lastKMVersion = KM.version; localStorage.lastKMVersion = KM.version;
} }
}); });
km.on('unziperror', function(ev){
alert('unziperror');
});
km.on('parseerror', function(ev){
alert('parseerror');
});
km.on('unknownprotocal', function(ev){
alert('unknownprotocal');
});
</script> </script>
<!--Baidu Tongji Code--> <!--Baidu Tongji Code-->
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
(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());
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
'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 | 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 //只读模式,默认是false
//readOnly: true //readOnly: true
......
/*! /*!
* ==================================================== * ====================================================
* kity - v2.0.0 - 2014-05-28 * kity - v2.0.0 - 2014-06-23
* https://github.com/fex-team/kity * https://github.com/fex-team/kity
* GitHub: https://github.com/fex-team/kity.git * GitHub: https://github.com/fex-team/kity.git
* Copyright (c) 2014 Baidu FEX; Licensed BSD * Copyright (c) 2014 Baidu FEX; Licensed BSD
...@@ -170,6 +170,9 @@ define("animate/animator", [ "animate/timeline", "graphic/eventhandler", "animat ...@@ -170,6 +170,9 @@ define("animate/animator", [ "animate/timeline", "graphic/eventhandler", "animat
} }
return this; return this;
}, },
timeline: function() {
return this._KityAnimateQueue[0].t;
},
stop: function() { stop: function() {
var queue = this._KityAnimateQueue; var queue = this._KityAnimateQueue;
if (queue) { if (queue) {
...@@ -462,6 +465,37 @@ define("animate/frame", [], function(require, exports) { ...@@ -462,6 +465,37 @@ define("animate/frame", [], function(require, exports) {
exports.requestFrame = requestFrame; exports.requestFrame = requestFrame;
exports.releaseFrame = releaseFrame; exports.releaseFrame = releaseFrame;
}); });
define("animate/motionanimator", [ "animate/animator", "animate/timeline", "animate/easing", "core/class", "graphic/shape", "graphic/geometry", "core/utils", "graphic/point", "graphic/vector", "graphic/matrix", "graphic/path", "graphic/svg" ], function(require) {
var Animator = require("animate/animator");
var g = require("graphic/geometry");
var Path = require("graphic/path");
var MotionAnimator = require("core/class").createClass("MotionAnimator", {
base: Animator,
constructor: function(path) {
var me = this;
this.callBase({
beginValue: 0,
finishValue: 1,
setter: function(target, value) {
var path = me.motionPath instanceof Path ? me.motionPath.getPathData() : me.motionPath;
var point = g.pointAtPath(path, value);
target.setTranslate(point.x, point.y);
target.setRotate(point.tan.getAngle());
}
});
this.updatePath(path);
},
updatePath: function(path) {
this.motionPath = path;
}
});
require("core/class").extendClass(Path, {
motion: function(path, duration, easing, delay, callback) {
return this.animate(new MotionAnimator(path), duration, easing, delay, callback);
}
});
return MotionAnimator;
});
define("animate/opacityanimator", [ "animate/animator", "animate/timeline", "animate/easing", "core/class", "graphic/shape", "graphic/svg", "core/utils", "graphic/eventhandler", "graphic/styled", "graphic/data", "graphic/matrix", "graphic/pen", "graphic/box" ], function(require) { define("animate/opacityanimator", [ "animate/animator", "animate/timeline", "animate/easing", "core/class", "graphic/shape", "graphic/svg", "core/utils", "graphic/eventhandler", "graphic/styled", "graphic/data", "graphic/matrix", "graphic/pen", "graphic/box" ], function(require) {
var Animator = require("animate/animator"); var Animator = require("animate/animator");
var OpacityAnimator = require("core/class").createClass("OpacityAnimator", { var OpacityAnimator = require("core/class").createClass("OpacityAnimator", {
...@@ -657,6 +691,7 @@ define("animate/timeline", [ "graphic/eventhandler", "core/utils", "graphic/shap ...@@ -657,6 +691,7 @@ define("animate/timeline", [ "graphic/eventhandler", "core/utils", "graphic/shap
this.finishValue = this.finishValue.call(this.target, this.target); this.finishValue = this.finishValue.call(this.target, this.target);
} }
this.time = 0; this.time = 0;
this.setValue(this.beginValue);
this.frame = frame.requestFrame(this.nextFrame.bind(this)); this.frame = frame.requestFrame(this.nextFrame.bind(this));
break; break;
...@@ -1070,11 +1105,7 @@ define("core/utils", [], function() { ...@@ -1070,11 +1105,7 @@ define("core/utils", [], function() {
* @return {Number|Object|Array} * @return {Number|Object|Array}
*/ */
paralle: function(v1, v2, op) { paralle: function(v1, v2, op) {
var Class, field, index, value; var Class, field, index, name, value;
// 是否数字
if (false === isNaN(parseFloat(v1))) {
return op(v1, v2);
}
// 数组 // 数组
if (v1 instanceof Array) { if (v1 instanceof Array) {
value = []; value = [];
...@@ -1085,24 +1116,27 @@ define("core/utils", [], function() { ...@@ -1085,24 +1116,27 @@ define("core/utils", [], function() {
} }
// 对象 // 对象
if (v1 instanceof Object) { if (v1 instanceof Object) {
value = {};
// 如果值是一个支持原始表示的实例,获取其原始表示 // 如果值是一个支持原始表示的实例,获取其原始表示
Class = v1.getClass && v1.getClass(); Class = v1.getClass && v1.getClass();
if (Class && Class.parse) { if (Class && Class.parse) {
v1 = v1.valueOf(); v1 = v1.valueOf();
v2 = v2.valueOf(); v2 = v2.valueOf();
} value = utils.paralle(v1, v2, op);
for (field in v1) {
if (v1.hasOwnProperty(field) && v2.hasOwnProperty(field)) {
value[field] = utils.paralle(v1[field], v2[field], op);
}
}
// 如果值是一个支持原始表示的实例,用其原始表示的结果重新封箱
if (Class && Class.parse) {
value = Class.parse(value); value = Class.parse(value);
} else {
value = {};
for (name in v1) {
if (v1.hasOwnProperty(name) && v2.hasOwnProperty(name)) {
value[name] = utils.paralle(v1[name], v2[name], op);
}
}
} }
return value; return value;
} }
// 是否数字
if (false === isNaN(parseFloat(v1))) {
return op(v1, v2);
}
return value; return value;
}, },
/** /**
...@@ -1613,31 +1647,25 @@ define("graphic/box", [ "core/class" ], function(require, exports, module) { ...@@ -1613,31 +1647,25 @@ define("graphic/box", [ "core/class" ], function(require, exports, module) {
if (height < 0) { if (height < 0) {
y -= height = -height; y -= height = -height;
} }
this.x = x; this.x = x || 0;
this.y = y; this.y = y || 0;
this.width = width; this.width = width || 0;
this.height = height; this.height = height || 0;
}, this.left = x;
getLeft: function() { this.right = this.x + this.width;
return this.x; this.top = this.y;
}, this.bottom = this.y + this.height;
getRight: function() { this.cx = x + this.width / 2;
return this.x + this.width; this.cy = y + this.height / 2;
},
getTop: function() {
return this.y;
},
getBottom: function() {
return this.y + this.height;
}, },
getRangeX: function() { getRangeX: function() {
return [ this.x, this.x + this.width ]; return [ this.left, this.right ];
}, },
getRangeY: function() { getRangeY: function() {
return [ this.y, this.y + this.height ]; return [ this.left, this.right ];
}, },
merge: function(another) { merge: function(another) {
var xMin = Math.min(this.x, another.x), xMax = Math.max(this.x + this.width, another.x + another.width), yMin = Math.min(this.y, another.y), yMax = Math.max(this.y + this.height, another.y + another.height); var xMin = Math.min(this.x, another.x), xMax = Math.max(this.right, another.right), yMin = Math.min(this.y, another.y), yMax = Math.max(this.bottom, another.bottom);
return new Box(xMin, yMin, xMax - xMin, yMax - yMin); return new Box(xMin, yMin, xMax - xMin, yMax - yMin);
}, },
valueOf: function() { valueOf: function() {
...@@ -3105,8 +3133,12 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph ...@@ -3105,8 +3133,12 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph
*/ */
g.pointAtBezier = function(bezierArray, t) { g.pointAtBezier = function(bezierArray, t) {
var b2t = cutBezier(bezierArray, t)[0]; var b2t = cutBezier(bezierArray, t)[0];
var p = Point.parse(b2t.slice(6)), c = Point.parse(b2t.slice(4, 2)); var p = Point.parse(b2t.slice(6)), c = Point.parse(b2t.slice(4, 2)), v = Vector.fromPoints(c, p);
p.tan = Vector.fromPoints(c, p).normalize(); if (t === 0) {
p.tan = g.pointAtBezier(bezierArray, .01).tan;
} else {
p.tan = v.normalize();
}
return p; return p;
}; };
/** /**
...@@ -3122,7 +3154,7 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph ...@@ -3122,7 +3154,7 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph
*/ */
g.bezierLength = cacher(function bezierLength(bezierArray, tolerate) { g.bezierLength = cacher(function bezierLength(bezierArray, tolerate) {
// 切割成多少段来计算 // 切割成多少段来计算
tolerate = Math.max(tolerate || .1, 1e-9); tolerate = Math.max(tolerate || .001, 1e-9);
function len(p, q) { function len(p, q) {
var dx = p[0] - q[0], dy = p[1] - q[1]; var dx = p[0] - q[0], dy = p[1] - q[1];
return Math.sqrt(dx * dx + dy * dy); return Math.sqrt(dx * dx + dy * dy);
...@@ -3138,7 +3170,7 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph ...@@ -3138,7 +3170,7 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph
return bezierLength(cutted[0], tolerate / 2) + bezierLength(cutted[1], tolerate / 3); return bezierLength(cutted[0], tolerate / 2) + bezierLength(cutted[1], tolerate / 3);
}); });
// 计算一个 pathSegment 中每一段的在整体中所占的长度范围,以及总长度 // 计算一个 pathSegment 中每一段的在整体中所占的长度范围,以及总长度
// 方法要求每一段都是贝塞尔曲线 // 方法要求每一段都是贝塞尔曲线
var getBezierPathSegmentRanges = cacher(function(pathSegment) { var getBezierPathSegmentRanges = cacher(function(pathSegment) {
var i, ii, segment, position, bezierLength, segmentRanges, totalLength; var i, ii, segment, position, bezierLength, segmentRanges, totalLength;
segmentRanges = []; segmentRanges = [];
...@@ -3424,8 +3456,8 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph ...@@ -3424,8 +3456,8 @@ define("graphic/geometry", [ "core/utils", "graphic/point", "core/class", "graph
* 补间的结果 * 补间的结果
*/ */
g.pathTween = function(path1, path2, t) { g.pathTween = function(path1, path2, t) {
//if (t === 0) return path1; if (t === 0) return path1;
//if (t === 1) return path2; if (t === 1) return path2;
var aligned = alignCurve(path1, path2); var aligned = alignCurve(path1, path2);
var result = [], seg, i, j; var result = [], seg, i, j;
path1 = aligned[0]; path1 = aligned[0];
...@@ -3725,14 +3757,14 @@ define("graphic/marker", [ "graphic/point", "core/class", "graphic/resource", "g ...@@ -3725,14 +3757,14 @@ define("graphic/marker", [ "graphic/point", "core/class", "graphic/resource", "g
}); });
var Path = require("graphic/path"); var Path = require("graphic/path");
require("core/class").extendClass(Path, { require("core/class").extendClass(Path, {
setMarkerStart: function(marker) { setMarker: function(marker, pos) {
this.node.setAttribute("marker-start", marker.toString()); pos = pos || "end";
}, if (!marker) {
setMarkerMid: function(marker) { this.node.removeAttribute("marker-" + pos);
this.node.setAttribute("marker-mid", marker.toString()); } else {
}, this.node.setAttribute("marker-" + pos, marker.toString());
setMarkerEnd: function(marker) { }
this.node.setAttribute("marker-end", marker.toString()); return this;
} }
}); });
return Marker; return Marker;
...@@ -3896,6 +3928,10 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p ...@@ -3896,6 +3928,10 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p
var m = this.m; var m = this.m;
return [ m.a, m.b, m.c, m.d, m.e, m.f ]; return [ m.a, m.b, m.c, m.d, m.e, m.f ];
}, },
equals: function(matrix) {
var m1 = this.m, m2 = matrix.m;
return m1.a == m2.a && m1.b == m2.b && m1.c == m2.c && m1.d == m2.d && m1.e == m2.e && m1.f == m2.f;
},
transformPoint: function() { transformPoint: function() {
return Matrix.transformPoint.apply(null, [].slice.call(arguments).concat([ this.m ])); return Matrix.transformPoint.apply(null, [].slice.call(arguments).concat([ this.m ]));
}, },
...@@ -3906,6 +3942,16 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p ...@@ -3906,6 +3942,16 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p
Matrix.parse = function(str) { Matrix.parse = function(str) {
var match; var match;
var f = parseFloat; var f = parseFloat;
if (str instanceof Array) {
return new Matrix({
a: str[0],
b: str[1],
c: str[2],
d: str[3],
e: str[4],
f: str[5]
});
}
if (match = mPattern.exec(str)) { if (match = mPattern.exec(str)) {
var values = match[1].split(","); var values = match[1].split(",");
if (values.length != 6) { if (values.length != 6) {
...@@ -3949,11 +3995,7 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p ...@@ -3949,11 +3995,7 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p
height: yMax - yMin height: yMax - yMin
}); });
utils.extend(box, { utils.extend(box, {
closurePoints: rps, closurePoints: rps
left: xMin,
right: xMax,
top: yMin,
bottom: yMax
}); });
return box; return box;
}; };
...@@ -4002,7 +4044,7 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p ...@@ -4002,7 +4044,7 @@ define("graphic/matrix", [ "core/utils", "graphic/box", "core/class", "graphic/p
ctm = target.node.getTransformToElement(refer.shapeNode || refer.node); ctm = target.node.getTransformToElement(refer.shapeNode || refer.node);
} }
} }
return new Matrix(ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f); return ctm ? new Matrix(ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f) : new Matrix();
}; };
return Matrix; return Matrix;
}); });
...@@ -4369,9 +4411,7 @@ define("graphic/path", [ "core/utils", "core/class", "graphic/shape", "graphic/s ...@@ -4369,9 +4411,7 @@ define("graphic/path", [ "core/utils", "core/class", "graphic/shape", "graphic/s
this.node.setAttribute("stroke", svg.defaults.stroke); this.node.setAttribute("stroke", svg.defaults.stroke);
}, },
setPathData: function(data) { setPathData: function(data) {
if (!data) { data = data || "M0,0";
return;
}
this.pathdata = g.pathToString(data); this.pathdata = g.pathToString(data);
this.node.setAttribute("d", this.pathdata); this.node.setAttribute("d", this.pathdata);
this.trigger("shapeupdate", { this.trigger("shapeupdate", {
...@@ -4542,6 +4582,9 @@ define("graphic/point", [ "core/class" ], function(require, exports, module) { ...@@ -4542,6 +4582,9 @@ define("graphic/point", [ "core/class" ], function(require, exports, module) {
}, },
toString: function() { toString: function() {
return this.valueOf().join(" "); return this.valueOf().join(" ");
},
spof: function() {
return new Point((this.x | 0) + .5, (this.y | 0) + .5);
} }
}); });
Point.fromPolar = function(radius, angle, unit) { Point.fromPolar = function(radius, angle, unit) {
...@@ -4705,8 +4748,8 @@ define("graphic/radialgradientbrush", [ "graphic/gradientbrush", "graphic/svg", ...@@ -4705,8 +4748,8 @@ define("graphic/radialgradientbrush", [ "graphic/gradientbrush", "graphic/svg",
} }
}); });
}); });
define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/path", "graphic/shape", "graphic/svg", "graphic/geometry" ], function(require, exports, module) { define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/box", "graphic/path", "graphic/shape", "graphic/svg", "graphic/geometry" ], function(require, exports, module) {
var RectUtils = {}, Utils = require("core/utils"), Point = require("graphic/point"); var RectUtils = {}, Utils = require("core/utils"), Point = require("graphic/point"), Box = require("graphic/box");
Utils.extend(RectUtils, { Utils.extend(RectUtils, {
//根据传递进来的width、height和radius属性, //根据传递进来的width、height和radius属性,
//获取最适合的radius值 //获取最适合的radius值
...@@ -4767,6 +4810,16 @@ define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/p ...@@ -4767,6 +4810,16 @@ define("graphic/rect", [ "core/utils", "graphic/point", "core/class", "graphic/p
this.height = height; this.height = height;
return this.update(); return this.update();
}, },
setBox: function(box) {
this.x = box.x;
this.y = box.y;
this.width = box.width;
this.height = box.height;
return this.update();
},
getBox: function() {
return new Box(this.x, this.y, this.width, this.height);
},
getRadius: function() { getRadius: function() {
return this.radius; return this.radius;
}, },
...@@ -5058,18 +5111,25 @@ define("graphic/shape", [ "graphic/svg", "core/utils", "graphic/eventhandler", " ...@@ -5058,18 +5111,25 @@ define("graphic/shape", [ "graphic/svg", "core/utils", "graphic/eventhandler", "
stroke: function(pen, width) { stroke: function(pen, width) {
if (pen && pen.stroke) { if (pen && pen.stroke) {
pen.stroke(this); pen.stroke(this);
} else { } else if (pen) {
// 字符串或重写了 toString 的对象 // 字符串或重写了 toString 的对象
this.node.setAttribute("stroke", pen.toString()); this.node.setAttribute("stroke", pen.toString());
if (width) { if (width) {
this.node.setAttribute("stroke-width", width); this.node.setAttribute("stroke-width", width);
} }
} else if (pen === null) {
this.node.removeAttribute("stroe");
} }
return this; return this;
}, },
fill: function(brush) { fill: function(brush) {
// 字符串或重写了 toString 的对象 // 字符串或重写了 toString 的对象
this.node.setAttribute("fill", brush.toString()); if (brush) {
this.node.setAttribute("fill", brush.toString());
}
if (brush === null) {
this.node.removeAttribute("fill");
}
return this; return this;
}, },
setAttr: function(a, v) { setAttr: function(a, v) {
...@@ -5685,6 +5745,11 @@ define("graphic/sweep", [ "graphic/point", "core/class", "graphic/path", "core/u ...@@ -5685,6 +5745,11 @@ define("graphic/sweep", [ "graphic/point", "core/class", "graphic/path", "core/u
}, },
drawSection: function(from, to) { drawSection: function(from, to) {
var angleLength = this.angle && (this.angle % 360 ? this.angle % 360 : 360), angleStart = this.angleOffset, angleHalf = angleStart + angleLength / 2, angleEnd = angleStart + angleLength, drawer = this.getDrawer(); var angleLength = this.angle && (this.angle % 360 ? this.angle % 360 : 360), angleStart = this.angleOffset, angleHalf = angleStart + angleLength / 2, angleEnd = angleStart + angleLength, drawer = this.getDrawer();
drawer.redraw();
if (angleLength === 0) {
drawer.done();
return;
}
drawer.moveTo(Point.fromPolar(from, angleStart)); drawer.moveTo(Point.fromPolar(from, angleStart));
drawer.lineTo(Point.fromPolar(to, angleStart)); drawer.lineTo(Point.fromPolar(to, angleStart));
if (to) { if (to) {
...@@ -5697,6 +5762,7 @@ define("graphic/sweep", [ "graphic/point", "core/class", "graphic/path", "core/u ...@@ -5697,6 +5762,7 @@ define("graphic/sweep", [ "graphic/point", "core/class", "graphic/path", "core/u
drawer.carcTo(from, 0, 1, Point.fromPolar(from, angleStart)); drawer.carcTo(from, 0, 1, Point.fromPolar(from, angleStart));
} }
drawer.close(); drawer.close();
drawer.done();
} }
}); });
}); });
...@@ -5711,8 +5777,11 @@ define("graphic/text", [ "graphic/textcontent", "graphic/shape", "core/class", " ...@@ -5711,8 +5777,11 @@ define("graphic/text", [ "graphic/textcontent", "graphic/shape", "core/class", "
if (offsetHash[font]) { if (offsetHash[font]) {
return offsetHash[font]; return offsetHash[font];
} }
var textContent = text.getContent();
text.setContent("test");
var bbox = text.getBoundaryBox(), y = text.getY() + +text.node.getAttribute("dy"); var bbox = text.getBoundaryBox(), y = text.getY() + +text.node.getAttribute("dy");
var topOffset = y - bbox.y, bottomOffset = topOffset - bbox.height; var topOffset = y - bbox.y, bottomOffset = topOffset - bbox.height;
text.setContent(textContent);
return offsetHash[font] = { return offsetHash[font] = {
top: topOffset, top: topOffset,
bottom: bottomOffset, bottom: bottomOffset,
...@@ -5805,7 +5874,7 @@ define("graphic/text", [ "graphic/textcontent", "graphic/shape", "core/class", " ...@@ -5805,7 +5874,7 @@ define("graphic/text", [ "graphic/textcontent", "graphic/shape", "core/class", "
this.node.appendChild(textpath); this.node.appendChild(textpath);
} }
textpath.setAttributeNS(svg.xlink, "xlink:href", "#" + path.node.id); textpath.setAttributeNS(svg.xlink, "xlink:href", "#" + path.node.id);
this.setAnchor(this.getAnchor()); this.setTextAnchor(this.getTextAnchor());
return this; return this;
} }
}); });
...@@ -5860,18 +5929,14 @@ define("graphic/textcontent", [ "graphic/shape", "graphic/svg", "core/utils", "g ...@@ -5860,18 +5929,14 @@ define("graphic/textcontent", [ "graphic/shape", "graphic/svg", "core/utils", "g
}); });
}, },
setFont: function(font) { setFont: function(font) {
if (font.family) { var node = this.node;
this.node.setAttribute("font-family", font.family); [ "family", "size", "weight", "style" ].forEach(function(section) {
} if (font[section] === null) {
if (font.size) { node.removeAttribute("font-" + section);
this.node.setAttribute("font-size", font.size); } else if (font[section]) {
} node.setAttribute("font-" + section, font[section]);
if (font.weight) { }
this.node.setAttribute("font-weight", font.weight); });
}
if (font.style) {
this.node.setAttribute("font-style", font.style);
}
return this; return this;
}, },
getExtentOfChar: function(index) { getExtentOfChar: function(index) {
...@@ -5979,7 +6044,13 @@ define("graphic/vector", [ "graphic/point", "core/class", "graphic/matrix", "cor ...@@ -5979,7 +6044,13 @@ define("graphic/vector", [ "graphic/point", "core/class", "graphic/matrix", "cor
reverse: function() { reverse: function() {
return this.multipy(-1); return this.multipy(-1);
}, },
getAngle: function() {} getAngle: function() {
var length = this.length();
if (length === 0) return 0;
var rad = Math.acos(this.x / length);
var sign = this.y > 0 ? 1 : -1;
return sign * 180 * rad / Math.PI;
}
}); });
Vector.fromPoints = function(p1, p2) { Vector.fromPoints = function(p1, p2) {
return new Vector(p2.x - p1.x, p2.y - p1.y); return new Vector(p2.x - p1.x, p2.y - p1.y);
...@@ -6033,7 +6104,7 @@ define("graphic/viewbox", [ "core/class" ], function(require, exports, module) { ...@@ -6033,7 +6104,7 @@ define("graphic/viewbox", [ "core/class" ], function(require, exports, module) {
} }
}); });
}); });
define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", "graphic/pointcontainer", "graphic/path", "graphic/bezierpoint", "graphic/shapepoint", "graphic/vector", "graphic/circle", "graphic/ellipse", "graphic/clip", "graphic/shape", "graphic/shapecontainer", "graphic/color", "graphic/standardcolor", "graphic/container", "graphic/curve", "graphic/point", "graphic/gradientbrush", "graphic/svg", "graphic/defbrush", "graphic/group", "graphic/hyperlink", "graphic/image", "graphic/line", "graphic/lineargradientbrush", "graphic/mask", "graphic/matrix", "graphic/box", "graphic/marker", "graphic/resource", "graphic/viewbox", "graphic/palette", "graphic/paper", "graphic/eventhandler", "graphic/styled", "graphic/geometry", "graphic/patternbrush", "graphic/pen", "graphic/polygon", "graphic/poly", "graphic/polyline", "graphic/pie", "graphic/sweep", "graphic/radialgradientbrush", "graphic/rect", "graphic/regularpolygon", "graphic/ring", "graphic/data", "graphic/star", "graphic/text", "graphic/textcontent", "graphic/textspan", "graphic/use", "animate/animator", "animate/timeline", "animate/easing", "animate/opacityanimator", "animate/rotateanimator", "animate/scaleanimator", "animate/frame", "animate/translateanimator", "filter/filter", "filter/effectcontainer", "filter/gaussianblurfilter", "filter/effect/gaussianblureffect", "filter/projectionfilter", "filter/effect/effect", "filter/effect/colormatrixeffect", "filter/effect/compositeeffect", "filter/effect/offseteffect", "filter/effect/convolvematrixeffect" ], function(require, exports, module) { define("kity", [ "core/utils", "core/class", "core/browser", "graphic/box", "graphic/bezier", "graphic/pointcontainer", "graphic/path", "graphic/bezierpoint", "graphic/shapepoint", "graphic/vector", "graphic/circle", "graphic/ellipse", "graphic/clip", "graphic/shape", "graphic/shapecontainer", "graphic/color", "graphic/standardcolor", "graphic/container", "graphic/curve", "graphic/point", "graphic/gradientbrush", "graphic/svg", "graphic/defbrush", "graphic/group", "graphic/hyperlink", "graphic/image", "graphic/line", "graphic/lineargradientbrush", "graphic/mask", "graphic/matrix", "graphic/marker", "graphic/resource", "graphic/viewbox", "graphic/palette", "graphic/paper", "graphic/eventhandler", "graphic/styled", "graphic/geometry", "graphic/patternbrush", "graphic/pen", "graphic/polygon", "graphic/poly", "graphic/polyline", "graphic/pie", "graphic/sweep", "graphic/radialgradientbrush", "graphic/rect", "graphic/regularpolygon", "graphic/ring", "graphic/data", "graphic/star", "graphic/text", "graphic/textcontent", "graphic/textspan", "graphic/use", "animate/animator", "animate/timeline", "animate/easing", "animate/opacityanimator", "animate/rotateanimator", "animate/scaleanimator", "animate/frame", "animate/translateanimator", "animate/pathanimator", "animate/motionanimator", "filter/filter", "filter/effectcontainer", "filter/gaussianblurfilter", "filter/effect/gaussianblureffect", "filter/projectionfilter", "filter/effect/effect", "filter/effect/colormatrixeffect", "filter/effect/compositeeffect", "filter/effect/offseteffect", "filter/effect/convolvematrixeffect" ], function(require, exports, module) {
var kity = {}, utils = require("core/utils"); var kity = {}, utils = require("core/utils");
kity.version = "2.0.0"; kity.version = "2.0.0";
utils.extend(kity, { utils.extend(kity, {
...@@ -6043,6 +6114,7 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", " ...@@ -6043,6 +6114,7 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", "
Utils: utils, Utils: utils,
Browser: require("core/browser"), Browser: require("core/browser"),
// shape // shape
Box: require("graphic/box"),
Bezier: require("graphic/bezier"), Bezier: require("graphic/bezier"),
BezierPoint: require("graphic/bezierpoint"), BezierPoint: require("graphic/bezierpoint"),
Circle: require("graphic/circle"), Circle: require("graphic/circle"),
...@@ -6091,6 +6163,8 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", " ...@@ -6091,6 +6163,8 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", "
ScaleAnimator: require("animate/scaleanimator"), ScaleAnimator: require("animate/scaleanimator"),
Timeline: require("animate/timeline"), Timeline: require("animate/timeline"),
TranslateAnimator: require("animate/translateanimator"), TranslateAnimator: require("animate/translateanimator"),
PathAnimator: require("animate/pathanimator"),
MotionAnimator: require("animate/motionanimator"),
// filter // filter
Filter: require("filter/filter"), Filter: require("filter/filter"),
GaussianblurFilter: require("filter/gaussianblurfilter"), GaussianblurFilter: require("filter/gaussianblurfilter"),
...@@ -6106,19 +6180,18 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", " ...@@ -6106,19 +6180,18 @@ define("kity", [ "core/utils", "core/class", "core/browser", "graphic/bezier", "
return window.kity = kity; return window.kity = kity;
}); });
/*global use:true*/ /* global use, inc: true */
/** /**
* 模块暴露 * 模块暴露
*/ */
(function(global) { (function() {
define('export', function(require) { try {
return require('kity'); inc.use('kity');
}); } catch (e) {
use('kity');
// build 环境中才含有use }
if (use) use('export');
})(this);})(); })();})();
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -716,11 +716,17 @@ ...@@ -716,11 +716,17 @@
function seekEOCDR(offset, entriesCallback) { function seekEOCDR(offset, entriesCallback) {
reader.readUint8Array(reader.size - offset, offset, function(bytes) { reader.readUint8Array(reader.size - offset, offset, function(bytes) {
var dataView = getDataHelper(bytes.length, bytes).view; var dataView = getDataHelper(bytes.length, bytes).view;
if (dataView.getUint32(0) != 0x504b0506) { try{
seekEOCDR(offset + 1, entriesCallback); if (dataView.getUint32(0) != 0x504b0506) {
} else { seekEOCDR(offset + 1, entriesCallback);
entriesCallback(dataView); } else {
entriesCallback(dataView);
}
}catch(e){
console.log(e);
onerror(ERR_READ);
} }
}, function() { }, function() {
onerror(ERR_READ); onerror(ERR_READ);
}); });
......
...@@ -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",
......
...@@ -42,6 +42,10 @@ kity.extendClass(MinderNode, { ...@@ -42,6 +42,10 @@ kity.extendClass(MinderNode, {
return this.getLayoutInstance().getOrderHint(this); return this.getLayoutInstance().getOrderHint(this);
}, },
getExpandPosition: function() {
return this.getLayoutInstance().getExpandPosition();
},
getLayoutInstance: function() { getLayoutInstance: function() {
var LayoutClass = KityMinder._layout[this.getLayout()]; var LayoutClass = KityMinder._layout[this.getLayout()];
var layout = new LayoutClass(); var layout = new LayoutClass();
...@@ -128,30 +132,19 @@ kity.extendClass(MinderNode, { ...@@ -128,30 +132,19 @@ kity.extendClass(MinderNode, {
} }
} }
this.getMinder().layout(this, duration); this.getMinder().layout(duration);
return this; return this;
},
getLayoutContextPoints: function() {
return this.getLayoutInstance().getLayoutContextPoints(this);
} }
}); });
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,17 +160,24 @@ kity.extendClass(Minder, { ...@@ -167,17 +160,24 @@ 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');
}, },
refresh: function(duration) {
this.getRoot().preTraverse(function(node) { node.render(); });
return this.layout(duration);
},
applyLayoutResult: function(root, duration) { applyLayoutResult: function(root, duration) {
root = root || this.getRoot(); root = root || this.getRoot();
var me = this; var me = this;
if (root.getComplex() > 100) duration = 0;
function apply(node, pMatrix) { function apply(node, pMatrix) {
var matrix = node.getLayoutTransform().merge(pMatrix); var matrix = node.getLayoutTransform().merge(pMatrix);
var lastMatrix = node._lastLayoutTransform || new kity.Matrix(); var lastMatrix = node._lastLayoutTransform || new kity.Matrix();
......
...@@ -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;
}, },
/** /**
......
...@@ -33,6 +33,7 @@ KityMinder.registerLayout('bottom', kity.createClass({ ...@@ -33,6 +33,7 @@ KityMinder.registerLayout('bottom', kity.createClass({
return box; return box;
}); });
var nodeContentBox = node.getContentBox(); var nodeContentBox = node.getContentBox();
node.setLayoutVector(new kity.Vector(nodeContentBox.cx - 5, nodeContentBox.bottom));
var i, x, y, child, childTreeBox, childContentBox; var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix(); var transform = new kity.Matrix();
x = -totalTreeWidth / 2; x = -totalTreeWidth / 2;
...@@ -50,7 +51,6 @@ KityMinder.registerLayout('bottom', kity.createClass({ ...@@ -50,7 +51,6 @@ KityMinder.registerLayout('bottom', kity.createClass({
y = nodeContentBox.height + node.getStyle('margin-bottom') + children[i].getStyle('margin-top'); y = nodeContentBox.height + node.getStyle('margin-bottom') + children[i].getStyle('margin-top');
children[i].setLayoutTransform(new kity.Matrix().translate(x, y)); children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
x += childTreeBox.width / 2 + children[i].getStyle('margin-right'); x += childTreeBox.width / 2 + children[i].getStyle('margin-right');
child.setLayoutVector(new kity.Vector(childContentBox.cx - 5, childContentBox.bottom));
} }
} }
} }
...@@ -64,6 +64,5 @@ KityMinder.registerConnectProvider('bottom', function(node, parent, connection) ...@@ -64,6 +64,5 @@ KityMinder.registerConnectProvider('bottom', function(node, parent, connection)
pathData.push('L', new kity.Point(pBox.cx, pBox.bottom + parent.getStyle('margin-bottom'))); pathData.push('L', new kity.Point(pBox.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, pBox.bottom + parent.getStyle('margin-bottom'))); pathData.push('L', new kity.Point(box.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, box.top)); pathData.push('L', new kity.Point(box.cx, box.top));
console.log(pathData);
connection.setPathData(pathData); connection.setPathData(pathData);
}); });
\ No newline at end of file
...@@ -14,7 +14,7 @@ KityMinder.registerConnectProvider('default', function(node, parent, connection, ...@@ -14,7 +14,7 @@ KityMinder.registerConnectProvider('default', function(node, parent, connection,
var start, end, vector; var start, end, vector;
var abs = Math.abs; var abs = Math.abs;
var pathData = []; var pathData = [];
var side = node.getLayoutVector().x > 0 ? 'right' : 'left'; var side = box.x > pBox.x ? 'right' : 'left';
node.getMinder().getPaper().addResource(connectMarker); node.getMinder().getPaper().addResource(connectMarker);
......
...@@ -66,6 +66,12 @@ KityMinder.registerLayout('default', kity.createClass({ ...@@ -66,6 +66,12 @@ KityMinder.registerLayout('default', kity.createClass({
y = -totalTreeHeight / 2; y = -totalTreeHeight / 2;
if (side != 'left') {
parent.setLayoutVector(new kity.Vector(nodeContentBox.right, nodeContentBox.cy));
} else {
parent.setLayoutVector(new kity.Vector(nodeContentBox.left, nodeContentBox.cy));
}
for (i = 0; i < children.length; i++) { for (i = 0; i < children.length; i++) {
child = children[i]; child = children[i];
childTreeBox = childTreeBoxes[i]; childTreeBox = childTreeBoxes[i];
...@@ -77,15 +83,9 @@ KityMinder.registerLayout('default', kity.createClass({ ...@@ -77,15 +83,9 @@ KityMinder.registerLayout('default', kity.createClass({
if (side == 'right') { if (side == 'right') {
x = nodeContentBox.right - childContentBox.left; x = nodeContentBox.right - childContentBox.left;
x += parent.getStyle('margin-right') + child.getStyle('margin-left'); x += parent.getStyle('margin-right') + child.getStyle('margin-left');
// 设置布局矢量
child.setLayoutVector(new kity.Vector(childContentBox.right, childContentBox.cy));
} else { } else {
x = nodeContentBox.left - childContentBox.right; x = nodeContentBox.left - childContentBox.right;
x -= parent.getStyle('margin-left') + child.getStyle('margin-right'); x -= parent.getStyle('margin-left') + child.getStyle('margin-right');
// 设置布局矢量
child.setLayoutVector(new kity.Vector(childContentBox.left, childContentBox.cy));
} }
// 竖直方向上的布局 // 竖直方向上的布局
......
...@@ -28,6 +28,7 @@ KityMinder.registerLayout('filetree', kity.createClass({ ...@@ -28,6 +28,7 @@ KityMinder.registerLayout('filetree', kity.createClass({
return box; return box;
}); });
var nodeContentBox = node.getContentBox(); var nodeContentBox = node.getContentBox();
node.setLayoutVector(new kity.Vector(nodeContentBox.left + 6, nodeContentBox.bottom));
var i, x, y, child, childTreeBox, childContentBox; var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix(); var transform = new kity.Matrix();
y = nodeContentBox.bottom + node.getStyle('margin-bottom'); y = nodeContentBox.bottom + node.getStyle('margin-bottom');
...@@ -41,7 +42,6 @@ KityMinder.registerLayout('filetree', kity.createClass({ ...@@ -41,7 +42,6 @@ KityMinder.registerLayout('filetree', kity.createClass({
y += child.getStyle('margin-top'); y += child.getStyle('margin-top');
child.setLayoutTransform(new kity.Matrix().translate(x, y)); child.setLayoutTransform(new kity.Matrix().translate(x, y));
y += childTreeBox.height + children[i].getStyle('margin-bottom'); y += childTreeBox.height + children[i].getStyle('margin-bottom');
child.setLayoutVector(new kity.Vector(childContentBox.left + 10, childContentBox.bottom));
} }
} }
}, },
......
...@@ -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 上
......
/* 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.getStatus() == 'textedit') { if (minder.getStatus() == 'textedit') {
...@@ -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) {
......
...@@ -14,7 +14,7 @@ KityMinder.registerTheme('bottom', { ...@@ -14,7 +14,7 @@ KityMinder.registerTheme('bottom', {
'main-font-size': 16, 'main-font-size': 16,
'main-padding': [6, 20], 'main-padding': [6, 20],
'main-margin': [30, 0, 10, 0], 'main-margin': [30, 0, 10, 0],
'main-radius': 10, 'main-radius': 5,
'main-space': 5, 'main-space': 5,
'sub-color': 'white', 'sub-color': 'white',
......
...@@ -13,8 +13,8 @@ KityMinder.registerTheme('filetree', { ...@@ -13,8 +13,8 @@ KityMinder.registerTheme('filetree', {
'main-stroke': 'none', 'main-stroke': 'none',
'main-font-size': 16, 'main-font-size': 16,
'main-padding': [6, 20], 'main-padding': [6, 20],
'main-margin': [30, 0, 10, 0], 'main-margin': [15, 15, 15, 10],
'main-radius': 10, 'main-radius': 0,
'main-space': 5, 'main-space': 5,
'sub-color': 'black', 'sub-color': 'black',
...@@ -22,8 +22,8 @@ KityMinder.registerTheme('filetree', { ...@@ -22,8 +22,8 @@ KityMinder.registerTheme('filetree', {
'sub-stroke': 'none', 'sub-stroke': 'none',
'sub-font-size': 12, 'sub-font-size': 12,
'sub-padding': [5, 10], 'sub-padding': [5, 10],
'sub-margin': [5, 15, 10, 5], 'sub-margin': [15, 15, 15, 10],
'sub-radius': 5, 'sub-radius': 0,
'sub-space': 5, 'sub-space': 5,
'connect-color': 'white', 'connect-color': 'white',
......
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