Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8160_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Apply `tickprefix` and `ticksuffix` to `tickvals` without explicit `ticktext` [[#8160](https://github.com/plotly/plotly.js/pull/8160)]
2 changes: 1 addition & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ function arrayTicks(ax, majorOnly) {
for(var i = 0; i < vals.length; i++) {
var vali = tickVal2l(vals[i]);
if(vali > tickMin && vali < tickMax) {
var obj = axes.tickText(ax, vali, false, String(text[i]), {
const obj = axes.tickText(ax, vali, false, text[i] !== undefined, {
first: i === firstIdx,
last: i === lastIdx,
});
Expand Down
34 changes: 34 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3931,6 +3931,40 @@ describe('Test axes', function() {
});
});

it('applies prefixes and suffixes to array ticks without explicit text', () => {
['linear', 'log', 'date', 'category'].forEach(axType => {
const vals = axType === 'date' ?
['2020-01-01', '2020-01-02', '2020-01-03'] :
axType === 'category' ? ['a', 'b', 'c'] : [1, 2, 3];
const ax = {
type: axType,
tickmode: 'array',
tickvals: vals,
range: axType === 'log' ? [0, 1] :
axType === 'category' ? [-0.5, 2.5] : [vals[0], vals[2]],
tickprefix: '<',
ticksuffix: '>',
showtickprefix: 'all',
showticksuffix: 'all',
nticks: 10
};
if(axType === 'category') {
ax._categories = vals;
ax._categoriesMap = {a: 0, b: 1, c: 2};
}
const bare = mockCalc({...ax, tickprefix: '', ticksuffix: ''});
expect(mockCalc(ax)).toEqual(bare.map(text => `<${text}>`), axType);
ax.ticktext = ['custom'];
expect(mockCalc(ax)).toEqual(['custom', `<${bare[1]}>`, `<${bare[2]}>`], axType);
ax.showtickprefix = 'first';
ax.showticksuffix = 'last';
delete ax.ticktext;
expect(mockCalc(ax)).toEqual([`<${bare[0]}`, bare[1], `${bare[2]}>`], axType);
ax.showtickprefix = ax.showticksuffix = 'none';
expect(mockCalc(ax)).toEqual(bare, axType);
});
});

it('should handle tickvals edge cases with category axes', function() {
var ax = {
type: 'category',
Expand Down