StyleCode - Number Pipeline

This pipeline controls the pretty-printing of numbers. The main behaviour is determined by the numbers property.

Selecting the scale and suffix

The common point between auto, simple, thousands, millions, percent and scientific is that they choose a scale and a suffix according to this table:

Mode Scale Suffix
simple 1
thousands 1000 k
millions 1000000 m
percent 0.01 %
scientific The power of ten P = 10^N such that P <= x < 10 P 1eN
auto Complex, see below.

When numbers is auto, an algorithm examines a set of numbers and determines a scale among 10^9, 10^6, 10^3, 1, 10^-3, 10^-6 and 10^-9 (and associated prefixes b, m, k, ``, 10⁻³, 10⁻⁶ and 10⁻⁹), and a precision, by trying to get the most visually appealing reasult when this scale, prefix and precision are applied to all numbers in the set.

The details of this optimization are implementation-defined (outside the scope of this specification) but the general idea is that the algorithm attempts to minimize noise digits (displaying 1 as 1.00 creates two digits of noise) as well as lost digits (displaying 1.23 as 1 loses two digits of data).

Each number on an Envision dashboard belongs to exactly one set of numbers, which will be considered together for the purpose of this optimization. These sets are:

All other numbers are considered alone.

Selecting the precision

The number will be displayed in format "X.Y", and the precision determines the number of digits in Y (a value between 0 and 16). This is a form of rounding, so 10.996 displayed with a precision of 2 becomes "11.00".

If numbers is auto, this precision has already been selected in the previous step.

The algorithm computes the number of significant digits D by looking for a sequence 000 or 999 in the decimal expansion of the number. For example:

Number D Ideal rendering
10 0 "10"
10.001 3 "10.001"
10.0001 0 "10"
10.399 3 "10.399"
10.3999 1 "10.4"

This number of significant digits D is then clamped between minPrecision and precision according to the following formula:

D = max(minPrecision, min(precision, D))

In other words: D should be between minPrecision and precision, and minPrecision wins.

Rendering the number

The rendering format is [unit-left][integer][decimal-sep][fraction][suffix][unit-right], where:

Digits in [integer] and [fraction] are combined in groups of three and separated by thousandSeparator.


Number numbers unit unitPosition precision minPrecision fractionSeparator thousandSeparator Result
1 auto " USD" auto auto 0 "." " " "1 USD"
0.249 percent "" auto auto 0 "." " " "24.9%"
0.249 scientific " m" auto auto 0 "," " " "2,49e-1 m"
1999 thousands "$" auto auto 0 "." " " "$2k"
1999 simple "$" right auto 2 "." "," "1,999.00$

Time Value pipeline

When the numbers property is minutes and seconds, a distinct pipeline is used that ignores all the other properties (except units). The rules are:

If provided, the unit is displayed according to unit and unitPosition rules.

User Contributed Notes
0 notes + add a note