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

Merge branch '217-colors-of-reactions' into 'devel_11.0.x'

creating surface overlay for reaction use proper color

See merge request piotr.gawron/minerva!129
parents 3b952856 f64562d7
......@@ -635,7 +635,7 @@ AbstractCustomMap.prototype._showSelectedLayout = function (layoutId, index, len
if (layoutReaction.getModelId() === self.getId()) {
return self.getModel().getReactionById(layoutReaction.getId()).then(function (reactionData) {
var element = new IdentifiedElement(reactionData);
var surface = new ReactionSurface({
return ReactionSurface.create({
layoutReaction: layoutReaction,
reaction: reactionData,
map: self,
......@@ -645,10 +645,10 @@ AbstractCustomMap.prototype._showSelectedLayout = function (layoutId, index, len
return self.getTopMap().callListeners("onBioEntityClick", element);
}],
customized: (length === 1)
}).then(function(surface){
self.selectedLayoutOverlays[layoutId].push(surface);
surface.show();
});
self.selectedLayoutOverlays[layoutId].push(surface);
surface.show();
});
}
});
......
......@@ -1314,7 +1314,7 @@ CustomMap.prototype.createSurfaceForDbOverlay = function (element, dbOverlay) {
});
} else if (element.getType() === "REACTION") {
return map.getModel().getReactionById(element.getId()).then(function (reactionData) {
var result = new ReactionSurface({
return ReactionSurface.create({
reaction: reactionData,
map: map,
customized: true,
......@@ -1324,10 +1324,11 @@ CustomMap.prototype.createSurfaceForDbOverlay = function (element, dbOverlay) {
}, function () {
return self.callListeners("onBioEntityClick", element);
}]
}).then(function(result){
result.show();
dbOverlay.mapOverlays[element.getType()][element.getId()] = result;
return result;
});
result.show();
dbOverlay.mapOverlays[element.getType()][element.getId()] = result;
return result;
});
} else if (element.getType() === "POINT") {
throw new Error("Not implemented");
......
......@@ -11,7 +11,7 @@ var IdentifiedElement = require('../data/IdentifiedElement');
/**
* Class representing overlay of the reaction on the map relevant for a specific
* layout.
*
*
* @param layoutReaction
* {@link LayoutReaction} for which overlay is created
* @param reactionData
......@@ -39,7 +39,6 @@ function ReactionSurface(params) {
if (overlayData.width) {
this.width = overlayData.width;
}
color = functions.overlayToColor(overlayData);
}
if (color === undefined) {
color = "#0000FF";
......@@ -58,11 +57,11 @@ ReactionSurface.prototype.constructor = ReactionSurface;
/**
* Returns {@link google.maps.Bounds bounds} of all google maps elements
* included in the object.
*
*
* @returns {@link google.maps.Bounds bounds} of all google maps elements
* included in the object
*/
ReactionSurface.prototype.getBounds = function() {
ReactionSurface.prototype.getBounds = function () {
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < this.getGoogleMapObjects().length; i++) {
......@@ -74,23 +73,23 @@ ReactionSurface.prototype.getBounds = function() {
return bounds;
};
ReactionSurface.prototype.setCustomized = function(customized) {
ReactionSurface.prototype.setCustomized = function (customized) {
this.customized = customized;
};
/**
* Sets color to be used by the reaction overlay visualization when visualized
* in customized mode.
*
*
* @param color
* new color value
*/
ReactionSurface.prototype.setColor = function(color) {
ReactionSurface.prototype.setColor = function (color) {
this._color = color;
var gmapObjects = this.getGoogleMapObjects();
for (var i = 0; i < gmapObjects.length; i++) {
gmapObjects[i].setOptions({
strokeColor : color,
strokeColor: color,
});
}
this.customized = true;
......@@ -99,11 +98,11 @@ ReactionSurface.prototype.setColor = function(color) {
/**
* Sets width of line to be used by the reaction overlay visualization when
* visualized in customized mode.
*
*
* @param width
* new width value
*/
ReactionSurface.prototype.setWidth = function(width) {
ReactionSurface.prototype.setWidth = function (width) {
if (width !== undefined || width !== null) {
this.width = width;
} else {
......@@ -114,19 +113,19 @@ ReactionSurface.prototype.setWidth = function(width) {
/**
* Returns color that should be used when visualized in customized mode.
*
*
* @returns color that should be used when visualized in customized mode.
*/
ReactionSurface.prototype.getColor = function() {
ReactionSurface.prototype.getColor = function () {
return this._color;
};
/**
* Returns width that should be used when visualized in customized mode.
*
*
* @returns width that should be used when visualized in customized mode.
*/
ReactionSurface.prototype.getWidth = function() {
ReactionSurface.prototype.getWidth = function () {
return this.width;
};
......@@ -138,7 +137,7 @@ ReactionSurface.prototype.getWidth = function() {
* of reaction should turn to some default mode where we know that reaction is
* highlighted, but we have no more information. In this way user will know that
* he should investigate the reaction manually.
*
*
* @param startX
* see {AliasSurface} class for detailes, in this implementation the
* only important information is that when there are more than one
......@@ -150,7 +149,7 @@ ReactionSurface.prototype.getWidth = function() {
* layout visualized at least one of the two parameters (startX,endX)
* will differ from {0.0, 1.0} values
*/
ReactionSurface.prototype.setBoundsForAlias = function(startX, endX) {
ReactionSurface.prototype.setBoundsForAlias = function (startX, endX) {
if (this.isCustomized() && (startX > 0 || endX < 1)) {
this.changedToDefault();
} else if (!this.isCustomized() && (startX <= 0 && endX >= 1)) {
......@@ -162,11 +161,11 @@ ReactionSurface.prototype.setBoundsForAlias = function(startX, endX) {
* Changes visualization of the ReactionSurface to default mode where we mark
* reaction as highlighted, but we skip customized reaction layout data.
*/
ReactionSurface.prototype.changedToDefault = function() {
ReactionSurface.prototype.changedToDefault = function () {
for (var i = 0; i < this.getGoogleMapObjects().length; i++) {
this.getGoogleMapObjects()[i].setOptions({
strokeColor : "#0000FF",
strokeWeight : 5,
strokeColor: "#0000FF",
strokeWeight: 5,
});
}
this.customized = false;
......@@ -176,11 +175,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.changedToCustimzed = function() {
ReactionSurface.prototype.changedToCustimzed = function () {
for (var i = 0; i < this.getGoogleMapObjects().length; i++) {
this.getGoogleMapObjects()[i].setOptions({
strokeColor : this.getColor(),
strokeWeight : this.getWidth(),
strokeColor: this.getColor(),
strokeWeight: this.getWidth(),
});
}
this.customized = true;
......@@ -188,7 +187,7 @@ ReactionSurface.prototype.changedToCustimzed = function() {
/**
* Creates {google.maps.Polyline} from input data.
*
*
* @param line
* raw data about line taken from server
* @param color
......@@ -199,41 +198,41 @@ ReactionSurface.prototype.changedToCustimzed = function() {
* {google.maps.Map} where line shoul dbe visualized
* @returns {google.maps.Polyline} from input data
*/
ReactionSurface.createLine = function(line, color, width, map) {
ReactionSurface.createLine = function (line, color, width, map) {
var pointA = new google.maps.Point(line.start.x, line.start.y);
var pointB = new google.maps.Point(line.end.x, line.end.y);
var latLngA = map.fromPointToLatLng(pointA);
var latLngB = map.fromPointToLatLng(pointB);
var path = [ latLngA, latLngB ];
var path = [latLngA, latLngB];
var googleLine = new google.maps.Polyline({
strokeColor : color,
strokeOpacity : 1.0,
strokeWeight : width,
path : path,
map : map.map
strokeColor: color,
strokeOpacity: 1.0,
strokeWeight: width,
path: path,
map: map.map
});
return googleLine;
};
/**
* Returns {@link Reaction} data for this marker.
*
*
* @returns {@link Reaction} data for this marker
*/
ReactionSurface.prototype.getReactionData = function() {
ReactionSurface.prototype.getReactionData = function () {
return this.reactionData;
};
ReactionSurface.prototype.getId = function() {
ReactionSurface.prototype.getId = function () {
return this._id;
};
ReactionSurface.prototype.setId = function(id) {
ReactionSurface.prototype.setId = function (id) {
this._id = id;
};
ReactionSurface.prototype.setReactionData = function(value) {
ReactionSurface.prototype.setReactionData = function (value) {
if (value === undefined || value === null) {
throw new Error("Reaction must be defined");
}
......@@ -241,11 +240,11 @@ ReactionSurface.prototype.setReactionData = function(value) {
this.setId(value.getId());
};
ReactionSurface.prototype.isCustomized = function() {
ReactionSurface.prototype.isCustomized = function () {
return this.customized;
};
ReactionSurface.prototype.init = function() {
ReactionSurface.prototype.init = function () {
var i;
var line;
var googleLine;
......@@ -269,4 +268,24 @@ ReactionSurface.prototype.init = function() {
}
};
ReactionSurface.create = function (params) {
var overlayData = params.layoutReaction;
var promise = Promise.resolve(params.color);
if (overlayData !== undefined && overlayData !== null) {
if (overlayData.width) {
this.width = overlayData.width;
}
promise = functions.overlayToColor(overlayData);
}
return promise.then(function (color) {
logger.debug(color);
if (color === undefined) {
color = "#0000FF";
}
params.color = color;
return new ReactionSurface(params);
});
};
module.exports = ReactionSurface;
"use strict";
require("../../mocha-config");
var ReactionSurface = require('../../../../main/js/map/surface/ReactionSurface');
var assert = require('assert');
var logger = require('../../logger');
describe('ReactionSurface', function() {
it("Constructor", function() {
describe('ReactionSurface', function () {
it("Constructor", function () {
var map = helper.createAbstractCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
var reactionOverlay = new ReactionSurface({
overlayData : layoutReaction,
reaction : reaction,
map : map,
customized : false
reaction: reaction,
map: map,
customized: false
});
assert.ok(reactionOverlay.getGoogleMapObjects().length > 0);
......@@ -26,19 +25,41 @@ describe('ReactionSurface', function() {
assert.ok(reactionOverlay.getReactionData());
assert.ok(reactionOverlay.getCustomMap());
assert.ok(reactionOverlay.getId());
assert.ok(typeof reactionOverlay.getColor() === "string");
});
it("create", function () {
var map = helper.createAbstractCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
return ReactionSurface.create({
layoutReaction: layoutReaction,
reaction: reaction,
map: map,
customized: false
}).then(function(reactionOverlay){
assert.ok(reactionOverlay.getGoogleMapObjects().length > 0);
assert.ok(reactionOverlay.getColor());
assert.ok(reactionOverlay.getWidth());
assert.ok(reactionOverlay.getBounds());
assert.ok(reactionOverlay.getReactionData());
assert.ok(reactionOverlay.getCustomMap());
assert.ok(reactionOverlay.getId());
assert.ok(typeof reactionOverlay.getColor() === "string");
});
});
it("show", function() {
it("show", function () {
var map = helper.createCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
var reactionOverlay = new ReactionSurface({
overlayData : layoutReaction,
reaction : reaction,
map : map,
customized : false
overlayData: layoutReaction,
reaction: reaction,
map: map,
customized: false
});
reactionOverlay.hide();
......@@ -55,16 +76,16 @@ describe('ReactionSurface', function() {
});
it("changedToCustimzed", function() {
it("changedToCustimzed", function () {
var map = helper.createCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
var reactionOverlay = new ReactionSurface({
overlayData : layoutReaction,
reaction : reaction,
map : map,
customized : false
overlayData: layoutReaction,
reaction: reaction,
map: map,
customized: false
});
reactionOverlay.changedToCustimzed();
......@@ -72,17 +93,17 @@ describe('ReactionSurface', function() {
});
it("createline", function() {
it("createline", function () {
var map = helper.createAbstractCustomMap();
var line = ReactionSurface.createLine({
start : {
x : 0,
y : 10
start: {
x: 0,
y: 10
},
end : {
x : 100,
y : 100
end: {
x: 100,
y: 100
},
}, "#000000", 3, map);
......
Supports Markdown
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