├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── c3.R ├── grid.R ├── legend.R ├── options.R ├── pipe.R ├── plots.R ├── region.R ├── subchart.R ├── tooltip.R └── zoom.R ├── README.md ├── _pkgdown.yml ├── c3.Rproj ├── cran-comments.md ├── docs ├── 404.html ├── articles │ ├── examples.html │ ├── examples_files │ │ ├── c3-0.6.7 │ │ │ ├── c3.min.css │ │ │ └── c3.min.js │ │ ├── c3-0.7.15 │ │ │ ├── c3.min.css │ │ │ └── c3.min.js │ │ ├── c3-binding-0.2.1 │ │ │ └── c3.js │ │ ├── c3-binding-0.3.0 │ │ │ └── c3.js │ │ ├── c3-binding-0.3.1 │ │ │ └── c3.js │ │ ├── d3-5.15.0 │ │ │ └── d3.min.js │ │ ├── d3-5.4.0 │ │ │ └── d3.min.js │ │ └── htmlwidgets-1.5.1 │ │ │ └── htmlwidgets.js │ └── index.html ├── authors.html ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── RColorBrewer.c3.html │ ├── c3-shiny.html │ ├── c3.html │ ├── c3_bar.html │ ├── c3_chart_size.html │ ├── c3_color.html │ ├── c3_colour.html │ ├── c3_donut.html │ ├── c3_gauge.html │ ├── c3_line.html │ ├── c3_mixedGeom.html │ ├── c3_pie.html │ ├── c3_scatter.html │ ├── c3_selection.html │ ├── c3_viridis.html │ ├── check_stacked.html │ ├── figures │ └── simple_fig.png │ ├── grid.c3.html │ ├── index.html │ ├── legend.c3.html │ ├── pipe.html │ ├── point_options.html │ ├── region.c3.html │ ├── subchart.c3.html │ ├── tickAxis.html │ ├── tooltip.c3.html │ ├── xAxis.c3.html │ └── zoom.c3.html ├── inst └── htmlwidgets │ ├── c3.js │ ├── c3.yaml │ ├── lib │ ├── c3-0.7.15 │ │ ├── c3.min.css │ │ └── c3.min.js │ └── d3-5.15.0 │ │ └── d3.min.js │ └── test.html ├── man ├── RColorBrewer.c3.Rd ├── c3-shiny.Rd ├── c3.Rd ├── c3_bar.Rd ├── c3_chart_size.Rd ├── c3_color.Rd ├── c3_colour.Rd ├── c3_donut.Rd ├── c3_gauge.Rd ├── c3_line.Rd ├── c3_mixedGeom.Rd ├── c3_pie.Rd ├── c3_scatter.Rd ├── c3_selection.Rd ├── c3_viridis.Rd ├── check_stacked.Rd ├── figures │ └── simple_fig.png ├── grid.c3.Rd ├── legend.c3.Rd ├── pipe.Rd ├── point_options.Rd ├── region.c3.Rd ├── subchart.c3.Rd ├── tickAxis.Rd ├── tooltip.c3.Rd ├── xAxis.c3.Rd └── zoom.c3.Rd ├── tests ├── testthat.R └── testthat │ ├── test_c3.R │ ├── test_options.R │ └── test_plots.R └── vignettes └── examples.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README\.md$ 4 | ^README\.Rmd$ 5 | README_files/ 6 | ^_pkgdown\.yml$ 7 | ^docs$ 8 | ^pkgdown$ 9 | ^cran-comments\.md$ 10 | ^\.github$ 11 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: 9 | branches: 10 | - main 11 | - master 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | - {os: windows-latest, r: 'release'} 26 | - {os: macOS-latest, r: 'release'} 27 | - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 28 | - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 29 | 30 | env: 31 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 32 | RSPM: ${{ matrix.config.rspm }} 33 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 34 | 35 | steps: 36 | - uses: actions/checkout@v2 37 | 38 | - uses: r-lib/actions/setup-r@v1 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | 42 | - uses: r-lib/actions/setup-pandoc@v1 43 | 44 | - name: Query dependencies 45 | run: | 46 | install.packages('remotes') 47 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 48 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 49 | shell: Rscript {0} 50 | 51 | - name: Cache R packages 52 | if: runner.os != 'Windows' 53 | uses: actions/cache@v2 54 | with: 55 | path: ${{ env.R_LIBS_USER }} 56 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 57 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 58 | 59 | - name: Install system dependencies 60 | if: runner.os == 'Linux' 61 | run: | 62 | while read -r cmd 63 | do 64 | eval sudo $cmd 65 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 66 | 67 | - name: Install dependencies 68 | run: | 69 | remotes::install_deps(dependencies = TRUE) 70 | remotes::install_cran("rcmdcheck") 71 | shell: Rscript {0} 72 | 73 | - name: Check 74 | env: 75 | _R_CHECK_CRAN_INCOMING_REMOTE_: false 76 | run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") 77 | shell: Rscript {0} 78 | 79 | - name: Upload check results 80 | if: failure() 81 | uses: actions/upload-artifact@main 82 | with: 83 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 84 | path: check 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: c3 2 | Type: Package 3 | Title: 'C3.js' Chart Library 4 | Description: Create interactive charts with the 'C3.js' charting library. All plot 5 | types in 'C3.js' are available and include line, bar, scatter, and mixed geometry plots. Plot 6 | annotations, labels and axis are highly adjustable. Interactive web based charts can be embedded 7 | in R Markdown documents or Shiny web applications. 8 | Version: 0.3.1 9 | Authors@R: c( 10 | person("Matt", "Johnson", email = "mrjoh3@gmail.com", 11 | role = c("aut", "cre")) 12 | ) 13 | Maintainer: Matt Johnson 14 | Depends: 15 | R (>= 3.2.2) 16 | Imports: 17 | jsonlite, 18 | data.table, 19 | lazyeval, 20 | htmlwidgets, 21 | dplyr, 22 | viridis 23 | URL: https://github.com/mrjoh3/c3 24 | BugReports: https://github.com/mrjoh3/c3/issues 25 | License: GPL (>= 3) 26 | LazyData: TRUE 27 | Encoding: UTF-8 28 | RoxygenNote: 6.1.1 29 | Suggests: 30 | testthat, 31 | RColorBrewer, 32 | knitr, 33 | rmarkdown, 34 | purrr 35 | VignetteBuilder: knitr 36 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(RColorBrewer,c3) 4 | S3method(grid,c3) 5 | S3method(legend,c3) 6 | S3method(region,c3) 7 | S3method(subchart,c3) 8 | S3method(tooltip,c3) 9 | S3method(xAxis,c3) 10 | S3method(y2Axis,c3) 11 | S3method(yAxis,c3) 12 | S3method(zoom,c3) 13 | export("%>%") 14 | export(RColorBrewer) 15 | export(c3) 16 | export(c3Output) 17 | export(c3_bar) 18 | export(c3_chart_size) 19 | export(c3_color) 20 | export(c3_colour) 21 | export(c3_donut) 22 | export(c3_gauge) 23 | export(c3_line) 24 | export(c3_mixedGeom) 25 | export(c3_pie) 26 | export(c3_scatter) 27 | export(c3_selection) 28 | export(c3_viridis) 29 | export(grid) 30 | export(legend) 31 | export(point_options) 32 | export(region) 33 | export(renderC3) 34 | export(subchart) 35 | export(tickAxis) 36 | export(tooltip) 37 | export(xAxis) 38 | export(y2Axis) 39 | export(yAxis) 40 | export(zoom) 41 | importFrom(data.table,dcast) 42 | importFrom(data.table,setDT) 43 | importFrom(dplyr,group_by_at) 44 | importFrom(dplyr,mutate) 45 | importFrom(dplyr,n) 46 | importFrom(dplyr,select) 47 | importFrom(htmlwidgets,JS) 48 | importFrom(jsonlite,fromJSON) 49 | importFrom(jsonlite,toJSON) 50 | importFrom(lazyeval,interp) 51 | importFrom(stats,formula) 52 | importFrom(utils,modifyList) 53 | importFrom(viridis,viridis) 54 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # c3 0.3.1 2 | 3 | * remove use of `iris` dataset in examples and documentation 4 | * option to parse group variables containing wildcard characters such as `()` 5 | 6 | 7 | # c3 0.3.0 8 | 9 | * Updated cs.js to 0.7.15 10 | * Updated d3.js to 5.15.0 11 | * All data.frame calls now use strinsAsFactors = TRUE in preparation for R version 4 12 | * migrated documentation to pkgdown 13 | -------------------------------------------------------------------------------- /R/grid.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #' @rdname grid.c3 5 | #' @family grid 6 | #' @export 7 | grid <- function(c3, 8 | axis, 9 | show = TRUE, 10 | lines = NULL, 11 | ticks = NULL, 12 | ...){ 13 | UseMethod('grid') 14 | } 15 | 16 | #' @title C3 Grid 17 | #' @description Modify grid and line elements on both x and y axis 18 | #' 19 | #' @param c3 c3 htmlwidget object 20 | #' @param axis character 'x' or 'y' 21 | #' @param show boolean 22 | #' @param ticks boolean placeholder. Not yet implemented in \href{http://c3js.org/reference.html#grid-y-ticks}{C3.js} 23 | #' @param lines dataframe with options: 24 | #' \itemize{ 25 | #' \item{value}{: numeric, character or date depending on axis} 26 | #' \item{text}{: character (optional)} 27 | #' \item{class}{: character css class (optional)} 28 | #' \item{position}{: character one of 'start', 'middle', 'end' (optional)} 29 | #' } 30 | #' @param ... additional options passed to the grid object 31 | #' 32 | #' @family c3 33 | #' @family grid 34 | #' @return c3 35 | #' @export 36 | #' 37 | #' @examples 38 | #' mtcars %>% 39 | #' c3(x = 'mpg', y = 'wt', group = 'cyl') %>% 40 | #' c3_scatter() %>% 41 | #' grid('y') %>% 42 | #' grid('x', show = FALSE, lines = data.frame(value=c(17, 21), 43 | #' text= c('Line 1', 'Line 2'))) 44 | #' 45 | grid.c3 <- function(c3, 46 | axis, 47 | show = TRUE, 48 | lines = NULL, 49 | ticks = NULL, 50 | ...){ 51 | 52 | stopifnot(!missing(axis)) 53 | 54 | grid <- list(show = show, 55 | lines = lines, # show inside axis 56 | ticks = ticks # only for yAxis 57 | ) 58 | 59 | grid <- modifyList(grid, list(...)) 60 | 61 | grid <- Filter(Negate(function(x) is.null(unlist(x))), grid) 62 | 63 | c3$x$grid[[axis]] <- grid 64 | 65 | return(c3) 66 | 67 | } 68 | -------------------------------------------------------------------------------- /R/legend.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' @rdname legend.c3 4 | #' @family legend 5 | #' @export 6 | legend <- function(c3, 7 | hide = FALSE, 8 | position = NULL, 9 | inset = NULL, 10 | item = NULL, 11 | ...){ 12 | UseMethod('legend') 13 | } 14 | 15 | #' @title C3 Legend Options 16 | #' @description Modify plot elements that relate to the legend. The c3 legend is on by default, this function allows the 17 | #' legend to be removed, or other legend attributes to be set. 18 | #' 19 | #' @param c3 c3 htmlwidget object 20 | #' @param hide boolean or character of parameters to hide 21 | #' @param position character one of 'bottom', 'right', 'inset' 22 | #' @param inset list with options: 23 | #' \itemize{ 24 | #' \item{anchor}{: character one of 'top-left', 'top-right', 'bottom-left', 'bottom-right'} 25 | #' \item{x}{: integer pixels} 26 | #' \item{y}{: integer pixels} 27 | #' \item{step}{: numeric} 28 | #' } 29 | #' @param item list with options: 30 | #' \itemize{ 31 | #' \item{onclick}{: character js function, wrap character or character vector in JS()} 32 | #' \item{onmouseover}{: character js function, wrap character or character vector in JS()} 33 | #' \item{onmouseout}{: character js function, wrap character or character vector in JS()} 34 | #' } 35 | #' @param ... additional options passed to the legend object 36 | #' 37 | #' @family c3 38 | #' @family legend 39 | #' @return c3 40 | #' @export 41 | #' 42 | #' @examples 43 | #' mtcars %>% 44 | #' c3(x = 'mpg', y = 'wt', group = 'cyl') %>% 45 | #' c3_scatter() %>% 46 | #' legend(position = 'right') 47 | #' 48 | legend.c3 <- function(c3, 49 | hide = FALSE, 50 | position = NULL, 51 | inset = NULL, 52 | item = NULL, 53 | ...){ 54 | 55 | legend <- list(hide = hide, 56 | position = position, 57 | inset = inset, 58 | item = item 59 | ) 60 | 61 | legend <- modifyList(legend, list(...)) 62 | 63 | legend <- Filter(Negate(function(x) is.null(unlist(x))), legend) 64 | 65 | c3$x$legend <- legend 66 | 67 | return(c3) 68 | 69 | } 70 | -------------------------------------------------------------------------------- /R/pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' Imports the pipe operator from magrittr. 4 | #' 5 | #' @export 6 | #' @param lhs a \code{\link{c3}} object 7 | #' @param rhs a pie settings function 8 | #' @rdname pipe 9 | #' @examples 10 | #' data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) %>% 11 | #' c3() 12 | `%>%` <- magrittr::`%>%` 13 | -------------------------------------------------------------------------------- /R/region.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #' @rdname region.c3 6 | #' @family region 7 | #' @export 8 | region <- function(c3, regions){ 9 | UseMethod('region') 10 | } 11 | 12 | #' @title Modify region elements on both x and y axis 13 | #' @description Regions are defined in multiple axis by passing a single `data.frame` 14 | #' @param c3 c3 htmlwidget object 15 | #' @param regions data.frame with columns listed below. Any columns can be missing but results may be unexpected. 16 | #' \itemize{ 17 | #' \item{axis}{: character one of 'x', 'y', 'y2'} 18 | #' \item{start}{: numeric but must match defined axis type} 19 | #' \item{end}{: numeric but must match defined axis type} 20 | #' \item{class}{: character css class} 21 | #' } 22 | #' @family c3 23 | #' @family region 24 | #' @return c3 25 | #' @export 26 | #' 27 | #' @examples 28 | #' mtcars %>% 29 | #' c3(x = 'mpg', y = 'wt', group = 'cyl') %>% 30 | #' c3_scatter() %>% 31 | #' region(data.frame(axis = 'x', 32 | #' start = 17, 33 | #' end = 21)) 34 | #' 35 | region.c3 <- function(c3, regions){ 36 | 37 | stopifnot(class(regions) == 'data.frame', 38 | all(colnames(regions) %in% c('axis', 'start', 'end', 'class'))) 39 | 40 | c3$x$regions <- regions 41 | 42 | return(c3) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /R/subchart.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #' @rdname subchart.c3 6 | #' @family subchart 7 | #' @export 8 | subchart <- function(c3, 9 | height = 20, 10 | onbrush = NULL){ 11 | UseMethod('subchart') 12 | } 13 | 14 | #' @title Add Subchart 15 | #' @description Subcharts are defined in multiple axis by passing a single `data.frame`. Subcharts are listed as an 16 | #' experimental feature in the \href{http://c3js.org/reference.html#subchart-onbrush}{C3 documentation}). 17 | #' @param c3 c3 htmlwidget object 18 | #' @param height integer pixels 19 | #' @param onbrush character js function, wrap character or character vector in JS() 20 | #' 21 | #' @importFrom htmlwidgets JS 22 | #' @family c3 23 | #' @family subchart 24 | #' @return c3 25 | #' @export 26 | #' 27 | #' @examples 28 | #' data.frame(a = abs(rnorm(20) * 10), 29 | #' b = abs(rnorm(20) * 10), 30 | #' date = seq(as.Date("2014-01-01"), by = "month", length.out = 20)) %>% 31 | #' c3(x = 'date') %>% 32 | #' subchart(height = 20, onbrush = 'function (domain) { console.log(domain) }') 33 | #' 34 | subchart.c3 <- function(c3, 35 | height = 20, 36 | onbrush = NULL){ 37 | 38 | subchart <- list( 39 | show = TRUE, 40 | size = list( 41 | height = height 42 | ) 43 | ) 44 | 45 | if (!is.null(onbrush)) { 46 | if (class(onbrush) != "JS_EVAL") {onbrush <- JS(onbrush)} 47 | subchart$onbrush <- onbrush 48 | } 49 | 50 | c3$x$subchart <- subchart 51 | 52 | return(c3) 53 | 54 | } 55 | -------------------------------------------------------------------------------- /R/tooltip.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #' @rdname tooltip.c3 5 | #' @family tooltip 6 | #' @export 7 | tooltip <- function(c3, 8 | show = TRUE, 9 | grouped = TRUE, 10 | format = NULL, 11 | position = NULL, 12 | contents = NULL, 13 | ...){ 14 | UseMethod('tooltip') 15 | } 16 | 17 | #' @title C3 Tooltips 18 | #' @description Modify plot elements that relate to tooltips. C3.js documentation contains an \href{http://c3js.org/samples/tooltip_format.html}{extended example}. 19 | #' 20 | #' @param c3 c3 htmlwidget object 21 | #' @param show boolean show or hide tooltips 22 | #' @param grouped boolean 23 | #' @param format list with options: 24 | #' \itemize{ 25 | #' \item{title}{: character js function, wrap character or character vector in JS()} 26 | #' \item{name}{: character js function, wrap character or character vector in JS()} 27 | #' \item{value}{: character js function, wrap character or character vector in JS()} 28 | #' } 29 | #' @param position character js function, wrap character or character vector in JS() 30 | #' @param contents character js function, wrap character or character vector in JS() 31 | #' @param ... addition options passed to the tooltip object 32 | #' 33 | #' @family c3 34 | #' @family tooltip 35 | #' @return c3 36 | #' @export 37 | #' 38 | #' @examples 39 | #' data <- data.frame(a = abs(rnorm(20) *10), 40 | #' b = abs(rnorm(20) *10), 41 | #' c = abs(rnorm(20) *10), 42 | #' d = abs(rnorm(20) *10)) 43 | #' data %>% 44 | #' c3() %>% 45 | #' tooltip(format = list(title = htmlwidgets::JS("function (x) { return 'Data ' + x; }"), 46 | #' name = htmlwidgets::JS('function (name, ratio, id, index)', 47 | #' ' { return name; }'), 48 | #' value = htmlwidgets::JS('function (value, ratio, id, index)', 49 | #' ' { return ratio; }'))) 50 | #' 51 | tooltip.c3 <- function(c3, 52 | show = TRUE, 53 | grouped = TRUE, 54 | format = NULL, 55 | position = NULL, 56 | contents = NULL, 57 | ...){ 58 | 59 | tooltip <- list(show = show, 60 | grouped = grouped, 61 | format = format, 62 | position = position, 63 | contents = contents 64 | ) 65 | 66 | tooltip <- modifyList(tooltip, list(...)) 67 | 68 | tooltip <- Filter(Negate(function(x) is.null(unlist(x))), tooltip) 69 | 70 | c3$x$tooltip <- tooltip 71 | 72 | return(c3) 73 | 74 | } 75 | -------------------------------------------------------------------------------- /R/zoom.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #' @rdname zoom.c3 6 | #' @family zoom 7 | #' @export 8 | zoom <- function(c3, 9 | enabled = TRUE, 10 | rescale = NULL, 11 | extent = NULL, 12 | onzoom = NULL, 13 | onzoomstart = NULL, 14 | onzoomend = NULL, 15 | ...){ 16 | UseMethod('zoom') 17 | } 18 | 19 | #' @title Add C3 Zoom 20 | #' @description Enable chart Zoom. 21 | #' 22 | #' @param c3 c3 htmlwidget object 23 | #' @param enabled boolean default is TRUE 24 | #' @param rescale boolean rescale axis when zooming 25 | #' @param extent numeric vector 26 | #' @param onzoom character js function, wrap character or character vector in JS() 27 | #' @param onzoomstart character js function, wrap character or character vector in JS() 28 | #' @param onzoomend character js function, wrap character or character vector in JS() 29 | #' @param ... additional options passed to the zoom object 30 | #' 31 | #' @family c3 32 | #' @family zoom 33 | #' @return c3 34 | #' @export 35 | #' 36 | #' @examples 37 | #' data.frame(a = abs(rnorm(20) * 10), 38 | #' b = abs(rnorm(20) * 10)) %>% 39 | #' c3() %>% 40 | #' zoom() 41 | #' 42 | zoom.c3 <- function(c3, 43 | enabled = TRUE, 44 | rescale = NULL, 45 | extent = NULL, 46 | onzoom = NULL, 47 | onzoomstart = NULL, 48 | onzoomend = NULL, 49 | ...){ 50 | 51 | #stopifnot() 52 | 53 | zoom <- modifyList( 54 | list( 55 | enabled = enabled, 56 | rescale = rescale, 57 | extent = extent, 58 | onzoom = onzoom, 59 | onzoomstart = onzoomstart, 60 | onzoomend = onzoomend 61 | ), list(...), keep.null = FALSE 62 | ) 63 | 64 | c3$x$zoom <- zoom 65 | 66 | return(c3) 67 | 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | c3 2 | ================ 3 | 4 | [![DOI](https://zenodo.org/badge/60614778.svg)](https://zenodo.org/badge/latestdoi/60614778) 5 | [![R-CMD-check](https://github.com/mrjoh3/c3/workflows/R-CMD-check/badge.svg)](https://github.com/mrjoh3/c3/actions) 6 | [![codecov](https://codecov.io/gh/mrjoh3/c3/branch/master/graph/badge.svg)](https://codecov.io/gh/mrjoh3/c3) 7 | [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/c3)](http://cran.r-project.org/package=c3/) 8 | [![](http://cranlogs.r-pkg.org/badges/c3)](http://cran.r-project.org/package=c3) 9 | 10 | 11 | The `c3` package is a wrapper, or 12 | [htmlwidget](http://www.htmlwidgets.org/), for the 13 | [C3](http://c3js.org/) javascript charting library by [Masayuki 14 | Tanaka](https://github.com/masayuki0812). You will find this package 15 | useful if you are wanting to create a chart using 16 | [R](https://www.r-project.org/) and embedding it in a Rmarkdown document 17 | or Shiny App. 18 | 19 | The `C3` library is very versatile and includes a lot of options. 20 | Currently this package wraps most of the `C3` [options 21 | object](http://c3js.org/reference.html). 22 | 23 | ## Installation 24 | 25 | You probably already guessed this bit. 26 | 27 | ``` r 28 | 29 | install.packages('c3') 30 | 31 | # OR 32 | 33 | devtools::install_github("mrjoh3/c3") 34 | ``` 35 | 36 | ## Basic Usage 37 | 38 | The `c3` package is intended to be as simple and lightweight as 39 | possible. As a starting point the data input must be a `data.frame` or 40 | `tibble` with several options. 41 | 42 | Where no options are supplied a simple line plot is produced by default. 43 | Where no x-axis is defined the plots are sequential. `Date` x-axis can 44 | be parsed with not additional setting if in the format `%Y-%m-%d` (ie 45 | ‘2014-01-01’) 46 | 47 | ``` r 48 | 49 | library(c3) 50 | 51 | data <- data.frame(a = abs(rnorm(20) * 10), 52 | b = abs(rnorm(20) * 10), 53 | date = seq(as.Date("2014-01-01"), by = "month", length.out = 20)) 54 | 55 | c3(data) 56 | ``` 57 | 58 | ![](man/figures/simple_fig.png) 59 | 60 | ## Documentation 61 | 62 | For more detailed documentation and methods see 63 | . 64 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | -------------------------------------------------------------------------------- /c3.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageCheckArgs: --as-cran 22 | PackageRoxygenize: rd,collate,namespace 23 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * local Windows install, R dev r77936 3 | * ubuntu 19.10, R 3.6.1 4 | * win-builder (release) 5 | 6 | ## R CMD check results 7 | 8 | 0 errors | 0 warnings | 0 note 9 | 10 | * This is a new release. 11 | -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 |
55 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 | Content not found. Please use links in the navbar. 122 | 123 |
124 | 125 |
126 | 127 | 128 | 129 |
130 | 133 | 134 |
135 |

