mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { Chart } from 'chart.js';
|
|
|
|
export const legendOptions = {
|
|
position: 'bottom',
|
|
labels: {
|
|
boxWidth: 12,
|
|
padding: 30,
|
|
generateLabels: (chart: Chart) => {
|
|
const datasets = chart.data.datasets;
|
|
const {
|
|
labels: { usePointStyle, pointStyle, textAlign, color },
|
|
} = chart?.legend?.options || {
|
|
labels: {},
|
|
};
|
|
return (chart as any)._getSortedDatasetMetas().map((meta: any) => {
|
|
const style = meta.controller.getStyle(
|
|
usePointStyle ? 0 : undefined,
|
|
);
|
|
return {
|
|
text: datasets[meta.index].label,
|
|
fillStyle: style.backgroundColor,
|
|
fontColor: color,
|
|
hidden: !meta.visible,
|
|
lineWidth: 0,
|
|
borderRadius: 6,
|
|
strokeStyle: style.borderColor,
|
|
pointStyle: pointStyle || style.pointStyle,
|
|
textAlign: textAlign || style.textAlign,
|
|
datasetIndex: meta.index,
|
|
};
|
|
});
|
|
},
|
|
},
|
|
} as const;
|