Skip to content

Commit b6feb64

Browse files
committed
add support for displaying link types
1 parent f03f228 commit b6feb64

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

core/frontend/graph.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ simulation.on('tick', function () {
8787
.attr('y1', (d) => d.source.y)
8888
.attr('x2', (d) => d.target.x)
8989
.attr('y2', (d) => d.target.y);
90+
91+
elts.linkLabels
92+
.attr("x", (d) => (d.source.x + d.target.x) / 2)
93+
.attr("y", (d) => (d.source.y + d.target.y) / 2)
94+
.attr("text-anchor", "middle")
95+
.attr("transform", d => {
96+
var angle = Math.atan2(d.target.y - d.source.y, d.target.x - d.source.x) * 180 / Math.PI;
97+
98+
// Adjust angle to avoid upside-down text
99+
if (angle > 90 || angle < -90) {
100+
angle = (angle + 180) % 360;
101+
}
102+
103+
var x = (d.source.x + d.target.x) / 2;
104+
var y = (d.source.y + d.target.y) / 2;
105+
return `rotate(${angle},${x},${y})`;
106+
});
90107

91108
elts.nodes.attr('transform', (d) => 'translate(' + d.x + ',' + d.y + ')');
92109

@@ -130,6 +147,15 @@ if (graphProperties.graph_arrows === true) {
130147
elts.links.attr('marker-end', 'url(#arrow)');
131148
}
132149

150+
elts.linkLabels = svgSub
151+
.append('g')
152+
.selectAll("text")
153+
.data(data.edges)
154+
.enter()
155+
.append("text")
156+
.attr('font-size', graphProperties.graph_text_size)
157+
.text(d => d.attributes.type); // Assuming each link has a label
158+
133159
const strokeWidth = 2;
134160

135161
/** @type {d3.Selection<SVGGElement, Node, SVGElement, any>} */
@@ -493,6 +519,14 @@ window.labelDisplayToggle = function (isChecked) {
493519
}
494520
};
495521

522+
window.linkLabelDisplayToggle = function (isChecked) {
523+
if (isChecked) {
524+
elts.linkLabels.style('display', null);
525+
} else {
526+
elts.linkLabels.style('display', 'none');
527+
}
528+
};
529+
496530
/**
497531
* Change the font size of graph labels
498532
*/

core/i18n.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ left_panel:
8181
input_labels_show:
8282
fr: Afficher les étiquettes
8383
en: Display labels
84+
input_link_labels_show:
85+
fr: Afficher les étiquettes liens
86+
en: Display link labels
8487
input_highlight_hover_node:
8588
fr: Surbrillance au survol
8689
en: Highlight on hover

static/template/cosmoscope.njk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@
176176
{{ translation.left_panel.menu_controls.input_labels_show[lang] }}
177177
</label>
178178
</li>
179+
<li>
180+
<label>
181+
<input type="checkbox" checked onchange="linkLabelDisplayToggle(this.checked)">
182+
{{ translation.left_panel.menu_controls.input_link_labels_show[lang] }}
183+
</label>
184+
</li>
179185
<li>
180186
<label>
181187
<input type="checkbox" {{ "checked" if graph.config.graph_highlight_on_hover }}

0 commit comments

Comments
 (0)