From 82e086c88c99320a9792bd9605489341e3421f8d Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Tue, 22 Oct 2024 09:23:10 -0400 Subject: [PATCH] feat: add thousands format for numbers (#2261) - Closes #2253 --- .../src/format-context-menus/DecimalFormatContextMenu.ts | 4 ++++ .../src/format-context-menus/IntegerFormatContextMenu.ts | 4 ++++ .../jsapi-utils/src/formatters/DecimalColumnFormatter.ts | 6 ++++++ .../jsapi-utils/src/formatters/IntegerColumnFormatter.ts | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/packages/iris-grid/src/format-context-menus/DecimalFormatContextMenu.ts b/packages/iris-grid/src/format-context-menus/DecimalFormatContextMenu.ts index de525b8e9b..de48c7da4d 100644 --- a/packages/iris-grid/src/format-context-menus/DecimalFormatContextMenu.ts +++ b/packages/iris-grid/src/format-context-menus/DecimalFormatContextMenu.ts @@ -37,6 +37,10 @@ class DecimalFormatContextMenu { format: DecimalColumnFormatter.FORMAT_BASIS_POINTS, group: DecimalFormatContextMenu.presetGroup, }, + { + format: DecimalColumnFormatter.FORMAT_THOUSANDS, + group: DecimalFormatContextMenu.presetGroup, + }, { format: DecimalColumnFormatter.FORMAT_MILLIONS, group: DecimalFormatContextMenu.presetGroup, diff --git a/packages/iris-grid/src/format-context-menus/IntegerFormatContextMenu.ts b/packages/iris-grid/src/format-context-menus/IntegerFormatContextMenu.ts index 31889be50b..e87e71ee97 100644 --- a/packages/iris-grid/src/format-context-menus/IntegerFormatContextMenu.ts +++ b/packages/iris-grid/src/format-context-menus/IntegerFormatContextMenu.ts @@ -27,6 +27,10 @@ class IntegerFormatContextMenu { onCustomFormatChange: (value: IntegerColumnFormat | null) => void ): FormatContextMenuOption[] { const formatItems = [ + { + format: IntegerColumnFormatter.FORMAT_THOUSANDS, + group: IntegerFormatContextMenu.presetGroup, + }, { format: IntegerColumnFormatter.FORMAT_MILLIONS, group: IntegerFormatContextMenu.presetGroup, diff --git a/packages/jsapi-utils/src/formatters/DecimalColumnFormatter.ts b/packages/jsapi-utils/src/formatters/DecimalColumnFormatter.ts index de09a154d2..3e30567717 100644 --- a/packages/jsapi-utils/src/formatters/DecimalColumnFormatter.ts +++ b/packages/jsapi-utils/src/formatters/DecimalColumnFormatter.ts @@ -111,6 +111,12 @@ export class DecimalColumnFormatter extends TableColumnFormatter { 10000 ); + static FORMAT_THOUSANDS = DecimalColumnFormatter.makePresetFormat( + 'Thousands', + '##0.000 k', + 0.001 + ); + static FORMAT_MILLIONS = DecimalColumnFormatter.makePresetFormat( 'Millions', '###,##0.000 mm', diff --git a/packages/jsapi-utils/src/formatters/IntegerColumnFormatter.ts b/packages/jsapi-utils/src/formatters/IntegerColumnFormatter.ts index 73cad020e7..b1122a60ad 100644 --- a/packages/jsapi-utils/src/formatters/IntegerColumnFormatter.ts +++ b/packages/jsapi-utils/src/formatters/IntegerColumnFormatter.ts @@ -121,6 +121,12 @@ export class IntegerColumnFormatter extends TableColumnFormatter { static DEFAULT_FORMAT_STRING = '###,##0'; + static FORMAT_THOUSANDS = IntegerColumnFormatter.makePresetFormat( + 'Thousands', + '##0.000 k', + 0.001 + ); + static FORMAT_MILLIONS = IntegerColumnFormatter.makePresetFormat( 'Millions', '###,##0.000 mm',