PyGraphVisual – Reference Guide

This guide is for versions 1.0 Release Candidate 0+

Source code

Class PyGraphVisual

    Facilitate data preparation for graph visualization using the Cytoscape.js library
    
nameargumentsreturns
__init__db=None

nameargumentsreturns
__str__selfstr
        Return an overview description of this object

        :return:    A string with a description of this object
        
nameargumentsreturns
serializeselfdict
        Extract and return a dict of relevent data from this object

        :return:
        
nameargumentsreturns
get_graph_dataselfdict
        Return a data dictionary with all the relevant visualization info
        (typically, to pass to the front-end, for eventual use by the Cytoscape.js library)

        :return:    A dict with 3 keys - "structure", "color_mapping" and "caption_mapping"
        
nameargumentsreturns
add_nodenode_id :Union[int,str], labels="", data=NoneNone
        Prepare and store the data for 1 node, in a format expected by the visualization front-end

        EXAMPLE:    {'id': 1, 'name': 'Julian', 'labels': ['PERSON']}

        :param node_id:         Either an integer or a string to uniquely identify this node in the graph;
                                    it will be used to specify the start/end nodes of edges.
                                    Typically, use either the internal database ID, or some URI
                                    Records with a duplicate node_id are silently disregarded
        :param labels:          A string, or list of strings, with the node's label(s) used in the graph database;
                                    if not used, pass an empty string
        :param data:            A dict with all other node data not already specified in any of the other arguments
        :return:                None
        
nameargumentsreturns
add_edgefrom_node :Union[str, int], to_node :Union[str, int], name :str, edge_id=None, data=NoneNone
        Prepare and store the data for 1 edge, in a format expected by the visualization front-end.

        EXAMPLE:   {'name': 'OWNS', 'source': 1, 'target': 2, 'id': 'edge-1'}

        Note that 'id', in this context, is whatever we pass to the visualization module for the nodes;
        not necessarily related to the internal database ID's

        :param from_node:   Integer or a string uniquely identify the "id" of the node where the edge originates
        :param to_node:     Integer or a string uniquely identify the "id" of the node where the edge ends
        :param name:        Name of the relationship
        :param edge_id:     (OPTIONAL)  If not provided, strings such as "edge-123" are used,
                                        with auto-generated consecutive integers
        :param data:        A dict with all other node data not already specified in any of the other arguments

        :return:            None
        
nameargumentsreturns
assign_captionlabel :str, caption="name"None
        Assign and store a mapping from label name to caption (name of field to use on the display)

        EXAMPLES:   assign_caption(label='PERSON', caption='name')
                    assign_caption(label='CAR', caption='color')

        :param label:   The name of a node label
        :param caption: The name of the node field to use on the display (by default, "name")
        :return:        None
        
nameargumentsreturns
assign_color_mappinglabel :str, color :strNone
        Assign and store a mapping from label name to color to use for nodes having that label

        :param label:   The name of a node label
        :param color:   The name (hex string or standard CSS name) of the color to use on the display
        :return:        None
        
nameargumentsreturns
prepare_graphresult_dataset :[dict], add_edges=True[int]
        Given a list of dictionary data about graph-database nodes - for example,
        as returned by NeoAccess.get_nodes() - construct and save visualization data for them.

        Each dictionary entry is expected to have a key named "internal_id";
        if not present, it will be silently ignored.
        Though not required, a key named "neo4j_labels" is typically present as well.

        :param result_dataset:  A list of dictionary data about graph-database nodes
        :param add_edges:       If True, all existing edges among the displayed nodes
                                    will also be part of the visualization
        :return:                A list of integers with the internal databased IDs
                                    of all the nodes added to the graph structure
        
nameargumentsreturns
link_node_groupsgroup1 :[int], group2 :[int]None
        Search the database for any edges from any of the nodes in the 1st group, to any node in the 2nd group.
        Any located edge will be added to the visualization data stored in this object

        :param group1:  List of integers with the internal databased IDs of the 1st group of nodes
        :param group2:  List of integers with the internal databased IDs of the 2nd group of nodes
        :return:        None