export const getHtmlLegendPlugin = (legendList) => ({
  id: 'htmlLegend',
  afterUpdate(chart) {
    // Remove old legend items
    legendList.innerHTML = '';
    legendList.style.setProperty('--legend-padding', `${chart.scales.x.left}px`);
    // Reuse the built-in legendItems generator
    const legendItems = chart.options.plugins.legend.labels.generateLabels(chart);
    legendItems.forEach(it => {
      const li = document.createElement('li');
      li.onclick = () => {
        const { type } = chart.config['_config'];
        if (type === 'pie' || type === 'doughnut') {
          // Pie and doughnut charts only have a single dataset and visibility is per item
          chart.toggleDataVisibility(it.index);
        }
        else {
          chart.setDatasetVisibility(it.datasetIndex, !chart.isDatasetVisible(it.datasetIndex));
        }
        chart.update();
      };
      // Color box
      const boxSpan = document.createElement('span');
      boxSpan.style.setProperty('--item-box-fill', it.fillStyle);
      boxSpan.style.setProperty('--item-box-stroke', it.strokeStyle);
      // Text
      const text = document.createTextNode(it.text);
      const textContainer = document.createElement('p');
      textContainer.style.setProperty('--item-text-color', it.fontColor);
      textContainer.style.setProperty('--item-text-decoration', it.hidden ? 'line-through' : 'none');
      textContainer.appendChild(text);
      li.appendChild(boxSpan);
      li.appendChild(textContainer);
      legendList.appendChild(li);
    });
  }
});
export const getBaseConfig = (type, datasets, labels, tooltips) => ({
  type,
  data: {
    datasets,
    labels
  },
  options: {
    maintainAspectRatio: false,
    plugins: {
      legend: {
        display: false,
      },
      tooltip: {
        enabled: tooltips,
      },
    },
    responsive: true,
  },
});
const DEFAULT_COLORS = [
  'rgba(209, 26, 111, 1)',
  'rgba(130, 18, 196, 1)',
  'rgba(153, 207, 247, 1)',
  'rgba(0, 134, 234, 1)',
  'rgba(238, 40, 42, 1)',
  'rgba(22, 47, 180, 1)',
  'rgba(78, 79, 95, 1)',
  'rgba(253, 165, 141, 1)',
];
export function getBackgroundColor(i) {
  const defaultColor = DEFAULT_COLORS[i % DEFAULT_COLORS.length];
  return i >= DEFAULT_COLORS.length ?
    defaultColor.replace('1)', '0.5)') :
    defaultColor;
}
export function getMockData(faker) {
  const datasetsQty = faker.datatype.number(5);
  const datapointsQty = faker.datatype.number(50);
  const datapointLabels = [];
  const datasets = [];
  for (let i = 0; i < datasetsQty; i++) {
    datasets.push(getMockDataset(faker, datapointsQty));
  }
  for (let j = 0; j < datapointsQty; j++) {
    datapointLabels.push(faker.random.words());
  }
  return {
    datapointLabels,
    datasets
  };
}
export function getMockDataset(faker, datapointsQty) {
  const label = faker.random.words();
  const data = [];
  for (let i = 0; i < datapointsQty; i++) {
    data.push(faker.datatype.number(1000));
  }
  return { label, data };
}
//# sourceMappingURL=chartHelpers.js.map
