new Vecta.Control(shape, [index])
Vecta control point object.
A control point is a user interface component that can be added to a shape to extend it's functionality. For example, adding a control point to easily reposition text on a shape.
Name | Type | Attributes | Description |
---|---|---|---|
shape | Vecta.Shape | The shape to add a control point to. | |
index | number | optional | 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); //creates a new control object
control.delete(); //delete the control point
.formula([field], [form]) Returns: string|Promise
Get or sets formula.
Name | Type | Attributes | Description |
---|---|---|---|
field | string|Object | optional | Accepts any methods found in Vecta.Control class. If not provided, returns all formula. For set operations, field can be a string to set formula for a field or an object to set multiple fields, with the following format:
|
form | string | optional | Formula for the given field. If not provided, returns current formula. If null is provided, remove the formula. If string is provided as a script, write into field as formula. |
Returns:
If get, returns formula for given field. Otherwise, returns promise that resolves validity of the formula.
Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
control = new Vecta.Control(shape); //creates a new control object
//returns all formulas available in this control point
console.log(control.formula());
//returns formula for min.x
console.log(control.formula('min.x'));
//remove formula for min.x
console.log(control.formula('min.x', null));
//adds a formula to min.x
control.formula('min.x', 'this.moveU().x').then(function (val) {
console.log(val);
});
//adds a formula to min.x and min.y
control.formula({ 'min.x': 'this.moveU().x', 'min.y': 'this.moveU().y' }).then(function (val) {
console.log(val);
});
.hidden([state]) Returns: boolean|Vecta.Control
Get or set the visibility of a control point.
Name | Type | Attributes | Description |
---|---|---|---|
state | boolean | optional | Undefined if get, or true or false if set |
Returns:
Returns true if hidden or false when not for get operation, and Vecta.Control for set operation.
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.hidden()); //false
control.hidden(true); //set control point to hidden
console.log(control.hidden()); //true
.id() Returns: string
Get the control point id. Read only.
Returns:
Returns the control point ID.
.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.
Name | Type | Attributes | Description |
---|---|---|---|
x | number|string | optional | x coordinates of the maximum limit. If null is supplied, x coordinate for maximum limit is removed. |
y | number|string | optional | 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); //remove the control point's maximum limits
control.move('60px', '60px'); //set the control point's maximum limits to 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.
Name | Type | Attributes | Description |
---|---|---|---|
unit | string | optional | The unit to return. If not supplied or invalid, will default to |
format | string | optional | Specifies the format of the returned value. If no format is specified, will return numbers. Valid formats are in the form of |
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('0mm', '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.
Name | Type | Attributes | Description |
---|---|---|---|
x | number|string | optional | x coordinates of the minimum limit. If null is supplied, x coordinate for minimum limit is removed. |
y | number|string | optional | 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); //removes the control point's minimum limit
control.move('-10px', '-10px'); //set the control point's minimum limit to -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.
Name | Type | Attributes | Description |
---|---|---|---|
unit | string | optional | The unit to return. If not supplied or invalid, will default to |
format | string | optional | Specifies the format of the returned value. If no format is specified, will return numbers. Valid formats are in the form of |
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('0mm', '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.
When a control point is first created, it's move coordinate is defaulted to the center of the shape
Name | Type | Attributes | Description |
---|---|---|---|
x | number|string | optional | x coordinate of the control point |
y | number|string | optional | 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.
Name | Type | Attributes | Description |
---|---|---|---|
unit | string | optional | The unit to return. If not supplied or invalid, will default to |
format | string | optional | Specifies the format of the returned value. If no format is specified, will return numbers. Valid formats are in the form of |
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('0mm', '0mm')); //{x: '7mm', y: '7mm'}
.parent() Returns: Vecta.Shape
Get the parent shape for the control point.
.xU([unit], [format]) Returns: number|string
Get x position of a control point in multiple formats. Read only.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
unit | string | optional | px | The unit to return. If not supplied or invalid, will default to |
format | string | optional | Specifies the format of the returned value. If no format is specified, will return numbers. Valid formats are in the form of |
Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
control = new Vecta.Control(shape);
console.log(control.xU()); //25
console.log(control.xU('mm')); //6.61458314934539
console.log(control.xU('mm', '0mm')); //7mm
.yU([unit], [format]) Returns: number|string
Get y position of a control point in multiple formats. Read only.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
unit | string | optional | px | The unit to return. If not supplied or invalid, will default to |
format | string | optional | Specifies the format of the returned value. If no format is specified, will return numbers. Valid formats are in the form of |
Examples:
var shape = Vecta.activePage.drawRect(0, 0, 50, 50),
control = new Vecta.Control(shape);
console.log(control.yU()); //25
console.log(control.yU('mm')); //6.61458314934539
console.log(control.yU('mm', '0mm')); //7mm