Skip to content

Commit

Permalink
Merge branch 'eliztang-dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mattflor committed Jul 11, 2016
2 parents eb320e4 + 81f701a commit bf2748c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions R/chorddiag.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 +207,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion man/chorddiag.Rd

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

4 changes: 2 additions & 2 deletions vignettes/chorddiagram-vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ First, we create a contingency table of how many passengers from the different c

```{r, fig.width = 8, warning = FALSE, message = FALSE}
library(dplyr)
titanic_tbl <- dplyr::tbl_dt(Titanic)
titanic_tbl <- dplyr::tbl_df(Titanic)
titanic_tbl <- titanic_tbl %>%
mutate_each(funs(factor), Class:Survived)
by_class_survival <- titanic_tbl %>%
group_by(Class, Survived) %>%
summarize(Count = sum(N))
summarize(Count = sum(n))
titanic.mat <- matrix(by_class_survival$Count, nrow = 4, ncol = 2)
dimnames(titanic.mat ) <- list(Class = levels(titanic_tbl$Class),
Survival = levels(titanic_tbl$Survived))
Expand Down

0 comments on commit bf2748c

Please sign in to comment.