Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion superset-frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = {
],
coverageReporters: ['lcov', 'json-summary', 'html', 'text'],
transformIgnorePatterns: [
'node_modules/(?!d3-(array|interpolate|color|time|scale|time-format)|internmap|@mapbox/tiny-sdf|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|unist-.*|hast-.*|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|react-error-boundary|react-json-tree|react-base16-styling|lodash-es)',
'node_modules/(?!d3-(array|interpolate|color|time|scale|time-format|format)|internmap|@mapbox/tiny-sdf|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|unist-.*|hast-.*|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|react-error-boundary|react-json-tree|react-base16-styling|lodash-es)',
],
preset: 'ts-jest',
transform: {
Expand Down
11 changes: 10 additions & 1 deletion superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"classnames": "^2.5.1",
"csstype": "^3.2.3",
"core-js": "^3.48.0",
"d3-format": "^1.3.2",
"d3-format": "^3.1.2",
"dayjs": "^1.11.19",
"d3-interpolate": "^3.0.1",
"d3-scale": "^4.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export const DEFAULT_D3_FORMAT: FormatLocaleDefinition = {
thousands: ',',
grouping: [3],
currency: ['$', ''],
minus: '-', // Use ASCII hyphen for backward compatibility (d3-format v3 defaults to Unicode minus sign)
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
format as d3Format,
formatLocale,
FormatLocaleDefinition,
} from 'd3-format';
import { formatLocale, FormatLocaleDefinition } from 'd3-format';
import { isRequired } from '../../utils';
import NumberFormatter from '../NumberFormatter';
import { NumberFormatFunction } from '../types';
import { DEFAULT_D3_FORMAT } from '../D3FormatConfig';

export default function createD3NumberFormatter(config: {
description?: string;
Expand All @@ -42,10 +39,7 @@ export default function createD3NumberFormatter(config: {
let isInvalid = false;

try {
formatFunc =
typeof locale === 'undefined'
? d3Format(formatString)
: formatLocale(locale).format(formatString);
formatFunc = formatLocale(locale ?? DEFAULT_D3_FORMAT).format(formatString);
} catch (error) {
formatFunc = value => `${value} (Invalid format: ${formatString})`;
isInvalid = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/

import { format as d3Format } from 'd3-format';
import { formatLocale } from 'd3-format';
import NumberFormatter from '../NumberFormatter';
import { DEFAULT_D3_FORMAT } from '../D3FormatConfig';

export default function createSiAtMostNDigitFormatter(
config: {
Expand All @@ -29,7 +30,8 @@ export default function createSiAtMostNDigitFormatter(
} = {},
) {
const { description, n = 3, id, label } = config;
const siFormatter = d3Format(`.${n}s`);
const locale = formatLocale(DEFAULT_D3_FORMAT);
const siFormatter = locale.format(`.${n}s`);

return new NumberFormatter({
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { format as d3Format } from 'd3-format';
import { formatLocale } from 'd3-format';
import NumberFormatter from '../NumberFormatter';
import NumberFormats from '../NumberFormats';
import { DEFAULT_D3_FORMAT } from '../D3FormatConfig';

const siFormatter = d3Format(`.3~s`);
const float2PointFormatter = d3Format(`.2~f`);
const float4PointFormatter = d3Format(`.4~f`);
const locale = formatLocale(DEFAULT_D3_FORMAT);
const siFormatter = locale.format(`.3~s`);
const float2PointFormatter = locale.format(`.2~f`);
const float4PointFormatter = locale.format(`.4~f`);

function formatValue(value: number) {
if (value === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,18 @@ describe('createD3NumberFormatter(config)', () => {
expect(formatter(200)).toEqual('€200.00');
});
});
describe('negative numbers', () => {
it('uses ASCII hyphen-minus (U+002D) for negative numbers, not Unicode minus (U+2212)', () => {
const formatter = createD3NumberFormatter({ formatString: ',d' });
const result = formatter(-1234);
// Verify the result contains ASCII hyphen-minus (char code 45), not Unicode minus (char code 8722)
// This is important for backward compatibility after d3-format v3 upgrade
expect(result).toEqual('-1,234');
expect(result.charCodeAt(0)).toEqual(45); // ASCII hyphen-minus
});
it('formats negative decimals correctly', () => {
const formatter = createD3NumberFormatter({ formatString: ',.2f' });
expect(formatter(-1234.5)).toEqual('-1,234.50');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('createSiAtMostNDigitFormatter({ n })', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 4 });
expect(formatter).toBeInstanceOf(NumberFormatter);
});
it('uses ASCII hyphen-minus (U+002D) for negative numbers, not Unicode minus (U+2212)', () => {
// This is important for backward compatibility after d3-format v3 upgrade
const formatter = createSiAtMostNDigitFormatter({ n: 3 });
const result = formatter(-1000);
expect(result.charCodeAt(0)).toBe(45); // ASCII hyphen-minus
});
it('when n is specified, it formats number in SI format with at most n significant digits', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 2 });
expect(formatter(10)).toBe('10');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe('createSmartNumberFormatter(options)', () => {
});
});
describe('for negative numbers', () => {
it('uses ASCII hyphen-minus (U+002D), not Unicode minus (U+2212)', () => {
// This is important for backward compatibility after d3-format v3 upgrade
const result = formatter(-1000);
expect(result.charCodeAt(0)).toBe(45); // ASCII hyphen-minus
});
it('formats billion with B in stead of G', () => {
expect(formatter(-1000000000)).toBe('-1B');
expect(formatter(-4560000000)).toBe('-4.56B');
Expand Down
Loading