Commit aa0c2a52 authored by techird's avatar techird

添加资源渲染

parent 1c1c0355
......@@ -3,8 +3,19 @@ kity.extendClass(Minder, {
_initSelection: function() {
this._selectedNodes = [];
},
renderChangedSelection: function(changed) {
renderChangedSelection: function(last) {
var current = this.getSelectedNodes();
var changed = [];
var i = 0;
current.forEach(function(node) {
if (last.indexOf(node) == -1) changed.push(node);
});
last.forEach(function(node) {
if (current.indexOf(node) == -1) changed.push(node);
});
while (i < changed.length) changed[i++].render();
},
getSelectedNodes: function() {
......@@ -16,25 +27,27 @@ kity.extendClass(Minder, {
},
removeAllSelectedNodes: function() {
var me = this;
var changed = this._selectedNodes;
var last = this._selectedNodes.splice(0);
this._selectedNodes = [];
this.renderChangedSelection(changed);
this.renderChangedSelection(last);
return this.fire('selectionclear');
},
removeSelectedNodes: function(nodes) {
var me = this;
var last = this._selectedNodes.slice(0);
nodes = Utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
var index;
if ((index = me._selectedNodes.indexOf(n)) === -1) return;
me._selectedNodes.splice(index, 1);
});
this.renderChangedSelection(nodes);
this.renderChangedSelection(last);
return this;
},
select: function(nodes, isSingleSelect) {
var lastSelect = this.getSelectedNodes().slice(0);
if (isSingleSelect) {
this.removeAllSelectedNodes();
this._selectedNodes = [];
}
var me = this;
nodes = Utils.isArray(nodes) ? nodes : [nodes];
......@@ -42,7 +55,7 @@ kity.extendClass(Minder, {
if (me._selectedNodes.indexOf(n) !== -1) return;
me._selectedNodes.push(n);
});
this.renderChangedSelection(nodes);
this.renderChangedSelection(lastSelect);
return this;
},
......
......@@ -36,7 +36,7 @@ kity.extendClass(Minder, {
var registered = this._renderers;
var renderers = [];
['center', 'left', 'top', 'bottom', 'outline', 'outside'].forEach(function(section) {
['center', 'left', 'right', 'top', 'bottom', 'outline', 'outside'].forEach(function(section) {
if (registered['before' + section]) {
renderers = renderers.concat(registered['before' + section]);
}
......
......@@ -3,7 +3,7 @@ KityMinder.registerModule('Resource', function() {
/**
* 自动使用的颜色序列
*/
var RESOURCE_COLOR_SERIES = [200, 51, 303, 75, 157, 0, 26, 254].map(function(h) {
var RESOURCE_COLOR_SERIES = [51, 303, 75, 200, 157, 0, 26, 254].map(function(h) {
return kity.Color.createHSL(h, 100, 85);
});
......@@ -167,7 +167,7 @@ KityMinder.registerModule('Resource', function() {
var text, rect;
rect = this.rect = new kity.Rect();
rect = this.rect = new kity.Rect().setRadius(4);
text = this.text = new kity.Text()
.setFontSize(12)
......@@ -182,27 +182,30 @@ KityMinder.registerModule('Resource', function() {
borderRadius = 4;
var text, box, rect;
text = this.text
.setX(paddingX)
.setContent(resourceName)
.fill(color.dec('l', 70));
text = this.text;
if (resourceName == this.lastResourceName) {
box = this.lastBox;
} else {
text.setContent(resourceName);
box = text.getBoundaryBox();
this.lastResourceName = resourceName;
this.lastBox = box;
rect.setPosition(0, box.y - paddingY);
rect.setSize(box.width + paddingX * 2, box.height + paddingY * 2);
}
rect = new kity.Rect(
box.width + paddingX * 2,
box.height + paddingY * 2,
box.x - paddingX,
box.y - paddingY,
borderRadius);
text.setX(paddingX).fill(color.dec('l', 70));
rect = this.rect;
rect.setPosition(0, box.y - paddingY);
rect.setSize(
this.width = box.width + paddingX * 2,
this.height = box.height + paddingY * 2);
rect.fill(color);
this.addShape(rect);
rect.bringRear();
}
});
......@@ -213,12 +216,49 @@ KityMinder.registerModule('Resource', function() {
base: KityMinder.Renderer,
create: function(node) {
this.container = new kity.Group();
this.overlays = [];
return new kity.Group();
},
shouldRender: function(node) {
return node.getData('resource') && node.getData('resource').length;
},
update: function(node) {
update: function(container, node, box) {
var spaceRight = node.getStyle('space-right');
var overlays = this.overlays;
var resource = node.getData('resource');
var minder = node.getMinder();
var i, overlay, x;
x = 0;
for (i = 0; i < resource.length; i++) {
x += spaceRight;
overlay = overlays[i];
if (!overlay) {
overlay = new ResourceOverlay();
overlays.push(overlay);
container.addShape(overlay);
}
overlay.setVisible(true);
overlay.setValue(resource[i], minder.getResourceColor(resource[i]));
overlay.setTranslate(x, 0);
x += overlay.width;
}
while ((overlay = overlays[i++])) overlay.setVisible(false);
container.setTranslate(box.right, 0);
return {
x: box.right,
y: -overlays[0].height / 2,
width: x,
height: overlays[0].height
};
}
});
......@@ -227,24 +267,6 @@ KityMinder.registerModule('Resource', function() {
'resource': ResourceCommand
},
events: {
'RenderNodeRight': function(e) {
var node = e.node;
var resource = node.getData('resource');
var content = node.getContRc();
var margin = 5;
var minder = this;
if (resource && resource.length) {
resource.forEach(function(name) {
var overlay = new ResourceOverlay(content, name, minder.getResourceColor(name));
var box = content.getBoundaryBox();
overlay.setTranslate(box.width + margin, 0);
});
}
}
},
renderers: {
right: ResourceRenderer
}
......
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