Skip to content

Commit c42358c

Browse files
committed
move & refactor period dtick logic inside a function
1 parent 77a51d3 commit c42358c

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/plots/cartesian/axes.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -592,34 +592,12 @@ function nMonths(dtick) {
592592
return +(dtick.substring(1));
593593
}
594594

595-
// calculate the ticks: text, values, positioning
596-
// if ticks are set to automatic, determine the right values (tick0,dtick)
597-
// in any case, set tickround to # of digits to round tick labels to,
598-
// or codes to this effect for log and date scales
599-
axes.calcTicks = function calcTicks(ax, opts) {
600-
axes.prepTicks(ax, opts);
601-
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
602-
603-
// now that we've figured out the auto values for formatting
604-
// in case we're missing some ticktext, we can break out for array ticks
605-
if(ax.tickmode === 'array') return arrayTicks(ax);
606-
607-
// add a tiny bit so we get ticks which may have rounded out
608-
var exRng = expandRange(rng);
609-
var startTick = exRng[0];
610-
var endTick = exRng[1];
611-
// check for reversed axis
612-
var axrev = (rng[1] < rng[0]);
613-
var minRange = Math.min(rng[0], rng[1]);
614-
var maxRange = Math.max(rng[0], rng[1]);
595+
function adjustPeriodDelta(ax) { // adjusts ax.dtick and returns definedDelta
596+
var definedDelta;
615597

616-
var isDLog = (ax.type === 'log') && !(isNumeric(ax.dtick) || ax.dtick.charAt(0) === 'L');
617598
var isMDate = (ax.type === 'date') && !(isNumeric(ax.dtick) || ax.dtick.charAt(0) === 'M');
618-
619599
var tickformat = axes.getTickFormat(ax);
620-
var isPeriod = ax.ticklabelmode === 'period';
621-
var definedDelta;
622-
if(isPeriod && tickformat) {
600+
if(tickformat) {
623601
var noDtick = ax._dtickInit !== ax.dtick;
624602
if(
625603
!(/%[fLQsSMX]/.test(tickformat))
@@ -695,6 +673,34 @@ axes.calcTicks = function calcTicks(ax, opts) {
695673
}
696674
}
697675

676+
return definedDelta;
677+
}
678+
679+
// calculate the ticks: text, values, positioning
680+
// if ticks are set to automatic, determine the right values (tick0,dtick)
681+
// in any case, set tickround to # of digits to round tick labels to,
682+
// or codes to this effect for log and date scales
683+
axes.calcTicks = function calcTicks(ax, opts) {
684+
axes.prepTicks(ax, opts);
685+
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
686+
687+
// now that we've figured out the auto values for formatting
688+
// in case we're missing some ticktext, we can break out for array ticks
689+
if(ax.tickmode === 'array') return arrayTicks(ax);
690+
691+
// add a tiny bit so we get ticks which may have rounded out
692+
var exRng = expandRange(rng);
693+
var startTick = exRng[0];
694+
var endTick = exRng[1];
695+
// check for reversed axis
696+
var axrev = (rng[1] < rng[0]);
697+
var minRange = Math.min(rng[0], rng[1]);
698+
var maxRange = Math.max(rng[0], rng[1]);
699+
700+
var isDLog = (ax.type === 'log') && !(isNumeric(ax.dtick) || ax.dtick.charAt(0) === 'L');
701+
var isPeriod = ax.ticklabelmode === 'period';
702+
var definedDelta = isPeriod ? adjustPeriodDelta(ax) : undefined;
703+
698704
// find the first tick
699705
ax._tmin = axes.tickFirst(ax, opts);
700706

0 commit comments

Comments
 (0)