Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge length? #197

Open
jordansaethre opened this issue Sep 14, 2020 · 8 comments
Open

Edge length? #197

jordansaethre opened this issue Sep 14, 2020 · 8 comments

Comments

@jordansaethre
Copy link

Is there a way to dictate how long the edges are based on the nodes that are being connected? I have been using this tool to visualize a simplicial complex that is the result of my own algorithm (not the mapper algorithm) and I want edge length to have meaning. If this is not already a feature would anyone be able to point me to the section of code that I would need to modify to make this happen? I have messed around with quite a few things, but haven't had any luck.

@deargle
Copy link
Collaborator

deargle commented Sep 14, 2020 via email

@sauln
Copy link
Member

sauln commented Sep 14, 2020

If you're okay with static graphs, the plotly visualization functionality should let you specify edge lengths. The entry point is here:

def plotlyviz(
scomplex,
colorscale=None,
title="Kepler Mapper",
graph_layout="kk",
color_values=None,
color_function_name=None,
dashboard=False,
graph_data=False,
factor_size=3,
edge_linewidth=1.5,
node_linecolor="rgb(200,200,200)",
width=600,
height=500,
bgcolor="rgba(240, 240, 240, 0.95)",
left=10,
bottom=35,
summary_height=300,
summary_width=600,
summary_left=20,
summary_right=20,
hist_left=25,
hist_right=25,
member_textbox_width=800,
filename=None,
):

Right now, it does not support supplying some sort of distance matrix, but I believe you should be able to thread a parameter all the way down to the point the graph_layout argument is used.

You might also try the networkx visualizations. They could be easier to work with.

@deargle
Copy link
Collaborator

deargle commented Sep 14, 2020

In addition to @sauln 's, suggestions, I also misspoke -- d3 force graphs do let you specify link distance, see https://github.com/d3/d3-force#link_distance . I have a PR in the works that upgrades d3 to the latest version which use the linked docs

@sauln
Copy link
Member

sauln commented Sep 14, 2020

It might be possible to overwrite the d3 force layout also..

var force = d3.layout.force()
.linkDistance(5)
.gravity(0.2)
.charge(-1200)
.size([w,h]);

You can supply a function to the linkDistance method that will instantiate the distance for each link. For an example, you can see http://bl.ocks.org/sathomas/83515b77c2764837aac2

force.linkDistance(function(link) {
  return link.graph === 0 ? height/2 : height/4;
});

Maybe instead you could do something like

force.linkDistance(function(link) {
  return link.length;
});

and then turn gravity (and probably other parameters) to 0 so the link length doesn't change?

@sauln
Copy link
Member

sauln commented Sep 14, 2020

@jordansaethre If you can get it to work, it'd be awesome to have this as a contribution to the library!

@deargle
Copy link
Collaborator

deargle commented Sep 14, 2020

@sauln I think the more recent versions of d3-force respect the link distance more than the current version does, so gravity wouldn't have to be messed with. Also, I think the concept of gravity has been replaced by charge in the latest versions. You can see some of the changes I had to make to the force layout in the most recent wip pr.

@deargle
Copy link
Collaborator

deargle commented Sep 14, 2020

To emphasize, if any work is going to be done on this, the changes between the d3-force version used in my WIP and the version on master are so drastic, that any changes to the d3 code should hold off a bit.

See 79ec3bd

@jordansaethre
Copy link
Author

@sauln @deargle I will definitely give it a shot. Thanks for the tips guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants