diff --git a/html/admin/js/graphViewer/graph/colourMapper.js b/html/admin/js/graphViewer/graph/colourMapper.js index 78a92fe3ef..6273a0a969 100644 --- a/html/admin/js/graphViewer/graph/colourMapper.js +++ b/html/admin/js/graphViewer/graph/colourMapper.js @@ -32,6 +32,7 @@ function ColourMapper() { var mapCreated = false, mapping = {}, + reverseMapping = {}, colours = [], nextColour = 0; @@ -59,6 +60,10 @@ function ColourMapper() { this.getColour = function(value) { if (mapping[value] === undefined) { mapping[value] = colours[nextColour]; + if (reverseMapping[colours[nextColour]] === undefined) { + reverseMapping[colours[nextColour]] = []; + } + reverseMapping[colours[nextColour]].push(value); nextColour++; if (nextColour === colours.length) { nextColour = 0; @@ -69,7 +74,13 @@ function ColourMapper() { this.reset = function() { mapping = {}; + reverseMapping = {}; nextColour = 0; }; + this.getList = function() { + return reverseMapping; + }; + + this.reset(); } \ No newline at end of file diff --git a/html/admin/js/graphViewer/graph/nodeShaper.js b/html/admin/js/graphViewer/graph/nodeShaper.js index d79ce75f87..da7c769f75 100644 --- a/html/admin/js/graphViewer/graph/nodeShaper.js +++ b/html/admin/js/graphViewer/graph/nodeShaper.js @@ -456,6 +456,10 @@ function NodeShaper(parent, flags, idfunc) { shapeNodes(); }; + self.getColourMapping = function() { + return colourMapper.getList(); + }; + } NodeShaper.shapes = Object.freeze({ diff --git a/html/admin/js/graphViewer/jasmine_test/specColourMapper/colourMapperSpec.js b/html/admin/js/graphViewer/jasmine_test/specColourMapper/colourMapperSpec.js index 5bca387538..aa89c7b749 100644 --- a/html/admin/js/graphViewer/jasmine_test/specColourMapper/colourMapperSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specColourMapper/colourMapperSpec.js @@ -1,8 +1,8 @@ /*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */ /*global beforeEach, afterEach */ -/*global describe, it, expect */ +/*global describe, it, expect, jasmine */ /*global document */ -/*global $, d3*/ +/*global $, d3, _*/ /*global ColourMapper*/ //////////////////////////////////////////////////////////////////////////////// @@ -116,6 +116,20 @@ expect(colours[0]).toEqual(cNew); }); + it('should be able to return the colour mapping list', function() { + mapper.getColour("1"); + mapper.getColour("2"); + mapper.getColour("3"); + + var colorList = mapper.getList(); + + expect(_.keys(colorList).length).toEqual(3); + _.each(_.values(colorList), function(v) { + expect(v).toEqual(jasmine.any(Array)); + expect(v.length).toEqual(1); + }); + + }); }); }()); \ No newline at end of file diff --git a/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js b/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js index 72c58e56cd..1e8f171a42 100644 --- a/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js @@ -1,6 +1,6 @@ /*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true */ /*global beforeEach, afterEach */ -/*global describe, it, expect */ +/*global describe, it, expect, jasmine */ /*global window, eb, loadFixtures, document */ /*global $, _, d3*/ /*global helper*/ @@ -277,6 +277,49 @@ expect(c3s).toEqual("#654321"); }); + it('should be able to receive the color <-> label mapping', function() { + var nodes = [ + { + _id: 1, + _data: { + label: "lbl1" + } + }, { + _id: 2, + _data: { + label: "lbl2" + } + }, { + _id: 3, + _data: { + label: "lbl3" + } + }, { + _id: 4, + _data: { + label: "lbl1" + } + }], + shaper = new NodeShaper(d3.select("svg"), + { + color: { + type: "attribute", + key: "label" + } + }), + colorList; + + shaper.drawNodes(nodes); + + colorList = shaper.getColourMapping(); + + expect(_.keys(colorList)).toEqual(3); + _.each(_.values(colorList), function(v) { + expect(v).toEqual(jasmine.any(Array)); + expect(v.length).toEqual(1); + }); + }); + }); describe('when nodes are already drawn', function() {