GraphWidget
Class
Inherits from ipywidgets.DOMWidget
The main widget class.
To be used in jupyter-notebook or jupyter-lab.
Example
from yfiles_jupyter_graphs import GraphWidget
w = GraphWidget()
w.show()
See notebooks for more examples.
Notes
Nodes and edges properties should be constructed recursively with basic python types otherwise {de-}serializers will fail.
Properties
nodes: typing.List[typing.Dict]
Data structure.
def get_nodes()
Getter for the nodes traitlets property.
Notes
This function acts as an alias for using GraphWidget.nodes property e.g. w.nodes == w.get_nodes()
.
Returns
Name | Type | Description |
---|---|---|
nodes |
typing.List[typing.Dict] |
Each node has the keys id: int and properties: typing.Dict . It might include keys that are not set directly, see (default) node mappings for details. |
def set_nodes(nodes)
Setter for the nodes traitlets property.
Parameters
Name | Type | Description |
---|---|---|
nodes |
typing.List[typing.Dict] |
Each node should have the keys id: int and properties: typing.Dict . Properties should be constructed recursively with basic python types, otherwise {de-}serializers will fail. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: w.set_nodes([
{'id': 0, 'properties': {'label': 'Hello World'}},
{'id': 1, 'properties': {'label': 'This is a second node.'}}
])
Notes
This function acts as an alias for using GraphWidget.nodes property e.g. w.nodes = [{...}]
has the same effect as using w.set_nodes([{...}])
.
edges: typing.List[typing.Dict]
Data structure.
def get_edges()
Getter for the edges traitlets property.
Notes
This function acts as an alias for using GraphWidget.edges property e.g. w.edges == w.get_edges()
is true
.
Returns
Name | Type | Description |
---|---|---|
edges |
typing.List[typing.Dict] |
Each edge has the keys id: int , start: int , end: int and properties: typing.Dict . It might include keys that are not set directly, see (default) edge mappings for details. |
def set_edges(edges)
Setter for the edges traitlets property.
Parameters
Name | Type | Description |
---|---|---|
edges |
typing.List[typing.Dict] |
Each edge should have the keys id: int , start: int , end:int and properties: typing.Dict . Ids for start and end should be among used node ids, otherwise the edge does not appear. Properties should be constructed recursively with basic python types, otherwise {de-}serializers will fail. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: w.set_edges([
{'id': 0, 'start': 0, 'end': 1, 'properties': {'label': 'edge between first and second node'}}
])
Notes
This function acts as an alias for using GraphWidget.edges property e.g. w.edges = [{...}]
has the same effect as using w.set_edges([{...}])
.
def get_selection()
Returns the nodes and edges, that are selected in the displayed widget.
Returns
Name | Type | Description |
---|---|---|
nodes |
typing.List[typing.Dict] |
List of selected nodes. |
edges |
typing.List[typing.Dict] |
List of selected edges. |
directed: bool
Graph wide flag for edge type.
def get_directed()
Getter for the directed traitlets property.
Notes
This function acts as an alias for using GraphWidget.directed property e.g. w.directed == w.get_directed()
is true
.
Returns
Name | Type | Description |
---|---|---|
directed |
bool |
Whether the graph is interpreted as directed. |
def set_directed(directed)
Setter for the directed traitlets property.
Parameters
Name | Type | Description |
---|---|---|
directed |
bool |
Whether the graph is interpreted as directed. |
Notes
This function acts as an alias for using GraphWidget.directed property e.g. w.directed = x
has the same effect as using w.set_directed(x)
.
graph_layout: typing.Dict
Choose an algorithm for positioning nodes and/or edges.
def get_graph_layout()
Getter for the graph layout traitlet property.
Notes
This function acts as an alias for using GraphWidget.graph_layout property
e.g. w.graph_layout == w.get_graph_layout()
is true
.
Returns
Name | Type | Description |
---|---|---|
graph_layout |
typing.Dict |
Returned dict has keys algorithm: str and options: dict, however options are empty because the algorithms use default settings from yFiles library. |
def set_graph_layout(algorithm)
Choose graph layout.
Currently the algorithms use default settings from yFiles library.
Parameters
Name | Type | Description |
---|---|---|
algorithm |
str |
Specify graph layout (or edge router) algorithm. Available algorithms are: ["circular", "circular_straight_line", "hierarchic", "organic", "interactive_organic", "orthogonal", "radial", "tree", "map", "orthogonal_edge_router", "organic_edge_router"] |
Notes
This function acts as an alias for using GraphWidget.graph_layout property
e.g. w.graph_layout = 'organic'
has the same effect as using w.set_graph_layout('organic')
.
Setting w.graph_layout = {'algorithm': 'organic', 'options': {}}
works as well,
which corresponds to using value given through the associated getter.
In case you want to use the edge routers
you should set a custom node position mapping as well.
See yFiles docs for more details about the algorithms.
neighborhood: typing.Dict
Control neighborhood view component.
def get_neighborhood()
Getter for the neighborhood traitlets property.
Returns
Name | Type | Description |
---|---|---|
neighborhood |
typing.Dict |
Returned dict has keys max_distance: int and selected_nodes: list, a list of node ids. |
def set_neighborhood(max_distance, selected_nodes)
Specify the neighborhood view in the widget.
The number of hops and focused nodes can be chosen.
Parameters
Name | Type | Description |
---|---|---|
max_distance |
int |
Set the maximum distance between selected and included nodes. If there are multiple paths to one (or multiple) selected nodes, the smallest path length is considered for this threshold. |
selected_nodes |
typing.List (optional) |
Choose a list of node ids that are highlighted in both main and neighborhood component. They act as starting points for neighborhood calculation. |
Notes
This function acts as an alias for using GraphWidget.neighborhood property.
You can assign values by w.neighborhood = {'max_distance': 2, 'selected_nodes':[2]}
or w.set_neighborhood(2, [2])
, both are equivalent.
The short form w.neighborhood = 3
sets only the max_distance variable
and resets the selected nodes.
sidebar: typing.Dict
Control sidebar component.
def get_sidebar()
Getter for the sidebar traitlets property.
Returns
Name | Type | Description |
---|---|---|
sidebar |
typing.Dict |
Returned dict has keys enabled: bool and start_with: str, whereat first one indicates open or closed sidebar and second one indicates start panel on widget show. |
def set_sidebar(enabled, start_with)
Specify the appearance of the sidebar in the widget.
Can be used to collapse sidebar or start with any panel.
Parameters
Name | Type | Description |
---|---|---|
enabled |
bool |
Whether to open or collapse sidebar at widget startup. |
start_with |
str |
The start panel identifier. Available are 'Neighborhood', 'Data', 'Search' and 'About' (the default). |
Notes
This function acts as an alias for using GraphWidget.sidebar property.
You can assign values by w.sidebar = {'enabled': True, 'start_with': 'Search'}
or w.set_sidebar(True, 'Search')
, both are equivalent.
The short form w.sidebar = True
sets only the enabled variable
and resets the start_with back to the default.
overview: bool
Control overview component.
def get_overview()
Getter for the overview traitlets property.
Returns
Name | Type | Description |
---|---|---|
overview |
bool |
Indicates open or closed overview state. A value of None means that a specific behaviour based on widget layout is followed. |
def set_overview(enabled)
Specify the appearance of the overview component in the widget.
Can be used to force open overview in case of a small widget layout or force collapsed overview in case of large widget layout.
Parameters
Name | Type | Description |
---|---|---|
enabled |
bool |
Whether to open or collapse overview at widget startup. |
node_label_mapping: Union[callable, str]
Data dependent change of node label on a per node basis.
def get_node_label_mapping()
Getter for the node label mapping property.
Notes
If no mapping is explicitly set, default_node_label_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_label_mapping |
Union[callable, str] |
A function that produces node labels or the name of the property to use for binding. |
def set_node_label_mapping(node_label_mapping)
Setter for the node label mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_label_mapping |
Union[callable, str] |
A function that produces node labels or the name of the property to use for binding. The function should have the same signature as default_node_label_mapping e.g. take in a node dictionary and return a string. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: w.node_label_mapping = 'id'
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_label_mapping(node: dict):
...
In [4]: w.set_node_label_mapping(custom_node_label_mapping)
def del_node_label_mapping()
Deleter for the name property.
Remove a custom node label mapping.
edge_label_mapping: Union[callable, str]
Data dependent change of edge label on a per edge basis.
def get_edge_label_mapping()
Getter for the edge label mapping property.
Notes
If no mapping is explicitly set, default_edge_label_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
edge_label_mapping |
Union[callable, str] |
A function that produces edge labels or the name of the property to use for binding. |
def set_edge_label_mapping(edge_label_mapping)
Setter for the edge label mapping property.
Parameters
Name | Type | Description |
---|---|---|
edge_label_mapping |
Union[callable, str] |
A function that produces edge labels or the name of the property to use for binding. The funtion should have the same signature as default_edge_label_mapping e.g. take in an edge dictionary and return a string. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: w.edge_label_mapping = 'id'
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_label_mapping(node: dict):
...
In [4]: w.set_edge_label_mapping(custom_edge_label_mapping)
def del_edge_label_mapping()
Deleter for the edge label mapping property.
Remove a custom edge label mapping.
node_property_mapping: Union[callable, str]
Data dependent change of node properties on a per node basis.
def get_node_property_mapping()
Getter for the node property mapping property.
Notes
If no mapping is explicitly set, default_node_property_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_property_mapping |
Union[callable, str] |
A function that produces node properties or the name of the property to use for binding. |
def set_node_property_mapping(node_property_mapping)
Setter for the node property mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_property_mapping |
Union[callable, str] |
A function that produces node properties or the name of the property to use for binding. The function should have the same signature as default_node_property_mapping e.g. take in a node dictionary and return a dictionary. |
Notes
Properties are changed inplace by this mapping.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_property_mapping(node: dict):
...
In [4]: w.set_node_property_mapping(custom_node_property_mapping)
def del_node_property_mapping()
Deleter for the node property mapping property.
Remove a custom node property mapping.
edge_property_mapping: Union[callable, str]
Data dependent change of edge properties on a per edge basis.
def get_edge_property_mapping()
Getter for the edge property mapping property.
Notes
If no mapping is explicitly set, default_edge_property_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
edge_property_mapping |
Union[callable, str] |
A function that produces edge properties or the name of the property to use for binding. |
def set_edge_property_mapping(edge_property_mapping)
Setter for the edge property mapping property.
Parameters
Name | Type | Description |
---|---|---|
edge_property_mapping |
Union[callable, str] |
A function that produces edge properties or the name of the property to use for binding. The function should have the same signature as default_edge_property_mapping e.g. take in an edge dictionary and return a dictionary. |
Notes
Properties are changed inplace by this mapping.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_property_mapping(node: dict):
...
In [4]: w.set_edge_property_mapping(custom_edge_property_mapping)
def del_edge_property_mapping()
Deleter for the edge property mapping property.
Remove a custom edge property mapping.
node_color_mapping: Union[callable, str]
Data dependent change of node color on a per node basis.
def get_node_color_mapping()
Getter for the node color mapping property.
Notes
If no mapping is explicitly set, default_node_color_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_color_mapping |
Union[callable, str] |
A function that produces node colors or the name of the property to use for binding. |
def set_node_color_mapping(node_color_mapping)
Setter for the node color mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_color_mapping |
Union[callable, str] |
A function that produces node colors or the name of the property to use for binding. The function should have the same signature as default_node_color_mapping e.g. take in a node dictionary and return a string. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_color_mapping(node: dict):
...
In [4]: w.set_node_color_mapping(custom_node_color_mapping)
def del_node_color_mapping()
Deleter for the node color mapping property.
Remove a custom node color mapping.
node_styles_mapping: Union[callable, str]
Data dependent change of node styles on a per node basis.
def get_node_styles_mapping()
Getter for the node styles mapping property.
Notes
If no mapping is explicitly set, default_node_styles_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_styles_mapping |
Union[callable, str] |
A function that produces node styles or the name of the property to use for binding. |
def set_node_styles_mapping(node_styles_mapping)
Setter for the node styles mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_styles_mapping |
Union[callable, str] |
A function that produces node styles or the name of the property to use for binding. The function should have the same signature as default_node_styles_mapping e.g. take in a node dictionary and return a string. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_styles_mapping(node: dict):
...
In [4]: w.set_node_styles_mapping(custom_node_styles_mapping)
def del_node_styles_mapping()
Deleter for the node styles mapping property.
Remove a custom node styles mapping.
edge_color_mapping: Union[callable, str]
Data dependent change of edge color on a per edge basis.
def get_edge_color_mapping()
Getter for the edge color mapping property.
Notes
If no mapping is explicitly set, default_edge_color_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
edge_color_mapping |
Union[callable, str] |
A function that produces edge colors or the name of the property to use for binding. |
def set_edge_color_mapping(edge_color_mapping)
Setter for the edge color mapping property.
Parameters
Name | Type | Description |
---|---|---|
edge_color_mapping |
Union[callable, str] |
A function that produces edge colors or the name of the property to use for binding. The function should have the same signature as default_edge_color_mapping e.g. take in an edge dictionary and return a string. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_color_mapping(node: dict):
...
In [4]: w.set_edge_color_mapping(custom_edge_color_mapping)
def del_edge_color_mapping()
Deleter for the edge color mapping property.
Remove a custom edge color mapping.
node_scale_factor_mapping: Union[callable, str]
Data dependent change of node scale factor on a per node basis.
def get_node_scale_factor_mapping()
Getter for the node scale factor mapping property.
Notes
If no mapping is explicitly set, default_node_scale_factor_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_scale_factor_mapping |
Union[callable, str] |
A function that produces node scale factor or the name of the property to use for binding. |
def set_node_scale_factor_mapping(node_scale_factor_mapping)
Setter for the node scale factor mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_scale_factor_mapping |
Union[callable, str] |
A function that produces node scale factors or the name of the property to use for binding. The function should have the same signature as default_node_scale_factor_mapping e.g. take in a node dictionary and return a positive float. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_scale_factor_mapping(node: dict):
...
In [4]: w.set_node_scale_factor_mapping(custom_node_scale_factor_mapping)
def del_node_scale_factor_mapping()
Deleter for the node scale factor mapping property.
Remove a custom node scale factor mapping.
node_size_mapping: Union[callable, str]
Data dependent change of node size on a per node basis.
def get_node_size_mapping()
Getter for the node size mapping property.
Notes
If no mapping is explicitly set, default_node_size_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_size_mapping |
Union[callable, str] |
A function that produces node sizes or the name of the property to use for binding. |
def set_node_size_mapping(node_size_mapping)
Setter for the node size mapping property.
A custom size mapping is only used if there is no custom node_layout
mapping.
If a custom node layout mapping and a custom size mapping is set, the node layout mapping always takes precedence.
Parameters
Name | Type | Description |
---|---|---|
node_size_mapping |
Union[callable, str] |
A function that produces node sizes or the name of the property to use for binding. The function should have the same signature as default_node_size_mapping e.g. take in a node dictionary and return a positive float 2-tuple. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_size_mapping(node: dict):
...
In [4]: w.set_node_size_mapping(custom_node_size_mapping)
def del_node_size_mapping()
Deleter for the node size mapping property.
Remove a custom node size mapping.
node_layout_mapping: Union[callable, str]
Data dependent change of node layout on a per node basis.
def get_node_layout_mapping()
Getter for the node layout mapping property.
Notes
If no mapping is explicitly set, default_node_layout_mapping
is returned.
Node layouts combine node position and node size.
The default node layout mapping is the currently set position and size mapping.
If a custom size or position mapping is set using set_node_size_mapping
or set_node_position_mapping
,
the default layout changes.
If a custom node layout mapping and a custom size/position mapping is set, the layout mapping takes precedence.
Returns
Name | Type | Description |
---|---|---|
node_layout_mapping |
Union[callable, str] |
A function that produces node layouts or the name of the property to use for binding. |
def set_node_layout_mapping(node_layout_mapping)
Setter for the node layout mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_layout_mapping |
Union[callable, str] |
A function that produces node layouts or the name of the property to use for binding. The function should have the same signature as default_node_layout_mapping e.g. take in a node dictionary and return a positive float 4-tuple. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_layout_mapping(node: dict):
...
In [4]: w.set_node_layout_mapping(custom_node_layout_mapping)
def del_node_layout_mapping()
Deleter for the node layout mapping property.
Remove a custom node layout mapping.
edge_thickness_factor_mapping: Union[callable, str]
Data dependent change of edge thickness factor on a per edge basis.
def get_edge_thickness_factor_mapping()
Getter for the edge thickness factor mapping property.
Notes
If no mapping is explicitly set, default_edge_thickness_factor_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
edge_thickness_factor_mapping |
Union[callable, str] |
A function that produces edge thickness factors or the name of the property to use for binding. |
def set_edge_thickness_factor_mapping(edge_thickness_factor_mapping)
Setter for the edge thickness factor mapping property.
Parameters
Name | Type | Description |
---|---|---|
edge_thickness_factor_mapping |
Union[callable, str] |
A function that produces edge thickness factors or the name of the property to use for binding. The function should have the same signature as default_edge_thickness_factor_mapping e.g. take in an edge dictionary and return a positive float. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_thickness_factor_mapping(node: dict):
...
In [4]: w.set_edge_thickness_factor_mapping(custom_edge_thickness_factor_mapping)
def del_edge_thickness_factor_mapping()
Deleter for the edge thickness factor mapping property.
Remove a custom edge thickness factor mapping.
node_type_mapping: Union[callable, str]
Data dependent change of node type on a per node basis.
def get_node_type_mapping()
Getter for the node type mapping property.
Notes
If no mapping is explicitly set, default_node_type_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_type_mapping |
Union[callable, str] |
A function that produces node types or the name of the property to use for binding. |
def set_node_type_mapping(node_type_mapping)
Setter for the node type mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_type_mapping |
Union[callable, str] |
A function that produces node types or the name of the property to use for binding. The function should have the same signature as default_node_type_mapping e.g. take in a node dictionary and return a bool/int/float or str value. |
Notes
Node types give more information for some layout algorithms.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_type_mapping(node: dict):
...
In [4]: w.set_node_type_mapping(custom_node_type_mapping)
References
def del_node_type_mapping()
Deleter for the node type mapping property.
Remove a custom node type mapping.
node_parent_mapping: Union[callable, str]
Data dependent change of node parent on a per node basis.
def get_node_parent_mapping()
Getter for the node parent mapping property.
Notes
If no mapping is explicitly set, default_node_parent_mapping
is returned.
Returns
Name | parent | Description |
---|---|---|
node_parent_mapping |
Union[callable, str] |
A function that produces node parents or the name of the property to use for binding. |
def set_node_parent_mapping(node_parent_mapping)
Setter for the node parent mapping property.
Parameters
Name | parent | Description |
---|---|---|
node_parent_mapping |
Union[callable, str] |
A function that produces node parent ids or the name of the property to use for binding. The function should have the same signature as default_node_parent_mapping e.g. take in a node dictionary and return a bool/int/float or str value. |
Notes
Given node parent ids create group nodes instead of regular nodes.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_parent_mapping(node: dict):
...
In [4]: w.set_node_parent_mapping(custom_node_parent_mapping)
def del_node_parent_mapping()
Deleter for the node parent mapping property.
Remove a custom node parent mapping.
### node_parent_group_mapping: Union[callable, str]
Data dependent change of node parent group on a per node basis.
def get_node_parent_group_mapping()
Getter for the node parent group mapping property.
Notes
If no mapping is explicitly set, default_node_parent_group_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_parent_group_mapping |
Union[callable, str] |
A function that produces node parents or the name of the property to use for binding. |
def set_node_parent_group_mapping(node_parent_group_mapping)
Setter for the node parent group mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_parent_group_mapping |
Union[callable, str] |
A function that produces node parents ids or the name of the property to use for binding. The function should have the same signature as default_node_parent_group_mapping e.g. take in a node dictionary and return a str/int/float or dict with a required label property. |
Notes
For every returned parent group, a new group node is created. In contrast to node_parent_mapping
this mapping does not
require the group nodes to be part of the given node dataset.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_parent_group_mapping(node: dict):
...
In [4]: w.set_node_parent_group_mapping(custom_node_parent_group_mapping)
def del_node_parent_group_mapping()
Deleter for the node parent group mapping property.
Remove a custom node parent group mapping.
node_position_mapping: Union[callable, str]
Data dependent change of node position on a per node basis.
def get_node_position_mapping()
Getter for the node position mapping property.
Notes
If no mapping is explicitly set, default_node_position_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_position_mapping |
Union[callable, str] |
A function that produces node positions or the name of the property to use for binding. |
def set_node_position_mapping(node_position_mapping)
Setter for the node position mapping property.
A custom position mapping is only used if there is no custom node_layout
mapping.
If a custom node layout mapping and a custom position mapping is set, the node layout mapping takes precedence.
Parameters
Name | Type | Description |
---|---|---|
node_position_mapping |
Union[callable, str] |
A function that produces node positions or the name of the property to use for binding. The function should have the same signature as default_node_position_mapping e.g. take in a node dictionary and return a float 2-tuple. |
Notes
Only edge router algorithms consider node positions,
all other algorithms calculate node positions themselves.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_position_mapping(node: dict):
...
In [4]: w.set_node_position_mapping(custom_node_position_mapping)
def del_node_position_mapping()
Deleter for the node position mapping property.
Remove a custom node position mapping.
heat_mapping: Union[callable, str]
Data dependent change of heat value on a per node and edge basis.
def get_heat_mapping()
Getter for the heat mapping property.
Notes
If no mapping is explicitly set, default_heat_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
heat_mapping |
Union[callable, str] |
A function that produces heat values or the name of the property to use for binding. |
def set_heat_mapping(heat_mapping)
Setter for the heat mapping property.
Parameters
Name | Type | Description |
---|---|---|
heat_mapping |
Union[callable, str] |
A function that produces heat values or the name of the property to use for binding. The function should have the same signature as default_heat_mapping e.g. take in a element dictionary and return a float. |
Notes
This mapping is used for both edges and nodes
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_heat_mapping(element: dict):
...
In [4]: w.set_heat_mapping(custom_heat_mapping)
def del_heat_mapping()
Deleter for the heat mapping property.
Remove a custom heat mapping.
node_coordinate_mapping: Union[callable, str]
Data dependent change of node coordinate on a per node basis.
def get_node_coordinate_mapping()
Getter for the node coordinate mapping property.
Notes
If no mapping is explicitly set, default_node_coordinate_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
node_coordinate_mapping |
Union[callable, str] |
A function that produces node coordinates or the name of the property to use for binding. |
def set_node_coordinate_mapping(node_coordinate_mapping)
Setter for the node coordinate mapping property.
Parameters
Name | Type | Description |
---|---|---|
node_coordinate_mapping |
Union[callable, str] |
A function that produces node coordinates or the name of the property to use for binding. The function should have the same signature as default_node_coordinate_mapping e.g. take in a node dictionary and return a float 2-tuple. |
Notes
Only the map layout consider node coordinates,
all other algorithms ignore node coordinates.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_coordinate_mapping(node: dict):
...
In [4]: w.set_node_coordinate_mapping(custom_node_coordinate_mapping)
def del_node_coordinate_mapping()
Deleter for the node coordinate mapping property.
Remove a custom node coordinate mapping.
directed_mapping: Union[callable, str]
Data dependent change if an edge is directed or not.
def get_directed_mapping()
Getter for the directed mapping property.
Notes
If no mapping is explicitly set, default_directed_mapping
is returned.
Returns
Name | Type | Description |
---|---|---|
directed_mapping |
Union[callable, str] |
A function that produces edge directions or the name of the property to use for binding. |
def set_directed_mapping(directed_mapping)
Setter for the directed mapping property.
Parameters
Name | Type | Description |
---|---|---|
directed_mapping |
Union[callable, str] |
A function that produces edge directions or the name of the property to use for binding. The function should have the same signature as default_directed_mapping e.g. take in an edge dictionary and return a boolean value. |
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_directed_mapping(node: dict):
...
In [4]: w.set_directed_mapping(custom_directed_mapping)
def del_directed_mapping()
Deleter for the directed mapping property.
Remove a custom directed mapping.
Methods
def init(widget_layout = None, overview_enabled = None, context_start_with = '')
GraphWidget constructor.
Parameters
Name | Type | Description |
---|---|---|
widget_layout |
ipywidgets.Layout (optional) |
Can be used to specify general widget appearance through css attributes. See references for a link to their documentation and available keywords. |
overview_enabled |
bool (optional) |
Enable graph overview component. Default behaviour depends on cell width. |
context_start_with |
str (optional) |
Specify context tab name to start with that tab opened. Default behaviour is open with About dialog. Use None to start with closed sidebar. Available are Neighborhood, Data, Search and About. |
def show()
Display widget in Jupyter.
Same as using single object reference in cell directly.
Notes
Mappings will only be applied shortly before showing the widget.
def import_graph(graph)
Import a graph object defined in an external module.
Sets the nodes
, edges
and directed
traitlets properties
with information extracted from the graph object.
See graph importers for object specific transformation details.
Parameters
Name | Type | Description |
---|---|---|
graph |
networkx.{Multi}{Di}Graph | graph_tool.Graph | igraph.Graph | pygraphviz.AGraph |
The graph data structure. |
Example
In [1]: from networkx import florentine_families_graph
In [2]: from yfiles_jupyter_graphs import GraphWidget
In [3]: w = GraphWidget()
In [4]: w.import_graph(florentine_families_graph())
Notes
Some graph data structures have special attributes for labels, some don't. Same goes for other graph properties. This method and the underlying transformations should be seen as best effort to provide an easy way to input data into the widget. For more granular control use nodes and edges properties directly.
def circular_layout()
Alias for GraphWidget.graph_layout = "circular".
See yFiles circular layout guide for more details about this specific algorithm.
def circular_straight_line_layout()
Alias for GraphWidget.graph_layout = "circular_straight_line".
Similar to circular layout but with straight edge paths instead of bundled paths.
See yFiles circular layout guide for more details about this specific algorithm.
def hierarchic_layout()
Alias for GraphWidget.graph_layout = "hierarchic".
See yFiles hierarchic layout guide for more details about this specific algorithm.
def organic_layout()
Alias for GraphWidget.graph_layout = "organic".
See yFiles organic layout guide for more details about this specific algorithm.
def orthogonal_layout()
Alias for GraphWidget.graph_layout = "orthogonal".
See yFiles orthogonal layout guide for more details about this specific algorithm.
def radial_layout()
Alias for GraphWidget.graph_layout = "radial".
See yFiles radial layout guide for more details about this specific algorithm.
def tree_layout()
Alias for GraphWidget.graph_layout = "tree".
See yFiles tree layout guide for more details about this specific algorithm.
def orthogonal_edge_router()
Alias for GraphWidget.graph_layout = "orthogonal_edge_router".
See yFiles orthogonal edge router guide for more details about this specific algorithm.
def interactive_organic_layout()
Alias for GraphWidget.graph_layout = "interactive_organic_layout".
See yFiles interactive organic layout guide for more details about this specific algorithm.
def organic_edge_router()
Alias for GraphWidget.graph_layout = "organic_edge_router".
See yFiles organic edge router guide for more details about this specific algorithm.
def default_element_label_mapping(index, element)
The default property mapping for graph elements.
The default label mapping for graph elements.
Element (dict) should have key properties which itself should be a dict.
Then one of the following values (in descending priority) is used as label if the label is a string:
- properties["label"]
- properties["yf_label"]
When importing a Neo4j graph, the following properties are values are used as labels (in descending priority):
- properties['name']
- properties['title']
- properties['label']
- properties['description']
- properties['caption']
- properties['text']
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in corresponding nodes or edges list. |
element |
typing.Dict |
Can be both node or edge. |
Notes
This is the default value for the {node|edge}_label_mapping property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: w.{node|edge}_label_mapping = 'id'
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_element_label_mapping(element: typing.Dict):
...
In [4]: w.set_{node|edge}_label_mapping(custom_element_label_mapping)
Returns
Name | Type | Description |
---|---|---|
label |
str |
The node or edge label. |
label |
typing.Dict| A Dict` with mappings for style attributes. See below for supported values. |
Supported style attributes in the return Dict
:
can contain the following key-value-pairs:
"text": str
Is used as the label.
"fontSize": number
Sets the size of the font.
"color": string
Css color value for the text color.
"backgroundColor": str
Css color value for the background color.
"position": 'center' | 'north' | 'east' | 'south' | 'west'
The label position at the node. Applies only to node labels.
"maximumWidth": number
The maximum width of the label. By default, the label is clipped at the given size, or wrapped when "wrapping" is set.
"maximumHeight": number
The maximum height of the label. Clips the label at the given height. May be combined with "wrapping".
"wrapping": 'character' | 'character_ellipsis' | 'none' | 'word' | 'word_ellipsis'
Text wrapping for the label. Must be set in combination with "maximumWidth".
"textAlignment": 'center' | 'left' | 'right'
The horizontal text alignment when "wrapping" is enabled.
def default_node_label_mapping(index, node)
The default label mapping for nodes.
See default_element_label_mapping
.
def default_edge_label_mapping(index, edge)
The default label mapping for edges.
See default_element_label_mapping
.
def default_element_property_mapping(index, element)
The default property mapping for graph elements.
Simply selects the properties value of element dictionary.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in corresponding nodes or edges list. |
element |
typing.Dict |
Can be both node or edge. |
Notes
This is the default value for the {node|edge}_property_mapping property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
When a string is provided as the function argument, the key will be searched for in both the properties dictionary and the element keys.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_element_property_mapping(element: typing.Dict):
...
In [4]: w.set_{node|edge}_property_mapping(custom_element_property_mapping)
Returns
Name | Type | Description |
---|---|---|
properties |
typing.Dict |
The node or edge properties. |
def default_node_property_mapping(index, node)
The default property mapping for nodes.
See default_element_property_mapping
.
def default_edge_property_mapping(index, edge)
The default property mapping for edges.
See default_element_property_mapping
.
def default_node_color_mapping(index, node)
The default color mapping for nodes.
Provides constant value of '#15afac' for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_color_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_color_mapping(node: typing.Dict):
...
In [4]: w.set_node_color_mapping(custom_node_color_mapping)
Returns
Name | Type | Description |
---|---|---|
color |
str |
CSS color value. |
References
def default_node_styles_mapping(index, node)
The default styles mapping for nodes.
Provides constant value of {} for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_styles_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_styles_mapping(node: typing.Dict):
...
In [4]: w.set_node_styles_mapping(custom_node_styles_mapping)
Returns
Name | Type | Description |
---|---|---|
styles |
typing.Dict |
A Dict with mappings for style attributes. See below for supported values. |
Supported style attributes in the return Dict
:
can contain the following key-value-pairs:
"color": str
css color value
"shape": str
possible values: 'ellipse', 'hexagon', 'hexagon2', 'octagon', 'pill', 'rectangle', 'round-rectangle' or 'triangle'
"image": str
url or data URL of the image
References
def default_edge_color_mapping(index, edge)
The default color mapping for edges.
Provides constant value of '#15afac' for all edges.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in edges list. |
edge |
typing.Dict |
Notes
This is the default value for the edge_color_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_color_mapping(edge: typing.Dict):
...
In [4]: w.set_edge_color_mapping(custom_edge_color_mapping)
Returns
Name | Type | Description |
---|---|---|
color |
str |
CSS color value. |
References
def default_node_scale_factor_mapping(index, node)
The default scale factor mapping for nodes.
Provides constant value of 1.0 for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_scale_factor_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_scale_factor_mapping(node: typing.Dict):
...
In [4]: w.set_node_scale_factor_mapping(custom_node_scale_factor_mapping)
Returns
Name | Type | Description |
---|---|---|
node_scale_factor |
float |
Positive scale factor. |
def default_node_size_mapping(index, node)
The default size mapping for nodes.
Provides constant value of [55.0,55.0] for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_size_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_size_mapping(node: typing.Dict):
...
In [4]: w.set_node_size_mapping(custom_node_size_mapping)
Returns
Name | Type | Description |
---|---|---|
node_size |
float 2-tuple |
size in (width, height). |
def default_node_layout_mapping(index, node)
The default layout mapping for nodes.
Provides constant value of [0.00, 0.00, 55.0, 55.0] for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_layout_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_layout_mapping(node: typing.Dict):
...
In [4]: w.set_node_layout_mapping(custom_node_layout_mapping)
Returns
Name | Type | Description |
---|---|---|
node_layout |
float 4-tuple |
layout containin position and size: (x, y, width, height). |
def default_heat_mapping(index, node)
The default heat mapping for nodes and edges.
Provides constant value of None for all nodes and edges.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
Position in element list. |
element |
typing.Dict |
Notes
This is the default value for the heat_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_heat_mapping(node: typing.Dict):
...
In [4]: w.set_heat_mapping(custom_heat_mapping)
Returns
Name | Type | Description |
---|---|---|
heat |
float |
The heat can be a number between 0 and 1. |
def default_edge_thickness_factor_mapping(index, edge)
The default thickness factor mapping for edges.
Provides constant value of 1.0 for all edges.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in edges list. |
edge |
typing.Dict |
Notes
This is the default value for the edge_thickness_factor_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_edge_thickness_factor_mapping(edge: typing.Dict):
...
In [4]: w.set_edge_thickness_factor_mapping(custom_edge_thickness_factor_mapping)
Returns
Name | Type | Description |
---|---|---|
edge_thickness_factor |
float |
Positive thickness factor. |
def default_node_type_mapping(index, node)
The default type mapping for nodes.
Provides constant value of None
for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_type_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_type_mapping(node: typing.Dict):
...
In [4]: w.set_node_type_mapping(custom_node_type_mapping)
Returns
Name | Type | Description |
---|---|---|
node_type |
None |
Node Type. |
def default_node_parent_mapping(index, node)
The default parent mapping for nodes.
Provides constant value of None
for all nodes.
Parameters
Name | parent | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_parent_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_parent_mapping(node: typing.Dict):
...
In [4]: w.set_node_parent_mapping(custom_node_parent_mapping)
Returns
Name | parent | Description |
---|---|---|
node_parent |
None |
Node parent Id. |
def default_node_parent_group_mapping(index, node)
The default parent group mapping for nodes.
Provides constant value of None
for all nodes.
Parameters
Name | parent | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_parent_group_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_parent_group_mapping(node: typing.Dict):
...
In [4]: w.set_node_parent_group_mapping(custom_node_parent_group_mapping)
Returns
Name | parent | Description |
---|---|---|
node_parent_group |
None |
Node parent label. |
def default_node_position_mapping(index, node)
The default position mapping for nodes.
Provides constant value of [0.0, 0.0] for all nodes.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_position_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_position_mapping(node: typing.Dict):
...
In [4]: w.set_node_position_mapping(custom_node_position_mapping)
Returns
Name | Type | Description |
---|---|---|
node_position |
float 2-tuple |
Position in euclidian plane. |
def default_node_coordinate_mapping(index, node)
The default coordinate mapping for nodes.
Provides constant value of None
for all nodes.
There is no coordinate mapping unless explicitly set.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) position in nodes list. |
node |
typing.Dict |
Notes
This is the default value for the node_coordinate_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_node_coordinate_mapping(node: typing.Dict):
...
In [4]: w.set_node_coordinate_mapping(custom_node_coordinate_mapping)
Returns
Name | Type | Description |
---|---|---|
node_coordinate |
float 2-tuple |
geo coordinates in latitude and longitude . |
def default_directed_mapping(index, edge)
The default directed mapping for edges.
Uses the graph wide directed attribute for all edges.
Parameters
Name | Type | Description |
---|---|---|
index |
int |
(optional) Position in edges list. |
edge |
typing.Dict |
Notes
This is the default value for the directed_mapping
property.
Can be 'overwritten' by setting the property with a function of the same signature.
If the given mapping function has only one parameter (that is not typed as int), then it will be called with the element (typing.Dict) as first parameter.
Example
In [1]: from yfiles_jupyter_graphs import GraphWidget
In [2]: w = GraphWidget()
In [3]: def custom_directed_mapping(edge: typing.Dict):
...
In [4]: w.set_directed_mapping(custom_directed_mapping)
Returns
Name | Type | Description |
---|---|---|
directed |
bool |
Whether the edge is directed or not. |