Skip to content

Commit 77f745e

Browse files
committed
fix log axes tickvals default text formatting bug
1 parent 74da7a4 commit 77f745e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/plots/cartesian/axes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ function arrayTicks(ax) {
714714
// make sure showing ticks doesn't accidentally add new categories
715715
var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
716716

717+
// array ticks on log axes always show the full number
718+
// (if no explicit ticktext overrides it)
719+
if(ax.type === 'log' && String(ax.dtick).charAt(0) !== 'L') {
720+
ax.dtick = 'L' + Math.pow(10, Math.floor(Math.min(ax.range[0], ax.range[1])) - 1);
721+
}
722+
717723
for(i = 0; i < vals.length; i++) {
718724
vali = tickVal2l(vals[i]);
719725
if(vali > tickMin && vali < tickMax) {

test/jasmine/tests/axes_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,19 +1535,19 @@ describe('Test axes', function() {
15351535
var textOut = mockCalc({
15361536
type: axType,
15371537
tickmode: 'array',
1538-
tickvals: [1, 1.5, 2.6999999, 3, 3.999, 10, 0.1],
1538+
tickvals: [1, 1.5, 2.6999999, 30, 39.999, 100, 0.1],
15391539
ticktext: ['One', '...and a half'],
15401540
// I'll be so happy when I can finally get rid of this switch!
1541-
range: axType === 'log' ? [-0.2, 0.8] : [0.5, 5],
1541+
range: axType === 'log' ? [-0.2, 1.8] : [0.5, 50],
15421542
nticks: 10
15431543
});
15441544

15451545
var expectedText = [
15461546
'One',
15471547
'...and a half', // the first two get explicit labels
15481548
'2.7', // 2.6999999 gets rounded to 2.7
1549-
'3',
1550-
'3.999' // 3.999 does not get rounded
1549+
'30',
1550+
'39.999' // 39.999 does not get rounded
15511551
// 10 and 0.1 are off scale
15521552
];
15531553
expect(textOut).toEqual(expectedText, axType);

0 commit comments

Comments
 (0)