Skip to content

Commit e953f2a

Browse files
committed
Fix tick prefixes and suffixes for explicit tick values
1 parent 0316e60 commit e953f2a

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎draftlogs/pending_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Apply `tickprefix` and `ticksuffix` to `tickvals` without explicit `ticktext`

‎src/plots/cartesian/axes.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ function arrayTicks(ax, majorOnly) {
15021502
for(var i = 0; i < vals.length; i++) {
15031503
var vali = tickVal2l(vals[i]);
15041504
if(vali > tickMin && vali < tickMax) {
1505-
var obj = axes.tickText(ax, vali, false, String(text[i]), {
1505+
const obj = axes.tickText(ax, vali, false, text[i] !== undefined, {
15061506
first: i === firstIdx,
15071507
last: i === lastIdx,
15081508
});

‎test/jasmine/tests/axes_test.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,6 +3931,40 @@ describe('Test axes', function() {
39313931
});
39323932
});
39333933

3934+
it('applies prefixes and suffixes to array ticks without explicit text', () => {
3935+
['linear', 'log', 'date', 'category'].forEach(axType => {
3936+
const vals = axType === 'date' ?
3937+
['2020-01-01', '2020-01-02', '2020-01-03'] :
3938+
axType === 'category' ? ['a', 'b', 'c'] : [1, 2, 3];
3939+
const ax = {
3940+
type: axType,
3941+
tickmode: 'array',
3942+
tickvals: vals,
3943+
range: axType === 'log' ? [0, 1] :
3944+
axType === 'category' ? [-0.5, 2.5] : [vals[0], vals[2]],
3945+
tickprefix: '<',
3946+
ticksuffix: '>',
3947+
showtickprefix: 'all',
3948+
showticksuffix: 'all',
3949+
nticks: 10
3950+
};
3951+
if(axType === 'category') {
3952+
ax._categories = vals;
3953+
ax._categoriesMap = {a: 0, b: 1, c: 2};
3954+
}
3955+
const bare = mockCalc({...ax, tickprefix: '', ticksuffix: ''});
3956+
expect(mockCalc(ax)).toEqual(bare.map(text => `<${text}>`), axType);
3957+
ax.ticktext = ['custom'];
3958+
expect(mockCalc(ax)).toEqual(['custom', `<${bare[1]}>`, `<${bare[2]}>`], axType);
3959+
ax.showtickprefix = 'first';
3960+
ax.showticksuffix = 'last';
3961+
delete ax.ticktext;
3962+
expect(mockCalc(ax)).toEqual([`<${bare[0]}`, bare[1], `${bare[2]}>`], axType);
3963+
ax.showtickprefix = ax.showticksuffix = 'none';
3964+
expect(mockCalc(ax)).toEqual(bare, axType);
3965+
});
3966+
});
3967+
39343968
it('should handle tickvals edge cases with category axes', function() {
39353969
var ax = {
39363970
type: 'category',

0 commit comments

Comments
 (0)