diff --git a/frontend-js/src/main/js/Functions.js b/frontend-js/src/main/js/Functions.js index 94949629be3185db6c749aa0e0ba02a459439d18..b233ee58d6325cbc9a2ed659ee42cc9409f0a316 100644 --- a/frontend-js/src/main/js/Functions.js +++ b/frontend-js/src/main/js/Functions.js @@ -113,6 +113,42 @@ Functions.prototype.colorToRgbaString = function (color, opacity) { return "rgba(" + red + "," + green + "," + blue + "," + alpha + ")"; }; + +/** + * + * @param {LayoutAlias[]|LayoutReaction[]} overlayData + * @returns {Promise<Array>} + */ +Functions.prototype.overlaysToColorDataStructure = function (overlayData) { + var promises = []; + for (var i = 0; i < overlayData.length; i++) { + promises.push(this.overlayToColor(overlayData[i])); + } + return Promise.all(promises).then(function (colors) { + var countByColor = [], color; + for (var i = 0; i < colors.length; i++) { + color = colors[i]; + if (countByColor[color] !== undefined) { + countByColor[color]++; + } else { + countByColor[color] = 1; + } + } + var result = []; + for (color in countByColor) { + if (countByColor.hasOwnProperty(color)) { + result.push({color: color, amount: countByColor[color]}); + } + } + var compare = function (a, b) { + return a.color.localeCompare(b.color); + }; + result.sort(compare); + return result; + }); + +}; + /** * Returns stack trace. * diff --git a/frontend-js/src/main/js/map/surface/AliasSurface.js b/frontend-js/src/main/js/map/surface/AliasSurface.js index 834889a49a622e69147d3e25b2fa61b0ca9c1996..b80391ef416accf3cd996390e639767efd78f6d5 100644 --- a/frontend-js/src/main/js/map/surface/AliasSurface.js +++ b/frontend-js/src/main/js/map/surface/AliasSurface.js @@ -184,32 +184,7 @@ AliasSurface.prototype._computeColors = function () { if (overlayData === undefined || overlayData.length === 0) { return self.getColor(); } else { - var promises = []; - for (var i = 0; i < overlayData.length; i++) { - promises.push(functions.overlayToColor(overlayData[i])); - } - return Promise.all(promises).then(function (colors) { - var countByColor = [], color; - for (var i = 0; i < colors.length; i++) { - color = colors[i]; - if (countByColor[color] !== undefined) { - countByColor[color]++; - } else { - countByColor[color] = 1; - } - } - var result = []; - for (color in countByColor) { - if (countByColor.hasOwnProperty(color)) { - result.push({color: color, amount: countByColor[color]}); - } - } - var compare = function (a, b) { - return a.color.localeCompare(b.color); - }; - result.sort(compare); - return result; - }); + return functions.overlaysToColorDataStructure(overlayData); } }; diff --git a/frontend-js/src/main/js/map/window/AliasInfoWindow.js b/frontend-js/src/main/js/map/window/AliasInfoWindow.js index b9abc108ccb20d40252e5d3db0adc30460ab16de..f80f8bfc7eeb1635491e921e36b5f9c8329ae146 100644 --- a/frontend-js/src/main/js/map/window/AliasInfoWindow.js +++ b/frontend-js/src/main/js/map/window/AliasInfoWindow.js @@ -202,7 +202,7 @@ AliasInfoWindow.prototype.createChartDiv = function (params) { overlayDataOnSubmap.push(data); } } - return self._computeColors(overlayDataOnSubmap).then(function (colors) { + return Functions.overlaysToColorDataStructure(overlayDataOnSubmap).then(function (colors) { var rowDiv = document.createElement("div"); rowDiv.className = "minerva-chart-row-odd"; var nameDiv = document.createElement("div"); @@ -545,41 +545,4 @@ AliasInfoWindow.prototype.getPosition = function () { return new Point(alias.x + alias.width / 2, alias.y + alias.height / 2); }; -/** - * - * @param {LayoutAlias[]} overlayData - * @returns {Promise<Array>} - * @private - */ -AliasInfoWindow.prototype._computeColors = function (overlayData) { - var promises = []; - for (var i = 0; i < overlayData.length; i++) { - promises.push(Functions.overlayToColor(overlayData[i])); - } - return Promise.all(promises).then(function (colors) { - var countByColor = [], color; - for (var i = 0; i < colors.length; i++) { - color = colors[i]; - if (countByColor[color] !== undefined) { - countByColor[color]++; - } else { - countByColor[color] = 1; - } - } - var result = []; - for (color in countByColor) { - if (countByColor.hasOwnProperty(color)) { - result.push({color: color, amount: countByColor[color]}); - } - } - var compare = function (a, b) { - return a.color.localeCompare(b.color); - }; - result.sort(compare); - return result; - }); - -}; - - module.exports = AliasInfoWindow;