Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db7534b

Browse files
committed
use prepMinorTicks method
1 parent 8a1472f commit db7534b

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/plots/cartesian/axes.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,27 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {
540540
// Ticks and grids
541541
// ----------------------------------------------------
542542

543+
// ensure we have minor tick0 and dtick calculated
544+
axes.prepMinorTicks = function(ax, opts) {
545+
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
546+
547+
// calculate max number of (auto) ticks to display based on plot size
548+
if(ax.tickmode === 'auto' || !ax.dtick) {
549+
var nt = ax.nticks;
550+
var minPx;
551+
552+
if(!nt) {
553+
minPx = ax._id.charAt(0) === 'y' ? 40 : 80;
554+
nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
555+
}
556+
557+
ax._roughDTick = Math.abs(rng[1] - rng[0]) / nt;
558+
axes.autoTicks(ax, ax._roughDTick, 'minor');
559+
}
560+
};
561+
543562
// ensure we have tick0, dtick, and tick rounding calculated
544-
axes.prepTicks = function(ax, opts, isMinor) {
563+
axes.prepTicks = function(ax, opts) {
545564
var rng = Lib.simpleMap(ax.range, ax.r2l, undefined, undefined, opts);
546565

547566
// calculate max number of (auto) ticks to display based on plot size
@@ -565,11 +584,11 @@ axes.prepTicks = function(ax, opts, isMinor) {
565584

566585
// add a couple of extra digits for filling in ticks when we
567586
// have explicit tickvals without tick text
568-
if(ax.tickmode === 'array' && !isMinor) nt *= 100;
587+
if(ax.tickmode === 'array') nt *= 100;
569588

570589

571590
ax._roughDTick = Math.abs(rng[1] - rng[0]) / nt;
572-
axes.autoTicks(ax, ax._roughDTick, isMinor);
591+
axes.autoTicks(ax, ax._roughDTick);
573592

574593
// check for a forced minimum dtick
575594
if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {
@@ -578,7 +597,7 @@ axes.prepTicks = function(ax, opts, isMinor) {
578597
}
579598
}
580599

581-
if(ax.ticklabelmode === 'period' && !isMinor) {
600+
if(ax.ticklabelmode === 'period') {
582601
adjustPeriodDelta(ax);
583602
}
584603

@@ -592,7 +611,7 @@ axes.prepTicks = function(ax, opts, isMinor) {
592611
if(ax.type === 'date' && ax.dtick < 0.1) ax.dtick = 0.1;
593612

594613
// now figure out rounding of tick values
595-
if(!isMinor) autoTickRound(ax);
614+
autoTickRound(ax);
596615
};
597616

598617
function nMonths(dtick) {
@@ -827,7 +846,11 @@ axes.calcTicks = function calcTicks(ax, opts) {
827846
}
828847
}
829848

830-
axes.prepTicks(mockAx, opts, isMinor);
849+
if(isMinor) {
850+
axes.prepMinorTicks(mockAx, opts);
851+
} else {
852+
axes.prepTicks(mockAx, opts);
853+
}
831854

832855
// now that we've figured out the auto values for formatting
833856
// in case we're missing some ticktext, we can break out for array ticks

0 commit comments

Comments
 (0)