From 8bc36b949b162873fb15335475d49cfa1f7150ca Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 3 Sep 2019 10:45:53 -0500 Subject: [PATCH 1/4] Improvements to algorithm for attaching key attribute for shiny's event data, fixes #1610 * Account for pointNumbers * Do nothing if we don't recognize the case --- inst/htmlwidgets/plotly.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index 7deca6f8d1..4c958072a2 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -263,10 +263,13 @@ HTMLWidgets.widget({ for (var i = 0; i < attrsToAttach.length; i++) { var attr = trace[attrsToAttach[i]]; if (Array.isArray(attr)) { - // pointNumber can be an array (e.g., heatmaps) - // TODO: can pointNumber be 3D? - obj[attrsToAttach[i]] = typeof pt.pointNumber === "number" ? - attr[pt.pointNumber] : attr[pt.pointNumber[0]][pt.pointNumber[1]]; + var ptNums = pt.pointNumber || pt.pointNumbers; + if (typeof ptNums === "number") { + ptNums = [ptNums]; + } + if (Array.isArray(ptNums)) { + obj[attrsToAttach[i]] = ptNums.map(function(i) { return attr[i]; }); + } } } return obj; From 8056cc562fb0a3e46282f23ae512f3c2a3489930 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 3 Sep 2019 14:49:24 -0500 Subject: [PATCH 2/4] When pointNumber is a constant, relay it as such --- inst/htmlwidgets/plotly.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index 4c958072a2..169519c15c 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -265,9 +265,8 @@ HTMLWidgets.widget({ if (Array.isArray(attr)) { var ptNums = pt.pointNumber || pt.pointNumbers; if (typeof ptNums === "number") { - ptNums = [ptNums]; - } - if (Array.isArray(ptNums)) { + obj[attrsToAttach[i]] = ptNums; + } else if (Array.isArray(ptNums)) { obj[attrsToAttach[i]] = ptNums.map(function(i) { return attr[i]; }); } } From 81caeeb004f3e2a8b4db0e83651b703cf018dcd5 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 3 Sep 2019 15:38:06 -0500 Subject: [PATCH 3/4] handle the 3 cases separately --- inst/htmlwidgets/plotly.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index 169519c15c..e02716e118 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -263,11 +263,12 @@ HTMLWidgets.widget({ for (var i = 0; i < attrsToAttach.length; i++) { var attr = trace[attrsToAttach[i]]; if (Array.isArray(attr)) { - var ptNums = pt.pointNumber || pt.pointNumbers; - if (typeof ptNums === "number") { - obj[attrsToAttach[i]] = ptNums; - } else if (Array.isArray(ptNums)) { - obj[attrsToAttach[i]] = ptNums.map(function(i) { return attr[i]; }); + if (typeof pt.pointNumber === "number") { + obj[attrsToAttach[i]] = attr[pt.pointNumber]; + } else if (Array.isArray(pt.pointNumber)) { + obj[attrsToAttach[i]] = attr[pt.pointNumber[0]][pt.pointNumber[1]]; + } else if (Array.isArray(pt.pointNumbers)) { + obj[attrsToAttach[i]] = pt.pointNumbers.map(function(i) { return attr[i]; }); } } } From 30e39972eb13b436121952d44d8bedce214bf9b7 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 3 Sep 2019 16:13:41 -0500 Subject: [PATCH 4/4] use idx instead of i --- inst/htmlwidgets/plotly.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/htmlwidgets/plotly.js b/inst/htmlwidgets/plotly.js index e02716e118..d1efe9c264 100644 --- a/inst/htmlwidgets/plotly.js +++ b/inst/htmlwidgets/plotly.js @@ -268,7 +268,7 @@ HTMLWidgets.widget({ } else if (Array.isArray(pt.pointNumber)) { obj[attrsToAttach[i]] = attr[pt.pointNumber[0]][pt.pointNumber[1]]; } else if (Array.isArray(pt.pointNumbers)) { - obj[attrsToAttach[i]] = pt.pointNumbers.map(function(i) { return attr[i]; }); + obj[attrsToAttach[i]] = pt.pointNumbers.map(function(idx) { return attr[idx]; }); } } }