Generate a visualization of the simplicial complex mapper output. Turns the complex dictionary into a HTML/D3.js visualization

        Parameters
        ----------
        graph : dict
            Simplicial complex output from the `map` method.

        color_function : list or 1d array
            A 1d vector with length equal to number of data points used to build Mapper. Each value should correspond to a value for each data point and color of node is computed as the average value for members in a node.

        path_html : String
            file name for outputing the resulting html.

        custom_meta: dict
            Render (key, value) in the Mapper Summary pane. 

        custom_tooltip: list or array like
            Value to display for each entry in the node. The cluster data pane will display entry for all values in the node. Default is index of data.

        save_file: bool, default is True
            Save file to `path_html`.

        X: numpy arraylike
            If supplied, compute statistics information about the original data source with respect to each node.

        X_names: list of strings
            Names of each variable in `X` to be displayed. If None, then display names by index.

        lens: numpy arraylike
            If supplied, compute statistics of each node based on the projection/lens

        lens_name: list of strings
            Names of each variable in `lens` to be displayed. In None, then display names by index.

        show_tooltips: bool, default is True.
            If false, completely disable tooltips. This is useful when using output in space-tight pages or will display node data in custom ways.

        nbins: int, default is 10
            Number of bins shown in histogram of tooltip color distributions.

        Returns
        --------
        html: string
            Returns the same html that is normally output to `path_html`. Complete graph and data ready for viewing.

        Examples
        ---------

        >>> # Basic creation of a `.html` file at `kepler-mapper-output.html`
        >>> html = mapper.visualize(graph, path_html="kepler-mapper-output.html")

        >>> # Jupyter Notebook support
        >>> from kmapper import jupyter
        >>> html = mapper.visualize(graph, path_html="kepler-mapper-output.html")
        >>> jupyter.display(path_html="kepler-mapper-output.html")

        >>> # Customizing the output text
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_meta={"Description":"A short description.",
        >>>                  "Cluster": "HBSCAN()"}
        >>> )

        >>> # Custom coloring function based on your 1d lens
        >>> html = mapper.visualize(
        >>>     graph,
        >>>     color_function=lens
        >>> )

        >>> # Custom coloring function based on the first variable
        >>> cf = mapper.project(X, projection=[0])
        >>> html = mapper.visualize(
        >>>     graph,
        >>>     color_function=cf
        >>> )

        >>> # Customizing the tooltips with binary target variables
        >>> X, y = split_data(df)
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_tooltips=y
        >>> )

        >>> # Customizing the tooltips with html-strings: locally stored images of an image dataset
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_tooltips=np.array(
        >>>             ["<img src='img/%s.jpg'>"%i for i in range(inverse_X.shape[0])]
        >>>     )
        >>> )

