Skip to content

Commit 5e0513b

Browse files
mappumjbenet
authored andcommitted
diagnostics/d3: Added link highlighting
1 parent a14d77e commit 5e0513b

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

diagnostics/d3/chord.html

+38-16
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
<meta charset="utf-8">
33
<style>
44

5-
body {
5+
.node {
66
font: 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
77
}
8+
.node:hover circle {
9+
stroke: red;
10+
stroke-width: 4px;
11+
}
812

9-
.node {
10-
font: 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
13+
.node .link {
14+
stroke-width: 0;
15+
}
16+
.node:hover .link {
17+
stroke-width: 4px;
1118
}
1219

1320
.link {
@@ -67,20 +74,14 @@ <h1>IPFS TestNet</h1>
6774
.data(graph.nodes)
6875
.enter().append("g")
6976
.attr("class", "node")
70-
.attr("transform", function(d) { return "rotate(" + (d.x - 90 + rotate) + ")translate(" + d.y + ")"; })
77+
78+
var p = projection
7179

7280
node.append("svg:circle")
73-
.attr("r", function(d) { return d.conns + 3; })
81+
.attr("r", function(d) { return d.conns + 2; })
7482
.style("fill", function(d, i) { return color(i % 20); })
83+
.attr("transform", function(d) { return "rotate(" + (d.x - 90 + rotate) + ")translate(" + d.y + ")"; })
7584

76-
node.append("text")
77-
.attr("dx", function(d) { return 8; })
78-
.attr("dy", ".31em")
79-
// .attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
80-
// .attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
81-
.text(function(d) { return d.conns + " - " + d.name; });
82-
83-
var p = projection
8485
var link = svg.selectAll(".link")
8586
.data(graph.paths)
8687
.enter().append("path")
@@ -90,9 +91,26 @@ <h1>IPFS TestNet</h1>
9091
+ "S" + p(d[1])[0] + "," + p(d[1])[1]
9192
+ " " + p(d[2])[0] + "," + p(d[2])[1];
9293
})
93-
.style("stroke", function(d) { return color(d[0].index % 20); })
94-
.style("stroke-opacity", function(d) { return 0.3; })
9594

95+
node.selectAll('.link')
96+
.data(function(d) { return d.links })
97+
.enter().append('path')
98+
.attr('class', 'link')
99+
.style("stroke", function(d) { return color(d.source.index % 20); })
100+
.attr("d", function(d) {
101+
return "M" + p(d.path[0])[0] + "," + p(d.path[0])[1]
102+
+ "S" + p(d.path[1])[0] + "," + p(d.path[1])[1]
103+
+ " " + p(d.path[2])[0] + "," + p(d.path[2])[1];
104+
})
105+
106+
node.append("text")
107+
.attr("class", "label")
108+
.attr("dx", -4)
109+
.attr("dy", 3)
110+
// .attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
111+
// .attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
112+
.text(function(d) { return d.conns + " - " + d.name; })
113+
.attr("transform", function(d) { return "rotate(" + (d.x - 90 + rotate) + ")translate(" + d.y + ")"; })
96114

97115
// var mid = svg.selectAll(".node-mid")
98116
// .data(graph.mids)
@@ -126,9 +144,10 @@ <h1>IPFS TestNet</h1>
126144
data.y = innerRadius
127145
data.x = ((360 / graph2.nodes.length) * i)
128146
data.conns = 0
129-
data.index = i
130147
graph.nodes.push(data)
131148
graph.byName[data.name] = data
149+
data.index = i
150+
data.links = []
132151
})
133152

134153
graph2.links.forEach(function(link) {
@@ -147,6 +166,9 @@ <h1>IPFS TestNet</h1>
147166

148167
var path = [source, mid, target]
149168
graph.paths.push(path)
169+
170+
source.links.push({path: path, source: source})
171+
target.links.push({path: path, source: target})
150172
})
151173

152174
document.getElementById("node-count").innerText = graph.nodes.length

0 commit comments

Comments
 (0)