自从我使用这个库以来已经很长时间了,但我遇到了类似的问题。你可以做的一件事就是这个。处理边的长度,使相邻边具有不同的长度,即边长于其相邻边。这样可以避免标签重叠。您可以覆盖边和节点的渲染,如以下代码所示。
自定义边缘类型的功能没有执行上述操作,但它可以帮助您弄清楚如何覆盖渲染。您可以遍历边缘并在其上设置标志以指示要渲染的长度。例如customLength:'short'/'long'
,您可以在您的渲染器函数中访问此标志getFDEdgeType
并相应地更改长度。希望能帮助到你。
,initFD: function() {
// other stuff..... like lableType etc.
// define your own edge type
$jit.ForceDirected.Plot.EdgeTypes.implement({
'label-arrow-line': this.getFDEdgeType()
});
}
,getFDEdgeType: function() {
return {
'render':function(adj, canvas) {
// get nodes cartesian coordinates
var pos = adj.nodeFrom.pos.getc(true);
var posChild = adj.nodeTo.pos.getc(true);
// plot arrow edge
this.edgeHelper.line.render( { x: pos.x, y: pos.y }, { x: posChild.x, y: posChild.y }, canvas );
// check for edge label in data
if( adj.getData('labelid') && adj.getData('labeltext') ) {
// now adjust the label placement
var radius = this.viz.canvas.getSize();
var x = parseInt((pos.x + posChild.x - ( adj.getData('labeltext').length * 1)) / 2);
var y = parseInt((pos.y + posChild.y ) /2);
if( adj.getData('showLabel') == 'true' )
this.viz.canvas.getCtx().fillText(adj.getData('labeltext'), x, y);
else this.viz.canvas.getCtx().fillText('', x, y); // do not show label is showLabel is false
}
},
'contains': function(adj,pos){
var posFrom = adj.nodeFrom.pos.getc(true);
var posTo = adj.nodeTo.pos.getc(true);
return this.edgeHelper.line.contains({ x: posFrom.x, y: posFrom.y }, { x: posTo.x, y: posTo.y }, { x: pos.x, y: pos.y }, adj.Config.dim);
}
};
}