Skip to content

How to stop automatic charge action (repelling) when manually repositioning node-link objects #312

@k-blenman

Description

@k-blenman

Thank you for your wonderful tool. I have the following simple script example:

# Load necessary libraries
library(networkD3)
# Sample data for disjointed links
links <- data.frame(
  source = c("spaghetti", "vermicelli", "macaroni", "linguini", "angel_hair", "rainbow", "bow_tie", "orange", "orange"),
  target = c("apple", "pear", "pear", "orange", "grape", "grapefruit", "mango", "cherry", "blueberries")
)
# Prepare nodes data frame to use name as node ID
nodes <- data.frame(name = unique(c(links$source, links$target)))
# Create the force network
network <- simpleNetwork(Data = links, Source = "source", Target = "target", height = 10, width = 10, linkDistance = 30, charge = -15, fontSize = 12, opacity = 5.0, zoom = TRUE)
# Save the network with the custom script
saveNetwork(network, file = "Example.html")

It results in a graph that has node text labels that overlap with nodes, link lines, and other text. Some of this can be resolved by manually repositioning the node link objects in question. However, every time you move anything in the canvas area even slightly it repels all node-link objects on the canvas. When there is a large number of node-link objects (>50), this expands the canvas to unreasonable proportions. This looks to be a function of the charge attribute. It is fully understood why this type of charge action would be useful. However, it would be helpful if there were some limits to this function.

With that said, is it possible to incorporate the same functionalities and constraints that we see in the D3 Disjoint force-directed graphs (https://observablehq.com/@d3/disjoint-force-directed-graph/2) into your tool? This will (1) allow the individual node-link objects (i.e., subgraphs) to be manually moved around with minimal impact to other node-link objects on the canvas, (2) prevent node-link objects from moving outside the field of view area, and (3) allow greater flexibility in shape and form of manual movements and placement of individual node-link objects to potentially reduce node text overlap with other nodes, link lines, and other text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions