CDCgov / MicrobeTrace

The Visualization Multitool for Molecular Epidemiology and Bioinformatics
https://microbetrace.cdc.gov/
Apache License 2.0
88 stars 38 forks source link

Setting link length to be uniform #278

Open ikb6 opened 3 years ago

ikb6 commented 3 years ago

Would be nice to adjust the links in a network to be the same length.

AABoyles commented 3 years ago

This isn't geometrically possible. Consider a network like this:

A - B - E
 \ / \ /
  C - D

There's no way in two dimensions to connect A to E with a link that's the same distance as all the other links. The same holds true for only slightly more complex examples in three dimensions. It may be possible under our implementation of Nearest Neighbor, but I'm not certain and would need to think about the edge cases a bit. Even if it turns out to be, I think that the added complexity isn't going to be worth the effort for just NN networks.

ells commented 3 years ago

Thanks @AABoyles. The primary use case we're envisioning is mimicking BioNumerics.

This may not be geometrically possible in all cases, but we just got off of a call where we saw a live example of a 2D network with fixed lengths. That being said, I did say: "This is a feature constraint that we may need to relax due to technical reasons, so I want to set expectations."

AABoyles commented 3 years ago

One way we might be able to accomplish this is by increasing d3-force's Link Strength. That way, the physics engine would work harder to make the link lengths agree. We could add the slider to do that with minimal effort.

wje7-cdc commented 3 years ago

Thanks, Tony. I will look into it.

wje7-cdc commented 3 years ago

I tried a slider of link strength but not sure it will meet the expectation. Google around, I found this link, basically stating no built-in way to enforce a fixed length.

AABoyles commented 3 years ago

Thanks @mchiuw. That had to be the case (again, because this constraint can't be enforced globally for certain network structures), my suggestion was just a way to get closer to the mark. I'm excited to see your implementation!