Skip to content

Fix Funnel margin calculation#6453

Merged
ckifer merged 1 commit intomainfrom
funnel-margin
Oct 17, 2025
Merged

Fix Funnel margin calculation#6453
ckifer merged 1 commit intomainfrom
funnel-margin

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Oct 14, 2025

Description

So I went and tried to fix #6427 and in the process I have discovered that, to my horror, Funnel is doing truly atrocious things with margins:

  • it counts left margin twice
  • ignores top margin
  • uses top for X coordinate
  • and uses left for Y coordinate

So I'm fixing these. There will be visual diff, I consider this a bugfix.

Related Issue

#6427

Screenshots (if appropriate):

Before

Funnel is vaguely present within the plot area, but it's not matching it at all:

Screenshot 2025-10-14 at 23 13 53 Screenshot 2025-10-14 at 23 13 59

After

Funnel precisely matches margin and plot area:

Screenshot 2025-10-14 at 23 06 14 Screenshot 2025-10-14 at 23 06 03

Types of changes

  • 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:

  • 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 VR test, or extended an existing story or VR test to show my changes

@PavelVanecek PavelVanecek requested review from ckifer and Copilot and removed request for ckifer October 14, 2025 14:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes margin calculation issues in the Funnel component that were causing incorrect positioning and sizing. The fix addresses issues where the funnel was counting left margin twice, ignoring top margin, and incorrectly using top for X coordinates and left for Y coordinates.

Key changes:

  • Corrected margin calculation logic in getRealWidthHeight function
  • Fixed coordinate calculation to properly use left for X and top for Y positioning
  • Improved documentation for the getPercentValue utility function

Reviewed Changes

Copilot reviewed 6 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/cartesian/Funnel.tsx Fixed margin calculation logic and coordinate positioning
src/util/DataUtils.ts Enhanced documentation for getPercentValue function
storybook/stories/API/chart/FunnelChart.stories.tsx Removed hardcoded width from story example
test/cartesian/Funnel.spec.tsx Updated test expectations for corrected positioning
test/cartesian/Funnel.animation.spec.tsx Updated animation test expectations for corrected positioning
test/component/Tooltip/Tooltip.visibility.spec.tsx Updated tooltip positioning test expectations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +120 to 121
type RealFunnelData = unknown;

Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific type instead of unknown for RealFunnelData. While unknown is safer than any, a proper interface or type would improve type safety and code documentation.

Suggested change
type RealFunnelData = unknown;
interface FunnelDataItem {
value?: number | string;
name?: string;
[key: string]: any; // Allow additional properties if needed
}
type RealFunnelData = FunnelDataItem[];

Copilot uses AI. Check for mistakes.
Comment on lines +335 to 344
const { width, height, left, top } = offset;

const realWidth: number = getPercentValue(customWidth, width, width);

return {
realWidth: realWidth - left - right - 50,
realHeight: realHeight - bottom - top,
offsetX: (width - realWidth) / 2,
offsetY: (height - realHeight) / 2,
realWidth,
realHeight: height,
offsetX: left,
offsetY: top,
};
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The realWidth calculation uses width as both the total value and default value for getPercentValue. Consider making this more explicit by passing a clear default value or adding a comment explaining this choice.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.83%. Comparing base (0da6676) to head (022c898).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6453      +/-   ##
==========================================
- Coverage   93.83%   93.83%   -0.01%     
==========================================
  Files         417      417              
  Lines       38423    38422       -1     
  Branches     4502     4504       +2     
==========================================
- Hits        36053    36052       -1     
  Misses       2353     2353              
  Partials       17       17              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Oct 14, 2025

Bundle Report

Changes will increase total bundle size by 650 bytes (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.08MB 380 bytes (0.04%) ⬆️
recharts/bundle-es6 929.76kB 387 bytes (0.04%) ⬆️
recharts/bundle-umd 497.69kB -117 bytes (-0.02%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js -117 bytes 497.69kB -0.02%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Funnel.js -326 bytes 16.39kB -1.95%
util/DataUtils.js 713 bytes 5.18kB 15.95% ⚠️
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Funnel.js -333 bytes 17.87kB -1.83%
util/DataUtils.js 713 bytes 6.05kB 13.36% ⚠️

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but as mentioned might cause some friction depending on what consumers think. Overall, the before is pretty whack

@ckifer ckifer merged commit de2bf63 into main Oct 17, 2025
26 of 28 checks passed
@ckifer ckifer deleted the funnel-margin branch October 17, 2025 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recharts 3 LabelsList has incorrect position within FunnelChart after upgrade from 2.x

3 participants