import { pie as d3Pie } from '../../../polyfill/d3';
/** The PieChartArchPathInputProcessor class processes input data to generate options for rendering a pie or donut chart with D3.js. */
export class PieChartArchPathInputProcessor {
  /**
   * This function processes input data to generate options for rendering a pie or donut chart with D3.js.
   *
   * @param {ChartOptions<PieChartSourceType>} input - The input parameter is an object containing chart options, including the data source, colors, layout, donut radius, and type of chart.
   * @param {PieChartRadiusProcessResultType} previousOutput - previous result from the other input process
   * @returns {ChartArcOptions} An object with a property `renderOptions` which contains an object with properties `data`,
   * `colors`, `outerRadius`, `donutRadius`, and `center`.
   */
  process(input, previousOutput) {
    const { dataSource: filterDataSource, colors } = input;
    const { radius, innerRadius, center } = previousOutput;
    const renderData = d3Pie().value((d) => d.value)(filterDataSource);
    return {
      data: renderData,
      colors,
      outerRadius: radius,
      donutRadius: innerRadius,
      center,
    };
  }
}
