-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
13,081 additions
and
9,932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#' Chord Visualization | ||
#' | ||
#' Chord diagram. | ||
#' | ||
#' @param data data set in data.frame. | ||
#' @param matrix a matrix used to compute the chord diagram. | ||
#' @param keys keys used to identify each cell in the matrix. | ||
#' @param render "svg" (responsive) or "canvas". "canvas" is well suited for | ||
#' large data sets as it does not impact DOM tree depth, however you'll lose the | ||
#' isomorphic rendering ability. | ||
#' @param ... additional arguments. | ||
#' @param width,height Must be a valid CSS unit (like \code{'100\%'}, | ||
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a | ||
#' string and have \code{'px'} appended. | ||
#' @param element_id element id of widgets. | ||
#' | ||
#' @import htmlwidgets | ||
#' @return a nivo Chord component | ||
#' @export | ||
#' @seealso \href{https://nivo.rocks/chord/}{Additional arguments} | ||
#' | ||
#' @examples | ||
#' library(nivor) | ||
#' | ||
#' # generate data | ||
#' set.seed(1) | ||
#' data <- matrix(round(rexp(25) * 100, 0), 5, 5) | ||
#' | ||
#' # the simplest use | ||
#' n_chord( | ||
#' matrix = data, | ||
#' keys = c("A", "B", "C", "D", "E") | ||
#' ) | ||
n_chord <- function( | ||
matrix, | ||
keys, | ||
render = c("svg", "canvas"), | ||
..., | ||
width = NULL, | ||
height = NULL, | ||
element_id = NULL) { | ||
render <- match.arg(render, c("svg", "canvas")) | ||
|
||
if (missing(matrix)) { | ||
stop("matrix should be passed in.") | ||
} | ||
if (!(is.matrix(matrix) || is.data.frame(matrix))) { | ||
stop("matrix only accepte a matrix or data.frame.") | ||
} | ||
if (nrow(matrix) != ncol(matrix)) { | ||
stop("row and column are not equal in matrix.") | ||
} | ||
if (nrow(matrix) != length(keys)) { | ||
stop("keys and dimension of matrix are not equal.") | ||
} | ||
|
||
# describe a React component to send to the browser for rendering. | ||
component <- reactR::reactMarkup( | ||
htmltools::tag( | ||
ifelse( | ||
render == "canvas", | ||
"ResponsiveChordCanvas", | ||
"ResponsiveChord" | ||
), | ||
list( | ||
matrix = unname(as.list(as.data.frame(matrix))), | ||
keys = keys, | ||
# assume extra arguments are props | ||
... | ||
) | ||
) | ||
) | ||
|
||
# create widget | ||
htmlwidgets::createWidget( | ||
name = "calendar", # TODO it's a bug, should be rename to nivo | ||
component, | ||
width = width, | ||
height = height, | ||
package = "nivor", | ||
elementId = element_id | ||
) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe("n_chord()", { | ||
it("matrix is not matrix", { | ||
data <- 1 | ||
expected <- "matrix only accepte a matrix or data.frame." | ||
expect_error(n_chord(data), expected) | ||
}) | ||
|
||
it("matrix dimension are not equal", { | ||
data <- matrix(round(rexp(20) * 100, 0), 5, 4) | ||
expected <- "row and column are not equal in matrix." | ||
expect_error(n_chord(data), expected) | ||
}) | ||
|
||
it("matrix dimension and keys are not equal", { | ||
data <- matrix(round(rexp(25) * 100, 0), 5, 5) | ||
keys <- "a" | ||
expected <- "keys and dimension of matrix are not equal." | ||
expect_error(n_chord(data, keys), expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -946,6 +946,19 @@ | |
lodash.memoize "^4.1.2" | ||
lodash.range "^3.2.0" | ||
|
||
"@nivo/chord@^0.67.0": | ||
version "0.67.0" | ||
resolved "https://registry.yarnpkg.com/@nivo/chord/-/chord-0.67.0.tgz#7b856a4373c7b31411d8fa8b4e7089a0cd67ccad" | ||
integrity sha512-V6F5D7Ihfc6hxjndvJnjQtoyuoM2od3Hv3DRs/UzJi2TIQfVdrvROC1qQzl79MM83ojA76UPsviV9Y/ssgnKRw== | ||
dependencies: | ||
"@nivo/colors" "0.67.0" | ||
"@nivo/legends" "0.67.0" | ||
"@nivo/tooltip" "0.67.0" | ||
d3-chord "^1.0.6" | ||
d3-shape "^1.3.5" | ||
lodash "^4.17.11" | ||
react-motion "^0.5.2" | ||
|
||
"@nivo/[email protected]": | ||
version "0.67.0" | ||
resolved "https://registry.yarnpkg.com/@nivo/colors/-/colors-0.67.0.tgz#5a2adc4b55406466efb8bbafecc08249e4e94e69" | ||
|
@@ -2169,13 +2182,26 @@ cyclist@^1.0.1: | |
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz" | ||
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk= | ||
|
||
d3-array@1: | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-1.2.4.tgz#635ce4d5eea759f6f605863dbcfc30edc737f71f" | ||
integrity sha512-KHW6M86R+FUPYGb3R5XiYjXPq7VzwxZ22buHhAEVG5ztoEcZZMLov530mmccaqA1GghZArjQV46fuc8kUqhhHw== | ||
|
||
d3-array@^2.3.0: | ||
version "2.11.0" | ||
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.11.0.tgz" | ||
integrity sha512-26clcwmHQEdsLv34oNKq5Ia9tQ26Y/4HqS3dQzF42QBUqymZJ+9PORcN1G52bt37NsL2ABoX4lvyYZc+A9Y0zw== | ||
dependencies: | ||
internmap "^1.0.0" | ||
|
||
d3-chord@^1.0.6: | ||
version "1.0.6" | ||
resolved "https://registry.yarnpkg.com/d3-chord/-/d3-chord-1.0.6.tgz#309157e3f2db2c752f0280fedd35f2067ccbb15f" | ||
integrity sha512-JXA2Dro1Fxw9rJe33Uv+Ckr5IrAa74TlfDEhE/jfLOaXegMQFQTAgAw9WnZL8+HxVBRXaRGCkrNU7pJeylRIuA== | ||
dependencies: | ||
d3-array "1" | ||
d3-path "1" | ||
|
||
"d3-color@1 - 2", d3-color@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-2.0.0.tgz" | ||
|