Skip to content

Commit

Permalink
send a subset of th data.points object
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Dec 8, 2015
1 parent d0b6118 commit d180812
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions inst/htmlwidgets/plotly.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,34 @@ HTMLWidgets.widget({
}

var g = x.data[0].set;
console.log(g);
var grp = crosstalk.group(g);

$('#'+el.id).on('plotly_click', function(event, data) {
// extract only the data we may want to access in R
var d = data.points.map(function(pt) {
var obj = {
curveNumber: pt.curveNumber,
pointNumber: pt.pointNumber,
x: pt.x,
y: pt.y
};
if (pt.data.hasOwnProperty("key")) {
if (typeof pt.pointNumber === "number") {
obj.key = pt.data.key[pt.pointNumber];
} else {
obj.key = pt.data.key[pt.pointNumber[0]][pt.pointNumber[1]];
} // TODO: can pointNumber be 3D?
}
return obj;
});

// tell crosstalk about click data so we can access it in R (and JS)
grp.var("plotly_click").set(data.points);
grp.var("plotly_click").set(d);
// TODO: provide visual clue that we've selected point(s)
// (it's possible this will be handled natively in plotlyjs)
// (it's possible this will be handled natively in plotlyjs...)
});

grp.var("plotly_click").on('change', function(e) {
grp.var('plotly_click').on('change', function(e) {
console.log(e.value);
// TODO: if e.value.x != e.oldValue.x, then newPlot? Otherwise, restyle?
});
Expand Down

0 comments on commit d180812

Please sign in to comment.