Can't add currency to Superset D3 Fortmatting

Viewed 387

I'm trying to add the Brazilian currency as a Number Format inside charts (12345.432 = > R$12.345,43). I've added the registerValue into setupFormatters and the option in the D3_FORMAT_OPTIONS list inside controls.jsx, but it doesn't appear inside superset. Is there something else that I'm missing?

down below there is the code to show what I've done

inside superset-frontend/src/setup/setupFormatters.ts

.registerValue(
  'CURRENCY_BRAZIL',
  createD3NumberFormatter({
    locale: {
      decimal: ',',
      thousands: '.',
      grouping: [3],
      currency: ['R$', ''],
    },
    formatString: '$,.2f',
  }),
)

inside superset-frontend/src/explore/controls.jsx

export const D3_FORMAT_OPTIONS = [
  ['SMART_NUMBER', 'Adaptative formating'],
  ['~g', 'Original value'],
  [',d', ',d (12345.432 => 12,345)'],
  ['.1s', '.1s (12345.432 => 10k)'],
  ['.3s', '.3s (12345.432 => 12.3k)'],
  [',.1%', ',.1% (12345.432 => 1,234,543.2%)'],
  ['.3%', '.3% (12345.432 => 1234543.200%)'],
  ['.4r', '.4r (12345.432 => 12350)'],
  [',.3f', ',.3f (12345.432 => 12,345.432)'],
  ['+,', '+, (12345.432 => +12,345.432)'],
  ['$,.2f', '$,.2f (12345.432 => $12,345.43)'],
  ['CURRENCY_BRAZIL', 'Brazilian Real Currency (12345.432 => R$12.345,43)'],
  ['DURATION_SUB', 'Duration in ms (100.40008 => 100ms 400µs 80ns)'],
  ['DURATION', 'Duration in ms (66000 => 1m 6s)'],
];

I've also reached out to the apache superset slack, and I received the following answer:

I am currently trying to add european currency (€), and encountered this issue. I seem to have solved it on my dev deployment. I added those same modifications that you mention, but instead of the file “superset-frontend/src/explore/controls.jsx”, I modified “superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts”

but it didn't actually solve my problem, because the file “superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts” does not exist in my project. (we're using the superset version 1.0.0 in the project)

0 Answers
Related