StyleCode - Number Pipeline
This pipeline controls the pretty-printing of numbers. The main behaviour is determined by the numbers
property.
auto
: collects all numbers within the same scope (a table column, a linechart series or axis, etc.) and picks a scale and precision. This is currently the default behaviour, unless overridden by the unit.simple
: numbers are displayed as floating-point values with a certain number of trailing digits.thousands
,millions
andpercent
: likefixed
, but values are divided by 1000, 1000000 and 100 respectively, and use ak
,m
or%
suffix, respectively.scientific
: numbers are displayed in scientific formatX.FeY
whereY
is chosen so thatX
has exactly one digit.minutes
andseconds
use the separate “time value” pipeline
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 the numbers on a given axis of a
plot
orlinechart
tile. - All the numbers on a given
series
. - All the numbers in a given
value
of atable
.
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:
[unit-left]
is the value ofunit
, but only ifunitPosition
isleft
.[integer]
is the integer portion ofNumber / Scale
.[decimal-sep]
is the value offractionSeparator
. It only appears if the number of significant digitsD
is non-zero.[fraction]
is the fractional portion ofNumber / Scale
, rounded to the number of significant digitsD
.[suffix]
is the suffix determined along with the scale.[unit-right]
is the value ofunit
, but only ifunitPosition
isright
.
Digits in [integer]
and [fraction]
are combined in groups of three and separated by thousandSeparator
.
Examples
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:
- For
minutes
, the value is interpreted as a number of minutes, rounded to the nearest integer, and displayed with ahh:mm
format (d.hh:mm
if it represented more than 24 hours). - For
seconds
, the value is interpreted as a number of seconds and displayed with amm:ss.f
format (hh:mm:ss.f
if it represented more than 60 minutes,d.hh:mm:ss.f
if it represented more than 24 hours). The fractional portion is only included if necessary.
If provided, the unit is displayed according to unit
and unitPosition
rules.