Skip to content

Commit 8f48fc7

Browse files
committed
Move text closer to nodes
1 parent 3c63141 commit 8f48fc7

1 file changed

Lines changed: 25 additions & 29 deletions

File tree

app/charts/route-trace.jsx

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,37 @@ class RouteTrace {
4242
  .force('link', d3.forceLink())
4343
  .force('charge', d3.forceManyBody())
4444
.force('center', d3.forceCenter(width / 2, height / 2))
45-
45+
4646
const node = svg
47-
.selectAll("circle")
47+
.selectAll('circle')
4848
.data(data[0])
4949
.enter()
50-
.append("circle")
51-
52-
// node.select('circle').data(stuff).append("circle").select('text')
53-
// .text(function(d) { return d.id });
50+
.append('circle')
51+
.on('mouseover', () => d3.select(this).text(d.id))
5452

55-
const circleAttributes = node
56-
.attr("r", 20)
57-
// .attr('cx', 200)
58-
// .attr('cy', 200)
59-
.style("fill", "#00eda0")
53+
const circleAttr = node
54+
.attr('r', 20)
55+
.attr('cx', 200)
56+
.attr('cy', 200)
57+
.style('fill', '#00eda0')
6058
.on('mouseup', (d, i, nodes) => this.setActiveDatapoint(d, nodes[i]))
6159

62-
const text = svg.selectAll("text")
63-
.data(data[0]).enter().append("text")
60+
const text = svg.selectAll('text')
61+
.data(data[0]).enter().append('text')
6462

65-
const labels = text
66-
.attr("x", d => d.x)
67-
.attr("y", d => d.y)
68-
.attr("dx", 12)
69-
.attr("dy",".35em")
63+
const textLabels = text
64+
.attr('x', d => d.x)
65+
.attr('y', d => d.y)
66+
.attr('dx', 100)
67+
.attr('dy','10em')
7068
.text(d => d.id);
7169

72-
73-
7470
const link = svg
75-
.selectAll("line")
71+
.selectAll('line')
7672
.data(data[1])
7773
.enter()
78-
.append("line")
79-
.style("stroke", "black")
74+
.append('line')
75+
.style('stroke', 'black')
8076

8177
simulation
8278
.nodes(data[0])
@@ -87,14 +83,14 @@ class RouteTrace {
8783

8884
function ticked() {
8985
link
90-
.attr("x1", function(d) { return d.source.x; })
91-
.attr("y1", function(d) { return d.source.y; })
92-
.attr("x2", function(d) { return d.target.x; })
93-
.attr("y2", function(d) { return d.target.y; });
86+
.attr('x1', function(d) { return d.source.x; })
87+
.attr('y1', function(d) { return d.source.y; })
88+
.attr('x2', function(d) { return d.target.x; })
89+
.attr('y2', function(d) { return d.target.y; });
9490

9591
node
96-
.attr("cx", function(d) { return d.x; })
97-
.attr("cy", function(d) { return d.y; });
92+
.attr('cx', function(d) { return d.x; })
93+
.attr('cy', function(d) { return d.y; });
9894
}
9995
}
10096

0 commit comments

Comments
 (0)