mirror of https://gitee.com/bigwinds/arangodb
GraphViewer: The colourmapper and NodeShaper can now return the mapping color -> label as a list
This commit is contained in:
parent
453dc3c1ec
commit
3b8a1fca81
|
@ -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();
|
||||
}
|
|
@ -456,6 +456,10 @@ function NodeShaper(parent, flags, idfunc) {
|
|||
shapeNodes();
|
||||
};
|
||||
|
||||
self.getColourMapping = function() {
|
||||
return colourMapper.getList();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
NodeShaper.shapes = Object.freeze({
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue