this._link = this._linksEle.selectAll('.link').data(this._links);
// enter selection
let linkEnter = this._link.enter().append('g')
.attr('id', function (d) {
var linkObj = d.source['link_' + d.source.id + d.target.id];
return linkObj.id;
})
.attr('source', function (d) {
return d.source.id;
})
.attr('target', function (d) {
return d.target.id;
})
.attr('class', 'link');
// Enter links
linkEnter.append('path')
.attr('id', function (d) {
return 'linkPath' + d.source.id + d.target.id;
})
.attr('class', 'link-path')
.style('fill', 'none')
.style('stroke', '#ccc')
.style('stroke-width', 2)
.style('cursor', 'pointer')
.attr('marker-end', 'url(#path_arrow)')
.on("click", function (d) {
self.fnEdgeClick(d);
});
linkEnter.append('text').attr('class', 'edge-label')
.attr({
'dx': 110,
'dy': -5,
'font-size': 10,
'fill': '#aaa'
})
.style('pointer-events', 'none')
.append('textPath')
.attr('xlink:href', function (d) {
return '#linkPath' + d.source.id + d.target.id;
})
.style('pointer-events', 'none')
.text(function (d) {
var linkObj = d.source['link_' + d.source.id + d.target.id];
return linkObj.relation ? linkObj.relation : 'Add relation';
});
到目前爲止,我在鏈接上添加了標籤,但其工作正常,但我需要添加功能以使它們可編輯/重命名。但我沒有找到任何相關的例子。任何機構都可以提出一個好的工作示例,以便我可以幫忙。如何在d3中的鏈接上使文本可編輯
代碼,請使其更清晰,以瞭解您的問題 –
請有在這裏看看可能會幫助你http://stackoverflow.com/a/36823304/5043867 –
@PardeepJain耆那教我在D3需要這個 –