text: import ChartJsV3 from 'chart.js-v3';
  const {toRadians} = ChartJsV3.helpers;
  import BoxAnnotation from './box';
  
  export default class EllipseAnnotation extends BoxAnnotation {
  
    inRange(x, y) {
      return pointInEllipse({x, y}, this);
    }
  
    draw(ctx) {
      const {width, height, options} = this;
      const center = this.getCenterPoint();
  
      ctx.save();
  
      ctx.translate(center.x, center.y);
      if (options.rotation) {
        ctx.rotate(toRadians(options.rotation));
      }
  
      ctx.beginPath();
  
      ctx.lineWidth = options.borderWidth;
      ctx.strokeStyle = options.borderColor;
      ctx.fillStyle = options.backgroundColor;
  
      ctx.setLineDash(options.borderDash);
      ctx.lineDashOffset = options.borderDashOffset;
  
      ctx.ellipse(0, 0, height / 2, width / 2, Math.PI / 2, 0, 2 * Math.PI);
  
      ctx.fill();
      ctx.stroke();
  
      ctx.restore();
    }
  }
  
  EllipseAnnotation.id = 'ellipseAnnotation';
  
  EllipseAnnotation.defaults = {
    display: true,
    adjustScaleRange: true,
    borderDash: [],
    borderDashOffset: 0,
    borderWidth: 1,
    rotation: 0,
    xScaleID: 'x',
    xMin: undefined,
    xMax: undefined,
    yScaleID: 'y',
    yMin: undefined,
    yMax: undefined
  };
  
  EllipseAnnotation.defaultRoutes = {
    borderColor: 'color',
    backgroundColor: 'color'
  };
  
  function pointInEllipse(p, ellipse) {
    const {width, height} = ellipse;
    const center = ellipse.getCenterPoint(true);
    const xRadius = width / 2;
    const yRadius = height / 2;
  
    if (xRadius <= 0 || yRadius <= 0) {
      return false;
    }
  
    return (Math.pow(p.x - center.x, 2) / Math.pow(xRadius, 2)) + (Math.pow(p.y - center.y, 2) / Math.pow(yRadius, 2)) <= 1.0;
  }
  