Graph editor

sage.graphs.graph_editor.graph_editor(graph=None, graph_name=None, replace_input=True, **layout_options)

Opens a graph editor in the Sage notebook.

INPUT:

  • graph - a Graph instance (default: graphs.CompleteGraph(2)); the graph to edit
  • graph_name - a string (default: None); the variable name to use for the updated instance; by default, this function attempts to determine the name automatically
  • replace_input - a boolean (default: True); whether to replace the text in the input cell with the updated graph data when “Save” is clicked; if this is False, the data is still evaluated as if it had been entered in the cell

EXAMPLES:

sage: g = graphs.CompleteGraph(3)
sage: graph_editor(g)                       # not tested
sage: graph_editor(graphs.HouseGraph())     # not tested
sage: graph_editor(graph_name='my_graph')   # not tested
sage: h = graphs.StarGraph(6)
sage: graph_editor(h, replace_input=False)  # not tested
sage.graphs.graph_editor.graph_to_js(g)

Returns a string representation of a Graph instance usable by the graph_editor(). The encoded information is the number of vertices, their 2D positions, and a list of edges.

INPUT:

OUTPUT:

  • a string

EXAMPLES:

sage: from sage.graphs.graph_editor import graph_to_js
sage: G = graphs.CompleteGraph(4)
sage: graph_to_js(G)
'num_vertices=4;edges=[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]];pos=[[0.5,0.0],[0.0,0.4999999999999999],[0.4999999999999999,1.0],[1.0,0.5000000000000001]];'
sage: graph_to_js(graphs.StarGraph(2))
'num_vertices=3;edges=[[0,1],[0,2]];pos=[[0.75,0.5],[1.0,0.0],[0.0,1.0]];'

Previous topic

LaTeX options for graphs

Next topic

Lists of graphs

This Page