- Remove all old layout classes.
- Rename nloyout to layout - Drag integrated.
This commit is contained in:
60
mindplot/src/main/javascript/layout/AbstractBasicSorter.js
Normal file
60
mindplot/src/main/javascript/layout/AbstractBasicSorter.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.AbstractBasicSorter = new Class({
|
||||
Extends: mindplot.nlayout.ChildrenSorterStrategy,
|
||||
|
||||
computeChildrenIdByHeights: function(treeSet, node) {
|
||||
var result = {};
|
||||
this._computeChildrenHeight(treeSet, node, result);
|
||||
return result;
|
||||
},
|
||||
|
||||
_computeChildrenHeight : function(treeSet, node, heightCache) {
|
||||
var height = node.getSize().height + (mindplot.nlayout.AbstractBasicSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding;
|
||||
|
||||
var result;
|
||||
var children = treeSet.getChildren(node);
|
||||
if (children.length == 0 || node.areChildrenShrunken()) {
|
||||
result = height;
|
||||
} else {
|
||||
var childrenHeight = 0;
|
||||
children.forEach(function(child) {
|
||||
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
|
||||
}, this);
|
||||
|
||||
result = Math.max(height, childrenHeight);
|
||||
}
|
||||
|
||||
if (heightCache) {
|
||||
heightCache[node.getId()] = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
_getSortedChildren:function(treeSet, node) {
|
||||
var result = treeSet.getChildren(node);
|
||||
result.sort(function(a, b) {
|
||||
return a.getOrder() - b.getOrder()
|
||||
});
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.nlayout.AbstractBasicSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||
mindplot.nlayout.AbstractBasicSorter.INTERNODE_HORIZONTAL_PADDING = 30;
|
||||
212
mindplot/src/main/javascript/layout/BalancedSorter.js
Normal file
212
mindplot/src/main/javascript/layout/BalancedSorter.js
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.BalancedSorter = new Class({
|
||||
Extends: mindplot.nlayout.AbstractBasicSorter,
|
||||
|
||||
initialize: function() {
|
||||
|
||||
},
|
||||
|
||||
computeChildrenIdByHeights: function(treeSet, node) {
|
||||
var result = {};
|
||||
this._computeChildrenHeight(treeSet, node, result);
|
||||
return result;
|
||||
},
|
||||
|
||||
_computeChildrenHeight : function(treeSet, node, heightCache) {
|
||||
var height = node.getSize().height + (mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING * 2); // 2* Top and down padding;
|
||||
|
||||
var result;
|
||||
var children = treeSet.getChildren(node);
|
||||
if (children.length == 0 || node.areChildrenShrunken()) {
|
||||
result = height;
|
||||
} else {
|
||||
var childrenHeight = 0;
|
||||
children.forEach(function(child) {
|
||||
childrenHeight += this._computeChildrenHeight(treeSet, child, heightCache);
|
||||
}, this);
|
||||
|
||||
result = Math.max(height, childrenHeight);
|
||||
}
|
||||
|
||||
if (heightCache) {
|
||||
heightCache[node.getId()] = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
predict : function(parent, graph, position) {
|
||||
|
||||
if (!position) {
|
||||
var right = this._getChildrenForOrder(parent, graph, 0);
|
||||
var left = this._getChildrenForOrder(parent, graph, 1);
|
||||
}
|
||||
// Filter nodes on one side..
|
||||
var order = position ? (position.x > 0 ? 0 : 1) : ((right.length - left.length) > 0 ? 1 : 0);
|
||||
var children = this._getChildrenForOrder(parent, graph, order);
|
||||
|
||||
// No children?
|
||||
if (children.length == 0) {
|
||||
return [0, {x:parent.getPosition().x + parent.getSize().width + mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING * 2, y:parent.getPosition().y}];
|
||||
}
|
||||
|
||||
|
||||
// Try to fit within ...
|
||||
var result = null;
|
||||
var last = children.getLast();
|
||||
position = position || {x: last.getPosition().x, y:last.getPosition().y + 1};
|
||||
children.each(function(child, index) {
|
||||
var cpos = child.getPosition();
|
||||
if (position.y > cpos.y) {
|
||||
yOffset = child == last ?
|
||||
child.getSize().height + mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING * 2 :
|
||||
(children[index + 1].getPosition().y - child.getPosition().y)/2;
|
||||
result = [child.getOrder() + 2,{x:cpos.x, y:cpos.y + yOffset}];
|
||||
}
|
||||
});
|
||||
|
||||
// Position wasn't below any node, so it must be inserted above
|
||||
if (!result) {
|
||||
var first = children[0];
|
||||
result = [position.x > 0 ? 0 : 1, {
|
||||
x:first.getPosition().x,
|
||||
y:first.getPosition().y - first.getSize().height - mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING * 2
|
||||
}];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
insert: function(treeSet, parent, child, order) {
|
||||
var children = this._getChildrenForOrder(parent, treeSet, order);
|
||||
|
||||
// Shift all the elements by two, so side is the same.
|
||||
// In case of balanced sorter, order don't need to be continuous...
|
||||
var max = 0;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var node = children[i];
|
||||
max = Math.max(max, node.getOrder());
|
||||
if (node.getOrder() >= order) {
|
||||
max = Math.max(max, node.getOrder() + 2);
|
||||
node.setOrder(node.getOrder() + 2);
|
||||
}
|
||||
}
|
||||
|
||||
var newOrder = order > (max+1) ? (max + 2) : order;
|
||||
child.setOrder(newOrder);
|
||||
},
|
||||
|
||||
detach:function(treeSet, node) {
|
||||
var parent = treeSet.getParent(node);
|
||||
// Filter nodes on one side..
|
||||
var children = this._getChildrenForOrder(parent, treeSet, node.getOrder());
|
||||
|
||||
children.each(function(child, index) {
|
||||
if (child.getOrder() > node.getOrder()) {
|
||||
child.setOrder(child.getOrder() - 2);
|
||||
}
|
||||
});
|
||||
node.setOrder(node.getOrder() % 2 == 0 ? 0 : 1);
|
||||
},
|
||||
|
||||
computeOffsets:function(treeSet, node) {
|
||||
$assert(treeSet, "treeSet can no be null.");
|
||||
$assert(node, "node can no be null.");
|
||||
|
||||
var children = this._getSortedChildren(treeSet, node);
|
||||
|
||||
// Compute heights ...
|
||||
var heights = children.map(
|
||||
function(child) {
|
||||
return {id:child.getId(), order:child.getOrder(), width: child.getSize().width, height:this._computeChildrenHeight(treeSet, child)};
|
||||
}, this).reverse();
|
||||
|
||||
|
||||
// Compute the center of the branch ...
|
||||
var totalPHeight = 0;
|
||||
var totalNHeight = 0;
|
||||
|
||||
heights.forEach(function(elem) {
|
||||
if (elem.order % 2 == 0) {
|
||||
totalPHeight += elem.height;
|
||||
} else {
|
||||
totalNHeight += elem.height;
|
||||
}
|
||||
});
|
||||
var psum = totalPHeight / 2;
|
||||
var nsum = totalNHeight / 2;
|
||||
var ysum = 0;
|
||||
|
||||
// Calculate the offsets ...
|
||||
var result = {};
|
||||
for (var i = 0; i < heights.length; i++) {
|
||||
var direction = heights[i].order % 2 ? -1 : 1;
|
||||
|
||||
if (direction > 0) {
|
||||
psum = psum - heights[i].height;
|
||||
ysum = psum;
|
||||
} else {
|
||||
nsum = nsum - heights[i].height;
|
||||
ysum = nsum;
|
||||
}
|
||||
|
||||
var yOffset = ysum + heights[i].height / 2;
|
||||
var xOffset = direction * (node.getSize().width/2 + heights[i].width/2 + + mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||
|
||||
$assert(!isNaN(xOffset), "xOffset can not be null");
|
||||
$assert(!isNaN(yOffset), "yOffset can not be null");
|
||||
|
||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
_getChildrenForSide: function(parent, graph, position) {
|
||||
position = position || {x: parent.getPosition().x + 1, y:parent.getPosition().y + 1};
|
||||
return graph.getChildren(parent).filter(function(child) {
|
||||
return position.x > 0 ? child.getPosition().x > 0 : child.getPosition().x < 0;
|
||||
});
|
||||
},
|
||||
|
||||
_getChildrenForOrder: function(parent, graph, order) {
|
||||
return this._getSortedChildren(graph, parent).filter(function(node) {
|
||||
return node.getOrder() % 2 == order % 2;
|
||||
});
|
||||
},
|
||||
|
||||
verify:function(treeSet, node) {
|
||||
// Check that all is consistent ...
|
||||
var children = this._getChildrenForOrder(node, treeSet, node.getOrder());
|
||||
|
||||
// All odd ordered nodes should be "continuous" by themselves
|
||||
// All even numbered nodes should be "continuous" by themselves
|
||||
var factor = node.getOrder() % 2 == 0 ? 2 : 1;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var order = i == 0 && factor == 1 ? 1 : (factor * i);
|
||||
$assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i*factor));
|
||||
}
|
||||
},
|
||||
|
||||
toString:function() {
|
||||
return "Balanced Sorter";
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.nlayout.BalancedSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||
mindplot.nlayout.BalancedSorter.INTERNODE_HORIZONTAL_PADDING = 30;
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.BaseLayoutManager = new Class({
|
||||
|
||||
options: {
|
||||
|
||||
},
|
||||
|
||||
initialize: function(designer, options) {
|
||||
this.setOptions(options);
|
||||
this._createBoard();
|
||||
this._designer = designer;
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeResizeEvent, this._nodeResizeEvent.bind(this));
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMoveEvent, this._nodeMoveEvent.bind(this));
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeDisconnectEvent, this._nodeDisconnectEvent.bind(this));
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeConnectEvent, this._nodeConnectEvent.bind(this));
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent, this._nodeRepositionateEvent.bind(this));
|
||||
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
|
||||
},
|
||||
|
||||
_nodeResizeEvent:function(node) {
|
||||
},
|
||||
|
||||
_nodeMoveEvent:function(node) {
|
||||
var modifiedTopics = [];
|
||||
this.getTopicBoardForTopic(node).updateChildrenPosition(node, modifiedTopics);
|
||||
},
|
||||
|
||||
_nodeDisconnectEvent:function(targetNode, node) {
|
||||
var modifiedTopics = [];
|
||||
this.getTopicBoardForTopic(targetNode).removeTopicFromBoard(node, modifiedTopics);
|
||||
},
|
||||
|
||||
_nodeConnectEvent:function(targetNode, node) {
|
||||
var modifiedTopics = [];
|
||||
this.getTopicBoardForTopic(targetNode).addBranch(node, modifiedTopics);
|
||||
},
|
||||
|
||||
_nodeRepositionateEvent:function(node) {
|
||||
var modifiedTopics = [];
|
||||
this.getTopicBoardForTopic(node).updateChildrenPosition(node, modifiedTopics);
|
||||
},
|
||||
|
||||
_nodeShrinkEvent:function(node) {
|
||||
},
|
||||
|
||||
_createBoard:function() {
|
||||
this._boards = new Hash();
|
||||
},
|
||||
getTopicBoardForTopic:function(node) {
|
||||
var id = node.getId();
|
||||
var result = this._boards[id];
|
||||
if (!$defined(result)) {
|
||||
result = this._addNode(node);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
_addNode:function(node) {
|
||||
var board = null;
|
||||
if (this._isCentralTopic(node))
|
||||
board = this._createCentralTopicBoard(node);
|
||||
else
|
||||
board = this._createMainTopicBoard(node);
|
||||
var id = node.getId();
|
||||
this._boards[id] = board;
|
||||
return board;
|
||||
},
|
||||
_createMainTopicBoard:function(node) {
|
||||
return new mindplot.layout.boards.Board(node, this);
|
||||
},
|
||||
_createCentralTopicBoard:function(node) {
|
||||
return new mindplot.layout.boards.Board(node, this);
|
||||
},
|
||||
prepareNode:function(node, children) {
|
||||
|
||||
},
|
||||
addHelpers:function(node) {
|
||||
|
||||
},
|
||||
needsPrepositioning:function() {
|
||||
return true;
|
||||
},
|
||||
getDesigner:function() {
|
||||
return this._designer;
|
||||
},
|
||||
_isCentralTopic:function(node) {
|
||||
var type = node.getModel().getType();
|
||||
return type == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE;
|
||||
},
|
||||
|
||||
getClassName:function() {
|
||||
return mindplot.layout.BaseLayoutManager.NAME;
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.BaseLayoutManager.NAME = "BaseLayoutManager";
|
||||
|
||||
mindplot.layout.BaseLayoutManager.implement(new Events);
|
||||
mindplot.layout.BaseLayoutManager.implement(new Options);
|
||||
53
mindplot/src/main/javascript/layout/ChangeEvent.js
Normal file
53
mindplot/src/main/javascript/layout/ChangeEvent.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.ChangeEvent = new Class({
|
||||
initialize:function(id) {
|
||||
$assert(!isNaN(id), "id can not be null");
|
||||
this._id = id;
|
||||
this._position = null;
|
||||
this._order = null;
|
||||
},
|
||||
|
||||
getId:function() {
|
||||
return this._id;
|
||||
},
|
||||
|
||||
getOrder: function() {
|
||||
return this._order;
|
||||
},
|
||||
|
||||
getPosition: function() {
|
||||
return this._position;
|
||||
},
|
||||
|
||||
setOrder: function(value) {
|
||||
$assert(!isNaN(value), "value can not be null");
|
||||
this._order = value;
|
||||
},
|
||||
|
||||
setPosition: function(value) {
|
||||
$assert(value, "value can not be null");
|
||||
this._position = value;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
return "[order:" + this.getOrder() + ", position: {" + this.getPosition().x + "," + this.getPosition().y + "}]";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.ChildrenSorterStrategy = new Class({
|
||||
initialize:function() {
|
||||
|
||||
},
|
||||
|
||||
computeChildrenIdByHeights: function(treeSet, node) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
computeOffsets:function(treeSet, node) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
insert: function(treeSet, parent, child, order) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
detach:function(treeSet, node) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
predict:function(treeSet, parent, position) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
verify:function(treeSet, node) {
|
||||
throw "Method must be implemented";
|
||||
},
|
||||
|
||||
toString:function() {
|
||||
throw "Method must be implemented: print name";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -15,20 +15,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.EventBus = new Class({
|
||||
Implements:Events,
|
||||
initialize: function() {
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.LayoutManagerFactory = {};
|
||||
mindplot.layout.LayoutManagerFactory.managers = {
|
||||
OriginalLayoutManager:mindplot.layout.OriginalLayoutManager,
|
||||
FreeMindLayoutManager:mindplot.layout.FreeMindLayoutManager
|
||||
};
|
||||
mindplot.layout.LayoutManagerFactory.getManagerByName = function(name) {
|
||||
var manager = mindplot.layout.LayoutManagerFactory.managers[name + "Manager"];
|
||||
if ($defined(manager)) {
|
||||
return manager;
|
||||
}
|
||||
else {
|
||||
return mindplot.layout.LayoutManagerFactory.managers["OriginalLayoutManager"];
|
||||
}
|
||||
mindplot.EventBus.events = {
|
||||
NodeResizeEvent:'NodeResizeEvent',
|
||||
NodeMoveEvent:'NodeMoveEvent',
|
||||
NodeRepositionateEvent:'NodeRepositionateEvent',
|
||||
NodeShrinkEvent:'NodeShrinkEvent',
|
||||
NodeConnectEvent:'NodeConnectEvent',
|
||||
NodeDisconnectEvent:'NodeDisconnectEvent',
|
||||
NodeAdded:'NodeAdded',
|
||||
NodeRemoved:'NodeRemoved',
|
||||
DoLayout:'DoLayout'
|
||||
};
|
||||
|
||||
|
||||
mindplot.EventBus.instance = new mindplot.EventBus();
|
||||
101
mindplot/src/main/javascript/layout/EventBusDispatcher.js
Normal file
101
mindplot/src/main/javascript/layout/EventBusDispatcher.js
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.EventBusDispatcher = new Class({
|
||||
|
||||
initialize:function(designerModel) {
|
||||
$assert(designerModel, "designerModel cannot be null");
|
||||
this.registerBusEvents();
|
||||
|
||||
var size = {width:25,height:25};
|
||||
this._layoutManager = new mindplot.nlayout.LayoutManager(0, size);
|
||||
|
||||
this._layoutManager.addEvent('change', function(event) {
|
||||
var id = event.getId();
|
||||
var topic = designerModel.findTopicById(id);
|
||||
console.log("Modify position to:" + id);
|
||||
|
||||
topic.setPosition(event.getPosition());
|
||||
topic.setOrder(event.getOrder());
|
||||
});
|
||||
},
|
||||
|
||||
registerBusEvents:function () {
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeAdded, this._nodeAdded.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRemoved, this._nodeRemoved.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeResizeEvent, this._nodeResizeEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMoveEvent, this._nodeMoveEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeDisconnectEvent, this._nodeDisconnectEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeConnectEvent, this._nodeConnectEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent, this._nodeRepositionateEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.DoLayout, this._doLayout.bind(this));
|
||||
},
|
||||
|
||||
_nodeResizeEvent: function(args) {
|
||||
this._layoutManager.updateNodeSize(args.node.getId(), args.size);
|
||||
},
|
||||
|
||||
_nodeMoveEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeMoveEvent: Not Implemented yet");
|
||||
|
||||
},
|
||||
|
||||
_nodeDisconnectEvent: function(node) {
|
||||
this._layoutManager.disconnectNode(node.getId());
|
||||
},
|
||||
|
||||
_nodeConnectEvent: function(args) {
|
||||
this._layoutManager.connectNode(args.parentNode.getId(), args.childNode.getId(), args.childNode.getOrder());
|
||||
|
||||
},
|
||||
|
||||
_nodeRepositionateEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeRepositionateEvent: Not Implemented yet");
|
||||
|
||||
},
|
||||
|
||||
_nodeShrinkEvent: function(node) {
|
||||
this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken());
|
||||
},
|
||||
|
||||
_nodeAdded: function(node) {
|
||||
// Centra topic must not be added twice ...
|
||||
if (node.getId() != 0) {
|
||||
this._layoutManager.addNode(node.getId(), {width:10,height:10}, node.getPosition());
|
||||
this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken());
|
||||
}
|
||||
},
|
||||
|
||||
_nodeRemoved: function(node) {
|
||||
this._layoutManager.removeNode(node.getId());
|
||||
},
|
||||
|
||||
_doLayout: function() {
|
||||
// (function() {
|
||||
this._layoutManager.layout(true);
|
||||
console.log("---------");
|
||||
this._layoutManager.dump();
|
||||
console.log("---------");
|
||||
// }).delay(0, this);
|
||||
},
|
||||
|
||||
getLayoutManager: function() {
|
||||
return this._layoutManager;
|
||||
}
|
||||
|
||||
});
|
||||
65
mindplot/src/main/javascript/layout/GridSorter.js
Normal file
65
mindplot/src/main/javascript/layout/GridSorter.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.GridSorter = new Class({
|
||||
Extends: mindplot.nlayout.AbstractBasicSorter,
|
||||
|
||||
computeOffsets: function(treeSet, node) {
|
||||
$assert(treeSet, "treeSet can no be null.");
|
||||
$assert(node, "node can no be null.");
|
||||
$assert("order can no be null.");
|
||||
|
||||
var children = this._getSortedChildren(treeSet, node);
|
||||
|
||||
// Compute heights ...
|
||||
var heights = children.map(function(child) {
|
||||
return {id:child.getId(),height:this._computeChildrenHeight(treeSet, child)};
|
||||
}.bind(this));
|
||||
|
||||
// Calculate the offsets ...
|
||||
var result = {};
|
||||
for (var i = 0; i < heights.length; i++) {
|
||||
var even = i%2 == 0 ? 1 : -1;
|
||||
|
||||
var zeroHeight = i == 0 ? 0 : heights[0].height/2 * even;
|
||||
var middleHeight = 0;
|
||||
for (var j=i-2; j>0; j=j-2) {
|
||||
middleHeight += heights[j].height * even;
|
||||
}
|
||||
var finalHeight = i == 0 ? 0 : heights[i].height/2 * even;
|
||||
|
||||
var yOffset = zeroHeight + middleHeight +finalHeight;
|
||||
var xOffset = node.getSize().width + mindplot.nlayout.GridSorter.GRID_HORIZONTAR_SIZE;
|
||||
|
||||
$assert(!isNaN(xOffset), "xOffset can not be null");
|
||||
$assert(!isNaN(yOffset), "yOffset can not be null");
|
||||
|
||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
||||
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
toString:function() {
|
||||
return "Grid Sorter";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mindplot.nlayout.GridSorter.GRID_HORIZONTAR_SIZE = 20;
|
||||
mindplot.nlayout.GridSorter.INTER_NODE_VERTICAL_DISTANCE = 50;
|
||||
|
||||
165
mindplot/src/main/javascript/layout/LayoutManager.js
Normal file
165
mindplot/src/main/javascript/layout/LayoutManager.js
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.LayoutManager = new Class({
|
||||
Extends: Events,
|
||||
initialize: function(rootNodeId, rootSize) {
|
||||
$assert($defined(rootNodeId), "rootNodeId can not be null");
|
||||
$assert(rootSize, "rootSize can not be null");
|
||||
|
||||
this._treeSet = new mindplot.nlayout.RootedTreeSet();
|
||||
this._layout = new mindplot.nlayout.OriginalLayout(this._treeSet);
|
||||
|
||||
var rootNode = this._layout.createNode(rootNodeId, rootSize, {x:0,y:0}, 'root');
|
||||
this._treeSet.setRoot(rootNode);
|
||||
this._events = [];
|
||||
},
|
||||
|
||||
updateNodeSize: function(id, size) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
|
||||
var node = this._treeSet.find(id);
|
||||
node.setSize(size);
|
||||
},
|
||||
|
||||
updateShrinkState: function(id, value) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
|
||||
var node = this._treeSet.find(id);
|
||||
node.setShrunken(value);
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
return this._treeSet.find(id);
|
||||
},
|
||||
|
||||
move: function() {
|
||||
//TODO(gb): implement
|
||||
},
|
||||
|
||||
connectNode: function(parentId, childId, order) {
|
||||
$assert($defined(parentId), "parentId can not be null");
|
||||
$assert($defined(childId), "childId can not be null");
|
||||
$assert($defined(order), "order can not be null");
|
||||
|
||||
this._layout.connectNode(parentId, childId, order);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
disconnectNode: function(id) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
this._layout.disconnectNode(id);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
addNode:function(id, size, position) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
var result = this._layout.createNode(id, size, position, 'topic');
|
||||
this._treeSet.add(result);
|
||||
},
|
||||
|
||||
removeNode: function(id) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
var node = this._treeSet.find(id);
|
||||
|
||||
// Is It connected ?
|
||||
if (this._treeSet.getParent(node)) {
|
||||
this.disconnectNode(id);
|
||||
}
|
||||
|
||||
// Remove the all the branch ...
|
||||
this._treeSet.remove(id);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
predict: function(parentId, position) {
|
||||
$assert($defined(parentId), "parentId can not be null");
|
||||
|
||||
var parent = this._treeSet.find(parentId);
|
||||
var sorter = parent.getSorter();
|
||||
var result = sorter.predict(parent, this._treeSet, position);
|
||||
return {order:result[0],position:result[1]};
|
||||
},
|
||||
|
||||
dump: function() {
|
||||
console.log(this._treeSet.dump());
|
||||
},
|
||||
|
||||
plot: function(containerId, size) {
|
||||
$assert(containerId, "containerId cannot be null");
|
||||
size = size || {width:200,height:200};
|
||||
var squaresize = 10;
|
||||
var canvas = Raphael(containerId, size.width, size.height);
|
||||
canvas.drawGrid(0, 0, size.width, size.height, size.width / squaresize, size.height / squaresize);
|
||||
this._treeSet.plot(canvas);
|
||||
|
||||
return canvas;
|
||||
},
|
||||
|
||||
layout: function(fireEvents) {
|
||||
// File repositioning ...
|
||||
this._layout.layout();
|
||||
|
||||
// Collect changes ...
|
||||
this._collectChanges();
|
||||
|
||||
if (!$(fireEvents) || fireEvents) {
|
||||
this._flushEvents();
|
||||
}
|
||||
},
|
||||
|
||||
_flushEvents: function() {
|
||||
this._events.forEach(function(event) {
|
||||
this.fireEvent('change', event);
|
||||
}, this);
|
||||
this._events = [];
|
||||
},
|
||||
|
||||
_collectChanges: function(nodes) {
|
||||
if (!nodes)
|
||||
nodes = this._treeSet.getTreeRoots();
|
||||
|
||||
nodes.forEach(function(node) {
|
||||
if (node.hasOrderChanged() || node.hasPositionChanged()) {
|
||||
|
||||
// Find or create a event ...
|
||||
var id = node.getId();
|
||||
var event = this._events.some(function(event) {
|
||||
return event.id == id;
|
||||
});
|
||||
if (!event) {
|
||||
event = new mindplot.nlayout.ChangeEvent(id);
|
||||
}
|
||||
|
||||
// Update nodes ...
|
||||
event.setOrder(node.getOrder());
|
||||
event.setPosition(node.getPosition());
|
||||
|
||||
node.resetPositionState();
|
||||
node.resetOrderState();
|
||||
this._events.push(event);
|
||||
}
|
||||
this._collectChanges(this._treeSet.getChildren(node));
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
138
mindplot/src/main/javascript/layout/Node.js
Normal file
138
mindplot/src/main/javascript/layout/Node.js
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.Node = new Class({
|
||||
initialize:function(id, size, position, sorter) {
|
||||
$assert(typeof id === 'number' && isFinite(id), "id can not be null");
|
||||
$assert(size, "size can not be null");
|
||||
$assert(position, "position can not be null");
|
||||
$assert(sorter, "sorter can not be null");
|
||||
|
||||
this._id = id;
|
||||
this._sorter = sorter;
|
||||
this._properties = {};
|
||||
|
||||
this.setSize(size);
|
||||
this.setPosition(position);
|
||||
this.setShrunken(false);
|
||||
},
|
||||
|
||||
getId:function() {
|
||||
return this._id;
|
||||
},
|
||||
|
||||
setShrunken: function(value) {
|
||||
this._setProperty('shrink', value);
|
||||
},
|
||||
|
||||
areChildrenShrunken: function() {
|
||||
return this._getProperty('shrink');
|
||||
},
|
||||
|
||||
setOrder: function(order) {
|
||||
$assert(typeof order === 'number' && isFinite(order), "Order can not be null. Value:" + order);
|
||||
this._setProperty('order', order);
|
||||
},
|
||||
|
||||
resetPositionState : function() {
|
||||
var prop = this._properties['position'];
|
||||
if (prop) {
|
||||
prop.hasChanged = false;
|
||||
}
|
||||
},
|
||||
|
||||
resetOrderState : function() {
|
||||
var prop = this._properties['order'];
|
||||
if (prop) {
|
||||
prop.hasChanged = false;
|
||||
}
|
||||
},
|
||||
|
||||
getOrder: function() {
|
||||
return this._getProperty('order');
|
||||
},
|
||||
|
||||
hasOrderChanged: function() {
|
||||
return this._isPropertyChanged('order');
|
||||
},
|
||||
|
||||
hasPositionChanged: function() {
|
||||
|
||||
return this._isPropertyChanged('position');
|
||||
},
|
||||
|
||||
getPosition: function() {
|
||||
return this._getProperty('position');
|
||||
},
|
||||
|
||||
setSize : function(size) {
|
||||
$assert($defined(size), "Size can not be null");
|
||||
this._setProperty('size', Object.clone(size));
|
||||
},
|
||||
|
||||
getSize: function() {
|
||||
return this._getProperty('size');
|
||||
},
|
||||
|
||||
setPosition : function(position) {
|
||||
$assert($defined(position), "Position can not be null");
|
||||
$assert($defined(position.x), "x can not be null");
|
||||
$assert($defined(position.y), "y can not be null");
|
||||
|
||||
this._setProperty('position', Object.clone(position));
|
||||
},
|
||||
|
||||
_setProperty: function(key, value) {
|
||||
var prop = this._properties[key];
|
||||
if (!prop) {
|
||||
prop = {
|
||||
hasChanged:false,
|
||||
value: null,
|
||||
oldValue : null
|
||||
};
|
||||
}
|
||||
|
||||
// Only update if the property has changed ...
|
||||
if (JSON.encode(prop.oldValue) != JSON.encode(value)) {
|
||||
prop.oldValue = prop.value;
|
||||
prop.value = value;
|
||||
prop.hasChanged = true;
|
||||
this._properties[key] = prop;
|
||||
}
|
||||
},
|
||||
|
||||
_getProperty: function(key) {
|
||||
var prop = this._properties[key];
|
||||
return $defined(prop) ? prop.value : null;
|
||||
},
|
||||
|
||||
_isPropertyChanged: function(key) {
|
||||
var prop = this._properties[key];
|
||||
return prop ? prop.hasChanged : false;
|
||||
},
|
||||
|
||||
getSorter: function() {
|
||||
return this._sorter;
|
||||
},
|
||||
|
||||
|
||||
toString: function() {
|
||||
return "[id:" + this.getId() + ", order:" + this.getOrder() + ", position: {" + this.getPosition().x + "," + this.getPosition().y + "}, size: {" + this.getSize().width + "," + this.getSize().height + "}";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
128
mindplot/src/main/javascript/layout/OriginalLayout.js
Normal file
128
mindplot/src/main/javascript/layout/OriginalLayout.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.OriginalLayout = new Class({
|
||||
initialize: function(treeSet) {
|
||||
this._treeSet = treeSet;
|
||||
},
|
||||
|
||||
createNode:function(id, size, position, type) {
|
||||
$assert($defined(id), "id can not be null");
|
||||
$assert(size, "size can not be null");
|
||||
$assert(position, "position can not be null");
|
||||
$assert(type, "type can not be null");
|
||||
|
||||
var strategy = type === 'root' ?
|
||||
mindplot.nlayout.OriginalLayout.BALANCED_SORTER :
|
||||
mindplot.nlayout.OriginalLayout.SYMMETRIC_SORTER;
|
||||
return new mindplot.nlayout.Node(id, size, position, strategy);
|
||||
},
|
||||
|
||||
connectNode: function(parentId, childId, order) {
|
||||
|
||||
var parent = this._treeSet.find(parentId);
|
||||
var child = this._treeSet.find(childId);
|
||||
|
||||
// Insert the new node ...
|
||||
var sorter = parent.getSorter();
|
||||
sorter.insert(this._treeSet, parent, child, order);
|
||||
|
||||
// Connect the new node ...
|
||||
this._treeSet.connect(parentId, childId);
|
||||
|
||||
// Fire a basic validation ...
|
||||
sorter.verify(this._treeSet, parent);
|
||||
},
|
||||
|
||||
disconnectNode: function(nodeId) {
|
||||
var node = this._treeSet.find(nodeId);
|
||||
var parent = this._treeSet.getParent(node);
|
||||
$assert(parent, "Node already disconnected");
|
||||
|
||||
// Remove from children list.
|
||||
var sorter = parent.getSorter();
|
||||
sorter.detach(this._treeSet, node);
|
||||
|
||||
// Disconnect the new node ...
|
||||
this._treeSet.disconnect(nodeId);
|
||||
|
||||
// Fire a basic validation ...
|
||||
sorter.verify(this._treeSet, node);
|
||||
},
|
||||
|
||||
layout: function() {
|
||||
var roots = this._treeSet.getTreeRoots();
|
||||
roots.forEach(function(node) {
|
||||
|
||||
// Calculate all node heights ...
|
||||
var sorter = node.getSorter();
|
||||
|
||||
// @Todo: This must not be implemented in this way.Each sorter could have different notion of heights ...
|
||||
var heightById = sorter.computeChildrenIdByHeights(this._treeSet, node);
|
||||
|
||||
this._layoutChildren(node, heightById);
|
||||
}, this);
|
||||
},
|
||||
|
||||
_layoutChildren: function(node, heightById) {
|
||||
|
||||
var nodeId = node.getId();
|
||||
var children = this._treeSet.getChildren(node);
|
||||
var parent = this._treeSet.getParent(node);
|
||||
var childrenOrderMoved = children.some(function(child) {
|
||||
return child.hasOrderChanged();
|
||||
});
|
||||
|
||||
// If ether any of the nodes has been changed of position or the height of the children is not
|
||||
// the same, children nodes must be repositioned ....
|
||||
var newBranchHeight = heightById[nodeId];
|
||||
|
||||
var parentHeightChanged = $defined(parent) ? parent._heightChanged : false;
|
||||
var heightChanged = node._branchHeight != newBranchHeight;
|
||||
node._heightChanged = heightChanged || parentHeightChanged;
|
||||
|
||||
if (childrenOrderMoved || heightChanged || parentHeightChanged) {
|
||||
var sorter = node.getSorter();
|
||||
var offsetById = sorter.computeOffsets(this._treeSet, node);
|
||||
var parentPosition = node.getPosition();
|
||||
|
||||
children.forEach(function(child) {
|
||||
var offset = offsetById[child.getId()];
|
||||
var parentX = parentPosition.x;
|
||||
var parentY = parentPosition.y;
|
||||
|
||||
var newPos = {x:parentX + offset.x,y:parentY + offset.y};
|
||||
|
||||
this._treeSet.updateBranchPosition(child, newPos);
|
||||
}.bind(this));
|
||||
|
||||
node._branchHeight = newBranchHeight;
|
||||
}
|
||||
|
||||
// Continue reordering the children nodes ...
|
||||
children.forEach(function(child) {
|
||||
this._layoutChildren(child, heightById);
|
||||
}, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mindplot.nlayout.OriginalLayout.SYMMETRIC_SORTER = new mindplot.nlayout.SymmetricSorter();
|
||||
mindplot.nlayout.OriginalLayout.BALANCED_SORTER = new mindplot.nlayout.BalancedSorter();
|
||||
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.OriginalLayoutManager = new Class({
|
||||
Extends:mindplot.layout.BaseLayoutManager,
|
||||
options:{
|
||||
|
||||
},
|
||||
initialize:function(designer, options) {
|
||||
this.parent(designer, options);
|
||||
|
||||
},
|
||||
|
||||
prepareNode:function(node, children) {
|
||||
// Sort children by order to solve adding order in for OriginalLayoutManager...
|
||||
var nodesByOrder = new Hash();
|
||||
var maxOrder = 0;
|
||||
var result = [];
|
||||
if (children.length > 0) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
var order = child.getOrder();
|
||||
if (!$defined(order)) {
|
||||
order = ++maxOrder;
|
||||
child.setOrder(order);
|
||||
}
|
||||
|
||||
if (nodesByOrder.has(order)) {
|
||||
if (Math.sign(child.getPosition().x) == Math.sign(nodesByOrder.get(order).getPosition().x)) {
|
||||
//duplicated order. Change order to next available.
|
||||
order = ++maxOrder;
|
||||
child.setOrder(order);
|
||||
}
|
||||
} else {
|
||||
nodesByOrder.set(order, child);
|
||||
if (order > maxOrder)
|
||||
maxOrder = order;
|
||||
}
|
||||
result[order] = child;
|
||||
}
|
||||
}
|
||||
nodesByOrder = null;
|
||||
return node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE ? result : children;
|
||||
},
|
||||
|
||||
_nodeResizeEvent:function(node) {
|
||||
|
||||
},
|
||||
|
||||
_nodeRepositionateEvent:function(node) {
|
||||
this.getTopicBoardForTopic(node).repositionate();
|
||||
},
|
||||
|
||||
getDragTopicPositioner : function() {
|
||||
return this._dragTopicPositioner;
|
||||
},
|
||||
|
||||
|
||||
|
||||
_createMainTopicBoard:function(node) {
|
||||
return new mindplot.layout.boards.original.MainTopicBoard(node, this);
|
||||
},
|
||||
|
||||
_createCentralTopicBoard:function(node) {
|
||||
return new mindplot.layout.boards.original.CentralTopicBoard(node, this);
|
||||
},
|
||||
|
||||
getClassName:function() {
|
||||
return mindplot.layout.OriginalLayoutManager.NAME;
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.OriginalLayoutManager.NAME = "OriginalLayoutManager";
|
||||
219
mindplot/src/main/javascript/layout/RootedTreeSet.js
Normal file
219
mindplot/src/main/javascript/layout/RootedTreeSet.js
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.RootedTreeSet = new Class({
|
||||
initialize:function() {
|
||||
this._rootNodes = [];
|
||||
},
|
||||
|
||||
setRoot:function(root) {
|
||||
$assert(root, 'root can not be null');
|
||||
this._rootNodes.push(this._decodate(root));
|
||||
},
|
||||
|
||||
getTreeRoots:function() {
|
||||
return this._rootNodes;
|
||||
},
|
||||
|
||||
_decodate:function(node) {
|
||||
node._children = [];
|
||||
return node;
|
||||
},
|
||||
|
||||
add: function(node) {
|
||||
$assert(node, 'node can not be null');
|
||||
$assert(!this.find(node.getId(), false), 'node already exits with this id. Id:' + node.getId());
|
||||
$assert(!node._children, 'node already added');
|
||||
this._rootNodes.push(this._decodate(node));
|
||||
},
|
||||
|
||||
|
||||
remove: function(nodeId) {
|
||||
$assert($defined(nodeId), 'nodeId can not be null');
|
||||
var node = this.find(nodeId);
|
||||
this._rootNodes.erase(node);
|
||||
},
|
||||
|
||||
connect: function(parentId, childId) {
|
||||
$assert($defined(parentId), 'parent can not be null');
|
||||
$assert($defined(childId), 'child can not be null');
|
||||
|
||||
var parent = this.find(parentId);
|
||||
var child = this.find(childId, true);
|
||||
$assert(!child._parent, 'node already connected. Id:' + child.getId() + ",previous:" + child._parent);
|
||||
|
||||
parent._children.push(child);
|
||||
child._parent = parent;
|
||||
this._rootNodes.erase(child);
|
||||
},
|
||||
|
||||
disconnect: function(nodeId) {
|
||||
$assert($defined(nodeId), 'nodeId can not be null');
|
||||
var node = this.find(nodeId);
|
||||
$assert(node._parent, "Node is not connected");
|
||||
|
||||
node._parent._children.erase(node);
|
||||
this._rootNodes.push(node);
|
||||
node._parent = null;
|
||||
},
|
||||
|
||||
find:function(id, validate) {
|
||||
$assert($defined(id), 'id can not be null');
|
||||
|
||||
var graphs = this._rootNodes;
|
||||
var result = null;
|
||||
for (var i = 0; i < graphs.length; i++) {
|
||||
var node = graphs[i];
|
||||
result = this._find(id, node);
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
validate = !$defined(validate) ? true : validate;
|
||||
$assert(validate ? result : true, 'node could not be found id:' + id);
|
||||
return result;
|
||||
|
||||
},
|
||||
|
||||
_find:function(id, parent) {
|
||||
if (parent.getId() == id) {
|
||||
return parent;
|
||||
|
||||
}
|
||||
|
||||
var result = null;
|
||||
var children = parent._children;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
result = this._find(id, child);
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
getChildren: function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
return node._children;
|
||||
},
|
||||
|
||||
getAncestors: function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
return this._getAncestors(this.getParent(node), []);
|
||||
},
|
||||
|
||||
_getAncestors: function(node, nodes) {
|
||||
var result = nodes;
|
||||
if (node) {
|
||||
result.push(node);
|
||||
this._getAncestors(this.getParent(node), result);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
getSiblings: function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
var siblings = node._parent._children;
|
||||
return siblings.erase(node);
|
||||
},
|
||||
|
||||
getParent:function(node) {
|
||||
$assert(node, 'node cannot be null');
|
||||
return node._parent;
|
||||
},
|
||||
|
||||
dump: function() {
|
||||
var branches = this._rootNodes;
|
||||
var result = "";
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
var branch = branches[i];
|
||||
result += this._dump(branch, "");
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
_dump:function(node, indent) {
|
||||
var result = indent + node + "\n";
|
||||
var children = this.getChildren(node);
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
result += this._dump(child, indent + " ");
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
plot: function(canvas) {
|
||||
var branches = this._rootNodes;
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
var branch = branches[i];
|
||||
this._plot(canvas, branch);
|
||||
}
|
||||
},
|
||||
|
||||
_plot: function(canvas, node, root) {
|
||||
var children = this.getChildren(node);
|
||||
var cx = node.getPosition().x + canvas.width / 2 - node.getSize().width / 2;
|
||||
var cy = node.getPosition().y + canvas.height / 2 - node.getSize().height / 2;
|
||||
var rect = canvas.rect(cx, cy, node.getSize().width, node.getSize().height);
|
||||
var order = node.getOrder() == null ? "r" : node.getOrder();
|
||||
var text = canvas.text(node.getPosition().x + canvas.width / 2, node.getPosition().y + canvas.height / 2, node.getId() + "[" + order + "]");
|
||||
text.attr('fill', '#FFF');
|
||||
var fillColor = this._rootNodes.contains(node) ? "#000" : "#c00";
|
||||
rect.attr('fill', fillColor);
|
||||
|
||||
rect.click(function() {
|
||||
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + node.getPosition().x + "," + node.getPosition().y + "), size:" + node.getSize().width + "x" + node.getSize().height + ", sorter:" + node.getSorter() +"]");
|
||||
});
|
||||
text.click(function() {
|
||||
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position:(" + node.getPosition().x + "," + node.getPosition().y + "), size:" + node.getSize().width + "x" + node.getSize().height + ", sorter:" + node.getSorter() +"]");
|
||||
});
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
this._plot(canvas, child);
|
||||
}
|
||||
},
|
||||
|
||||
updateBranchPosition : function(node, position) {
|
||||
|
||||
var oldPos = node.getPosition();
|
||||
node.setPosition(position);
|
||||
|
||||
var xOffset = oldPos.x - position.x;
|
||||
var yOffset = oldPos.y - position.y;
|
||||
|
||||
var children = this.getChildren(node);
|
||||
children.forEach(function(child) {
|
||||
this._shiftBranchPosition(child, xOffset, yOffset);
|
||||
}.bind(this));
|
||||
|
||||
},
|
||||
|
||||
_shiftBranchPosition : function(node, xOffset, yOffset) {
|
||||
var position = node.getPosition();
|
||||
node.setPosition({x:position.x + xOffset, y:position.y + yOffset});
|
||||
|
||||
var children = this.getChildren(node);
|
||||
children.forEach(function(child) {
|
||||
this._shiftBranchPosition(child, xOffset, yOffset);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
146
mindplot/src/main/javascript/layout/SymmetricSorter.js
Normal file
146
mindplot/src/main/javascript/layout/SymmetricSorter.js
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.SymmetricSorter = new Class({
|
||||
Extends: mindplot.nlayout.AbstractBasicSorter,
|
||||
initialize:function() {
|
||||
|
||||
},
|
||||
|
||||
predict : function(parent, graph, position) {
|
||||
var direction = parent.getPosition().x > 0 ? 1 : -1;
|
||||
|
||||
// No children...
|
||||
var children = graph.getChildren(parent);
|
||||
if (children.length == 0) {
|
||||
position = position || {x:parent.getPosition().x + direction, y:parent.getPosition().y};
|
||||
var position = {
|
||||
x: parent.getPosition().x + direction * (parent.getSize().width + mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING),
|
||||
y:parent.getPosition().y
|
||||
}
|
||||
return [0, position];
|
||||
}
|
||||
|
||||
// Try to fit within ...
|
||||
var result = null;
|
||||
var last = children.getLast();
|
||||
position = position || {x:last.getPosition().x + direction, y:last.getPosition().y + 1};
|
||||
children.each(function(child, index) {
|
||||
var cpos = child.getPosition();
|
||||
if (position.y > cpos.y) {
|
||||
yOffset = child == last ?
|
||||
child.getSize().height + mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2 :
|
||||
(children[index + 1].getPosition().y + children[index + 1].getSize().height/2 - child.getPosition().y)/2;
|
||||
result = [child.getOrder() + 1,{x:cpos.x, y:cpos.y + yOffset}];
|
||||
}
|
||||
});
|
||||
|
||||
// Position wasn't below any node, so it must be inserted above
|
||||
if (!result) {
|
||||
var first = children[0];
|
||||
result = [0, {
|
||||
x:first.getPosition().x,
|
||||
y:first.getPosition().y - first.getSize().height - mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING * 2
|
||||
}];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
insert: function(treeSet, parent, child, order) {
|
||||
var children = this._getSortedChildren(treeSet, parent);
|
||||
$assert(order <= children.length, "Order must be continues and can not have holes. Order:" + order);
|
||||
|
||||
// Shift all the elements in one .
|
||||
for (var i = order; i < children.length; i++) {
|
||||
var node = children[i];
|
||||
node.setOrder(i + 1);
|
||||
}
|
||||
child.setOrder(order);
|
||||
},
|
||||
|
||||
detach:function(treeSet, node) {
|
||||
var parent = treeSet.getParent(node);
|
||||
var children = this._getSortedChildren(treeSet, parent);
|
||||
var order = node.getOrder();
|
||||
$assert(children[order] === node, "Node seems not to be in the right position");
|
||||
|
||||
// Shift all the nodes ...
|
||||
for (var i = node.getOrder() + 1; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
child.setOrder(child.getOrder() - 1);
|
||||
}
|
||||
node.setOrder(0);
|
||||
},
|
||||
|
||||
computeOffsets:function(treeSet, node) {
|
||||
$assert(treeSet, "treeSet can no be null.");
|
||||
$assert(node, "node can no be null.");
|
||||
|
||||
var children = this._getSortedChildren(treeSet, node);
|
||||
|
||||
// Compute heights ...
|
||||
var heights = children.map(
|
||||
function(child) {
|
||||
return {id:child.getId(), order:child.getOrder(), position: child.getPosition(), width: child.getSize().width, height: this._computeChildrenHeight(treeSet, child)};
|
||||
}, this).reverse();
|
||||
|
||||
// Compute the center of the branch ...
|
||||
var totalHeight = 0;
|
||||
heights.forEach(function(elem) {
|
||||
totalHeight += elem.height;
|
||||
});
|
||||
var ysum = totalHeight / 2;
|
||||
|
||||
// Calculate the offsets ...
|
||||
var result = {};
|
||||
for (var i = 0; i < heights.length; i++) {
|
||||
ysum = ysum - heights[i].height;
|
||||
var parent = treeSet.getParent(treeSet.find(heights[i].id));
|
||||
|
||||
//TODO(gb): actually compare to branch's root node position
|
||||
var direction = parent.getPosition().x > 0 ? 1 : -1;
|
||||
|
||||
var yOffset = ysum + heights[i].height / 2;
|
||||
var xOffset = direction * (heights[i].width/2 + node.getSize().width/2 + mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING);
|
||||
|
||||
$assert(!isNaN(xOffset), "xOffset can not be null");
|
||||
$assert(!isNaN(yOffset), "yOffset can not be null");
|
||||
|
||||
result[heights[i].id] = {x:xOffset,y:yOffset};
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
verify:function(treeSet, node) {
|
||||
// Check that all is consistent ...
|
||||
var children = this._getSortedChildren(treeSet, node);
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
$assert(children[i].getOrder() == i, "missing order elements");
|
||||
}
|
||||
},
|
||||
|
||||
toString:function() {
|
||||
return "Symmetric Sorter";
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING = 5;
|
||||
mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING = 30;
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
mindplot.layout.boards.Board = new Class({
|
||||
Implements: [Events,Options],
|
||||
options: {
|
||||
|
||||
},
|
||||
initialize: function(node, layoutManager, options) {
|
||||
this.setOptions(options);
|
||||
this._node = node;
|
||||
this._layoutManager = layoutManager;
|
||||
},
|
||||
getClassName:function() {
|
||||
return mindplot.layout.boards.Board.NAME;
|
||||
},
|
||||
removeTopicFromBoard:function(node, modifiedTopics) {
|
||||
$assert(false, "no Board implementation found!");
|
||||
},
|
||||
addBranch:function(node, modifiedTopics) {
|
||||
$assert(false, "no Board implementation found!");
|
||||
},
|
||||
updateChildrenPosition:function(node, modifiedTopics) {
|
||||
$assert(false, "no Board implementation found!");
|
||||
},
|
||||
setNodeMarginTop:function(node, delta) {
|
||||
$assert(false, "no Board implementation found!");
|
||||
},
|
||||
getNode:function() {
|
||||
return this._node;
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.boards.Board.NAME = "Board";
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.Board = new Class({
|
||||
initialize : function(defaultHeight, referencePoint) {
|
||||
$assert(referencePoint, "referencePoint can not be null");
|
||||
this._defaultWidth = defaultHeight;
|
||||
this._entries = new mindplot.layout.boards.original.BidirectionalArray();
|
||||
this._referencePoint = referencePoint;
|
||||
},
|
||||
|
||||
getReferencePoint : function() {
|
||||
return this._referencePoint;
|
||||
},
|
||||
|
||||
_removeEntryByOrder : function(order, position) {
|
||||
var board = this._getBoard(position);
|
||||
var entry = board.lookupEntryByOrder(order);
|
||||
|
||||
$assert(!entry.isAvailable(), 'Entry must not be available in order to be removed.Entry Order:' + order);
|
||||
entry.removeTopic();
|
||||
board.update(entry);
|
||||
},
|
||||
|
||||
removeTopicFromBoard : function(topic) {
|
||||
var position = topic.getPosition();
|
||||
var order = topic.getOrder();
|
||||
|
||||
this._removeEntryByOrder(order, position);
|
||||
topic.setOrder(null);
|
||||
},
|
||||
|
||||
positionateDragTopic :function(dragTopic) {
|
||||
throw "this method must be overrided";
|
||||
},
|
||||
|
||||
getHeight: function() {
|
||||
var board = this._getBoard();
|
||||
return board.getHeight();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* ---------------------------------------
|
||||
*/
|
||||
mindplot.layout.boards.original.BidirectionalArray = new Class({
|
||||
|
||||
initialize: function() {
|
||||
this._leftElem = [];
|
||||
this._rightElem = [];
|
||||
},
|
||||
|
||||
get :function(index, sign) {
|
||||
$assert($defined(index), 'Illegal argument, index must be passed.');
|
||||
if ($defined(sign)) {
|
||||
$assert(index >= 0, 'Illegal absIndex value');
|
||||
index = index * sign;
|
||||
}
|
||||
|
||||
var result = null;
|
||||
if (index >= 0 && index < this._rightElem.length) {
|
||||
result = this._rightElem[index];
|
||||
} else if (index < 0 && Math.abs(index) < this._leftElem.length) {
|
||||
result = this._leftElem[Math.abs(index)];
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
set : function(index, elem) {
|
||||
$assert($defined(index), 'Illegal index value');
|
||||
|
||||
var array = (index >= 0) ? this._rightElem : this._leftElem;
|
||||
array[Math.abs(index)] = elem;
|
||||
},
|
||||
|
||||
length : function(index) {
|
||||
$assert($defined(index), 'Illegal index value');
|
||||
return (index >= 0) ? this._rightElem.length : this._leftElem.length;
|
||||
},
|
||||
|
||||
upperLength : function() {
|
||||
return this.length(1);
|
||||
},
|
||||
|
||||
lowerLength : function() {
|
||||
return this.length(-1);
|
||||
},
|
||||
|
||||
inspect : function() {
|
||||
var result = '{';
|
||||
var lenght = this._leftElem.length;
|
||||
for (var i = 0; i < lenght; i++) {
|
||||
var entry = this._leftElem[lenght - i - 1];
|
||||
if (entry != null) {
|
||||
if (i != 0) {
|
||||
result += ', ';
|
||||
}
|
||||
result += entry.inspect();
|
||||
}
|
||||
}
|
||||
|
||||
lenght = this._rightElem.length;
|
||||
for (var i = 0; i < lenght; i++) {
|
||||
var entry = this._rightElem[i];
|
||||
if (entry != null) {
|
||||
if (i != 0) {
|
||||
result += ', ';
|
||||
}
|
||||
result += entry.inspect();
|
||||
}
|
||||
}
|
||||
result += '}';
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
});
|
||||
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.BoardEntry = new Class({
|
||||
initialize:function(lowerLimit, upperLimit, order) {
|
||||
if ($defined(lowerLimit) && $defined(upperLimit)) {
|
||||
$assert(lowerLimit < upperLimit, 'lowerLimit can not be greater that upperLimit');
|
||||
}
|
||||
this._upperLimit = upperLimit;
|
||||
this._lowerLimit = lowerLimit;
|
||||
this._order = order;
|
||||
this._topic = null;
|
||||
this._xPos = null;
|
||||
},
|
||||
|
||||
|
||||
getUpperLimit : function() {
|
||||
return this._upperLimit;
|
||||
},
|
||||
|
||||
setXPosition : function(xPosition) {
|
||||
this._xPos = xPosition;
|
||||
},
|
||||
|
||||
workoutEntryYCenter : function() {
|
||||
return this._lowerLimit + ((this._upperLimit - this._lowerLimit) / 2);
|
||||
},
|
||||
|
||||
setUpperLimit : function(value) {
|
||||
$assert(!isNaN(value), "upper limit can not be null");
|
||||
$assert(!isNaN(value), "illegal value");
|
||||
this._upperLimit = value;
|
||||
},
|
||||
|
||||
isCoordinateIn : function(coord) {
|
||||
return this._lowerLimit <= coord && coord < this._upperLimit;
|
||||
},
|
||||
|
||||
getLowerLimit : function() {
|
||||
return this._lowerLimit;
|
||||
},
|
||||
|
||||
setLowerLimit : function(value) {
|
||||
$assert(!isNaN(value), "upper limit can not be null");
|
||||
$assert(!isNaN(value), "illegal value");
|
||||
this._lowerLimit = value;
|
||||
},
|
||||
|
||||
setOrder : function(value) {
|
||||
this._order = value;
|
||||
},
|
||||
|
||||
getWidth : function() {
|
||||
return Math.abs(this._upperLimit - this._lowerLimit);
|
||||
},
|
||||
|
||||
|
||||
getTopic : function() {
|
||||
return this._topic;
|
||||
},
|
||||
|
||||
|
||||
removeTopic : function() {
|
||||
$assert(!this.isAvailable(), "Entry doesn't have a topic.");
|
||||
var topic = this.getTopic();
|
||||
this.setTopic(null);
|
||||
topic.setOrder(null);
|
||||
},
|
||||
|
||||
|
||||
update : function() {
|
||||
var topic = this.getTopic();
|
||||
this.setTopic(topic);
|
||||
},
|
||||
|
||||
setTopic : function(topic, updatePosition) {
|
||||
if (!$defined(updatePosition) || ($defined(updatePosition) && !updatePosition)) {
|
||||
updatePosition = true;
|
||||
}
|
||||
|
||||
this._topic = topic;
|
||||
if ($defined(topic)) {
|
||||
// Fixed positioning. Only for main topic ...
|
||||
var position = null;
|
||||
var topicPosition = topic.getPosition();
|
||||
|
||||
// Must update position base on the border limits?
|
||||
if ($defined(this._xPos)) {
|
||||
position = new core.Point();
|
||||
|
||||
// Update x position ...
|
||||
var topicSize = topic.getSize();
|
||||
var halfTopicWidh = parseInt(topicSize.width / 2);
|
||||
halfTopicWidh = (this._xPos > 0) ? halfTopicWidh : -halfTopicWidh;
|
||||
position.x = this._xPos + halfTopicWidh;
|
||||
position.y = this.workoutEntryYCenter();
|
||||
} else {
|
||||
|
||||
// Central topic
|
||||
this._height = topic.getSize().height;
|
||||
var xPos = topicPosition.x;
|
||||
var yPos = this.workoutEntryYCenter();
|
||||
position = new core.Point(xPos, yPos);
|
||||
}
|
||||
|
||||
// @todo: No esta de mas...
|
||||
topic.setPosition(position);
|
||||
topic.setOrder(this._order);
|
||||
}
|
||||
else {
|
||||
this._height = this._defaultWidth;
|
||||
}
|
||||
},
|
||||
|
||||
isAvailable : function() {
|
||||
return !$defined(this._topic);
|
||||
},
|
||||
|
||||
getOrder : function() {
|
||||
return this._order;
|
||||
},
|
||||
|
||||
inspect : function() {
|
||||
return '(order: ' + this._order + ', lowerLimit:' + this._lowerLimit + ', upperLimit: ' + this._upperLimit + ', available:' + this.isAvailable() + ')';
|
||||
}
|
||||
});
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.CentralTopicBoard = new Class({
|
||||
Extends:mindplot.layout.boards.original.Board,
|
||||
initialize:function(centralTopic, layoutManager) {
|
||||
var point = new core.Point(0, 0);
|
||||
this._layoutManager = layoutManager;
|
||||
this._rightBoard = new mindplot.layout.boards.original.VariableDistanceBoard(50, point);
|
||||
this._leftBoard = new mindplot.layout.boards.original.VariableDistanceBoard(50, point);
|
||||
this._centralTopic = centralTopic;
|
||||
},
|
||||
|
||||
_getBoard : function(position) {
|
||||
return (position.x >= 0) ? this._rightBoard : this._leftBoard;
|
||||
},
|
||||
|
||||
positionateDragTopic : function(dragTopic) {
|
||||
$assert(dragTopic != null, 'dragTopic can not be null');
|
||||
$assert(dragTopic.isDragTopic, 'dragTopic must be DragTopic instance');
|
||||
|
||||
// This node is a main topic node. Position
|
||||
var dragPos = dragTopic.getPosition();
|
||||
var board = this._getBoard(dragPos);
|
||||
|
||||
// Look for entry ...
|
||||
var entry = board.lookupEntryByPosition(dragPos);
|
||||
|
||||
// Calculate 'y' position base on the entry ...
|
||||
var yCoord;
|
||||
if (!entry.isAvailable() && entry.getTopic() != dragTopic.getDraggedTopic()) {
|
||||
yCoord = entry.getLowerLimit();
|
||||
} else {
|
||||
yCoord = entry.workoutEntryYCenter();
|
||||
}
|
||||
|
||||
|
||||
// MainTopic can not be positioned over the drag topic ...
|
||||
var centralTopic = this._centralTopic;
|
||||
var centralTopicSize = centralTopic.getSize();
|
||||
var halfWidth = (centralTopicSize.width / 2);
|
||||
if (Math.abs(dragPos.x) < halfWidth + 60) {
|
||||
var distance = halfWidth + 60;
|
||||
dragPos.x = (dragPos.x > 0) ? distance : -distance;
|
||||
}
|
||||
|
||||
// Update board position.
|
||||
var pivotPos = new core.Point(dragPos.x, yCoord);
|
||||
dragTopic.setBoardPosition(pivotPos);
|
||||
},
|
||||
|
||||
|
||||
addBranch : function(topic) {
|
||||
// Update topic position ...
|
||||
var position = topic.getPosition();
|
||||
|
||||
var order = topic.getOrder();
|
||||
var board = this._getBoard(position);
|
||||
var entry = null;
|
||||
if (order != null) {
|
||||
entry = board.lookupEntryByOrder(order);
|
||||
} else {
|
||||
entry = board.lookupEntryByPosition(position);
|
||||
}
|
||||
|
||||
// If the entry is not available, I must swap the the entries...
|
||||
if (!entry.isAvailable()) {
|
||||
board.freeEntry(entry);
|
||||
}
|
||||
|
||||
// Add it to the board ...
|
||||
entry.setTopic(topic);
|
||||
board.update(entry);
|
||||
},
|
||||
|
||||
updateChildrenPosition : function(topic, xOffset, modifiedTopics) {
|
||||
var board = this._rightBoard;
|
||||
var oldReferencePosition = board.getReferencePoint();
|
||||
var newReferencePosition = new core.Point(oldReferencePosition.x + xOffset, oldReferencePosition.y);
|
||||
board.updateReferencePoint(newReferencePosition);
|
||||
|
||||
board = this._leftBoard;
|
||||
oldReferencePosition = board.getReferencePoint();
|
||||
newReferencePosition = new core.Point(oldReferencePosition.x - xOffset, oldReferencePosition.y);
|
||||
board.updateReferencePoint(newReferencePosition);
|
||||
},
|
||||
|
||||
repositionate : function() {
|
||||
//@todo: implement ..
|
||||
}
|
||||
});
|
||||
@@ -1,286 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.FixedDistanceBoard = new Class({
|
||||
Extends:mindplot.layout.boards.original.Board,
|
||||
initialize:function(defaultHeight, topic, layoutManager) {
|
||||
this._topic = topic;
|
||||
this._layoutManager = layoutManager;
|
||||
var reference = topic.getPosition();
|
||||
this.parent(defaultHeight, reference);
|
||||
this._height = defaultHeight;
|
||||
this._entries = [];
|
||||
},
|
||||
|
||||
getHeight : function() {
|
||||
return this._height;
|
||||
},
|
||||
|
||||
lookupEntryByOrder : function(order) {
|
||||
var result = null;
|
||||
var entries = this._entries;
|
||||
if (order < entries.length) {
|
||||
result = entries[order];
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
var defaultHeight = this._defaultWidth;
|
||||
var reference = this.getReferencePoint();
|
||||
if (entries.length == 0) {
|
||||
var yReference = reference.y;
|
||||
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
|
||||
} else {
|
||||
var entriesLenght = entries.length;
|
||||
var lastEntry = entries[entriesLenght - 1];
|
||||
var lowerLimit = lastEntry.getUpperLimit();
|
||||
var upperLimit = lowerLimit + defaultHeight;
|
||||
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
createBoardEntry : function(lowerLimit, upperLimit, order) {
|
||||
var result = new mindplot.layout.boards.original.BoardEntry(lowerLimit, upperLimit, order);
|
||||
var xPos = this.workoutXBorderDistance();
|
||||
result.setXPosition(xPos);
|
||||
return result;
|
||||
},
|
||||
|
||||
updateReferencePoint : function() {
|
||||
var entries = this._entries;
|
||||
var parentTopic = this.getTopic();
|
||||
var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition());
|
||||
var referencePoint = this.getReferencePoint();
|
||||
var yOffset = parentPosition.y - referencePoint.y;
|
||||
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i];
|
||||
|
||||
if ($defined(entry)) {
|
||||
var upperLimit = entry.getUpperLimit() + yOffset;
|
||||
var lowerLimit = entry.getLowerLimit() + yOffset;
|
||||
entry.setUpperLimit(upperLimit);
|
||||
entry.setLowerLimit(lowerLimit);
|
||||
|
||||
// Fix x position ...
|
||||
var xPos = this.workoutXBorderDistance();
|
||||
entry.setXPosition(xPos);
|
||||
entry.update();
|
||||
}
|
||||
}
|
||||
this._referencePoint = parentPosition.clone();
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This x distance doesn't take into account the size of the shape.
|
||||
*/
|
||||
workoutXBorderDistance : function() {
|
||||
var topic = this.getTopic();
|
||||
|
||||
var topicPosition = topic.getPosition();
|
||||
var topicSize = topic.getSize();
|
||||
var halfTargetWidth = topicSize.width / 2;
|
||||
var result;
|
||||
if (topicPosition.x >= 0) {
|
||||
// It's at right.
|
||||
result = topicPosition.x + halfTargetWidth + mindplot.layout.boards.original.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE;
|
||||
} else {
|
||||
result = topicPosition.x - (halfTargetWidth + mindplot.layout.boards.original.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
getTopic : function() {
|
||||
return this._topic;
|
||||
},
|
||||
|
||||
freeEntry : function(entry) {
|
||||
var newEntries = [];
|
||||
var entries = this._entries;
|
||||
var order = 0;
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i];
|
||||
if (e == entry) {
|
||||
order++;
|
||||
}
|
||||
newEntries[order] = e;
|
||||
order++;
|
||||
}
|
||||
this._entries = newEntries;
|
||||
},
|
||||
|
||||
repositionate : function() {
|
||||
// Workout width and update topic height.
|
||||
var entries = this._entries;
|
||||
var height = 0;
|
||||
var model = this._topic.getModel();
|
||||
if (entries.length >= 1 && !model.areChildrenShrunken()) {
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i];
|
||||
if (e && e.getTopic()) {
|
||||
var topic = e.getTopic();
|
||||
var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
|
||||
var topicBoardHeight = topicBoard.getHeight();
|
||||
|
||||
|
||||
height += topicBoardHeight + mindplot.layout.boards.original.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var topic = this._topic;
|
||||
height = topic.getSize().height + mindplot.layout.boards.original.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
|
||||
}
|
||||
|
||||
var oldHeight = this._height;
|
||||
this._height = height;
|
||||
|
||||
// I must update all the parent nodes first...
|
||||
if (oldHeight != this._height) {
|
||||
var topic = this._topic;
|
||||
var parentTopic = topic.getParent();
|
||||
if (parentTopic != null) {
|
||||
var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
|
||||
board.repositionate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Workout center the new topic center...
|
||||
var refence = this.getReferencePoint();
|
||||
var lowerLimit;
|
||||
if (entries.length > 0) {
|
||||
var l = 0;
|
||||
for (l = 0; l < entries.length; l++) {
|
||||
if ($defined(entries[l]))
|
||||
break;
|
||||
}
|
||||
var topic = entries[l].getTopic();
|
||||
var firstNodeHeight = topic.getSize().height;
|
||||
lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1;
|
||||
}
|
||||
|
||||
var upperLimit = null;
|
||||
|
||||
// Start moving all the elements ...
|
||||
var newEntries = [];
|
||||
var order = 0;
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i];
|
||||
if (e && e.getTopic()) {
|
||||
|
||||
var currentTopic = e.getTopic();
|
||||
e.setLowerLimit(lowerLimit);
|
||||
|
||||
// Update entry ...
|
||||
var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
|
||||
var topicBoardHeight = topicBoard.getHeight();
|
||||
|
||||
upperLimit = lowerLimit + topicBoardHeight + mindplot.layout.boards.original.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
|
||||
e.setUpperLimit(upperLimit);
|
||||
lowerLimit = upperLimit;
|
||||
|
||||
e.setOrder(order);
|
||||
currentTopic.setOrder(order);
|
||||
|
||||
e.update();
|
||||
newEntries[order] = e;
|
||||
order++;
|
||||
}
|
||||
}
|
||||
this._entries = newEntries;
|
||||
},
|
||||
|
||||
removeTopic : function(topic) {
|
||||
var order = topic.getOrder();
|
||||
var entry = this.lookupEntryByOrder(order);
|
||||
$assert(!entry.isAvailable(), "Illegal state");
|
||||
|
||||
entry.setTopic(null);
|
||||
topic.setOrder(null);
|
||||
this._entries.erase(entry);
|
||||
|
||||
// Repositionate all elements ...
|
||||
this.repositionate();
|
||||
},
|
||||
|
||||
addTopic : function(order, topic) {
|
||||
|
||||
// If the entry is not available, I must swap the the entries...
|
||||
var entry = this.lookupEntryByOrder(order);
|
||||
if (!entry.isAvailable()) {
|
||||
this.freeEntry(entry);
|
||||
// Create a dummy entry ...
|
||||
// Puaj, do something with this...
|
||||
entry = this.createBoardEntry(-1, 0, order);
|
||||
this._entries[order] = entry;
|
||||
}
|
||||
this._entries[order] = entry;
|
||||
|
||||
// Add to the board ...
|
||||
entry.setTopic(topic, false);
|
||||
|
||||
// Repositionate all elements ...
|
||||
this.repositionate();
|
||||
},
|
||||
|
||||
lookupEntryByPosition : function(pos) {
|
||||
$assert(pos, 'position can not be null');
|
||||
|
||||
var entries = this._entries;
|
||||
var result = null;
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var entry = entries[i];
|
||||
if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) {
|
||||
result = entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
var defaultHeight = this._defaultWidth;
|
||||
if (entries.length == 0) {
|
||||
var reference = this.getReferencePoint();
|
||||
var yReference = reference.y;
|
||||
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
|
||||
} else {
|
||||
var firstEntry = entries[0];
|
||||
if (pos.y < firstEntry.getLowerLimit()) {
|
||||
var upperLimit = firstEntry.getLowerLimit();
|
||||
var lowerLimit = upperLimit - defaultHeight;
|
||||
result = this.createBoardEntry(lowerLimit, upperLimit, 0);
|
||||
} else {
|
||||
var entriesLenght = entries.length;
|
||||
var lastEntry = entries[entriesLenght - 1];
|
||||
var lowerLimit = lastEntry.getUpperLimit();
|
||||
var upperLimit = lowerLimit + defaultHeight;
|
||||
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.boards.original.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60;
|
||||
mindplot.layout.boards.original.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6;
|
||||
|
||||
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.MainTopicBoard = new Class({
|
||||
Extends:mindplot.layout.boards.original.Board,
|
||||
initialize:function(topic, layoutManager) {
|
||||
this._layoutManager = layoutManager;
|
||||
this._topic = topic;
|
||||
this._board = null;
|
||||
this._height = 0;
|
||||
},
|
||||
|
||||
|
||||
_getBoard: function() {
|
||||
if (!$defined(this._board)) {
|
||||
var topic = this._topic;
|
||||
this._board = new mindplot.layout.boards.original.FixedDistanceBoard(mindplot.MainTopic.DEFAULT_MAIN_TOPIC_HEIGHT, topic, this._layoutManager);
|
||||
}
|
||||
return this._board;
|
||||
},
|
||||
|
||||
updateReferencePoint : function(position) {
|
||||
this._board.updateReferencePoint(position);
|
||||
},
|
||||
|
||||
updateChildrenPosition : function(topic) {
|
||||
var board = this._getBoard();
|
||||
board.updateReferencePoint();
|
||||
},
|
||||
|
||||
positionateDragTopic : function(dragTopic) {
|
||||
$assert(dragTopic != null, 'dragTopic can not be null');
|
||||
$assert(dragTopic.isDragTopic, 'dragTopic must be DragTopic instance');
|
||||
|
||||
// This node is a main topic node. Position
|
||||
var dragPos = dragTopic.getPosition();
|
||||
var board = this._getBoard();
|
||||
|
||||
// Look for entry ...
|
||||
var entry = board.lookupEntryByPosition(dragPos);
|
||||
|
||||
// Calculate 'y' position base on the entry ...
|
||||
var yCoord;
|
||||
if (!entry.isAvailable() && entry.getTopic() != dragTopic.getDraggedTopic()) {
|
||||
yCoord = entry.getLowerLimit();
|
||||
} else {
|
||||
yCoord = entry.workoutEntryYCenter();
|
||||
}
|
||||
|
||||
// Update board position.
|
||||
var targetTopic = dragTopic.getConnectedToTopic();
|
||||
var xCoord = this._workoutXBorderDistance(targetTopic);
|
||||
|
||||
// Add the size of the pivot to the distance ...
|
||||
var halfPivotWidth = mindplot.DragTopic.PIVOT_SIZE.width / 2;
|
||||
xCoord = xCoord + ((dragPos.x > 0) ? halfPivotWidth : -halfPivotWidth);
|
||||
|
||||
var pivotPos = new core.Point(xCoord, yCoord);
|
||||
dragTopic.setBoardPosition(pivotPos);
|
||||
|
||||
var order = entry.getOrder();
|
||||
dragTopic.setOrder(order);
|
||||
},
|
||||
|
||||
/**
|
||||
* This x distance doesn't take into account the size of the shape.
|
||||
*/
|
||||
_workoutXBorderDistance : function(topic) {
|
||||
$assert(topic, 'topic can not be null');
|
||||
var board = this._getBoard();
|
||||
return board.workoutXBorderDistance(topic);
|
||||
},
|
||||
|
||||
addBranch : function(topic) {
|
||||
var order = topic.getOrder();
|
||||
$assert($defined(order), "Order must be defined");
|
||||
|
||||
// If the entry is not available, I must swap the the entries...
|
||||
var board = this._getBoard();
|
||||
var entry = board.lookupEntryByOrder(order);
|
||||
if (!entry.isAvailable()) {
|
||||
board.freeEntry(entry);
|
||||
}
|
||||
|
||||
// Add the topic to the board ...
|
||||
board.addTopic(order, topic);
|
||||
|
||||
// Repositionate all the parent topics ...
|
||||
var currentTopic = this._topic;
|
||||
if (currentTopic.getOutgoingConnectedTopic()) {
|
||||
var parentTopic = currentTopic.getOutgoingConnectedTopic();
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [parentTopic]);
|
||||
}
|
||||
},
|
||||
|
||||
repositionate : function() {
|
||||
var board = this._getBoard();
|
||||
board.repositionate();
|
||||
},
|
||||
|
||||
removeTopicFromBoard : function(topic) {
|
||||
var board = this._getBoard();
|
||||
board.removeTopic(topic);
|
||||
|
||||
// Repositionate all the parent topics ...
|
||||
var parentTopic = this._topic;
|
||||
if (parentTopic.getOutgoingConnectedTopic()) {
|
||||
var connectedTopic = parentTopic.getOutgoingConnectedTopic();
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [connectedTopic]);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.boards.original.VariableDistanceBoard = new Class({
|
||||
Extends: mindplot.layout.boards.original.Board,
|
||||
initialize: function(defaultHeight, referencePoint) {
|
||||
this.parent(defaultHeight, referencePoint);
|
||||
var zeroEntryCoordinate = referencePoint.y;
|
||||
var entry = this.createBoardEntry(zeroEntryCoordinate - (defaultHeight / 2), zeroEntryCoordinate + (defaultHeight / 2), 0);
|
||||
this._entries.set(0, entry);
|
||||
},
|
||||
|
||||
lookupEntryByOrder:function(order) {
|
||||
var entries = this._entries;
|
||||
var index = this._orderToIndex(order);
|
||||
|
||||
var result = entries.get(index);
|
||||
if (!$defined(result)) {
|
||||
// I've not found a entry. I have to create a new one.
|
||||
var i = 1;
|
||||
var zeroEntry = entries.get(0);
|
||||
var distance = zeroEntry.getWidth() / 2;
|
||||
var indexSign = Math.sign(index);
|
||||
var absIndex = Math.abs(index);
|
||||
while (i < absIndex) {
|
||||
// Move to the next entry ...
|
||||
var entry = entries.get(i, indexSign);
|
||||
if (entry != null) {
|
||||
distance += entry.getWidth();
|
||||
} else {
|
||||
distance += this._defaultWidth;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// Calculate limits ...
|
||||
var upperLimit = -1;
|
||||
var lowerLimit = -1;
|
||||
var offset = zeroEntry.workoutEntryYCenter();
|
||||
if (index >= 0) {
|
||||
lowerLimit = offset + distance;
|
||||
upperLimit = lowerLimit + this._defaultWidth;
|
||||
} else {
|
||||
upperLimit = offset - distance;
|
||||
lowerLimit = upperLimit - this._defaultWidth;
|
||||
}
|
||||
|
||||
result = this.createBoardEntry(lowerLimit, upperLimit, order);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
createBoardEntry:function(lowerLimit, upperLimit, order) {
|
||||
return new mindplot.layout.boards.original.BoardEntry(lowerLimit, upperLimit, order);
|
||||
},
|
||||
|
||||
updateReferencePoint:function(position) {
|
||||
var entries = this._entries;
|
||||
var referencePoint = this._referencePoint;
|
||||
|
||||
// Update zero entry current position.
|
||||
this._referencePoint = position.clone();
|
||||
var yOffset = position.y - referencePoint.y;
|
||||
|
||||
var i = -entries.lowerLength();
|
||||
for (; i <= entries.length(1); i++) {
|
||||
var entry = entries.get(i);
|
||||
if (entry != null) {
|
||||
var upperLimit = entry.getUpperLimit() + yOffset;
|
||||
var lowerLimit = entry.getLowerLimit() + yOffset;
|
||||
entry.setUpperLimit(upperLimit);
|
||||
entry.setLowerLimit(lowerLimit);
|
||||
|
||||
// Update topic position ...
|
||||
if (!entry.isAvailable()) {
|
||||
var topic = entry.getTopic();
|
||||
var topicPosition = topic.getPosition();
|
||||
topicPosition.y = topicPosition.y + yOffset;
|
||||
|
||||
// MainTopicToCentral must be positioned based on the referencePoint.
|
||||
var xOffset = position.x - referencePoint.x;
|
||||
topicPosition.x = topicPosition.x + xOffset;
|
||||
|
||||
topic.setPosition(topicPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
lookupEntryByPosition:function(pos) {
|
||||
$assert(pos, 'position can not be null');
|
||||
var entries = this._entries;
|
||||
var zeroEntry = entries.get(0);
|
||||
if (zeroEntry.isCoordinateIn(pos.y)) {
|
||||
return zeroEntry;
|
||||
}
|
||||
|
||||
// Is Upper or lower ?
|
||||
var sign = -1;
|
||||
if (pos.y >= zeroEntry.getUpperLimit()) {
|
||||
sign = 1;
|
||||
}
|
||||
|
||||
var i = 1;
|
||||
var tempEntry = this.createBoardEntry();
|
||||
var currentEntry = zeroEntry;
|
||||
while (true) {
|
||||
// Move to the next entry ...
|
||||
var index = i * sign;
|
||||
var entry = entries.get(index);
|
||||
if ($defined(entry)) {
|
||||
currentEntry = entry;
|
||||
} else {
|
||||
// Calculate boundaries...
|
||||
var lowerLimit, upperLimit;
|
||||
if (sign > 0) {
|
||||
lowerLimit = currentEntry.getUpperLimit();
|
||||
upperLimit = lowerLimit + this._defaultWidth;
|
||||
}
|
||||
else {
|
||||
upperLimit = currentEntry.getLowerLimit();
|
||||
lowerLimit = upperLimit - this._defaultWidth;
|
||||
}
|
||||
|
||||
// Update current entry.
|
||||
currentEntry = tempEntry;
|
||||
currentEntry.setLowerLimit(lowerLimit);
|
||||
currentEntry.setUpperLimit(upperLimit);
|
||||
|
||||
var order = this._indexToOrder(index);
|
||||
currentEntry.setOrder(order);
|
||||
}
|
||||
|
||||
// Have I found the item?
|
||||
if (currentEntry.isCoordinateIn(pos.y)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return currentEntry;
|
||||
},
|
||||
|
||||
update:function(entry) {
|
||||
$assert(entry, 'Entry can not be null');
|
||||
var order = entry.getOrder();
|
||||
var index = this._orderToIndex(order);
|
||||
|
||||
this._entries.set(index, entry);
|
||||
|
||||
},
|
||||
|
||||
freeEntry:function(entry) {
|
||||
var order = entry.getOrder();
|
||||
var entries = this._entries;
|
||||
|
||||
var index = this._orderToIndex(order);
|
||||
var indexSign = Math.sign(index);
|
||||
|
||||
var currentTopic = entry.getTopic();
|
||||
var i = Math.abs(index) + 1;
|
||||
while (currentTopic) {
|
||||
var e = entries.get(i, indexSign);
|
||||
if ($defined(currentTopic) && !$defined(e)) {
|
||||
var entryOrder = this._indexToOrder(i * indexSign);
|
||||
e = this.lookupEntryByOrder(entryOrder);
|
||||
}
|
||||
|
||||
// Move the topic to the next entry ...
|
||||
var topic = null;
|
||||
if ($defined(e)) {
|
||||
topic = e.getTopic();
|
||||
if ($defined(currentTopic)) {
|
||||
e.setTopic(currentTopic);
|
||||
}
|
||||
this.update(e);
|
||||
}
|
||||
currentTopic = topic;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Clear the entry topic ...
|
||||
entry.setTopic(null);
|
||||
},
|
||||
|
||||
_orderToIndex:function(order) {
|
||||
var index = Math.round(order / 2);
|
||||
return ((order % 2) == 0) ? index : -index;
|
||||
},
|
||||
|
||||
_indexToOrder:function(index) {
|
||||
var order = Math.abs(index) * 2;
|
||||
return (index >= 0) ? order : order - 1;
|
||||
},
|
||||
|
||||
inspect:function() {
|
||||
return this._entries.inspect();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
<map name="mapId" version="pela">
|
||||
<topic central="true" id="0">
|
||||
<topic position="156,-49" order="0" id="1"/>
|
||||
<topic position="-156,-49" order="1" id="2"/>
|
||||
<topic position="156,-16" order="2" id="3"/>
|
||||
<topic position="-156,-16" order="3" id="4"/>
|
||||
<topic position="156,16" order="4" id="5"/>
|
||||
<topic position="-156,16" order="5" id="6"/>
|
||||
<topic position="156,49" order="6" id="7"/>
|
||||
<topic position="-156,49" order="7" id="8"/>
|
||||
</topic>
|
||||
</map>
|
||||
Reference in New Issue
Block a user