Skip to content
Permalink
Browse files

change weight column name to value to be consistent with newest d3-sa…

…nkey
  • Loading branch information
timelyportfolio committed Jul 4, 2017
1 parent ce74ca5 commit 65b913322f1a6c71db21496f158bb0bed645a1f6
Showing with 18 additions and 12 deletions.
  1. +2 −2 DESCRIPTION
  2. +6 −0 NEWS.md
  3. +6 −6 R/table.R
  4. +4 −4 tests/testthat/test_table.R
@@ -1,8 +1,8 @@
Package: d3r
Type: Package
Title: 'd3.js' Utilities for R
Version: 0.6.6
Date: 2017-06-26
Version: 0.6.7
Date: 2017-07-04
Authors@R: c(
person(
"Mike", "Bostock"
@@ -1,3 +1,9 @@
# d3r 0.6.7

### API Changes

* **(BREAKING)** d3_table weight column is now named value to be consistent with the newest d3-sankey plugin [commit]().

# d3r 0.6.6

### Updates
@@ -26,13 +26,13 @@ links_get <- function(tB, vars=NULL, agg="Freq") {
function(f){
structure(
data.frame(stats::xtabs(paste0(agg,"~",f),tB)),
names = c("source","target","weight")
names = c("source","target","value")
)
}
)
)

colnames(vars_df) <- c("source","target","weight")
colnames(vars_df) <- c("source","target","value")
vars_df
}

@@ -50,14 +50,14 @@ links_transform <- function(links=NULL, nodes=NULL, vars=NULL, agg=NULL, tB=NULL
)

links <- data.frame(links, stringsAsFactors = F)
colnames(links) <- c("source","target","weight")
colnames(links) <- c("source","target","value")
}

links_tail <- data.frame(
utils::tail(nodes,1),
stats::xtabs(paste0(agg,"~",vars[1]),tB)
)
colnames(links_tail) <- c("source","target","weight")
colnames(links_tail) <- c("source","target","value")

links <- rbind(
links,
@@ -125,15 +125,15 @@ d3_table <- function( tB = NULL, vars = NULL, agg = "Freq" ) {

nodes_df <- data.frame(
name = names(unlist(nodes_df)),
weight = as.vector(unlist(nodes_df)),
value = as.vector(unlist(nodes_df)),
stringsAsFactors = F
)

nodes_df <- rbind(
nodes_df,
data.frame(
name = utils::tail(nodes,1),
weight = sum(tB)
value = sum(tB)
)
)
# not sure if this is necessary any more
@@ -7,15 +7,15 @@ test_that("d3_table works with 1 var", {
nodes=structure(
data.frame(
name = c("Admitted","Rejected","UCBAdmissions"),
weight = c(1755,2771,4526),
value = c(1755,2771,4526),
stringsAsFactors = FALSE
),
row.names = as.character(1:3)
),
links = data.frame(
source = c(2,2),
target = c(0,1),
weight = c(1755, 2771),
value = c(1755, 2771),
stringsAsFactors = FALSE
)
)
@@ -29,15 +29,15 @@ test_that("d3_table works with > 1 var", {
nodes = structure(
data.frame(
name = c("Child","Adult","Male","Female","Titanic"),
weight = c(109,2092,1731,470,2201),
value = c(109,2092,1731,470,2201),
stringsAsFactors = FALSE
),
row.names = as.character(seq_len(5))
),
links = data.frame(
source = c(0,1,0,1,4,4),
target = c(2,2,3,3,0,1),
weight = c(64,1667,45,425,109,2092),
value = c(64,1667,45,425,109,2092),
stringsAsFactors = FALSE
)
)

0 comments on commit 65b9133

Please sign in to comment.
You can’t perform that action at this time.