Skip to content

#921 Guard against divide-by-zero in visualizationUtils.calculateTren… - #1129

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Kappa16:#921-Guard-against-divide-by-zero-in-visualizationUtils.calculateTrend-FIX
Aug 1, 2026
Merged

#921 Guard against divide-by-zero in visualizationUtils.calculateTren…#1129
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Kappa16:#921-Guard-against-divide-by-zero-in-visualizationUtils.calculateTrend-FIX

Conversation

@Kappa16

@Kappa16 Kappa16 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

CLOSE #921

Title: Guard against divide-by-zero in visualizationUtils.calculateTrend FIXED

Description

Fixes a division-by-zero in calculateTrend (src/utils/visualizationUtils.ts) where change = ((last - first) / first) * 100 produced Infinity/-Infinity/NaN when the first data point is 0 (common for new metrics), and absurd percentages (e.g. ~5e14%) for near-zero baselines. Dashboards consuming useDataVisualization().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 conventional 100% 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 --noEmit exit 0 ✓ · ESLint 0 errors ✓ · Prettier clean ✓ · full pnpm run build green (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 by first === 0 yields Infinity/NaN and nonsensical trend in dashboards (zero/near-zero guard required before dividing).

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • Code follows project style guidelines (ESLint 0 errors, Prettier --check clean on both touched files)
  • Self-review completed (diff reviewed: minimal +18/+44, original formula untouched for non-zero baselines)
  • No console errors (no console statements added; build + type-check + tests all clean)
  • Uses Lucide icons consistently (N/A — no UI/icon changes)
  • Responsive design implemented (N/A — no UI changes; logic-only utility fix)
  • Starknet best practices followed (N/A — no Web3/Starknet code paths touched)

@drips-wave

drips-wave Bot commented Jul 31, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 1094c35 into rinafcode:main Aug 1, 2026
6 checks passed
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.

Guard against divide-by-zero in visualizationUtils.calculateTrend

2 participants