Skip to content

Commit

Permalink
provide mechanism to customize legend sizing; thx @jrangeles #9
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Mar 8, 2016
1 parent b75017b commit 53fba99
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -33,4 +33,4 @@ Imports:
Suggests:
knitr
VignetteBuilder: knitr
RoxygenNote: 4.1.1.9001
RoxygenNote: 5.0.1
4 changes: 3 additions & 1 deletion R/sunburst.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -34,6 +34,7 @@ sunburst <- function(
, count = FALSE
, explanation = NULL
, breadcrumb = list()
, legend = list()
, width = NULL
, height = NULL
) {
Expand All @@ -56,6 +57,7 @@ sunburst <- function(
,count = count
,explanation = explanation
,breadcrumb = breadcrumb
,legend = legend
)
)

Expand Down
3 changes: 1 addition & 2 deletions inst/htmlwidgets/lib/sequences/sequences.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

.sunburst-sidebar {
position: absolute;
width: 10%;
left: 90%;
right: 10px;
top: 10px;
}

Expand Down
8 changes: 7 additions & 1 deletion inst/htmlwidgets/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions man/sunburst.Rd

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

0 comments on commit 53fba99

Please sign in to comment.