1
0
Fork 0

GraphViewer: Added function to toggle display of labels without redefining them

This commit is contained in:
Michael Hackstein 2013-05-03 14:07:59 +02:00
parent b7464677cc
commit 91a7d66dbd
4 changed files with 80 additions and 4 deletions

View File

@ -49,6 +49,7 @@ function EdgeShaper(parent, flags, idfunc) {
var self = this,
edges = [],
toplevelSVG,
visibleLabels = true,
idFunction = function(d) {
return d.source._id + "-" + d.target._id;
@ -120,7 +121,9 @@ function EdgeShaper(parent, flags, idfunc) {
addQue = function (line, g) {
addShape(line, g);
addLabel(line, g);
if (visibleLabels) {
addLabel(line, g);
}
addColor(line, g);
addEvents(line, g);
addPosition(line, g);
@ -336,7 +339,16 @@ function EdgeShaper(parent, flags, idfunc) {
self.reshapeEdges = function() {
shapeEdges();
};
};
self.activateLabel = function(toogle) {
if (toogle) {
visibleLabels = true;
} else {
visibleLabels = false;
}
shapeEdges();
};
}
EdgeShaper.shapes = Object.freeze({

View File

@ -64,7 +64,8 @@ function NodeShaper(parent, flags, idfunc) {
"use strict";
var self = this,
nodes = [],
nodes = [],
visibleLabels = true,
noop = function (node) {
},
@ -120,7 +121,9 @@ function NodeShaper(parent, flags, idfunc) {
addQue = function (g) {
addShape(g);
addLabel(g);
if (visibleLabels) {
addLabel(g);
}
addColor(g);
addEvents(g);
addDistortion();
@ -350,6 +353,15 @@ function NodeShaper(parent, flags, idfunc) {
shapeNodes();
};
self.activateLabel = function(toogle) {
if (toogle) {
visibleLabels = true;
} else {
visibleLabels = false;
}
shapeNodes();
};
}
NodeShaper.shapes = Object.freeze({

View File

@ -693,6 +693,32 @@
expect($("#2-1")[0].textContent).toEqual("new");
});
it('should be possible to toggle label display', function() {
var nodes = helper.createSimpleNodes([1, 2]),
edges = [
{
"source": nodes[0],
"target": nodes[1],
_data: {
"label": "test"
}
}
];
shaper.drawEdges(edges);
expect($("#1-2")[0].textContent).toEqual("test");
shaper.activateLabel(false);
expect($("#1-2")[0].textContent).toEqual("");
expect($("#1-2 text").length).toEqual(0);
shaper.activateLabel(true);
expect($("#1-2")[0].textContent).toEqual("test");
});
});
describe('using a function for labels', function() {

View File

@ -710,6 +710,32 @@
});
it('should be possible to toggle label display', function() {
var node = [{
_id: 1,
_data: {
label: "test"
}
}];
shaper.drawNodes(node);
expect($("svg .node text").length).toEqual(1);
expect($("svg .node text")[0].textContent).toEqual("test");
shaper.activateLabel(false);
expect($("svg .node text").length).toEqual(0);
shaper.activateLabel(true);
expect($("svg .node text").length).toEqual(1);
expect($("svg .node text")[0].textContent).toEqual("test");
});
});
describe('using a function for labels', function () {