Virtual properties

Virtual properties in visualization can be created or modified in the Detail tab. Virtual properties are usually small javascript functions (called formulas) which can be used to create properties based on values stored in an element or in the elements in its neighborhood. This formula has to return a single value (string or number) which represents the value of this virtual property for the particular element.

images/download/attachments/28835957/virtualProp.jpg

images/download/thumbnails/28836097/red_1.png Create or unhide virtual property

With this menu you can create new virtual property which will be created on every element (nodes, relationships or merged relationships) or you can unhide hidden virtual properties.

images/download/thumbnails/28836097/red_2.png Edit, hide or delete virtual property

With this menu you can

  • edit virtual property (change title or formula) or

  • hide virtual property (it will be not shown in Virtual properties list but you can unhide it anytime) or

  • delete virtual property (it will be no longer available and you can't restore it)

Creating a virtual property

Virtual property is created for every element in a group. Group is formed by nodes, relationships, merged relationships and direction merged relationships. So when you create a virtual property on the Detail tab of a node, this property is added to every node in the visualization.

images/download/attachments/28835957/image2016-10-7_11_23_21.png

When creating a virtual property:

  • define title for property (mandatory)

  • define formula (mandatory). Only valid formulas can be created - you can test your formula with the Test formula button. You can write your own formula or you can insert one of the build-in formula templates and change it to suit your purpose.

Context of a virtual property

Every group of elements has different context when creating a virtual property. Context is set of variables available in the formula by default.

  • Virtual property on a node can use these variables:

    • node : object with node's data

      • When you want use a particular DB property of a node in formula, use node.data.name_of_property.

    • edges : array of objects with data of node's relationships (all relationship in node's neigborhood)

      • When you want use a particular DB property of the first relationship in formula, use edges[0].data.name_of_property.

    • numOfHiddenRelationships : number of all node's relationships stored in DB (incoming or outoing) minus the number of node's relationships already in visualization

  • Virtual property on a relationship can use these variables:

    • edge : object with relationship's data

      • When you want use a particular DB property of a relationship in formula, use edge.data.name_of_property.

    • source : relationship's source (start) node

      • When you want use a particular DB property of the source (start) node in formula, use source.data.name_of_property.

    • target : relationship's target (end) node

      • When you want use a particular DB property of the target (end) node in formula, use target.data.name_of_property.

  • Virtual property on a merged relationship can use these variables:

    • edges : array of objects with data of relationships which are merged to a particular merged relationship

      • When you want to use a particular DB property of the first relationship in the formula, use edges[0].data.name_of_property.

    • source : relationship's source (start) node

      • When you want use a particular DB property of the source (start) node in formula, use source.data.name_of_property.

    • target : relationship's target (end) node

      • When you want use a particular DB property of the target (end) node in formula, use target.data.name_of_property.

  • Virtual property on a direction merged relationship can use these variables:

    • edges : array of objects with data of relationships which are merged to a particular merged relationship

      • When you want to use a particular DB property of the first relationship in the formula, use edges[0].data.name_of_property.

    • source : relationship's source (start) node

      • When you want use a particular DB property of the source (start) node in formula, use source.data.name_of_property.

    • target : relationship's target (end) node

      • When you want use a particular DB property of the target (end) node in formula, use target.data.name_of_property.

Examples

Title by node labels - if you want to, for instance, use different property values as titles of nodes for different node labels, you can create a virtual property on nodes (example below) and then use this virtual property as the node title to show the values in the visualization.

Title by node labels
for (var i = 0; i < node.data._dbLabels.length; i++){
var label = node.data._dbLabels[i];
switch (label){
case "Person":
return node.data.name;
break;
case "Company":
return node.data.title;
break;
case "Address":
return node.data.street + ", " + node.data.city;
break;
default:
return node.data.uuid;
}
}

Average of property values - this formula can be used to calculate an average value of some property stored on relationships of a node. This virtual property can be then used for styling the nodes in the visualization, e.g. size or color can be linearly mapped to numerical intervals.

Average of property values
if (edges == undefined || edges.length == 0){return 0;}
var sum = 0;
var count = 0;
for (var i = 0; i < edges.length; i++){
var edge = edges[i];
var value = parseFloat(edge.data.property);
if (!isNaN(value)){
sum += value;
count++;
}
}
var avg = sum/count;
return avg;