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

Function generateLabels

src/plugins/plugin.legend.js:675–709  ·  view source on GitHub ↗
(chart)

Source from the content-addressed store, hash-verified

673 // lineJoin :
674 // lineWidth :
675 generateLabels(chart) {
676 const datasets = chart.data.datasets;
677 const {labels: {usePointStyle, pointStyle, textAlign, color, useBorderRadius, borderRadius}} = chart.legend.options;
678
679 return chart._getSortedDatasetMetas().map((meta) => {
680 const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
681 const borderWidth = toPadding(style.borderWidth);
682 const itemPointStyle = pointStyle || style.pointStyle;
683 // a line symbol stands for the dataset line but the point scope has no dash
684 // on it so read that off the dataset element instead, markers stay solid
685 const dashStyle = usePointStyle && itemPointStyle === 'line'
686 ? meta.controller.getStyle(undefined)
687 : style;
688
689 return {
690 text: datasets[meta.index].label,
691 fillStyle: style.backgroundColor,
692 fontColor: color,
693 hidden: !meta.visible,
694 lineCap: style.borderCapStyle,
695 lineDash: dashStyle.borderDash,
696 lineDashOffset: dashStyle.borderDashOffset,
697 lineJoin: style.borderJoinStyle,
698 lineWidth: (borderWidth.width + borderWidth.height) / 4,
699 strokeStyle: style.borderColor,
700 pointStyle: itemPointStyle,
701 rotation: style.rotation,
702 textAlign: textAlign || style.textAlign,
703 borderRadius: useBorderRadius && (borderRadius || style.borderRadius),
704
705 // Below is extra data used for toggling the datasets
706 datasetIndex: meta.index
707 };
708 }, this);
709 }
710 },
711
712 title: {

Callers

nothing calls this directly

Calls 3

toPaddingFunction · 0.85
getStyleMethod · 0.80

Tested by

no test coverage detected