Help - Old:Calculating node/branch data (until 2.3.0)
This article describes this feature for TreeGraph 2.3.0 or (not necessaryly all) earlier versions. See here for the article on the latest version and a list on other available article versions. |
The Calculate node/branch data... function allows you to specify an mathematical expression which defines values for all lines of a node/branch data column. In this expression you can reference the current values of the specified column as well as the values of all other columns. Additionally a set of predefined functions and constants (see below) can be used.
Note that this feature was not available before version 2.0.24. The Edit node/branch data-dialog which was present before this version offered a set of rescaling operations instead. It is recommended to use the latest version of TreeGraph 2.
Contents
The dialog
To access the Calculate node/branch data-dialog select Edit → Node/branch data → Calculate node/branch data... from the main menu.
Column
Here you can select the node/branch data column that shall be calculated. The column which was selected in the document window is preselected here if it is editable.
Expression
You can type in a mathematical expression like it is describes below here.
Recently used expressions
In this list you select one of the last 25 valid expressions you have specified to use them again.
Expressions
Accessing node/branch data
The function getValue
returns the value of a specified node/branch data column in the line which is currently calculated. It can take one or two parameters. The first parameter always specifies the column that should be referenced either by its ID (if it is a hidden node/branch data or a label column) or by a special key word (see below) used to identify the default node name-, node name- or branch length-column.
The second parameter is optional and defines a default value which is returned if the referenced column does not contain a value in the current line. If no default value is specified and the referenced column contains no value the calculation for this line is aborted and the value stored in the target column will be empty.
Examples
Expression: | Description: |
---|---|
getValue(NAME) |
Returns the node name in the current line. (Could be a numeric or a textual value.) |
getValue(LENGTH) |
Returns the branch length in the current line. |
getValue(LENGTH, 0) |
Returns the branch length in the current line or 0 if no branch length is specified. |
getValue("id1") |
Returns the value of the column with the ID "id1" in the current line. (This could be a hidden node data-, a hidden branch data or a label column.) |
Checking node/branch data
The function hasValue
can be used to check whether a node/branch data column contains a value in the current line. It has one parameter which specifies the column (analog to getValue
) that shall be checked.
This function can be helpful in combination with the if
-function (see below) in an expression like this:
if(hasValue("id1") || hasValue("id2"), getValue(NAME), "undefined")
Special keywords
The following special keywords can be used with the getValue
or hasValue
functions.
THIS
: References the column which shall be calculated by this expression. (E.g.getValue(THIS) * 2
would set the new value of this column as two times the old value.)UNIQUE
: References the unique node name column.NAME
: References the node name column.LENGTH
: References the branch length column.
Operators
The following list contains all valid operators. Each operator binds as strong or more than all operators listed below. The right columns indicate of which types the operands have to be.
General functions
Name: | Definition: | Description: |
---|---|---|
Sum | sum(Numeric v1, Numeric v2, ...) |
Returns the sum of all passed parameters. Two or more parameters can be passed.(This function was not available before version 2.0.47.) |
Product | product(Numeric v1, Numeric v2, ...) |
Returns the product of all passed parameters. Two or more parameters can be passed.(This function was not available before version 2.0.47.) |
Maximum value | max(Numeric v1, Numeric v2, ...) |
Returns the maximum of all passed parameters. Two or more parameters can be passed.(This function was not available before version 2.0.47.) |
Minimum value | min(Numeric v1, Numeric v2, ...) |
Returns the minimum of all passed parameters. Two or more parameters can be passed.(This function was not available before version 2.0.47.) |
Sine | sin(Numeric x) |
Calculates the sine of the passed numeric value. |
Cosine | cos(Numeric x) |
Calculates the cosine of the passed numeric value. |
Tangent | tan(Numeric x) |
Calculates the tangent of the passed numeric value. |
Inverse sine | asin(Numeric x) |
Calculates the inverse sine of the passed numeric value. |
Inverse cosine | acos(Numeric x) |
Calculates the inverse cosine of the passed numeric value. |
Inverse tangent | atan(Numeric x) |
Calculates the inverse tangent of the passed numeric value. |
Inverse tangent | atan2(Numeric x, Numeric y) |
Calculates the inverse tangent (or arcus tangent) of y / x given adjacent and x. The result is between -π and π |
Hyperbolic sine | sinh(Numeric x) |
Calculates the hyperbolic sine of the given angle. |
Hyperbolic cosine | cosh(Numeric x) |
Calculates the hyperbolic cosine of the given angle. |
Hyperbolic tangent | tanh(Numeric x) |
Calculates the hyperbolic tangent of the given angle. |
Inverse hyperbolic sine | asinh(Numeric x) |
Calculates the inverse hyperbolic sine of the given angle. |
Inverse hyperbolic cosine | acosh(Numeric x) |
Calculates the inverse hyperbolic cosine of the given angle. |
Inverse hyperbolic tangent | atanh(Numeric x) |
Calculates the inverse hyperbolic tangent of the given angle. |
Natural logarithm | ln(Numeric x) |
Calculates the natural logarithm of the passed numeric value. |
Logarithm to the base 10 | log(Numeric x) |
Calculates the logarithm to the base 10 of the passed numeric value. |
Exponential function | exp(Numeric x) |
Calculates the exponential function to the base e. It is the inverse function of the natural logarithm (ln ). |
Magnitude | abs(Numeric x) |
Returns the absolute value of the passed numeric parameter. |
Random number | rand(Numeric x) |
Returns a random number between 0 and 1. |
Square Root | sqrt(Numeric x) |
Calculates the square root of the passed numeric parameter. |
Alternative | if(Boolean condition, Numeric or textual trueValue, Numeric or textual falseValue) |
Returns the second parameter if the condition is true or the third if not. |
Number to text | str(Numeric or textual x) |
Returns a textual representation of the passed parameter. |
Constants
- Euler's number:
e
- π:
pi