Reformat with fx

With graph-based f(x) functions you can calculate values based on existing properties and write the results back to new or existing properties of the source nodes or edges. This capability is similar to formulas in Excel and SQL, and functions in a MapReduce framework.

An f(x) javascript formula is run on the data of a single category or relationship. To apply a pre-defined or custom formula, you select existing categories or relationships and their properties, specify the formula, and either write the results to a new property or overwrite the original property value.

f(x) Preset formulas

The following table lists the available preset formulas and their general formats.

Preset Function Format

Custom

Editable format

(propVal,props) => propVal

toNumber

String or Number => a Number

(propVal,props) => Number(propVal) | 0

toString

String, Number, or Date => a String

(propVal,props) => String(propVal)

toDate

Valid date-time =>
a YYYY-MM-DD HH:mm:ss timestamp

(propVal,props) => moment(propVal).format('YYYY-MM-DD HH:mm:ss')

toDayOfWeek

Valid date-time =>
a weekday (e.g. Monday)

(propVal,props) => moment(propVal).format('dddd')

convertCustomDate

Custom date format MM,DD,YYYY => a YYYY-MM-DD HH:mm:ss timestamp

(propVal,props) => moment(propVal, "MM,DD,YYYY").format('YYYY-MM-DD HH:mm:ss')

fixDayFirst

Custom date format DD/MM/YYYY => a YYYY-MM-DD HH:mm:ss timestamp

(propVal,props) => moment(propVal, "MM/DD/YYYY").format('YYYY-MM-DD HH:mm:ss')

Run a preset f(x) formula

Formulas apply to one category or relationship at a time. You can run more than one formula at a time on a selection of data. In the following example we’ll use the toString preset to transform data from numerical values to a string.

To run a preset formula:

  1. Open the Transform panel and f(x) tab.

  2. Under Select Target, choose a Category or Relationship from the dropdown menu.

    All the data for the chosen category or relationship will be transformed unless you explicitly select data to be transformed. If you select nodes or edges on the canvas, the transform operates only on that data. You might do this to test your transform with a subset of the data for the selected category or relationship.
  3. Under Select Properties choose the property value to transform (e.g. Score), or click the + icon in the table of properties below the dropdown to select it. A preview shows existing values and their data formats.

  4. Choose a preset formula from the dropdown menu, in this case, toString to convert the numerical values in the Score property to text strings.

    06 01 01 FxPresetStart
  5. Enter a descriptive name for the new property (e.g. scoreString). If you don’t enter a name, the default transform simply adds new to the existing Selected Property name.

    06 01 02 FxPresetToString
    You can enter the source property name to overwrite the existing property values, and this may be useful in some cases. However, it is usually best to create a new property.
  6. Check the sample output property values for the formula (displayed beneath the Selected Property and New Property Name, respectively) to see that the formula returns values you expect.

    If the input property value is invalid for a selected formula, a brief description of the problem is displayed.
    • In this example, we’ll run just one formula. At this point we could:

      • Add more formulas (for example to transform other property values in the selected Category or Relationship).

      • Delete a formula by clicking its Trash can icon.

  7. Scroll to the bottom of the panel to run the transform. On the run button, check that the number of nodes (or edges) is what you expect. Then click the button to create the new property and calculate its values.

    The new property is added to the category or relationship. The property name and calculated value is added to each node (or edge) that supplies valid input. Log status messages appear below the run button.

    06 01 03 FxPresetToStringDone
  8. To inspect the new property and its values, open the Table panel and under Category or Relationship, click to show the table. You can also review the new property in an information panel for a node or edge.

Run a Custom f(x) formula

Custom formulas enable you to enter javascript functions to combine multiple properties into a single property, and handle many other complex data conversions.

Supported libraries are Lodash.js and Moment.js.

To run a custom formula to create a new property:

  1. Open the Transform panel and f(x) tab.

    In this example, we use a custom formula on the nodes of an Officer category to combine first name and surname property values to create a new fullName property.

  2. In the Select Target section, we click Category and select Officer from the dropdown menu.

  3. In Select Properties choose a property (e.g. name) from the dropdown menu, or click its name in the preview list. This copies it to the Configure Transformations section.

  4. In Configure Transformations we open the Input formula menu, select Custom , and enter the following javascript formula:

    (propVal, props) => !props['name'] ? propVal : `${props['name']} ${props['surname']}`

    If there is a problem with the formula or the source data, a brief message appears under the property name (for example, "Invalid input").

  5. In the New Property Name textbox, enter the new property name (e.g. fullName).

    06 01 04 CustomFxSetup
  6. Scroll to the bottom of the panel to run the transform. Click the run button to create the new custom property values.

    The new property is added to the selected category and the name and calculated value will be added to each node that includes valid input, and Log status messages appear below the run button.

    06 01 05 CustomFxDone
  7. To inspect the new property and its values, open the Table panel and select the category (or relationship). You can also see the new property in a node’s information panel.