Skip to content

Commit

Permalink
Fix: Modify to ensure data is not sliced if the active index is outsi…
Browse files Browse the repository at this point in the history
…de the dataIndex range. (#4718)

<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue

#4717 
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] I have added a storybook story or extended an existing story to
show my changes
  • Loading branch information
HHongSeungWoo authored Jul 4, 2024
1 parent 0fe105e commit e6834ed
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/chart/generateCategoricalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ const getTooltipContent = (
*/
let data = child.props.data ?? chartData;

if (data && state.dataStartIndex + state.dataEndIndex !== 0) {
if (
data &&
state.dataStartIndex + state.dataEndIndex !== 0 &&
// https://github.com/recharts/recharts/issues/4717
// The data is sliced only when the active index is within the start/end index range.
state.dataEndIndex - state.dataStartIndex >= activeIndex
) {
data = data.slice(state.dataStartIndex, state.dataEndIndex + 1);
}

Expand Down Expand Up @@ -681,6 +687,7 @@ export const createDefaultState = (props: CategoricalChartProps): CategoricalCha
const brushItem = findChildByType(children, Brush);
let startIndex = 0;
let endIndex = 0;

if (props.data && props.data.length !== 0) {
endIndex = props.data.length - 1;
}
Expand Down

0 comments on commit e6834ed

Please sign in to comment.