Extend assert support.
This commit is contained in:
@@ -17,197 +17,197 @@
|
||||
*/
|
||||
|
||||
mindplot.VariableDistanceBoard = new Class({
|
||||
Extends: mindplot.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);
|
||||
},
|
||||
Extends: mindplot.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);
|
||||
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;
|
||||
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 {
|
||||
upperLimit = offset - distance;
|
||||
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.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;
|
||||
}
|
||||
|
||||
result = this.createBoardEntry(lowerLimit, upperLimit, order);
|
||||
// Update current entry.
|
||||
currentEntry = tempEntry;
|
||||
currentEntry.setLowerLimit(lowerLimit);
|
||||
currentEntry.setUpperLimit(upperLimit);
|
||||
|
||||
var order = this._indexToOrder(index);
|
||||
currentEntry.setOrder(order);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
createBoardEntry:function(lowerLimit, upperLimit, order) {
|
||||
return new mindplot.BoardEntry(lowerLimit, upperLimit, order);
|
||||
},
|
||||
// Have I found the item?
|
||||
if (currentEntry.isCoordinateIn(pos.y)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return currentEntry;
|
||||
},
|
||||
|
||||
updateReferencePoint:function(position) {
|
||||
var entries = this._entries;
|
||||
var referencePoint = this._referencePoint;
|
||||
update:function(entry) {
|
||||
$assert(entry, 'Entry can not be null');
|
||||
var order = entry.getOrder();
|
||||
var index = this._orderToIndex(order);
|
||||
|
||||
// Update zero entry current position.
|
||||
this._referencePoint = position.clone();
|
||||
var yOffset = position.y - referencePoint.y;
|
||||
this._entries.set(index, entry);
|
||||
|
||||
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);
|
||||
},
|
||||
freeEntry:function(entry) {
|
||||
var order = entry.getOrder();
|
||||
var entries = this._entries;
|
||||
|
||||
// Update topic position ...
|
||||
if (!entry.isAvailable()) {
|
||||
var topic = entry.getTopic();
|
||||
var topicPosition = topic.getPosition();
|
||||
topicPosition.y = topicPosition.y + yOffset;
|
||||
var index = this._orderToIndex(order);
|
||||
var indexSign = Math.sign(index);
|
||||
|
||||
// MainTopicToCentral must be positioned based on the referencePoint.
|
||||
var xOffset = position.x - referencePoint.x;
|
||||
topicPosition.x = topicPosition.x + xOffset;
|
||||
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);
|
||||
}
|
||||
|
||||
topic.setPosition(topicPosition);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
},
|
||||
|
||||
lookupEntryByPosition:function(pos) {
|
||||
$assert($defined(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();
|
||||
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