Menu

calculate false in formulas

b_alary
2017-09-12
2017-09-12
  • b_alary

    b_alary - 2017-09-12

    Hello,

    I installed Freeplane 1.6.6 and I discover with great pleasure the possibility of carrying out calculations in the attributes.
    Only after several attempts the formula returns an erroneous result.
    Not knowing the language I find it difficult to find the error.
    Could anyone help me?

    "=children.size()>0?children.sum(0){it["Durée"].num0}:Current["Durée"].num0"

    the formula summates the child nodes but does not add the current node.

    thanking you in advance

     
  • Luigi Kang

    Luigi Kang - 2017-09-12
    =children.sum(0){it["Durée"].num0}+node["Durée"].num0
    
     
  • b_alary

    b_alary - 2017-09-13

    Hello,

    Thank you for your answer.

    This solution was the one I had thought of at the bottom and in the end I find that this solution seems therefore the most viable.

    Nevertheless, after analyzing several maps, I noticed the addition at the beginning of the formula "= children.size ()> 0?" to check that the nodes were not empty in verification and that the attributes were not empty and therefore to avoid the formulation of an error. Also I would have 3 questions:
    - Does this formula start verifying whether the node is empty or not?
    - This notation corresponds to what syntax?
    - Where can I find a doc on these different syntaxes, the documentation being very vast?

    indeed, the possibility of making formulas is very interesting especially in a conceptual map, unfortunately, there is very little documentation or help on this subject especially for a non-professional programming or application development.

    thank you in advance for any additional answers

     
  • Luigi Kang

    Luigi Kang - 2017-09-13

    The formula in my previous post does not check the size of children to be more than 0. Though some map developed using older Freeplane veresion may need the size check, it will not give you an error on Freeplane version 1.6.3, whether there's no child, or no target attribute name e.g. Durée, in the current node. If the formula gives you an error please state your Freeplane version and upload the map where you run into problem.

    If you want to avoid the theoretical (since the formula above doesn't actually give an error on a childless node) null exception error, you can use the safe navigation operator.

    =children?.sum(0){it["Durée"].num0}+node["Durée"].num0
    

    Formulas are similar to Groovy scripting. And in Freeplane API documentation, "node" refers to the currently selected node.
    http://groovy-lang.org/operators.html#_normal_arithmetic_operators
    https://www.freeplane.org/wiki/index.php/Formulas
    https://www.freeplane.org/wiki/index.php/Scripting#Hello_Controller

     
  • b_alary

    b_alary - 2017-09-13

    Thank you for the clarification

     
  • Mike Petonic

    Mike Petonic - 2017-09-17

    Can you mark a post as "Answered: <previous post="" subject="">"? That would be good manners and nice housekeeping.