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

new functionality: set focus on creation #13

Open
pchtsp opened this issue May 23, 2024 · 0 comments
Open

new functionality: set focus on creation #13

pchtsp opened this issue May 23, 2024 · 0 comments

Comments

@pchtsp
Copy link

pchtsp commented May 23, 2024

I work with networkx and I use the layout produced by it. The problem is that when the graph is produced in my notebook, the image is not centered and I cannot control where I want the zoom/view to start. I figure out that it tries to show the origin of coordinates (0, 0) and so now I modify the positions coming from networkx so that they're positioned around the (0, 0) coordinate.

Instead of this hack, maybe it could be useful to pass an argument to the gv.d3 function with the coordinates to display by default on the creation of the graph?

I guess this is only useful when someone is setting the coordinates manually as I'm doing.

Example:

G = my_instance.create_scenario_tree()
pos = nx.drawing.nx_pydot.graphviz_layout(G, prog="dot")

def prepare_graph(g):
  g = g.copy()
  x_coord = {v[1] for v in pos.values()}
  y_coord = {v[0] for v in pos.values()}
  max_y, min_y = max(y_coord), min(y_coord)
  max_x, min_x = max(x_coord), min(x_coord)

  for node_id in g.nodes:
    node = g.nodes[node_id]
    node['x'] = (-pos[node_id][1] + (max_x-min_x)/2)*4
    node['y'] = (pos[node_id][0] - (max_y-min_y)/2)/3
  return g


gv.d3(prepare_graph(G), zoom_factor=0.2, node_label_size_factor=3, show_node_label_border=True, graph_height=500, layout_algorithm_active=False)
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

1 participant