Skip to content

Commit

Permalink
Added documentation for the new clickAction argument.
Browse files Browse the repository at this point in the history
Merge branch 'dev'

# Conflicts:
#	DESCRIPTION
  • Loading branch information
mattflor committed Jul 20, 2016
2 parents ea5171c + b6b06ed commit 6722fa1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
7 changes: 5 additions & 2 deletions R/chorddiag.R
Expand Up @@ -65,6 +65,7 @@
#' triangle pointing from source to target.
#' @param precision Integer number of significant digits to be used for tooltip
#' display.
#' @param clickAction character string containing JavaScript code to be executed on a mouse click so that shiny can get the sourceIndex and targetIndex for the purpose of filtering the data on other visualizations
#'
#' @source Based on \url{http://bl.ocks.org/mbostock/4062006} with several
#' modifications.
Expand Down Expand Up @@ -105,7 +106,8 @@ chorddiag <- function(data,
tooltipUnit = NULL,
tooltipFontsize = 12,
tooltipGroupConnector = " &#x25B6; ",
precision = NULL) {
precision = NULL,
clickAction = NULL) {

if (!is.matrix(data))
stop("'data' must be a matrix class object.")
Expand Down Expand Up @@ -206,7 +208,8 @@ chorddiag <- function(data,
tooltipFontsize = tooltipFontsize,
tooltipUnit = tooltipUnit,
tooltipGroupConnector = tooltipGroupConnector,
precision = precision))
precision = precision,
clickAction = clickAction))
params = Filter(Negate(is.null), params)

# create widget
Expand Down
8 changes: 7 additions & 1 deletion inst/examples/shiny/server.R
Expand Up @@ -19,6 +19,12 @@ shinyServer(function(input, output) {
groupColors = groupColors,
groupnamePadding = input$groupnamePadding,
showTicks = input$showTicks,
margin = input$margin)
margin = input$margin,
clickAction = "Shiny.onInputChange('sourceIndex', d.source.index+1);
Shiny.onInputChange('targetIndex', d.target.index+1);")
)

output$shiny_return <- renderPrint({
paste0(groupNames[input$sourceIndex], " <-> ", groupNames[input$targetIndex])
})
})
3 changes: 2 additions & 1 deletion inst/examples/shiny/ui.R
Expand Up @@ -12,7 +12,8 @@ shinyUI(fluidPage(
),

mainPanel(
chorddiagOutput('chorddiag', height = '600px')
chorddiagOutput('chorddiag', height = '600px'),
verbatimTextOutput("shiny_return")
)
)
))
7 changes: 6 additions & 1 deletion inst/htmlwidgets/chorddiag.js
Expand Up @@ -217,7 +217,8 @@ HTMLWidgets.widget({
.on("mouseout", function(d) {
if (showTooltips) chordTip.hide(d);
return chordFade(d, 1);
});
})
.on("click", click);

// create group labels
if (showGroupnames) {
Expand Down Expand Up @@ -338,6 +339,10 @@ HTMLWidgets.widget({
var mult = Math.pow(10, sig - Math.floor(Math.log(n) / Math.LN10) - 1);
return Math.round(n * mult) / mult;
}

function click(d) {
return eval(options.clickAction);
}

} // end renderValue function

Expand Down
4 changes: 3 additions & 1 deletion man/chorddiag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6722fa1

Please sign in to comment.