Commit a238a70b authored by S Anand's avatar S Anand

ENH: allow circle, line, label layers to be independently toggled

parent 5b9ba585
......@@ -258,16 +258,8 @@ _G_network.force = function() {
.attr('fill', 'rgba(0,0,0,.5)')
}
function draw_label(labels) {
labels
.text(function(node) { return node.key + ': ' + node.value })
.attr({
'text-anchor': 'middle',
'dy': '-0.8em',
'fill': 'rgba(0,0,0,.8)',
'font-size': 8,
})
}
// By default, don't draw labels
var draw_label
force.on('tick', function() {
self.lines.attr('x1', function(d) { return d.source.x })
......@@ -384,7 +376,8 @@ _G_network.force = function() {
// TODO: find better way to get the SVG-space dimensions
var width = +svg.attr('width'),
height = +svg.attr('height')
height = +svg.attr('height'),
enter
force.size([width, height])
// Create / find the g.lines and g.circles layers
......@@ -408,30 +401,36 @@ _G_network.force = function() {
self.lines = $lines.selectAll('line.link')
.data(links, function(d) { return d.id })
self.lines.exit().remove()
var enter = self.lines.enter()
.append('line')
.attr('class', 'link')
draw_line(self.lines)
if (draw_line) {
enter = self.lines.enter()
.append('line')
.attr('class', 'link')
draw_line(self.lines)
}
self.circles = $circles.selectAll('circle.node')
.data(nodes, function(d) { return d.id })
self.circles.exit().remove()
enter = self.circles.enter()
.append('circle')
.attr('class', 'node')
.on('dblclick.release', _node_release)
.call(force.drag)
draw_circle(self.circles)
if (draw_circle) {
enter = self.circles.enter()
.append('circle')
.attr('class', 'node')
.on('dblclick.release', _node_release)
.call(force.drag)
draw_circle(self.circles)
}
self.labels = $labels.selectAll('text.node')
.data(nodes, function(d) { return d.id })
self.labels.exit().remove()
enter = self.labels.enter()
.append('text')
.attr('class', 'node')
.on('dblclick.release', _node_release)
.call(force.drag)
draw_label(self.labels)
if (draw_label) {
enter = self.labels.enter()
.append('text')
.attr('class', 'node')
.on('dblclick.release', _node_release)
.call(force.drag)
draw_label(self.labels)
}
if (!svg.on('dblclick.release'))
svg.on('dblclick.release', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment