Skip to content

Commit 29dd170

Browse files
committed
don't try to attach key to relayout event data; fixes #1039
also, make use of HTMLWidgets.shinyMode and remove old code
1 parent 1a89ab8 commit 29dd170

File tree

1 file changed

+3
-72
lines changed

1 file changed

+3
-72
lines changed

inst/htmlwidgets/plotly.js

+3-72
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ HTMLWidgets.widget({
2424

2525
renderValue: function(el, x, instance) {
2626

27-
var shinyMode;
2827
if (typeof(window) !== "undefined") {
29-
// make sure plots don't get created outside the network
28+
// make sure plots don't get created outside the network (for on-prem)
3029
window.PLOTLYENV = window.PLOTLYENV || {};
3130
window.PLOTLYENV.BASE_URL = x.base_url;
32-
shinyMode = !!window.Shiny;
3331
}
3432

3533
var graphDiv = document.getElementById(el.id);
@@ -209,12 +207,12 @@ HTMLWidgets.widget({
209207
}
210208

211209
// send user input event data to shiny
212-
if (shinyMode) {
210+
if (HTMLWidgets.shinyMode) {
213211
// https://plot.ly/javascript/zoom-events/
214212
graphDiv.on('plotly_relayout', function(d) {
215213
Shiny.onInputChange(
216214
".clientValue-plotly_relayout-" + x.source,
217-
JSON.stringify(eventDataWithKey(d))
215+
JSON.stringify(d)
218216
);
219217
});
220218
graphDiv.on('plotly_hover', function(d) {
@@ -805,70 +803,3 @@ function removeBrush(el) {
805803
outlines[i].remove();
806804
}
807805
}
808-
809-
/* Currently not used
810-
811-
// Given an array of strings, return an object that hierarchically
812-
// represents the corresponding curves/points.
813-
//
814-
// For example, the following data:
815-
//
816-
// [
817-
// {curveNumber: 0, pointNumber: 1},
818-
// {curveNumber: 0, pointNumber: 2},
819-
// {curveNumber: 2, pointNumber: 1}
820-
// ]
821-
//
822-
// would be returned as:
823-
// {
824-
// "0": [1, 2],
825-
// "2": [1]
826-
// }
827-
828-
// # Begin Crosstalk support
829-
830-
// ## Crosstalk point/key translation functions
831-
//
832-
// Plotly.js uses curveNumber/pointNumber addressing to refer
833-
// to data points (i.e. when plotly_selected is received). We
834-
// prefer to let the R user use key-based addressing, where
835-
// a string is used that uniquely identifies a data point (we
836-
// can also use row numbers in a pinch).
837-
//
838-
// The pointsToKeys and keysToPoints functions let you convert
839-
// between the two schemes.
840-
841-
// Combine the name of a set and key into a single string, suitable for
842-
// using as a keyCache key.
843-
function joinSetAndKey(set, key) {
844-
return set + "\n" + key;
845-
}
846-
847-
// To allow translation from sets+keys to points in O(1) time, we
848-
// make a cache that lets us map keys to objects with
849-
// {curveNumber, pointNumber} properties.
850-
var keyCache = {};
851-
for (var i = 0; i < x.data.length; i++) {
852-
var trace = x.data[i];
853-
if (!trace.key || !trace.set) {
854-
continue;
855-
}
856-
for (var j = 0; j < trace.key.length; j++) {
857-
var nm = joinSetAndKey(trace.set, trace.key[j]);
858-
keyCache[nm] = {curveNumber: i, pointNumber: j};
859-
}
860-
}
861-
862-
function keysToPoints(set, keys) {
863-
var curves = {};
864-
for (var i = 0; i < keys.length; i++) {
865-
var pt = keyCache[joinSetAndKey(set, keys[i])];
866-
if (!pt) {
867-
throw new Error("Unknown key " + keys[i]);
868-
}
869-
curves[pt.curveNumber] = curves[pt.curveNumber] || [];
870-
curves[pt.curveNumber].push(pt.pointNumber);
871-
}
872-
return curves;
873-
}
874-
*/

0 commit comments

Comments
 (0)