From eb320e4e8f1584e02e667345fbe8c6782f4da435 Mon Sep 17 00:00:00 2001 From: Matt Flor Date: Sun, 24 Apr 2016 19:31:58 +0200 Subject: [PATCH 1/5] Created dev branch. --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4c1c464..74023db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: chorddiag Title: Interactive Chord Diagrams -Version: 0.0.1 +Version: 0.0.1.9000 Authors@R: person("Matthias", "Flor", email = "matthias.c.flor@gmail.com", role = c("aut", "cre")) Description: Interactive Chord Diagrams via the D3 JavaScript library Based on http://bl.ocks.org/mbostock/4062006 with some modifications From 5b3941a4f7a574224d9198257c05e3e8f1c072eb Mon Sep 17 00:00:00 2001 From: eliztang Date: Fri, 8 Jul 2016 14:28:40 +0800 Subject: [PATCH 2/5] Added clickAction --- inst/htmlwidgets/chorddiag.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/inst/htmlwidgets/chorddiag.js b/inst/htmlwidgets/chorddiag.js index 811c7a2..136c7d3 100644 --- a/inst/htmlwidgets/chorddiag.js +++ b/inst/htmlwidgets/chorddiag.js @@ -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) { @@ -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 From 46dd89a2034378c66f1c7e23c18dae143129a4c2 Mon Sep 17 00:00:00 2001 From: eliztang Date: Fri, 8 Jul 2016 14:47:33 +0800 Subject: [PATCH 3/5] to demonstrate clickAction to demonstrate getting source and target index from clickAction --- inst/examples/shiny/ui.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/examples/shiny/ui.R b/inst/examples/shiny/ui.R index bd742a2..5b24e7f 100644 --- a/inst/examples/shiny/ui.R +++ b/inst/examples/shiny/ui.R @@ -12,7 +12,8 @@ shinyUI(fluidPage( ), mainPanel( - chorddiagOutput('chorddiag', height = '600px') + chorddiagOutput('chorddiag', height = '600px'), + verbatimTextOutput("shiny_return") ) ) )) From ad22e4c9f64934e7f7b2aa7e559eeca36304fbd1 Mon Sep 17 00:00:00 2001 From: eliztang Date: Fri, 8 Jul 2016 14:51:58 +0800 Subject: [PATCH 4/5] to demonstrate clickAction to demonstrate getting source and target index from clickAction --- inst/examples/shiny/server.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inst/examples/shiny/server.R b/inst/examples/shiny/server.R index 7c22112..d61ba4e 100644 --- a/inst/examples/shiny/server.R +++ b/inst/examples/shiny/server.R @@ -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]) + }) }) From 81f701a39c8ae0ae438b82e3c9c9aa5fe3bfd6e8 Mon Sep 17 00:00:00 2001 From: eliztang Date: Fri, 8 Jul 2016 15:21:08 +0800 Subject: [PATCH 5/5] added clickAction --- R/chorddiag.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/chorddiag.R b/R/chorddiag.R index a1da5ec..ef64787 100644 --- a/R/chorddiag.R +++ b/R/chorddiag.R @@ -105,7 +105,8 @@ chorddiag <- function(data, tooltipUnit = NULL, tooltipFontsize = 12, tooltipGroupConnector = " ▶ ", - precision = NULL) { + precision = NULL, + clickAction = NULL) { if (!is.matrix(data)) stop("'data' must be a matrix class object.") @@ -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