def visualize(
        self,
        graph,
        color_function=None,
        custom_tooltips=None,
        custom_meta=None,
        path_html="mapper_visualization_output.html",
        title="Kepler Mapper",
        save_file=True,
        X=None,
        X_names=None,
        lens=None,
        lens_names=None,
        show_tooltips=True,
        nbins=10,
    ):
        """Generate a visualization of the simplicial complex mapper output. Turns the complex dictionary into a HTML/D3.js visualization

        Parameters
        ----------
        graph : dict
            Simplicial complex output from the `map` method.

        color_function : list or 1d array
            A 1d vector with length equal to number of data points used to build Mapper. Each value should correspond to a value for each data point and color of node is computed as the average value for members in a node.

        path_html : String
            file name for outputing the resulting html.

        custom_meta: dict
            Render (key, value) in the Mapper Summary pane. 

        custom_tooltip: list or array like
            Value to display for each entry in the node. The cluster data pane will display entry for all values in the node. Default is index of data.

        save_file: bool, default is True
            Save file to `path_html`.

        X: numpy arraylike
            If supplied, compute statistics information about the original data source with respect to each node.

        X_names: list of strings
            Names of each variable in `X` to be displayed. If None, then display names by index.

        lens: numpy arraylike
            If supplied, compute statistics of each node based on the projection/lens

        lens_name: list of strings
            Names of each variable in `lens` to be displayed. In None, then display names by index.

        show_tooltips: bool, default is True.
            If false, completely disable tooltips. This is useful when using output in space-tight pages or will display node data in custom ways.

        nbins: int, default is 10
            Number of bins shown in histogram of tooltip color distributions.

        Returns
        --------
        html: string
            Returns the same html that is normally output to `path_html`. Complete graph and data ready for viewing.

        Examples
        ---------

        >>> # Basic creation of a `.html` file at `kepler-mapper-output.html`
        >>> html = mapper.visualize(graph, path_html="kepler-mapper-output.html")

        >>> # Jupyter Notebook support
        >>> from kmapper import jupyter
        >>> html = mapper.visualize(graph, path_html="kepler-mapper-output.html")
        >>> jupyter.display(path_html="kepler-mapper-output.html")

        >>> # Customizing the output text
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_meta={"Description":"A short description.",
        >>>                  "Cluster": "HBSCAN()"}
        >>> )

        >>> # Custom coloring function based on your 1d lens
        >>> html = mapper.visualize(
        >>>     graph,
        >>>     color_function=lens
        >>> )

        >>> # Custom coloring function based on the first variable
        >>> cf = mapper.project(X, projection=[0])
        >>> html = mapper.visualize(
        >>>     graph,
        >>>     color_function=cf
        >>> )

        >>> # Customizing the tooltips with binary target variables
        >>> X, y = split_data(df)
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_tooltips=y
        >>> )

        >>> # Customizing the tooltips with html-strings: locally stored images of an image dataset
        >>> html = mapper.visualize(
        >>>     graph, 
        >>>     path_html="kepler-mapper-output.html",
        >>>     title="Fashion MNIST with UMAP",
        >>>     custom_tooltips=np.array(
        >>>             ["<img src='img/%s.jpg'>"%i for i in range(inverse_X.shape[0])]
        >>>     )
        >>> )

        """

        # TODO:
        #   - Make color functions more intuitive. How do they even work?
        #   - Allow multiple color functions that can be toggled on and off.

        if not len(graph["nodes"]) > 0:
            raise Exception(
                "Visualize requires a mapper with more than 0 nodes. \nIt is possible that the constructed mapper could have been constructed with bad parameters. This can occasionally happens when using the default clustering algorithm. Try changing `eps` or `min_samples` in the DBSCAN clustering algorithm."
            )

        # Find the module absolute path and locate templates
        module_root = os.path.join(os.path.dirname(__file__), "templates")
        env = Environment(loader=FileSystemLoader(module_root))
        # Color function is a vector of colors?
        color_function = init_color_function(graph, color_function)

        if X_names is None:
            X_names = []

        if lens_names is None:
            lens_names = []

        mapper_data = format_mapper_data(
            graph,
            color_function,
            X,
            X_names,
            lens,
            lens_names,
            custom_tooltips,
            env,
            nbins,
        )

        colorscale = colorscale_default

        histogram = graph_data_distribution(graph, color_function, colorscale)

        mapper_summary = format_meta(graph, custom_meta)

        # Find the absolute module path and the static files
        js_path = os.path.join(os.path.dirname(__file__), "static", "kmapper.js")
        with open(js_path, "r") as f:
            js_text = f.read()

        css_path = os.path.join(os.path.dirname(__file__), "static", "style.css")
        with open(css_path, "r") as f:
            css_text = f.read()

        # Render the Jinja template, filling fields as appropriate
        template = env.get_template("base.html").render(
            title=title,
            mapper_summary=mapper_summary,
            histogram=histogram,
            dist_label="Node",
            mapper_data=mapper_data,
            colorscale=colorscale,
            js_text=js_text,
            css_text=css_text,
            show_tooltips=True,
        )

        if save_file:
            with open(path_html, "wb") as outfile:
                if self.verbose > 0:
                    print("Wrote visualization to: %s" % (path_html))
                outfile.write(template.encode("utf-8"))

        return template