Skip to content

Commit

Permalink
Option to remove save button
Browse files Browse the repository at this point in the history
  • Loading branch information
nvelden committed Jun 19, 2024
1 parent dc33252 commit c82ff6e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
13 changes: 11 additions & 2 deletions R/geneviewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -185,14 +187,21 @@ 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",
x,
width = width,
height = height,
package = "geneviewer",
dependencies = fontawesome::fa_html_dependency(),
dependencies = dependencies,
elementId = elementId
)
}
Expand Down
3 changes: 2 additions & 1 deletion inst/htmlwidgets/geneviewerwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ HTMLWidgets.widget({
}

// Save icon
createSaveIcon(widgetId, el);
createSaveIcon(widgetId, el, show = saveButton);

};

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions inst/htmlwidgets/lib/geneviewer-0.1.8/geneviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -645,6 +646,7 @@ function createSaveIcon(widgetId, el) {
});
});
});
}
}

// Make links function
Expand Down
5 changes: 4 additions & 1 deletion man/GC_chart.Rd

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

0 comments on commit c82ff6e

Please sign in to comment.