From e953f2ae1fb77e81b938def9e5e4c6996fa2f49a Mon Sep 17 00:00:00 2001 From: Davis Rens <166565828+davrens101@users.noreply.github.com> Date: Sat, 31 Oct 2026 23:48:22 -0700 Subject: [PATCH 1/2] Fix tick prefixes and suffixes for explicit tick values --- draftlogs/pending_fix.md | 1 + src/plots/cartesian/axes.js | 2 +- test/jasmine/tests/axes_test.js | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 draftlogs/pending_fix.md diff --git a/draftlogs/pending_fix.md b/draftlogs/pending_fix.md new file mode 100644 index 00000000000..9a87408c969 --- /dev/null +++ b/draftlogs/pending_fix.md @@ -0,0 +1 @@ +- Apply `tickprefix` and `ticksuffix` to `tickvals` without explicit `ticktext` diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 1661d8c115c..d6f2e562b7a 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -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, }); diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index e964c3c33da..aff194fc690 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -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', From c8ecfd27a4e52229b17d598ad18243189a2f221e Mon Sep 17 00:00:00 2001 From: Davis Rens <166565828+davrens101@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:04:39 -0800 Subject: [PATCH 2/2] Link the tick prefix and suffix draftlog to PR 8160 --- draftlogs/8160_fix.md | 1 + draftlogs/pending_fix.md | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 draftlogs/8160_fix.md delete mode 100644 draftlogs/pending_fix.md diff --git a/draftlogs/8160_fix.md b/draftlogs/8160_fix.md new file mode 100644 index 00000000000..dff6b4ee856 --- /dev/null +++ b/draftlogs/8160_fix.md @@ -0,0 +1 @@ +- Apply `tickprefix` and `ticksuffix` to `tickvals` without explicit `ticktext` [[#8160](https://github.com/plotly/plotly.js/pull/8160)] diff --git a/draftlogs/pending_fix.md b/draftlogs/pending_fix.md deleted file mode 100644 index 9a87408c969..00000000000 --- a/draftlogs/pending_fix.md +++ /dev/null @@ -1 +0,0 @@ -- Apply `tickprefix` and `ticksuffix` to `tickvals` without explicit `ticktext`