Add ggplot2 support und bump to v0.2.0

Change-Id: Iee69051bc64fb9fbde55bbea61c7e892ff95229d
diff --git a/R/ggplot-theme.R b/R/ggplot-theme.R
new file mode 100644
index 0000000..fb3176b
--- /dev/null
+++ b/R/ggplot-theme.R
@@ -0,0 +1,108 @@
+#' IDS Theme for ggplot2
+#'
+#' Based on Highcharts ggtheme \link[ggthemes]{theme_hc}
+#' which again is based on the plots in \url{Highcharts JS}.
+#'
+#' @note
+#'
+#' Note that here, unlike with the highcharter theme, you have to set the scale
+#' explicitly.
+#'
+#'
+#' @references
+#'
+#' \link[ggthemes]{theme_hc}
+#'
+#' \url{http://www.highcharts.com/demo/line-basic}
+#'
+#' \url{https://github.com/highslide-software/highcharts.com/tree/master/js/themes}
+#'
+#' @inheritParams ggplot2::theme_bw
+#' @param style \code{'light'}, \code{'dark'}.
+#' @param bgcolor Deprecated
+#' @example inst/examples/ex-ggplot.R
+#' @family themes ids
+#' @importFrom ggplot2 theme element_rect element_text element_line element_blank
+#' @export
+theme_ids <- function(base_size = 14,
+                     base_family = idsBaseFontFamily,
+                     style = c("default", "light", "dark"),
+                     bgcolor = NULL) {
+
+  if (!is.null(bgcolor)) {
+    warning("`bgcolor` is deprecated. Use `style` instead.")
+    style <- bgcolor
+  }
+  style <- match.arg(style)
+  bgcolor <- switch(style,
+                    default = backgroundColor,
+                    "light" = backgroundColor,
+                    "mono" = backgroundColor,
+                    "dark" = backgroundColorDark)
+
+  ret <- theme(rect = element_rect(fill = bgcolor, linetype = 0, colour = NA),
+               text = element_text(size = base_size, family = base_family),
+               plot.title = element_text(hjust = 0.5),
+               plot.subtitle = element_text(hjust = 0.5, size = 13, colour = mediumContrastColor),
+               title = element_text(hjust = 0.5),
+               axis.title.x = element_text(hjust = 0.5, size=11),
+               axis.title.y = element_text(hjust = 0.5, size=11),
+               legend.title = element_text(size=11),
+               panel.grid.major.y = element_line(colour = lowContrastColor),
+               panel.grid.minor.y = element_blank(),
+               panel.grid.major.x = element_blank(),
+               panel.grid.minor.x = element_blank(),
+               panel.border = element_blank(),
+               panel.background = element_blank(),
+               legend.position = "right",
+               legend.key = element_rect(fill = paste0(bgcolor,"00")))
+
+  if (style == "dark") {
+    ret <- (ret + theme(rect = element_rect(fill = bgcolor),
+                        text = element_text(colour = textColorDark),
+                        plot.title = element_text(colour = highContrastColorDark),
+                        plot.subtitle = element_text(colour = mediumContrastColorDark),
+                        axis.title.x = element_text(colour = textColorDark),
+                        axis.title.y = element_text(colour = textColorDark),
+                        axis.text.x = element_text(color=textColorDark),
+                        axis.text.y = element_text(color=textColorDark),
+                        panel.grid.major.y = element_line(colour = lowContrastColorDark),
+                        legend.title = element_text(colour = textColorDark)))
+  }
+  ret
+}
+
+
+#' IDS color and fill scales
+#'
+#' Colour and fill scales which use the palettes in
+#' \code{\link{ids_pal}()} and are meant for use with
+#' \code{\link{theme_ids}()}.
+#'
+#' @param palette A palette function that when called with a single integer
+#' argument (the number of levels in the scale) returns the values that they should take.
+#'
+#' @importFrom ggthemes gdocs_pal
+#' @importFrom ggplot2 discrete_scale
+#'
+#' @inheritDotParams  ggthemes::scale_colour_gdocs
+#' @family colour ids
+#' @rdname scale_ids
+#' @export
+scale_colour_ids <- function(palette = "default", ...) {
+  discrete_scale("colour", "ids", ids_pal(), ...)
+}
+
+#' @rdname scale_ids
+#' @inheritDotParams  ggthemes::scale_colour_gdocs
+#' @importFrom ggplot2 discrete_scale
+#' @export
+scale_color_ids <- scale_colour_ids
+
+#' @rdname scale_ids
+#' @inheritParams ggthemes::scale_fill_gdocs
+#' @importFrom ggplot2 discrete_scale
+#' @export
+scale_fill_ids <- function(palette = "default", ...) {
+  discrete_scale("fill", "ids", ids_pal(), ...)
+}
diff --git a/R/highcharter-themes.R b/R/highcharter-themes.R
index 7cafeb2..d9bca09 100644
--- a/R/highcharter-themes.R
+++ b/R/highcharter-themes.R
@@ -1,11 +1,11 @@
 #' Dark IDS theme for \link[highcharter]{highcharter}
 #'
