Skip to content

Commit c3e3f54

Browse files
committed
apply latest d3-format in plotly.js
1 parent 7fb8266 commit c3e3f54

File tree

9 files changed

+25
-13
lines changed

9 files changed

+25
-13
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"country-regex": "^1.1.0",
7070
"d3": "^3.5.17",
7171
"d3-force": "^1.2.1",
72+
"d3-format": "^1.4.4",
7273
"d3-hierarchy": "^1.1.9",
7374
"d3-interpolate": "^1.4.0",
7475
"d3-time-format": "^2.2.3",

src/components/drawing/index.js

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

1212
var d3 = require('d3');
13+
var numberFormat = require('d3-format').format;
1314
var isNumeric = require('fast-isnumeric');
1415
var tinycolor = require('tinycolor2');
1516

@@ -275,7 +276,7 @@ function makePointPath(symbolNumber, r) {
275276

276277
var HORZGRADIENT = {x1: 1, x2: 0, y1: 0, y2: 0};
277278
var VERTGRADIENT = {x1: 0, x2: 0, y1: 1, y2: 0};
278-
var stopFormatter = d3.format('~.1f');
279+
var stopFormatter = numberFormat('~f');
279280
var gradientInfo = {
280281
radial: {node: 'radialGradient'},
281282
radialreversed: {node: 'radialGradient', reversed: true},

src/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
'use strict';
1010

11-
var d3 = require('d3');
11+
var numberFormat = require('d3-format').format;
1212
var utcFormat = require('d3-time-format').utcFormat;
1313
var isNumeric = require('fast-isnumeric');
1414

@@ -1078,7 +1078,7 @@ function templateFormatString(string, labels, d3locale) {
10781078
if(format) {
10791079
var fmt;
10801080
if(format[0] === ':') {
1081-
fmt = d3locale ? d3locale.numberFormat : d3.format;
1081+
fmt = numberFormat;
10821082
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
10831083
}
10841084

src/plots/cartesian/dragbox.js

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

1111
var d3 = require('d3');
12+
var numberFormat = require('d3-format').format;
1213
var tinycolor = require('tinycolor2');
1314
var supportsPassive = require('has-passive-events');
1415

@@ -983,11 +984,11 @@ function getEndText(ax, end) {
983984
return initialVal;
984985
} else if(ax.type === 'log') {
985986
dig = Math.ceil(Math.max(0, -Math.log(diff) / Math.LN10)) + 3;
986-
return d3.format('.' + dig + 'g')(Math.pow(10, initialVal));
987+
return numberFormat('.' + dig + 'g')(Math.pow(10, initialVal));
987988
} else { // linear numeric (or category... but just show numbers here)
988989
dig = Math.floor(Math.log(Math.abs(initialVal)) / Math.LN10) -
989990
Math.floor(Math.log(diff) / Math.LN10) + 4;
990-
return d3.format('.' + String(dig) + 'g')(initialVal);
991+
return numberFormat('.' + String(dig) + 'g')(initialVal);
991992
}
992993
}
993994

src/plots/cartesian/set_convert.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var d3 = require('d3');
12+
var numberFormat = require('d3-format').format;
1213
var utcFormat = require('d3-time-format').utcFormat;
1314
var isNumeric = require('fast-isnumeric');
1415

@@ -961,7 +962,7 @@ module.exports = function setConvert(ax, fullLayout) {
961962
// occasionally we need _numFormat to pass through
962963
// even though it won't be needed by this axis
963964
ax._separators = fullLayout.separators;
964-
ax._numFormat = locale ? locale.numberFormat : d3.format;
965+
ax._numFormat = numberFormat;
965966

966967
// and for bar charts and box plots: reset forced minimum tick spacing
967968
delete ax._minDtick;

src/traces/parcoords/parcoords.js

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

1111
var d3 = require('d3');
12+
var numberFormat = require('d3-format').format;
1213
var rgba = require('color-rgba');
1314

1415
var Axes = require('../../plots/cartesian/axes');
@@ -85,7 +86,7 @@ function domainScale(height, padding, dimension, tickvals, ticktext) {
8586
var extent = dimensionExtent(dimension);
8687
if(tickvals) {
8788
return d3.scale.ordinal()
88-
.domain(tickvals.map(toText(d3.format(dimension.tickformat), ticktext)))
89+
.domain(tickvals.map(toText(numberFormat(dimension.tickformat), ticktext)))
8990
.range(tickvals
9091
.map(function(d) {
9192
var unitVal = (d - extent[0]) / (extent[1] - extent[0]);
@@ -272,7 +273,7 @@ function viewModel(state, callbacks, model) {
272273

273274
// ensure ticktext and tickvals have same length
274275
if(!Array.isArray(ticktext) || !ticktext.length) {
275-
ticktext = tickvals.map(d3.format(dimension.tickformat));
276+
ticktext = tickvals.map(numberFormat(dimension.tickformat));
276277
} else if(ticktext.length > tickvals.length) {
277278
ticktext = ticktext.slice(0, tickvals.length);
278279
} else if(tickvals.length > ticktext.length) {

src/traces/sankey/plot.js

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

1111
var d3 = require('d3');
12+
var numberFormat = require('d3-format').format;
1213
var render = require('./render');
1314
var Fx = require('../../components/fx');
1415
var Color = require('../../components/color');
@@ -200,7 +201,7 @@ module.exports = function plot(gd, calcData) {
200201
link.fullData = link.trace;
201202
obj = d.link.trace.link;
202203
var hoverCenter = hoverCenterPosition(link);
203-
var hovertemplateLabels = {valueLabel: d3.format(d.valueFormat)(link.value) + d.valueSuffix};
204+
var hovertemplateLabels = {valueLabel: numberFormat(d.valueFormat)(link.value) + d.valueSuffix};
204205

205206
hoverItems.push({
206207
x: hoverCenter[0],
@@ -210,7 +211,7 @@ module.exports = function plot(gd, calcData) {
210211
link.label || '',
211212
sourceLabel + link.source.label,
212213
targetLabel + link.target.label,
213-
link.concentrationscale ? concentrationLabel + d3.format('%0.2f')(link.flow.labelConcentration) : ''
214+
link.concentrationscale ? concentrationLabel + numberFormat('%0.2f')(link.flow.labelConcentration) : ''
214215
].filter(renderableValuePresent).join('<br>'),
215216
color: castHoverOption(obj, 'bgcolor') || Color.addOpacity(link.color, 1),
216217
borderColor: castHoverOption(obj, 'bordercolor'),
@@ -289,14 +290,14 @@ module.exports = function plot(gd, calcData) {
289290
var hoverCenterX1 = boundingBox.right + 2 - rootBBox.left;
290291
var hoverCenterY = boundingBox.top + boundingBox.height / 4 - rootBBox.top;
291292

292-
var hovertemplateLabels = {valueLabel: d3.format(d.valueFormat)(d.node.value) + d.valueSuffix};
293+
var hovertemplateLabels = {valueLabel: numberFormat(d.valueFormat)(d.node.value) + d.valueSuffix};
293294
d.node.fullData = d.node.trace;
294295

295296
var tooltip = Fx.loneHover({
296297
x0: hoverCenterX0,
297298
x1: hoverCenterX1,
298299
y: hoverCenterY,
299-
name: d3.format(d.valueFormat)(d.node.value) + d.valueSuffix,
300+
name: numberFormat(d.valueFormat)(d.node.value) + d.valueSuffix,
300301
text: [
301302
d.node.label,
302303
incomingLabel + d.node.targetLinks.length,

src/traces/table/plot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
var c = require('./constants');
1212
var d3 = require('d3');
13+
var numberFormat = require('d3-format').format;
1314
var gup = require('../../lib/gup');
1415
var Drawing = require('../../components/drawing');
1516
var svgUtil = require('../../lib/svg_text_utils');
@@ -534,7 +535,7 @@ function populateCellText(cellText, tableControlView, allColumnBlock, gd) {
534535
var suffix = latex ? '' : gridPick(d.calcdata.cells.suffix, col, row) || '';
535536
var format = latex ? null : gridPick(d.calcdata.cells.format, col, row) || null;
536537

537-
var prefixSuffixedText = prefix + (format ? d3.format(format)(d.value) : d.value) + suffix;
538+
var prefixSuffixedText = prefix + (format ? numberFormat(format)(d.value) : d.value) + suffix;
538539

539540
var hasWrapSplitCharacter;
540541
d.wrappingNeeded = !d.wrapped && !userBrokenText && !latex && (hasWrapSplitCharacter = hasWrapCharacter(prefixSuffixedText));

0 commit comments

Comments
 (0)