The object to specify and apply transformations.
# Coordinate(options?: Options) : Coordinate
Returns a new coordinate object with specified options.
/* basic usage */
import { Coordinate, Options } from '@antv/coord';
const options: Options = {
x: 10,
y: 20,
width: 500,
height: 600,
transformations: [
['cartesian'],
['translate', 10, 10]
],
};
const coord = new Coordinate(options);
Key | Description | Type | Default |
---|---|---|---|
x | x of the bounding box of the coordinate | number | 0 |
y | y of the bounding box of the coordinate | number | 0 |
width | width of the bounding box of the coordinate | number | 300 |
height | height of the bounding box of the coordinate | number | 150 |
transformations | transformations to be applied to input vector | Array | [] |
# update(options?: Options) : void
Updates the options of the coordinate object.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord.update({
width: 200,
height: 200,
});
# transform(...args?: Tranformation) : Coordinate
Specifies transformation to be applied to the input vector.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord
.transform('polar', 0, Math.PI * 2, 0, 1)
.transform('cartesian')
.transform('scale', 10, 10);
# clear() : void
Clears current transformations.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord
.transform('polar', 0, Math.PI * 2, 0, 1)
.transform('cartesian')
.transform('scale', 10, 10);
coord.clear();
# map(vector: Vector2 | Vector) : Vector2 | Vector
Applies specified transformations to input vector and returns transformed vector. All dimensions of input vector must be normalized value.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord
.transform('cartesian')
.transform('scale', 10, 10);
coord.map([0.5, 0.5]); // [1500, 750]
# invert(vector: Vector2 | Vector) : Vector2 | Vector
Invert specified transformations to transformed vector and returns original vector.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord
.transform('cartesian')
.transform('scale', 10, 10);
coord.invert([1500, 750]); // [0.5, 0.5]
# getSize() : Vector2
Returns the size of the bounding box of the coordinate object.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord.getSize(); // [300, 150]
# getCenter() : Vector2
Returns the center of the bounding box of the coordinate object.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
coord.getCenter(); // [150, 75]
# clone() : Coordinate
Returns a new coordinate object with the same but independent options.
import { Coordinate } from '@antv/coord';
const coord = new Coordinate();
const coord1 = coord.clone();