Skip to content

Commit

Permalink
Merge pull request #112 from ScottLogic/sfd-147-label-percentage
Browse files Browse the repository at this point in the history
SFD-147 Show percentage as well as category title
  • Loading branch information
mgriffin-scottlogic authored Jul 19, 2024
2 parents 7d53e8a + 28269a0 commit 7700a67
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app/carbon-estimation/carbon-estimation.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ const getCustomTooltip = (isPlaceholder: boolean) => {
return customTooltip;
};

const getCustomDataLabel = (isPlaceholder: boolean) => {
const customDataLabel = (value: string | number | number[], {
seriesIndex,
dataPointIndex,
w,
}: {
seriesIndex: number;
dataPointIndex: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
w: any;
}) => {
const initialSeries = w.globals.initialSeries[seriesIndex];
const data = initialSeries.data[dataPointIndex];

return `${value} - ${isPlaceholder ? '?' : tooltipFormatter(data.y)}`
}
return customDataLabel;
}

export const getBaseChartOptions = (isPlaceholder: boolean) => {
const chartOptions: ChartOptions = {
legend: {
Expand Down Expand Up @@ -94,6 +113,7 @@ export const getBaseChartOptions = (isPlaceholder: boolean) => {
},
},
dataLabels: {
formatter: getCustomDataLabel(isPlaceholder),
style: {
fontSize: '16px',
fontFamily: 'ui-sans-serif, system-ui, sans-serif',
Expand Down

0 comments on commit 7700a67

Please sign in to comment.