openmdao/devtools/problem_viewer/problem_viewer.py
def view_model(data_source, outfile='n2.html', show_browser=True, embeddable=False,
               draw_potential_connections=True):
    """
    Generates an HTML file containing a tree viewer.

    Optionally opens a web browser to view the file.

    Parameters
    ----------
    data_source : <Problem> or str
        The Problem or case recorder database containing the model or model data.

    outfile : str, optional
        The name of the final output file

    show_browser : bool, optional
        If True, pop up the system default web browser to view the generated html file.
        Defaults to True.

    embeddable : bool, optional
        If True, gives a single HTML file that doesn't have the <html>, <DOCTYPE>, <body>
        and <head> tags. If False, gives a single, standalone HTML file for viewing.

    draw_potential_connections : bool, optional
        If true, allows connections to be drawn on the N2 that do not currently exist
        in the model. Defaults to True.
    """
    # grab the model viewer data
    model_viewer_data = _get_viewer_data(data_source)
    model_viewer_data = 'var modelData = %s' % json.dumps(model_viewer_data)

    # if MPI is active only display one copy of the viewer
    if MPI and MPI.COMM_WORLD.rank != 0:
        return

    html_begin_tags = """
                      <html>
                      <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                      </head>
                      <body>\n
                      """
    html_end_tags = """
                    </body>
                    </html>
                    """

    code_dir = os.path.dirname(os.path.abspath(__file__))
    vis_dir = os.path.join(code_dir, "visualization")
    libs_dir = os.path.join(vis_dir, "libs")
    src_dir = os.path.join(vis_dir, "src")
    style_dir = os.path.join(vis_dir, "style")

    # grab the libraries
    with open(os.path.join(libs_dir, "awesomplete.js"), "r") as f:
        awesomplete = f.read()
    with open(os.path.join(libs_dir, "d3.v4.min.js"), "r") as f:
        d3 = f.read()
    with open(os.path.join(libs_dir, "vkBeautify.js"), "r") as f:
        vk_beautify = f.read()

    # grab the src
    with open(os.path.join(src_dir, "constants.js"), "r") as f:
        constants = f.read()
    with open(os.path.join(src_dir, "draw.js"), "r") as f:
        draw = f.read()
    with open(os.path.join(src_dir, "legend.js"), "r") as f:
        legend = f.read()
    with open(os.path.join(src_dir, "modal.js"), "r") as f:
        modal = f.read()
    with open(os.path.join(src_dir, "ptN2.js"), "r") as f:
        pt_n2 = f.read()
    with open(os.path.join(src_dir, "search.js"), "r") as f:
        search = f.read()
    with open(os.path.join(src_dir, "svg.js"), "r") as f:
        svg = f.read()

    # grab the style
    with open(os.path.join(style_dir, "awesomplete.css"), "r") as f:
        awesomplete_style = f.read()
    with open(os.path.join(style_dir, "partition_tree.css"), "r") as f:
        partition_tree_style = f.read()
    with open(os.path.join(style_dir, "fontello.woff"), "rb") as f:
        encoded_font = str(base64.b64encode(f.read()).decode("ascii"))

    # grab the index.html
    with open(os.path.join(vis_dir, "index.html"), "r") as f:
        index = f.read()

    # add the necessary HTML tags if we aren't embedding
    if not embeddable:
        index = html_begin_tags + index + html_end_tags

    # put all style and JS into index
    index = index.replace('{{awesomplete_style}}', awesomplete_style)
    index = index.replace('{{partition_tree_style}}', partition_tree_style)
    index = index.replace('{{fontello}}', encoded_font)
    index = index.replace('{{d3_lib}}', d3)
    index = index.replace('{{awesomplete_lib}}', awesomplete)
    index = index.replace('{{vk_beautify_lib}}', vk_beautify)
    index = index.replace('{{model_data}}', model_viewer_data)
    index = index.replace('{{constants_lib}}', constants)
    index = index.replace('{{modal_lib}}', modal)
    index = index.replace('{{svg_lib}}', svg)
    index = index.replace('{{search_lib}}', search)
    index = index.replace('{{legend_lib}}', legend)
    index = index.replace('{{draw_lib}}', draw)
    index = index.replace('{{ptn2_lib}}', pt_n2)
    if draw_potential_connections:
        index = index.replace('{{draw_potential_connections}}', 'true')
    else:
        index = index.replace('{{draw_potential_connections}}', 'false')

    with open(outfile, 'w') as f:
        f.write(index)

    # open it up in the browser
    if show_browser:
        from openmdao.devtools.webview import webview
        webview(outfile)

    Generates an HTML file containing a tree viewer.

    Optionally opens a web browser to view the file.

    Parameters
    ----------
    data_source : <Problem> or str
        The Problem or case recorder database containing the model or model data.

    outfile : str, optional
        The name of the final output file

    show_browser : bool, optional
        If True, pop up the system default web browser to view the generated html file.
        Defaults to True.

    embeddable : bool, optional
        If True, gives a single HTML file that doesn't have the <html>, <DOCTYPE>, <body>
        and <head> tags. If False, gives a single, standalone HTML file for viewing.

    draw_potential_connections : bool, optional
        If true, allows connections to be drawn on the N2 that do not currently exist
        in the model. Defaults to True.
    
