MCPcopy Create free account
hub / github.com/Rello/analytics / customGenerateLabels

Function customGenerateLabels

js/visualization.js:1790–1822  ·  view source on GitHub ↗
(chart)

Source from the content-addressed store, hash-verified

1788
1789 const defaultGenerateLabels = Chart.defaults.plugins.legend.labels.generateLabels;
1790 const customGenerateLabels = function (chart) {
1791 let labels;
1792
1793 // Chart.js does not generate category labels for doughnuts when only
1794 // a single dataset without label is present. Build them manually.
1795 if (chart.config.type === 'doughnut') {
1796 const data = chart.data;
1797 const dataset = data.datasets[0] || {};
1798 const colors = dataset.backgroundColor || [];
1799 labels = data.labels.map((label, index) => ({
1800 text: label,
1801 fillStyle: colors[index],
1802 strokeStyle: colors[index],
1803 hidden: !chart.getDataVisibility(index),
1804 datasetIndex: 0,
1805 index: index
1806 }));
1807 } else {
1808 labels = OCA.Analytics.Visualization.getGroupedChartLegend(chart) || defaultGenerateLabels(chart);
1809 }
1810
1811 const showAllNeeded = labels.length > 4 && labels.some(label => label.hidden);
1812 if (showAllNeeded) {
1813 labels.push({
1814 text: t('analytics', 'Show all'),
1815 fillStyle: 'transparent',
1816 strokeStyle: 'transparent',
1817 hidden: false,
1818 datasetIndex: -1
1819 });
1820 }
1821 return labels;
1822 };
1823
1824 this.showElement('tableSeparatorContainer');
1825 this.showElement('chartContainer');

Callers

nothing calls this directly

Calls 3

mapMethod · 0.80
getDataVisibilityMethod · 0.80
tFunction · 0.50

Tested by

no test coverage detected