| name | arguments | returns |
| export_plot | graph_data :dict, graphic_component :str,
filename :str, caption="Interactive network plot",
vue_comps_dir="https://life123.science/libraries/vue_components/" | None |
Send to the given file the HTML data to create a Vue-based display of a network.
This is meant to work alongside a Vue.js component that expects 2 arguments ("props"):
1) graph_data
2) component_id
:param graph_data: A python dictionary of data to pass to the Vue component.
It must contain 3 keys:
'structure' A list of dicts
EXAMPLE (two nodes followed by an edge):
[{'id': 1, '_node_labels': ['PERSON'], 'name': 'Julian'},
{'id': 2, '_node_labels': ['CAR'], 'color': 'white'},
{'id': 'edge-1', 'source': 1, 'target': 2, 'name': 'OWNS'}]
Note: 'id' values can be integers or strings
'color_mapping' A dict
EXAMPLE: {"label_1": "#8DCC92", "label_2": "#D9C8AD"}
'caption_mapping' A dict
EXAMPLE: {"label_1": "name", "label_2": "name"}
:param graphic_component: The basename of a existing JavaScript and CSS files a
that provides the interactive visualization functionality.
The JS file is expected to implement a Vue.js component by the same name
(but with hyphens in lieu of any underscore in the name, if applicable.)
EXAMPLE: "vue_cytoscape_4" (assuming that a "vue_cytoscape_4.js" file
and a "vue_cytoscape_4.css" file
exist in the directory specified by the argument `vue_comps_dir`,
and that the .js file implements a Vue component named "vue-cytoscape-4")
:param filename: The name of the file into which to place the HTML code
to create the interactive network plot.
The suffix ".htm" will be added if it doesn't end with ".htm" or ".html"
If the file already exists, it will get overwritten.
(Note: this file will automatically include an internal reference to the JavaScript
file specified in `graphic_component`)
:param caption: [OPTIONAL] String displayed at the top of the HTML file.
By default, "Interactive network plot"
:param vue_comps_dir: [OPTIONAL] The full name of the directory where the Vue components reside.
A final "/" in the name is optional.
Note: when this function is used in a Jupyterlab notebook, it's best to use
a URL. EXAMPLE: "https://life123.science/libraries/vue_components/"
:return: None
|
| name | arguments | returns |
| get_graph_data | | dict |
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"
For more details, see object constructor
|
| name | arguments | returns |
| add_node | node_id :int|str, labels="", properties=None | None |
From the given data about a database node, assemble and cumulatively store the data
in a format expected by Cytoscape.js (the visualization front-end).
Calls with a duplicate node_id are silently disregarded.
NO database operation is performed. You need to first extract, or have on hand, that node data.
EXAMPLE: given a call to: add_node(node_id=1, labels=['PERSON'], data={'name': 'Julian'})
then the internal format, cumulatively added to self.structure, will be:
{'id': 1, '_node_labels': ['PERSON'], 'name': 'Julian'}
: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 properties: A dict with all the node properties of interest
:return: None
|
| name | arguments | returns |
| add_edge | from_node :str|int, to_node :str|int,
name :str, edge_id=None, properties=None | None |
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 properties: A dict with all the edge properties of interest
:return: None
|
| name | arguments | returns |
| assign_caption | label :str, caption="name" | None |
Incrementally assign and store a mapping from label name to caption (name of field to use on the display).
Additional calls to this function will register further assignments.
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
|
| name | arguments | returns |
| assign_color_mapping | label :str, color :str | None |
Incrementally assign and store a mapping from label name to color to use for nodes having that label.
Additional calls to this function will register further assignments.
EXAMPLES: assign_color_mapping(label='PERSON', color='purple')
assign_color_mapping(label='CAR', color='#FF0088')
: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,
OR one of the non-standard names provided by this class,
in the object variable self.EXTRA_COLORS
:return: None
|
| name | arguments | returns |
| prepare_recordset | id_list :[int|str] | [dict] |
Given a list of node internal id's, construct and return a dataset of their properties,
plus the special fields `internal_id` and `_node_labels`
:param id_list: A list of internal id's of database nodes
:return: A list of dicts, with the node properties plus the special fields `internal_id` and `_node_labels`
EXAMPLE:
[{'internal_id': 123, '_node_labels': ['Person'], 'name': 'Julian'}]
|
| name | arguments | returns |
| prepare_graph | result_dataset :[dict], cumulative=False, add_edges=True, avoid_links=None | [int|str] |
Given a list of dictionary data containing the properties of graph-database nodes - for example,
as returned by GraphAccess.get_nodes() - construct and save in the object visualization data for them.
Each dictionary entry MUST have a key named "internal_id".
If any key named "id" is found, it get automatically renamed "id_original" (since "id" is used by the visualization software);
if "id_original" already exists, an Exception is raised. (Copies are made; the original data object isn't affected.)
Though not required, a key named "_node_labels" is typically present as well.
Any date/datetime value found in the database will first be "sanitized" into a string representation of the date;
the time portion, if present, will get dropped
:param result_dataset: A list of dictionary data about graph-database nodes;
each dict must contain an entry with the key "internal_id"
:param cumulative: If False (default) then any previous call to this function will get ignored,
and a new graph is appended
:param add_edges: If True, all existing edges among the displayed nodes
will also be part of the visualization
:param avoid_links: Name or list of name of links to avoid including
:return: A list of values with the internal databased IDs
of all the nodes added to the graph structure
|
| name | arguments | returns |
| assemble_graph | id_list :[int|str] | [dict] |
Given a list of node internal id's, construct and return the data needed by the Cytoscape graph visualization.
Any date/datetime value found in the database will first be "sanitized" into a string representation of the date;
the time portion, if present, will get dropped
:param id_list: A list of internal id's of database nodes
:return: A list of dicts defining nodes, and possibly edges as well,
with all the data needed by the Cytoscape graph visualization
|
| name | arguments | returns |
| link_node_groups | group1 :[int|str], group2 :[int|str] | 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 the internal databased IDs of the 1st group of nodes
:param group2: List of the internal databased IDs of the 2nd group of nodes
:return: None
|