diff --git a/R/geneviewer.R b/R/geneviewer.R index 1f8b7ab..830a760 100644 --- a/R/geneviewer.R +++ b/R/geneviewer.R @@ -29,6 +29,7 @@ magrittr::`%>%` #' list(backgroundColor = "white", border = "2px solid black"). Default is an #' empty list. #' @param elementId Optional identifier string for the widget. Default is NULL. +#' @param save_button Logical, whether to include a save button. Default is TRUE. #' #' @return A GC chart widget. #' @@ -51,7 +52,7 @@ magrittr::`%>%` #' @import htmlwidgets #' @import fontawesome #' @export -GC_chart <- function(data, start = "start", end = "end", cluster = NULL, group = NULL, strand = NULL, width = "100%", height = "400px", style = list(), elementId = NULL) { +GC_chart <- function(data, start = "start", end = "end", cluster = NULL, group = NULL, strand = NULL, width = "100%", height = "400px", style = list(), elementId = NULL, save_button = TRUE) { x <- list() # Capture all arguments with their current values @@ -127,6 +128,7 @@ GC_chart <- function(data, start = "start", end = "end", cluster = NULL, group = width = width ) x$legend$style <- list(width = "100%", backgroundColor = style$backgroundColor) + x$saveButton <- save_button if (is.null(cluster)) { @@ -185,6 +187,13 @@ GC_chart <- function(data, start = "start", end = "end", cluster = NULL, group = ) } + # Determine dependencies + dependencies <- if (save_button) { + list(fontawesome::fa_html_dependency()) + } else { + NULL + } + # create the widget htmlwidgets::createWidget( name = "geneviewer", @@ -192,7 +201,7 @@ GC_chart <- function(data, start = "start", end = "end", cluster = NULL, group = width = width, height = height, package = "geneviewer", - dependencies = fontawesome::fa_html_dependency(), + dependencies = dependencies, elementId = elementId ) } diff --git a/inst/htmlwidgets/geneviewerwidget.js b/inst/htmlwidgets/geneviewerwidget.js index 8b3cb36..eb4976c 100644 --- a/inst/htmlwidgets/geneviewerwidget.js +++ b/inst/htmlwidgets/geneviewerwidget.js @@ -173,7 +173,7 @@ HTMLWidgets.widget({ } // Save icon - createSaveIcon(widgetId, el); + createSaveIcon(widgetId, el, show = saveButton); }; @@ -203,6 +203,7 @@ HTMLWidgets.widget({ data = HTMLWidgets.dataframeToD3(input.data); links = input.links; series = input.series; + saveButton = input.saveButton; titleOptions = input.title; legendOptions = input.legend; draw(width, height); diff --git a/inst/htmlwidgets/lib/geneviewer-0.1.8/geneviewer.js b/inst/htmlwidgets/lib/geneviewer-0.1.8/geneviewer.js index a729c0c..df24e7d 100644 --- a/inst/htmlwidgets/lib/geneviewer-0.1.8/geneviewer.js +++ b/inst/htmlwidgets/lib/geneviewer-0.1.8/geneviewer.js @@ -583,9 +583,10 @@ function addScalePadding(startValue, endValue, padding, to) { } } -function createSaveIcon(widgetId, el) { - // Create an icon in the top right corner of the container div - var icon = d3.select(el).append("i") +function createSaveIcon(widgetId, el, show = true) { + + if (show) { + var icon = d3.select(el).append("i") .attr("class", "fa-solid fa-download") .attr("id", `saveIcon-${widgetId}`) .style("position", "absolute") @@ -645,6 +646,7 @@ function createSaveIcon(widgetId, el) { }); }); }); + } } // Make links function diff --git a/man/GC_chart.Rd b/man/GC_chart.Rd index a8c03dc..301a9d3 100644 --- a/man/GC_chart.Rd +++ b/man/GC_chart.Rd @@ -14,7 +14,8 @@ GC_chart( width = "100\%", height = "400px", style = list(), - elementId = NULL + elementId = NULL, + save_button = TRUE ) } \arguments{ @@ -50,6 +51,8 @@ list(backgroundColor = "white", border = "2px solid black"). Default is an empty list.} \item{elementId}{Optional identifier string for the widget. Default is NULL.} + +\item{save_button}{Logical, whether to include a save button. Default is TRUE.} } \value{ A GC chart widget.