diff --git a/DESCRIPTION b/DESCRIPTION index 9d58779..84780f1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: sunburstR Type: Package Title: htmlwidget for Kerry Rodden d3.js sequence sunburst -Version: 0.2.1 -Date: 2016-02-04 +Version: 0.2.2 +Date: 2016-03-08 Authors@R: c( person( "Mike", "Bostock" @@ -33,4 +33,4 @@ Imports: Suggests: knitr VignetteBuilder: knitr -RoxygenNote: 4.1.1.9001 +RoxygenNote: 5.0.1 diff --git a/R/sunburst.R b/R/sunburst.R index 8d6c12f..688722e 100644 --- a/R/sunburst.R +++ b/R/sunburst.R @@ -14,7 +14,7 @@ #' @param count \code{logical} to include count and total in the explanation. #' @param explanation JavaScript function to define a custom explanation for the center #' of the sunburst. Note, this will override \code{percent} and \code{count}. -#' @param breadcrumb \code{list} to customize the breadcrumb trail. This argument +#' @param breadcrumb,legend \code{list} to customize the breadcrumb trail or legend. This argument #' should be in the form \code{list(w =, h =, s =, t = )} where #' \code{w} is the width, \code{h} is the height, \code{s} is the spacing, #' and \code{t} is the tail all in \code{px}. @@ -34,6 +34,7 @@ sunburst <- function( , count = FALSE , explanation = NULL , breadcrumb = list() + , legend = list() , width = NULL , height = NULL ) { @@ -56,6 +57,7 @@ sunburst <- function( ,count = count ,explanation = explanation ,breadcrumb = breadcrumb + ,legend = legend ) ) diff --git a/inst/htmlwidgets/lib/sequences/sequences.css b/inst/htmlwidgets/lib/sequences/sequences.css index 8b88dab..ac1f130 100644 --- a/inst/htmlwidgets/lib/sequences/sequences.css +++ b/inst/htmlwidgets/lib/sequences/sequences.css @@ -5,8 +5,7 @@ .sunburst-sidebar { position: absolute; - width: 10%; - left: 90%; + right: 10px; top: 10px; } diff --git a/inst/htmlwidgets/sunburst.js b/inst/htmlwidgets/sunburst.js index 47d1874..e607fce 100644 --- a/inst/htmlwidgets/sunburst.js +++ b/inst/htmlwidgets/sunburst.js @@ -16,7 +16,7 @@ HTMLWidgets.widget({ d3.select(el).select(".sunburst-chart svg").remove(); // Dimensions of sunburst. - var width = el.getBoundingClientRect().width; + var width = el.getBoundingClientRect().width - (x.options.legend.w ? x.options.legend.w : 75); var height = el.getBoundingClientRect().height - 70; var radius = Math.min(width, height) / 2; @@ -313,6 +313,12 @@ HTMLWidgets.widget({ w: 75, h: 30, s: 3, r: 3 }; + // if legend is provided in the option, we will overwrite + // with what is provided + Object.keys(x.options.legend).map(function(ky){ + li[ky] = x.options.legend[ky]; + }); + // remove if already drawn d3.select(el).select(".sunburst-legend svg").remove(); diff --git a/man/sunburst.Rd b/man/sunburst.Rd index e394981..7757092 100644 --- a/man/sunburst.Rd +++ b/man/sunburst.Rd @@ -6,7 +6,7 @@ \usage{ sunburst(csvdata = NULL, jsondata = NULL, legendOrder = NULL, colors = NULL, percent = TRUE, count = FALSE, explanation = NULL, - breadcrumb = list(), width = NULL, height = NULL) + breadcrumb = list(), legend = list(), width = NULL, height = NULL) } \arguments{ \item{csvdata}{data in csv source,target form} @@ -27,7 +27,7 @@ manual colors.} \item{explanation}{JavaScript function to define a custom explanation for the center of the sunburst. Note, this will override \code{percent} and \code{count}.} -\item{breadcrumb}{\code{list} to customize the breadcrumb trail. This argument +\item{breadcrumb, legend}{\code{list} to customize the breadcrumb trail or legend. This argument should be in the form \code{list(w =, h =, s =, t = )} where \code{w} is the width, \code{h} is the height, \code{s} is the spacing, and \code{t} is the tail all in \code{px}.}