     if relation.source and relation.target and relation.source.visible and relation.target.visible
       console.log 'addRelationVisible'
       @data_relations_visibles.push relation
-      @linkedByIndex[relation.source_id+','+relation.target_id] = true
+      @addRelationToLinkedByIndex relation.source_id, relation.target_id
+      @setLinkIndex()
 
   # maybe we need to split removeVisibleRelationaData & removeRelationData
   removeRelationData: (relation) =>

      # Add relation to data_relations_visibles array if both nodes exist and are visibles
      if d.source and d.target and d.source.visible and d.target.visible
        @data_relations_visibles.push d
        @linkedByIndex[d.source_id+','+d.target_id] = true

    console.log 'current nodes', @data_nodes
    console.log 'current relations', @data_relations_visibles


    dx = d.target.x - d.source.x
    dy = d.target.y - d.source.y
    
    # Calculate distance between source & target positions
    dist = @parameters.relationsCurvature * Math.sqrt dx*dx + dy*dy  
    # if there are multiple links between these two nodes, we need generate different dr for each path
    if @linkedByIndex[d.source_id+','+d.target_id] > 1
      dist = dist / (1 + (1/@linkedByIndex[d.source_id+','+d.target_id]) * (d.linkindex - 1))

    # Calculate relation angle in order to draw always convex arcs & avoid relation labels facing down
    d.angle = Math.atan2(dx,dy) # *(180/Math.PI) to convert to degrees