-#' @param fontFamily              font family        
+#' @param fontFamily              font family
 #' @param fontSize                default font size
 #' @param textColor               default text color
-#' @param lowContrastColor        color with low contrast to background 
-#' @param highContrastColor       color with high contrast to background 
-#' @param palette                 array of colors to be used for different series 
+#' @param lowContrastColor        color with low contrast to background
+#' @param highContrastColor       color with high contrast to background
+#' @param palette                 array of colors to be used for different series
 #' @param backgroundColor         background color
 #' @param titleColor              color of the title text
 #' @param subtitleColor           color of the subtitle text
@@ -41,31 +41,10 @@
 hc_theme_ids_dark <-
   function(fontFamily = "Fira Sans Condensed",
            fontSize = "medium",
-           textColor = "#E0E0E3",
-           lowContrastColor = "#707073",
-           highContrastColor = "#F0F0F3",
-           palette = c(
-             '#EB7C31',
-             "#1F77B4",
-             "#2CA02C",
-             "#D62728",
-             "#9467BD",
-             "#8C564B",
-             "#E377C2",
-             "#7F7F7F",
-             "#BCBD22",
-             "#17BECF",
-             "#AEC7E8",
-             "#FFBB78",
-             "#98DF8A",
-             "#FF9896",
-             "#C5B0D5",
-             "#C49C94",
-             "#F7B6D2",
-             "#C7C7C7",
-             "#DBDB8D",
-             "#9EDAE5"
-           ),
+           textColor = textColorDark,
+           lowContrastColor = lowContrastColorDark,
+           highContrastColor = highContrastColorDark,
+           palette = idsPalette,
            backgroundColor = list(linearGradient = list(
              x1 = 0,
              y1 = 1,
@@ -152,17 +131,17 @@
         ),
         credits = list(style = list(color = creditsColor)),
         labels = list(style = list(color = "#707073")),
-        
+
         drilldown = list(
           activeAxisLabelStyle = list(color = "#F0F0F3"),
           activeDataLabelStyle = list(color = "#F0F0F3")
         ),
-        
+
         navigation = list(buttonOptions = list(
           symbolStroke = "#DDDDDD",
           theme = list(fill = burgerMenuBackground)
         )),
-        
+
         rangeSelector = list(
           buttonTheme = list(
             fill = "#505053",
@@ -186,7 +165,7 @@
                             color = "silver"),
           labelStyle = list(color = "silver")
         ),
-        
+
         navigator = list(
           handles = list(backgroundColor = "#666",
                          borderColor = "#AAA"),
@@ -195,7 +174,7 @@
                         lineColor = "#A6C7ED"),
           xAxis = list(gridLineColor = "#505053")
         ),
-        
+
         scrollbar = list(
           barBackgroundColor = "#808083",
           barBorderColor = "#808083",
@@ -206,7 +185,7 @@
           trackBackgroundColor = "#404043",
           trackBorderColor = "#404043"
         ),
-        
+
         legendBackgroundColor = "rgba(0, 0, 0, 0)",
         background2 = "#233238",
         dataLabelsColor = "#233238",
@@ -214,14 +193,14 @@
         maskColor = "rgba(255,255,255,0.3)",
         contrastTextColor = highContrastColor
       )
