Add spec_color and family
diff --git a/R/cell_spec.R b/R/cell_spec.R
index f5bff2a..aacac76 100644
--- a/R/cell_spec.R
+++ b/R/cell_spec.R
@@ -20,25 +20,27 @@
#' while for LaTeX, you can only choose from `l`, `c` & `r`.
#' @param font_size Only if you want to specify font size locally in HTML.
#' This feature is not available in LaTeX
-#' @param angle 0-360, degree that the text will rotate.
+#' @param angle 0-360, degree that the text will rotate. Can be a vector.
+#' @param hover_message A vector of strings to be displayed as hover message.
+#' Of course, this feature is nly available in HTML.
#'
#' @export
cell_spec <- function(x, format,
bold = F, italic = F, monospace = F,
color = NULL, background = NULL,
- align = NULL, font_size = NULL, angle = NULL) {
+ align = NULL, font_size = NULL, angle = NULL,
+ hover_message = NULL) {
if (missing(format) || is.null(format)) format = getOption('knitr.table.format')
if (is.null(format)) {
- warning("Output format for cell_formatter was not specified. Using ",
- "html as default. You may consider to set it up via option knitr.table.format.",
- "See ?cell_formatter for details. ")
- return(x)
+ message("Setting cell_spec format as html")
+ format <- "html"
}
if (tolower(format) == "html") {
return(cell_spec_html(x, bold, italic, monospace,
- color, background, align, font_size, angle))
+ color, background, align, font_size, angle,
+ hover_message))
}
if (tolower(format) == "latex") {
return(cell_spec_latex(x, bold, italic, monospace,
@@ -47,31 +49,37 @@
}
cell_spec_html <- function(x, bold, italic, monospace,
- color, background, align, font_size, angle) {
+ color, background, align, font_size, angle,
+ hover_message) {
cell_style <- NULL
if (bold) cell_style <- paste(cell_style,"font-weight: bold;")
if (italic) cell_style <- paste(cell_style, "font-style: italic;")
if (monospace) cell_style <- paste(cell_style, "font-family: monospace;")
- if (!is.null(color)) cell_style <- paste0(cell_style, " color: ", color, ";")
+ if (!is.null(color)) cell_style <- paste0(cell_style, "color: ", color, ";")
if (!is.null(background)) {
- cell_style <- paste0(cell_style, " border-radius: 4px; padding-right: 2px",
- "; background-color: ", background, ";")
+ cell_style <- paste0(cell_style, "border-radius: 4px; padding-right: 4px",
+ ";padding-left: 4px; background-color: ", background, ";")
}
if (!is.null(align)) {
- cell_style <- paste0(cell_style, " text-align: ", align, ";")
+ cell_style <- paste0(cell_style, "text-align: ", align, ";")
}
if (!is.null(font_size)) {
- cell_style <- paste0(cell_style, " font-size: ", font_size, "px;")
+ cell_style <- paste0(cell_style, "font-size: ", font_size, "px;")
}
if (!is.null(angle)) {
cell_style <- paste0(cell_style,
- " -webkit-transform: rotate(", angle,
+ "-webkit-transform: rotate(", angle,
"deg); -moz-transform: rotate(", angle,
"deg); -ms-transform: rotate(", angle,
"deg); -o-transform: rotate(", angle, "deg);")
}
+
+ if (!is.null(hover_message)) {
+ hover_message <- gsub("\n", "
", hover_message)
+ hover_message <- paste0("data-toggle='tooltip' title='", hover_message, "'")
+ }
out <- paste0(
- '<div style="', cell_style, '">', x, '</div>'
+ '<div style="', cell_style, '"', hover_message, '>', x, '</div>'
)
return(out)
}
@@ -81,8 +89,14 @@
if (bold) x <- paste0("\\bfseries{", x, "}")
if (italic) x <-paste0("\\em{", x, "}")
if (monospace) x <- paste0("\\ttfamily{", x, "}")
- if (!is.null(color)) x <- paste0("\\textcolor{", color, "}{", x, "}")
- if (!is.null(background)) x <- paste0("\\cellcolor{", background, "}{", x, "}")
+ if (!is.null(color)) {
+ color <- latex_color(color)
+ x <- paste0("\\textcolor", color, "{", x, "}")
+ }
+ if (!is.null(background)) {
+ background <- latex_color(background)
+ x <- paste0("\\cellcolor", background, "{", x, "}")
+ }
if (!is.null(align)) x <- paste0("\\multicolumn{1}{", align, "}{", x, "}")
if (!is.null(angle)) x <- paste0("\\rotatebox{", angle, "}{", x, "}")
return(x)