diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index 6059ce377ef..5cf67cf8dbc 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -51,7 +51,7 @@ drawing.translatePoint = function(d, sel, xa, ya) { var x = d.xp || xa.c2p(d.x), y = d.yp || ya.c2p(d.y); - if(isNumeric(x) && isNumeric(y)) { + if(isNumeric(x) && isNumeric(y) && sel.node()) { // for multiline text this works better if(sel.node().nodeName === 'text') { sel.attr('x', x).attr('y', y); diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 76cfb9802ce..e6deca855b0 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -178,6 +178,28 @@ describe('Test plot api', function() { }) .then(done); }); + + it('can set empty text nodes', function(done) { + var data = [{ + x: [1, 2, 3], + y: [0, 0, 0], + text: ['', 'Text', ''], + mode: 'lines+text' + }]; + var scatter = null; + var oldHeight = 0; + Plotly.plot(gd, data) + .then(function() { + scatter = document.getElementsByClassName('scatter')[0]; + oldHeight = scatter.getBoundingClientRect().height; + return Plotly.relayout(gd, 'yaxis.range', [0.5, 0.5, 0.5]); + }) + .then(function() { + var newHeight = scatter.getBoundingClientRect().height; + expect(newHeight).toEqual(oldHeight); + }) + .then(done); + }); }); describe('Plotly.restyle', function() {