diff --git a/draftlogs/8176_fix.md b/draftlogs/8176_fix.md new file mode 100644 index 00000000000..7ec5bf24d64 --- /dev/null +++ b/draftlogs/8176_fix.md @@ -0,0 +1 @@ +- Fix a heatmap with a single `x` or `y` value on a category axis, which was drawn at twice its category index [[#8176](https://github.com/plotly/plotly.js/pull/8176)] diff --git a/src/traces/heatmap/make_bound_array.js b/src/traces/heatmap/make_bound_array.js index cf1eecd38de..47dc463cf1b 100644 --- a/src/traces/heatmap/make_bound_array.js +++ b/src/traces/heatmap/make_bound_array.js @@ -80,7 +80,8 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, if(isHist) { v0 = ax.r2c(v0In, 0, calendar); } else { - if(isArrayOrTypedArray(arrayIn) && arrayIn.length === 1) { + // on a category axis, z is already laid out on all the axis categories (clean_2d_array) + if(isArrayOrTypedArray(arrayIn) && arrayIn.length === 1 && ax.type !== 'category') { v0 = arrayIn[0]; } else if(v0In === undefined) { v0 = 0; diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index ceb527f4132..7530edead84 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -668,6 +668,18 @@ describe('heatmap plot', function() { afterEach(destroyGraphDiv); + it('places a one-column trace at its category on a shared category axis', function(done) { + Plotly.newPlot(gd, [ + {type: 'heatmap', x: ['b', 'c'], y: ['x', 'y', 'z'], z: [[1, 4], [2, 5], [3, 6]]}, + {type: 'heatmap', x: ['a'], y: ['x', 'y', 'z'], z: [[7], [8], [9]]} + ]).then(function() { + // z of every trace is laid out on all the axis categories, so bricks start at 0 + expect(gd.calcdata[1][0].x).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]); + expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.5, 2.5]); + }) + .then(done, done.fail); + }); + it('should not draw traces that are off-screen', function(done) { var mock = require('../../image/mocks/heatmap_multi-trace.json'); var mockCopy = Lib.extendDeep({}, mock);