Skip to content

Commit c57f2c8

Browse files
committed
revert changes in axes.autoTicks
1 parent 80933c4 commit c57f2c8

File tree

1 file changed

+12
-69
lines changed

1 file changed

+12
-69
lines changed

src/plots/cartesian/axes.js

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,21 +1280,6 @@ function roundDTick(roughDTick, base, roundingSet) {
12801280
// log showing powers plus some intermediates:
12811281
// D1 shows all digits, D2 shows 2 and 5
12821282
axes.autoTicks = function(ax, roughDTick, isMinor) {
1283-
var majorDtick = ax._majorDtick;
1284-
var hasMinorNtick = isMinor && ax.nticks;
1285-
1286-
var mayRound = function(roughDTick, base, roundingSet) {
1287-
return hasMinorNtick ?
1288-
roughDTick :
1289-
roundDTick(roughDTick, base, roundingSet);
1290-
};
1291-
1292-
var mayCeil = function(roughDTick) {
1293-
return hasMinorNtick ?
1294-
roughDTick :
1295-
Math.ceil(roughDTick);
1296-
};
1297-
12981283
var base;
12991284

13001285
function getBase(v) {
@@ -1304,27 +1289,19 @@ axes.autoTicks = function(ax, roughDTick, isMinor) {
13041289
if(ax.type === 'date') {
13051290
ax.tick0 = Lib.dateTick0(ax.calendar, 0);
13061291

1307-
var _roundDays = ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays;
1308-
13091292
// the criteria below are all based on the rough spacing we calculate
13101293
// being > half of the final unit - so precalculate twice the rough val
13111294
var roughX2 = 2 * roughDTick;
13121295

1313-
var months;
13141296
if(roughX2 > ONEAVGYEAR) {
13151297
roughDTick /= ONEAVGYEAR;
13161298
base = getBase(10);
1317-
months = 12 * mayRound(roughDTick, base, roundBase10);
1318-
months = Math.round(months);
1319-
ax.dtick = 'M' + months;
1299+
ax.dtick = 'M' + (12 * roundDTick(roughDTick, base, roundBase10));
13201300
} else if(roughX2 > ONEAVGMONTH) {
13211301
roughDTick /= ONEAVGMONTH;
1322-
months = mayRound(roughDTick, 1, roundBase24);
1323-
months = Math.round(months);
1324-
if(months < 1) months = 1;
1325-
ax.dtick = 'M' + months;
1302+
ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
13261303
} else if(roughX2 > ONEDAY) {
1327-
ax.dtick = mayRound(roughDTick, ONEDAY, _roundDays);
1304+
ax.dtick = roundDTick(roughDTick, ONEDAY, ax._hasDayOfWeekBreaks ? [1, 2, 7, 14] : roundDays);
13281305
if(!isMinor) {
13291306
// get week ticks on sunday
13301307
// this will also move the base tick off 2000-01-01 if dtick is
@@ -1342,49 +1319,15 @@ axes.autoTicks = function(ax, roughDTick, isMinor) {
13421319
if(isPeriod) ax._dowTick0 = ax.tick0;
13431320
}
13441321
} else if(roughX2 > ONEHOUR) {
1345-
ax.dtick = mayRound(roughDTick, ONEHOUR, roundBase24);
1322+
ax.dtick = roundDTick(roughDTick, ONEHOUR, roundBase24);
13461323
} else if(roughX2 > ONEMIN) {
1347-
ax.dtick = mayRound(roughDTick, ONEMIN, roundBase60);
1324+
ax.dtick = roundDTick(roughDTick, ONEMIN, roundBase60);
13481325
} else if(roughX2 > ONESEC) {
1349-
ax.dtick = mayRound(roughDTick, ONESEC, roundBase60);
1326+
ax.dtick = roundDTick(roughDTick, ONESEC, roundBase60);
13501327
} else {
13511328
// milliseconds
13521329
base = getBase(10);
1353-
ax.dtick = mayRound(roughDTick, base, roundBase10);
1354-
}
1355-
1356-
if(isMinor && !hasMinorNtick) {
1357-
if(
1358-
typeof majorDtick === 'string' &&
1359-
majorDtick.charAt(0) === 'M'
1360-
) {
1361-
if(majorDtick === 'M24') {
1362-
ax.dtick = 'M12';
1363-
}
1364-
1365-
if(majorDtick === 'M12') {
1366-
ax.dtick = 'M3';
1367-
}
1368-
1369-
if(typeof ax.dtick !== 'string') {
1370-
ax.dtick = 'M1';
1371-
}
1372-
}
1373-
1374-
if(majorDtick > ONEDAY) {
1375-
if(majorDtick === 14 * ONEDAY) ax.dtick = 7 * ONEDAY;
1376-
else {
1377-
var v = mayRound(majorDtick, ONEDAY, _roundDays);
1378-
if(v >= majorDtick) {
1379-
v = mayRound(majorDtick / 7, ONEDAY, _roundDays);
1380-
}
1381-
1382-
if((majorDtick / ONEDAY) % (v / ONEDAY)) {
1383-
v = ONEDAY;
1384-
}
1385-
ax.dtick = v;
1386-
}
1387-
}
1330+
ax.dtick = roundDTick(roughDTick, base, roundBase10);
13881331
}
13891332
} else if(ax.type === 'log') {
13901333
ax.tick0 = 0;
@@ -1397,7 +1340,7 @@ axes.autoTicks = function(ax, roughDTick, isMinor) {
13971340
}
13981341
if(roughDTick > 0.7) {
13991342
// only show powers of 10
1400-
ax.dtick = mayCeil(roughDTick);
1343+
ax.dtick = Math.ceil(roughDTick);
14011344
} else if(Math.abs(rng[1] - rng[0]) < 1) {
14021345
// span is less than one power of 10
14031346
var nt = 1.5 * Math.abs((rng[1] - rng[0]) / roughDTick);
@@ -1406,7 +1349,7 @@ axes.autoTicks = function(ax, roughDTick, isMinor) {
14061349
roughDTick = Math.abs(Math.pow(10, rng[1]) -
14071350
Math.pow(10, rng[0])) / nt;
14081351
base = getBase(10);
1409-
ax.dtick = 'L' + mayRound(roughDTick, base, roundBase10);
1352+
ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);
14101353
} else {
14111354
// include intermediates between powers of 10,
14121355
// labeled with small digits
@@ -1415,16 +1358,16 @@ axes.autoTicks = function(ax, roughDTick, isMinor) {
14151358
}
14161359
} else if(ax.type === 'category' || ax.type === 'multicategory') {
14171360
ax.tick0 = 0;
1418-
ax.dtick = mayCeil(Math.max(roughDTick, 1));
1361+
ax.dtick = Math.ceil(Math.max(roughDTick, 1));
14191362
} else if(isAngular(ax)) {
14201363
ax.tick0 = 0;
14211364
base = 1;
1422-
ax.dtick = mayRound(roughDTick, base, roundAngles);
1365+
ax.dtick = roundDTick(roughDTick, base, roundAngles);
14231366
} else {
14241367
// auto ticks always start at 0
14251368
ax.tick0 = 0;
14261369
base = getBase(10);
1427-
ax.dtick = mayRound(roughDTick, base, roundBase10);
1370+
ax.dtick = roundDTick(roughDTick, base, roundBase10);
14281371
}
14291372

14301373
// prevent infinite loops

0 commit comments

Comments
 (0)