Skip to content

Commit 7598ddd

Browse files
committed
attempt fixing minor and major overlaps
1 parent c6b7231 commit 7598ddd

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/plots/cartesian/axes.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,22 @@ axes.calcTicks = function calcTicks(ax, opts) {
963963

964964
var majorValues = tickVals.map(function(d) { return d.value; });
965965

966-
minorTickVals = minorTickVals.filter(function(d) {
967-
return majorValues.indexOf(d.value) === -1;
968-
});
969-
970-
// TODO: also filter using almostEq to handle rounding errors as illustrated by mock 32
966+
var list = [];
967+
for(var k = 0; k < minorTickVals.length; k++) {
968+
var T = minorTickVals[k];
969+
var v = T.value;
970+
if(majorValues.indexOf(v) !== -1) {
971+
continue;
972+
}
973+
var found = false;
974+
for(var q = 0; !found && (q < tickVals.length); q++) {
975+
if(almostEq(v, tickVals[q].value)) {
976+
found = true;
977+
}
978+
}
979+
if(!found) list.push(T);
980+
}
981+
minorTickVals = list;
971982
}
972983
}
973984

@@ -1844,13 +1855,13 @@ function formatAngle(ax, out, hover, extraPrecision, hideexp) {
18441855
}
18451856
}
18461857

1858+
function almostEq(a, b) {
1859+
return Math.abs(a - b) <= 1e-6;
1860+
}
1861+
18471862
// inspired by
18481863
// https://github.com/yisibl/num2fraction/blob/master/index.js
18491864
function num2frac(num) {
1850-
function almostEq(a, b) {
1851-
return Math.abs(a - b) <= 1e-6;
1852-
}
1853-
18541865
function findGCD(a, b) {
18551866
return almostEq(b, 0) ? a : findGCD(b, a % b);
18561867
}

test/image/baselines/32.png

-68 Bytes
Loading

0 commit comments

Comments
 (0)