View area

In AnyLogic the whole agent structure is defined on one presentation diagram that is drawn in the graphical editor. This feature enables users to see all elements of an agent, including animation, charts, statecharts, etc. in the same window at model runtime. And thus the user can analyze the whole state and behavior of the model at a glance. However, in case of large and complex models agents commonly contain a great number of elements, which may result in another inconvenience: it could be impossible to fit all these elements within the model frame area that is shown at runtime.  

AnyLogic offers a special element for solving this problem - view area. Using this element, you can mark out some particular areas on the presentation diagram, containing some logically detached groups of elements or parts of the diagram. Once you have defined such view areas, you can easily switch between them at the model runtime using special navigation tools. This feature enables users to quickly navigate to some particular places of agent's diagram.

Using view areas you can e.g. scatter groups of various elements to different places of the graphical diagram and switch between them at model runtime:

Demo model: View Area

 To define a view area

  1. Drag the View area element from the  Presentation palette to the graphical editor.
  2. You'll see the view area's anchor  and the orange rectangle appeared in the graphical editor. This anchor marks the view area's top-left corner. The orange rectangle marks the actual area that will be displayed when switching to this view area in the model design mode or at model runtime:

  3. By default, the size of a newly added view area matches the model frame size. To change the size, select the view area's anchor in the graphical editor and drag the handles at its borders. Alternatively, set the position and size of the view area in the Position and size section of its properties. 

Properties

General

Name – The name of the area. It is used to identify and access the element from code.

Show name – If selected, the area's name is displayed on a presentation diagram.

Ignore – If selected, the view area is excluded from the model.

Title – Here you can define a title for this view area. The title will be shown in navigation lists opened by toolbar buttons (View areas at the model design time and Show area...  at the model runtime correspondingly). 

Position and size

X – The x-coordinate of the area's anchor.

Y – The y-coordinate of the area's anchor.

Width – The width of the area (in pixels).

Height – The height of the area (in pixels).

How to navigate between view areas

View areas are used either for navigation through the graphical editor in the model design mode and for navigation through the presentation window in the model execution mode. Note that navigating to a view area will automatically scale the view area's content up or down to fit the model frame as closely as possible. For example, if the view area size is smaller than the model frame size, navigating to this view area will scale up the corresponding part of the presentation.

 To navigate to a view area in the model design mode

  1. Click the agent diagram to make the graphical editor active.
  2. Click the View areas  toolbar button and choose from the drop-down list the particular view area you want to navigate to.

 To navigate to a view area in the model execution mode

  1. Right-click (Mac OS: Ctrl+click) in the canvas of the presentation window, choose View area from context menu and choose from the popup list a view area you want to navigate to.

  1. Alternatively, click the Navigate to view area...  toolbar button and choose from the popup list a view area you want to navigate to (this button belongs to the View area toolbar section and if you cannot see it in the toolbar, probably you should set this section visible).

Moreover, you can place on presentation your own elements that will navigate to some view area on mouse click. To implement this, you should write the following code in the corresponding property of that element (Action in the case of a control or On click in the case of a presentation shape):

areaName.navigateTo();

View areas can be used not only to switch between parts of a single agent, but also between different agents. Consider the main object with a population people. To get access from main to the 124-th agent, write:

people(123).personAreaName.navigateTo();

and vice versa, to go one level up from an embedded agent to its container (main object), you can call the code:

main.mainAreaName.navigateTo();

Functions

Navigating to a view area

Function

Description

void navigateTo()

Navigates to the view area.

View area location

Function

Description

double getX()

Returns the X coordinate of the view area.

double getY()

Returns the Y coordinate of the view area.

void setX(double x)

Sets the X coordinate of the view area.

Parameter: x - the new value of X coordinate

void setY(double y)

Sets the Y coordinate of the view area.

Parameter: y - the new value of Y coordinate

View area size

Function

Description

double getHeight()

Returns the height of the view area.

double getWidth()

Returns the width of the view area.

void setHeight(double height)

Sets the height of the view area.

Parameter: height - new height of the view area

void setWidth(double width)

Sets the width of the view area.

Parameter: width - new width of the view area

View area title

Function

Description

String getTitle()

Returns the title of view area (it is shown in the navigation lists (View areas at model design time and Show area...  at model runtime).

void setTitle(String title)

Sets the title for the view area (it is shown in the navigation lists (View areas at model design time and Show area...  at model runtime).

Parameter:
title - the title to set


Related topics

Frame

Moving Presentation Shapes

Resizing Presentation Shapes

 API Reference: ViewArea Class