Skip to content

Commit

Permalink
feat: [WCG-7] Implement colors for lines in the growth chart (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
edvinstava authored Feb 19, 2024
1 parent cf96689 commit 03123d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import i18n from '@dhis2/d2-i18n'
import { Line } from 'react-chartjs-2';
import 'chart.js/auto';
import { ChartDataTypes } from '../../../types/chartDataTypes';
import { chartLineColorPicker } from '../../../utils/chartLineColorPicker';


export const GrowthChartBuilder = ({ dataSetValues, dataSetMetadata, xLabelValues, keysDataSet }: ChartDataTypes) => {
Expand All @@ -11,7 +12,7 @@ export const GrowthChartBuilder = ({ dataSetValues, dataSetMetadata, xLabelValue
datasets: keysDataSet.map(key => ({
data: dataSetValues.map(entry => entry[key]),
borderWidth: 0.9,
borderColor: 'black',
borderColor: chartLineColorPicker(key),
})),
};

Expand Down
20 changes: 20 additions & 0 deletions src/utils/chartLineColorPicker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const chartLineColorPicker = (key: string): string => {
switch (key) {
case 'SD3neg':
return 'black';
case 'SD2neg':
return 'red';
case 'SD1neg':
return 'orange';
case 'SD0':
return 'green';
case 'SD1':
return 'orange';
case 'SD2':
return 'red';
case 'SD3':
return 'black';
default:
return 'gray';
}
};

0 comments on commit 03123d0

Please sign in to comment.