A Key
interaction allows the user to trigger an event when their mouse cursor is inside of a Component
and a specified key is pressed.
var data = [];
for (var i = 0; i < 250; i++) { data.push({"x": i, "y": Math.random()}); }
var plot = new Plottable.Plots.Scatter()
.addDataset(new Plottable.Dataset(data))
.x(function(d) { return d.x; }, new Plottable.Scales.Linear())
.y(function(d) { return d.y; }, new Plottable.Scales.Linear())
.renderTo("svg#example");
var interaction = new Plottable.Interactions.Key();
var timeout;
for (var i = 48; i < 90; i++) {
interaction.onKeyPress(i, function(keyCode) {
if (timeout != null) {
clearTimeout(timeout);
}
$("#key-feedback").html(String.fromCharCode(keyCode)).fadeIn(100);
timeout = setTimeout(function() {
$("#key-feedback").fadeOut(800);
}, 1400);
});
}
interaction.attachTo(plot);
.onKeyPress(keyCode, callback)
Adds a callback to be called when the key with the given keyCode is pressed and the user is moused over the Component.
.offKeyPress(keyCode, callback)
Removes a callback to be called when the key with the given keyCode is pressed and the user is moused over the Component.