« Back

Fit Name Attribute during Element Resize

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Fit Name Attribute during Element Resize
community graphrep documentation
Answer
3/27/14 12:12 PM
In my model, the value of the "Name" attribute is shown inside the element. However, if the element is manually resized to a smaller size, the name is not within the element borders anymore. How can I ensure that the name is resized together with the element OR that it is restricted to resize the element once the name cannot be fitted within the borders anymore?

The attached picture shows the element upon creation (left) and the element upon resize (right).

Thanks!
Attachment

Attachments: Name_Resize.png (9.4k)

RE: Fit Name Attribute during Element Resize
Answer
1/23/14 2:35 PM as a reply to Natalia Sudakova.
Dear Natalia,

In order to restrict the possibility to resize the object so that the name is not displayed outside the boundaries, I recommend using the elements ATTRBOX and TABLE for calculating and "reserving" space for displaying the attribute "Name".
Below is a simple example of their usage, including some explanations:
 1GRAPHREP sizing: asymmetrical
 2SHADOW off
 3
 4ATTRBOX "Name" w:c h:c
 5# use runtime variables textw and texth
 6
 7TABLE   x: (-textw/2 - 0.1cm) y: (-texth/2 - 0.1cm) w: (textw + 0.2cm) h: (texth + 0.2cm) cols:3 rows:3
 8        w1:0.1cm w2:100% w3:0.1cm
 9        h1:0.1cm h2:100% h3:0.1cm
10
11SET tabw: (tabx2 - tabx1) tabh: (taby2 - taby1)
12
13IF (tabw < textw) {
14   SET tabx0: (-textw/2 - 0.1cm)
15   SET tabx1: (-textw/2)
16   SET tabx2: ( textw/2)
17   SET tabx3: ( textw/2 + 0.1cm)
18}
19IF (tabh < texth) {
20   SET taby0: (-texth/2 - 0.1cm)
21   SET taby1: (-texth/2)
22   SET taby2: (texth/2)
23   SET taby3: (texth/2 + 0.1cm)
24}
25
26SET tabw: (tabx2 - tabx1) tabh: (taby2 - taby1)
27
28STRETCH off
29
30RECTANGLE x: (tabx1) y: (taby1) w: (tabw) h: (tabh)
31
32ATTR "Name" w:c h:c

ATTRBOX is an element which do not produce direct output to the drawing area, but calculates the needed (rectangle) area for the element ATTR.

The parameters resulting from the calculation are assigned to the following variables:
textx1 x-coordinate of the left margin of the text box
texty1
y-coordinate of the above margin of the text box
textx2
x-coordinate of the right margin of the text box
texty2 y-coordinate of the under margin of the text box
textw
width of the textbox
texth
height of the text box

In the code above, textw and texth are used for preventing the object to be shrunk to a size less than the size of the text.

The TABLE element is an assigning element used for re-sizeable objects. A table consists of columns and lines which each have
either a fixed or a variable width or height. Variable widths or heights change when the object's size is changed. The sizes calculated are assigned to runtime variables which the elements below can access. Usually, a TABLE element is followed by a STRETCH off, to avoid double stretching of the elements.

A table defines a rectangular area divided into a fixed number of columns ( cols) and rows ( rows) The attributes for the single column widths of a table of n columns bear the names w1 to wn. Similarly, the attributes for the line heights for m lines are named h1 to hm. If you wish to specify a fixed column width or line height, such as w1:0.2cm you have to
enter this directly. For variable sizes, an amount such as w2:50% or w:0.5 is specified instead. This amount refers to the rest of the table's height or width after the fixed sizes have been subtracted.

From a TABLE element with n columns and m lines the following runtime variables are calculated/derived:
tabw1
to tabwn- column widths
tabh1
to tabhm- line heights
tabx0
to tabxn- x-positions of the columns
taby0
to tabym- y-positions of the columns

In the example above, a table with 3 rows and 3 columns has been defined, where the columns 1 and 3 and the rows 1 and 3 have a fixed dimension of 0.1cm for nicer appearance and the cell at column 2 and row 2 covers the rest of the object area. Every time the width of this central cell falls below the width required to display the value of the attribute "Name", the width of the central cell is set equal to the width required by the attribute. The same happens when the heigth of the central cell falls below the height of the area required by the attribute "Name".

In the end, a rectangle is drawn around the area where the attribute will be displayed ( line 30 ) and then the attribute "Name" is displayed (line 32)