Control

Vecta.Control

new Vecta.Control(shape, [index])

Vecta control point object. A control point can be attached to all shapes, except to a connector.

The purpose is to add more controls to extend the functionality of a shape.

NameTypeAttributesDescription
shapeVecta.Shape

The shape to add a control point to.

indexnumberoptional

The index of the control point. If given, find the control point. Else, create a control point

Methods

.delete()

Deletes the control point from the shape.

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
    control = new Vecta.Control(shape);

console.log(shape.controls()); //[Vecta.Control]
control.delete();
console.log(shape.controls()); //[]

.formula(field, [formula]) Returns: string|boolean|object

Gets or sets formula.

NameTypeAttributesDescription
fieldstring

Accepts any methods found in Vecta.Control class.

formulastringoptional

Formula for the given field. Undefined to get the formula, null to remove or pass in a script to write into field as formula.

Examples:
var control = new Vecta.Control(Vecta.activePage.shapes()[0], 0);

console.log(control.formula()); //returns all formulas available in this control point.
console.log(control.formula('min.x')); //returns formula for min.x
console.log(control.formula('min.x', null)); //remove formula for min.x
console.log(control.formula('min.x', 'this.moveU().x')); //adds a formula to min.x

.max([x], [y]) Returns: Vecta.Control|Object

Get or set maximum limit for control point movement. If both x and y is undefined, maximum value will be returned.

NameTypeAttributesDescription
xnumber|stringoptional

x coordinates of the maximum limit. If null is supplied, x coordinate for maximum limit is removed.

ynumber|stringoptional

y coordinates of the maximum limit. If null is supplied, y coordinate for maximum limit is removed.

Returns:

Returns Vecta.Control or x and y coordinates

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
    control = new Vecta.Control(shape);

console.log(control.max()); //x: "50px", y: "50px"}
control.move('60px', '60px'); //Error: Both x and y coordinates supplied are not within the limits set by min (or/and) max.

control.max(null, null);
control.move('60px', '60px');
console.log(control.move()); //x: "60px", y: "60px"}

.maxU([unit], [format]) Returns: Object

Get control point's maximum limit in multiple formats. Read only.

NameTypeAttributesDescription
unitstringoptional

The unit to return. If not supplied or invalid, will default to px. Valid values are: px, mm, in, cm

formatstringoptional

Specifies the format of the returned value. If no format is specified, will return numbers.

Valid formats are in the form of 0.00mm or 0.0000 cm.

Returns:

Returns x and y in the following format:

[x: number|string, y: number|string]

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50), //creates a rectangle shape
    control = new Vecta.Control(shape); //create a control point

console.log(control.maxU()); //{x: 50, y: 50}
console.log(control.maxU('mm')); //{x: 13.22916629869078, y: 13.22916629869078}
console.log(control.maxU('mm', '0mm')); //{x: "13mm", y: "13mm"}

.min([x], [y]) Returns: Vecta.Control|Object

Get or set minimum limit for control point movement. If both x and y is undefined, minimum value will be returned.

NameTypeAttributesDescription
xnumber|stringoptional

x coordinates of the minimum limit. If null is supplied, x coordinate for minimum limit is removed.

ynumber|stringoptional

y coordinates of the minimum limit. If null is supplied, y coordinate for minimum limit is removed.

Returns:

Returns Vecta.Control or x and y coordinates

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
    control = new Vecta.Control(shape);

console.log(control.min()); //x: "0px", y: "0px"}
control.move('-10px', '-10px'); //Error: Both x and y coordinates supplied are not within the limits set by min (or/and) max.

control.min(null, null);
control.move('-10px', '-10px');
console.log(control.move()); //x: "-10px", y: "-10px"}

.minU([unit], [format]) Returns: Object

Get control point's minimum limit in multiple formats. Read only.

NameTypeAttributesDescription
unitstringoptional

The unit to return. If not supplied or invalid, will default to px. Valid values are: px, mm, in, cm

formatstringoptional

Specifies the format of the returned value. If no format is specified, will return numbers.

Valid formats are in the form of 0.00mm or 0.0000 cm.

Returns:

Returns x and y in the following format:

[x: number|string, y: number|string]

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50), //creates a rectangle shape
    control = new Vecta.Control(shape); //create a control point

console.log(control.minU()); //{x: 0, y: 0}
console.log(control.minU('mm')); //{x: 0, y: 0}
console.log(control.minU('mm', '0mm')); //{x: '0mm', y: '0mm'}

.move([x], [y]) Returns: Vecta.Control|Object

Gets or sets the control point's position. If both x and y is undefined, returns the control point's position. During creation, the move coordinate is defaulted to half the shape's width and height

NameTypeAttributesDescription
xnumber|stringoptional

x coordinate of the control point

ynumber|stringoptional

y coordinate of the control point

Returns:

Returns Vecta.Control or x and y coordinates

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
    control = new Vecta.Control(shape);

console.log(control.move()) //{x: 25, y: 25}
control.move(10, 10);
console.log(control.move()) //{x: 10, y: 10}
control.move('10px', '10px');
console.log(control.move()) //{x: '10px', y: '10px'}

.moveU([unit], [format]) Returns: Object

Get control point's coordinates in multiple formats. Read only.

NameTypeAttributesDescription
unitstringoptional

The unit to return. If not supplied or invalid, will default to px. Valid values are: px, mm, in, cm

formatstringoptional

Specifies the format of the returned value. If no format is specified, will return numbers.

Valid formats are in the form of 0.00mm or 0.0000 cm.

Returns:

Returns x and y in the following format:

[x: number|string, y: number|string]

Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
    control = new Vecta.Control(shape);

console.log(control.moveU()); //{x: 25, y: 25}
console.log(control.moveU('mm')); //{x: 6.61458314934539, y: 6.61458314934539}
console.log(control.moveU('mm', '0mm')); //{x: '7mm', y: '7mm'}