Skip to content

Commit

Permalink
Fix some simple issues from pull request feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Mar 19, 2015
1 parent 30f9291 commit 6028263
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 46 deletions.
10 changes: 5 additions & 5 deletions R/bootstrap.R
Expand Up @@ -1741,7 +1741,7 @@ verbatimTextOutput <- function(outputId) {
#' position. To control the hover time or hover delay type, you must use
#' \code{\link{hoverOpts}}.
#' @param clickId Deprecated; use \code{click} instead. Also see the
#' \code{\link{hoverOpts}} function.
#' \code{\link{clickOpts}} function.
#' @param hoverId Deprecated; use \code{hover} instead. Also see the
#' \code{\link{hoverOpts}} function.
#' @param hoverDelay Deprecated; use \code{hover} instead. Also see the
Expand Down Expand Up @@ -1804,7 +1804,7 @@ verbatimTextOutput <- function(outputId) {
#' plotOutput("plot", height=300,
#' click = "plot_click", # Equiv, to click=clickOpts(id="plot_click")
#' hover = hoverOpts(id = "plot_hover", delayType = "throttle"),
#' brush = brushOpts(id = "plot_brush", color = "red")
#' brush = brushOpts(id = "plot_brush", fill = "red")
#' )
#' ),
#' column(width = 3,
Expand Down Expand Up @@ -1853,7 +1853,7 @@ verbatimTextOutput <- function(outputId) {
#' delay = 500,
#' delayType = "throttle"
#' ),
#' brush = brushOpts(id = "image_brush", color = "red")
#' brush = brushOpts(id = "image_brush", fill = "red")
#' )
#' ),
#' column(width = 3,
Expand Down Expand Up @@ -2001,8 +2001,8 @@ imageOutput <- function(outputId, width = "100%", height="400px",
args <- c(args, list(
`data-brush-id` = brush$id,
`data-brush-clip` = brush$clip,
`data-brush-color` = brush$color,
`data-brush-outline` = brush$outline,
`data-brush-fill` = brush$fill,
`data-brush-stroke` = brush$stroke,
`data-brush-opacity` = brush$opacity,
`data-brush-delay` = brush$delay,
`data-brush-delay-type` = brush$delayType,
Expand Down
27 changes: 16 additions & 11 deletions R/image-interact-opts.R
Expand Up @@ -27,7 +27,12 @@ clickOpts <- function(id = NULL, clip = TRUE) {
#' the \code{dblclick} argument of \code{\link{imageOutput}} or
#' \code{\link{plotOutput}}.
#'
#' @inheritParams clickOpts
#' @param id Input value name. For example, if the value is
#' \code{"plot_dblclick"}, then the click coordinates will be available as
#' \code{input$plot_dblclick}.
#' @param clip Should the click area be clipped to the plotting area? If FALSE,
#' then the server will receive double-click events even when the mouse is
#' outside the plotting area, as long as it is still inside the image.
#' @param delay Maximum delay (in ms) between a pair clicks for them to be
#' counted as a double-click.
#' @export
Expand Down Expand Up @@ -62,7 +67,7 @@ dblclickOpts <- function(id = NULL, clip = TRUE, delay = 400) {
#' the plotting area, as long as it is still inside the image.
#' @export
hoverOpts <- function(id = NULL, delay = 300,
delayType = c("debounce", "throttle"), clip = TRUE) {
delayType = c("debounce", "throttle"), clip = TRUE) {
if (is.null(id))
stop("id must not be NULL")

Expand All @@ -82,8 +87,8 @@ hoverOpts <- function(id = NULL, delay = 300,
#'
#' @param id Input value name. For example, if the value is \code{"plot_brush"},
#' then the coordinates will be available as \code{input$plot_brush}.
#' @param color Fill color of the brush.
#' @param outline Outline color of the brush.
#' @param fill Fill color of the brush.
#' @param stroke Outline color of the brush.
#' @param opacity Opacity of the brush
#' @param delay How long to delay (in milliseconds) when debouncing or
#' throttling, before sending the brush data to the server.
Expand All @@ -104,18 +109,18 @@ hoverOpts <- function(id = NULL, delay = 300,
#' brush. Using \code{TRUE} is useful if you want to clear the brush whenever
#' the plot is updated.
#' @export
brushOpts <- function(id = NULL, color = "#666", outline = "#000",
opacity = 0.3, delay = 300,
delayType = c("debounce", "throttle"), clip = TRUE,
direction = c("xy", "x", "y"),
resetOnNew = FALSE) {
brushOpts <- function(id = NULL, fill = "#666", stroke = "#000",
opacity = 0.3, delay = 300,
delayType = c("debounce", "throttle"), clip = TRUE,
direction = c("xy", "x", "y"),
resetOnNew = FALSE) {
if (is.null(id))
stop("id must not be NULL")

list(
id = id,
color = color,
outline = outline,
fill = fill,
stroke = stroke,
opacity = opacity,
delay = delay,
delayType = match.arg(delayType),
Expand Down
44 changes: 24 additions & 20 deletions inst/www/shared/shiny.js
Expand Up @@ -67,6 +67,20 @@
return Math.floor(0x100000000 + (Math.random() * 0xF00000000)).toString(16);
}

function strToBool(str) {
if (!str || !str.toLowerCase)
return undefined;

switch(str.toLowerCase()) {
case 'true':
return true;
case 'false':
return false;
default:
return undefined;
}
}

// A wrapper for getComputedStyle that is compatible with older browsers.
// This is significantly faster than jQuery's .css() function.
function getStyle(el, styleProp) {
Expand Down Expand Up @@ -1293,15 +1307,6 @@
return;
}

function strToBool(str) {
if (str.toLowerCase() === 'true')
return true;
else if (str.toLowerCase() === 'false')
return false;
else
return undefined;
}

var opts = {
clickId: $el.data('click-id'),
clickClip: strToBool($el.data('click-clip')) || true,
Expand All @@ -1319,8 +1324,8 @@
brushClip: strToBool($el.data('brush-clip')) || true,
brushDelayType: $el.data('brush-delay-type') || 'debounce',
brushDelay: $el.data('brush-delay') || 300,
brushColor: $el.data('brush-color') || '#666',
brushOutline: $el.data('brush-outline') || '#000',
brushFill: $el.data('brush-fill') || '#666',
brushStroke: $el.data('brush-stroke') || '#000',
brushOpacity: $el.data('brush-opacity') || 0.3,
brushDirection: $el.data('brush-direction') || 'xy',
brushResetOnNew: strToBool($el.data('brush-reset-on-new')) || false,
Expand Down Expand Up @@ -1504,7 +1509,7 @@
}

// Returns a brush handler object. This has three public functions:
// mousedown, mousemove, and mouseup.
// mousedown, mousemove, and onRemoveImg.
function createBrushHandler(inputId) {

// Object that encapsulates brush state
Expand Down Expand Up @@ -1628,13 +1633,13 @@
this.$div = $(document.createElement('div'))
.attr('id', el.id + '_brush')
.css({
'background-color': opts.brushColor,
'background-color': opts.brushFill,
'opacity': opts.brushOpacity,
'pointer-events': 'none',
'position': 'absolute'
});

var borderStyle = '1px solid ' + opts.brushOutline;
var borderStyle = '1px solid ' + opts.brushStroke;
if (opts.brushDirection === 'xy') {
this.$div.css({
'border': borderStyle
Expand Down Expand Up @@ -1818,8 +1823,7 @@
xmin: Math.min(min.x, max.x),
xmax: Math.max(min.x, max.x),
ymin: Math.min(min.y, max.y),
ymax: Math.max(min.y, max.y),
'.nonce': Math.random()
ymax: Math.max(min.y, max.y)
};

// Send data to server
Expand Down Expand Up @@ -1982,7 +1986,7 @@
};
var e2;

// If no dblclick listener, immediately trigger a click2 event.
// If no dblclick listener, immediately trigger a mousedown2 event.
if (!opts.dblclickId) {
e2 = $.Event('mousedown2', eInfo);
$el.trigger(e2);
Expand All @@ -1996,8 +2000,8 @@
if (clickCount === 1) {
clickTimer = setTimeout(function() {
e2 = $.Event('mousedown2', eInfo);
$el.trigger(e2);
clickCount = 0;
$el.trigger(e2);

}, opts.dblclickDelay);

Expand All @@ -2007,15 +2011,15 @@
clearTimeout(clickTimer);
e2 = $.Event('dblclick2', eInfo);

$el.trigger(e2);
clickCount = 0;
$el.trigger(e2);
}
});

// IE8 needs a special hack because when you do a double-click it doesn't
// trigger the click event twice - it directly triggers dblclick.
if (browser.isIE && browser.IEVersion === 8) {
$el.on('dblclick', function(e) {
$el.on('dblclick.image_output', function(e) {
var e2 = $.Event('dblclick2', {
which: 1, // In IE8, e.which is 0 instead of 1. ???
pageX: e.pageX,
Expand Down
6 changes: 3 additions & 3 deletions man/brushOpts.Rd
Expand Up @@ -4,17 +4,17 @@
\alias{brushOpts}
\title{Create an object representing brushing options}
\usage{
brushOpts(id = NULL, color = "#666", outline = "#000", opacity = 0.3,
brushOpts(id = NULL, fill = "#666", stroke = "#000", opacity = 0.3,
delay = 300, delayType = c("debounce", "throttle"), clip = TRUE,
direction = c("xy", "x", "y"), resetOnNew = FALSE)
}
\arguments{
\item{id}{Input value name. For example, if the value is \code{"plot_brush"},
then the coordinates will be available as \code{input$plot_brush}.}

\item{color}{Fill color of the brush.}
\item{fill}{Fill color of the brush.}

\item{outline}{Outline color of the brush.}
\item{stroke}{Outline color of the brush.}

\item{opacity}{Opacity of the brush}

Expand Down
9 changes: 5 additions & 4 deletions man/dblclickOpts.Rd
Expand Up @@ -7,12 +7,13 @@
dblclickOpts(id = NULL, clip = TRUE, delay = 400)
}
\arguments{
\item{id}{Input value name. For example, if the value is \code{"plot_click"},
then the click coordinates will be available as \code{input$plot_click}.}
\item{id}{Input value name. For example, if the value is
\code{"plot_dblclick"}, then the click coordinates will be available as
\code{input$plot_dblclick}.}

\item{clip}{Should the click area be clipped to the plotting area? If FALSE,
then the server will receive click events even when the mouse is outside
the plotting area, as long as it is still inside the image.}
then the server will receive double-click events even when the mouse is
outside the plotting area, as long as it is still inside the image.}

\item{delay}{Maximum delay (in ms) between a pair clicks for them to be
counted as a double-click.}
Expand Down
6 changes: 3 additions & 3 deletions man/imageOutput.Rd
Expand Up @@ -66,7 +66,7 @@ value will be a named list with \code{xmin}, \code{xmax}, \code{ymin}, and
behavior, use \code{\link{brushOpts}}.}

\item{clickId}{Deprecated; use \code{click} instead. Also see the
\code{\link{hoverOpts}} function.}
\code{\link{clickOpts}} function.}

\item{hoverId}{Deprecated; use \code{hover} instead. Also see the
\code{\link{hoverOpts}} function.}
Expand Down Expand Up @@ -137,7 +137,7 @@ shinyApp(
plotOutput("plot", height=300,
click = "plot_click", # Equiv, to click=clickOpts(id="plot_click")
hover = hoverOpts(id = "plot_hover", delayType = "throttle"),
brush = brushOpts(id = "plot_brush", color = "red")
brush = brushOpts(id = "plot_brush", fill = "red")
)
),
column(width = 3,
Expand Down Expand Up @@ -186,7 +186,7 @@ shinyApp(
delay = 500,
delayType = "throttle"
),
brush = brushOpts(id = "image_brush", color = "red")
brush = brushOpts(id = "image_brush", fill = "red")
)
),
column(width = 3,
Expand Down

0 comments on commit 6028263

Please sign in to comment.