Site built with pkgdown 1.4.1.

136 |
137 | 138 |
139 |
140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/articles/examples_files/c3-0.6.7/c3.min.css: -------------------------------------------------------------------------------- 1 | .c3 svg{font:10px sans-serif;-webkit-tap-highlight-color:transparent}.c3 line,.c3 path{fill:none;stroke:#000}.c3 text{-webkit-user-select:none;-moz-user-select:none;user-select:none}.c3-bars path,.c3-event-rect,.c3-legend-item-tile,.c3-xgrid-focus,.c3-ygrid{shape-rendering:crispEdges}.c3-chart-arc path{stroke:#fff}.c3-chart-arc rect{stroke:#fff;stroke-width:1}.c3-chart-arc text{fill:#fff;font-size:13px}.c3-grid line{stroke:#aaa}.c3-grid text{fill:#aaa}.c3-xgrid,.c3-ygrid{stroke-dasharray:3 3}.c3-text.c3-empty{fill:grey;font-size:2em}.c3-line{stroke-width:1px}.c3-circle._expanded_{stroke-width:1px;stroke:#fff}.c3-selected-circle{fill:#fff;stroke-width:2px}.c3-bar{stroke-width:0}.c3-bar._expanded_{fill-opacity:1;fill-opacity:.75}.c3-target.c3-focused{opacity:1}.c3-target.c3-focused path.c3-line,.c3-target.c3-focused path.c3-step{stroke-width:2px}.c3-target.c3-defocused{opacity:.3!important}.c3-region{fill:#4682b4;fill-opacity:.1}.c3-brush .extent{fill-opacity:.1}.c3-legend-item{font-size:12px}.c3-legend-item-hidden{opacity:.15}.c3-legend-background{opacity:.75;fill:#fff;stroke:#d3d3d3;stroke-width:1}.c3-title{font:14px sans-serif}.c3-tooltip-container{z-index:10}.c3-tooltip{border-collapse:collapse;border-spacing:0;background-color:#fff;empty-cells:show;-webkit-box-shadow:7px 7px 12px -9px #777;-moz-box-shadow:7px 7px 12px -9px #777;box-shadow:7px 7px 12px -9px #777;opacity:.9}.c3-tooltip tr{border:1px solid #ccc}.c3-tooltip th{background-color:#aaa;font-size:14px;padding:2px 5px;text-align:left;color:#fff}.c3-tooltip td{font-size:13px;padding:3px 6px;background-color:#fff;border-left:1px dotted #999}.c3-tooltip td>span{display:inline-block;width:10px;height:10px;margin-right:6px}.c3-tooltip td.value{text-align:right}.c3-area{stroke-width:0;opacity:.2}.c3-chart-arcs-title{dominant-baseline:middle;font-size:1.3em}.c3-chart-arcs .c3-chart-arcs-background{fill:#e0e0e0;stroke:#fff}.c3-chart-arcs .c3-chart-arcs-gauge-unit{fill:#000;font-size:16px}.c3-chart-arcs .c3-chart-arcs-gauge-max{fill:#777}.c3-chart-arcs .c3-chart-arcs-gauge-min{fill:#777}.c3-chart-arc .c3-gauge-value{fill:#000}.c3-chart-arc.c3-target g path{opacity:1}.c3-chart-arc.c3-target.c3-focused g path{opacity:1}.c3-drag-zoom.enabled{pointer-events:all!important;visibility:visible}.c3-drag-zoom.disabled{pointer-events:none!important;visibility:hidden}.c3-drag-zoom .extent{fill-opacity:.1} -------------------------------------------------------------------------------- /docs/articles/examples_files/c3-0.7.15/c3.min.css: -------------------------------------------------------------------------------- 1 | .c3 svg{font:10px sans-serif;-webkit-tap-highlight-color:transparent}.c3 line,.c3 path{fill:none;stroke:#000}.c3 text{-webkit-user-select:none;-moz-user-select:none;user-select:none}.c3-bars path,.c3-event-rect,.c3-legend-item-tile,.c3-xgrid-focus,.c3-ygrid{shape-rendering:crispEdges}.c3-chart-arc path{stroke:#fff}.c3-chart-arc rect{stroke:#fff;stroke-width:1}.c3-chart-arc text{fill:#fff;font-size:13px}.c3-grid line{stroke:#aaa}.c3-grid text{fill:#aaa}.c3-xgrid,.c3-ygrid{stroke-dasharray:3 3}.c3-text.c3-empty{fill:grey;font-size:2em}.c3-line{stroke-width:1px}.c3-circle{fill:currentColor}.c3-circle._expanded_{stroke-width:1px;stroke:#fff}.c3-selected-circle{fill:#fff;stroke-width:2px}.c3-bar{stroke-width:0}.c3-bar._expanded_{fill-opacity:1;fill-opacity:.75}.c3-target.c3-focused{opacity:1}.c3-target.c3-focused path.c3-line,.c3-target.c3-focused path.c3-step{stroke-width:2px}.c3-target.c3-defocused{opacity:.3!important}.c3-region{fill:#4682b4;fill-opacity:.1}.c3-region text{fill-opacity:1}.c3-brush .extent{fill-opacity:.1}.c3-legend-item{font-size:12px}.c3-legend-item-hidden{opacity:.15}.c3-legend-background{opacity:.75;fill:#fff;stroke:#d3d3d3;stroke-width:1}.c3-title{font:14px sans-serif}.c3-tooltip-container{z-index:10}.c3-tooltip{border-collapse:collapse;border-spacing:0;background-color:#fff;empty-cells:show;-webkit-box-shadow:7px 7px 12px -9px #777;-moz-box-shadow:7px 7px 12px -9px #777;box-shadow:7px 7px 12px -9px #777;opacity:.9}.c3-tooltip tr{border:1px solid #ccc}.c3-tooltip th{background-color:#aaa;font-size:14px;padding:2px 5px;text-align:left;color:#fff}.c3-tooltip td{font-size:13px;padding:3px 6px;background-color:#fff;border-left:1px dotted #999}.c3-tooltip td>span{display:inline-block;width:10px;height:10px;margin-right:6px}.c3-tooltip .value{text-align:right}.c3-area{stroke-width:0;opacity:.2}.c3-chart-arcs-title{dominant-baseline:middle;font-size:1.3em}.c3-chart-arcs .c3-chart-arcs-background{fill:#e0e0e0;stroke:#fff}.c3-chart-arcs .c3-chart-arcs-gauge-unit{fill:#000;font-size:16px}.c3-chart-arcs .c3-chart-arcs-gauge-max{fill:#777}.c3-chart-arcs .c3-chart-arcs-gauge-min{fill:#777}.c3-chart-arc .c3-gauge-value{fill:#000}.c3-chart-arc.c3-target g path{opacity:1}.c3-chart-arc.c3-target.c3-focused g path{opacity:1}.c3-drag-zoom.enabled{pointer-events:all!important;visibility:visible}.c3-drag-zoom.disabled{pointer-events:none!important;visibility:hidden}.c3-drag-zoom .extent{fill-opacity:.1} -------------------------------------------------------------------------------- /docs/articles/examples_files/c3-binding-0.2.1/c3.js: -------------------------------------------------------------------------------- 1 | HTMLWidgets.widget({ 2 | 3 | name: 'c3', 4 | 5 | type: 'output', 6 | 7 | factory: function(el, width, height) { 8 | 9 | // TODO: define shared variables for this instance 10 | var chart; 11 | 12 | // needto id when tab / plot becomes visible 13 | //$('#' + el.id).on('onblur', function(){ 14 | // jQuery(window).trigger('resize'); 15 | // }) 16 | 17 | return { 18 | 19 | renderValue: function(x) { 20 | 21 | el.innerText = x.message; 22 | 23 | x.bindto = '#' + el.id; 24 | 25 | // when tab hidden el.get... returns 0 26 | var w = el.getBoundingClientRect().width; 27 | var h = el.getBoundingClientRect().height; 28 | 29 | console.log(h + ' - h - initial size') 30 | console.log(w + ' - w - initial size') 31 | //x.transition = { 32 | // duration: 1500 33 | //} 34 | //x.onresize = function() { 35 | // this.selectChart.style('max-height', h + "px"); 36 | //} 37 | // set size if missing 38 | if (x.size === null) { 39 | x.size = { 40 | height: h, 41 | width: w 42 | } 43 | console.log('no size set') 44 | } 45 | 46 | // this works because x.data always exists 47 | if (x.data.groups) { 48 | if (x.data.types) { 49 | x.data.groups = [x.data.groups] 50 | } else { 51 | x.data.groups = [x.data.groups.value] 52 | //console.log(x.data.groups); 53 | } 54 | } 55 | 56 | 57 | // Grid Lines 58 | var gridLinesX = (((x || {}).grid || {}).x || {}).lines, 59 | gridLinesY = (((x || {}).grid || {}).y || {}).lines; 60 | if (gridLinesX) { 61 | //x.grid.x.lines = [x.grid.x.lines] 62 | x.grid.x.lines = HTMLWidgets.dataframeToD3(x.grid.x.lines) 63 | } 64 | if (gridLinesY) { 65 | x.grid.y.lines = HTMLWidgets.dataframeToD3(x.grid.y.lines) 66 | } 67 | 68 | // Regions 69 | if (x.regions) { 70 | x.regions = HTMLWidgets.dataframeToD3(x.regions) 71 | } 72 | 73 | // Define the chart 74 | chart = c3.generate( 75 | x 76 | ); 77 | 78 | //setTimeout(chart.flush, 300) 79 | 80 | 81 | // set colours using column headers 82 | //chart.data.colors({ 83 | // a: '#FFFFFF', 84 | // b: '#000000' 85 | //}); 86 | 87 | }, 88 | 89 | resize: function(width, height) { 90 | 91 | //setTimeout(chart.flush, 600) 92 | 93 | var w = el.getBoundingClientRect().width; 94 | var h = el.getBoundingClientRect().height; 95 | 96 | // code to re-render the widget with a new size 97 | chart.resize({ 98 | height: h, 99 | width: w 100 | }) 101 | 102 | // http://stackoverflow.com/questions/26003591/c3-chart-sizing-is-too-big-when-initially-loaded 103 | //jQuery('#' + el.id).trigger('resize'); 104 | 105 | console.log(h) 106 | //console.log(el) 107 | } 108 | 109 | }; 110 | 111 | } 112 | }); 113 | -------------------------------------------------------------------------------- /docs/articles/examples_files/c3-binding-0.3.0/c3.js: -------------------------------------------------------------------------------- 1 | HTMLWidgets.widget({ 2 | 3 | name: 'c3', 4 | 5 | type: 'output', 6 | 7 | factory: function(el, width, height) { 8 | 9 | // TODO: define shared variables for this instance 10 | var chart; 11 | 12 | // needto id when tab / plot becomes visible 13 | //$('#' + el.id).on('onblur', function(){ 14 | // jQuery(window).trigger('resize'); 15 | // }) 16 | 17 | return { 18 | 19 | renderValue: function(x) { 20 | 21 | el.innerText = x.message; 22 | 23 | x.bindto = '#' + el.id; 24 | 25 | // when tab hidden el.get... returns 0 26 | var w = el.getBoundingClientRect().width; 27 | var h = el.getBoundingClientRect().height; 28 | 29 | console.log(h + ' - h - initial size') 30 | console.log(w + ' - w - initial size') 31 | //x.transition = { 32 | // duration: 1500 33 | //} 34 | //x.onresize = function() { 35 | // this.selectChart.style('max-height', h + "px"); 36 | //} 37 | // set size if missing 38 | if (x.size === null) { 39 | x.size = { 40 | height: h, 41 | width: w 42 | } 43 | console.log('no size set') 44 | } 45 | 46 | // this works because x.data always exists 47 | if (x.data.groups) { 48 | if (x.data.types) { 49 | x.data.groups = [x.data.groups] 50 | } else { 51 | x.data.groups = [x.data.groups.value] 52 | //console.log(x.data.groups); 53 | } 54 | } 55 | 56 | 57 | // Grid Lines 58 | var gridLinesX = (((x || {}).grid || {}).x || {}).lines, 59 | gridLinesY = (((x || {}).grid || {}).y || {}).lines; 60 | if (gridLinesX) { 61 | //x.grid.x.lines = [x.grid.x.lines] 62 | x.grid.x.lines = HTMLWidgets.dataframeToD3(x.grid.x.lines) 63 | } 64 | if (gridLinesY) { 65 | x.grid.y.lines = HTMLWidgets.dataframeToD3(x.grid.y.lines) 66 | } 67 | 68 | // Regions 69 | if (x.regions) { 70 | x.regions = HTMLWidgets.dataframeToD3(x.regions) 71 | } 72 | 73 | // Define the chart 74 | chart = c3.generate( 75 | x 76 | ); 77 | 78 | //setTimeout(chart.flush, 300) 79 | 80 | 81 | // set colours using column headers 82 | //chart.data.colors({ 83 | // a: '#FFFFFF', 84 | // b: '#000000' 85 | //}); 86 | 87 | }, 88 | 89 | resize: function(width, height) { 90 | 91 | //setTimeout(chart.flush, 600) 92 | 93 | var w = el.getBoundingClientRect().width; 94 | var h = el.getBoundingClientRect().height; 95 | 96 | // code to re-render the widget with a new size 97 | chart.resize({ 98 | height: h, 99 | width: w 100 | }) 101 | 102 | // http://stackoverflow.com/questions/26003591/c3-chart-sizing-is-too-big-when-initially-loaded 103 | //jQuery('#' + el.id).trigger('resize'); 104 | 105 | console.log(h) 106 | //console.log(el) 107 | } 108 | 109 | }; 110 | 111 | } 112 | }); 113 | -------------------------------------------------------------------------------- /docs/articles/examples_files/c3-binding-0.3.1/c3.js: -------------------------------------------------------------------------------- 1 | HTMLWidgets.widget({ 2 | 3 | name: 'c3', 4 | 5 | type: 'output', 6 | 7 | factory: function(el, width, height) { 8 | 9 | // TODO: define shared variables for this instance 10 | var chart; 11 | 12 | // needto id when tab / plot becomes visible 13 | //$('#' + el.id).on('onblur', function(){ 14 | // jQuery(window).trigger('resize'); 15 | // }) 16 | 17 | return { 18 | 19 | renderValue: function(x) { 20 | 21 | el.innerText = x.message; 22 | 23 | x.bindto = '#' + el.id; 24 | 25 | // when tab hidden el.get... returns 0 26 | var w = el.getBoundingClientRect().width; 27 | var h = el.getBoundingClientRect().height; 28 | 29 | console.log(h + ' - h - initial size') 30 | console.log(w + ' - w - initial size') 31 | //x.transition = { 32 | // duration: 1500 33 | //} 34 | //x.onresize = function() { 35 | // this.selectChart.style('max-height', h + "px"); 36 | //} 37 | // set size if missing 38 | if (x.size === null) { 39 | x.size = { 40 | height: h, 41 | width: w 42 | } 43 | console.log('no size set') 44 | } 45 | 46 | // this works because x.data always exists 47 | if (x.data.groups) { 48 | if (x.data.types) { 49 | x.data.groups = [x.data.groups] 50 | } else { 51 | x.data.groups = [x.data.groups.value] 52 | //console.log(x.data.groups); 53 | } 54 | } 55 | 56 | 57 | // Grid Lines 58 | var gridLinesX = (((x || {}).grid || {}).x || {}).lines, 59 | gridLinesY = (((x || {}).grid || {}).y || {}).lines; 60 | if (gridLinesX) { 61 | //x.grid.x.lines = [x.grid.x.lines] 62 | x.grid.x.lines = HTMLWidgets.dataframeToD3(x.grid.x.lines) 63 | } 64 | if (gridLinesY) { 65 | x.grid.y.lines = HTMLWidgets.dataframeToD3(x.grid.y.lines) 66 | } 67 | 68 | // Regions 69 | if (x.regions) { 70 | x.regions = HTMLWidgets.dataframeToD3(x.regions) 71 | } 72 | 73 | // Define the chart 74 | chart = c3.generate( 75 | x 76 | ); 77 | 78 | //setTimeout(chart.flush, 300) 79 | 80 | 81 | // set colours using column headers 82 | //chart.data.colors({ 83 | // a: '#FFFFFF', 84 | // b: '#000000' 85 | //}); 86 | 87 | }, 88 | 89 | resize: function(width, height) { 90 | 91 | //setTimeout(chart.flush, 600) 92 | 93 | var w = el.getBoundingClientRect().width; 94 | var h = el.getBoundingClientRect().height; 95 | 96 | // code to re-render the widget with a new size 97 | chart.resize({ 98 | height: h, 99 | width: w 100 | }) 101 | 102 | // http://stackoverflow.com/questions/26003591/c3-chart-sizing-is-too-big-when-initially-loaded 103 | //jQuery('#' + el.id).trigger('resize'); 104 | 105 | console.log(h) 106 | //console.log(el) 107 | } 108 | 109 | }; 110 | 111 | } 112 | }); 113 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 |
55 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
122 |

All vignettes

123 |

124 | 125 | 128 |
129 |
130 |
131 | 132 | 133 |
134 | 137 | 138 |
139 |

Site built with pkgdown 1.4.1.

140 |
141 | 142 |
143 |
144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 |
55 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
    122 |
  • 123 |

    Matt Johnson. Author, maintainer. 124 |

    125 |
  • 126 |
127 | 128 |
129 | 130 |
131 | 132 | 133 | 134 |
135 | 138 | 139 |
140 |

Site built with pkgdown 1.4.1.

141 |
142 | 143 |
144 |
145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Changelog • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
54 |
55 | 110 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 121 | 122 |
123 |

124 | c3 0.3.1 Unreleased 125 |

126 |
    127 |
  • remove use of iris dataset in examples and documentation
  • 128 |
  • option to parse group variables containing wildcard characters such as () 129 |
  • 130 |
131 |
132 |
133 |

134 | c3 0.3.0 2020-03-16 135 |

136 |
    137 |
  • Updated cs.js to 0.7.15
  • 138 |
  • Updated d3.js to 5.15.0
  • 139 |
  • All data.frame calls now use strinsAsFactors = TRUE in preparation for R version 4
  • 140 |
  • migrated documentation to pkgdown
  • 141 |
142 |
143 |
144 | 145 | 154 | 155 |
156 | 157 | 158 |
159 | 162 | 163 |
164 |

Site built with pkgdown 1.4.1.

165 |
166 | 167 |
168 |
169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body > .container { 21 | display: flex; 22 | height: 100%; 23 | flex-direction: column; 24 | } 25 | 26 | body > .container .row { 27 | flex: 1 0 auto; 28 | } 29 | 30 | footer { 31 | margin-top: 45px; 32 | padding: 35px 0 36px; 33 | border-top: 1px solid #e5e5e5; 34 | color: #666; 35 | display: flex; 36 | flex-shrink: 0; 37 | } 38 | footer p { 39 | margin-bottom: 0; 40 | } 41 | footer div { 42 | flex: 1; 43 | } 44 | footer .pkgdown { 45 | text-align: right; 46 | } 47 | footer p { 48 | margin-bottom: 0; 49 | } 50 | 51 | img.icon { 52 | float: right; 53 | } 54 | 55 | img { 56 | max-width: 100%; 57 | } 58 | 59 | /* Fix bug in bootstrap (only seen in firefox) */ 60 | summary { 61 | display: list-item; 62 | } 63 | 64 | /* Typographic tweaking ---------------------------------*/ 65 | 66 | .contents .page-header { 67 | margin-top: calc(-60px + 1em); 68 | } 69 | 70 | /* Section anchors ---------------------------------*/ 71 | 72 | a.anchor { 73 | margin-left: -30px; 74 | display:inline-block; 75 | width: 30px; 76 | height: 30px; 77 | visibility: hidden; 78 | 79 | background-image: url(./link.svg); 80 | background-repeat: no-repeat; 81 | background-size: 20px 20px; 82 | background-position: center center; 83 | } 84 | 85 | .hasAnchor:hover a.anchor { 86 | visibility: visible; 87 | } 88 | 89 | @media (max-width: 767px) { 90 | .hasAnchor:hover a.anchor { 91 | visibility: hidden; 92 | } 93 | } 94 | 95 | 96 | /* Fixes for fixed navbar --------------------------*/ 97 | 98 | .contents h1, .contents h2, .contents h3, .contents h4 { 99 | padding-top: 60px; 100 | margin-top: -40px; 101 | } 102 | 103 | /* Sidebar --------------------------*/ 104 | 105 | #sidebar { 106 | margin-top: 30px; 107 | position: -webkit-sticky; 108 | position: sticky; 109 | top: 70px; 110 | } 111 | #sidebar h2 { 112 | font-size: 1.5em; 113 | margin-top: 1em; 114 | } 115 | 116 | #sidebar h2:first-child { 117 | margin-top: 0; 118 | } 119 | 120 | #sidebar .list-unstyled li { 121 | margin-bottom: 0.5em; 122 | } 123 | 124 | .orcid { 125 | height: 16px; 126 | /* margins are required by official ORCID trademark and display guidelines */ 127 | margin-left:4px; 128 | margin-right:4px; 129 | vertical-align: middle; 130 | } 131 | 132 | /* Reference index & topics ----------------------------------------------- */ 133 | 134 | .ref-index th {font-weight: normal;} 135 | 136 | .ref-index td {vertical-align: top;} 137 | .ref-index .icon {width: 40px;} 138 | .ref-index .alias {width: 40%;} 139 | .ref-index-icons .alias {width: calc(40% - 40px);} 140 | .ref-index .title {width: 60%;} 141 | 142 | .ref-arguments th {text-align: right; padding-right: 10px;} 143 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 144 | .ref-arguments .name {width: 20%;} 145 | .ref-arguments .desc {width: 80%;} 146 | 147 | /* Nice scrolling for wide elements --------------------------------------- */ 148 | 149 | table { 150 | display: block; 151 | overflow: auto; 152 | } 153 | 154 | /* Syntax highlighting ---------------------------------------------------- */ 155 | 156 | pre { 157 | word-wrap: normal; 158 | word-break: normal; 159 | border: 1px solid #eee; 160 | } 161 | 162 | pre, code { 163 | background-color: #f8f8f8; 164 | color: #333; 165 | } 166 | 167 | pre code { 168 | overflow: auto; 169 | word-wrap: normal; 170 | white-space: pre; 171 | } 172 | 173 | pre .img { 174 | margin: 5px 0; 175 | } 176 | 177 | pre .img img { 178 | background-color: #fff; 179 | display: block; 180 | height: auto; 181 | } 182 | 183 | code a, pre a { 184 | color: #375f84; 185 | } 186 | 187 | a.sourceLine:hover { 188 | text-decoration: none; 189 | } 190 | 191 | .fl {color: #1514b5;} 192 | .fu {color: #000000;} /* function */ 193 | .ch,.st {color: #036a07;} /* string */ 194 | .kw {color: #264D66;} /* keyword */ 195 | .co {color: #888888;} /* comment */ 196 | 197 | .message { color: black; font-weight: bolder;} 198 | .error { color: orange; font-weight: bolder;} 199 | .warning { color: #6A0366; font-weight: bolder;} 200 | 201 | /* Clipboard --------------------------*/ 202 | 203 | .hasCopyButton { 204 | position: relative; 205 | } 206 | 207 | .btn-copy-ex { 208 | position: absolute; 209 | right: 0; 210 | top: 0; 211 | visibility: hidden; 212 | } 213 | 214 | .hasCopyButton:hover button.btn-copy-ex { 215 | visibility: visible; 216 | } 217 | 218 | /* headroom.js ------------------------ */ 219 | 220 | .headroom { 221 | will-change: transform; 222 | transition: transform 200ms linear; 223 | } 224 | .headroom--pinned { 225 | transform: translateY(0%); 226 | } 227 | .headroom--unpinned { 228 | transform: translateY(-100%); 229 | } 230 | 231 | /* mark.js ----------------------------*/ 232 | 233 | mark { 234 | background-color: rgba(255, 255, 51, 0.5); 235 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 236 | padding: 1px; 237 | } 238 | 239 | /* vertical spacing after htmlwidgets */ 240 | .html-widget { 241 | margin-bottom: 10px; 242 | } 243 | 244 | /* fontawesome ------------------------ */ 245 | 246 | .fab { 247 | font-family: "Font Awesome 5 Brands" !important; 248 | } 249 | 250 | /* don't display links in code chunks when printing */ 251 | /* source: https://stackoverflow.com/a/10781533 */ 252 | @media print { 253 | code a:link:after, code a:visited:after { 254 | content: ""; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('body').scrollspy({ 13 | target: '#sidebar', 14 | offset: 60 15 | }); 16 | 17 | $('[data-toggle="tooltip"]').tooltip(); 18 | 19 | var cur_path = paths(location.pathname); 20 | var links = $("#navbar ul li a"); 21 | var max_length = -1; 22 | var pos = -1; 23 | for (var i = 0; i < links.length; i++) { 24 | if (links[i].getAttribute("href") === "#") 25 | continue; 26 | // Ignore external links 27 | if (links[i].host !== location.host) 28 | continue; 29 | 30 | var nav_path = paths(links[i].pathname); 31 | 32 | var length = prefix_length(nav_path, cur_path); 33 | if (length > max_length) { 34 | max_length = length; 35 | pos = i; 36 | } 37 | } 38 | 39 | // Add class to parent
  • , and enclosing
  • if in dropdown 40 | if (pos >= 0) { 41 | var menu_anchor = $(links[pos]); 42 | menu_anchor.parent().addClass("active"); 43 | menu_anchor.closest("li.dropdown").addClass("active"); 44 | } 45 | }); 46 | 47 | function paths(pathname) { 48 | var pieces = pathname.split("/"); 49 | pieces.shift(); // always starts with / 50 | 51 | var end = pieces[pieces.length - 1]; 52 | if (end === "index.html" || end === "") 53 | pieces.pop(); 54 | return(pieces); 55 | } 56 | 57 | // Returns -1 if not found 58 | function prefix_length(needle, haystack) { 59 | if (needle.length > haystack.length) 60 | return(-1); 61 | 62 | // Special case for length-0 haystack, since for loop won't run 63 | if (haystack.length === 0) { 64 | return(needle.length === 0 ? 0 : -1); 65 | } 66 | 67 | for (var i = 0; i < haystack.length; i++) { 68 | if (needle[i] != haystack[i]) 69 | return(i); 70 | } 71 | 72 | return(haystack.length); 73 | } 74 | 75 | /* Clipboard --------------------------*/ 76 | 77 | function changeTooltipMessage(element, msg) { 78 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 79 | element.setAttribute('data-original-title', msg); 80 | $(element).tooltip('show'); 81 | element.setAttribute('data-original-title', tooltipOriginalTitle); 82 | } 83 | 84 | if(ClipboardJS.isSupported()) { 85 | $(document).ready(function() { 86 | var copyButton = ""; 87 | 88 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 89 | 90 | // Insert copy buttons: 91 | $(copyButton).prependTo(".hasCopyButton"); 92 | 93 | // Initialize tooltips: 94 | $('.btn-copy-ex').tooltip({container: 'body'}); 95 | 96 | // Initialize clipboard: 97 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 98 | text: function(trigger) { 99 | return trigger.parentNode.textContent; 100 | } 101 | }); 102 | 103 | clipboardBtnCopies.on('success', function(e) { 104 | changeTooltipMessage(e.trigger, 'Copied!'); 105 | e.clearSelection(); 106 | }); 107 | 108 | clipboardBtnCopies.on('error', function() { 109 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 110 | }); 111 | }); 112 | } 113 | })(window.jQuery || window.$) 114 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: '2.5' 2 | pkgdown: 1.4.1 3 | pkgdown_sha: ~ 4 | articles: 5 | examples: examples.html 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/c3-shiny.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Shiny bindings for c3 — c3-shiny • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
    58 |
    59 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 126 | 127 |
    128 | 129 |

    Output and render functions for using c3 within Shiny 130 | applications and interactive Rmd documents.

    131 | 132 |
    133 | 134 |
    c3Output(outputId, width = "100%", height = "100%")
    135 | 
    136 | renderC3(expr, env = parent.frame(), quoted = FALSE)
    137 | 138 |

    Arguments

    139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 163 | 164 |
    outputId

    output variable to read from

    width, height

    Must be a valid CSS unit (like '100%', 148 | '400px', 'auto') or a number, which will be coerced to a 149 | string and have 'px' appended.

    expr

    An expression that generates a c3

    env

    The environment in which to evaluate expr.

    quoted

    Is expr a quoted expression (with quote())? This 162 | is useful if you want to save an expression in a variable.

    165 | 166 | 167 |
    168 | 175 |
    176 | 177 | 178 |
    179 | 182 | 183 |
    184 |

    Site built with pkgdown 1.4.1.

    185 |
    186 | 187 |
    188 |
    189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /docs/reference/c3_bar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Bar Plot — c3_bar • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Add bars to a C3 plot

    129 | 130 |
    131 | 132 |
    c3_bar(c3, stacked = FALSE, rotated = FALSE, bar_width = 0.6,
    133 |   zerobased = TRUE)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 |
    c3

    c3 htmlwidget object

    stacked

    boolean place bars on top of each other

    rotated

    boolean use to make x-axis vertical

    bar_width

    numeric pixel width of bars

    zerobased

    boolean

    159 | 160 |

    Value

    161 | 162 |

    c3

    163 | 164 | 165 |

    Examples

    166 |
    data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) %>% 167 | c3() %>% 168 | c3_bar(stacked = TRUE)
    169 |
    170 | 181 |
    182 | 183 | 184 |
    185 | 188 | 189 |
    190 |

    Site built with pkgdown 1.4.1.

    191 |
    192 | 193 |
    194 |
    195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /docs/reference/c3_color.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Color Palette — c3_color • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Manually assign colors

    129 | 130 |
    131 | 132 |
    c3_color(c3, colors)
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
    c3

    c3 htmlwidget object

    colors

    character vector of colors

    146 | 147 |

    Value

    148 | 149 |

    c3

    150 | 151 | 152 |

    Examples

    153 |
    data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) %>% 154 | c3() %>% 155 | c3_color(c('red','black'))
    156 |
    157 | 168 |
    169 | 170 | 171 |
    172 | 175 | 176 |
    177 |

    Site built with pkgdown 1.4.1.

    178 |
    179 | 180 |
    181 |
    182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /docs/reference/c3_colour.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Colour Palette — c3_colour • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Manually assign colours

    129 | 130 |
    131 | 132 |
    c3_colour(c3, colours)
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
    c3

    c3 htmlwidget object

    colours

    character vector of colours

    146 | 147 |

    Value

    148 | 149 |

    c3

    150 | 151 | 152 |

    Examples

    153 |
    data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) %>% 154 | c3() %>% 155 | c3_colour(c('red','black'))
    156 |
    157 | 168 |
    169 | 170 | 171 |
    172 | 175 | 176 |
    177 |

    Site built with pkgdown 1.4.1.

    178 |
    179 | 180 |
    181 |
    182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /docs/reference/c3_donut.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Donut Charts — c3_donut • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Create simple Donut charts

    129 | 130 |
    131 | 132 |
    c3_donut(c3, expand = TRUE, title = NULL, width = NULL,
    133 |   show = TRUE, threshold = NULL, format = NULL, ...)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 |
    c3

    c3 htmlwidget object

    expand

    boolean expand segment on hover

    title

    character

    width

    integer pixels width of donut

    show

    boolean show labels

    threshold

    numeric proportion of segment to hide label

    format

    character label js function, wrap character or character vector in JS()

    ...

    additional values passed to the donut label object

    171 | 172 |

    Value

    173 | 174 |

    c3

    175 | 176 | 177 |

    Examples

    178 |
    data.frame(red=20,green=45,blue=10) %>% 179 | c3() %>% 180 | c3_donut(title = 'Colors')
    181 |
    182 | 193 |
    194 | 195 | 196 |
    197 | 200 | 201 |
    202 |

    Site built with pkgdown 1.4.1.

    203 |
    204 | 205 |
    206 |
    207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | -------------------------------------------------------------------------------- /docs/reference/c3_line.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Line Plot — c3_line • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Add lines to a C3 plot

    129 | 130 |
    131 | 132 |
    c3_line(c3, type, stacked = FALSE, connectNull = FALSE,
    133 |   step_type = NULL)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 167 | 168 |
    c3

    c3 htmlwidget object

    type

    character type of line plot. Must be one of:

      145 |
    • line

    • 146 |
    • spline

    • 147 |
    • step

    • 148 |
    • area

    • 149 |
    • area-step

    • 150 |
    stacked

    boolean

    connectNull

    boolean connect null (missing) data points

    step_type

    character, one of:

      163 |
    • step

    • 164 |
    • step-after

    • 165 |
    • step-before

    • 166 |
    169 | 170 |

    Value

    171 | 172 |

    c3

    173 | 174 | 175 |

    Examples

    176 |
    data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) %>% 177 | c3() %>% 178 | c3_line('spline')
    179 |
    180 | 191 |
    192 | 193 | 194 |
    195 | 198 | 199 |
    200 |

    Site built with pkgdown 1.4.1.

    201 |
    202 | 203 |
    204 |
    205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /docs/reference/c3_pie.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Pie Charts — c3_pie • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    C3 Pie Charts

    129 | 130 |
    131 | 132 |
    c3_pie(c3, show = TRUE, threshold = NULL, format = NULL,
    133 |   expand = TRUE, ...)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |
    c3

    c3 htmlwidget object

    show

    boolean show labels

    threshold

    numeric proportion of segment to hide label

    format

    character label js function, wrap character or character vector in JS()

    expand

    boolean expand segment on hover

    ...

    additional values passed to the pie label object

    163 | 164 |

    Value

    165 | 166 |

    c3

    167 | 168 | 169 |

    Examples

    170 |
    data.frame(red = 20, green = 45, blue = 10) %>% 171 | c3() %>% 172 | c3_pie()
    173 |
    174 | 185 |
    186 | 187 | 188 |
    189 | 192 | 193 |
    194 |

    Site built with pkgdown 1.4.1.

    195 |
    196 | 197 |
    198 |
    199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /docs/reference/c3_scatter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Scatter Plots — c3_scatter • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    For scatter plots options are defined in the `c3` function. Options are limited to x, y and groups

    129 | 130 |
    131 | 132 |
    c3_scatter(c3)
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 |
    c3

    c3 htmlwidget object

    142 | 143 |

    Value

    144 | 145 |

    c3

    146 | 147 | 148 |

    Examples

    149 |
    mtcars %>% 150 | c3(x = 'mpg', 151 | y = 'wt', 152 | group = 'cyl') %>% 153 | c3_scatter()
    154 |
    155 | 166 |
    167 | 168 | 169 |
    170 | 173 | 174 |
    175 |

    Site built with pkgdown 1.4.1.

    176 |
    177 | 178 |
    179 |
    180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /docs/reference/c3_viridis.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Viridis Palette — c3_viridis • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Use Viridis palette options

    129 | 130 |
    131 | 132 |
    c3_viridis(c3, pal = "D")
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
    c3

    c3 htmlwidget object

    pal

    character palette options

    146 | 147 |

    Value

    148 | 149 |

    c3

    150 | 151 | 152 |

    Examples

    153 |
    data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) %>% 154 | c3() %>% 155 | c3_viridis()
    156 |
    157 | 168 |
    169 | 170 | 171 |
    172 | 175 | 176 |
    177 |

    Site built with pkgdown 1.4.1.

    178 |
    179 | 180 |
    181 |
    182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /docs/reference/check_stacked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Check groups for stacked plots — check_stacked • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
    58 |
    59 | 114 | 115 | 116 | 117 |
    118 | 119 |
    120 |
    121 | 126 | 127 |
    128 | 129 |

    For plots where stacking is required this function will 130 | define the columns to be stacked based on column headers.

    131 | 132 |
    133 | 134 |
    check_stacked(c3, stacked)
    135 | 136 |

    Arguments

    137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
    c3

    c3 htmlwidget object

    stacked

    boolean

    148 | 149 |

    Value

    150 | 151 |

    c3 object

    152 | 153 | 154 |
    155 | 164 |
    165 | 166 | 167 |
    168 | 171 | 172 |
    173 |

    Site built with pkgdown 1.4.1.

    174 |
    175 | 176 |
    177 |
    178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /docs/reference/figures/simple_fig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjoh3/c3/f4784a7e449888927ca17bfff3417cdf54420e88/docs/reference/figures/simple_fig.png -------------------------------------------------------------------------------- /docs/reference/pipe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Pipe operator — %>% • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Imports the pipe operator from magrittr.

    129 | 130 |
    131 | 132 |
    lhs %>% rhs
    133 | 134 |

    Arguments

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 |
    lhs

    a c3 object

    rhs

    a pie settings function

    146 | 147 | 148 |

    Examples

    149 |
    data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) %>% 150 | c3()
    151 |
    152 | 161 |
    162 | 163 | 164 |
    165 | 168 | 169 |
    170 |

    Site built with pkgdown 1.4.1.

    171 |
    172 | 173 |
    174 |
    175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /docs/reference/point_options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Point Options — point_options • c3 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
    57 |
    58 | 113 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Modify point options

    129 | 130 |
    131 | 132 |
    point_options(c3, show = TRUE, r = 2.5, expand = TRUE,
    133 |   expand.r = 1.75, select.r = 4)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |
    c3

    c3 htmlwidget object

    show

    boolean

    r

    numeric radius of point

    expand

    boolean

    expand.r

    numeric multiplier for radius expansion

    select.r

    numeric multiplier for radius expansion

    163 | 164 |

    Value

    165 | 166 |

    c3

    167 | 168 | 169 |

    Examples

    170 |
    data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) %>% 171 | c3() %>% 172 | point_options(r = 5, expand.r = 2)
    173 |
    174 | 185 |
    186 | 187 | 188 |
    189 | 192 | 193 |
    194 |

    Site built with pkgdown 1.4.1.

    195 |
    196 | 197 |
    198 |
    199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /inst/htmlwidgets/c3.js: -------------------------------------------------------------------------------- 1 | HTMLWidgets.widget({ 2 | 3 | name: 'c3', 4 | 5 | type: 'output', 6 | 7 | factory: function(el, width, height) { 8 | 9 | // TODO: define shared variables for this instance 10 | var chart; 11 | 12 | // needto id when tab / plot becomes visible 13 | //$('#' + el.id).on('onblur', function(){ 14 | // jQuery(window).trigger('resize'); 15 | // }) 16 | 17 | return { 18 | 19 | renderValue: function(x) { 20 | 21 | el.innerText = x.message; 22 | 23 | x.bindto = '#' + el.id; 24 | 25 | // when tab hidden el.get... returns 0 26 | var w = el.getBoundingClientRect().width; 27 | var h = el.getBoundingClientRect().height; 28 | 29 | console.log(h + ' - h - initial size') 30 | console.log(w + ' - w - initial size') 31 | //x.transition = { 32 | // duration: 1500 33 | //} 34 | //x.onresize = function() { 35 | // this.selectChart.style('max-height', h + "px"); 36 | //} 37 | // set size if missing 38 | if (x.size === null) { 39 | x.size = { 40 | height: h, 41 | width: w 42 | } 43 | console.log('no size set') 44 | } 45 | 46 | // this works because x.data always exists 47 | if (x.data.groups) { 48 | if (x.data.types) { 49 | x.data.groups = [x.data.groups] 50 | } else { 51 | x.data.groups = [x.data.groups.value] 52 | //console.log(x.data.groups); 53 | } 54 | } 55 | 56 | 57 | // Grid Lines 58 | var gridLinesX = (((x || {}).grid || {}).x || {}).lines, 59 | gridLinesY = (((x || {}).grid || {}).y || {}).lines; 60 | if (gridLinesX) { 61 | //x.grid.x.lines = [x.grid.x.lines] 62 | x.grid.x.lines = HTMLWidgets.dataframeToD3(x.grid.x.lines) 63 | } 64 | if (gridLinesY) { 65 | x.grid.y.lines = HTMLWidgets.dataframeToD3(x.grid.y.lines) 66 | } 67 | 68 | // Regions 69 | if (x.regions) { 70 | x.regions = HTMLWidgets.dataframeToD3(x.regions) 71 | } 72 | 73 | // Define the chart 74 | chart = c3.generate( 75 | x 76 | ); 77 | 78 | //setTimeout(chart.flush, 300) 79 | 80 | 81 | // set colours using column headers 82 | //chart.data.colors({ 83 | // a: '#FFFFFF', 84 | // b: '#000000' 85 | //}); 86 | 87 | }, 88 | 89 | resize: function(width, height) { 90 | 91 | //setTimeout(chart.flush, 600) 92 | 93 | var w = el.getBoundingClientRect().width; 94 | var h = el.getBoundingClientRect().height; 95 | 96 | // code to re-render the widget with a new size 97 | chart.resize({ 98 | height: h, 99 | width: w 100 | }) 101 | 102 | // http://stackoverflow.com/questions/26003591/c3-chart-sizing-is-too-big-when-initially-loaded 103 | //jQuery('#' + el.id).trigger('resize'); 104 | 105 | console.log(h) 106 | //console.log(el) 107 | } 108 | 109 | }; 110 | 111 | } 112 | }); 113 | -------------------------------------------------------------------------------- /inst/htmlwidgets/c3.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - name: d3 3 | version: 5.15.0 4 | src: htmlwidgets/lib/d3-5.15.0 5 | script: d3.min.js 6 | - name: c3 7 | version: 0.7.15 8 | src: htmlwidgets/lib/c3-0.7.15 9 | script: c3.min.js 10 | stylesheet: c3.min.css 11 | 12 | -------------------------------------------------------------------------------- /inst/htmlwidgets/lib/c3-0.7.15/c3.min.css: -------------------------------------------------------------------------------- 1 | .c3 svg{font:10px sans-serif;-webkit-tap-highlight-color:transparent}.c3 line,.c3 path{fill:none;stroke:#000}.c3 text{-webkit-user-select:none;-moz-user-select:none;user-select:none}.c3-bars path,.c3-event-rect,.c3-legend-item-tile,.c3-xgrid-focus,.c3-ygrid{shape-rendering:crispEdges}.c3-chart-arc path{stroke:#fff}.c3-chart-arc rect{stroke:#fff;stroke-width:1}.c3-chart-arc text{fill:#fff;font-size:13px}.c3-grid line{stroke:#aaa}.c3-grid text{fill:#aaa}.c3-xgrid,.c3-ygrid{stroke-dasharray:3 3}.c3-text.c3-empty{fill:grey;font-size:2em}.c3-line{stroke-width:1px}.c3-circle{fill:currentColor}.c3-circle._expanded_{stroke-width:1px;stroke:#fff}.c3-selected-circle{fill:#fff;stroke-width:2px}.c3-bar{stroke-width:0}.c3-bar._expanded_{fill-opacity:1;fill-opacity:.75}.c3-target.c3-focused{opacity:1}.c3-target.c3-focused path.c3-line,.c3-target.c3-focused path.c3-step{stroke-width:2px}.c3-target.c3-defocused{opacity:.3!important}.c3-region{fill:#4682b4;fill-opacity:.1}.c3-region text{fill-opacity:1}.c3-brush .extent{fill-opacity:.1}.c3-legend-item{font-size:12px}.c3-legend-item-hidden{opacity:.15}.c3-legend-background{opacity:.75;fill:#fff;stroke:#d3d3d3;stroke-width:1}.c3-title{font:14px sans-serif}.c3-tooltip-container{z-index:10}.c3-tooltip{border-collapse:collapse;border-spacing:0;background-color:#fff;empty-cells:show;-webkit-box-shadow:7px 7px 12px -9px #777;-moz-box-shadow:7px 7px 12px -9px #777;box-shadow:7px 7px 12px -9px #777;opacity:.9}.c3-tooltip tr{border:1px solid #ccc}.c3-tooltip th{background-color:#aaa;font-size:14px;padding:2px 5px;text-align:left;color:#fff}.c3-tooltip td{font-size:13px;padding:3px 6px;background-color:#fff;border-left:1px dotted #999}.c3-tooltip td>span{display:inline-block;width:10px;height:10px;margin-right:6px}.c3-tooltip .value{text-align:right}.c3-area{stroke-width:0;opacity:.2}.c3-chart-arcs-title{dominant-baseline:middle;font-size:1.3em}.c3-chart-arcs .c3-chart-arcs-background{fill:#e0e0e0;stroke:#fff}.c3-chart-arcs .c3-chart-arcs-gauge-unit{fill:#000;font-size:16px}.c3-chart-arcs .c3-chart-arcs-gauge-max{fill:#777}.c3-chart-arcs .c3-chart-arcs-gauge-min{fill:#777}.c3-chart-arc .c3-gauge-value{fill:#000}.c3-chart-arc.c3-target g path{opacity:1}.c3-chart-arc.c3-target.c3-focused g path{opacity:1}.c3-drag-zoom.enabled{pointer-events:all!important;visibility:visible}.c3-drag-zoom.disabled{pointer-events:none!important;visibility:hidden}.c3-drag-zoom .extent{fill-opacity:.1} -------------------------------------------------------------------------------- /inst/htmlwidgets/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 | 12 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /man/RColorBrewer.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{RColorBrewer} 4 | \alias{RColorBrewer} 5 | \alias{RColorBrewer.c3} 6 | \title{RColorBrewer Palette} 7 | \usage{ 8 | RColorBrewer(c3, pal = "Spectral") 9 | 10 | \method{RColorBrewer}{c3}(c3, pal = "Spectral") 11 | } 12 | \arguments{ 13 | \item{c3}{c3 htmlwidget object} 14 | 15 | \item{pal}{character palette must match `RColorBrewer::brewer.pal.info`} 16 | } 17 | \value{ 18 | c3 19 | } 20 | \description{ 21 | Use RColorBrewer palettes 22 | } 23 | \examples{ 24 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5), c = c(5,3,4,1)) \%>\% 25 | c3() \%>\% 26 | RColorBrewer() 27 | 28 | } 29 | \seealso{ 30 | Other c3: \code{\link{c3}}, \code{\link{grid}}, 31 | \code{\link{legend}}, \code{\link{region}}, 32 | \code{\link{subchart}}, \code{\link{tooltip}}, 33 | \code{\link{xAxis}}, \code{\link{zoom}} 34 | } 35 | \concept{RColorBrewer} 36 | \concept{c3} 37 | -------------------------------------------------------------------------------- /man/c3-shiny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/c3.R 3 | \name{c3-shiny} 4 | \alias{c3-shiny} 5 | \alias{c3Output} 6 | \alias{renderC3} 7 | \title{Shiny bindings for c3} 8 | \usage{ 9 | c3Output(outputId, width = "100\%", height = "100\%") 10 | 11 | renderC3(expr, env = parent.frame(), quoted = FALSE) 12 | } 13 | \arguments{ 14 | \item{outputId}{output variable to read from} 15 | 16 | \item{width, height}{Must be a valid CSS unit (like \code{'100\%'}, 17 | \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a 18 | string and have \code{'px'} appended.} 19 | 20 | \item{expr}{An expression that generates a c3} 21 | 22 | \item{env}{The environment in which to evaluate \code{expr}.} 23 | 24 | \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This 25 | is useful if you want to save an expression in a variable.} 26 | } 27 | \description{ 28 | Output and render functions for using c3 within Shiny 29 | applications and interactive Rmd documents. 30 | } 31 | -------------------------------------------------------------------------------- /man/c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/c3.R 3 | \name{c3} 4 | \alias{c3} 5 | \title{C3} 6 | \usage{ 7 | c3(data, x = NULL, y = NULL, group = NULL, width = NULL, 8 | height = NULL, axes = NULL, labels = NULL, hide = NULL, 9 | onclick = NULL, onmouseover = NULL, onmouseout = NULL, 10 | fixString = FALSE, ...) 11 | } 12 | \arguments{ 13 | \item{data}{data.frame or tibble} 14 | 15 | \item{x}{character column name} 16 | 17 | \item{y}{character column name} 18 | 19 | \item{group}{character column name} 20 | 21 | \item{width}{integer htmlwidget width (separate from plot width)} 22 | 23 | \item{height}{integer htmlwidget height (separate from plot height)} 24 | 25 | \item{axes}{list, use to assign plot elements to secondary y axis} 26 | 27 | \item{labels}{character or list with options: 28 | \itemize{ 29 | \item{format}{: list format functions for each parameter label (see \href{http://c3js.org/reference.html#data-labels}{c3 data-labels})} 30 | }} 31 | 32 | \item{hide}{boolean or character vector of parameters to hide} 33 | 34 | \item{onclick}{character js function, wrap character or character vector in JS()} 35 | 36 | \item{onmouseover}{character js function, wrap character or character vector in JS()} 37 | 38 | \item{onmouseout}{character js function, wrap character or character vector in JS()} 39 | 40 | \item{fixString}{boolean option to parse grouping variables that contain wildcard characters such as `(`} 41 | 42 | \item{...}{addition options passed to the data object} 43 | } 44 | \description{ 45 | An `R` wrapper, or \href{http://www.htmlwidgets.org/}{htmlwidget}, for the \href{http://c3js.org/}{c3} javascript charting library by \href{https://github.com/masayuki0812}{Masayuki Tanaka}. 46 | } 47 | \examples{ 48 | data <- data.frame(a = c(1,2,3,2), b = c(2,3,1,5)) 49 | 50 | data \%>\% 51 | c3(onclick = htmlwidgets::JS("function(d, element){console.log(d)}")) 52 | 53 | data \%>\% 54 | c3(axes = list(a = 'y', 55 | b = 'y2')) \%>\% 56 | y2Axis() 57 | 58 | data.frame(sugar = 20, fat = 45, salt = 10) \%>\% 59 | c3(onclick = htmlwidgets::JS("function(d, element){dp = d}")) \%>\% 60 | c3_pie() 61 | 62 | } 63 | \seealso{ 64 | Other c3: \code{\link{RColorBrewer}}, \code{\link{grid}}, 65 | \code{\link{legend}}, \code{\link{region}}, 66 | \code{\link{subchart}}, \code{\link{tooltip}}, 67 | \code{\link{xAxis}}, \code{\link{zoom}} 68 | } 69 | \concept{c3} 70 | -------------------------------------------------------------------------------- /man/c3_bar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_bar} 4 | \alias{c3_bar} 5 | \title{Bar Plot} 6 | \usage{ 7 | c3_bar(c3, stacked = FALSE, rotated = FALSE, bar_width = 0.6, 8 | zerobased = TRUE) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{stacked}{boolean place bars on top of each other} 14 | 15 | \item{rotated}{boolean use to make x-axis vertical} 16 | 17 | \item{bar_width}{numeric pixel width of bars} 18 | 19 | \item{zerobased}{boolean} 20 | } 21 | \value{ 22 | c3 23 | } 24 | \description{ 25 | Add bars to a C3 plot 26 | } 27 | \examples{ 28 | data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) \%>\% 29 | c3() \%>\% 30 | c3_bar(stacked = TRUE) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/c3_chart_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{c3_chart_size} 4 | \alias{c3_chart_size} 5 | \title{Chart Size} 6 | \usage{ 7 | c3_chart_size(c3, left = NULL, right = NULL, top = NULL, 8 | bottom = NULL, width = NULL, height = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{left}{integer padding pixels} 14 | 15 | \item{right}{integer padding pixels} 16 | 17 | \item{top}{integer padding pixels} 18 | 19 | \item{bottom}{integer padding pixels} 20 | 21 | \item{width}{integer pixels} 22 | 23 | \item{height}{integer pixels} 24 | 25 | \item{...}{additional options passed to the padding and size objects} 26 | } 27 | \value{ 28 | c3 29 | } 30 | \description{ 31 | Modify the size of the chart within the htmlwidget area. Generally charts size 32 | to the div in which they are placed. These options enable finer scale sizing with the div 33 | } 34 | \examples{ 35 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 36 | c3() \%>\% 37 | c3_chart_size(width = 600, height = 200) 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/c3_color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{c3_color} 4 | \alias{c3_color} 5 | \title{Color Palette} 6 | \usage{ 7 | c3_color(c3, colors) 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | 12 | \item{colors}{character vector of colors} 13 | } 14 | \value{ 15 | c3 16 | } 17 | \description{ 18 | Manually assign colors 19 | } 20 | \examples{ 21 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 22 | c3() \%>\% 23 | c3_color(c('red','black')) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/c3_colour.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{c3_colour} 4 | \alias{c3_colour} 5 | \title{Colour Palette} 6 | \usage{ 7 | c3_colour(c3, colours) 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | 12 | \item{colours}{character vector of colours} 13 | } 14 | \value{ 15 | c3 16 | } 17 | \description{ 18 | Manually assign colours 19 | } 20 | \examples{ 21 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 22 | c3() \%>\% 23 | c3_colour(c('red','black')) 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/c3_donut.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_donut} 4 | \alias{c3_donut} 5 | \title{Donut Charts} 6 | \usage{ 7 | c3_donut(c3, expand = TRUE, title = NULL, width = NULL, 8 | show = TRUE, threshold = NULL, format = NULL, ...) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{expand}{boolean expand segment on hover} 14 | 15 | \item{title}{character} 16 | 17 | \item{width}{integer pixels width of donut} 18 | 19 | \item{show}{boolean show labels} 20 | 21 | \item{threshold}{numeric proportion of segment to hide label} 22 | 23 | \item{format}{character label js function, wrap character or character vector in JS()} 24 | 25 | \item{...}{additional values passed to the donut label object} 26 | } 27 | \value{ 28 | c3 29 | } 30 | \description{ 31 | Create simple Donut charts 32 | } 33 | \examples{ 34 | data.frame(red=20,green=45,blue=10) \%>\% 35 | c3() \%>\% 36 | c3_donut(title = 'Colors') 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/c3_gauge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_gauge} 4 | \alias{c3_gauge} 5 | \title{Gauge Charts} 6 | \usage{ 7 | c3_gauge(c3, label = NULL, min = 0, max = 100, units = NULL, 8 | width = NULL, pattern = c("#FF0000", "#F97600", "#F6C600", 9 | "#60B044"), threshold = list(unit = "value", max = 100, values = c(30, 10 | 60, 90, 100)), height = NULL, ...) 11 | } 12 | \arguments{ 13 | \item{c3}{c3 htmlwidget object} 14 | 15 | \item{label}{list with options: 16 | \itemize{ 17 | \item{show}{: boolean} 18 | \item{format}{: function, wrap in JS() } 19 | }} 20 | 21 | \item{min}{numeric} 22 | 23 | \item{max}{numeric} 24 | 25 | \item{units}{character appended to numeric value} 26 | 27 | \item{width}{integer pixel width of the arc} 28 | 29 | \item{pattern}{character vector or palette of colors} 30 | 31 | \item{threshold}{list with options: 32 | \itemize{ 33 | \item{unit}{: character one of 'percent', 'value'} 34 | \item{max}{: numeric} 35 | \item{values}{: numeric vector of threshold values for color change} 36 | }} 37 | 38 | \item{height}{integer pixel height of the chart. Proportion of gauge 39 | never changes so height scales with width despite this setting.} 40 | 41 | \item{...}{additional values passed to the gauge, color and size objects} 42 | } 43 | \value{ 44 | c3 45 | } 46 | \description{ 47 | Create simple Gauge Charts 48 | } 49 | \examples{ 50 | data.frame(data=10) \%>\% 51 | c3() \%>\% 52 | c3_gauge(title = 'Colors') 53 | 54 | } 55 | -------------------------------------------------------------------------------- /man/c3_line.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_line} 4 | \alias{c3_line} 5 | \title{Line Plot} 6 | \usage{ 7 | c3_line(c3, type, stacked = FALSE, connectNull = FALSE, 8 | step_type = NULL) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{type}{character type of line plot. Must be one of: 14 | \itemize{ 15 | \item{line} 16 | \item{spline} 17 | \item{step} 18 | \item{area} 19 | \item{area-step} 20 | }} 21 | 22 | \item{stacked}{boolean} 23 | 24 | \item{connectNull}{boolean connect null (missing) data points} 25 | 26 | \item{step_type}{character, one of: 27 | \itemize{ 28 | \item{step} 29 | \item{step-after} 30 | \item{step-before} 31 | }} 32 | } 33 | \value{ 34 | c3 35 | } 36 | \description{ 37 | Add lines to a C3 plot 38 | } 39 | \examples{ 40 | data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) \%>\% 41 | c3() \%>\% 42 | c3_line('spline') 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/c3_mixedGeom.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_mixedGeom} 4 | \alias{c3_mixedGeom} 5 | \title{Mixed Geometry Plots} 6 | \usage{ 7 | c3_mixedGeom(c3, types, type = "line", stacked = NULL) 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | 12 | \item{types}{list containing key value pairs of column header and plot type} 13 | 14 | \item{type}{character default plot type where not defined} 15 | 16 | \item{stacked}{character vector of column headers to stack} 17 | } 18 | \value{ 19 | c3 20 | } 21 | \description{ 22 | Use multiple geometry types in a single plot 23 | } 24 | \examples{ 25 | data <- data.frame(a = abs(rnorm(20) *10), 26 | b = abs(rnorm(20) *10), 27 | c = abs(rnorm(20) *10), 28 | d = abs(rnorm(20) *10)) 29 | data \%>\% 30 | c3() \%>\% 31 | c3_mixedGeom(type = 'bar', 32 | stacked = c('b','d'), 33 | types = list(a='area', 34 | c='spline')) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/c3_pie.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_pie} 4 | \alias{c3_pie} 5 | \title{Pie Charts} 6 | \usage{ 7 | c3_pie(c3, show = TRUE, threshold = NULL, format = NULL, 8 | expand = TRUE, ...) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{show}{boolean show labels} 14 | 15 | \item{threshold}{numeric proportion of segment to hide label} 16 | 17 | \item{format}{character label js function, wrap character or character vector in JS()} 18 | 19 | \item{expand}{boolean expand segment on hover} 20 | 21 | \item{...}{additional values passed to the pie label object} 22 | } 23 | \value{ 24 | c3 25 | } 26 | \description{ 27 | C3 Pie Charts 28 | } 29 | \examples{ 30 | data.frame(red = 20, green = 45, blue = 10) \%>\% 31 | c3() \%>\% 32 | c3_pie() 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/c3_scatter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{c3_scatter} 4 | \alias{c3_scatter} 5 | \title{Scatter Plots} 6 | \usage{ 7 | c3_scatter(c3) 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | } 12 | \value{ 13 | c3 14 | } 15 | \description{ 16 | For scatter plots options are defined in the `c3` function. Options are limited to x, y and groups 17 | } 18 | \examples{ 19 | mtcars \%>\% 20 | c3(x = 'mpg', 21 | y = 'wt', 22 | group = 'cyl') \%>\% 23 | c3_scatter() 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/c3_selection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{c3_selection} 4 | \alias{c3_selection} 5 | \title{Data Select} 6 | \usage{ 7 | c3_selection(c3, enabled = FALSE, grouped = FALSE, multiple = FALSE, 8 | draggable = FALSE, isselectable = JS("function () { return true; }"), 9 | ...) 10 | } 11 | \arguments{ 12 | \item{c3}{c3 htmlwidget object} 13 | 14 | \item{enabled}{boolean} 15 | 16 | \item{grouped}{boolean} 17 | 18 | \item{multiple}{boolean} 19 | 20 | \item{draggable}{boolean} 21 | 22 | \item{isselectable}{character js function, wrap character or character vector in JS()} 23 | 24 | \item{...}{additional options passed to data selection object} 25 | } 26 | \value{ 27 | c3 28 | } 29 | \description{ 30 | Define options for selecting data within the plot area 31 | } 32 | \examples{ 33 | data.frame(a = c(1,2,3,2), b = c(2,3,1,5)) \%>\% 34 | c3() \%>\% 35 | c3_selection(enabled = TRUE, 36 | multiple = TRUE) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/c3_viridis.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{c3_viridis} 4 | \alias{c3_viridis} 5 | \title{Viridis Palette} 6 | \usage{ 7 | c3_viridis(c3, pal = "D") 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | 12 | \item{pal}{character palette options} 13 | } 14 | \value{ 15 | c3 16 | } 17 | \description{ 18 | Use Viridis palette options 19 | } 20 | \examples{ 21 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 22 | c3() \%>\% 23 | c3_viridis() 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/check_stacked.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plots.R 3 | \name{check_stacked} 4 | \alias{check_stacked} 5 | \title{Check groups for stacked plots} 6 | \usage{ 7 | check_stacked(c3, stacked) 8 | } 9 | \arguments{ 10 | \item{c3}{c3 htmlwidget object} 11 | 12 | \item{stacked}{boolean} 13 | } 14 | \value{ 15 | c3 object 16 | } 17 | \description{ 18 | For plots where stacking is required this function will 19 | define the columns to be stacked based on column headers. 20 | } 21 | -------------------------------------------------------------------------------- /man/figures/simple_fig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrjoh3/c3/f4784a7e449888927ca17bfff3417cdf54420e88/man/figures/simple_fig.png -------------------------------------------------------------------------------- /man/grid.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grid.R 3 | \name{grid} 4 | \alias{grid} 5 | \alias{grid.c3} 6 | \title{C3 Grid} 7 | \usage{ 8 | grid(c3, axis, show = TRUE, lines = NULL, ticks = NULL, ...) 9 | 10 | \method{grid}{c3}(c3, axis, show = TRUE, lines = NULL, ticks = NULL, 11 | ...) 12 | } 13 | \arguments{ 14 | \item{c3}{c3 htmlwidget object} 15 | 16 | \item{axis}{character 'x' or 'y'} 17 | 18 | \item{show}{boolean} 19 | 20 | \item{lines}{dataframe with options: 21 | \itemize{ 22 | \item{value}{: numeric, character or date depending on axis} 23 | \item{text}{: character (optional)} 24 | \item{class}{: character css class (optional)} 25 | \item{position}{: character one of 'start', 'middle', 'end' (optional)} 26 | }} 27 | 28 | \item{ticks}{boolean placeholder. Not yet implemented in \href{http://c3js.org/reference.html#grid-y-ticks}{C3.js}} 29 | 30 | \item{...}{additional options passed to the grid object} 31 | } 32 | \value{ 33 | c3 34 | } 35 | \description{ 36 | Modify grid and line elements on both x and y axis 37 | } 38 | \examples{ 39 | mtcars \%>\% 40 | c3(x = 'mpg', y = 'wt', group = 'cyl') \%>\% 41 | c3_scatter() \%>\% 42 | grid('y') \%>\% 43 | grid('x', show = FALSE, lines = data.frame(value=c(17, 21), 44 | text= c('Line 1', 'Line 2'))) 45 | 46 | } 47 | \seealso{ 48 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 49 | \code{\link{legend}}, \code{\link{region}}, 50 | \code{\link{subchart}}, \code{\link{tooltip}}, 51 | \code{\link{xAxis}}, \code{\link{zoom}} 52 | } 53 | \concept{c3} 54 | \concept{grid} 55 | -------------------------------------------------------------------------------- /man/legend.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/legend.R 3 | \name{legend} 4 | \alias{legend} 5 | \alias{legend.c3} 6 | \title{C3 Legend Options} 7 | \usage{ 8 | legend(c3, hide = FALSE, position = NULL, inset = NULL, 9 | item = NULL, ...) 10 | 11 | \method{legend}{c3}(c3, hide = FALSE, position = NULL, inset = NULL, 12 | item = NULL, ...) 13 | } 14 | \arguments{ 15 | \item{c3}{c3 htmlwidget object} 16 | 17 | \item{hide}{boolean or character of parameters to hide} 18 | 19 | \item{position}{character one of 'bottom', 'right', 'inset'} 20 | 21 | \item{inset}{list with options: 22 | \itemize{ 23 | \item{anchor}{: character one of 'top-left', 'top-right', 'bottom-left', 'bottom-right'} 24 | \item{x}{: integer pixels} 25 | \item{y}{: integer pixels} 26 | \item{step}{: numeric} 27 | }} 28 | 29 | \item{item}{list with options: 30 | \itemize{ 31 | \item{onclick}{: character js function, wrap character or character vector in JS()} 32 | \item{onmouseover}{: character js function, wrap character or character vector in JS()} 33 | \item{onmouseout}{: character js function, wrap character or character vector in JS()} 34 | }} 35 | 36 | \item{...}{additional options passed to the legend object} 37 | } 38 | \value{ 39 | c3 40 | } 41 | \description{ 42 | Modify plot elements that relate to the legend. The c3 legend is on by default, this function allows the 43 | legend to be removed, or other legend attributes to be set. 44 | } 45 | \examples{ 46 | mtcars \%>\% 47 | c3(x = 'mpg', y = 'wt', group = 'cyl') \%>\% 48 | c3_scatter() \%>\% 49 | legend(position = 'right') 50 | 51 | } 52 | \seealso{ 53 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 54 | \code{\link{grid}}, \code{\link{region}}, 55 | \code{\link{subchart}}, \code{\link{tooltip}}, 56 | \code{\link{xAxis}}, \code{\link{zoom}} 57 | } 58 | \concept{c3} 59 | \concept{legend} 60 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{a \code{\link{c3}} object} 11 | 12 | \item{rhs}{a pie settings function} 13 | } 14 | \description{ 15 | Imports the pipe operator from magrittr. 16 | } 17 | \examples{ 18 | data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) \%>\% 19 | c3() 20 | } 21 | -------------------------------------------------------------------------------- /man/point_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{point_options} 4 | \alias{point_options} 5 | \title{Point Options} 6 | \usage{ 7 | point_options(c3, show = TRUE, r = 2.5, expand = TRUE, 8 | expand.r = 1.75, select.r = 4) 9 | } 10 | \arguments{ 11 | \item{c3}{c3 htmlwidget object} 12 | 13 | \item{show}{boolean} 14 | 15 | \item{r}{numeric radius of point} 16 | 17 | \item{expand}{boolean} 18 | 19 | \item{expand.r}{numeric multiplier for radius expansion} 20 | 21 | \item{select.r}{numeric multiplier for radius expansion} 22 | } 23 | \value{ 24 | c3 25 | } 26 | \description{ 27 | Modify point options 28 | } 29 | \examples{ 30 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 31 | c3() \%>\% 32 | point_options(r = 5, expand.r = 2) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/region.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/region.R 3 | \name{region} 4 | \alias{region} 5 | \alias{region.c3} 6 | \title{Modify region elements on both x and y axis} 7 | \usage{ 8 | region(c3, regions) 9 | 10 | \method{region}{c3}(c3, regions) 11 | } 12 | \arguments{ 13 | \item{c3}{c3 htmlwidget object} 14 | 15 | \item{regions}{data.frame with columns listed below. Any columns can be missing but results may be unexpected. 16 | \itemize{ 17 | \item{axis}{: character one of 'x', 'y', 'y2'} 18 | \item{start}{: numeric but must match defined axis type} 19 | \item{end}{: numeric but must match defined axis type} 20 | \item{class}{: character css class} 21 | }} 22 | } 23 | \value{ 24 | c3 25 | } 26 | \description{ 27 | Regions are defined in multiple axis by passing a single `data.frame` 28 | } 29 | \examples{ 30 | mtcars \%>\% 31 | c3(x = 'mpg', y = 'wt', group = 'cyl') \%>\% 32 | c3_scatter() \%>\% 33 | region(data.frame(axis = 'x', 34 | start = 17, 35 | end = 21)) 36 | 37 | } 38 | \seealso{ 39 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 40 | \code{\link{grid}}, \code{\link{legend}}, 41 | \code{\link{subchart}}, \code{\link{tooltip}}, 42 | \code{\link{xAxis}}, \code{\link{zoom}} 43 | } 44 | \concept{c3} 45 | \concept{region} 46 | -------------------------------------------------------------------------------- /man/subchart.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subchart.R 3 | \name{subchart} 4 | \alias{subchart} 5 | \alias{subchart.c3} 6 | \title{Add Subchart} 7 | \usage{ 8 | subchart(c3, height = 20, onbrush = NULL) 9 | 10 | \method{subchart}{c3}(c3, height = 20, onbrush = NULL) 11 | } 12 | \arguments{ 13 | \item{c3}{c3 htmlwidget object} 14 | 15 | \item{height}{integer pixels} 16 | 17 | \item{onbrush}{character js function, wrap character or character vector in JS()} 18 | } 19 | \value{ 20 | c3 21 | } 22 | \description{ 23 | Subcharts are defined in multiple axis by passing a single `data.frame`. Subcharts are listed as an 24 | experimental feature in the \href{http://c3js.org/reference.html#subchart-onbrush}{C3 documentation}). 25 | } 26 | \examples{ 27 | data.frame(a = abs(rnorm(20) * 10), 28 | b = abs(rnorm(20) * 10), 29 | date = seq(as.Date("2014-01-01"), by = "month", length.out = 20)) \%>\% 30 | c3(x = 'date') \%>\% 31 | subchart(height = 20, onbrush = 'function (domain) { console.log(domain) }') 32 | 33 | } 34 | \seealso{ 35 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 36 | \code{\link{grid}}, \code{\link{legend}}, 37 | \code{\link{region}}, \code{\link{tooltip}}, 38 | \code{\link{xAxis}}, \code{\link{zoom}} 39 | } 40 | \concept{c3} 41 | \concept{subchart} 42 | -------------------------------------------------------------------------------- /man/tickAxis.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{tickAxis} 4 | \alias{tickAxis} 5 | \title{Axis Tick Options} 6 | \usage{ 7 | tickAxis(c3, axis, centered = TRUE, format = NULL, culling = NULL, 8 | count = NULL, fit = TRUE, values = NULL, rotate = 0, 9 | outer = TRUE, ...) 10 | } 11 | \arguments{ 12 | \item{c3}{c3 htmlwidget object} 13 | 14 | \item{axis}{character 'x', 'y' or 'y2' axis} 15 | 16 | \item{centered}{boolean (x-axis only)} 17 | 18 | \item{format}{character js function, wrap character or character vector in JS()} 19 | 20 | \item{culling}{boolean or list defining number of ticks `list(max = 5)` this 21 | option effects tick labels (x-axis only)} 22 | 23 | \item{count}{integer number of ticks to display. This effects tick lines and labels} 24 | 25 | \item{fit}{boolean position ticks evenly or set to values (x-axis only)} 26 | 27 | \item{values}{vector. Must match axis format type} 28 | 29 | \item{rotate}{integer degrees to rotate labels (x-axis only)} 30 | 31 | \item{outer}{boolean show axis outer tick} 32 | 33 | \item{...}{additional options passed to axis tick object} 34 | } 35 | \value{ 36 | c3 37 | } 38 | \description{ 39 | Modify axis tick formatting options 40 | } 41 | \examples{ 42 | data.frame(a = c(1,2,3,2), b = c(2,4,1,5)) \%>\% 43 | c3() \%>\% 44 | tickAxis('y', values = c(1,3)) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/tooltip.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tooltip.R 3 | \name{tooltip} 4 | \alias{tooltip} 5 | \alias{tooltip.c3} 6 | \title{C3 Tooltips} 7 | \usage{ 8 | tooltip(c3, show = TRUE, grouped = TRUE, format = NULL, 9 | position = NULL, contents = NULL, ...) 10 | 11 | \method{tooltip}{c3}(c3, show = TRUE, grouped = TRUE, format = NULL, 12 | position = NULL, contents = NULL, ...) 13 | } 14 | \arguments{ 15 | \item{c3}{c3 htmlwidget object} 16 | 17 | \item{show}{boolean show or hide tooltips} 18 | 19 | \item{grouped}{boolean} 20 | 21 | \item{format}{list with options: 22 | \itemize{ 23 | \item{title}{: character js function, wrap character or character vector in JS()} 24 | \item{name}{: character js function, wrap character or character vector in JS()} 25 | \item{value}{: character js function, wrap character or character vector in JS()} 26 | }} 27 | 28 | \item{position}{character js function, wrap character or character vector in JS()} 29 | 30 | \item{contents}{character js function, wrap character or character vector in JS()} 31 | 32 | \item{...}{addition options passed to the tooltip object} 33 | } 34 | \value{ 35 | c3 36 | } 37 | \description{ 38 | Modify plot elements that relate to tooltips. C3.js documentation contains an \href{http://c3js.org/samples/tooltip_format.html}{extended example}. 39 | } 40 | \examples{ 41 | data <- data.frame(a = abs(rnorm(20) *10), 42 | b = abs(rnorm(20) *10), 43 | c = abs(rnorm(20) *10), 44 | d = abs(rnorm(20) *10)) 45 | data \%>\% 46 | c3() \%>\% 47 | tooltip(format = list(title = htmlwidgets::JS("function (x) { return 'Data ' + x; }"), 48 | name = htmlwidgets::JS('function (name, ratio, id, index)', 49 | ' { return name; }'), 50 | value = htmlwidgets::JS('function (value, ratio, id, index)', 51 | ' { return ratio; }'))) 52 | 53 | } 54 | \seealso{ 55 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 56 | \code{\link{grid}}, \code{\link{legend}}, 57 | \code{\link{region}}, \code{\link{subchart}}, 58 | \code{\link{xAxis}}, \code{\link{zoom}} 59 | } 60 | \concept{c3} 61 | \concept{tooltip} 62 | -------------------------------------------------------------------------------- /man/xAxis.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/options.R 3 | \name{xAxis} 4 | \alias{xAxis} 5 | \alias{xAxis.c3} 6 | \alias{yAxis} 7 | \alias{yAxis.c3} 8 | \alias{y2Axis} 9 | \alias{y2Axis.c3} 10 | \title{C3 Axis} 11 | \usage{ 12 | xAxis(c3, show = TRUE, type = "indexed", localtime = NULL, 13 | categories = NULL, max = NULL, min = NULL, padding = list(), 14 | height = NULL, extent = NULL, label = NULL, ...) 15 | 16 | \method{xAxis}{c3}(c3, show = TRUE, type = "indexed", 17 | localtime = NULL, categories = NULL, max = NULL, min = NULL, 18 | padding = list(), height = NULL, extent = NULL, label = NULL, 19 | ...) 20 | 21 | yAxis(c3, show = TRUE, inner = NULL, max = NULL, min = NULL, 22 | padding = NULL, inverted = NULL, center = NULL, label = NULL, 23 | ...) 24 | 25 | \method{yAxis}{c3}(c3, show = TRUE, inner = NULL, max = NULL, 26 | min = NULL, padding = NULL, inverted = NULL, center = NULL, 27 | label = NULL, ...) 28 | 29 | y2Axis(c3, show = TRUE, inner = NULL, max = NULL, min = NULL, 30 | padding = NULL, inverted = NULL, center = NULL, label = NULL, 31 | ...) 32 | 33 | \method{y2Axis}{c3}(c3, show = TRUE, inner = NULL, max = NULL, 34 | min = NULL, padding = NULL, inverted = NULL, center = NULL, 35 | label = NULL, ...) 36 | } 37 | \arguments{ 38 | \item{c3}{c3 htmlwidget object} 39 | 40 | \item{show}{boolean} 41 | 42 | \item{type}{character on of 'indexed', timeseries' or 'category'} 43 | 44 | \item{localtime}{boolean} 45 | 46 | \item{categories}{character vector. Can be used to modify axis labels. Not needed if 47 | already defined in data} 48 | 49 | \item{max}{numeric set value of axis range} 50 | 51 | \item{min}{numeric set value of axis range} 52 | 53 | \item{padding}{list with options: 54 | \itemize{ 55 | \item{left}{: numeric pixels} 56 | \item{right}{: numeric pixels} 57 | }} 58 | 59 | \item{height}{integer pixels to set height of axis} 60 | 61 | \item{extent}{vector or character function (wrapped in JS()) that returns a vector of values} 62 | 63 | \item{label}{can be character or list with options (see \href{http://c3js.org/reference.html#axis-x-label}{c3 axis-x-label}): 64 | \itemize{ 65 | \item{text}{: character} 66 | \item{position}{: character} 67 | } 68 | label position options for horizontal axis are: 69 | \itemize{ 70 | \item{inner-right} 71 | \item{inner-center} 72 | \item{inner-left} 73 | \item{outer-right} 74 | \item{outer-center} 75 | \item{outer-left} 76 | } 77 | label position options for vertical axis are: 78 | \itemize{ 79 | \item{inner-top} 80 | \item{inner-middle} 81 | \item{inner-bottom} 82 | \item{outer-top} 83 | \item{outer-middle} 84 | \item{outer-bottom} 85 | }} 86 | 87 | \item{...}{additional options passed to the axis object} 88 | 89 | \item{inner}{boolean show axis inside chart (Y and Y2 axis only)} 90 | 91 | \item{inverted}{boolean TRUE will reverse the direction of the axis (Y and Y2 axis only)} 92 | 93 | \item{center}{integer or numeric value for center line (Y and Y2 axis only)} 94 | } 95 | \value{ 96 | c3 97 | } 98 | \description{ 99 | Modify plot elements that relate to the axis. 100 | } 101 | \examples{ 102 | data.frame(a=c(1,2,3,2),b=c(2,3,1,5)) \%>\% 103 | c3(axes = list(a = 'y', 104 | b = 'y2')) \%>\% 105 | xAxis(label = list(text = 'testing', 106 | position = 'inner-center')) \%>\% 107 | y2Axis() 108 | 109 | } 110 | \seealso{ 111 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 112 | \code{\link{grid}}, \code{\link{legend}}, 113 | \code{\link{region}}, \code{\link{subchart}}, 114 | \code{\link{tooltip}}, \code{\link{zoom}} 115 | } 116 | \concept{c3} 117 | \concept{xAxis} 118 | \concept{y2Axis} 119 | \concept{yAxis} 120 | -------------------------------------------------------------------------------- /man/zoom.c3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoom.R 3 | \name{zoom} 4 | \alias{zoom} 5 | \alias{zoom.c3} 6 | \title{Add C3 Zoom} 7 | \usage{ 8 | zoom(c3, enabled = TRUE, rescale = NULL, extent = NULL, 9 | onzoom = NULL, onzoomstart = NULL, onzoomend = NULL, ...) 10 | 11 | \method{zoom}{c3}(c3, enabled = TRUE, rescale = NULL, extent = NULL, 12 | onzoom = NULL, onzoomstart = NULL, onzoomend = NULL, ...) 13 | } 14 | \arguments{ 15 | \item{c3}{c3 htmlwidget object} 16 | 17 | \item{enabled}{boolean default is TRUE} 18 | 19 | \item{rescale}{boolean rescale axis when zooming} 20 | 21 | \item{extent}{numeric vector} 22 | 23 | \item{onzoom}{character js function, wrap character or character vector in JS()} 24 | 25 | \item{onzoomstart}{character js function, wrap character or character vector in JS()} 26 | 27 | \item{onzoomend}{character js function, wrap character or character vector in JS()} 28 | 29 | \item{...}{additional options passed to the zoom object} 30 | } 31 | \value{ 32 | c3 33 | } 34 | \description{ 35 | Enable chart Zoom. 36 | } 37 | \examples{ 38 | data.frame(a = abs(rnorm(20) * 10), 39 | b = abs(rnorm(20) * 10)) \%>\% 40 | c3() \%>\% 41 | zoom() 42 | 43 | } 44 | \seealso{ 45 | Other c3: \code{\link{RColorBrewer}}, \code{\link{c3}}, 46 | \code{\link{grid}}, \code{\link{legend}}, 47 | \code{\link{region}}, \code{\link{subchart}}, 48 | \code{\link{tooltip}}, \code{\link{xAxis}} 49 | } 50 | \concept{c3} 51 | \concept{zoom} 52 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(jsonlite) 3 | library(c3) 4 | 5 | test_check("c3") 6 | -------------------------------------------------------------------------------- /tests/testthat/test_c3.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | context('main package') 4 | 5 | 6 | 7 | d <- data.frame(a = abs(rnorm(20) * 10), 8 | b = abs(rnorm(20) * 10), 9 | date = seq(as.Date("2014-01-01"), by = "month", length.out = 20), 10 | stringsAsFactors = TRUE) 11 | 12 | d$c <- abs(rnorm(20) *10) 13 | d$d <- abs(rnorm(20) *10) 14 | 15 | cp <- c3(d) 16 | 17 | 18 | test_that("a simple plot works", { 19 | expect_is(cp, "c3") 20 | expect_is(cp, "htmlwidget") 21 | }) 22 | 23 | 24 | 25 | test_that('data structure is in the expected format', { 26 | 27 | expect_is(cp$x$data$json, 'json') 28 | 29 | }) 30 | 31 | test_that('the data structure can be converted', { 32 | 33 | df <- fromJSON(cp$x$data$json) 34 | 35 | expect_is(df, 'data.frame') 36 | expect_equal(colnames(df), c('a','b','c','d')) 37 | expect_equal(nrow(df), 20) 38 | 39 | }) 40 | 41 | 42 | context('color palettes') 43 | 44 | test_that('colors can be set by RColorBrewer', { 45 | 46 | brw <- RColorBrewer(cp, 'Dark2') 47 | 48 | expect_equal(brw$x$color$pattern[1], "#1B9E77") 49 | 50 | expect_is(brw, "c3") 51 | expect_is(brw, "htmlwidget") 52 | 53 | }) 54 | 55 | 56 | test_that('colors can be set by viridis', { 57 | 58 | vir <- c3_viridis(cp) 59 | 60 | expect_equal(vir$x$color$pattern[1], "#440154") 61 | 62 | expect_is(vir, "c3") 63 | expect_is(vir, "htmlwidget") 64 | 65 | }) 66 | 67 | 68 | test_that('colors can be set manually', { 69 | 70 | clr <- c3_colour(cp, c('red','black','orange','green')) 71 | 72 | expect_equal(clr$x$color$pattern[1], "red") 73 | 74 | expect_is(clr, "c3") 75 | expect_is(clr, "htmlwidget") 76 | 77 | }) 78 | 79 | 80 | context('grid.R') 81 | 82 | test_that('grids can be added', { 83 | 84 | grd <- grid(cp,'y') 85 | 86 | expect_true(grd$x$grid$y$show) 87 | 88 | expect_is(grd, "c3") 89 | expect_is(grd, "htmlwidget") 90 | 91 | }) 92 | 93 | 94 | 95 | context('legend.R') 96 | 97 | test_that('legends can be removed', { 98 | 99 | lgd <- legend(cp, hide = TRUE) 100 | 101 | expect_true(lgd$x$legend$hide) 102 | 103 | expect_is(lgd, "c3") 104 | expect_is(lgd, "htmlwidget") 105 | 106 | }) 107 | 108 | 109 | test_that('legends attribute can be modified', { 110 | 111 | lgd <- legend(cp, position = 'right') 112 | 113 | expect_equal(lgd$x$legend$position, 'right') 114 | expect_false(lgd$x$legend$hide) 115 | 116 | expect_is(lgd, "c3") 117 | expect_is(lgd, "htmlwidget") 118 | 119 | }) 120 | 121 | 122 | context('region.R') 123 | 124 | test_that('regions can be added', { 125 | 126 | reg <- region(cp, data.frame(axis = 'x', 127 | start = 5, 128 | end = 12, 129 | stringsAsFactors = TRUE)) 130 | 131 | expect_error(region(cp, data.frame(axis = 'x', 132 | start = 5, 133 | error = 4, 134 | stringsAsFactors = TRUE)) 135 | ) 136 | 137 | expect_equal(reg$x$regions$start, 5) 138 | expect_equal(reg$x$regions$axis, factor('x')) 139 | 140 | expect_is(reg, "c3") 141 | expect_is(reg, "htmlwidget") 142 | 143 | }) 144 | 145 | 146 | 147 | context('subchart.R') 148 | 149 | test_that('subcharts can be added', { 150 | 151 | sbc <- subchart(cp) 152 | 153 | expect_true(sbc$x$subchart$show) 154 | expect_equal(sbc$x$subchart$size$height, 20) 155 | 156 | expect_is(sbc, "c3") 157 | expect_is(sbc, "htmlwidget") 158 | 159 | }) 160 | 161 | test_that('subcharts attributes can be set', { 162 | 163 | sbc <- subchart(cp, height = 50) 164 | 165 | expect_true(sbc$x$subchart$show) 166 | expect_equal(sbc$x$subchart$size$height, 50) 167 | 168 | expect_is(sbc, "c3") 169 | expect_is(sbc, "htmlwidget") 170 | 171 | }) 172 | 173 | test_that('subcharts onbrush attributes can be set', { 174 | 175 | b1 <- subchart(cp, onbrush = 'function (domain) { console.log(domain) }') 176 | b2 <- subchart(cp, onbrush = JS('function (domain) { console.log(domain) }')) 177 | 178 | expect_is(b1$x$subchart$onbrush, "JS_EVAL") 179 | expect_is(b2$x$subchart$onbrush, "JS_EVAL") 180 | 181 | expect_is(b1, "c3") 182 | expect_is(b1, "htmlwidget") 183 | expect_is(b2, "c3") 184 | expect_is(b2, "htmlwidget") 185 | 186 | }) 187 | 188 | context('tooltip.R') 189 | 190 | test_that('tooltips can be switched off', { 191 | 192 | tt <- tooltip(cp, show = FALSE) 193 | 194 | expect_false(tt$x$tooltip$show) 195 | 196 | expect_is(tt, "c3") 197 | expect_is(tt, "htmlwidget") 198 | 199 | }) 200 | 201 | 202 | test_that('tooltips attributes can be set', { 203 | 204 | tt <- tooltip(cp, grouped = FALSE) 205 | 206 | expect_false(tt$x$tooltip$grouped) 207 | 208 | expect_is(tt, "c3") 209 | expect_is(tt, "htmlwidget") 210 | 211 | }) 212 | 213 | 214 | context('zoom.R') 215 | 216 | test_that('zoom settings work', { 217 | 218 | zm <- zoom(cp, rescale = TRUE) 219 | 220 | expect_true(zm$x$zoom$enabled) 221 | expect_true(zm$x$zoom$rescale) 222 | 223 | expect_is(zm, "c3") 224 | expect_is(zm, "htmlwidget") 225 | 226 | }) 227 | 228 | 229 | context('Tibble Compatibility') 230 | 231 | test_that('Tibble x axis can be defined', { 232 | 233 | d <- dplyr::as_tibble(d) 234 | 235 | cp <- c3(d, x = 'date') 236 | 237 | expect_is(cp, "c3") 238 | expect_is(cp, "htmlwidget") 239 | 240 | }) 241 | -------------------------------------------------------------------------------- /tests/testthat/test_options.R: -------------------------------------------------------------------------------- 1 | 2 | d <- data.frame(a = abs(rnorm(20) * 10), 3 | b = abs(rnorm(20) * 10), 4 | date = seq(as.Date("2014-01-01"), by = "month", length.out = 20)) 5 | 6 | 7 | context('options') 8 | 9 | 10 | test_that('xaxis options can be set', { 11 | 12 | cp <- c3(d, x = 'date') 13 | cx <- xAxis(cp, type = 'timeseries', label = list(text = 'testing', 14 | position = 'inner-center')) 15 | 16 | expect_true(cx$x$axis$x$show) 17 | expect_equal(cx$x$axis$x$type, 'timeseries') 18 | expect_equal(cx$x$axis$x$label$text, 'testing') 19 | expect_equal(cx$x$axis$x$label$position, 'inner-center') 20 | 21 | expect_is(cx, "c3") 22 | expect_is(cx, "htmlwidget") 23 | 24 | }) 25 | 26 | test_that('xaxis warnings work', { 27 | 28 | cp <- c3(d, x = 'b') 29 | 30 | # where non-timeseries column is specified 31 | expect_warning(xAxis(cp, type = 'timeseries')) 32 | 33 | }) 34 | 35 | 36 | test_that('yaxis can be removed', { 37 | 38 | cp <- c3(d) 39 | cy <- yAxis(cp, show = FALSE) 40 | 41 | expect_false(cy$x$axis$y$show) 42 | 43 | expect_is(cy, "c3") 44 | expect_is(cy, "htmlwidget") 45 | 46 | }) 47 | 48 | 49 | test_that('yaxis options can be set', { 50 | 51 | cp <- c3(d) 52 | cy <- yAxis(cp, label = 'Testing', inverted = TRUE, center = TRUE) 53 | 54 | expect_true(cy$x$axis$y$show) 55 | expect_true(cy$x$axis$y$inverted) 56 | expect_true(cy$x$axis$y$center) 57 | expect_equal(cy$x$axis$y$label, 'Testing') 58 | 59 | expect_is(cy, "c3") 60 | expect_is(cy, "htmlwidget") 61 | 62 | }) 63 | 64 | 65 | test_that('second yaxis can be set', { 66 | 67 | cp <- c3(d, 68 | x = 'date', 69 | axes = list(a = 'y', 70 | b = 'y2')) 71 | cy <- y2Axis(cp) 72 | 73 | expect_true(cy$x$axis$y2$show) 74 | 75 | expect_is(cy, "c3") 76 | expect_is(cy, "htmlwidget") 77 | 78 | }) 79 | 80 | ## tickAxis() 81 | 82 | test_that('axis tick options can be set', { 83 | 84 | cp <- c3(d, x = 'date') 85 | 86 | tkx <- tickAxis(cp, 'x', culling = list(max = 3), centered = FALSE, rotate = 45) 87 | tky1 <- tickAxis(cp, 'y', values = c(0,10,20)) 88 | tky2 <- tickAxis(cp, 'y', count = 5, outer = FALSE) 89 | 90 | expect_false(tkx$x$axis$x$tick$centered) 91 | expect_equal(tkx$x$axis$x$tick$rotate, 45) 92 | expect_equal(tkx$x$axis$x$tick$culling$max, 3) 93 | 94 | expect_equal(tky1$x$axis$y$tick$values, c(0,10,20)) 95 | 96 | expect_false(tky2$x$axis$y$tick$outer) 97 | expect_equal(tky2$x$axis$y$tick$count, 5) 98 | 99 | expect_is(tky2, "c3") 100 | expect_is(tky2, "htmlwidget") 101 | 102 | }) 103 | 104 | 105 | 106 | ## c3_selection() 107 | 108 | test_that('selection works as expected', { 109 | 110 | cp <- c3(d, x = 'date') 111 | 112 | sl <- c3_selection(cp, enabled = TRUE, multiple = TRUE) 113 | 114 | expect_true(sl$x$data$selection$enabled) 115 | expect_true(sl$x$data$selection$multiple) 116 | 117 | expect_false(sl$x$data$selection$grouped) 118 | expect_false(sl$x$data$selection$draggable) 119 | 120 | expect_is(sl$x$data$selection$isselectable, "JS_EVAL") 121 | 122 | expect_is(sl, "c3") 123 | expect_is(sl, "htmlwidget") 124 | 125 | }) 126 | 127 | 128 | 129 | ## c3_chart_size() 130 | 131 | test_that('chart size options can be set', { 132 | 133 | cp <- c3(d, x = 'date') 134 | 135 | sz <- c3_chart_size(cp, left = 20, right = 20, top = 20, bottom = 20, width = 600, height = 200) 136 | 137 | expect_equal(sz$x$size$height, 200) 138 | expect_equal(sz$x$size$width, 600) 139 | 140 | expect_equal(sz$x$padding$left, 20) 141 | expect_equal(sz$x$padding$right, 20) 142 | expect_equal(sz$x$padding$top, 20) 143 | expect_equal(sz$x$padding$bottom, 20) 144 | 145 | expect_is(sz, "c3") 146 | expect_is(sz, "htmlwidget") 147 | 148 | }) 149 | 150 | 151 | ## point_options() 152 | 153 | test_that('point options can be set', { 154 | 155 | cp <- c3(d, x = 'date') 156 | 157 | pt <- point_options(cp, show = TRUE, r = 10, expand = TRUE, expand.r = 2, select.r = 15) 158 | 159 | expect_true(pt$x$point$show) 160 | expect_true(pt$x$point$focus$expand$enabled) 161 | 162 | expect_equal(pt$x$point$focus$expand$r, 20) # r * expand.r 163 | expect_equal(pt$x$point$r, 10) 164 | expect_equal(pt$x$point$select$r, 150) # r * select.r 165 | 166 | expect_is(pt, "c3") 167 | expect_is(pt, "htmlwidget") 168 | 169 | }) 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /tests/testthat/test_plots.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | context('plots') 4 | 5 | 6 | d <- data.frame(a = abs(rnorm(20) * 10), 7 | b = abs(rnorm(20) * 10), 8 | date = seq(as.Date("2014-01-01"), by = "month", length.out = 20)) 9 | 10 | d$c <- abs(rnorm(20) *10) 11 | d$d <- abs(rnorm(20) *10) 12 | 13 | cp <- c3(d) 14 | 15 | 16 | 17 | context('c3_bar()') 18 | 19 | test_that("bar plots works", { 20 | 21 | br <- c3_bar(cp) 22 | 23 | expect_equal(br$x$data$type, 'bar') 24 | 25 | expect_is(br, "c3") 26 | expect_is(br, "htmlwidget") 27 | 28 | }) 29 | 30 | test_that('bar plots settings can be set', { 31 | 32 | br <- c3_bar(cp, stacked = TRUE, rotated = TRUE) 33 | grp <- fromJSON(br$x$data$groups)$value # indicates stacking 34 | 35 | expect_true(br$x$axis$rotated) 36 | expect_equal(grp, c("a","b","c","d")) 37 | 38 | }) 39 | 40 | 41 | context('c3_line()') 42 | 43 | test_that("C3 line options can be set", { 44 | 45 | cl <- c3_line(cp, 'spline') 46 | cs <- c3_line(cp, 'step', stacked = TRUE, step_type = 'step') 47 | grp <- fromJSON(cs$x$data$groups)$value # indicates stacking 48 | 49 | expect_error(c3_line(cp)) #line type not being defined 50 | 51 | expect_equal(cl$x$data$type, 'spline') 52 | expect_equal(cs$x$data$type, 'step') 53 | expect_equal(grp, c("a","b","c","d")) 54 | 55 | expect_is(cl, "c3") 56 | expect_is(cl, "htmlwidget") 57 | 58 | }) 59 | 60 | test_that('Null values can be connected', { 61 | 62 | d <- data.frame(a = c(1,2,3,2), b = c(2,NA,1,5)) 63 | p <- c3(d) 64 | 65 | cp <- c3_line(p, 'line', connectNull = TRUE) 66 | 67 | expect_true(cp$x$line$connectNull) 68 | 69 | }) 70 | 71 | context('c3_mixedgeometry()') 72 | 73 | test_that("C3 mixed geometry options can be set", { 74 | 75 | typs <- list(a='area', 76 | c='spline') 77 | stk <- c('b','d') 78 | mg <- c3_mixedGeom(cp, types = typs, stacked = stk) 79 | grp <- fromJSON(mg$x$data$groups) # indicates stacking 80 | 81 | expect_equal(mg$x$data$type, 'line') # default value 82 | expect_equal(mg$x$data$types$a, 'area') 83 | expect_equal(mg$x$data$types$c, 'spline') 84 | expect_equal(grp, stk) 85 | 86 | expect_is(mg, "c3") 87 | expect_is(mg, "htmlwidget") 88 | 89 | }) 90 | 91 | 92 | context('c3_scatter()') 93 | 94 | test_that('scatter plots work', { 95 | 96 | sp <- c3(mtcars, 97 | x = 'mpg', 98 | y = 'wt', 99 | group = 'cyl') 100 | 101 | sc <- c3_scatter(sp) 102 | 103 | expect_is(sc, "c3") 104 | expect_is(sc, "htmlwidget") 105 | 106 | 107 | }) 108 | 109 | 110 | 111 | context('c3_pie()') 112 | 113 | test_that('Pie charts work', { 114 | 115 | pd <- c3(data.frame(red=20,green=45,blue=10)) 116 | 117 | pid <- c3_pie(pd) 118 | 119 | expect_equal(pid$x$data$type, 'pie') 120 | 121 | expect_is(pid, "c3") 122 | expect_is(pid, "htmlwidget") 123 | 124 | }) 125 | 126 | 127 | context('c3_donut()') 128 | 129 | test_that('Donut charts work', { 130 | 131 | d <- c3(data.frame(red=20,green=45,blue=10)) 132 | 133 | dc <- c3_donut(d, title = "test") 134 | 135 | expect_equal(dc$x$data$type, 'donut') 136 | expect_equal(dc$x$donut$title, 'test') 137 | 138 | expect_is(dc, "c3") 139 | expect_is(dc, "htmlwidget") 140 | 141 | }) 142 | 143 | 144 | 145 | context('c3_guage()') 146 | 147 | test_that('Guage charts work', { 148 | 149 | d <- c3(data.frame(data = 10)) 150 | c <- c3_gauge(d, title = "test") 151 | 152 | expect_equal(c$x$data$type, 'gauge') 153 | 154 | expect_is(c, "c3") 155 | expect_is(c, "htmlwidget") 156 | 157 | }) 158 | 159 | --------------------------------------------------------------------------------