diff --git a/frontend-js/src/main/js/map/data/Alias.js b/frontend-js/src/main/js/map/data/Alias.js index a813a5ba24c25ec4300d1ea8d1a5aeabb71fba5f..e1d30f6f0c66dab022ab81fa5fe382b00cac5637 100644 --- a/frontend-js/src/main/js/map/data/Alias.js +++ b/frontend-js/src/main/js/map/data/Alias.js @@ -2,6 +2,7 @@ var BioEntity = require("./BioEntity"); +// noinspection JSUnusedLocalSymbols var logger = require('../../logger'); /** @@ -26,7 +27,7 @@ function Alias(javaObject) { } if (this._modelId === undefined) { - throw new Error("ModelId is not defined for alias", javaObject); + throw new Error("ModelId is not defined for alias"); } if (javaObject.name === undefined) { diff --git a/frontend-js/src/main/js/map/marker/AliasMarker.js b/frontend-js/src/main/js/map/marker/AliasMarker.js index 2b6c66c608c0770241c06a2e7d822462e787033b..a74a1a7bac3e04a3d78c6bf2297b60ace970ee48 100644 --- a/frontend-js/src/main/js/map/marker/AliasMarker.js +++ b/frontend-js/src/main/js/map/marker/AliasMarker.js @@ -40,8 +40,8 @@ AliasMarker.prototype.setAliasData = function (data) { * @returns {google.maps.Point} - coordinates where marker is pointing */ AliasMarker.prototype.getCoordinates = function () { - return new google.maps.Point(this._aliasData.x + this._aliasData.width / 2, this._aliasData.y - + this._aliasData.height / 2); + var alias = this.getAliasData(); + return new google.maps.Point(alias.getX() + alias.getWidth() / 2, alias.getY() + alias.getHeight() / 2); }; AliasMarker.prototype.init = function () { diff --git a/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js b/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js index d657fd6bceeb294d0f01cd2440652bce567ba8d7..a161dca5d6494cb96bfaa3a38014e807f9d32a2f 100644 --- a/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js +++ b/frontend-js/src/main/js/map/surface/AbstractSurfaceElement.js @@ -8,7 +8,7 @@ var ObjectWithListeners = require('../../ObjectWithListeners'); * Class representing abstract overlay element on the map relevant for a * specific layout. */ -function AbstractOverlayElement(params) { +function AbstractSurfaceElement(params) { var self = this; // call super constructor ObjectWithListeners.call(this); @@ -31,16 +31,16 @@ function AbstractOverlayElement(params) { } } -AbstractOverlayElement.prototype = Object.create(ObjectWithListeners.prototype); -AbstractOverlayElement.prototype.constructor = AbstractOverlayElement; +AbstractSurfaceElement.prototype = Object.create(ObjectWithListeners.prototype); +AbstractSurfaceElement.prototype.constructor = AbstractSurfaceElement; -AbstractOverlayElement.prototype.setMap = function(map) { +AbstractSurfaceElement.prototype.setMap = function (map) { for (var i = 0; i < this.getGoogleMapObjects().length; i++) { this.getGoogleMapObjects()[i].setMap(map); } }; -AbstractOverlayElement.prototype.getBounds = function() { +AbstractSurfaceElement.prototype.getBounds = function () { var bounds = new google.maps.LatLngBounds(); for (var i = 0; i < this.getGoogleMapObjects().length; i++) { bounds.extend(this.getGoogleMapObjects()[i].getBounds().getSouthWest()); @@ -49,7 +49,7 @@ AbstractOverlayElement.prototype.getBounds = function() { return bounds; }; -AbstractOverlayElement.prototype.isShown = function() { +AbstractSurfaceElement.prototype.isShown = function () { var result = false; for (var i = 0; i < this.getGoogleMapObjects().length; i++) { var map = this.getGoogleMapObjects()[i].getMap(); @@ -61,7 +61,7 @@ AbstractOverlayElement.prototype.isShown = function() { return result; }; -AbstractOverlayElement.prototype.show = function() { +AbstractSurfaceElement.prototype.show = function () { if (this.isShown()) { logger.warn("Surface already shown"); return; @@ -69,51 +69,60 @@ AbstractOverlayElement.prototype.show = function() { this.setMap(this.getCustomMap().getGoogleMap()); }; -AbstractOverlayElement.prototype.hide = function() { +AbstractSurfaceElement.prototype.hide = function () { this.setMap(null); }; -AbstractOverlayElement.prototype.onClickHandler = function() { +AbstractSurfaceElement.prototype.onClickHandler = function () { return this.callListeners("onClick"); }; -AbstractOverlayElement.prototype.getGoogleMarker = function() { +AbstractSurfaceElement.prototype.getGoogleMarker = function () { return this.getGoogleMapObjects()[0]; }; -AbstractOverlayElement.prototype.getGoogleMapObjects = function() { +AbstractSurfaceElement.prototype.getGoogleMapObjects = function () { return this._googleMapObjects; }; -AbstractOverlayElement.prototype.addGoogleMapObject = function(googleObject) { +AbstractSurfaceElement.prototype.addGoogleMapObject = function (googleObject) { this._googleMapObjects.push(googleObject); var self = this; - var onclick = function() { + var onclick = function () { return self.onClickHandler(); }; google.maps.event.addListener(googleObject, 'click', onclick); }; -AbstractOverlayElement.prototype.getIdentifiedElement = function() { +AbstractSurfaceElement.prototype.getIdentifiedElement = function () { return this._identifiedElement; }; -AbstractOverlayElement.prototype.getModelId = function() { +AbstractSurfaceElement.prototype.setIdentifiedElement = function (identifiedElement) { + this._identifiedElement = identifiedElement; +}; + +AbstractSurfaceElement.prototype.getBioEntity = function () { + return this._bioEntity; +}; + +AbstractSurfaceElement.prototype.setBioEntity = function (bioEntity) { + this._bioEntity = bioEntity; +}; + + +AbstractSurfaceElement.prototype.getModelId = function () { return this.getIdentifiedElement().getModelId(); }; -AbstractOverlayElement.prototype.updateIdentifiedElement = function(identifiedElement) { +AbstractSurfaceElement.prototype.updateIdentifiedElement = function (identifiedElement) { if (identifiedElement.getColor() !== undefined) { this.setColor(identifiedElement.getColor()); } }; -AbstractOverlayElement.prototype.setIdentifiedElement = function(identifiedElement) { - this._identifiedElement = identifiedElement; -}; - -AbstractOverlayElement.prototype.getBounds = function() { +AbstractSurfaceElement.prototype.getBounds = function () { var self = this; var bounds = new google.maps.LatLngBounds(); for (var i = 0; i < self.getGoogleMapObjects().length; i++) { @@ -127,15 +136,15 @@ AbstractOverlayElement.prototype.getBounds = function() { /** * Returns {@link AbstractCustomMap} where surface is located. - * - * @returns {@link AbstractCustomMap} where surface is located + * + * @returns {AbstractCustomMap} where surface is located */ -AbstractOverlayElement.prototype.getCustomMap = function() { +AbstractSurfaceElement.prototype.getCustomMap = function () { return this._customMap; }; -AbstractOverlayElement.prototype.setCustomMap = function(customMap) { +AbstractSurfaceElement.prototype.setCustomMap = function (customMap) { this._customMap = customMap; }; -module.exports = AbstractOverlayElement; +module.exports = AbstractSurfaceElement; diff --git a/frontend-js/src/main/js/map/surface/AliasSurface.js b/frontend-js/src/main/js/map/surface/AliasSurface.js index 58c38c691eafad16972d0090a2449c600e16e007..f062657fdc63d1f28a7a33d37da61bcb6cdbead4 100644 --- a/frontend-js/src/main/js/map/surface/AliasSurface.js +++ b/frontend-js/src/main/js/map/surface/AliasSurface.js @@ -2,6 +2,7 @@ /* exported logger */ +// noinspection JSUnusedLocalSymbols var logger = require('../../logger'); var functions = require('../../Functions'); @@ -20,18 +21,18 @@ function AliasSurface(params) { this.addGoogleMapObject(params.gmapObj); // original data - this.aliasData = params.alias; + this.setBioEntity(params.alias); } AliasSurface.prototype = Object.create(AbstractSurfaceElement.prototype); AliasSurface.prototype.constructor = AliasSurface; -AliasSurface.prototype.setColor = function(color) { +AliasSurface.prototype.setColor = function (color) { this._color = color; var googleMapObjects = this.getGoogleMapObjects(); for (var i = 0; i < googleMapObjects.length; i++) { googleMapObjects[i].setOptions({ - strokeColor : color, + strokeColor: color }); } }; @@ -40,16 +41,16 @@ AliasSurface.prototype.setColor = function(color) { * Function used to recalculate boundaries of the {@link AliasSurface}. * Boundaries define how big part of original alias is taken by this layout * visualization. - * + * * @param startX * value between 0..1 defining where should be the start on OX axis * @param endX * value between 0..1 defining where should be the end on OX axis */ -AliasSurface.prototype.setBoundsForAlias = function(startX, endX) { - var pointA = new google.maps.Point(this.aliasData.x + startX * this.aliasData.width, this.aliasData.y); - var pointB = new google.maps.Point(this.aliasData.x + endX * this.aliasData.width, this.aliasData.y - + this.aliasData.height); +AliasSurface.prototype.setBoundsForAlias = function (startX, endX) { + var alias = this.getBioEntity(); + var pointA = new google.maps.Point(alias.x + startX * alias.width, alias.y); + var pointB = new google.maps.Point(alias.x + endX * alias.width, alias.y + alias.height); var latLngA = this.getCustomMap().fromPointToLatLng(pointA); var latLngB = this.getCustomMap().fromPointToLatLng(pointB); @@ -61,7 +62,7 @@ AliasSurface.prototype.setBoundsForAlias = function(startX, endX) { /** * Creates {@link AliasSurface}. - * + * * @param params * dict containing set of information required for surface creation: * <li>overlayAlias - {@link LayoutAlias} for which overlay is created @@ -79,7 +80,7 @@ AliasSurface.prototype.setBoundsForAlias = function(startX, endX) { * starting point of the overlay * @returns {AliasSurface} */ -AliasSurface.create = function(params) { +AliasSurface.create = function (params) { var overlayAlias = params.overlayAlias; var alias = params.alias; var map = params.map; @@ -95,32 +96,32 @@ AliasSurface.create = function(params) { bounds.extend(latLngA); bounds.extend(latLngB); var rectangle = new google.maps.Rectangle({ - fillOpacity : 0.8, - strokeWeight : 1, - map : map.getGoogleMap(), - bounds : bounds + fillOpacity: 0.8, + strokeWeight: 1, + map: map.getGoogleMap(), + bounds: bounds }); - return functions.overlayToColor(overlayAlias).then(function(color) { + return functions.overlayToColor(overlayAlias).then(function (color) { rectangle.setOptions({ - fillColor : color, + fillColor: color }); var result = new AliasSurface({ - map : map, - gmapObj : rectangle, - alias : alias, - onClick : params.onClick + map: map, + gmapObj: rectangle, + alias: alias, + onClick: params.onClick }); result.setIdentifiedElement(new IdentifiedElement(alias)); return result; }); }; -AliasSurface.createFromIdentifiedElement = function(params) { +AliasSurface.createFromIdentifiedElement = function (params) { var element = params.element; var map = params.map; var model = map.getModel().getSubmodelById(element.getModelId()); - return model.getByIdentifiedElement(element).then(function(alias) { + return model.getByIdentifiedElement(element).then(function (alias) { var pointA = new google.maps.Point(alias.getX(), alias.getY()); var pointB = new google.maps.Point(alias.getX() + alias.getWidth(), alias.getY() + alias.getHeight()); var latLngA = map.fromPointToLatLng(pointA); @@ -152,21 +153,21 @@ AliasSurface.createFromIdentifiedElement = function(params) { } var rectangle = new google.maps.Rectangle({ - map : map.getGoogleMap(), - bounds : bounds, - - fillOpacity : fillOpacity, - fillColor : color, - strokeColor : strokeColor, - strokeOpacity : strokeOpacity, - strokeWeight : strokeWeight, + map: map.getGoogleMap(), + bounds: bounds, + + fillOpacity: fillOpacity, + fillColor: color, + strokeColor: strokeColor, + strokeOpacity: strokeOpacity, + strokeWeight: strokeWeight }); var result = new AliasSurface({ - gmapObj : rectangle, - map : map, - onClick : params.onClick, - alias : alias, + gmapObj: rectangle, + map: map, + onClick: params.onClick, + alias: alias }); result.setIdentifiedElement(element); return result; diff --git a/frontend-js/src/main/js/map/surface/ReactionSurface.js b/frontend-js/src/main/js/map/surface/ReactionSurface.js index e57d7d8086c3026fc8cfca5ff9ac513d142f45ed..58748537d193ee03bb53accf1092483d5653f6a2 100644 --- a/frontend-js/src/main/js/map/surface/ReactionSurface.js +++ b/frontend-js/src/main/js/map/surface/ReactionSurface.js @@ -1,5 +1,7 @@ "use strict"; +var Promise = require("bluebird"); + /* exported logger */ var functions = require('../../Functions'); @@ -29,7 +31,7 @@ function ReactionSurface(params) { AbstractSurfaceElement.call(this, params); var overlayData = params.layoutReaction; - this.setReactionData(params.reaction); + this.setBioEntity(params.reaction); var color = params.color; this.width = 5.0; @@ -46,7 +48,7 @@ function ReactionSurface(params) { this.setColor(color); this.setCustomized(params.customized); - this.setIdentifiedElement(new IdentifiedElement(this.getReactionData())); + this.setIdentifiedElement(new IdentifiedElement(this.getBioEntity())); this.init(); } @@ -89,7 +91,7 @@ ReactionSurface.prototype.setColor = function (color) { var gmapObjects = this.getGoogleMapObjects(); for (var i = 0; i < gmapObjects.length; i++) { gmapObjects[i].setOptions({ - strokeColor: color, + strokeColor: color }); } this.customized = true; @@ -165,7 +167,7 @@ ReactionSurface.prototype.changedToDefault = function () { for (var i = 0; i < this.getGoogleMapObjects().length; i++) { this.getGoogleMapObjects()[i].setOptions({ strokeColor: "#0000FF", - strokeWeight: 5, + strokeWeight: 5 }); } this.customized = false; @@ -175,11 +177,11 @@ ReactionSurface.prototype.changedToDefault = function () { * Changes visualization of the ReactionSurface to customized mode where we mark * reaction as highlighted with customized reaction layout data. */ -ReactionSurface.prototype.changedToCustomized = function() { +ReactionSurface.prototype.changedToCustomized = function () { for (var i = 0; i < this.getGoogleMapObjects().length; i++) { this.getGoogleMapObjects()[i].setOptions({ strokeColor: this.getColor(), - strokeWeight: this.getWidth(), + strokeWeight: this.getWidth() }); } this.customized = true; @@ -215,15 +217,6 @@ ReactionSurface.createLine = function (line, color, width, map) { return googleLine; }; -/** - * Returns {@link Reaction} data for this marker. - * - * @returns {@link Reaction} data for this marker - */ -ReactionSurface.prototype.getReactionData = function () { - return this.reactionData; -}; - ReactionSurface.prototype.getId = function () { return this._id; }; @@ -232,11 +225,11 @@ ReactionSurface.prototype.setId = function (id) { this._id = id; }; -ReactionSurface.prototype.setReactionData = function (value) { +ReactionSurface.prototype.setBioEntity = function (value) { if (value === undefined || value === null) { throw new Error("Reaction must be defined"); } - this.reactionData = value; + AbstractSurfaceElement.prototype.setBioEntity.call(this, value); this.setId(value.getId()); }; @@ -245,21 +238,22 @@ ReactionSurface.prototype.isCustomized = function () { }; ReactionSurface.prototype.init = function () { + var reaction = this.getBioEntity(); var i; var line; var googleLine; - for (i = 0; i < this.reactionData.startLines.length; i++) { - line = this.reactionData.startLines[i]; + for (i = 0; i < reaction.startLines.length; i++) { + line = reaction.startLines[i]; googleLine = ReactionSurface.createLine(line, this.getColor(), this.width, this.getCustomMap()); this.addGoogleMapObject(googleLine); } - for (i = 0; i < this.reactionData.endLines.length; i++) { - line = this.reactionData.endLines[i]; + for (i = 0; i < reaction.endLines.length; i++) { + line = reaction.endLines[i]; googleLine = ReactionSurface.createLine(line, this.getColor(), this.width, this.getCustomMap()); this.addGoogleMapObject(googleLine); } - for (i = 0; i < this.reactionData.midLines.length; i++) { - line = this.reactionData.midLines[i]; + for (i = 0; i < reaction.midLines.length; i++) { + line = reaction.midLines[i]; googleLine = ReactionSurface.createLine(line, this.getColor(), this.width, this.getCustomMap()); this.addGoogleMapObject(googleLine); } diff --git a/frontend-js/src/test/js/map/data/Alias-test.js b/frontend-js/src/test/js/map/data/Alias-test.js index 2444f2ac02ebf0abfe95595a16d9aff32f775a6a..9c72fb22fdcf754cc7560e22fe60cd07f7347975 100644 --- a/frontend-js/src/test/js/map/data/Alias-test.js +++ b/frontend-js/src/test/js/map/data/Alias-test.js @@ -61,70 +61,91 @@ describe('Alias', function () { }); - it("Alias update method", function () { - var javaObject = { - bounds: { - x: 190, - y: 44, - width: 80, - height: 40 - }, - modelId: 57, - idObject: 18554 - }; - var alias = new Alias(javaObject); - var javaObject2 = { - notes: "", - type: "Protein", - name: "s1", - synonyms: [], - formerSymbols: [], - references: [], - other: [], - bounds: { - x: 59, - y: 73, - width: 80, - height: 40 - }, - modelId: 54, - idObject: 18552 - }; - alias.update(javaObject2); - assert.ok(alias.isComplete()); - assert.equal('s1', alias.name); - }); + describe("update", function () { + describe("from json", function () { + it("full update", function () { + var javaObject = { + bounds: { + x: 190, + y: 44, + width: 80, + height: 40 + }, + modelId: 57, + idObject: 18554 + }; + var alias = new Alias(javaObject); + var javaObject2 = { + notes: "", + type: "Protein", + name: "s1", + synonyms: [], + formerSymbols: [], + references: [], + other: [], + bounds: { + x: 59, + y: 73, + width: 80, + height: 40 + }, + modelId: 54, + idObject: 18552 + }; + alias.update(javaObject2); + assert.ok(alias.isComplete()); + assert.equal('s1', alias.getName()); + }); + + it("partial update", function () { + var javaObject = { + bounds: { + x: 190, + y: 44, + width: 80, + height: 40 + }, + modelId: 57, + idObject: 18554 + }; + var alias = new Alias(javaObject); + var javaObject2 = { + notes: "", + type: "Protein", + synonyms: [], + formerSymbols: [], + references: [], + other: [], + bounds: { + x: 59, + y: 73, + width: 80, + height: 40 + }, + modelId: 54, + idObject: 18552 + }; + alias.update(javaObject2); + assert.equal(alias.isComplete(), false); + }); + }); - it("Alias update method 2", function () { - var javaObject = { - bounds: { - x: 190, - y: 44, - width: 80, - height: 40 - }, - modelId: 57, - idObject: 18554 - }; - var alias = new Alias(javaObject); - var javaObject2 = { - notes: "", - type: "Protein", - synonyms: [], - formerSymbols: [], - references: [], - other: [], - bounds: { - x: 59, - y: 73, - width: 80, - height: 40 - }, - modelId: 54, - idObject: 18552 - }; - alias.update(javaObject2); - assert.equal(alias.isComplete(), false); + it("from Alias", function () { + var javaObject = { + bounds: { + x: 190, + y: 44, + width: 80, + height: 40 + }, + modelId: 57, + idObject: 18554 + }; + var alias = new Alias(javaObject); + var alias2 = new Alias(javaObject); + alias.update(alias2); + assert.equal(alias.isComplete(), false); + }); }); }); diff --git a/frontend-js/src/test/js/map/data/MapModel-test.js b/frontend-js/src/test/js/map/data/MapModel-test.js index 5bad0d3b69968bb7314a452a5e4d9bfd90a8b6b7..77ae8c60cab9c8b203023875539d4c44de2b9aed 100644 --- a/frontend-js/src/test/js/map/data/MapModel-test.js +++ b/frontend-js/src/test/js/map/data/MapModel-test.js @@ -7,6 +7,7 @@ var LayoutData = require('../../../../main/js/map/data/LayoutData'); var MapModel = require('../../../../main/js/map/data/MapModel'); var NetworkError = require('../../../../main/js/NetworkError'); var PointData = require('../../../../main/js/map/data/PointData'); +var ServerConnector = require('../../ServerConnector-mock'); var assert = require('chai').assert; diff --git a/frontend-js/src/test/js/map/surface/ReactionSurface-test.js b/frontend-js/src/test/js/map/surface/ReactionSurface-test.js index c8a81162dc4e1244185126d171bd98cbe1c36224..babf8bf7fdc4c2097910502dab9fd1e232947ba2 100644 --- a/frontend-js/src/test/js/map/surface/ReactionSurface-test.js +++ b/frontend-js/src/test/js/map/surface/ReactionSurface-test.js @@ -23,7 +23,7 @@ describe('ReactionSurface', function () { assert.ok(reactionOverlay.getColor()); assert.ok(reactionOverlay.getWidth()); assert.ok(reactionOverlay.getBounds()); - assert.ok(reactionOverlay.getReactionData()); + assert.ok(reactionOverlay.getBioEntity()); assert.ok(reactionOverlay.getCustomMap()); assert.ok(reactionOverlay.getId()); assert.ok(typeof reactionOverlay.getColor() === "string"); @@ -44,7 +44,7 @@ describe('ReactionSurface', function () { assert.ok(reactionOverlay.getColor()); assert.ok(reactionOverlay.getWidth()); assert.ok(reactionOverlay.getBounds()); - assert.ok(reactionOverlay.getReactionData()); + assert.ok(reactionOverlay.getBioEntity()); assert.ok(reactionOverlay.getCustomMap()); assert.ok(reactionOverlay.getId()); assert.ok(typeof reactionOverlay.getColor() === "string");