Skip to content

Commit

Permalink
change to not double count pre-summed trees #60
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Feb 15, 2018
1 parent 46f5d61 commit b8a18d1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 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: 1.0.3
Date: 2018-01-29
Version: 2.0.0
Date: 2018-02-15
Authors@R: c(
person(
"Mike", "Bostock"
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# sunburstR 1.1.0

* fix to correctly handle pre-summed trees, like `treemap::treemap` to not double count the aggregate (see (issue)[https://github.com/timelyportfolio/sunburstR/issues/60#issuecomment-365751989])

# sunburstR 1.0.3

* change text color in legend and breadcrumb to white or black for legibility using d3plus
Expand Down
5 changes: 4 additions & 1 deletion inst/htmlwidgets/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ function draw (el, instance, dispatch_) {

// Turn the data into a d3 hierarchy and calculate the sums.
var root = d3Hierarchy.hierarchy(json)
.sum(function(d) { return d[x.options.valueField || "size"]; });
.sum(function(d) {
// only sum if no children (or is leaf)
if(!(d.children && d.children.length > 0)) return d[x.options.valueField || "size"];
});

// check for sort function
if(x.options.sortFunction){
Expand Down
5 changes: 4 additions & 1 deletion javascript/src/sunburst-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ export default function (el, instance, dispatch_) {

// Turn the data into a d3 hierarchy and calculate the sums.
var root = hierarchy(json)
.sum(function(d) { return d[x.options.valueField || "size"]; });
.sum(function(d) {
// only sum if no children (or is leaf)
if(!(d.children && d.children.length > 0)) return d[x.options.valueField || "size"];
});

// check for sort function
if(x.options.sortFunction){
Expand Down

0 comments on commit b8a18d1

Please sign in to comment.