From f1f8c4730dc1424a894291ee1bda760a92a96f6a Mon Sep 17 00:00:00 2001 From: Bennett Payoyo <75754746+Yahiro025@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:11:44 +0800 Subject: [PATCH 1/3] Keep shape label texttemplate working on category axes Shape label templates map positions with axis.d2l, which multicategory axes do not define, so a label with texttemplate throws 'axis.d2l is not a function'. On category axes d2l also appends unknown positions as categories, so the template changes the axis range. Use d2l_noadd when the axis provides it: it returns existing category indices and numeric positions without adding categories, and it is the only data-to-linear conversion multicategory axes define. --- src/components/shapes/label_texttemplate.js | 6 ++- test/jasmine/tests/shapes_test.js | 43 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/components/shapes/label_texttemplate.js b/src/components/shapes/label_texttemplate.js index cce3abfdecb..3b6174c15b4 100644 --- a/src/components/shapes/label_texttemplate.js +++ b/src/components/shapes/label_texttemplate.js @@ -3,7 +3,11 @@ // Wrapper functions to handle paper-referenced shapes, which have no axis function d2l(v, axis) { - return axis ? axis.d2l(v) : v; + if(!axis) return v; + // Category axes expose d2l_noadd, which maps positions without appending + // new categories; multicategory axes only define that variant. + var conv = axis.d2l_noadd || axis.d2l; + return conv(v); } function l2d(v, axis) { diff --git a/test/jasmine/tests/shapes_test.js b/test/jasmine/tests/shapes_test.js index 683d3bb3e59..d07376ab423 100644 --- a/test/jasmine/tests/shapes_test.js +++ b/test/jasmine/tests/shapes_test.js @@ -2170,3 +2170,46 @@ describe('Shape labels with pixel sizemode', () => { .then(done, done.fail); }); }); + +describe('Shape labels with texttemplate on a multicategory axis', () => { + let gd; + beforeEach(() => { + gd = createGraphDiv(); + }); + afterEach(destroyGraphDiv); + + it('renders the template without adding categories', (done) => { + const data = [{ + type: 'bar', + x: [ + ['2023', '2023', '2024', '2024'], + ['H1', 'H2', 'H1', 'H2'] + ], + y: [3, 5, 4, 6] + }]; + const layout = { + shapes: [{ + type: 'rect', + xref: 'x', + x0: 1.5, + x1: 3.5, + yref: 'paper', + y0: 0, + y1: 1, + label: { texttemplate: '2024' } + }] + }; + + Plotly.newPlot(gd, data, layout) + .then(() => { + expect(gd._fullLayout.xaxis._categories.length).toBe(4); + expect(d3SelectAll('.shape-label-text').text()).toBe('2024'); + + return Plotly.relayout(gd, 'shapes[0].label.texttemplate', '%{width}'); + }) + .then(() => { + expect(d3SelectAll('.shape-label-text').text()).toBe('2'); + }) + .then(done, done.fail); + }); +}); From 9f85661fa9ccc890e7b41408762b269eb21da5c0 Mon Sep 17 00:00:00 2001 From: Bennett Payoyo <75754746+Yahiro025@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:12:22 +0800 Subject: [PATCH 2/3] Add draft log for #8219 --- draftlogs/8219_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/8219_fix.md diff --git a/draftlogs/8219_fix.md b/draftlogs/8219_fix.md new file mode 100644 index 00000000000..eacf075ec8c --- /dev/null +++ b/draftlogs/8219_fix.md @@ -0,0 +1 @@ + - Fix shape label `texttemplate` on category and multicategory axes [[#8219](https://github.com/plotly/plotly.js/pull/8219)] From c780ac18208c05ba9f21dcefe7645acd9504ec79 Mon Sep 17 00:00:00 2001 From: Bennett Payoyo <75754746+Yahiro025@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:34:56 +0800 Subject: [PATCH 3/3] Start the #8219 draft log entry at column zero --- draftlogs/8219_fix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draftlogs/8219_fix.md b/draftlogs/8219_fix.md index eacf075ec8c..355dd7ba825 100644 --- a/draftlogs/8219_fix.md +++ b/draftlogs/8219_fix.md @@ -1 +1 @@ - - Fix shape label `texttemplate` on category and multicategory axes [[#8219](https://github.com/plotly/plotly.js/pull/8219)] +- Fix shape label `texttemplate` on category and multicategory axes [[#8219](https://github.com/plotly/plotly.js/pull/8219)]