Visualizations and dashboards for kmapper graphs using Plotly. This method is suitable for use in Jupyter notebooks.


        The generated FigureWidget can be updated (by performing a restyle or relayout). For example, let us add a title 
        to the colorbar (the name of the color function, if any),
        and set the title font size. To perform these updates faster, Plotly 3.+ provides a context manager that batches up all data and layout updates:

        To display more info on the generated kmapper-graph, define two more FigureWidget(s):  
        the global node distribution figure, and a dummy figure
        that displays info on the  algorithms involved in getting the graph from data, as well as  sklearn  class instances.

        A FigureWidget has event listeners for hovering, clicking or selecting. Using the first one for `fw_graph`
        we   define, via the function `hovering_widgets()`, widgets that display the node distribution, when the node is hovered over, and two textboxes for the cluster size and the member ids/labels of the hovered node members.



        Parameters
        -----------

        scomplex: dict
            Simplicial complex is the output from the KeplerMapper `map` method.
    
        title: str
            Title of output graphic

        graph_layout: igraph layout; 
            recommended 'kk' (kamada-kawai) or 'fr' (fruchterman-reingold)
        
        colorscale: 
             Plotly colorscale(colormap) to color graph nodes

        dashboard: bool, default is False
            If true, display complete dashboard of node information

        graph_data: bool, default is False
            If true, display graph metadata

        factor_size: double, default is 3
            a factor for the node size

        edge_linewidth : double, default is 1.5
        node_linecolor: color str, default is "rgb(200,200,200)"
        width: int, default is 600,
        height: int, default is 500,
        bgcolor: color str, default is "rgba(240, 240, 240, 0.95)",
        left: int, default is 10,
        bottom: int, default is 35,
        summary_height: int, default is 300,
        summary_width: int, default is 600, 
        summary_left: int, default is 20,
        summary_right: int, default is 20,
        hist_left: int, default is 25,
        hist_right: int, default is 25,
        member_textbox_width: int, default is 800, 
        filename: str, default is None
            if filename is given, the graphic will be saved to that file.


        Returns
        ---------
        result: plotly.FigureWidget
            A FigureWidget that can be shown or editted. See the Plotly Demo notebook for examples of use.

def plotlyviz(
    scomplex,
    colorscale=None,
    title="Kepler Mapper",
    graph_layout="kk",
    color_function=None,
    color_function_name=None,
    dashboard=False,
    graph_data=False,
    factor_size=3,
    edge_linewidth=1.5,
    node_linecolor="rgb(200,200,200)",
    width=600,
    height=500,
    bgcolor="rgba(240, 240, 240, 0.95)",
    left=10,
    bottom=35,
    summary_height=300,
    summary_width=600,
    summary_left=20,
    summary_right=20,
    hist_left=25,
    hist_right=25,
    member_textbox_width=800,
    filename=None,
):
    """
        Visualizations and dashboards for kmapper graphs using Plotly. This method is suitable for use in Jupyter notebooks.


        The generated FigureWidget can be updated (by performing a restyle or relayout). For example, let us add a title 
        to the colorbar (the name of the color function, if any),
        and set the title font size. To perform these updates faster, Plotly 3.+ provides a context manager that batches up all data and layout updates:

        To display more info on the generated kmapper-graph, define two more FigureWidget(s):  
        the global node distribution figure, and a dummy figure
        that displays info on the  algorithms involved in getting the graph from data, as well as  sklearn  class instances.

        A FigureWidget has event listeners for hovering, clicking or selecting. Using the first one for `fw_graph`
        we   define, via the function `hovering_widgets()`, widgets that display the node distribution, when the node is hovered over, and two textboxes for the cluster size and the member ids/labels of the hovered node members.



        Parameters
        -----------

        scomplex: dict
            Simplicial complex is the output from the KeplerMapper `map` method.
    
        title: str
            Title of output graphic

        graph_layout: igraph layout; 
            recommended 'kk' (kamada-kawai) or 'fr' (fruchterman-reingold)
        
        colorscale: 
             Plotly colorscale(colormap) to color graph nodes

        dashboard: bool, default is False
            If true, display complete dashboard of node information

        graph_data: bool, default is False
            If true, display graph metadata

        factor_size: double, default is 3
            a factor for the node size

        edge_linewidth : double, default is 1.5
        node_linecolor: color str, default is "rgb(200,200,200)"
        width: int, default is 600,
        height: int, default is 500,
        bgcolor: color str, default is "rgba(240, 240, 240, 0.95)",
        left: int, default is 10,
        bottom: int, default is 35,
        summary_height: int, default is 300,
        summary_width: int, default is 600, 
        summary_left: int, default is 20,
        summary_right: int, default is 20,
        hist_left: int, default is 25,
        hist_right: int, default is 25,
        member_textbox_width: int, default is 800, 
        filename: str, default is None
            if filename is given, the graphic will be saved to that file.


        Returns
        ---------
        result: plotly.FigureWidget
            A FigureWidget that can be shown or editted. See the Plotly Demo notebook for examples of use.

    """

    if not colorscale:
        colorscale = default_colorscale

    kmgraph, mapper_summary, n_color_distribution = get_mapper_graph(
        scomplex,
        colorscale=colorscale,
        color_function=color_function,
        color_function_name=color_function_name,
    )

    annotation = get_kmgraph_meta(mapper_summary)

    plgraph_data = plotly_graph(
        kmgraph,
        graph_layout=graph_layout,
        colorscale=colorscale,
        factor_size=factor_size,
        edge_linewidth=edge_linewidth,
        node_linecolor=node_linecolor,
    )

    layout = plot_layout(
        title=title,
        width=width,
        height=height,
        annotation_text=annotation,
        bgcolor=bgcolor,
        left=left,
        bottom=bottom,
    )
    result = go.FigureWidget(data=plgraph_data, layout=layout)

    if color_function_name:
        with result.batch_update():
            result.data[1].marker.colorbar.title = color_function_name
            result.data[1].marker.colorbar.titlefont.size = 10

    if dashboard or graph_data:
        fw_hist = node_hist_fig(n_color_distribution, left=hist_left, right=hist_right)
        fw_summary = summary_fig(
            mapper_summary,
            width=summary_width,
            height=summary_height,
            left=summary_left,
            right=summary_right,
        )

        fw_graph = result
        result = hovering_widgets(
            kmgraph, fw_graph, member_textbox_width=member_textbox_width
        )

        if graph_data:
            result = ipw.VBox([fw_graph, ipw.HBox([fw_summary, fw_hist])])

    if filename:
        pio.write_image(result, filename)

    return result