import type { DisplayObjectConfig, EllipseStyleProps as GEllipseStyleProps, Group } from '@antv/g';
import { Ellipse as GEllipse } from '@antv/g';
import { ICON_SIZE_RATIO } from '../../constants/element';
import type { Point } from '../../types';
import { getEllipseIntersectPoint } from '../../utils/point';
import { mergeOptions } from '../../utils/style';
import type { IconStyleProps } from '../shapes';
import type { BaseNodeStyleProps } from './base-node';
import { BaseNode } from './base-node';
/**
* 椭圆节点样式配置项
*
* Ellipse node style props
*/
export interface EllipseStyleProps extends BaseNodeStyleProps {}
/**
* 椭圆节点
*
* Ellipse node
*/
export class Ellipse extends BaseNode {
static defaultStyleProps: Partial = {
size: [45, 35],
};
constructor(options: DisplayObjectConfig) {
super(mergeOptions({ style: Ellipse.defaultStyleProps }, options));
}
protected drawKeyShape(attributes: Required, container: Group) {
return this.upsert('key', GEllipse, this.getKeyStyle(attributes), container);
}
protected getKeyStyle(attributes: Required): GEllipseStyleProps {
const keyStyle = super.getKeyStyle(attributes);
const [majorAxis, minorAxis] = this.getSize(attributes);
return {
...keyStyle,
rx: majorAxis / 2,
ry: minorAxis / 2,
};
}
protected getIconStyle(attributes: Required): false | IconStyleProps {
const style = super.getIconStyle(attributes);
const { rx, ry } = this.getShape('key').attributes;
const size = Math.min(+rx, +ry) * 2 * ICON_SIZE_RATIO;
return style ? ({ width: size, height: size, ...style } as IconStyleProps) : false;
}
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
const keyShapeBounds = this.getShape('key').getBounds();
return getEllipseIntersectPoint(point, keyShapeBounds, useExtendedLine);
}
}