#921 Guard against divide-by-zero in visualizationUtils.calculateTren… - #1129
Merged
Conversation
…ulateTrend FIXED
|
@Kappa16 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Thank you for contributing to the project. |
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.
CLOSE #921
Title:
Guard against divide-by-zero in visualizationUtils.calculateTrend FIXEDDescription
Fixes a division-by-zero in
calculateTrend(src/utils/visualizationUtils.ts) wherechange = ((last - first) / first) * 100producedInfinity/-Infinity/NaNwhen the first data point is0(common for new metrics), and absurd percentages (e.g.~5e14%) for near-zero baselines. Dashboards consuminguseDataVisualization().calculateStats()rendered nonsensical trends as a result.Changes (2 files, +62/-0):
src/utils/visualizationUtils.ts— added a zero/near-zero guard (Number.EPSILON) before the division: both endpoints ≈ 0 →{ neutral, 0 }; zero baseline with movement → direction of movement with a finite conventional100%fallback. All other inputs use the unchanged original formula (no breaking changes).src/utils/__tests__/visualizationUtils.test.ts— 5 new regression tests (zero-baseline up/down, 0→0 NaN case, near-zero baseline, both-endpoints-near-zero).Validation: module tests 31/31 ✓ ·
tsc --noEmitexit 0 ✓ · ESLint 0 errors ✓ · Prettier clean ✓ · fullpnpm run buildgreen (compile ✓, 71/71 static pages ✓) ✓ · full workspace suite run with zero regressions attributable to this change (pre-existing failures in unrelated files A/B-verified against pristine HEAD) ✓.Related Issue
src/utils/visualizationUtils.ts calculateTrend(lines 236–238) — division byfirst === 0yields Infinity/NaN and nonsensical trend in dashboards (zero/near-zero guard required before dividing).Type of Change
Checklist
--checkclean on both touched files)