diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index 0a2c86f4f6f..7dc1a272114 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -92,6 +92,13 @@ module.exports = function setConvert(ax, fullLayout) { * - defaults to ax.calendar */ function dt2ms(v, _, calendar, opts) { + if((opts || {}).msUTC && isNumeric(v)) { + // For now it is only used + // to fix bar length in milliseconds & gl3d ticks + // It could be applied in other places in v2 + return +v; + } + // NOTE: Changed this behavior: previously we took any numeric value // to be a ms, even if it was a string that could be a bare year. // Now we convert it as a date if at all possible, and only try @@ -100,13 +107,6 @@ module.exports = function setConvert(ax, fullLayout) { if(ms === BADNUM) { if(isNumeric(v)) { v = +v; - if((opts || {}).msUTC) { - // For now it is only used - // to fix bar length in milliseconds. - // It could be applied in other places in v2 - return v; - } - // keep track of tenths of ms, that `new Date` will drop // same logic as in Lib.ms2DateTime var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10); diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index 3ef5568c3c2..5b162e897af 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -423,6 +423,31 @@ describe('Bar.calc', function() { var cd = gd.calcdata; assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]); }); + + it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (vertical case)', function() { + var gd = mockBarPlot([{ + type: 'bar', + base: [0], + y: [2000], + x: ['A'] + }], {yaxis: {type: 'date'}}); + + var cd = gd.calcdata; + assertPointField(cd, 's', [[2000]]); + }); + + it('should translate sizes e.g. 2000 to milliseconds not to year when base is present (horizontal case)', function() { + var gd = mockBarPlot([{ + type: 'bar', + orientation: 'h', + base: [0], + x: [2000], + y: ['A'] + }], {xaxis: {type: 'date'}}); + + var cd = gd.calcdata; + assertPointField(cd, 's', [[2000]]); + }); }); describe('Bar.crossTraceCalc (formerly known as setPositions)', function() {