AntV
Search…
Group

Group

1
new Group(config);
Copied!
Group constructor. Groups are used to contain shapes or other groups.
  • config: Object or Null, if config is an object, it can contain the following attributes:
Name
Type
Description
zIndex
Number
z-index for group, used to adjust the drawing order.
visible
Boolean
visible or hidden
className
String
mark of the object, specified by users
Example:
1
const group = new F2.G.Group();
Copied!

Methods

getChildren()

1
/**
2
* Get the elements contained in the container
3
* @return {Array}
4
*/
5
getChildren()
Copied!
isDestroyed()
1
/**
2
* Wether the object is destroyed.
3
* @return {Boolean}
4
*/
5
isDestroyed()
Copied!
isVisible()
1
/**
2
* Wether the current group object is visible.
3
* @return {Boolean}
4
*/
5
isVisible()
Copied!
isGroup()
1
/**
2
* If true, the current object is a group object.
3
* @return {Boolean}
4
*/
5
isGroup()
Copied!
addShape(type, config)
1
/**
2
* Create a shape and add it to group
3
* @param {String} type Type of shape to create and add
4
* @param {Object} config Configuration of the shape
5
* @return {Shape}
6
*/
7
addShape(type, config = {})
Copied!
The config parameter passed in is the configuration of the shape, includes:
1
{
2
className: {String}, // class name specified by users
3
zIndex: {Number}, // z-index of the shape
4
visible: {Boolean}, // wether the shape is visible
5
attrs: {Object} // graphic attributes of the shape, different shapes have different attributes, see Shape for more details.
6
}
Copied!
addGroup(config)
1
/**
2
* Create and add a group
3
* @param {Object||Null} cfg Configuration for group
4
* @return {Group}
5
*/
6
addGroup(config)
Copied!
config can be Null or Object, if the config is an object, passed in is the configuration for Group can be:
1
{
2
className: {String}, // user specified class name
3
zIndex: {Number}, // hierarchical index of the group
4
visible: Boolean // wether the group is visible
5
}
Copied!
add(items)
1
/**
2
* Add elements to group
3
* @param {Array||Group||Shape} Items can be a shape instance, a group instance, a shape array or a group array
4
* @return {Group}
5
*/
6
add(items)
Copied!
contain(item)
1
/**
2
* Wether current grop contains the item
3
* @param {Shape||Group} Item can be a shape instance or group instance
4
* @return {Boolean}
5
*/
6
contain(item)
Copied!
sort()
1
/**
2
* Sort the elements in the container by their zIndex, in descending order
3
* @return {Group}
4
*/
5
sort()
Copied!
getBBox()
1
/**
2
* Get the minimum bounding box of the current group
3
* @return {Object}
4
*/
5
getBBox()
Copied!
The bounding box returned has the following structure:
1
{
2
minX: 39.17999267578125,
3
minY: 52.131654999999995,
4
maxX: 211,
5
maxY: 116.58097999999998,
6
width: 171.82000732421875,
7
height: 64.44932499999999
8
}
Copied!
getParent()
1
/**
2
* Get the parent element
3
* @return {Group || Canvas} The parent element of the current object, may be a group object or canvas object
4
*/
5
getParent()
Copied!
show()
1
/**
2
* Display the group
3
*/
4
show()
Copied!
hide()
1
/**
2
* Hide the group
3
*/
4
hide()
Copied!
get(name)
1
/**
2
* Get the attribute from group by attribute name
3
* @param {String} name attribute name
4
* @return {*}
5
*/
6
get(name)
Copied!
set(name, value)
1
/**
2
* Set the attribute value for the corresponding attribute name
3
* @param {String} name attribute name
4
* @param {String} value the value setting for the attribute
5
*/
6
set(name, value)
Copied!
getMatrix()
1
/**
2
* Get the current matrix
3
* @return {Array}
4
*/
5
getMatrix()
Copied!
setMatrix(m)
1
/**
2
* Set matrix
3
* @param {Array} m Matrix array
4
*/
5
setMatrix(m)
Copied!
transform(actions)
Perform matrix transformation on the current object.
1
transform(actions) // actions is an array containing the set of operations
Copied!
The operations supported in actions are 't' (translate), 's' (scale), 'r' (rotate), operations can be combined in any combination order. For example:
1
[
2
[ 't', x, y ], // t for translate, x for offset on x-axis direction, y for offset in y-axis direction
3
[ 's', sx, sy ], // s for scale, sx for scale on x-axis direction, sy for scale on y-axis direction
4
[ 'r', radian] // r for rotate,radian for the radians of the rotation
5
]
Copied!
translate(x, y)
1
/**
2
* Translate the current element
3
* @param {Number} x Offset in x-axis direction
4
* @param {Number} y Offset in y-axis direction
5
*/
6
translate(x, y)
Copied!
rotate(radians)
1
/**
2
* Rotate the current element
3
* @param {Number} radian The radians of the rotation
4
*/
5
rotate(radian)
Copied!
scale(sx, sy)
1
/**
2
* Perform scale operation on current object
3
* @param {Number} sx The scale on x-axis direction
4
* @param {Number} sy The scale on y-axis direction
5
*/
6
scale(sx, sy)
Copied!
setTransform(actions)
Do translating, rotating and scaling operations after resetting the matrix.
1
setTransform(actions) // actions is an array containing operations
Copied!
The actions parameter is same as the parameter in transform(actions).
clear()
1
/**
2
* Clear all the elements
3
* @return {Group} The container itself
4
*/
5
clear()
Copied!
remove(destroy)
1
/**
2
* Remove item itself from its parent
3
* @param {Boolean} destroy true means to destroy iteself after removing, false means just remove but not destroy.
4
* @return {null}
5
*/
6
remove(destroy)
Copied!
destroy()
Destroy the element itself, if it has a parent, remove it from parent.
Last modified 3yr ago
Copy link
Contents
Group