-
Notifications
You must be signed in to change notification settings - Fork 16
Description
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:
- Determine the magnitude bucket (K/M/B/T) from the column max
- Divide column range by the magnitude divisor (e.g. range / 1e9 for B)
- Pick
fraction_digits= minimum digits such thatrange_in_bucket * 10^digits >= 1(i.e. at least 1 unit of difference in the last displayed digit) - Clamp to a reasonable max (e.g. 4)
Auto by default, overridable
- If
fraction_digitsis omitted, Python computes it from column stats - User can explicitly set
fraction_digitsto 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 memberpackages/buckaroo-js-core/src/components/DFViewerParts/DFWhole.ts— new interface + unionpackages/buckaroo-js-core/src/components/DFViewerParts/Displayer.ts— new formatter that readsfraction_digitspackages/buckaroo-js-core/src/components/DFViewerParts/gridUtils.ts— tooltip wiring (same pattern ascompact_number)- Python analysis class to compute
fraction_digitsfrom summary stats - Tests
Related
- Add opt-in compact numeric formatter (3M, 5.7B) with full-value tooltip #597 / PR feat: add opt-in compact_number displayer (#597) #601 —
compact_number(fixed precision, merged) - bad default styling #595 — bad default styling (compact abbreviations requested)
- Follow-up: column width contention policy and toggleable style presets #596 — width contention policy