diff --git a/DESCRIPTION b/DESCRIPTION index 59609a6cf..caa52627a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,7 +54,6 @@ Imports: Rcpp, rstac (>= 0.9.2-3), sf (>= 1.0-12), - showtext, sysfonts, slider (>= 0.2.0), stats, diff --git a/R/api_colors.R b/R/api_colors.R index 7c08160b7..4a71d4c28 100644 --- a/R/api_colors.R +++ b/R/api_colors.R @@ -81,7 +81,7 @@ #' @noRd #' @param color_tb A SITS color table #' @return a gglot2 object -.colors_show <- function(color_tb) { +.colors_show <- function(color_tb, font_family) { color_tb$name <- purrr::map_chr(color_tb$name, function(name) { paste(name = unlist(strsplit(name, split = "_")), collapse = " ")}) n_colors <- nrow(color_tb) @@ -119,7 +119,7 @@ y = .data[["y"]] + 0.8, label = stringr::str_wrap(.data[["name"]], width = 10) ), - family = "opensans", + family = font_family, colour = "grey15", hjust = 0.5, vjust = 1, diff --git a/R/api_conf.R b/R/api_conf.R index 6033e0147..04f071fae 100644 --- a/R/api_conf.R +++ b/R/api_conf.R @@ -195,12 +195,11 @@ keep.null = FALSE ) colors <- config_colors$colors - base_names <- names(colors) - color_table <- purrr::map2_dfr(colors, base_names, function(cl, bn) { + color_table <- purrr::map2_dfr(colors, names(colors), + function(cl, nm) { cc_tb <- tibble::tibble( - name = names(cl), - color = unlist(cl), - group = bn + name = nm, + color = cl ) return(cc_tb) }) @@ -250,8 +249,7 @@ } else { color_table <- tibble::add_row(color_table, name = name, - color = col, - group = "User" + color = col ) } } @@ -274,11 +272,10 @@ #' @return NULL, called for side effects #' .conf_set_fonts <- function() { - library(showtext) - library(sysfonts) + # verifies if sysfonts package is installed + .check_require_packages("sysfonts") sysfonts::font_add_google("Open Sans", family = "opensans") - sysfonts::font_add_google("IBM Plex Sans", family = "ibm") - sysfonts::font_add_google("Noto Sans", family = "noto") + sysfonts::font_add_google("Roboto", family = "roboto") return(NULL) } #' @title Return the user configuration set in enviromental variable diff --git a/R/sits_colors.R b/R/sits_colors.R index 8a10e3936..b00ac86a3 100644 --- a/R/sits_colors.R +++ b/R/sits_colors.R @@ -20,6 +20,7 @@ sits_colors <- function() { #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} #' @description Shows the default SITS colors #' @param legend One of the accepted legend in sits +#' @param font_family A font family loaded in SITS #' #' @return no return, called for side effects #' @@ -30,16 +31,20 @@ sits_colors <- function() { #' } #' @export #' -sits_colors_show <- function(legend = NULL) { - # verifies if stringr package is installed - .check_require_packages("stringr") +sits_colors_show <- function(legend = NULL, + font_family = "opensans") { + # verifies if sysfonts package is installed + .check_require_packages("sysfonts") + # checks if font family is available + if (!font_family %in% sysfonts::font_families()) + font_family <- "opensans" legends <- .conf("legends") if (purrr::is_null(legend)) { print("Showing all available colors") leg <- paste0(paste("Optional - select one of the legends: "), paste(legends, collapse = ", ")) print(leg) - g <- .colors_show(sits_colors()) + g <- .colors_show(sits_colors(), font_family) return(g) } else { if (legend %in% legends) { @@ -48,7 +53,7 @@ sits_colors_show <- function(legend = NULL) { dplyr::filter(.data[["name"]] %in% colors) color_table_legend <- color_table_legend[ match(colors, color_table_legend$name), ] - g <- .colors_show(color_table_legend) + g <- .colors_show(color_table_legend, font_family) return(g) } else { print("Selected map legend not available") diff --git a/inst/extdata/config_colors.yml b/inst/extdata/config_colors.yml index f1b6b536b..b00ebb9b2 100644 --- a/inst/extdata/config_colors.yml +++ b/inst/extdata/config_colors.yml @@ -7,7 +7,8 @@ # and 1970 U.S. Vegetation Map # class_schemes: - legends: ["IGBP", "UMD", "ESA_CCI_LC", "WORLDCOVER", "PRODES"] + legends: ["IGBP", "UMD", "ESA_CCI_LC", "WORLDCOVER", "PRODES", + "TERRA_CLASS"] IGBP: ["Evergreen_Needleleaf_Forests", "Evergreen_Broadleaf_Forests", "Deciduous_Needleleaf_Forests", "Deciduous_Broadleaf_Forests", @@ -193,8 +194,13 @@ class_schemes: "Mining", "Water", "Wetland", "Urban_Area", "Cropland", "Pasture"] + TERRA_CLASS: ["Forest", "Secondary_Vegetation","Degradation", + "Deforestation", + "Cropland", "Pasture", "Cerradao", "Cerrado", + "Campo_Cerrado", "Mining", "Water", "Wetland", + "Urban_Area"] + colors: - Tropical_Forest: # Oak-hickory-pine forest in US Veg Map Evergreen_Broadleaf_Forest : &forest "#518940" Evergreen_Broadleaf_Forests : *forest @@ -227,7 +233,6 @@ colors: Woody_Savannas : *woodlands Cerradao : *woodlands - Deciduous_Tropical_Forests: # Caatinga and decidous tropical forest Caatinga : &caatinga "#c7ebdb" Deciduous_Forest : *caatinga @@ -236,14 +241,13 @@ colors: Deciduous_Broadleaf_Forest : *caatinga Deciduous_Broadleaf_Forests : *caatinga - Planted_Forest: # Silviculture and Planted Forest # Northern hardwood Planted_Forest : &planted_forest "#90cac8" Planted_Forests : *planted_forest Silviculture : *planted_forest - Temperate_Forest: + # Temperate Forests # Great lakes pine forest in US Veg Map Evergreen_Needleleaf_Forest : &enf "#96b1b7" Evergreen_Needleleaf_Forests : *enf @@ -256,7 +260,6 @@ colors: Mixed_Forests : *mixedforest Tree_Cover_Mixed_Leaf : *mixedforest - Savanna: # Savanna and Cerrado # Bluestem praire in US Veg Map Savanna : &savanna "#a2d43f" @@ -269,7 +272,7 @@ colors: Savanna_Parkland : *campo_cerrado Open_Cerrado : *campo_cerrado - Grassland: + # Grasslands and similar # California steppe Grassland : &grassland "#f6cc41" Grasslands : *grassland @@ -281,7 +284,7 @@ colors: Dense_Herbaceous : *pasture Herbaceous_Vegetation : *pasture - Shrubland: + # Shrublands # Based on "pumpkin" palette of Flat Design Color Chart Closed_Shrubland : &closed_shrubland "#BA4A00" Closed_Shrublands : *closed_shrubland @@ -293,7 +296,7 @@ colors: Sparse_Shrubland : *shrubland Rocky_Savanna : *shrubland - Barren: + # Barren and Sparse Vegetation # Based on "orange" palette of Flat Design Color Chart Barren : &barren "#FDEBD0" Bare_Area : *barren @@ -304,12 +307,12 @@ colors: Non_Vegetated_Lands : *barren Dunes : "#FEF9E7" - Tundra: + # Tundra # based on the "wisteria" palette of Flat Design Color Chart Lichens_Mosses : &moss "#E8DAEF" Moss_Lichen : *moss - Flooded_trees: + # Flooded_trees and mangroves Mangrove : &mangrove "#D4E6F1" Mangroves : *mangrove Tree_Cover_Flooded_Saline_Water: *mangrove @@ -318,7 +321,7 @@ colors: Herbaceous_Wetland : *flooded Shrub_Herbaceous_Cover_Flooded: *flooded - Wetland: + # Water and Wetlands # Based on "belize hole" palette from Flat Design Color Chart Water : &water "#2980B9" Water_Bodies : *water @@ -328,7 +331,7 @@ colors: Permanent_Wetland : *wetlands Permanent_Wetlands : *wetlands - Cropland: + # Croplands # Based on "carrot" palette from Flat Design Color Chart Cropland : &cropland "#F0B27A" Croplands : *cropland @@ -376,7 +379,6 @@ colors: # Based on "turquoise" palette of Flat Design Color Chart Rice : "#FBEEE6" - Mosaic: # Mosaic classes Forest_Cropland_Mosaic : &mosaic_1 "#947E13" Mosaic_Vegetation_Cropland : *mosaic_1 @@ -387,13 +389,13 @@ colors: Mosaic_Cropland_Vegetation: *mosaic_2 Mosaic_Herbaceous_Tree_Shrub: *mosaic_2 - Deforestation: + # Deforestation - PRODES and DETER # Secondary Vegetation # Beech-maple forest Secondary_Vegetation : "#9bd15e" # Deforestation, Degradation, Mining - # Based on "Alizarin" palette from Flat Design Color Chart - Degradation : "#afc97f" + # Based on "Alizarin" palette from Flat Design Color Chart "#afc97f" + Degradation : "#D6D295" # PRODES # Based on "Alizarin" palette from Flat Design Color Chart Burned_Area : &burned_area "#CD6155" @@ -410,24 +412,27 @@ colors: Clear_Cut_Vegetation : *clear_cut_deg # Based on "amethyst" palette from Flat Design Color Chart Mining : "#C39BD3" - # Deforestation_Mask #FDEBD0 - Deforestation : &deforestation "#C9D6AE" + # Deforestation_Mask #FDEBD0 "#C9D6AE" + Deforestation : &deforestation "#CAD4C9" Deforestation_Mask : *deforestation # Based on "silver" palette from Flat Design Color Chart - Non_Forest : &non_forest "#BDC3C7" + Non_Forest : &non_forest "#C9D6AE" Natural_Non_Forested : *non_forest - Urban: + + # Urban Areas # Based on "wet asphalt" palette from Flat Design Color Chart Urban_Area : &urban "#85929E" Urban_Builtup_Lands : *urban Builtup : *urban - Snow_Ice: + + # Snow and Ice # Based on "asbestos" palette from Flat Design Color Chart Snow_Ice : &snow "#E5E8E8" Permanent_Snow_Ice : *snow Snow_and_Ice : *snow - Others: - # No Class uses "silver" palette from Flat Design Color Chart + + # Others + # uses "silver" palette from Flat Design Color Chart No_Class : &no_class "#F2F3F4" No_Data : *no_class Unclassified : *no_class diff --git a/man/sits_colors_show.Rd b/man/sits_colors_show.Rd index 2a6546bee..fac567d29 100644 --- a/man/sits_colors_show.Rd +++ b/man/sits_colors_show.Rd @@ -4,10 +4,12 @@ \alias{sits_colors_show} \title{Function to show colors in SITS} \usage{ -sits_colors_show(legend = NULL) +sits_colors_show(legend = NULL, font_family = "opensans") } \arguments{ \item{legend}{One of the accepted legend in sits} + +\item{font_family}{A font family loaded in SITS} } \value{ no return, called for side effects