Generates an HTML file containing a tree viewer.
Optionally opens a web browser to view the file.

Parameters

data_source :  or str
The Problem or case recorder database containing the model or model data.

outfile : str, optional
The name of the final output file

show_browser : bool, optional
If True, pop up the system default web browser to view the generated html file.
Defaults to True.

embeddable : bool, optional
If True, gives a single HTML file that doesn't have the , , 
and  tags. If False, gives a single, standalone HTML file for viewing.

draw_potential_connections : bool, optional
If true, allows connections to be drawn on the N2 that do not currently exist
in the model. Defaults to True.
Generates an HTML file containing a tree viewer . Optionally opens a web browser to view the file . Parameters data_source : or str The Problem or case recorder database containing the model or model data . outfile : str optional The name of the final output file show_browser : bool optional If True pop up the system default web browser to view the generated html file . Defaults to True . embeddable : bool optional If True gives a single HTML file that doesn ' t have the and tags . If False gives a single standalone HTML file for viewing . draw_potential_connections : bool optional If true allows connections to be drawn on the N2 that do not currently exist in the model . Defaults to True .
def view_model(data_source, outfile='n2.html', show_browser=True, embeddable=False,
               draw_potential_connections=True):
    model_viewer_data = _get_viewer_data(data_source)
    model_viewer_data = 'var modelData = %s' % json.dumps(model_viewer_data)
    if MPI and MPI.COMM_WORLD.rank != 0:
        return
    html_begin_tags = """
                      <html>
                      <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                      </head>
                      <body>\n
                      """
    html_end_tags = """
                    </body>
                    </html>
                    """
    code_dir = os.path.dirname(os.path.abspath(__file__))
    vis_dir = os.path.join(code_dir, "visualization")
    libs_dir = os.path.join(vis_dir, "libs")
    src_dir = os.path.join(vis_dir, "src")
    style_dir = os.path.join(vis_dir, "style")
    with open(os.path.join(libs_dir, "awesomplete.js"), "r") as f:
        awesomplete = f.read()
    with open(os.path.join(libs_dir, "d3.v4.min.js"), "r") as f:
        d3 = f.read()
    with open(os.path.join(libs_dir, "vkBeautify.js"), "r") as f:
        vk_beautify = f.read()
    with open(os.path.join(src_dir, "constants.js"), "r") as f:
        constants = f.read()
    with open(os.path.join(src_dir, "draw.js"), "r") as f:
        draw = f.read()
    with open(os.path.join(src_dir, "legend.js"), "r") as f:
        legend = f.read()
    with open(os.path.join(src_dir, "modal.js"), "r") as f:
        modal = f.read()
    with open(os.path.join(src_dir, "ptN2.js"), "r") as f:
        pt_n2 = f.read()
    with open(os.path.join(src_dir, "search.js"), "r") as f:
        search = f.read()
    with open(os.path.join(src_dir, "svg.js"), "r") as f:
        svg = f.read()
    with open(os.path.join(style_dir, "awesomplete.css"), "r") as f:
        awesomplete_style = f.read()
    with open(os.path.join(style_dir, "partition_tree.css"), "r") as f:
        partition_tree_style = f.read()
    with open(os.path.join(style_dir, "fontello.woff"), "rb") as f:
        encoded_font = str(base64.b64encode(f.read()).decode("ascii"))
    with open(os.path.join(vis_dir, "index.html"), "r") as f:
        index = f.read()
    if not embeddable:
        index = html_begin_tags + index + html_end_tags
    index = index.replace('{{awesomplete_style}}', awesomplete_style)
    index = index.replace('{{partition_tree_style}}', partition_tree_style)
    index = index.replace('{{fontello}}', encoded_font)
    index = index.replace('{{d3_lib}}', d3)
    index = index.replace('{{awesomplete_lib}}', awesomplete)
    index = index.replace('{{vk_beautify_lib}}', vk_beautify)
    index = index.replace('{{model_data}}', model_viewer_data)
    index = index.replace('{{constants_lib}}', constants)
    index = index.replace('{{modal_lib}}', modal)
    index = index.replace('{{svg_lib}}', svg)
    index = index.replace('{{search_lib}}', search)
    index = index.replace('{{legend_lib}}', legend)
    index = index.replace('{{draw_lib}}', draw)
    index = index.replace('{{ptn2_lib}}', pt_n2)
    if draw_potential_connections:
        index = index.replace('{{draw_potential_connections}}', 'true')
    else:
        index = index.replace('{{draw_potential_connections}}', 'false')
    with open(outfile, 'w') as f:
        f.write(index)
    if show_browser:
        from openmdao.devtools.webview import webview
        webview(outfile)
