ChangeNodeVisibility


new to Analytica 5.0

ChangeNodeVisibility(obj, option, what)

This function can hide or show a node in its Diagram, or display it as "disabled" -- i.e. grayed out to show it is not currently available. For example:

 ChangeNodeVisibility(A, 'Hidden')

hides the node for object A in its Diagram. You can use it to create a dynamic user interface in which certain user inputs or user outputs appear or disappear based on the state of other user inputs. In such cases, you might use ChangeNodeVisibility() in the OnChange attribute of a checkbox or Choice menu user input to control whether other user inputs or outputs are shown.

You can also use this function to query the current visibility state of the node. For example:

 ChangeNodeVisibility(A, 'Is Visible?')

returns true if node A is currently visible.

«obj» parameter

The «obj» parameter is a handle to the node that you want to change or query.

«option» parameter

Change the visibility state by setting the «option» parameter to:

  • "Hidden": The node is not visible in its parent diagram.
  • "Disabled": The node is visible but disabled. It appears "grayed out" and does not respond to user input.
  • "Visible": The node is visible in the diagram user interface.
  • "Enabled": Synonymous with Visible, but this parameter definition may be clearer to a reviewer if your interface is disabling and enabling user inputs (rather than making them visible or hidden).


While a "Hidden" node is invisible in its diagram, the object will still appear and its Object Window accessible in the Outline window, Find Dialog, and links to it that might appear in results, or in inputs and outputs of other variables, etc. It also remains selectable on the diagram in edit mode, even though it is invisible. These options let you hide it more securely:

  • "Very hidden": Node is invisible in its diagram, the Outline window, hierarchy stripe, Find Dialog, etc. However, you can still hyperlink to it if a hyperlink exists.
  • "Extremely hidden": Set so that you can't reach the node via existing hyperlinks get to it from the Analytica UI in general. At this level, it appears to the end-user as if it doesn't exist

It is sometimes useful to hide (or disable) a node in Browse mode but enable it in Edit mode. Hence these options:

  • "Hidden in browse": Make the node is present and visible is edit mode, but does not appear on the diagram in browse mode.
  • "Disabled in browse": Make the node disabled in browse mode. It is enabled in edit mode.

These options let you query a nodes visibility state. (Note that they all end with a question mark.):

  • "Is Visible?": Returns true if the node is visible, and true if disabled but visible. False if not visible on influence diagram.
  • "Is Hidden?": Returns true if the node is hidden (not visible), true otherwise.
  • "Is Disabled?": Returns true if the node is hidden or disabled. True if visible and enabled.
  • "Is Enabled?": Returns true if the node is visible and enabled. False otherwise.
  • "How hidden?": Returns the option text describing the visibility state; "Visible", "Hidden", "Hidden in browse", "Very Hidden", "Extremely hidden", "Disabled", or "Disabled in browse".

When you query the visibility state and specify «what» to be 'UserInputs' or 'UserOutputs', the result is a 1-D array with a local index, where the local index contains the handles of each user input or each user output node, and the value is the result for that node.

«what» parameter

By default, if you omit «what», the functions changes (or queries) the visibility of the node for «obj». But, you can also change the visibility of the user inputs or outputs for a Variable. You set «what» to 'UserInputs' or 'UserOutputs' to change the visibility of all inputs or all outputs of the variable. If you want to changed the visibility of a single user input or user output node, then you should ensure that this is a handle to the user input node, not a handle to the original variable node, and that «what» is omitted. You can also pass 'Original' to «what» to change the visibility of the original (not the alias) of «obj».

Examples

Hide, show, disable or re-enable the user inputs for variable Gender:

ChangeNodeVisibility( Handle(Gender), 'Hidden', 'UserInputs' )
ChangeNodeVisibility( Handle(Gender), 'Visible', 'UserInputs' )
ChangeNodeVisibility( Handle(Gender), 'Disabled', 'UserInputs' )
ChangeNodeVisibility( Handle(Gender), 'Enabled', 'UserInputs' )

Hide your model details module node from your end user:

ChangeNodeVisibility( Handle(Model_details), 'Hidden in browse' )

Make visible user input nodes only when the user makes the choice to edit them. In this example, we augment the car cost model which begins in Tutorial: Create a model. With the following addition to the OnChange field, the user may change the estimated annual maintenance cost and the estimated miles driven per year:

Variable := Choice(Self, 2, 0)
ChangeNodeVisibility( handle( Maintenance_cost ), IF Self = 'No' THEN 'Hidden' ELSE 'Visible', 'UserInputs' );
ChangeNodeVisibility( handle( Mpy ), IF Self = 'No' THEN 'Hidden' ELSE 'Visible', 'UserInputs' )
Onchange example1.gif
Onchange example2.gif

Example Video

Video: Hiding and disabling UI elements (5 minutes)

See Also

Comments


Marksmith

32 months ago
Score 0
This is a nice change to User input and output nodes that lets input nodes to act more like other Windows controls --enable/disable; show/hide-- that we used to only mimic by "greying" the NodeColor or NodeFontColor or by whisking the input control off to a cache module (Evaluatescript('Move ...')). I like the way this enhances the changes that Analytica 4.6 introduced to OnClick and OnChange attributes to replace the Script attribute. Expanding the OnChange attribute to other input node types --not only CheckBox and Choice-- is also a good idea.

You are not allowed to post comments.