From 0796e10cae8be805e0f7e56fc865b9782885d98d Mon Sep 17 00:00:00 2001
From: William Cheung <indreamhk@gmail.com>
Date: Fri, 27 Jan 2017 02:18:54 +0800
Subject: [PATCH] Fix #1328 skip translatePoint for empty nodes

---
 src/components/drawing/index.js     |  2 +-
 test/jasmine/tests/plot_api_test.js | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

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() {