Skip to content

Commit c080bc5

Browse files
committed
adjust period labels depending on break size
1 parent f47c820 commit c080bc5

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/plots/cartesian/axes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,14 @@ axes.calcTicks = function calcTicks(ax, opts) {
838838
var r = c / nAll;
839839
if(ax.maskBreaks(A * (1 - r) + B * r) === BADNUM) nOut++;
840840
}
841-
periodLength *= 1 - nOut / nAll;
841+
var ratio = 1 - nOut / nAll;
842+
if(ratio > 0.5) {
843+
// case of short gap
844+
periodLength *= ratio;
845+
} else {
846+
// case of big gap
847+
periodLength = ratio * actualDelta;
848+
}
842849
}
843850

844851
if(periodLength <= actualDelta) { // i.e. to ensure new label positions remain between ticks

test/jasmine/tests/axes_test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,37 +5867,37 @@ describe('Test axes', function() {
58675867
[
58685868
{
58695869
range: ['2020-12-14 08:00', '2022-12-14 08:00'],
5870-
positions: ['2020-12-06 10:26:47.1429', '2021-03-07 09:50:21.4286', '2021-06-06 16:26:47.1429', '2021-09-06 16:26:47.1429', '2021-12-07 09:50:21.4286', '2022-03-06 16:26:47.1429', '2022-06-06 16:26:47.1429', '2022-09-07 01:08:34.2857', '2022-12-07 01:08:34.2857'],
5871-
labels: ['', 'Mar 2021', 'Jun 2021', 'Sep 2021', 'Dec 2021', 'Mar 2022', 'Jun 2022', 'Sep 2022', 'Dec 2022']
5870+
positions: ['2020-12-17 02:47:08.5714', '2021-03-19 20:51:25.7143', '2021-06-17 16:17:08.5714', '2021-09-17 12:00', '2021-12-19 11:08:34.2857', '2022-03-17 16:17:08.5714', '2022-06-17 16:17:08.5714', '2022-09-18 14:00', '2022-12-18 14:00'],
5871+
labels: ['Dec 2020', 'Mar 2021', 'Jun 2021', 'Sep 2021', 'Dec 2021', 'Mar 2022', 'Jun 2022', 'Sep 2022', '']
58725872
},
58735873
{
58745874
range: ['2020-12-14 08:00', '2021-08-14 08:00'],
5875-
positions: ['2020-12-06 04:17:08.5714', '2020-12-27 22:00', '2021-01-24 22:00', '2021-02-21 22:00', '2021-03-21 22:00', '2021-04-18 22:00', '2021-05-16 22:00', '2021-06-13 22:00', '2021-07-11 22:00', '2021-08-08 22:00'],
5875+
positions: ['2020-12-08 17:21:25.7143', '2020-12-27 22:00', '2021-01-24 22:00', '2021-02-21 22:00', '2021-03-21 22:00', '2021-04-18 22:00', '2021-05-16 22:00', '2021-06-13 22:00', '2021-07-11 22:00', '2021-08-08 22:00'],
58765876
labels: ['', 'Dec 21<br>2020', 'Jan 18<br>2021', 'Feb 15', 'Mar 15', 'Apr 12', 'May 10', 'Jun 7', 'Jul 5', 'Aug 2']
58775877
},
58785878
{
58795879
range: ['2020-12-14 08:00', '2021-04-14 08:00'],
5880-
positions: ['2020-12-13 03:42:51.4286', '2020-12-21 11:42:51.4286', '2021-01-04 11:42:51.4286', '2021-01-18 11:42:51.4286', '2021-02-01 11:42:51.4286', '2021-02-15 11:42:51.4286', '2021-03-01 11:42:51.4286', '2021-03-15 11:42:51.4286', '2021-03-29 11:42:51.4286', '2021-04-12 11:42:51.4286'],
5881-
labels: ['', 'Dec 21<br>2020', 'Jan 4<br>2021', 'Jan 18', 'Feb 1', 'Feb 15', 'Mar 1', 'Mar 15', 'Mar 29', 'Apr 12']
5880+
positions: ['2020-12-14 06:38:34.2857', '2020-12-24 14:00', '2021-01-07 14:00', '2021-01-21 14:00', '2021-02-04 14:00', '2021-02-18 14:00', '2021-03-04 14:00', '2021-03-18 14:00', '2021-04-01 14:00', '2021-04-15 14:00'],
5881+
labels: ['', 'Dec 21<br>2020', 'Jan 4<br>2021', 'Jan 18', 'Feb 1', 'Feb 15', 'Mar 1', 'Mar 15', 'Mar 29', '']
58825882
},
58835883
{
58845884
range: ['2020-12-14 08:00', '2021-02-14 08:00'],
5885-
positions: ['2020-12-13 03:42:51.4286', '2020-12-21 10:17:08.5714', '2020-12-28 10:17:08.5714', '2021-01-04 10:17:08.5714', '2021-01-11 10:17:08.5714', '2021-01-18 10:17:08.5714', '2021-01-25 10:17:08.5714', '2021-02-01 10:17:08.5714', '2021-02-08 11:42:51.4286', '2021-02-14 13:42:51.4286'],
5885+
positions: ['2020-12-14 06:38:34.2857', '2020-12-22 12:00', '2020-12-29 12:00', '2021-01-05 12:00', '2021-01-12 12:00', '2021-01-19 12:00', '2021-01-26 12:00', '2021-02-02 12:00', '2021-02-09 16:45:42.8571', '2021-02-15 18:45:42.8571'],
58865886
labels: ['', 'Dec 21<br>2020', 'Dec 28', 'Jan 4<br>2021', 'Jan 11', 'Jan 18', 'Jan 25', 'Feb 1', 'Feb 8', '']
58875887
},
58885888
{
58895889
range: ['2020-12-14 08:00', '2021-01-14 08:00'],
5890-
positions: ['2020-12-14 05:08:34.2857', '2020-12-16 12:17:08.5714', '2020-12-18 09:08:34.2857', '2020-12-22 12:17:08.5714', '2020-12-24 09:08:34.2857', '2020-12-28 12:17:08.5714', '2020-12-30 12:17:08.5714', '2021-01-01 09:08:34.2857', '2021-01-05 12:17:08.5714', '2021-01-07 09:08:34.2857', '2021-01-11 12:17:08.5714', '2021-01-13 12:17:08.5714'],
5891-
labels: ['', 'Dec 16<br>2020', 'Dec 18', 'Dec 22', 'Dec 24', 'Dec 28', 'Dec 30', 'Jan 1<br>2021', 'Jan 5', 'Jan 7', 'Jan 11', 'Jan 13']
5890+
positions: ['2020-12-14 11:34:17.1429', '2020-12-16 12:17:08.5714', '2020-12-18 18:34:17.1429', '2020-12-22 12:17:08.5714', '2020-12-24 18:34:17.1429', '2020-12-28 12:17:08.5714', '2020-12-30 12:17:08.5714', '2021-01-01 18:34:17.1429', '2021-01-05 12:17:08.5714', '2021-01-07 18:34:17.1429', '2021-01-11 12:17:08.5714', '2021-01-13 12:17:08.5714'],
5891+
labels: ['Dec 14<br>2020', 'Dec 16', 'Dec 18', 'Dec 22', 'Dec 24', 'Dec 28', 'Dec 30', 'Jan 1<br>2021', 'Jan 5', 'Jan 7', 'Jan 11', 'Jan 13']
58925892
},
58935893
{
58945894
range: ['2020-12-14 08:00', '2021-01-01 08:00'],
5895-
positions: ['2020-12-14 05:08:34.2857', '2020-12-16 12:17:08.5714', '2020-12-18 09:08:34.2857', '2020-12-22 12:17:08.5714', '2020-12-24 09:08:34.2857', '2020-12-28 12:17:08.5714', '2020-12-30 12:17:08.5714', '2021-01-01 12:17:08.5714'],
5896-
labels: ['', 'Dec 16<br>2020', 'Dec 18', 'Dec 22', 'Dec 24', 'Dec 28', 'Dec 30', '']
5895+
positions: ['2020-12-14 11:34:17.1429', '2020-12-16 12:17:08.5714', '2020-12-18 18:34:17.1429', '2020-12-22 12:17:08.5714', '2020-12-24 18:34:17.1429', '2020-12-28 12:17:08.5714', '2020-12-30 12:17:08.5714', '2021-01-01 12:17:08.5714'],
5896+
labels: ['Dec 14<br>2020', 'Dec 16', 'Dec 18', 'Dec 22', 'Dec 24', 'Dec 28', 'Dec 30', '']
58975897
},
58985898
{
58995899
range: ['2020-12-14 08:00', '2020-12-22 08:00'],
5900-
positions: ['2020-12-14 04:51:25.7143', '2020-12-15 12:00', '2020-12-16 12:00', '2020-12-17 12:00', '2020-12-18 08:00', '2020-12-21 12:00', '2020-12-22 12:00'],
5900+
positions: ['2020-12-14 06:04:17.1429', '2020-12-15 12:00', '2020-12-16 12:00', '2020-12-17 12:00', '2020-12-18 12:00', '2020-12-21 12:00', '2020-12-22 12:00'],
59015901
labels: ['', '06:00<br>Dec 15, 2020', '06:00<br>Dec 16, 2020', '06:00<br>Dec 17, 2020', '06:00<br>Dec 18, 2020', '06:00<br>Dec 21, 2020', '']
59025902
},
59035903
{

0 commit comments

Comments
 (0)