From c21af6d1f553952bedf0b0f5225b11dbab0c49a2 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 19 Aug 2020 10:45:33 -0400 Subject: [PATCH] improve monthly period label positioning --- src/constants/numerical.js | 2 ++ src/plots/cartesian/axes.js | 11 +++++++++-- test/jasmine/tests/axes_test.js | 16 ++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/constants/numerical.js b/src/constants/numerical.js index 8d535a9c2d9..17111ce1a6d 100644 --- a/src/constants/numerical.js +++ b/src/constants/numerical.js @@ -33,7 +33,9 @@ module.exports = { */ ONEAVGYEAR: 31557600000, // 365.25 days ONEAVGQUARTER: 7889400000, // 1/4 of ONEAVGYEAR + ONEMAXMONTH: 2678400000, // 31 * ONEDAY ONEAVGMONTH: 2629800000, // 1/12 of ONEAVGYEAR + ONEMINMONTH: 2419200000, // 28 * ONEDAY ONEWEEK: 604800000, // 7 * ONEDAY ONEDAY: 86400000, ONEHOUR: 3600000, diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 929831f8e16..26e73e7b0cf 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -25,7 +25,9 @@ var cleanTicks = require('./clean_ticks'); var constants = require('../../constants/numerical'); var ONEAVGYEAR = constants.ONEAVGYEAR; var ONEAVGQUARTER = constants.ONEAVGQUARTER; +var ONEMAXMONTH = constants.ONEMAXMONTH; var ONEAVGMONTH = constants.ONEAVGMONTH; +var ONEMINMONTH = constants.ONEMINMONTH; var ONEWEEK = constants.ONEWEEK; var ONEDAY = constants.ONEDAY; var ONEHOUR = constants.ONEHOUR; @@ -780,8 +782,13 @@ axes.calcTicks = function calcTicks(ax, opts) { v += ONEAVGYEAR / 2; } else if(delta >= ONEAVGQUARTER) { v += ONEAVGQUARTER / 2; - } else if(delta >= ONEDAY * 28) { // Months could have days less than ONEAVGMONTH period - v += ONEAVGMONTH / 2; + } else if(delta >= ONEMINMONTH) { // Months could have days less than ONEAVGMONTH period + var actualDelta = Math.abs(B - A); + if(actualDelta >= ONEMINMONTH && actualDelta <= ONEMAXMONTH) { + v += actualDelta / 2; + } else { + v += ONEAVGMONTH / 2; + } } else if(delta >= ONEWEEK) { v += ONEWEEK / 2; } else if(delta >= ONEDAY) { diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 918a8e96f84..1f9e9ca9781 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -5297,14 +5297,14 @@ describe('Test axes', function() { }) .then(function() { _assert('', [ - '2019-12-16 05:15', - '2020-01-16 05:15', - '2020-02-16 05:15', - '2020-03-16 05:15', - '2020-04-16 05:15', - '2020-05-16 05:15', - '2020-06-16 05:15', - '2020-07-16 05:15' + '2019-12-16 12:00', + '2020-01-16 12:00', + '2020-02-15 12:00', + '2020-03-16 12:00', + '2020-04-16', + '2020-05-16 12:00', + '2020-06-16', + '2020-07-16' ], [ ['', '1-January', '1-February', '1-March', '2-April', '2-May', '2-June', ''], ['', '1-Jan', '1-Feb', '1-Mar', '2-Apr', '2-May', '2-Jun', ''],