diff --git a/component/charts/bar-graph/bar-graph.tsx b/component/charts/bar-graph/bar-graph.tsx index 22b4d01..6dff88d 100644 --- a/component/charts/bar-graph/bar-graph.tsx +++ b/component/charts/bar-graph/bar-graph.tsx @@ -10,6 +10,7 @@ import { CustomBars } from '../custom-bars'; import { CustomGrid } from '../custom-grid'; import { graphStyles } from '../chart-styles'; import ChartView from '../chart-view'; +import ChartLabel from '../chart-label/chart-label'; interface Props { data: GraphData; @@ -55,10 +56,13 @@ export const BarGraph: React.FC = ({ data, useCommonScale = false, testID // eslint-disable-next-line react-hooks/rules-of-hooks } = useGraphData(data, props); - + // TODO: Will come from BE & destructured / color assigned in useGraphData + const yLabels = [{ displayName: 'Shots Taken', axis: 'LEFT' as 'LEFT', color: barColors[0] }, { displayName:'Make Percentage', axis: 'RIGHT' as 'RIGHT', color: barColors[1] }] + const title = 'Shots Taken / Make Percentage by Cut Angle' return ( + ; +}; + +const renderLabels = (yLabels: Array) => { + return yLabels.map((label) => ( + + + + {label.displayName} + + + )); +}; + +export default function ChartLabel({ title, yLabels }: ChartLabelProps) { + + return ( + + + {title} + + {renderLabels(yLabels)} + + ); +} \ No newline at end of file diff --git a/component/charts/chart-styles.ts b/component/charts/chart-styles.ts index 7840848..726d0c1 100644 --- a/component/charts/chart-styles.ts +++ b/component/charts/chart-styles.ts @@ -21,3 +21,25 @@ export const graphStyles = StyleSheet.create({ xAxisFontStyle: { fontSize: 12, fill: 'black' }, xAxisMarginTop: { marginTop: -15 } }); + +export const chartLabel = StyleSheet.create({ + titleRow: { + flexDirection: 'row', + marginHorizontal: 10 + }, + titleText: { fontWeight: '500' }, + labelOuterRow: { + flexDirection: 'row', + flexWrap: 'wrap', + marginHorizontal: 10 + }, + labelInnerRow: { flexDirection: 'row', alignItems: 'center', marginTop: 5 }, + labelColorBox: { + height: 15, + width: 15, + borderRadius: 4, + marginRight: 2 + }, + labelTextMargin: { marginRight: 15 }, + labelText: { fontSize: 12 } +}); diff --git a/test/component/chart-label.test.tsx b/test/component/chart-label.test.tsx new file mode 100644 index 0000000..10749c1 --- /dev/null +++ b/test/component/chart-label.test.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import { render } from '@testing-library/react-native'; +import "@testing-library/jest-native/extend-expect"; + +import ChartLabel from '../../component/charts/chart-label/chart-label'; + +describe('ChartLabel Component Tests', () => { + const mockData = { + yLabels: [ + { displayName: 'Shots Taken', axis: 'LEFT' as 'LEFT', color: '#598EBB' }, + { displayName:'Make Percentage', axis: 'RIGHT' as 'RIGHT', color: '#F2D4BC'} + ], + title: 'Shots Taken / Make Percentage by Cut Angle' + }; + + it('should render the correct labels given yLabels', () => { + const { getByText } = render( + + ); + + mockData.yLabels.forEach(label => { + expect(getByText(label.displayName)).toBeTruthy(); + }); + }); + + it('should render the correct number of label boxes', () => { + const { getAllByText } = render( + + ); + + // Assuming displayName is unique and used only for labels + const labelElements = mockData.yLabels.map(label => + getAllByText(label.displayName) + ).flat(); + + expect(labelElements.length).toBe(mockData.yLabels.length); + }); +});