Skip to content

Commit 1faaf8b

Browse files
committed
use existing fullLayout._d3locale instead of package d3-format
1 parent 1575739 commit 1faaf8b

File tree

6 files changed

+11
-27
lines changed

6 files changed

+11
-27
lines changed

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"country-regex": "^1.1.0",
6767
"d3": "^3.5.12",
6868
"d3-force": "^1.0.6",
69-
"d3-format": "^1.3.2",
7069
"d3-interpolate": "1",
7170
"d3-sankey-circular": "0.32.0",
7271
"delaunay-triangulate": "^1.1.6",

src/components/fx/hover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,15 +971,15 @@ function createHoverText(hoverData, opts, gd) {
971971
}
972972

973973
// hovertemplate
974-
var locale = gd._fullLayout._format;
974+
var d3locale = gd._fullLayout._d3locale;
975975
var hovertemplate = d.hovertemplate || false;
976976
var hovertemplateLabels = d.hovertemplateLabels || d;
977977
var eventData = d.eventData[0] || {};
978978
if(hovertemplate) {
979979
text = Lib.hovertemplateString(
980980
hovertemplate,
981981
hovertemplateLabels,
982-
locale,
982+
d3locale,
983983
eventData,
984984
{meta: fullLayout.meta}
985985
);

src/lib/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'use strict';
1111

1212
var d3 = require('d3');
13-
var d3format = require('d3-format');
1413
var isNumeric = require('fast-isnumeric');
1514

1615
var numConstants = require('../constants/numerical');
@@ -1036,14 +1035,14 @@ var maximumNumberOfHoverTemplateWarnings = 10;
10361035
* Lib.hovertemplateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
10371036
* Lib.hovertemplateString('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'
10381037
*
1039-
* @param {obj} data object containing the locale
1038+
* @param {obj} d3 locale
10401039
* @param {string} input string containing %{...:...} template strings
10411040
* @param {obj} data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}
10421041
* @param {obj} data objects containing substitution values
10431042
*
10441043
* @return {string} templated string
10451044
*/
1046-
lib.hovertemplateString = function(string, labels, locale) {
1045+
lib.hovertemplateString = function(string, labels, d3locale) {
10471046
var args = arguments;
10481047
// Not all that useful, but cache nestedProperty instantiation
10491048
// just in case it speeds things up *slightly*:
@@ -1078,9 +1077,13 @@ lib.hovertemplateString = function(string, labels, locale) {
10781077
}
10791078

10801079
if(format) {
1081-
var fmt = d3format;
1082-
if(locale) fmt = fmt.formatLocale(locale);
1083-
value = fmt.format(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
1080+
var fmt;
1081+
if(d3locale) {
1082+
fmt = d3locale.numberFormat;
1083+
} else {
1084+
fmt = d3.format;
1085+
}
1086+
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
10841087
} else {
10851088
if(labels.hasOwnProperty(key + 'Label')) value = labels[key + 'Label'];
10861089
}

src/plots/plots.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ plots.supplyDefaults = function(gd, opts) {
372372

373373
newFullLayout._d3locale = getFormatter(formatObj, newFullLayout.separators);
374374
newFullLayout._extraFormat = getFormatObj(gd, extraFormatKeys);
375-
newFullLayout._format = formatObj;
376375

377376
newFullLayout._initialAutoSizeIsDone = true;
378377

test/jasmine/tests/lib_test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,18 +2241,6 @@ describe('Test lib.js:', function() {
22412241
}
22422242
expect(Lib.warn.calls.count()).toBe(10);
22432243
});
2244-
2245-
describe('support different locale as argument', function() {
2246-
var locale = {
2247-
decimal: ',',
2248-
thousands: ' ',
2249-
currency: ['£', ''],
2250-
grouping: [3]
2251-
};
2252-
it('formats value using d3 mini-language', function() {
2253-
expect(Lib.hovertemplateString('a: %{a:$010,.2f}', {}, locale, {a: 1253})).toEqual('a: £001 253,00');
2254-
});
2255-
});
22562244
});
22572245

22582246
describe('relativeAttr()', function() {

0 commit comments

Comments
 (0)