︠2b73e029-14a7-492a-9591-466c3009de98︠ %html ︡85859d28-ee3d-4c59-bf03-c517232dad9d︡{"html": "\n\n "}︡ ︠249172b7-5c29-4a4a-9495-cc7c05e89457︠ G = graphs.DodecahedralGraph().to_directed() H = DiGraph() H.add_edges( G.edge_iterator() ); H.plot() ︡81b164bd-8cdc-492d-bc94-7dbf9c4ca9f5︡{"html": ""}︡ ︠f7367d27-8c30-4f04-a7d8-198303a5f2d0︠ graph_editor?? ︡2a000452-8e0c-40aa-aac2-78b4ad2560db︡{"html": "\n\n
\n \n

File: /sagenb/sage_install/sage-4.7/local/lib/python2.6/site-packages/sage/graphs/graph_editor.py

\n

Source Code (starting at line 77):

\n
def graph_editor(graph=None, graph_name=None,\n                 replace_input=True, **layout_options):\n    """\n    Opens a graph editor in the Sage notebook.\n\n    INPUT:\n\n    - ``graph`` - a :class:`Graph` instance (default:\n      graphs.CompleteGraph(2)); the graph to edit\n\n    - ``graph_name`` - a string (default: None); the variable name to\n      use for the updated instance; by default, this function attempts\n      to determine the name automatically\n\n    - ``replace_input`` - a boolean (default: True); whether to\n      replace the text in the input cell with the updated graph data\n      when "Save" is clicked; if this is False, the data is **still**\n      evaluated as if it had been entered in the cell\n\n    EXAMPLES::\n\n        sage: g = graphs.CompleteGraph(3)\n        sage: graph_editor(g)                       # not tested\n        sage: graph_editor(graphs.HouseGraph())     # not tested\n        sage: graph_editor(graph_name='my_graph')   # not tested\n        sage: h = graphs.StarGraph(6)\n        sage: graph_editor(h, replace_input=False)  # not tested\n    """\n    if graph is None:\n        graph = graphs.CompleteGraph(2)\n\n    if not EMBEDDED_MODE:\n        return "This graph editor only runs in the Sage notebook."\n\n    graph.layout(save_pos = True, **layout_options)\n\n    if graph_name is None:\n        graph_name = ''\n        locs = sys._getframe(1).f_locals\n        for var in locs:\n            if id(locs[var]) == id(graph):\n                graph_name = var\n\n    cell_id = sagenb.notebook.interact.SAGE_CELL_ID\n\n    # TODO: Put reasonable checks for large graphs, before disaster\n    # occurs (i.e., breaks browser).\n\n    close_button = r"""<button onclick="cell_delete_output(%(cell_id)s);">Close</button>""" % locals()\n\n    if replace_input:\n        eval_strategy = r"""\n    f += ' graph_editor(' + g[2] + ');'\n    \\$('#cell_input_%(cell_id)s').val(f);\n    cell_input_resize(%(cell_id)s);\n    evaluate_cell(%(cell_id)s, false);\n""" % locals()\n    else:\n        eval_strategy = r"""\n    saved_input = \\$('#cell_input_%(cell_id)s').val();\n    \\$('#cell_input_%(cell_id)s').val(f);\n    evaluate_cell(%(cell_id)s, false);\n    \\$('#cell_input_%(cell_id)s').val(saved_input);\n    send_cell_input(%(cell_id)s);\n    cell_input_resize(%(cell_id)s);\n""" % locals()\n\n    update_button = r"""<button onclick="\n    var f, g, saved_input;\n    g = \\$('#iframe_graph_editor_%(cell_id)s')[0].contentWindow.update_sage();\n\n    if (g[2] === '') {\n        alert('You need to give a Sage variable name to the graph, before saving it.');\n        return;\n    }\n    f = g[2] + ' = Graph(' + g[0] + '); ' + g[2] + '.set_pos(' + g[1] + '); '\n    %(eval_strategy)s\n">Save</button>""" % locals()\n\n    graph_js = graph_to_js(graph)\n    data_fields = """<input type="hidden" id="graph_data_%(cell_id)s" value="%(graph_js)s"><input type="hidden" id="graph_name_%(cell_id)s" value="%(graph_name)s">""" % locals()\n\n    return html(r"""<div id="graph_editor_%(cell_id)s"><table><tbody>\n      <tr><td><iframe style="width: 800px; height: 400px; border: 0;" id="iframe_graph_editor_%(cell_id)s" src="/javascript/graph_editor/graph_editor.html?cell_id=%(cell_id)s"></iframe>%(data_fields)s</td></tr>\n      <tr><td>%(update_button)s%(close_button)s</td></tr>\n</tbody></table></div>""" % locals())\n
\n
\n\n\n
\n"}︡ ︠c76f1347-5c38-40eb-bd79-cae6e4140ca5︠ graph_editor(H) ︡f266150f-d82e-4600-8b96-76ac19ab346c︡︡ ︠ff92664c-386e-4e7b-986f-7b728fcefe16︠ from sagenb.notebook.js import javascript s = javascript() ︡18797413-7118-44e8-900e-3b5e646ecb61︡︡