Skip to content

Commit

Permalink
fix(BarChart/ColumnChart): fix data labels for nested data accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusNotheis committed Jun 19, 2020
1 parent 12e3278 commit ca653b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/charts/src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
XAxis,
YAxis
} from 'recharts';
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils';
import { useChartMargin } from '../../hooks/useChartMargin';
import { useLongestYAxisLabelBar } from '../../hooks/useLongestYAxisLabelBar';
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
Expand All @@ -40,6 +41,10 @@ const measureDefaults = {
opacity: 1
};

const valueAccessor = (attribute) => ({ payload }) => {
return getValueByDataKey(payload, attribute);
};

interface MeasureConfig extends IChartMeasure {
/**
* Bar Width
Expand Down Expand Up @@ -164,9 +169,6 @@ const BarChart: FC<BarChartProps> = forwardRef((props: BarChartProps, ref: Ref<a
const [width, legendPosition] = useLongestYAxisLabelBar(dataset, dimensions);
const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
const [xAxisHeight] = useObserveXAxisHeights(chartRef, 1);
const valueAccessor = (attribute) => ({ payload }) => {
return payload[attribute];
};

return (
<ChartContainer
Expand Down
8 changes: 5 additions & 3 deletions packages/charts/src/components/ColumnChart/ColumnChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
XAxis,
YAxis
} from 'recharts';
import { getValueByDataKey } from 'recharts/lib/util/ChartUtils';
import { useChartMargin } from '../../hooks/useChartMargin';
import { useLongestYAxisLabel } from '../../hooks/useLongestYAxisLabel';
import { useObserveXAxisHeights } from '../../hooks/useObserveXAxisHeights';
Expand Down Expand Up @@ -88,6 +89,10 @@ const measureDefaults = {
opacity: 1
};

const valueAccessor = (attribute) => ({ payload }) => {
return getValueByDataKey(payload, attribute);
};

/**
* <code>import { ColumnChart } from '@ui5/webcomponents-react-charts/lib/ColumnChart';</code>
*/
Expand Down Expand Up @@ -169,9 +174,6 @@ const ColumnChart: FC<ColumnChartProps> = forwardRef((props: ColumnChartProps, r

const marginChart = useChartMargin(chartConfig.margin, chartConfig.zoomingTool);
const xAxisHeights = useObserveXAxisHeights(chartRef, props.dimensions.length);
const valueAccessor = (attribute) => ({ payload }) => {
return payload[attribute];
};

return (
<ChartContainer
Expand Down

0 comments on commit ca653b6

Please sign in to comment.