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

Skip to content

Commit 4bc28dd

Browse files
committed
further tweak of autoShiftNumericBins
and fix its tests for the improved behavior
1 parent 17c04c5 commit 4bc28dd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/plots/cartesian/axes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ function autoShiftNumericBins(binStart, data, ax, dataMin, dataMax) {
610610
// the bin size, just enough to clear up endpoint
611611
// ambiguity about which integers are in which bins.
612612
else {
613-
binStart += (binStart + 0.5 < dataMin) ? 0.5 : -0.5;
613+
binStart -= 0.5;
614+
if(binStart + ax.dtick < dataMin) binStart += ax.dtick;
614615
}
615616
}
616617
else if(midcount < dataCount * 0.1) {

test/jasmine/tests/axes_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ describe('Test axes', function() {
18091809
);
18101810

18111811
expect(out).toEqual({
1812-
start: -0.5,
1812+
start: 0.5,
18131813
end: 4.5,
18141814
size: 1
18151815
});
@@ -1822,6 +1822,9 @@ describe('Test axes', function() {
18221822
2
18231823
);
18241824

1825+
// when size > 1 with all integers, we want the starting point to be
1826+
// a half integer below the round number a tick would be at (in this case 0)
1827+
// to approximate the half-open interval [) that's commonly used.
18251828
expect(out).toEqual({
18261829
start: -0.5,
18271830
end: 5.5,

0 commit comments

Comments
 (0)