Skip to content

Commit d76a4fe

Browse files
Merge pull request #223 from refactorfirst/render-node-names-in-force-graph-correctly
Render Node Names in Force Graphs with Correct Name
2 parents 16a6556 + 5bffbbe commit d76a4fe

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎report/src/main/java/org/hjug/refactorfirst/report/HtmlReport.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function createForceGraph(popupId, containerName, dot) {
154154
var nodeData = graphlibGraph.node(node);
155155
nodes.push({
156156
id: node,
157+
label: graphlibGraph.node(node).label || node,
157158
color: nodeData.color || 'white',
158159
});
159160
});
@@ -189,7 +190,7 @@ function createForceGraph(popupId, containerName, dot) {
189190
190191
const Graph = new ForceGraph3D(container)
191192
.graphData(gData)
192-
.nodeLabel('id')
193+
.nodeLabel('label')
193194
.width(container.clientWidth)
194195
.height(container.clientHeight);
195196
@@ -199,7 +200,7 @@ function createForceGraph(popupId, containerName, dot) {
199200
200201
// use node labels instead of spheres
201202
Graph.nodeThreeObject(node => {
202-
const sprite = new SpriteText(node.id);
203+
const sprite = new SpriteText(node.label);
203204
sprite.material.depthWrite = false; // make sprite background transparent
204205
sprite.color = node.color;
205206
sprite.textHeight = 4;
@@ -612,14 +613,15 @@ private void renderClassVertices(
612613

613614
dot.append(" [");
614615
dot.append(hyperlinkClassForDot(vertex, repoUrl, codebaseGraphDTO));
615-
if (className.contains("$")) {
616-
dot.append(" label=\"").append(escapeDotQuoted(className)).append("\"");
617-
} else if (isAnonymousFqn(vertex)) {
616+
617+
if (isAnonymousFqn(vertex)) {
618618
// Kotlin "<anonymous>" renders under the enclosing source file's base name as the
619619
// owner with $ as the enclosing-class separator (escaped for DOT).
620620
dot.append(" label=\"")
621621
.append(escapeDotQuoted(anonymousOwnerLabel(vertex, codebaseGraphDTO)))
622622
.append("\"");
623+
} else {
624+
dot.append(" label=\"").append(escapeDotQuoted(className)).append("\"");
623625
}
624626

625627
if (classesToRemove.contains(vertex)) {

‎report/src/test/java/org/hjug/refactorfirst/report/HtmlReportKotlinTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ void buildClassCycleDot_kotlinSourcePaths() {
9595
KotlinCycleA -\\u003E KotlinCycleB [ label = "2" weight = "2" ];
9696
KotlinCycleB -\\u003E KotlinCycleC [ label = "1" weight = "1" ];
9797
KotlinCycleC -\\u003E KotlinCycleA [ label = "1" weight = "1" ];
98-
KotlinCycleA [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleA.kt" target="_blank"];
99-
KotlinCycleB [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleB.kt" target="_blank"];
100-
KotlinCycleC [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleC.kt" target="_blank"];
98+
KotlinCycleA [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleA.kt" target="_blank" label="KotlinCycleA"];
99+
KotlinCycleB [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleB.kt" target="_blank" label="KotlinCycleB"];
100+
KotlinCycleC [URL="https://github.com/refactorfirst/RefactorFirst/blob/src/main/kotlin/com/kotlin/cycles/KotlinCycleC.kt" target="_blank" label="KotlinCycleC"];
101101
}`;\
102102
""";
103103

‎report/src/test/java/org/hjug/refactorfirst/report/HtmlReportTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ void buildClassCycleDot() {
6666
+ "A -\\u003E B [ label = \"2\" weight = \"2\" ];\n"
6767
+ "B -\\u003E C [ label = \"1\" weight = \"1\" ];\n"
6868
+ "C -\\u003E A [ label = \"1\" weight = \"1\" ];\n"
69-
+ "A [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/A.java\" target=\"_blank\"];\n"
70-
+ "B [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/B.java\" target=\"_blank\"];\n"
71-
+ "C [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/C.java\" target=\"_blank\"];\n"
69+
+ "A [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/A.java\" target=\"_blank\" label=\"A\"];\n"
70+
+ "B [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/B.java\" target=\"_blank\" label=\"B\"];\n"
71+
+ "C [URL=\"https://github.com/refactorfirst/RefactorFirst/blob/src/main/java/org/hjug/refactorfirst/C.java\" target=\"_blank\" label=\"C\"];\n"
7272
+ "}`;";
7373

7474
assertEquals(expectedDot, dot);

0 commit comments

Comments
 (0)