Skip to content

Commit 7fb8266

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

File tree

8 files changed

+25
-6
lines changed

8 files changed

+25
-6
lines changed

package-lock.json

Lines changed: 13 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
@@ -71,6 +71,7 @@
7171
"d3-force": "^1.2.1",
7272
"d3-hierarchy": "^1.1.9",
7373
"d3-interpolate": "^1.4.0",
74+
"d3-time-format": "^2.2.3",
7475
"delaunay-triangulate": "^1.1.6",
7576
"es6-promise": "^4.2.8",
7677
"fast-isnumeric": "^1.1.4",

src/lib/dates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;
2525

2626
var Registry = require('../registry');
2727

28-
var utcFormat = d3.time.format.utc;
28+
var utcFormat = require('d3-time-format').utcFormat;
2929

3030
var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
3131
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months

src/lib/index.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 utcFormat = require('d3-time-format').utcFormat;
1213
var isNumeric = require('fast-isnumeric');
1314

1415
var numConstants = require('../constants/numerical');
@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
10821083
}
10831084

10841085
if(format[0] === '|') {
1085-
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
1086+
fmt = d3locale ? d3locale.utcFormat : utcFormat;
10861087
var ms = lib.dateTime2ms(value);
10871088
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
10881089
}

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 utcFormat = require('d3-time-format').utcFormat;
1213
var isNumeric = require('fast-isnumeric');
1314

1415
var Lib = require('../../lib');
@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
954955
// Fall back on default format for dummy axes that don't care about formatting
955956
var locale = fullLayout._d3locale;
956957
if(ax.type === 'date') {
957-
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
958+
ax._dateFormat = locale ? locale.utcFormat : utcFormat;
958959
ax._extraFormat = fullLayout._extraFormat;
959960
}
960961
// occasionally we need _numFormat to pass through

src/plots/plots.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 timeFormatLocale = require('d3-time-format').timeFormatLocale;
1213
var isNumeric = require('fast-isnumeric');
1314

1415
var Registry = require('../registry');
@@ -723,7 +724,7 @@ function getFormatter(formatObj, separators) {
723724
formatObj.decimal = separators.charAt(0);
724725
formatObj.thousands = separators.charAt(1);
725726

726-
return d3.locale(formatObj);
727+
return timeFormatLocale(formatObj);
727728
}
728729

729730
function fillMetaTextHelpers(newFullData, newFullLayout) {

test/jasmine/tests/axes_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Plotly = require('@lib/index');
22
var d3 = require('d3');
3+
var utcFormat = require('d3-time-format').utcFormat;
34

45
var Plots = require('@src/plots/plots');
56
var Lib = require('@src/lib');
@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
52065207
}
52075208

52085209
function getFormatter(format) {
5209-
return d3.time.format.utc(format);
5210+
return utcFormat(format);
52105211
}
52115212

52125213
describe('Test Axes.getTickformat', function() {

test/jasmine/tests/localize_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var _ = Lib._;
33
var Registry = require('@src/registry');
44

55
var d3 = require('d3');
6+
var utcFormat = require('d3-time-format').utcFormat;
67

78
var Plotly = require('@lib');
89
var createGraphDiv = require('../assets/create_graph_div');
@@ -236,7 +237,7 @@ describe('localization', function() {
236237
expect(firstYLabel()).toBe('0~5');
237238
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
238239
// sanity check that d0 is what we think...
239-
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
240+
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
240241
// full names were not overridden, so fall back on english
241242
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
242243
})

0 commit comments

Comments
 (0)