Move layout files in order to reflethe final layout structure.
This commit is contained in:
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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: {
|
||||
|
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.FreeMindLayoutManager = mindplot.layout.BaseLayoutManager.extend({
|
||||
options:{
|
||||
|
||||
|
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.LayoutManagerFactory = {};
|
||||
mindplot.layout.LayoutManagerFactory.managers = {
|
||||
OriginalLayoutManager:mindplot.layout.OriginalLayoutManager,
|
||||
|
@@ -133,11 +133,11 @@ mindplot.layout.OriginalLayoutManager = new Class({
|
||||
},
|
||||
|
||||
_createMainTopicBoard:function(node) {
|
||||
return new mindplot.MainTopicBoard(node, this);
|
||||
return new mindplot.layout.boards.original.MainTopicBoard(node, this);
|
||||
},
|
||||
|
||||
_createCentralTopicBoard:function(node) {
|
||||
return new mindplot.CentralTopicBoard(node, this);
|
||||
return new mindplot.layout.boards.original.CentralTopicBoard(node, this);
|
||||
},
|
||||
|
||||
getClassName:function() {
|
||||
|
@@ -1,5 +1,3 @@
|
||||
mindplot.layout.boards = {};
|
||||
|
||||
mindplot.layout.boards.Board = new Class({
|
||||
Implements: [Events,Options],
|
||||
options: {
|
||||
|
132
mindplot/src/main/javascript/layout/boards/original/Board.js
Normal file
132
mindplot/src/main/javascript/layout/boards/original/Board.js
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
}
|
||||
});
|
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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() + ')';
|
||||
}
|
||||
});
|
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 ..
|
||||
}
|
||||
});
|
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* 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.areChildrenShrinked()) {
|
||||
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;
|
||||
|
||||
|
||||
|
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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]);
|
||||
}
|
||||
}
|
||||
});
|
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
});
|
Reference in New Issue
Block a user