fix(web): guard usePoolChartData against division by zero with single snapshot - #715
Open
Ennyblack wants to merge 1 commit into
Open
fix(web): guard usePoolChartData against division by zero with single snapshot#715Ennyblack wants to merge 1 commit into
Ennyblack wants to merge 1 commit into
Conversation
… snapshot When data.length is 1, the expression index / (data.length - 1) produces NaN. Add an early return that places the single data point at the center of the chart and produces valid SVG paths. Add 7 unit tests covering empty data, undefined data, single-point, two-point, multi-point, and equal-value cases. Closes TrusTrove#278 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Contributor
|
@Cjay-Cyber-2 is attempting to deploy a commit to the K1NGD4VID Team on Vercel. A member of the Team first needs to authorize it. |
|
MergeKeeper review unavailable AI provider review response did not contain valid JSON No approval or merge action was taken. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix division by zero in
usePoolChartDatawhen only one snapshot exists.When
data.length === 1, the expressionindex / (data.length - 1)divides by zero, producing NaN coordinates. This PR adds an early return that places the single data point at the horizontal center of the chart, producing valid SVG paths and a meaningful visual.Changes
apps/web/hooks/usePoolChartData.ts: Added early return fordata.length === 1that centers the single point and generates validlinePath/areaPathstrings.apps/web/hooks/usePoolChartData.test.ts: New test file with 7 tests covering empty data, undefined data, single-point, two-point, multi-point, centering, and equal-value cases.Verification
pnpm --filter web exec tsc --noEmit— cleanpnpm --filter web lint— clean (only pre-existing warnings)pnpm --filter web test— all tests passCloses #278
🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com