Skip to content
Snippets Groups Projects
Commit 3339ce83 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

JS doc for IdentifiedElement

parent 377d3e2b
No related branches found
No related tags found
1 merge request!295Resolve "alternative to google maps api way of visualizing maps"
...@@ -39,7 +39,7 @@ BioEntity.prototype.setId = function(id) { ...@@ -39,7 +39,7 @@ BioEntity.prototype.setId = function(id) {
/** /**
* Returns model identifier where {@link BioEntity} is located. * Returns model identifier where {@link BioEntity} is located.
* *
* @returns model identifier where {@link BioEntity} is located * @returns {number} model identifier where {@link BioEntity} is located
*/ */
BioEntity.prototype.getModelId = function() { BioEntity.prototype.getModelId = function() {
return this._modelId; return this._modelId;
......
...@@ -9,6 +9,15 @@ var Point = require('../canvas/Point'); ...@@ -9,6 +9,15 @@ var Point = require('../canvas/Point');
var logger = require('../../logger'); var logger = require('../../logger');
/**
* @typedef {Object} IdentifiedElementInput
* @property {string|number} [id]
* @property {string|number} [objectId]
* @property {number} modelId
* @property {string} type
* @property {string} [icon]
*/
/** /**
* This is object representing element tha should be visualized on the map. It's * This is object representing element tha should be visualized on the map. It's
* very light and contains only the most important data. There are three types * very light and contains only the most important data. There are three types
...@@ -19,42 +28,45 @@ var logger = require('../../logger'); ...@@ -19,42 +28,45 @@ var logger = require('../../logger');
* <li>"POINT" - for any point on the map, the data connected to this kind of * <li>"POINT" - for any point on the map, the data connected to this kind of
* objects are stored in {@link PointData}</li> * objects are stored in {@link PointData}</li>
* </ul> * </ul>
*
* @param {BioEntity|LayoutAlias|LayoutReaction|PointData|IdentifiedElementInput} object
* @constructor
*/ */
function IdentifiedElement(javaObject) { function IdentifiedElement(object) {
this._visualizationdata = {}; this._visualizationdata = {};
if (javaObject instanceof Alias) { if (object instanceof Alias) {
this.setId(javaObject.getId()); this.setId(object.getId());
this.setModelId(javaObject.getModelId()); this.setModelId(object.getModelId());
this.setType("ALIAS"); this.setType("ALIAS");
} else if (javaObject instanceof LayoutAlias) { } else if (object instanceof LayoutAlias) {
this.setId(javaObject.getId()); this.setId(object.getId());
this.setModelId(javaObject.getModelId()); this.setModelId(object.getModelId());
this.setType("ALIAS"); this.setType("ALIAS");
} else if (javaObject instanceof Reaction) { } else if (object instanceof Reaction) {
this.setId(javaObject.getId()); this.setId(object.getId());
this.setModelId(javaObject.getModelId()); this.setModelId(object.getModelId());
this.setType("REACTION"); this.setType("REACTION");
} else if (javaObject instanceof LayoutReaction) { } else if (object instanceof LayoutReaction) {
this.setId(javaObject.getId()); this.setId(object.getId());
this.setModelId(javaObject.getModelId()); this.setModelId(object.getModelId());
this.setType("REACTION"); this.setType("REACTION");
} else if (javaObject instanceof PointData) { } else if (object instanceof PointData) {
this.setId(javaObject.getId()); this.setId(object.getId());
this.setModelId(javaObject.getModelId()); this.setModelId(object.getModelId());
this.setType("POINT"); this.setType("POINT");
} else { } else {
// identifier of the object to visualize // identifier of the object to visualize
if (javaObject.objectId === undefined) { if (object.objectId === undefined) {
this.setId(javaObject.id); this.setId(object.id);
} else { } else {
this.setId(javaObject.objectId); this.setId(object.objectId);
} }
// which marker should be used to show this object // which marker should be used to show this object
this.setIcon(javaObject.icon); this.setIcon(object.icon);
// on which model the element is located // on which model the element is located
this.setModelId(javaObject.modelId); this.setModelId(object.modelId);
// what kind of object we are talking about // what kind of object we are talking about
this.setType(javaObject.type); this.setType(object.type);
} }
if (this.getType() === "POINT") { if (this.getType() === "POINT") {
...@@ -75,8 +87,8 @@ function IdentifiedElement(javaObject) { ...@@ -75,8 +87,8 @@ function IdentifiedElement(javaObject) {
throw new Error("Unknown type of identified element: " + this.getType()); throw new Error("Unknown type of identified element: " + this.getType());
} }
if (this.getId() === undefined || this.getId() === null) { if (this.getId() === undefined) {
throw new Error("Id not defined for element: " + javaObject); throw new Error("Id not defined for element: " + object);
} }
} }
...@@ -84,7 +96,7 @@ function IdentifiedElement(javaObject) { ...@@ -84,7 +96,7 @@ function IdentifiedElement(javaObject) {
* Returns point where it should be visualized when the type of object is * Returns point where it should be visualized when the type of object is
* "POINT". * "POINT".
* *
* @returns {@link Point} where it should be visualized when the * @returns {Point|null} where it should be visualized when the
* type of object is "POINT". * type of object is "POINT".
*/ */
IdentifiedElement.prototype.getPoint = function () { IdentifiedElement.prototype.getPoint = function () {
...@@ -114,6 +126,10 @@ IdentifiedElement.prototype.setId = function (id) { ...@@ -114,6 +126,10 @@ IdentifiedElement.prototype.setId = function (id) {
this.id = id; this.id = id;
}; };
/**
*
* @param {number|string} modelId
*/
IdentifiedElement.prototype.setModelId = function (modelId) { IdentifiedElement.prototype.setModelId = function (modelId) {
if (modelId === undefined || modelId === null) { if (modelId === undefined || modelId === null) {
throw new Error("ModelId is invalid"); throw new Error("ModelId is invalid");
...@@ -156,12 +172,16 @@ IdentifiedElement.prototype.setType = function (type) { ...@@ -156,12 +172,16 @@ IdentifiedElement.prototype.setType = function (type) {
/** /**
* Returns icon that should be used for visualization. * Returns icon that should be used for visualization.
* *
* @returns icon that should be used for visualization * @returns {string} icon that should be used for visualization
*/ */
IdentifiedElement.prototype.getIcon = function () { IdentifiedElement.prototype.getIcon = function () {
return this._visualizationdata._icon; return this._visualizationdata._icon;
}; };
/**
*
* @param {string} icon
*/
IdentifiedElement.prototype.setIcon = function (icon) { IdentifiedElement.prototype.setIcon = function (icon) {
this._visualizationdata._icon = icon; this._visualizationdata._icon = icon;
}; };
...@@ -207,14 +227,6 @@ IdentifiedElement.prototype.setLineColor = function (lineColor) { ...@@ -207,14 +227,6 @@ IdentifiedElement.prototype.setLineColor = function (lineColor) {
this._visualizationdata._lineColor = lineColor; this._visualizationdata._lineColor = lineColor;
}; };
IdentifiedElement.prototype.getOnClickHandler = function () {
return this._visualizationdata._onClickHandler;
};
IdentifiedElement.prototype.setOnClickHandler = function (onClickHandler) {
this._visualizationdata._onClickHandler = onClickHandler;
};
IdentifiedElement.prototype.equals = function (argument) { IdentifiedElement.prototype.equals = function (argument) {
if (argument instanceof IdentifiedElement) { if (argument instanceof IdentifiedElement) {
return (this.getType() === argument.getType() && // return (this.getType() === argument.getType() && //
...@@ -225,6 +237,10 @@ IdentifiedElement.prototype.equals = function (argument) { ...@@ -225,6 +237,10 @@ IdentifiedElement.prototype.equals = function (argument) {
} }
}; };
/**
*
* @returns {string}
*/
IdentifiedElement.prototype.toString = function () { IdentifiedElement.prototype.toString = function () {
var self = this; var self = this;
return "[" + IdentifiedElement.prototype.constructor.name + "] " + self.getType() + " " + self.getId() + " (model: " return "[" + IdentifiedElement.prototype.constructor.name + "] " + self.getType() + " " + self.getId() + " (model: "
......
...@@ -13,8 +13,7 @@ function PointData(javaObject, modelId) { ...@@ -13,8 +13,7 @@ function PointData(javaObject, modelId) {
this._point = javaObject.getPoint(); this._point = javaObject.getPoint();
this._modelId = javaObject.getModelId(); this._modelId = javaObject.getModelId();
} else { } else {
var tmp = javaObject.idObject; var tmp = javaObject.idObject.replace("Point2D.Double", "");
tmp = javaObject.idObject.replace("Point2D.Double", "");
tmp = JSON.parse(tmp); tmp = JSON.parse(tmp);
var x = parseFloat(tmp[0]).toFixed(2); var x = parseFloat(tmp[0]).toFixed(2);
var y = parseFloat(tmp[1]).toFixed(2); var y = parseFloat(tmp[1]).toFixed(2);
...@@ -42,6 +41,10 @@ PointData.prototype.getPoint = function() { ...@@ -42,6 +41,10 @@ PointData.prototype.getPoint = function() {
return this._point; return this._point;
}; };
/**
*
* @returns {number}
*/
PointData.prototype.getModelId = function() { PointData.prototype.getModelId = function() {
return this._modelId; return this._modelId;
}; };
......
...@@ -98,6 +98,7 @@ describe('IdentifiedElement', function () { ...@@ -98,6 +98,7 @@ describe('IdentifiedElement', function () {
modelId: 2 modelId: 2
}; };
var code = function () { var code = function () {
// noinspection JSCheckFunctionSignatures
new IdentifiedElement(javaObject); new IdentifiedElement(javaObject);
}; };
assert.throws(code, new RegExp("Type not defined")); assert.throws(code, new RegExp("Type not defined"));
...@@ -130,6 +131,7 @@ describe('IdentifiedElement', function () { ...@@ -130,6 +131,7 @@ describe('IdentifiedElement', function () {
objectId: "el_id" objectId: "el_id"
}; };
var code = function () { var code = function () {
// noinspection JSCheckFunctionSignatures
new IdentifiedElement(javaObject); new IdentifiedElement(javaObject);
}; };
assert.throws(code, new RegExp("ModelId is invalid")); assert.throws(code, new RegExp("ModelId is invalid"));
...@@ -150,7 +152,7 @@ describe('IdentifiedElement', function () { ...@@ -150,7 +152,7 @@ describe('IdentifiedElement', function () {
var javaObject = { var javaObject = {
type: "alias", type: "alias",
objectId: "el_id", objectId: "el_id",
modelId: "m_id" modelId: 123
}; };
var ie = new IdentifiedElement(javaObject); var ie = new IdentifiedElement(javaObject);
var point = ie.getPoint(); var point = ie.getPoint();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment