MCPcopy Create free account
hub / github.com/chartjs/Chart.js / generateLabels

Function generateLabels

src/plugins/plugin.legend.ts:866–900  ·  view source on GitHub ↗
(chart)

Source from the content-addressed store, hash-verified

864 // lineJoin :
865 // lineWidth :
866 generateLabels(chart) {
867 const datasets = chart.data.datasets;
868 const {labels: {usePointStyle, pointStyle, textAlign, color, useBorderRadius, borderRadius}} = chart.legend.options;
869
870 return chart._getSortedDatasetMetas().map((meta) => {
871 const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
872 const borderWidth = toPadding(style.borderWidth);
873 const itemPointStyle = pointStyle || style.pointStyle;
874 // a line symbol stands for the dataset line but the point scope has no dash
875 // on it so read that off the dataset element instead, markers stay solid
876 const dashStyle = usePointStyle && itemPointStyle === 'line'
877 ? meta.controller.getStyle(undefined)
878 : style;
879
880 return {
881 text: datasets[meta.index].label,
882 fillStyle: style.backgroundColor,
883 fontColor: color,
884 hidden: !meta.visible,
885 lineCap: style.borderCapStyle,
886 lineDash: dashStyle.borderDash,
887 lineDashOffset: dashStyle.borderDashOffset,
888 lineJoin: style.borderJoinStyle,
889 lineWidth: (borderWidth.width + borderWidth.height) / 4,
890 strokeStyle: style.borderColor,
891 pointStyle: itemPointStyle,
892 rotation: style.rotation,
893 textAlign: textAlign || style.textAlign,
894 borderRadius: useBorderRadius && (borderRadius || style.borderRadius),
895
896 // Below is extra data used for toggling the datasets
897 datasetIndex: meta.index
898 };
899 }, this);
900 }
901 },
902
903 title: {

Callers

nothing calls this directly

Calls 3

toPaddingFunction · 0.85
getStyleMethod · 0.80

Tested by

no test coverage detected