Skip to content

feat: adaptive_compact_number displayer with range-aware precision #602

@paddymul

Description

@paddymul

Summary

Add an adaptive_compact_number displayer that automatically picks the right compact precision based on the column's value range, so that values close together (e.g. 5.68B vs 5.60B) remain distinguishable.

Problem

The compact_number displayer (#597/PR #601) uses a fixed maximumFractionDigits: 1, which works well when values span a wide range (2.3B vs 30B → 2.3B / 30B). But when all values in a column are clustered (e.g. 5,682,123,830 to 5,600,123,123), they'd all display as 5.7B — losing the meaningful differences.

Expected behavior

For the narrow-range example above: 5.68B / 5.60B — keep the compact suffix (B) but increase decimal places until values are distinguishable.

Design

New displayer type: adaptive_compact_number

export interface AdaptiveCompactNumberDisplayerA {
    displayer: "adaptive_compact_number";
    // Optional override — if omitted, Python auto-computes from column stats
    fraction_digits?: number;
}

Separate from compact_number so the simple fixed-precision version remains available.

Python-side range analysis

Compute the required precision in the Python styling pipeline using existing summary stats (min, max, range). Pass a fraction_digits hint in displayer_args to JS.

Algorithm sketch:

  1. Determine the magnitude bucket (K/M/B/T) from the column max
  2. Divide column range by the magnitude divisor (e.g. range / 1e9 for B)
  3. Pick fraction_digits = minimum digits such that range_in_bucket * 10^digits >= 1 (i.e. at least 1 unit of difference in the last displayed digit)
  4. Clamp to a reasonable max (e.g. 4)

Auto by default, overridable

  • If fraction_digits is omitted, Python computes it from column stats
  • User can explicitly set fraction_digits to override the auto behavior

Tooltip

Same as compact_number — full precision value shown on hover.

Files to modify

  • buckaroo/dataflow/styling_core.py — new TypedDict + union member
  • packages/buckaroo-js-core/src/components/DFViewerParts/DFWhole.ts — new interface + union
  • packages/buckaroo-js-core/src/components/DFViewerParts/Displayer.ts — new formatter that reads fraction_digits
  • packages/buckaroo-js-core/src/components/DFViewerParts/gridUtils.ts — tooltip wiring (same pattern as compact_number)
  • Python analysis class to compute fraction_digits from summary stats
  • Tests

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions