| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- var __rest = (this && this.__rest) || function (s, e) {
- var t = {};
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
- t[p] = s[p];
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
- t[p[i]] = s[p[i]];
- }
- return t;
- };
- import { Coordinate } from '@antv/coord';
- import { useLibrary } from './library';
- export function createCoordinate(layout, partialOptions, library) {
- const [useCoordinate] = useLibrary('coordinate', library);
- const { innerHeight, innerWidth, insetLeft, insetTop, insetRight, insetBottom, marginLeft, marginTop, } = layout;
- const { coordinates: partialTransform = [] } = partialOptions;
- const transform = inferCoordinate(partialTransform);
- const coordinate = new Coordinate(Object.assign(Object.assign({}, layout), { x: insetLeft + marginLeft, y: insetTop + marginTop, width: innerWidth - insetLeft - insetRight, height: innerHeight - insetBottom - insetTop, transformations: transform.map(useCoordinate).flat() }));
- return coordinate;
- }
- export function coordinate2Transform(node, library) {
- // @ts-ignore
- const { coordinate = {} } = node, rest = __rest(node, ["coordinate"]);
- const { type, transform = [] } = coordinate, options = __rest(coordinate, ["type", "transform"]);
- if (!type)
- return Object.assign(Object.assign({}, rest), { coordinates: transform });
- const [, createCoordinate] = useLibrary('coordinate', library);
- const { transform: isTransform = false } = createCoordinate(type).props || {};
- if (isTransform) {
- throw new Error(`Unknown coordinate: ${type}.`);
- }
- return Object.assign(Object.assign({}, rest), { coordinates: [Object.assign({ type }, options), ...transform] });
- }
- export function coordOf(coordinates, type) {
- return coordinates.filter((d) => d.type === type);
- }
- /**
- * todo Duplication is not considered
- */
- export function isPolar(coordinates) {
- return coordOf(coordinates, 'polar').length > 0;
- }
- export function isHelix(coordinates) {
- return coordOf(coordinates, 'helix').length > 0;
- }
- /**
- * todo The number of transposes matters
- */
- export function isTranspose(coordinates) {
- return coordOf(coordinates, 'transpose').length % 2 === 1;
- }
- export function isParallel(coordinates) {
- return coordOf(coordinates, 'parallel').length > 0;
- }
- export function isTheta(coordinates) {
- return coordOf(coordinates, 'theta').length > 0;
- }
- export function isReflect(coordinates) {
- return coordOf(coordinates, 'reflect').length > 0;
- }
- export function isRadial(coordinates) {
- return coordOf(coordinates, 'radial').length > 0;
- }
- export function isRadar(coordinates) {
- return coordOf(coordinates, 'radar').length > 0;
- }
- /**
- * todo The axis corresponding to the Y reversal is not reversed
- */
- export function isReflectY(coordinates) {
- return coordOf(coordinates, 'reflectY').length > 0;
- }
- function inferCoordinate(coordinates) {
- if (coordinates.find((d) => d.type === 'cartesian'))
- return coordinates;
- return [...coordinates, { type: 'cartesian' }];
- }
- //# sourceMappingURL=coordinate.js.map
|