Commit 76628137 authored by Akikonata's avatar Akikonata

Merge branch 'dev' of https://github.com/fex-team/kityminder into dev

parents ba48e96d 257373fa
(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>' +
...@@ -9,13 +8,13 @@ ...@@ -9,13 +8,13 @@
'</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,19 +50,19 @@ ...@@ -51,19 +50,19 @@
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" />')
......
...@@ -15,12 +15,14 @@ ...@@ -15,12 +15,14 @@
'core/minder.module.js', 'core/minder.module.js',
'core/minder.command.js', 'core/minder.command.js',
'core/minder.node.js', 'core/minder.node.js',
'core/minder.select.js',
'core/keymap.js', 'core/keymap.js',
'core/minder.lang.js', 'core/minder.lang.js',
'core/minder.defaultoptions.js', 'core/minder.defaultoptions.js',
'core/minder.preference.js', 'core/minder.preference.js',
'core/browser.js', 'core/browser.js',
'core/layout.js', 'core/layout.js',
'core/connect.js',
'core/render.js', 'core/render.js',
'core/theme.js', 'core/theme.js',
'layout/default.js', 'layout/default.js',
...@@ -38,7 +40,6 @@ ...@@ -38,7 +40,6 @@
'module/priority.js', 'module/priority.js',
'module/image.js', 'module/image.js',
'module/resource.js', 'module/resource.js',
'core/minder.select.js',
'module/view.js', 'module/view.js',
'module/dragtree.js', 'module/dragtree.js',
'module/dropfile.js', 'module/dropfile.js',
......
/* global Renderer: true */ /* global Renderer: true */
utils.extend(KityMinder, {
_connectProviders: {},
_defaultConnectProvider: function(node, parent) {
return [
'M', parent.getLayoutPoint(),
'L', node.getLayoutPoint()
];
},
registerConnectProvider: function(layout, provider) {
KityMinder._connectProviders[layout] = provider;
},
getConnectProvider: function(layout) {
return KityMinder._connectProviders[layout] || KityMinder._defaultConnectProvider;
}
});
kity.extendClass(Minder, { kity.extendClass(Minder, {
createConnect: function(node) { createConnect: function(node) {
...@@ -30,59 +49,14 @@ kity.extendClass(Minder, { ...@@ -30,59 +49,14 @@ kity.extendClass(Minder, {
if (!parent) return; if (!parent) return;
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.cx > pBox.cx ? 'right' : 'left';
if (parent.isCollapsed()) { if (parent.isCollapsed()) {
connection.setVisible(false); connection.setVisible(false);
return; return;
} }
connection.setVisible(true); connection.setVisible(true);
switch (node.getType()) { var provider = KityMinder.getConnectProvider(node.getLayout());
var pathData = provider(node, parent);
case 'main':
start = new kity.Point(pBox.cx, pBox.cy);
end = side == 'left' ?
new kity.Point(box.right, box.cy) :
new kity.Point(box.left, box.cy);
vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
break;
case 'sub':
var radius = node.getStyle('connect-radius');
if (side == 'right') {
start = new kity.Point(box.left - node.getStyle('margin-left') / 2, pBox.cy);
end = new kity.Point(box.right + node.getStyle('margin-right') / 2, box.bottom);
} else {
start = new kity.Point(box.right + node.getStyle('margin-right') / 2, pBox.cy);
end = new kity.Point(box.left - node.getStyle('margin-left') / 2, box.bottom);
}
end.y += 1;
var isTop = parent.children.length > 1 && node.getIndex() === 0;
pathData.push('M', start);
pathData.push('L', start.x, isTop ? (end.y + radius) : (end.y - radius));
var sf = +(side == 'right' && isTop || side == 'left' && !isTop);
var ex = side == 'right' ? (start.x + radius) : (start.x - radius);
pathData.push('A', radius, radius, 0, 0, sf, ex, end.y);
pathData.push('L', end);
}
connection.setPathData(pathData); connection.setPathData(pathData);
} }
......
/* global Layout:true */ /* global Layout:true */
window.layoutSwitch = true; window.layoutSwitch = true;
KityMinder.registerLayout('default', kity.createClass({ KityMinder.registerLayout('default', kity.createClass({
base: Layout, base: Layout,
...@@ -108,3 +109,55 @@ KityMinder.registerLayout('default', kity.createClass({ ...@@ -108,3 +109,55 @@ KityMinder.registerLayout('default', kity.createClass({
} }
} }
})); }));
KityMinder.registerConnectProvider('default', function(node, parent) {
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var start, end, vector;
var abs = Math.abs;
var pathData = [];
var side = box.cx > pBox.cx ? 'right' : 'left';
switch (node.getType()) {
case 'main':
start = new kity.Point(pBox.cx, pBox.cy);
end = side == 'left' ?
new kity.Point(box.right, box.cy) :
new kity.Point(box.left, box.cy);
vector = kity.Vector.fromPoints(start, end);
pathData.push('M', start);
pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
break;
case 'sub':
var radius = node.getStyle('connect-radius');
if (side == 'right') {
start = new kity.Point(box.left - node.getStyle('margin-left') / 2, pBox.cy);
end = new kity.Point(box.right + node.getStyle('margin-right') / 2, box.bottom);
} else {
start = new kity.Point(box.right + node.getStyle('margin-right') / 2, pBox.cy);
end = new kity.Point(box.left - node.getStyle('margin-left') / 2, box.bottom);
}
end.y += 1;
var isTop = parent.children.length > 1 && node.getIndex() === 0;
pathData.push('M', start);
pathData.push('L', start.x, isTop ? (end.y + radius) : (end.y - radius));
var sf = +(side == 'right' && isTop || side == 'left' && !isTop);
var ex = side == 'right' ? (start.x + radius) : (start.x - radius);
pathData.push('A', radius, radius, 0, 0, sf, ex, end.y);
pathData.push('L', end);
}
return pathData;
});
...@@ -34,7 +34,7 @@ KityMinder.registerModule('Resource', function() { ...@@ -34,7 +34,7 @@ KityMinder.registerModule('Resource', function() {
colorMapping[resource] = nextIndex; colorMapping[resource] = nextIndex;
} }
// 资源过多,找不到可用索引颜色,统一返回白色åå // 资源过多,找不到可用索引颜色,统一返回白色
return RESOURCE_COLOR_SERIES[colorMapping[resource]] || RESOURCE_COLOR_OVERFLOW; return RESOURCE_COLOR_SERIES[colorMapping[resource]] || RESOURCE_COLOR_OVERFLOW;
}, },
...@@ -162,27 +162,36 @@ KityMinder.registerModule('Resource', function() { ...@@ -162,27 +162,36 @@ KityMinder.registerModule('Resource', function() {
var ResourceOverlay = kity.createClass('ResourceOverlay', { var ResourceOverlay = kity.createClass('ResourceOverlay', {
base: kity.Group, base: kity.Group,
constructor: function(container, resourceName, color) { constructor: function() {
this.callBase(); this.callBase();
var text, rect;
rect = this.rect = new kity.Rect();
text = this.text = new kity.Text()
.setFontSize(12)
.setVerticalAlign('middle');
this.addShapes([rect, text]);
},
setValue: function(resourceName, color) {
var paddingX = 8, var paddingX = 8,
paddingY = 4, paddingY = 4,
borderRadius = 4; borderRadius = 4;
var text, box, rect; var text, box, rect;
container.addShape(this); text = this.text
text = new kity.Text()
.setContent(resourceName)
.setFontSize(12)
.setVerticalAlign('middle')
.setX(paddingX) .setX(paddingX)
.setContent(resourceName)
.fill(color.dec('l', 70)); .fill(color.dec('l', 70));
this.addShape(text);
box = text.getBoundaryBox(); box = text.getBoundaryBox();
rect.setPosition(0, box.y - paddingY);
rect.setSize(box.width + paddingX * 2, box.height + paddingY * 2);
rect = new kity.Rect( rect = new kity.Rect(
box.width + paddingX * 2, box.width + paddingX * 2,
box.height + paddingY * 2, box.height + paddingY * 2,
...@@ -194,6 +203,21 @@ KityMinder.registerModule('Resource', function() { ...@@ -194,6 +203,21 @@ KityMinder.registerModule('Resource', function() {
this.addShape(rect); this.addShape(rect);
rect.bringRear(); rect.bringRear();
}
});
/**
* @class 资源渲染器
*/
var ResourceRenderer = kity.createClass('ResourceRenderer', {
base: KityMinder.Renderer,
create: function(node) {
this.container = new kity.Group();
this.overlays = [];
},
update: function(node) {
} }
}); });
...@@ -219,6 +243,10 @@ KityMinder.registerModule('Resource', function() { ...@@ -219,6 +243,10 @@ KityMinder.registerModule('Resource', function() {
}); });
} }
} }
},
renderers: {
right: ResourceRenderer
} }
}; };
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment