Skip to content

Commit

Permalink
updated billboard.js to 3.10.2
Browse files Browse the repository at this point in the history
added bb_padding()
updated bb_labs(caption = )
  • Loading branch information
pvictor committed Oct 31, 2023
1 parent dd5b3bc commit 97bca13
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 130 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: billboarder
Title: Create Interactive Chart with the JavaScript 'Billboard' Library
Version: 0.4.1.9000
Version: 0.4.1.9010
Authors@R: c(
person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre")),
person("Fanny", "Meyer", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export(bb_line)
export(bb_linechart)
export(bb_load)
export(bb_lollipop)
export(bb_padding)
export(bb_pie)
export(bb_piechart)
export(bb_point)
Expand Down
28 changes: 18 additions & 10 deletions R/bb_labs.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param x Text for x axis title.
#' @param y Text for y axis title.
#' @param caption Text for the caption displayed in the bottom-right of the chart.
#' @param caption_href Associate the caption with a link to an URL.
#' @param ... Not used.
#'
#' @return A \code{billboard} \code{htmlwidget} object.
#' @export
Expand All @@ -27,7 +27,23 @@
#' caption = "Data source: RTE (https://opendata.reseaux-energies.fr/)",
#' caption_href = "https://opendata.reseaux-energies.fr/"
#' )
bb_labs <- function(bb, title = NULL, x = NULL, y = NULL, caption = NULL, caption_href = NULL) {
bb_labs <- function(bb, title = NULL, x = NULL, y = NULL, caption = NULL, ...) {

if (!is.null(caption)) {
# bb <- .bb_opt2(bb, "caption", l = dropNulls(list(
# text = caption,
# href = caption_href
# )))
# bb <- .bb_opt(bb, "padding", bottom = 10)
if (is.null(title))
title <- ""
title <- paste(title, caption, sep = "\n")
bb <- bb_add_style(
bb = bb,
".bb-title tspan:nth-child(2)" = "font-size: smaller; font-weight: lighter;"
)
bb <- bb_padding(bb, top = 30)
}

if (!is.null(title)) {
bb <- bb_title(
Expand All @@ -51,13 +67,5 @@ bb_labs <- function(bb, title = NULL, x = NULL, y = NULL, caption = NULL, captio
)
}

if (!is.null(caption)) {
bb <- .bb_opt2(bb, "caption", l = dropNulls(list(
text = caption,
href = caption_href
)))
bb <- .bb_opt(bb, "padding", bottom = 10)
}

return(bb)
}
23 changes: 11 additions & 12 deletions R/bb_utils.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@

# dropNulls
dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE = logical(1))]
}


`%||%` <- function(x, y) {
if (!is.null(x)) x else y
}



#' Utility function to create Billboard parameters JSON
Expand Down Expand Up @@ -984,5 +974,14 @@ bb_render <- function(bb, ...) {

}



#' The padding of the chart element.
#'
#' @param bb A \code{\link{billboarder}} \code{htmlwidget} object
#' or a \code{\link{billboarderProxy}} \code{htmlwidget} object.
#' @param ... See \url{https://naver.github.io/billboard.js/release/latest/doc/Options.html#.padding} for possible options.
#'
#' @return A \code{billboard} \code{htmlwidget} object.
#' @export
bb_padding <- function(bb, ...) {
.bb_opt(bb, "padding", ...)
}
2 changes: 1 addition & 1 deletion R/billboarder.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ billboard_dependencies <- function() {
}
htmlDependency(
name = "billboard",
version = "3.10.0",
version = "3.10.2",
src = c(file = "htmlwidgets/lib"),
package = "billboarder",
script = "billboard/billboard.pkgd.min.js",
Expand Down
8 changes: 8 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE = logical(1))]
}

`%||%` <- function(x, y) {
if (!is.null(x)) x else y
}

list1 <- function(x) {
if (length(x) == 1) {
list(x)
Expand Down
71 changes: 0 additions & 71 deletions inst/htmlwidgets/billboarder.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,43 +173,6 @@ HTMLWidgets.widget({
head.appendChild(stylecustom);
}

// Caption
if (bb_opts.hasOwnProperty("caption")) {

var caption = document.querySelector("#" + el.id + " svg > .bb-caption");
if (caption === null) {

var svg = document.querySelector("#" + el.id + " svg");
var captionG = document.createElementNS("http://www.w3.org/2000/svg", "g");
captionG.setAttribute("class", "bb-caption");
captionG.setAttribute("transform", "translate(" + w + "," + (h-3) + ")");

var captionText = document.createElementNS("http://www.w3.org/2000/svg", "text");
captionText.setAttribute("text-anchor", "end");
captionText.innerHTML = bb_opts.caption.text;

if (bb_opts.caption.hasOwnProperty("href")) {
var captionLink = document.createElementNS("http://www.w3.org/2000/svg", "a");
captionLink.setAttribute("href", bb_opts.caption.href);
captionLink.appendChild(captionText);
captionG.appendChild(captionLink);
} else {
captionG.appendChild(captionText);
}

if (svg !== null) {
svg.appendChild(captionG);
}

} else {
caption.setAttribute("transform", "translate(" + w + "," + (h-3) + ")");
//caption.firstChild.innerHTML = bb_opts.caption.text;
var textUpdate = caption.querySelector("text");
textUpdate.innerHTML = bb_opts.caption.text;
}
}


},

getChart: function() {
Expand All @@ -223,40 +186,6 @@ HTMLWidgets.widget({
var w = container.clientWidth;
var h = container.clientHeight;
chart.resize({ width: w, height: h });

// Caption
if (typeof bb_opts.caption != "undefined") {
var caption = document.querySelector("#" + el.id + " svg > .bb-caption");
if (caption === null) {

var svg = document.querySelector("#" + el.id + " svg");
var captionG = document.createElementNS("http://www.w3.org/2000/svg", "g");
captionG.setAttribute("class", "bb-caption");
captionG.setAttribute("transform", "translate(" + w + "," + (h-3) + ")");

var captionText = document.createElementNS("http://www.w3.org/2000/svg", "text");
captionText.setAttribute("text-anchor", "end");
captionText.innerHTML = bb_opts.caption.text;

if (bb_opts.caption.hasOwnProperty("href")) {
var captionLink = document.createElementNS("http://www.w3.org/2000/svg", "a");
captionLink.setAttribute("href", bb_opts.caption.href);
captionLink.appendChild(captionText);
captionG.appendChild(captionLink);
} else {
captionG.appendChild(captionText);
}

if (svg !== null) {
svg.appendChild(captionG);
}

} else {
caption.setAttribute("transform", "translate(" + w + "," + (h-3) + ")");
var textUpdate = caption.querySelector("text");
textUpdate.innerHTML = bb_opts.caption.text;
}
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/billboard/billboard.min.css

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

4 changes: 2 additions & 2 deletions inst/htmlwidgets/lib/billboard/billboard.pkgd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/billboard/datalab.min.css

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

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/billboard/graph.min.css

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

Loading

0 comments on commit 97bca13

Please sign in to comment.