-    
+
     theme <- structure(theme, class = "hc_theme")
-    
+
     if (length(list(...)) > 0) {
       theme <- hc_theme_merge(theme,
                               hc_theme(...))
     }
-    
+
     theme
   }
 
@@ -229,8 +208,9 @@
 #'
 #' See \code{\link{hc_theme_ids_dark}} for further documentation.
 #'
-#' @param ... named arguments to modify the theme
-#' 
+#' @inheritParams hc_theme_ids_dark
+#' @inheritDotParams hc_theme_ids_dark
+#'
 #' @importFrom magrittr %>%
 #' @import tidyverse
 #' @import highcharter
@@ -244,7 +224,7 @@
 hc_theme_ids_light <- function(...) {
   hc_theme_ids_dark(
     backgroundColor = "#ffffff",
-    textColor = "#383838",
+    textColor = textColor ,
     highContrastColor = "#101013",
     lowContrastColor = "#E0E0E3",
     tooltipBackgroundColor = "#ffffffe0",
@@ -258,8 +238,9 @@
 #'
 #' See \code{\link{hc_theme_ids_dark}} for further documentation.
 #'
-#' @param ... named arguments to modify the theme
-#' 
+#' @inheritParams hc_theme_ids_dark
+#' @inheritDotParams hc_theme_ids_dark
+#'
 #' @importFrom magrittr %>%
 #' @import tidyverse
 #' @import highcharter
@@ -272,9 +253,7 @@
 #' @export
 hc_theme_ids_mono <- function(...) {
   hc_theme_ids_dark(
-    palette = c(
-      "#000000", "#B2B0AD", "#737373", "#D8D7D6", "#B2B0AD", "#8C8984"
-    ),
+    palette = idsPaletteGreyscale,
     backgroundColor = "white",
     textColor = "black",
     highContrastColor = "black",
diff --git a/R/idsThemeR.R b/R/idsThemeR.R
new file mode 100644
index 0000000..d62f03c
--- /dev/null
+++ b/R/idsThemeR.R
@@ -0,0 +1,60 @@
+idsBaseFontFamily <- 'Fira Sans Condensed'
+
+idsPalette <- c(
+  '#EB7C31',
+  "#1F77B4",
+  "#2CA02C",
+  "#D62728",
+  "#9467BD",
+  "#8C564B",
+  "#E377C2",
+  "#7F7F7F",
+  "#BCBD22",
+  "#17BECF",
+  "#AEC7E8",
+  "#FFBB78",
+  "#98DF8A",
+  "#FF9896",
+  "#C5B0D5",
+  "#C49C94",
+  "#F7B6D2",
+  "#C7C7C7",
+  "#DBDB8D",
+  "#9EDAE5"
+)
+
+idsPaletteGreyscale <- c(
+  "#000000", "#B2B0AD", "#737373", "#D8D7D6", "#B2B0AD", "#8C8984"
+)
+
+backgroundColorDark <- "#2a2a2a"
+textColorDark <- "#E0E0E3"
+lowContrastColorDark <- "#707073"
+highContrastColorDark <- "#F0F0F3"
+mediumContrastColorDark <- "#808083"
+
+backgroundColor <- "#ffffff"
+textColor <- "#383838"
+highContrastColor <- "#101013"
+lowContrastColor <- "#E0E0E3"
+mediumContrastColor <- "#404043"
+tooltipBackgroundColor <- "#ffffffe0"
+boxplotFillColor <- "#505053"
+candlestickColor <- "black"
+errorbarColor <- "black"
+
+#' IDS color palette based on the d3 color palette
+#'
+#' @importFrom scales manual_pal
+#' @export
+#'
+#' @references
+#'
+#' \url{https://github.com/d3/d3}
+#'
+ids_pal <- function() {
+  values <- idsPalette
+  f <- scales::manual_pal(values)
+  attr(f, "max_n") <- length(values)
+  f
+}