Transformations that simply treat data as a table of values, without understanding the network structure of a dataset (i.e., that an edge connects a source and target nodes) are instead defined in the data
block.
Not all Network Transformations change the network topology.
When constructing a network, you can specify a list of transformations that should be applied to it.
- aggregating edges (the data is aggregated, but the node and link references are not)
- filtering edges or nodes (for consistency, this requires filtering out any edges connected to filtered-out nodes)
- projecting edges
- aggregating nodes into a
supernode
Transformations applied to a network do not modify the data from which the network was created.
Transformations are applied in the order in which they are listed.
Topological changes
Aggregation
Aggregate Edges
Aggregate multiple edges with the same source and target node into a single edge.
Attribute | Type | Description |
---|---|---|
type | "aggregateEdges" | |
operation? | AggregationFunc | Aggregation function to be applied to the edges that are being merged, to obtain the data for the new aggregate edge. |
directed? | boolean | If directed is false, two edges between the same pair of nodes will be merged even if they have opposite directions. |
An aggregation function can be specified to define how data associated with each edge should be combined.
Aggregate Nodes
Aggregate nodes into a single node.
Attribute | Type | Description |
---|---|---|
type | "aggregateNodes" | |
field | string | Nodes with the same value for this field will be merged. |
fields | string | Nodes with the same value for these fields will be merged. |
expression | string | Nodes for which evaluating this expression gives the same result will be merged. |
as? | string | The merged nodes will contain the name of the field (or result of evaluating expression) as a field with this name. |
Note that only one of field
, fields
and expression
can be specified.
Grouping nodes is similar to grouping tabular data, except that the attached edges also have to be adjusted.
Nodes will be merged into a single node if they have the same value for the specified field
, or if the expression
gives the same value when evaluated for them.
Note that aggregating nodes does not aggregate the attached edges; this can achieved by a separate transform.
Project Edges
Projection replaces a path between two nodes via a third node with a single link directly joining them (i.e., A->B->C become A->C)
Attribute | Type | Description |
---|---|---|
type | "project" | |
fieldName? | string | Field that indicates the node type (default: "_type"). |
remainingNodeType | string or number | The value of the node type field for the nodes that will be joined by the newly-created link (i.e., nodes A and C in the example A->B->C). |
removedNodeType | string or number | The value of the node type filed for the node that will be replace (i.e., node B in the example A->B->C) |
directed | boolean | If directed is false, ignore edge directions when considering paths to project (i.e, A->B->C and A<-B->C would become A->C ). |
linkDataReducer | any | How to aggregate the data from the links that are being merged. |
Remove Isolated Nodes
Remove isolate nodes (i.e., nodes with no attached edges)
Attribute | Type | Description |
---|---|---|
type | "removeIsolated" |
Filter
Nodes or edges can be filtered by providing an expression.
Note that when filtering nodes, any link connected to a removed node is also removed as dangling links are invalid.
When filtering links, isolated nodes are not removed; they can be removed by applying a removeIsolated
transform.
Filter nodes
Remove some nodes, retaining only those for which the expression is true. When a node is removed, so are any edges that were attached to it.
Attribute | Type | Description |
---|---|---|
type | "filterNodes" | |
expression | string | The expression to evaluate for each node. |
Filter edges
Remove some edges, retaining only those for which the expression is true.
Attribute | Type | Description |
---|---|---|
type | "filterEdges" | |
expression | string | The expression to evaluate for each edge. |
Connect nodes
Add a connection between each pair of nodes for which the value of a specified field (or result of evaluating a specified expression) in the same.
Attribute | Type | Description |
---|---|---|
type | "connect" | |
as? | string | Value to be stored in the "_type" field for edges created by this operation. |
field | string | The name of the field to be examined. |
expression | string | The expression to be evaluated. |
bothDirections? | boolean | Each pair of nodes will be joined by a single edge (if false ), or a pair of edges with opposite directions (if true ). Default is true . |
Only one of field
or expression
can be specified.
Reverse Edge Directions
Swap the direction of edges.
Attribute | Type | Description |
---|---|---|
type | "reverseEdges" | |
condition? | string | If an expression is provided as a condition, then only edges for which it evaluates to true will be reversed. |
Set Edge Directedness
Change whether or not edges are directed.
Attribute | Type | Description |
---|---|---|
type | "setDirectness" | |
value | "directed" or "undirected" | The value of directedness to apply to all edges. |
expression | string | This expression will be evaluated for all edges; if it evaluates to true , then the edge will be treated as directed. |
Swap Nodes And Edges
Swap nodes and links by computing the Line Graph.This consists of a node for each edge in the original graph;these are joined if they share a common edge in the original graph (in the undirected case)or if they correspond to edges that form a directed path of length two in the original graph.
Attribute | Type | Description |
---|---|---|
type | "swapNodesAndEdges" | |
directed? | boolean | Whether to treat edges as directed |
Promote field or expression to a node
Promote a field to a node type. This creates a node for each distinct value of a field (or evaluating an expression) on existing nodes, and adds an edge from each original node to the corresponding new value node.
Attribute | Type | Description |
---|---|---|
type | "promote" | |
field | string | The name of the field to be promoted. |
expression | string | The expression to be evaluated for each node |
prefix | string | Prefix to be applied before the value when assigning the ID for the new nodes. |
linkPrefix? | string | Prefix to be applied to the ID of newly created edges. |
direction? | "toValue" or "fromValue" | Whether the new edges should be directed from the existing nodes to the new value nodes or vice-versa. |
Only one of field or expression can be specified.
Deriving new attributes
Calculate new attribute, considering nodes in isolation
Calculate new attribute for each node or link, based on the current attributes of only the same node or link.
Attribute | Type | Description |
---|---|---|
type | "calculate" | |
for? | "nodes" or "links" | Whether to do calculation for each node or edge (default is nodes). |
calculate | string | The expression to calculate. |
as | string | The name of the field in which result should be stored (defaults to the same as the method). |
You can specify an expression to be evaluated for each node or link, with the result saved in an attribute.
For example:
{"type": "calculate", "as": "label", "calculate": "datum.name + ' (' + datum.louvain + ')'"},
{"type": "calculate", "as": "label", "calculate": "datum.source.name + ' --- ' + datum.target.name", "for": "links"},
In some cases, expressions like this can be used directly in the specification of visual encodings, but it may be clearer to separately calculate them as separate attributes.
Calculate new attribute, based on node and neighbours
Computes a new data attribute for each node, based on the data associated with its neighbours.
For each edge, the attribute selector is applied to an object with a node
and edge
attributes; the selector can thus access properties of either the neighbouring node or the edge connecting it.
Attribute | Type | Description |
---|---|---|
type | "connectivityBasedAttribute" | |
attributeSelector | string | Which data attribute to select for each neighbouring node. |
as | string | The name of the field in which the result should be stored. |
operation? | AggregationFunc | The aggregation operation to be applied. |
direction? | "in" or "out" or "both" | When calculating value for a node, consider edges directed in towards that node, out away from that node, or both.Default is both. |
Calculate metrics based on whole network
Compute a metric for each node. These may depend on the structure of the network as a whole.
Attribute | Type | Description |
---|---|---|
type | "metric" | |
metric | MetricName | Which metric to calculate. |
as? | string | The name of the field in which the value of the metric calculated for each node should be stored (defaults to the same as the metric). |
Several node metrics can be calculated: "degree" | "in-degree" | "out-degree" | "undirected-betweeness" | "directed-betweeness" | "closeness" | "eccentricity"
Cluster Nodes
Perform clustering/community detection.
Attribute | Type | Description |
---|---|---|
type | "cluster" | |
method? | "louvain" | The clustering method to use. |
as? | string | The name of the field in which the cluster id of each node should be stored (defaults to the same as the method). |
NetPanorama currently supports community detection using the Louvain method, as implemented by ngraph.louvain.