Skip to content

Commit 4d9e015

Browse files
committed
Initial commit
0 parents  commit 4d9e015

20 files changed

+439
-0
lines changed

.Rbuildignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
^chartjs\.Rproj$
2+
^\.Rproj\.user$
3+
^README\.Rmd$
4+
^LICENSE\.md$

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.Rproj.user
2+
.Rhistory
3+
.Rdata
4+
.httr-oauth
5+
.DS_Store

DESCRIPTION

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Package: chartjs
2+
Title: What the Package Does (One Line, Title Case)
3+
Version: 0.0.0.9000
4+
Authors@R:
5+
person("First", "Last", , "[email protected]", role = c("aut", "cre"),
6+
comment = c(ORCID = "YOUR-ORCID-ID"))
7+
Description: What the package does (one paragraph).
8+
License: MIT + file LICENSE
9+
Encoding: UTF-8
10+
Roxygen: list(markdown = TRUE)
11+
RoxygenNote: 7.2.1

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2022
2+
COPYRIGHT HOLDER: chartjs authors

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2022 chartjs authors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(chartjs)
4+
export(chartjsOutput)
5+
export(renderChartjs)
6+
import(htmlwidgets)

R/chartjs.R

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#' Chartjs widget
2+
#'
3+
#' Basic Chartjs widget
4+
#'
5+
#' @import htmlwidgets
6+
#'
7+
#' @export
8+
chartjs <- function(data, x, y, type = 'bar', width = NULL, height = NULL, elementId = NULL) {
9+
10+
data <-
11+
dplyr::select(
12+
data,
13+
x = {{ x }},
14+
y = {{ y }},
15+
)
16+
17+
# forward options using x
18+
x = list(
19+
data = data,
20+
type = type
21+
)
22+
23+
# create widget
24+
htmlwidgets::createWidget(
25+
name = 'chartjs',
26+
x,
27+
width = width,
28+
height = height,
29+
package = 'chartjs',
30+
elementId = elementId
31+
)
32+
}
33+
34+
chartjs_html <- function(...){
35+
htmltools::tags$div(
36+
htmltools::tags$canvas(...)
37+
)
38+
}
39+
40+
#' Shiny bindings for chartjs
41+
#'
42+
#' Output and render functions for using chartjs within Shiny
43+
#' applications and interactive Rmd documents.
44+
#'
45+
#' @param outputId output variable to read from
46+
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
47+
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
48+
#' string and have \code{'px'} appended.
49+
#' @param expr An expression that generates a chartjs
50+
#' @param env The environment in which to evaluate \code{expr}.
51+
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
52+
#' is useful if you want to save an expression in a variable.
53+
#'
54+
#' @name chartjs-shiny
55+
#'
56+
#' @export
57+
chartjsOutput <- function(outputId, width = '100%', height = '400px'){
58+
htmlwidgets::shinyWidgetOutput(outputId, 'chartjs', width, height, package = 'chartjs')
59+
}
60+
61+
#' @rdname chartjs-shiny
62+
#' @export
63+
renderChartjs <- function(expr, env = parent.frame(), quoted = FALSE) {
64+
if (!quoted) { expr <- substitute(expr) } # force quoted
65+
htmlwidgets::shinyRenderWidget(expr, chartjsOutput, env, quoted = TRUE)
66+
}

R/download_chartjs.R

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#' Download Chartjs built files
2+
#'
3+
#' @description
4+
#' Download built Chartjs files to package library `inst/htmlwidgets/lib/Chart.js-{version}`
5+
#'
6+
#' @param version version to download
7+
download_chartjs <- function(version = '4.1.1'){
8+
9+
dir =
10+
paste0('inst/htmlwidgets/lib/Chart.js-', version)
11+
12+
dir.create(dir, recursive = TRUE)
13+
14+
chartjs <-
15+
file.path(
16+
"https://cdnjs.cloudflare.com/ajax",
17+
"libs/Chart.js",
18+
version,
19+
"chart.umd.js"
20+
)
21+
22+
download.file(chartjs, destfile = file.path(dir, "chart.umd.js"))
23+
}

README.Rmd

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
output: github_document
3+
---
4+
5+
<!-- README.md is generated from README.Rmd. Please edit that file -->
6+
7+
```{r, include = FALSE}
8+
knitr::opts_chunk$set(
9+
collapse = TRUE,
10+
comment = "#>",
11+
fig.path = "man/figures/README-",
12+
out.width = "100%"
13+
)
14+
```
15+
16+
# chartjs
17+
18+
<!-- badges: start -->
19+
<!-- badges: end -->
20+
21+
The goal of chartjs is to ...
22+
23+
## Installation
24+
25+
You can install the development version of chartjs like so:
26+
27+
``` r
28+
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
29+
```
30+
31+
## Example
32+
33+
## Dev notes
34+
35+
How to build the package following chartjs design?

chartjs.Rproj

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
LineEndingConversion: Posix
18+
19+
BuildType: Package
20+
PackageUseDevtools: Yes
21+
PackageInstallArgs: --no-multiarch --with-keep.source
22+
PackageRoxygenize: rd,collate,namespace

inst/htmlwidgets/chartjs.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
HTMLWidgets.widget({
2+
3+
name: 'chartjs',
4+
5+
type: 'output',
6+
7+
factory: function(el, width, height) {
8+
9+
// TODO: define shared variables for this instance
10+
11+
return {
12+
13+
renderValue: function(x) {
14+
15+
console.log(x)
16+
17+
new Chart(el,
18+
{
19+
type: x.type,
20+
data: {
21+
labels: x.data.x,
22+
datasets: [
23+
{
24+
label: 'COMPLETE_ME',
25+
data: x.data.y
26+
}
27+
]
28+
}
29+
}
30+
);
31+
},
32+
33+
resize: function(width, height) {
34+
35+
// TODO: code to re-render the widget with a new size
36+
37+
}
38+
39+
};
40+
}
41+
});

inst/htmlwidgets/chartjs.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dependencies:
2+
- name: Chart.js
3+
version: 4.1.1
4+
src: htmlwidgets/lib/Chart.js-4.1.1
5+
script: chart.umd.js

inst/htmlwidgets/lib/Chart.js-2.1.0/Chart.min.js

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2013-2016 Nick Downie
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

inst/htmlwidgets/lib/Chart.js-4.1.1/chart.umd.js

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2011-2016 Tim Wood, Iskren Chernev, Moment.js contributors
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

inst/htmlwidgets/lib/Moment.js-2.0.13/moment-with-locales.min.js

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/chartjs-shiny.Rd

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/chartjs.Rd

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/download_chartjs.Rd

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)