From 7a0243e6d74ff7dd8f366879a35d9351ac0620a7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 17 Jan 2019 10:08:15 -0700 Subject: [PATCH] Use store currency settings to initialize D3 format. --- .../packages/components/src/chart/index.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/packages/components/src/chart/index.js b/plugins/woocommerce-admin/packages/components/src/chart/index.js index d53a4f178db..00927fd45df 100644 --- a/plugins/woocommerce-admin/packages/components/src/chart/index.js +++ b/plugins/woocommerce-admin/packages/components/src/chart/index.js @@ -5,7 +5,6 @@ import { __, sprintf } from '@wordpress/i18n'; import classNames from 'classnames'; import { Component, createRef, Fragment } from '@wordpress/element'; -import { decodeEntities } from '@wordpress/html-entities'; import { formatDefaultLocale as d3FormatDefaultLocale } from 'd3-format'; import { get, isEqual, partial } from 'lodash'; import Gridicon from 'gridicons'; @@ -26,11 +25,28 @@ import ChartPlaceholder from './placeholder'; import { H, Section } from '../section'; import { D3Chart, D3Legend } from './d3chart'; +function getD3CurrencyFormat( symbol, position ) { + switch ( position ) { + case 'left_space': + return [ symbol + ' ', '' ]; + case 'right': + return [ '', symbol ]; + case 'right_space': + return [ '', ' ' + symbol ]; + case 'left': + default: + return [ symbol, '' ]; + } +} + +const currencySymbol = get( wcSettings, [ 'currency', 'symbol' ], '' ); +const symbolPosition = get( wcSettings, [ 'currency', 'position' ], 'left' ); + d3FormatDefaultLocale( { - decimal: '.', - thousands: ',', + decimal: get( wcSettings, [ 'currency', 'decimal_separator' ], '.' ), + thousands: get( wcSettings, [ 'currency', 'thousand_separator' ], ',' ), grouping: [ 3 ], - currency: [ decodeEntities( get( wcSettings, 'currency.symbol', '' ) ), '' ], + currency: getD3CurrencyFormat( currencySymbol, symbolPosition ), } ); function getOrderedKeys( props, previousOrderedKeys = [] ) {