def view_model ( data_source , outfile = 'n2.html' , show_browser = True , embeddable = False , draw_potential_connections = True ) : model_viewer_data = _get_viewer_data ( data_source ) model_viewer_data = 'var modelData = %s' % json . dumps ( model_viewer_data ) if MPI and MPI . COMM_WORLD . rank != 0 : return html_begin_tags = """
                      <html>
                      <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                      </head>
                      <body>\n
                      """ html_end_tags = """
                    </body>
                    </html>
                    """ code_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) vis_dir = os . path . join ( code_dir , "visualization" ) libs_dir = os . path . join ( vis_dir , "libs" ) src_dir = os . path . join ( vis_dir , "src" ) style_dir = os . path . join ( vis_dir , "style" ) with open ( os . path . join ( libs_dir , "awesomplete.js" ) , "r" ) as f : awesomplete = f . read ( ) with open ( os . path . join ( libs_dir , "d3.v4.min.js" ) , "r" ) as f : d3 = f . read ( ) with open ( os . path . join ( libs_dir , "vkBeautify.js" ) , "r" ) as f : vk_beautify = f . read ( ) with open ( os . path . join ( src_dir , "constants.js" ) , "r" ) as f : constants = f . read ( ) with open ( os . path . join ( src_dir , "draw.js" ) , "r" ) as f : draw = f . read ( ) with open ( os . path . join ( src_dir , "legend.js" ) , "r" ) as f : legend = f . read ( ) with open ( os . path . join ( src_dir , "modal.js" ) , "r" ) as f : modal = f . read ( ) with open ( os . path . join ( src_dir , "ptN2.js" ) , "r" ) as f : pt_n2 = f . read ( ) with open ( os . path . join ( src_dir , "search.js" ) , "r" ) as f : search = f . read ( ) with open ( os . path . join ( src_dir , "svg.js" ) , "r" ) as f : svg = f . read ( ) with open ( os . path . join ( style_dir , "awesomplete.css" ) , "r" ) as f : awesomplete_style = f . read ( ) with open ( os . path . join ( style_dir , "partition_tree.css" ) , "r" ) as f : partition_tree_style = f . read ( ) with open ( os . path . join ( style_dir , "fontello.woff" ) , "rb" ) as f : encoded_font = str ( base64 . b64encode ( f . read ( ) ) . decode ( "ascii" ) ) with open ( os . path . join ( vis_dir , "index.html" ) , "r" ) as f : index = f . read ( ) if not embeddable : index = html_begin_tags + index + html_end_tags index = index . replace ( '{{awesomplete_style}}' , awesomplete_style ) index = index . replace ( '{{partition_tree_style}}' , partition_tree_style ) index = index . replace ( '{{fontello}}' , encoded_font ) index = index . replace ( '{{d3_lib}}' , d3 ) index = index . replace ( '{{awesomplete_lib}}' , awesomplete ) index = index . replace ( '{{vk_beautify_lib}}' , vk_beautify ) index = index . replace ( '{{model_data}}' , model_viewer_data ) index = index . replace ( '{{constants_lib}}' , constants ) index = index . replace ( '{{modal_lib}}' , modal ) index = index . replace ( '{{svg_lib}}' , svg ) index = index . replace ( '{{search_lib}}' , search ) index = index . replace ( '{{legend_lib}}' , legend ) index = index . replace ( '{{draw_lib}}' , draw ) index = index . replace ( '{{ptn2_lib}}' , pt_n2 ) if draw_potential_connections : index = index . replace ( '{{draw_potential_connections}}' , 'true' ) else : index = index . replace ( '{{draw_potential_connections}}' , 'false' ) with open ( outfile , 'w' ) as f : f . write ( index ) if show_browser : from openmdao . devtools . webview import webview webview ( outfile )
Generates an HTML file containing a tree viewer.
Generates an HTML file containing a tree viewer .
"""
    Generates an HTML file containing a tree viewer.

    Optionally opens a web browser to view the file.

    Parameters
    ----------
    data_source : <Problem> or str
        The Problem or case recorder database containing the model or model data.

    outfile : str, optional
        The name of the final output file

    show_browser : bool, optional
        If True, pop up the system default web browser to view the generated html file.
        Defaults to True.

    embeddable : bool, optional
        If True, gives a single HTML file that doesn't have the <html>, <DOCTYPE>, <body>
        and <head> tags. If False, gives a single, standalone HTML file for viewing.

    draw_potential_connections : bool, optional
        If true, allows connections to be drawn on the N2 that do not currently exist
        in the model. Defaults to True.
    """ # grab the model viewer data # if MPI is active only display one copy of the viewer # grab the libraries # grab the src # grab the style # grab the index.html # add the necessary HTML tags if we aren't embedding # put all style and JS into index # open it up in the browser
data_source
outfile
show_browser
embeddable
draw_potential_connections