import React from 'react'; import * as scale from 'd3-scale'; import { View } from 'react-native'; import { BarChart, XAxis, YAxis } from 'react-native-svg-charts'; import { useGraphData } from '../../../hooks/charts/useGraphData'; import ChartView from '../ChartView'; import { GraphData, YAxisProps } from '../graph-types'; import { CustomBars } from '../custom-bars'; import { CustomGrid } from '../custom-grid'; import { graphStyles } from '../../../styles'; interface Props { data: GraphData; height?: number; spacingInner?: number; spacingOuter?: number; contentInset?: { top: number; bottom: number }; min?: number; numberOfTicks?: number; barColors?: Array; useCommonScale?: boolean; yAxisProps?: YAxisProps; } export const BarGraph: React.FC = ({ data, useCommonScale = false, ...props }) => { if (!data || typeof data !== 'object') return null; // TODO: replace when we have error/loading context from useQueryHandler const { xValues, yData, yAxisRightLabels, yAxisLeftLabels, defaultProps: { height, spacingInner, spacingOuter, contentInset, min, numberOfTicks, barColors, yAxisProps: { maxLeftYAxisValue, maxRightYAxisValue, formatRightYAxisLabel, formatLeftYAxisLabel } } } = useGraphData(data, props, useCommonScale); return ( (item as unknown as { value: number }).value} contentInset={contentInset} spacingInner={spacingInner} spacingOuter={spacingOuter} > index)} formatLabel={(_, index) => xValues[index]} style={graphStyles.xAxisMarginTop} svg={graphStyles.xAxisFontStyle} scale={scale.scaleBand} /> ); }; export default BarGraph;