@antv/g2
Version:
the Grammar of Graphics in Javascript
29 lines (25 loc) • 725 B
text/typescript
import {
curveCatmullRomClosed,
curveMonotoneX,
curveMonotoneY,
} from 'd3-shape';
import { isPolar, isTranspose } from '../../utils/coordinate';
import { ShapeComponent as SC } from '../../runtime';
import { Curve } from './curve';
export type SmoothOptions = Record<string, any>;
export const Smooth: SC<SmoothOptions> = (options, context) => {
const { ...rest } = options;
const { coordinate } = context;
return (...params) => {
const curve = isPolar(coordinate)
? curveCatmullRomClosed
: isTranspose(coordinate)
? curveMonotoneY
: curveMonotoneX;
return Curve({ curve, ...rest }, context)(...params);
};
};
Smooth.props = {
...Curve.props,
defaultMarker: 'smooth',
};