Skip to content

DRY: consolidate compact number formatting #80

@lowhung

Description

@lowhung

Summary

Extract compact numeric formatting (k/M suffix logic) into a shared formatting utility and reuse for rates/counts.

Why

format_rate and format_count each implement similar scale-threshold logic. Consolidating avoids divergence and improves formatting consistency.

Affected files

  • src/ui/drawing.rs
  • src/ui/panels.rs
  • (new) src/ui/format.rs

Extraction plan

  • Add shared utility in src/ui/format.rs (e.g. format_scaled).
  • Refactor format_rate to delegate while preserving 0 => "" behavior.
  • Refactor format_count to delegate while preserving integer-like output for small values.
  • Add tests for thresholds, rounding, and zero behavior.

Risk

Medium. String output changes can affect tests/UX expectations and may require deliberate compatibility decisions.

Acceptance criteria

  • Shared formatting utility exists and is reused by rate/count formatters.
  • Existing expected output behavior is preserved or intentionally updated with tests.
  • Tests pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions