Skip to content

Commit

Permalink
AreaChart: Respect baseValue of AreaChart, but allow override from Ar…
Browse files Browse the repository at this point in the history
…ea (#3140)

Fix a bug, introduced in #3013,
which neglects to respect the AreaChart baseValue and thereby breaks
existing charts.

## Related Issue
#3051

## How Has This Been Tested?
I tested the change locally by running the demo project, verifying that
the baseValue of the AreaChart is effective by itself, and that
overriding it per Area component is possible.

## Screenshots (if appropriate):
<img width="1319" alt="Screenshot 2023-01-04 at 15 20 14"
src="https://user-images.githubusercontent.com/27995606/210575218-491c0a7e-1e80-4d98-b06b-2bf706a5694c.png">
<img width="1319" alt="Screenshot 2023-01-04 at 15 20 04"
src="https://user-images.githubusercontent.com/27995606/210575226-6e029126-a7c1-4685-b196-2a9333af91d2.png">
<img width="1319" alt="Screenshot 2023-01-04 at 15 19 53"
src="https://user-images.githubusercontent.com/27995606/210575230-5836c24a-bb0a-4b32-a491-3f2af1edaf41.png">

## 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! -->

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
Nikolas Rieble committed Jan 4, 2023
1 parent 2e8dffd commit c07f762
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cartesian/Area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ export class Area extends PureComponent<Props, State> {
};

static getBaseValue = (props: Props, item: Area, xAxis: Props['xAxis'], yAxis: Props['yAxis']): number => {
const { layout } = props;
const { baseValue } = item.props;
const { layout, baseValue: chartBaseValue } = props;
const { baseValue: itemBaseValue } = item.props;

// The baseValue can be defined both on the AreaChart as well as on the Area.
// The value for the item takes precedence.
const baseValue = itemBaseValue ?? chartBaseValue;

if (isNumber(baseValue) && typeof baseValue === 'number') {
return baseValue;
Expand Down

0 comments on commit c07f762

Please sign in to comment.