For Dashboard Designers Reference Expressions
Friday, November 11, 2022 12:54 PMExpressions
Different parts of Graphileon support Javascript expressions to determine values based on some internal state. For security reasons, the expressions are run in a sandbox, supporting a subset of Javascript expressions and a range of included functions.
Supported expressions
The following expressions are supported:
- Binary operators:
+,-,*,/,%,==,!=,===,!==,>,<,>=,<=,&&,|| - Literals (string/number/boolean/RegExp/null)
- Identifiers (variables)
- Array function expression (e.g. `(arg1, arg2) => arg1 + arg2)
- Call expresion (e.g.
func(arg1, arg2)) - Object expression (e.g.
{prop1: value1, prop2: value2}) - Array expression (e.g.
myArray[0]) - Member expression (e.g.
myObject.prop1) - Conditional expression (e.g.
condition ? value1 : value2) - Unary expressions:
!,-
Supported variables
The following built-in variables are supported:
| Variable | Alias | Situation | Value |
|---|---|---|---|
_global |
(@) |
Functions, Triggers, Permissions, GraphStyles | Global info (see below) |
_event |
(%) |
Triggers, Permissions | Event data, specific for each trigger or permission event |
_entity |
(%) |
GraphStyles | Entity (node/relation) |
Global data
The global data variable (_global or (@)) is an object with the following keys:
| Key | Type | Description |
|---|---|---|
backend |
string | Url of the backend. |
dashboard |
object |
Information of the current dashboard. |
edition |
string | Current Graphileon Edition code. |
instances |
object |
Map of named Function instances, with their current models. |
language |
string | Current language code. |
stores |
object |
Map of store names and their basic info. |
user |
object |
Current user info. |
version |
string | Graphileon software version. |
Supported functions
Graphileon expressions support all functions from the Lodash library, without the _. prefix.
For example, the Lodash function _.get can be used as get.
Besides the Lodash functions, the following functions are supported in Graphileon expressions:
-
addColumn(data, columnName, columnData): adds a column to a tabular data structure.-
data: (array of objects) data -
columnName: (string) name of the column to add -
columnData: (array) values to insert into the new column - returns: (array of objects) modified table data
-
-
arrayToTable(array): converts a simple array into a single-column table.-
array: (array) simple array - returns: (array of objects) table structure with one column
-
-
btoa(str): encodes the given string to a Base64 string.-
str: (string) string to encode - returns: (string) Base64-encoded string
-
-
evaluateString(str): evaluate the given string as a Graphileon expression.-
str: (string) the string to evaluate - returns: (any) the result of the expression
-
-
formatString(template, arg1, arg2, ...): wrapper for the string-format library.-
template: (string) template into which the arguments will be filled in -
arg1,arg2, ...: (any) arguments to be filled into the template -
returns: (string) if both
templateand args are provided, the formatted string. (function) If onlytemplateis provided, returns a function that takes only args and returns a the formatted string.
-
-
isoDate(date): provides the given date asYYYY-mm-ddformat (e.g.2021-03-01).-
date: (Date/string) Date object or date string. If ommitted, current date will be used. - returns: (string) formatted date.
-
-
md5(str): encodes the given string to an MD5 string.-
str: (string) string to encode - returns: (string) MD5-encoded string
-
-
Math(): returns the Javscript Math object.- returns: (Math)
-
pivot(dataArray, rows, columns, aggregationDimension, aggregator, rowHeader, sortFunction, columnSortFunction): wrapper around quick-pivot library, to pivot data. Please see quick-pivot for usage documentation. -returns: (Pivot) Pivot object. -
pivotDataToObjects(params, data): converts an array of cell definitions (e.g.{row: 1, col: 'name', value: 'myName'}). to an array of row objects (e.g.{name: myName})-
params.rowKey: (string) the key of the cell definition to consider the row -
params.columnKey: (string) the key of the cell definition to consider the column -
params.valueKey: (string) the key of the cell definition to consider the value - returns: (array of objects) table format
-
-
toDate(value): creates a Date object based on the given value.-
value: (string/number) date string or timestamp - returns: (Date)
-
-
translate(str): attempts to translate the given string to the current language. See Translations documentation for more info on translations.-
str: (string) the string to translate - returns: (string) translated string, or input string if no translation was found.
-
-
t(str): short-hand alias fortranslate.