@opendata-ai/openchart-core 6.15.1 → 6.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-core",
3
- "version": "6.15.1",
3
+ "version": "6.16.0",
4
4
  "description": "Types, theme, colors, accessibility, and utilities for openchart",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Riley Hilliard",
@@ -110,6 +110,13 @@ describe('buildD3Formatter', () => {
110
110
  expect(fmt!(7000)).toBe('$7k');
111
111
  expect(fmt!(14000)).toBe('$14k');
112
112
  });
113
+
114
+ it('$~s replaces SI "G" with "B" for billions', () => {
115
+ const fmt = buildD3Formatter('$~s');
116
+ expect(fmt).not.toBeNull();
117
+ expect(fmt!(1_500_000_000)).toBe('$1.5B');
118
+ expect(fmt!(2_000_000_000)).toBe('$2B');
119
+ });
113
120
  });
114
121
 
115
122
  describe('formatDate', () => {
@@ -95,7 +95,12 @@ export function buildD3Formatter(formatStr: string | undefined): ((v: number) =>
95
95
  if (!formatStr) return null;
96
96
 
97
97
  try {
98
- return d3Format(formatStr);
98
+ const fmt = d3Format(formatStr);
99
+ // Replace SI prefix "G" (giga) with "B" (billion) for financial readability
100
+ if (formatStr.includes('s')) {
101
+ return (v: number) => fmt(v).replace(/G$/, 'B');
102
+ }
103
+ return fmt;
99
104
  } catch {
100
105
  // If d3-format rejects it, try stripping a trailing literal suffix
101
106
  const m = formatStr.match(D3_FORMAT_SUFFIX_RE);