Commit 4edda694 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

neutral color for data overlays is provided (by default it's white, but it can be changed)

parent faf97857
Pipeline #2602 passed with stage
in 42 seconds
......@@ -8,6 +8,7 @@ var ConfigurationType = {
LEGEND_FILES: "LEGEND_FILES",
MIN_COLOR_VAL: "MIN_COLOR_VAL",
MAX_COLOR_VAL: "MAX_COLOR_VAL",
NEUTRAL_COLOR_VAL: "NEUTRAL_COLOR_VAL",
REQUEST_ACCOUNT_EMAIL: "REQUEST_ACCOUNT_EMAIL",
SIMPLE_COLOR_VAL: "SIMPLE_COLOR_VAL",
SEARCH_DISTANCE: "SEARCH_DISTANCE",
......
......@@ -173,44 +173,49 @@ Functions.overlayToColor = function (elementOverlay) {
return Promise.resolve(self.intToColorString(elementOverlay.color.rgb));
} else {
var ratio = 0;
var promiseColor = null;
var promiseColors;
if (elementOverlay.value !== undefined && elementOverlay.value !== null) {
if (elementOverlay.value < 0) {
ratio = -elementOverlay.value;
promiseColor = ServerConnector.getMinOverlayColorInt();
promiseColors = [ServerConnector.getMinOverlayColorInt(), ServerConnector.getNeutralOverlayColorInt()];
} else {
ratio = elementOverlay.value;
promiseColor = ServerConnector.getMaxOverlayColorInt();
promiseColors = [ServerConnector.getMaxOverlayColorInt(), ServerConnector.getNeutralOverlayColorInt()];
}
} else {
ratio = 1;
promiseColor = ServerConnector.getSimpleOverlayColorInt();
promiseColors = [ServerConnector.getSimpleOverlayColorInt(), ServerConnector.getNeutralOverlayColorInt()];
}
return promiseColor.then(function (color) {
return Promise.all(promiseColors).then(function (colors) {
var maxColor = colors[0];
var neutralColor = colors[1];
ratio = 1 - ratio;
var MAX_RED = 0xFF0000;
var MAX_GREEN = 0x00FF00;
var MAX_BLUE = 0x0000FF;
var red = color & MAX_RED;
var red = maxColor & MAX_RED;
var neutralRed = neutralColor & MAX_RED;
red = red + (MAX_RED - red) * ratio;
red = red + (neutralRed - red) * ratio;
red = parseInt(red);
red = red & 0xFF0000;
red = red & MAX_RED;
var green = color & MAX_GREEN;
green = green + (MAX_GREEN - green) * ratio;
var green = maxColor & MAX_GREEN;
var neutralGreen = neutralColor & MAX_GREEN;
green = green + (neutralGreen - green) * ratio;
green = parseInt(green);
green = green & MAX_GREEN;
var blue = color & MAX_BLUE;
blue = blue + (MAX_BLUE - blue) * ratio;
var blue = maxColor & MAX_BLUE;
var neutralBlue = neutralColor & MAX_BLUE;
blue = blue + (neutralBlue - blue) * ratio;
blue = parseInt(blue);
blue = blue & MAX_BLUE;
color = red | green | blue;
var color = red | green | blue;
return self.intToColorString(color);
});
}
......
......@@ -110,6 +110,14 @@ ServerConnector.getMaxOverlayColorInt = function () {
});
};
ServerConnector.getNeutralOverlayColorInt = function () {
var self = this;
return self.getLoggedUser().then(function (user) {
var userColor = user.getNeutralColor();
return self.returnUserOrSystemColor(userColor, self.getConfigurationParam(ConfigurationType.NEUTRAL_COLOR_VAL));
});
};
ServerConnector.sendGetRequest = function (url, description) {
return this.sendRequest({
url: url,
......
......@@ -22,6 +22,7 @@ function User(javaObject) {
this.setPreferences(javaObject.preferences);
this.setMinColor(javaObject.minColor);
this.setMaxColor(javaObject.maxColor);
this.setNeutralColor(javaObject.neutralColor);
this.setSimpleColor(javaObject.simpleColor);
}
......@@ -86,6 +87,14 @@ User.prototype.getSimpleColor = function () {
return this._simpleColor;
};
User.prototype.setNeutralColor = function (neutralColor) {
this._neutralColor = neutralColor;
};
User.prototype.getNeutralColor = function () {
return this._neutralColor;
};
User.prototype.setMaxColor = function (maxColor) {
this._maxColor = maxColor;
};
......
"use strict";
require('./mocha-config');
var functions = require('../../main/js/Functions');
var logger = require('./logger');
var assert = require('assert');
var originalNavigator = null;
describe('functions', function() {
describe('functions', function () {
beforeEach(function() {
beforeEach(function () {
originalNavigator = global.navigator;
});
afterEach(function() {
afterEach(function () {
global.navigator = originalNavigator;
});
it('Point inside polygon 1', function() {
it('Point inside polygon 1', function () {
var point = {
x : 123,
y : 124
x: 123,
y: 124
};
var polygon = [];
polygon[0] = {
x : 0,
y : 0
x: 0,
y: 0
};
polygon[1] = {
x : 100,
y : 0
x: 100,
y: 0
};
polygon[2] = {
x : 100,
y : 100
x: 100,
y: 100
};
polygon[3] = {
x : 0,
y : 100
x: 0,
y: 100
};
assert.equal(false, functions.pointInsidePolygon(point, polygon));
});
it('Point inside polygon 2', function() {
it('Point inside polygon 2', function () {
var point = {
x : 123,
y : 124
x: 123,
y: 124
};
var polygon = [];
polygon[0] = {
x : 0,
y : 0
x: 0,
y: 0
};
polygon[1] = {
x : 1000,
y : 0
x: 1000,
y: 0
};
polygon[2] = {
x : 1000,
y : 1000
x: 1000,
y: 1000
};
polygon[3] = {
x : 0,
y : 1000
x: 0,
y: 1000
};
assert.ok(functions.pointInsidePolygon(point, polygon));
});
it('Point inside polygon 3', function() {
it('Point inside polygon 3', function () {
var point = {
x : 20,
y : 50
x: 20,
y: 50
};
var polygon = [];
polygon[0] = {
x : 0,
y : 0
x: 0,
y: 0
};
polygon[1] = {
x : 100,
y : 0
x: 100,
y: 0
};
polygon[2] = {
x : 10,
y : 50
x: 10,
y: 50
};
polygon[3] = {
x : 100,
y : 100
x: 100,
y: 100
};
polygon[4] = {
x : 0,
y : 100
x: 0,
y: 100
};
assert.equal(false, functions.pointInsidePolygon(point, polygon));
});
it('Point inside polygon 4', function() {
it('Point inside polygon 4', function () {
var point = {
x : 5,
y : 50
x: 5,
y: 50
};
var polygon = [];
polygon[0] = {
x : 0,
y : 0
x: 0,
y: 0
};
polygon[1] = {
x : 100,
y : 0
x: 100,
y: 0
};
polygon[2] = {
x : 10,
y : 50
x: 10,
y: 50
};
polygon[3] = {
x : 100,
y : 100
x: 100,
y: 100
};
polygon[4] = {
x : 0,
y : 100
x: 0,
y: 100
};
assert.ok(functions.pointInsidePolygon(point, polygon));
});
it('Integer to html color', function() {
it('Integer to html color', function () {
var integer = -16711936;
var color = functions.intToColorString(integer);
assert.equal(7, color.length);
assert.equal(color.charAt(0), '#');
});
it('isInt', function() {
it('isInt', function () {
assert.ok(functions.isInt(12));
assert.ok(functions.isInt(-12));
assert.ok(functions.isInt(0));
......@@ -144,11 +146,11 @@ describe('functions', function() {
assert.equal(functions.isInt(""), false);
});
it('stackTrace', function() {
it('stackTrace', function () {
assert.ok(functions.stackTrace());
});
it('getPosition', function() {
it('getPosition', function () {
var div = document.createElement('div');
div.scrollLeft = 0;
div.scrollTop = 0;
......@@ -157,7 +159,7 @@ describe('functions', function() {
assert.equal(0, pos.y);
});
it('isDomElement', function() {
it('isDomElement', function () {
assert.strictEqual(false, functions.isDomElement(12));
assert.strictEqual(false, functions.isDomElement(-12));
assert.strictEqual(false, functions.isDomElement(0));
......@@ -168,43 +170,44 @@ describe('functions', function() {
assert.strictEqual(true, functions.isDomElement(document.createElement('div')));
});
it('overlayToColor', function() {
var overlay = {
value : 0.5,
};
return functions.overlayToColor(overlay).then(function(colorString) {
// check the format of the html color
assert.equal(colorString.charAt(0), "#");
assert.equal(colorString.length, 7);
describe('overlayToColor', function () {
it('positive value', function () {
var overlay = {
value: 0.5
};
return functions.overlayToColor(overlay).then(function (colorString) {
// check the format of the html color
assert.equal(colorString.charAt(0), "#");
assert.equal(colorString.length, 7);
});
});
});
it('overlayToColor 2', function() {
var overlay = {
value : -0.5,
};
return functions.overlayToColor(overlay).then(function(colorString) {
// check the format of the html color
assert.equal(colorString.charAt(0), "#");
assert.equal(colorString.length, 7);
it('negative value', function () {
var overlay = {
value: -0.5
};
return functions.overlayToColor(overlay).then(function (colorString) {
// check the format of the html color
assert.equal(colorString.charAt(0), "#");
assert.equal(colorString.length, 7);
});
});
});
it('overlayToColor with invalid arg', function() {
return functions.overlayToColor(null).then(function(colorString) {
throw new Error('Promise was unexpectedly fulfilled. Result: ' + colorString);
}, function rejected(error) {
assert.ok(error.indexOf("cannot be null") >= 0);
it('invalid arg', function () {
return functions.overlayToColor(null).then(function (colorString) {
throw new Error('Promise was unexpectedly fulfilled. Result: ' + colorString);
}, function rejected(error) {
assert.ok(error.indexOf("cannot be null") >= 0);
});
});
});
it('overlayToColor with invalid arg 2', function() {
return functions.overlayToColor({}).then(function(colorString) {
assert.ok(colorString);
it('invalid arg 2', function () {
return functions.overlayToColor({}).then(function (colorString) {
assert.ok(colorString);
});
});
});
it('bound with null params', function() {
it('bound with null params', function () {
var value = 12;
var result = functions.bound(value, 13, null);
assert.equal(result, 13);
......@@ -214,17 +217,17 @@ describe('functions', function() {
assert.equal(result2, -1);
});
it('browser detection simulation with unsupported detection browser', function() {
it('browser detection simulation with unsupported detection browser', function () {
var browser = functions.browser;
browser.init();
assert.equal(browser.name, "Unknown");
assert.equal(browser.version, "Unknown");
});
it('browser detection simulation with IE', function() {
it('browser detection simulation with IE', function () {
global.navigator = {
appName : 'Microsoft Internet Explorer',
userAgent : "MSIE 7.0",
appName: 'Microsoft Internet Explorer',
userAgent: "MSIE 7.0"
};
var browser = functions.browser;
......@@ -233,10 +236,10 @@ describe('functions', function() {
assert.equal(browser.version, "7.0");
});
it('browser detection simulation with other', function() {
it('browser detection simulation with other', function () {
global.navigator = {
appName : 'Netscape',
userAgent : "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko",
appName: 'Netscape',
userAgent: "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko"
};
var browser = functions.browser;
......
......@@ -363,4 +363,11 @@ describe('ServerConnector', function () {
});
});
it('getNeutralOverlayColorInt', function () {
return ServerConnector.getNeutralOverlayColorInt().then(function (color) {
assert.ok(color);
});
});
});
package lcsb.mapviewer.model.user;
/**
* This enum defines all possible configuration parameter that are configurable
* by the user.
* This enumerate defines all possible configuration parameter that are
* configurable by the user.
*
* @author Piotr Gawron
*
*/
public enum ConfigurationElementType {
/**
* Email address used for sending email from the system.
*/
EMAIL_ADDRESS("E-mail address", "your.account@domain.com", ConfigurationElementEditType.EMAIL, true), //
/**
* Login for the email account.
*/
EMAIL_LOGIN("E-mail server login", "your@login", ConfigurationElementEditType.STRING, true), //
/**
* Password for the email account.
*/
EMAIL_PASSWORD("E-mail server password", "email.secret.password", ConfigurationElementEditType.PASSWORD, true), //
/**
* Address of the imap server.
*/
EMAIL_IMAP_SERVER("IMAP server", "your.imap.domain.com", ConfigurationElementEditType.STRING, true), //
/**
* Address of the smtp server.
*/
EMAIL_SMTP_SERVER("SMTP server", "your.smtp.domain.com", ConfigurationElementEditType.STRING, true), //
/**
* Port used for smtp connection (sending e-mails).
*/
EMAIL_SMTP_PORT("SMTP port", "25", ConfigurationElementEditType.INTEGER, true), //
/**
* Default map that should be presented if no map is selected by user side.
*/
DEFAULT_MAP("Default Project Id", "empty", ConfigurationElementEditType.STRING, false), //
/**
* Logo presented in the system.
*/
LOGO_IMG("Logo icon", "udl.png", ConfigurationElementEditType.URL, false), //
/**
* Address connected to the logo.
*/
LOGO_LINK("Logo link (after click)", "http://wwwen.uni.lu/", ConfigurationElementEditType.URL, false), //
/**
* Maximum distance (in pixels) that is allowed during finding closest element
* on the map.
*/
SEARCH_DISTANCE("Max distance for clicking on element (px)", "10", ConfigurationElementEditType.DOUBLE, false),
/**
* Email used for requesting an account (in client side).
*/
REQUEST_ACCOUNT_EMAIL("Email used for requesting an account", "your.email@domain.com", ConfigurationElementEditType.EMAIL, false),
/**
* Max number of results in search box.
*/
SEARCH_RESULT_NUMBER("Max number of results in search box. ", "100", ConfigurationElementEditType.INTEGER, false),
/**
* Google Analytics tracking ID used for statistics. This tracking ID should
* look like "UA-000000-01". More information about tracking ID can be found
* <a href="https://support.google.com/analytics/answer/1032385?hl=en"> here
* </a>.
*/
GOOGLE_ANALYTICS_IDENTIFIER("Google Analytics tracking ID used for statistics", "", ConfigurationElementEditType.STRING, false),
/**
* Description of the logo presented in the system.
*/
LOGO_TEXT("Logo description", "University of Luxembourg", ConfigurationElementEditType.STRING, false),
/**
* Domain allowed to connect via x-frame technology.
*/
X_FRAME_DOMAIN("Domain allowed to connect via x-frame technology", "", ConfigurationElementEditType.URL, false),
/**
* Relative directory (in webapps folder) where big files will be stored.
*/
BIG_FILE_STORAGE_DIR("Path to store big files", "minerva-big/", ConfigurationElementEditType.STRING, false),
/**
* File where legend 1/4 is stored.
*/
LEGEND_FILE_1("Legend 1 image file", "resources/images/legend_a.png", ConfigurationElementEditType.URL, false),
/**
* File where legend 2/4 is stored.
*/
LEGEND_FILE_2("Legend 2 image file", "resources/images/legend_b.png", ConfigurationElementEditType.URL, false),
/**
* File where legend 3/4 is stored.
*/
LEGEND_FILE_3("Legend 3 image file", "resources/images/legend_c.png", ConfigurationElementEditType.URL, false),
/**
* File where legend 4/4 is stored.
*/
LEGEND_FILE_4("Legend 4 image file", "resources/images/legend_d.png", ConfigurationElementEditType.URL, false),
/**
* File where legend 4/4 is stored.
*/
USER_MANUAL_FILE("User manual file", "resources/other/user_guide.pdf", ConfigurationElementEditType.URL, false),
/**
* Color used for negative overlay values.
*/
MIN_COLOR_VAL("Overlay color for negative values", "FF0000", ConfigurationElementEditType.COLOR, false),
/**
* Color used for positive overlay values.
*/
MAX_COLOR_VAL("Overlay color for postive values", "0000FF", ConfigurationElementEditType.COLOR, false),
/**
* Color used for undefined overlay values.
*/