From 2b26e5a14af6d85b44f56742518392f2d8fd5674 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 Aug 2020 17:08:14 -0400 Subject: [PATCH 1/3] convert numeric dates to ms for bars with base --- src/plots/cartesian/set_convert.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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); From a4c8095929d3b251fb69f03f0f82e6f08b954525 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 Aug 2020 17:37:04 -0400 Subject: [PATCH 2/3] add jasmine tests --- test/jasmine/tests/bar_test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index 3ef5568c3c2..592d13a364e 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -423,6 +423,33 @@ 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'] + }], {}); + + var cd = gd.calcdata; + assertPointField(cd, 'b', [[0]]); + 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'] + }], {}); + + var cd = gd.calcdata; + assertPointField(cd, 'b', [[0]]); + assertPointField(cd, 's', [[2000]]); + }); }); describe('Bar.crossTraceCalc (formerly known as setPositions)', function() { From 3e439e01428fb1a3d56aa45b7a51ed50a8dc6557 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 10 Aug 2020 21:50:02 -0400 Subject: [PATCH 3/3] add date axis types - fixup test to catch issue 5057 --- test/jasmine/tests/bar_test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index 592d13a364e..5b162e897af 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -430,10 +430,9 @@ describe('Bar.calc', function() { base: [0], y: [2000], x: ['A'] - }], {}); + }], {yaxis: {type: 'date'}}); var cd = gd.calcdata; - assertPointField(cd, 'b', [[0]]); assertPointField(cd, 's', [[2000]]); }); @@ -444,10 +443,9 @@ describe('Bar.calc', function() { base: [0], x: [2000], y: ['A'] - }], {}); + }], {xaxis: {type: 'date'}}); var cd = gd.calcdata; - assertPointField(cd, 'b', [[0]]); assertPointField(cd, 's', [[2000]]); }); });