def graph_to_js(g):
    """
    Returns a string representation of a :class:`Graph` instance
    usable by the :func:`graph_editor`.  The encoded information is
    the number of vertices, their 2D positions, and a list of edges.

    INPUT:

    - ``g`` - a :class:`Graph` instance

    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]];'
    """
    string = ''
    vertex_list = g.get_vertices().keys()
    string += 'num_vertices=' + str(len(vertex_list)) + ';'
    string += 'edges=['
    for i, e in enumerate(g.edges()):
        if(i != 0):
            string += ','
        string += '[' + str(vertex_list.index(e[0])) + ',' + str(vertex_list.index(e[1])) + ']'
    string += '];'
    string += 'pos=['
    pos = g.get_pos()
    max_x = max([i[0] for i in pos.values()])
    max_y = max([i[1] for i in pos.values()])
    min_x = min([i[0] for i in pos.values()])
    min_y = min([i[1] for i in pos.values()])
    if max_x == 0:
        max_x = 1
    if max_y == 0:
        max_y = 1
    for i, v in enumerate(vertex_list):
        if(i != 0):
            string += ','
        new_pos = [float(pos[v][0] - min_x) / (max_x - min_x),
                   1.0 - float(pos[v][1] - min_y) / (max_y - min_y)]
        string += str(new_pos)
    string += '];'
    string = string.replace(' ', '')
    return string