Commit cd542682 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

compartment is properly resolved when bigger compartment is located in smaller...

compartment is properly resolved when bigger compartment is located in smaller compartment, but click is done on border of the bigger element
parent e0a5a1e9
minerva (12.2.0~beta.2) unstable; urgency=medium
* Bug fix: clicking on compartment border inside pathway should return
compartment, not a pathway (#324)
* Bug fix: clicking outside of the element sometimes resulted with the
invalid element highlighted (#324)
* Bug fix: parent compartment/pathway use proper type name in left panel
(#324)
(#324)
* Bug fix: editing/removing project requires Map Management privilege (#681)
* Bug fix: when removeAllListeners is called list of registered listeners is
cleaned (#687)
......
......@@ -98,28 +98,39 @@ SearchDbOverlay.prototype.getElementsByQuery = function (query) {
/**
*
* @param {Point} coordinates
* @param {IdentifiedElement} compartment
* @param {IdentifiedElement[]} compartments
* @param {number} maxDistance
* @returns {Promise}
* @private
*/
SearchDbOverlay.prototype._returnCompartmentIfClickOnBorder = function (coordinates, compartment, maxDistance) {
var model = this.getMap().getSubmapById(compartment.getModelId()).getModel();
return model.getByIdentifiedElement(compartment).then(function (result) {
var p1 = new Point(result.getX(), result.getY());
var p2 = new Point(result.getX() + result.getWidth(), result.getY());
var p3 = new Point(result.getX() + result.getWidth(), result.getY() + result.getHeight());
var p4 = new Point(result.getX(), result.getY() + result.getHeight());
var distance = Functions.distance(coordinates, {start: p1, end: p2});
distance = Math.min(distance, Functions.distance(coordinates, {start: p2, end: p3}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p3, end: p4}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p4, end: p1}));
if (maxDistance>distance) {
return compartment;
} else {
return undefined;
SearchDbOverlay.prototype._returnCompartmentIfClickOnBorder = function (coordinates, compartments, maxDistance) {
var promises = [];
for (var i = 0; i < compartments.length; i++) {
var compartment = compartments[i];
var model = this.getMap().getSubmapById(compartment.getModelId()).getModel();
promises.push(model.getByIdentifiedElement(compartment).then(function (result) {
var p1 = new Point(result.getX(), result.getY());
var p2 = new Point(result.getX() + result.getWidth(), result.getY());
var p3 = new Point(result.getX() + result.getWidth(), result.getY() + result.getHeight());
var p4 = new Point(result.getX(), result.getY() + result.getHeight());
var distance = Functions.distance(coordinates, {start: p1, end: p2});
distance = Math.min(distance, Functions.distance(coordinates, {start: p2, end: p3}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p3, end: p4}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p4, end: p1}));
if (maxDistance > distance) {
return new IdentifiedElement(result);
} else {
return undefined;
}
})
);
}
return Promise.all(promises).then(function (result) {
for (var i = 0; i < result.length; i++) {
if (result[i] !== undefined) {
return result[i];
}
}
});
};
......@@ -144,7 +155,7 @@ SearchDbOverlay.prototype._getFirstVisibleParentOrObject = function (identifiedE
//transparent compartments shouldn't be clickable
if (fullElement.getTransparencyLevel() <= zoomLevel && fullElement.getType() === "Compartment") {
var maxDistance = self.computeMaxDistance(model, zoomLevel);
return self._returnCompartmentIfClickOnBorder(coordinates, identifiedElement, maxDistance);
return self._returnCompartmentIfClickOnBorder(coordinates, [identifiedElement], maxDistance);
}
}
return identifiedElement;
......@@ -202,18 +213,20 @@ SearchDbOverlay.prototype.findCompartmentByCoordinates = function (coordinates,
return ServerConnector.getClosestElementsByCoordinates({
modelId: model.getId(),
coordinates: coordinates,
count: 1,
type: ["Compartment"]
count: 10,
type: ["Compartment", "Pathway"]
}).then(function (elements) {
var nestedOverlay = "Pathways and compartments";
if (elements.length === 0) {
return undefined;
} else {
if (self.getMap().getBackgroundDataOverlay().getName() === nestedOverlay) {
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom(), coordinates);
} else {
return self._returnCompartmentIfClickOnBorder(coordinates, elements[0], maxDistance);
}
return self._returnCompartmentIfClickOnBorder(coordinates, elements, maxDistance).then(function (result) {
var nestedOverlay = "Pathways and compartments";
if (result === undefined && self.getMap().getBackgroundDataOverlay().getName() === nestedOverlay) {
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom(), coordinates);
} else {
return result;
}
});
}
});
};
......
......@@ -172,7 +172,6 @@ describe('GuiUtils', function () {
alias.setCompartmentId(compartment.getId());
return guiUtils.createAliasElement({alias: alias}).then(function (div) {
console.log(div.innerHTML);
assert.ok(div.innerHTML.indexOf(compartment.getName()) >= 0);
assert.ok(div.innerHTML.indexOf(compartment.getType()) >= 0);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment