Formatting#
Classes for formatting various data types.
Classes for formatting different types of data, including numeric values, date and time values, and text.
AxisNumberFormatting #
AxisNumberFormatting(
*,
scale: NumberScale = DYNAMIC_ABSOLUTE,
decimals: int | None = None,
prefix: TemplatedStringItem | DataField | None = None,
suffix: TemplatedStringItem | DataField | None = None,
)
Numeric axis formatting.
Description for formatting numeric axis, allowing customization of scale, decimal places, prefix, and suffix.
Constructor for AxisNumberFormatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
NumberScale
|
scale used to format number. For example, if NumberScale.THOUSAND, number is divided by 1_000 and a suffix "K" is added. Defaults to NumberScale.DYNAMIC_ABSOLUTE (formats K, M, Bn), but not percentage or basis point values. |
DYNAMIC_ABSOLUTE
|
decimals
|
Optional[int]
|
number of decimal places to show after adjusting for scale. Defaults to 0 if scale is Dynamic Absolute, Millions or Thousands. Defaults to 2 for the remaining scales. |
None
|
prefix
|
Optional[Union[TemplatedStringItem, DataField]]
|
Fixed text (or key/column data) to be added before axis. Defaults to None. |
None
|
suffix
|
Optional[Union[TemplatedStringItem, DataField]]
|
Fixed text (or key/column data) to be added after axis. Defaults to None. |
None
|
DateTimeFormatting #
DateTimeFormatting(
*,
template: str | None = None,
time_unit: DateTimeUnit = DATE,
)
Date and time value formatting.
Description for formatting date and time values, specifying template and time unit.
Constructor for DateTimeFormatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template
|
Optional[str]
|
using spec from https://date-fns.org/v1.30.1/docs/format |
None
|
time_unit
|
DateTimeUnit
|
determines part of timestamp to consider. Defaults to DateTimeUnit.DATE. |
DATE
|
MapperFormatting #
Factory class to map a column with ordinal numbers to text.
Factory class to map ordinal numbers to text labels for categorical data.
Constructor for MapperFormatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mapping
|
Mapping[int, str]
|
mapping between number and text label. |
required |
NumberFormatting #
NumberFormatting(
*,
scale: NumberScale | GenericLink = DYNAMIC_ABSOLUTE,
decimals: int | None = None,
prefix: TemplatedStringItem | DataField | None = None,
suffix: TemplatedStringItem | DataField | None = None,
show_positive_sign: bool = False,
)
Numeric value formatting.
Description for formatting numeric values, providing options for scale, decimal places, prefix, suffix, and displaying positive sign.
Constructor for NumberFormatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
NumberScale | GenericLink
|
scale used to format number if is type NumberScale. For example, if NumberScale.THOUSAND, number is divided by 1_000 and a suffix "K" is added. If is type TemplatedStringItem, this variable allow formatting to be dynamically. Defaults to NumberScale.DYNAMIC_ABSOLUTE (formats K, M, Bn), but not percentage or basis point values. |
DYNAMIC_ABSOLUTE
|
decimals
|
int | None
|
number of decimal places to show after adjusting for scale. Defaults to 0 if scale is Dynamic Absolute, Millions or Thousands. Defaults to 2 for the remaining scales. |
None
|
prefix
|
TemplatedStringItem | DataField | None
|
Fixed text to be added before number. Cannot be defined if prefix_key is used. |
None
|
suffix
|
TemplatedStringItem | DataField | None
|
Fixed text to be added after number. Cannot be defined if suffix_key is used. |
None
|
show_positive_sign
|
bool
|
Flag to activate the plus sign in positive number values. |
False
|
TextFormatting #
Customize maximum characters and splitting options.
Description for formatting text, allowing customization of maximum characters and splitting.
Constructor for TextFormatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_characters
|
int
|
number of characters to show before text is trimmed. If len(text) > max_characters, text is trimmed to max_characters and ... are added and full text shown on hover. Defaults to 30. |
30
|
split
|
Optional[str]
|
split character to determine first word. After split character, ... are added and full text shown on hover. Defaults to None. |
None
|
Enums#
Enums define scales for numbers, units for date/time.
Enumerations for defining scales to format numbers and units for date and time values.
NumberScale #
Scales to format numbers.
Description of different scaling options available for formatting numbers.
Attributes:
Name | Type | Description |
---|---|---|
BASE |
str
|
No scale applied. |
PERCENTAGE |
str
|
Numbers are multiplied by 100 and a suffix % is added. |
BASISPOINT |
str
|
Numbers are multiplied by 10000 and a suffix bps is added. |
PIP |
str
|
Numbers are multiplied by 1000000 and a suffix pip is added. |
THOUSAND |
str
|
Numbers are divided by 1000 and suffix K is added. |
MILLION |
str
|
Numbers are divided by 1e6 and suffix M is added. |
BILLION |
str
|
Numbers are divided by 1e9 and suffix Bn is added. |
DYNAMIC_ABSOLUTE |
str
|
Scale is dynamically detected based on range of values. |
DYNAMIC_RELATIVE |
str
|
Apply BASISPOINT if median < 0.01, PERCENTAGE otherwise. |
DateTimeUnit #
DateTime units.
Available units for datetime formatting.
Attributes:
Name | Type | Description |
---|---|---|
DATE |
str
|
Date unit. |
TIME |
str
|
Time unit. |
DATETIME |
str
|
DateTime unit. |
Types#
FormattingType
module-attribute
#
FormattingType = (
DateTimeFormatting
| MapperFormatting
| NumberFormatting
| TextFormatting
)