From 2d97d123d02ad3a880e7fee465b1ecc11eb6e61d Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Sun, 12 Jun 2022 20:48:19 -0500 Subject: [PATCH] patch to allow root label specification with `csv_to_hier` #114 and let `rootLabel` argument work again with `sund2b()` --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ R/converters.R | 4 ++-- inst/htmlwidgets/sund2b.js | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 653b560..41f527f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: sunburstR Type: Package Title: Sunburst 'Htmlwidget' -Version: 2.1.6 -Date: 2021-09-19 +Version: 2.1.7 +Date: 2022-06-12 Authors@R: c( person( "Mike", "Bostock" diff --git a/NEWS.md b/NEWS.md index d8d25d8..79591ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# sunburstR 2.1.7 + +* allow specification of root label in internal `csv_to_hier` converter function +* fix bug where `rootLabel` argument for `sund2b` was not working ; (see [issue 114](https://github.com/timelyportfolio/sunburstR/issues/114)) + # sunburstR 2.1.6 * add labels for slices based on https://bl.ocks.org/vasturiano/12da9071095fbd4df434e60d52d2d58d diff --git a/R/converters.R b/R/converters.R index 63339fe..4670358 100644 --- a/R/converters.R +++ b/R/converters.R @@ -1,5 +1,5 @@ #' @keywords internal -csv_to_hier <- function(csv, delim = "-") { +csv_to_hier <- function(csv, delim = "-", rootLabel = "root") { hier_col <- strsplit(as.character(csv[[1]]), delim) # determine max length of all the paths to build column names # issue 107 @@ -21,5 +21,5 @@ csv_to_hier <- function(csv, delim = "-") { df <- df[,-1] } df$size = csv[[2]] - d3r::d3_nest(df, value_cols = "size") + d3r::d3_nest(df, value_cols = "size", root = rootLabel) } diff --git a/inst/htmlwidgets/sund2b.js b/inst/htmlwidgets/sund2b.js index 67b2544..ee3784e 100644 --- a/inst/htmlwidgets/sund2b.js +++ b/inst/htmlwidgets/sund2b.js @@ -74,7 +74,7 @@ HTMLWidgets.widget({ } if(x.options.hasOwnProperty("rootLabel") && x.options.rootLabel !== null) { - x.data.root.label = x.options.rootLabel; + x.data.root.name = x.options.rootLabel; } d3.select(el).datum(x.data)