Skip to content

Commit 22e5658

Browse files
committed
avoid too tick overlaps on x axes with rangebreaks and now only when tickmode is auto
1 parent 9e7b80e commit 22e5658

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

src/plots/cartesian/axes.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,12 @@ axes.calcTicks = function calcTicks(ax) {
625625
// and reduce ticks
626626
var len = tickVals.length;
627627
if(len > 2) {
628-
var tf2 = 2 * (ax.tickfont ? ax.tickfont.size : 12);
628+
var tf = 0;
629+
if(ax.tickmode === 'auto') {
630+
tf =
631+
(ax._id.charAt(0) === 'y' ? 2 : 5) *
632+
(ax.tickfont ? ax.tickfont.size : 12);
633+
}
629634

630635
var newTickVals = [];
631636
var prevPos;
@@ -650,7 +655,7 @@ axes.calcTicks = function calcTicks(ax) {
650655
if(newTickVals[newTickVals.length - 1].value < tickVal.value) {
651656
newTickVals[newTickVals.length - 1] = tickVal;
652657
}
653-
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf2) {
658+
} else if(prevPos === undefined || Math.abs(pos - prevPos) > tf) {
654659
prevPos = pos;
655660
newTickVals.push(tickVal);
656661
}
-5.7 KB
Loading
Loading
Loading
-357 Bytes
Loading

test/jasmine/tests/axes_test.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ describe('Test axes', function() {
19061906
expect(axIn.tickmode).toBeUndefined();
19071907
});
19081908

1909-
it(woTemplate + 'should set nticks iff tickmode=auto', function() {
1909+
it(woTemplate + 'should set nticks if tickmode=auto', function() {
19101910
var axIn = {};
19111911
var axOut = {};
19121912
mockSupplyDefaults(axIn, axOut, 'linear');
@@ -1923,7 +1923,7 @@ describe('Test axes', function() {
19231923
expect(axOut.nticks).toBe(undefined);
19241924
});
19251925

1926-
it(woTemplate + 'should set tick0 and dtick iff tickmode=linear', function() {
1926+
it(woTemplate + 'should set tick0 and dtick if tickmode=linear', function() {
19271927
var axIn = {tickmode: 'auto', tick0: 1, dtick: 1};
19281928
var axOut = {};
19291929
mockSupplyDefaults(axIn, axOut, 'linear');
@@ -2040,7 +2040,7 @@ describe('Test axes', function() {
20402040
});
20412041
});
20422042

2043-
it(woTemplate + 'should set tickvals and ticktext iff tickmode=array', function() {
2043+
it(woTemplate + 'should set tickvals and ticktext if tickmode=array', function() {
20442044
var axIn = {tickmode: 'auto', tickvals: [1, 2, 3], ticktext: ['4', '5', '6']};
20452045
var axOut = {};
20462046
mockSupplyDefaults(axIn, axOut, 'linear');
@@ -5067,17 +5067,16 @@ describe('Test axes', function() {
50675067
.then(function() {
50685068
_assert('base', {
50695069
tickVals: [
5070-
'1970-01-01 08:00',
5071-
'1970-01-01 12:00', '1970-01-01 16:00',
5072-
'1970-01-02 12:00', '1970-01-02 16:00',
5073-
'1970-01-05 12:00', '1970-01-05 16:00',
5074-
'1970-01-06 12:00', '1970-01-06 16:00',
5075-
'1970-01-07 12:00', '1970-01-07 16:00',
5076-
'1970-01-08 12:00', '1970-01-08 16:00',
5077-
'1970-01-09 12:00', '1970-01-09 16:00',
5078-
'1970-01-12 12:00', '1970-01-12 16:00',
5079-
'1970-01-13 12:00', '1970-01-13 16:00',
5080-
'1970-01-14 12:00', '1970-01-14 16:00'
5070+
'1970-01-01 08:00', '1970-01-01 12:00', '1970-01-01 16:00',
5071+
'1970-01-02 08:00', '1970-01-02 12:00', '1970-01-02 16:00',
5072+
'1970-01-05 08:00', '1970-01-05 12:00', '1970-01-05 16:00',
5073+
'1970-01-06 08:00', '1970-01-06 12:00', '1970-01-06 16:00',
5074+
'1970-01-07 08:00', '1970-01-07 12:00', '1970-01-07 16:00',
5075+
'1970-01-08 08:00', '1970-01-08 12:00', '1970-01-08 16:00',
5076+
'1970-01-09 08:00', '1970-01-09 12:00', '1970-01-09 16:00',
5077+
'1970-01-12 08:00', '1970-01-12 12:00', '1970-01-12 16:00',
5078+
'1970-01-13 08:00', '1970-01-13 12:00', '1970-01-13 16:00',
5079+
'1970-01-14 08:00', '1970-01-14 12:00', '1970-01-14 16:00'
50815080
].map(Lib.dateTime2ms)
50825081
});
50835082
})
@@ -5130,17 +5129,16 @@ describe('Test axes', function() {
51305129
.then(function() {
51315130
_assert('2-hour dtick', {
51325131
tickVals: [
5133-
'1970-01-01 08:00',
5134-
'1970-01-01 10:00', '1970-01-01 12:00', '1970-01-01 14:00', '1970-01-01 16:00',
5135-
'1970-01-02 10:00', '1970-01-02 12:00', '1970-01-02 14:00', '1970-01-02 16:00',
5136-
'1970-01-05 10:00', '1970-01-05 12:00', '1970-01-05 14:00', '1970-01-05 16:00',
5137-
'1970-01-06 10:00', '1970-01-06 12:00', '1970-01-06 14:00', '1970-01-06 16:00',
5138-
'1970-01-07 10:00', '1970-01-07 12:00', '1970-01-07 14:00', '1970-01-07 16:00',
5139-
'1970-01-08 10:00', '1970-01-08 12:00', '1970-01-08 14:00', '1970-01-08 16:00',
5140-
'1970-01-09 10:00', '1970-01-09 12:00', '1970-01-09 14:00', '1970-01-09 16:00',
5141-
'1970-01-12 10:00', '1970-01-12 12:00', '1970-01-12 14:00', '1970-01-12 16:00',
5142-
'1970-01-13 10:00', '1970-01-13 12:00', '1970-01-13 14:00', '1970-01-13 16:00',
5143-
'1970-01-14 10:00', '1970-01-14 12:00', '1970-01-14 14:00', '1970-01-14 16:00'
5132+
'1970-01-01 08:00', '1970-01-01 10:00', '1970-01-01 12:00', '1970-01-01 14:00', '1970-01-01 16:00',
5133+
'1970-01-02 08:00', '1970-01-02 10:00', '1970-01-02 12:00', '1970-01-02 14:00', '1970-01-02 16:00',
5134+
'1970-01-05 08:00', '1970-01-05 10:00', '1970-01-05 12:00', '1970-01-05 14:00', '1970-01-05 16:00',
5135+
'1970-01-06 08:00', '1970-01-06 10:00', '1970-01-06 12:00', '1970-01-06 14:00', '1970-01-06 16:00',
5136+
'1970-01-07 08:00', '1970-01-07 10:00', '1970-01-07 12:00', '1970-01-07 14:00', '1970-01-07 16:00',
5137+
'1970-01-08 08:00', '1970-01-08 10:00', '1970-01-08 12:00', '1970-01-08 14:00', '1970-01-08 16:00',
5138+
'1970-01-09 08:00', '1970-01-09 10:00', '1970-01-09 12:00', '1970-01-09 14:00', '1970-01-09 16:00',
5139+
'1970-01-12 08:00', '1970-01-12 10:00', '1970-01-12 12:00', '1970-01-12 14:00', '1970-01-12 16:00',
5140+
'1970-01-13 08:00', '1970-01-13 10:00', '1970-01-13 12:00', '1970-01-13 14:00', '1970-01-13 16:00',
5141+
'1970-01-14 08:00', '1970-01-14 10:00', '1970-01-14 12:00', '1970-01-14 14:00', '1970-01-14 16:00'
51445142
].map(Lib.dateTime2ms)
51455143
});
51465144
})

0 commit comments

Comments
 (0)