Browse Source

fa5

pull/65/head
boB Rudis 5 years ago
parent
commit
4c25a015b0
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      DESCRIPTION
  2. 3
      NAMESPACE
  3. 85
      R/fontawesome.R
  4. 2
      R/waffle-package.R
  5. 39
      R/waffle.R
  6. 4
      README.Rmd
  7. 2
      README.md
  8. BIN
      README_files/figure-gfm/medkit-1.png
  9. 2825
      inst/css/fontawesome.css
  10. BIN
      inst/extdat/fadf.rds
  11. BIN
      inst/fonts/fa-brands-400.ttf
  12. BIN
      inst/fonts/fa-regular-400.ttf
  13. BIN
      inst/fonts/fa-solid-900.ttf
  14. BIN
      inst/fonts/fontawesome-webfont.ttf
  15. BIN
      inst/json/icons.json.gz
  16. 6
      man/fa_grep.Rd
  17. 4
      man/fa_list.Rd
  18. 11
      man/install_fa_fonts.Rd
  19. 4
      man/waffle.Rd

4
DESCRIPTION

@ -39,5 +39,7 @@ Imports:
extrafont,
curl,
stringr,
stats
stats,
htmlwidgets,
DT
RoxygenNote: 6.1.1

3
NAMESPACE

@ -5,12 +5,15 @@ export(StatWaffle)
export(fa_grep)
export(fa_list)
export(geom_waffle)
export(install_fa_fonts)
export(iron)
export(stat_waffle)
export(theme_enhance_waffle)
export(waffle)
import(DT)
import(curl)
import(gridExtra)
import(htmlwidgets)
import(stringr)
importFrom(RColorBrewer,brewer.pal)
importFrom(extrafont,choose_font)

85
R/fontawesome.R

@ -2,35 +2,82 @@
# This variation updates it from the latests css from github
.fa_unicode_init <- function() {
fa_lib <- readLines(system.file("css", "fontawesome.css", package="waffle"))
# fa_lib <- readLines(system.file("css", "fontawesome.css", package="waffle"))
#Extract from CSS
strings <- stringr::str_extract(fa_lib, ("(?<=fa-)(.*)(?=:before \\{)"))
unicode <- stringr::str_extract(fa_lib, stringr::regex("(?<=content: \")(.*)(?=\")"))
unicode <- stringr::str_replace(unicode, "\\\\", "")
# fa_json <- jsonlite::fromJSON(system.file("json", "icons.json", package="waffle"))
#
# data.frame(
# name = names(fa_json),
# type = vapply(fa_json, function(.x, wat) .x[[wat]][[1]],
# character(1), "free", USE.NAMES = FALSE),
# unicode = vapply(fa_json, function(.x, wat) .x[[wat]][[1]],
# character(1), "unicode", USE.NAMES = FALSE),
# stringsAsFactors = FALSE
# ) -> fa_df
#
# vapply(
# seq_along(fa_df[["name"]]),
# function(.i) {
# # name <- fa_df[.i, "name"]
# type <- fa_df[.i, "type"]
# fa_json[[.i]][["svg"]][[type]][["raw"]]
# },
# character(1), USE.NAMES = FALSE
# ) -> fa_df[["glyph"]]
#
# fa_df[["unicode"]] <- as.character(
# parse(text = shQuote(stringr::str_c('\\u', fa_df[["unicode"]])))
# )
#
# fa_df <- fa_df[complete.cases(fa_df),]
#
# return(fa_df)
#
#remove NA lines
strings <- strings[!is.na(strings)]
unicode <- unicode[!is.na(unicode)]
return(readRDS(system.file("extdat/fadf.rds", package = "waffle")))
#Convert to unicdoe
unicode <- as.character(parse(text=shQuote(stringr::str_c('\\u',unicode))))
fa_unicode <- structure(unicode, .Names = strings)
}
return(fa_unicode)
.fa_unicode <- .fa_unicode_init()
.display_fa <- function(fdf) {
vb <- stringr::str_match(fdf[["glyph"]], '(viewBox="[^"]+")')[,2]
stringr::str_replace(
fdf[["glyph"]],
vb,
sprintf('%s width="24" height="24"', vb)
) -> fdf[["glyph"]]
DT::datatable(fdf, escape = FALSE)
}
.fa_unicode <- .fa_unicode_init()
#' Search Font Awesome glyph names for a pattern
#'
#' @param pattern pattern to search for in the names of Font Awesome fonts
#' @export
fa_grep <- function(pattern) {
res <- which(grepl(pattern, .fa_unicode[["name"]]))
if (length(res)) {
.display_fa(.fa_unicode[res, ])
} else {
message("No Font Awesome font found with that name pattern.")
}
}
#' Search FontAwesome names for a pattern
#' List all Font Awesome glyphs
#'
#' @param pattern pattern to search for in the names of FontAwesome fonts
#' @export
fa_grep <- function(pattern) { grep(pattern, names(.fa_unicode), value=TRUE) }
fa_list <- function() {
.display_fa(.fa_unicode)
}
#' List all FontAwesome names
#' Install Font Awesome 5 Fonts
#'
#' @export
fa_list <- function() { print(names(.fa_unicode)) }
install_fa_fonts <- function() {
message(
"The TTF font files for Font Awesome 5 fonts are in:\n\n",
system.file("fonts", package = "waffle"),
"\n\nPlease navigate to that directory and install them on ",
"your system."
)
}

2
R/waffle-package.R

@ -11,6 +11,8 @@
#' @import gridExtra
#' @import stringr
#' @import curl
#' @import DT
#' @import htmlwidgets
#' @importFrom gtable is.gtable
#' @importFrom RColorBrewer brewer.pal
#' @importFrom ggplot2 ggplot geom_tile scale_fill_manual guides geom_tile ggplotGrob

39
R/waffle.R

@ -87,11 +87,11 @@
#' # print(chart)
waffle <- function(parts, rows=10, keep=TRUE, xlab=NULL, title=NULL, colors=NA,
size=2, flip=FALSE, reverse=FALSE, equal=TRUE, pad=0,
use_glyph=FALSE,
glyph_size=12,
glyph_font = "FontAwesome",
glyph_font_family = "FontAwesome",
legend_pos="right") {
use_glyph = FALSE,
glyph_size = 12,
glyph_font = "Font Awesome 5 Free Solid",
glyph_font_family = "FontAwesome5Free-Solid",
legend_pos = "right") {
if (inherits(parts, "data.frame")) {
stats::setNames(
@ -128,39 +128,46 @@ waffle <- function(parts, rows=10, keep=TRUE, xlab=NULL, title=NULL, colors=NA,
if (length(use_glyph) == 1L) {
if (glyph_font == "FontAwesome") {
if (grepl("wesom", glyph_font)) {
fontlab <- .fa_unicode[.fa_unicode[["name"]] == use_glyph, "unicode"]
dat$fontlab <- c(
rep(.fa_unicode[use_glyph], length(parts_vec)),
rep(NA, nrow(dat) - length(parts_vec)
rep(fontlab, length(parts_vec)),
rep("", nrow(dat) - length(parts_vec)
# rep(NA, nrow(dat) - length(parts_vec)
)
)
} else {
dat$fontlab <- c(
rep(use_glyph, length(parts_vec)),
rep(NA, nrow(dat) - length(parts_vec)
rep("", nrow(dat) - length(parts_vec)
# rep(NA, nrow(dat) - length(parts_vec)
)
)
}
} else if (length(use_glyph) == length(parts)) {
if (glyph_font == "FontAwesome") {
fontlab <- .fa_unicode[use_glyph]
if (grepl("wesom", glyph_font)) {
fontlab <- .fa_unicode[.fa_unicode[["name"]] %in% use_glyph, "unicode"]
# fontlab <- .fa_unicode[use_glyph]
dat$fontlab <- c(
fontlab[as.numeric(factor(parts_vec, levels = names(parts)))],
rep(NA, nrow(dat) - length(parts_vec))
rep("", nrow(dat) - length(parts_vec))
# rep(NA, nrow(dat) - length(parts_vec))
)
} else {
dat$fontlab <- c(
use_glyph[as.numeric(factor(parts_vec, levels = names(parts)))],
rep(NA, nrow(dat) - length(parts_vec))
# rep(NA, nrow(dat) - length(parts_vec))
rep("", nrow(dat) - length(parts_vec))
)
}
} else if (length(use_glyph) == length(parts_vec)) {
if (glyph_font == "FontAwesome") {
dat$fontlab <- c(.fa_unicode[use_glyph], rep(NA, nrow(dat) - length(parts_vec)))
if (grepl("wesom", glyph_font)) {
fontlab <- .fa_unicode[.fa_unicode[["name"]] %in% use_glyph, "unicode"]
dat$fontlab <- c(fontlab, rep(NA, nrow(dat) - length(parts_vec)))
} else {
dat$fontlab <- c(use_glyph, rep(NA, nrow(dat) - length(parts_vec)))
}
@ -278,4 +285,4 @@ waffle <- function(parts, rows=10, keep=TRUE, xlab=NULL, title=NULL, colors=NA,
gg
}
}

4
README.Rmd

@ -171,7 +171,7 @@ library(extrafont)
waffle(
parts / 10, rows = 3, colors = c("#969696", "#1879bf", "#009bda"),
use_glyph = "medkit", size = 8
)
) + expand_limits(y = c(0, 4))
```
```{r medkit, echo=FALSE, fig.width=6, fig.height=2}
@ -180,7 +180,7 @@ library(extrafont)
waffle(
parts / 10, rows = 3, colors = c("#969696", "#1879bf", "#009bda"),
use_glyph = "medkit", glyph_size = 8
)
) + expand_limits(y = c(0, 4))
```
### Replicating an old favourite

2
README.md

@ -170,7 +170,7 @@ library(extrafont)
waffle(
parts / 10, rows = 3, colors = c("#969696", "#1879bf", "#009bda"),
use_glyph = "medkit", size = 8
)
) + expand_limits(y = c(0, 4))
```
<img src="README_files/figure-gfm/medkit-1.png" width="576" />

BIN
README_files/figure-gfm/medkit-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 30 KiB

2825
inst/css/fontawesome.css

File diff suppressed because it is too large

BIN
inst/extdat/fadf.rds

Binary file not shown.

BIN
inst/fonts/fa-brands-400.ttf

Binary file not shown.

BIN
inst/fonts/fa-regular-400.ttf

Binary file not shown.

BIN
inst/fonts/fa-solid-900.ttf

Binary file not shown.

BIN
inst/fonts/fontawesome-webfont.ttf

Binary file not shown.

BIN
inst/json/icons.json.gz

Binary file not shown.

6
man/fa_grep.Rd

@ -2,13 +2,13 @@
% Please edit documentation in R/fontawesome.R
\name{fa_grep}
\alias{fa_grep}
\title{Search FontAwesome names for a pattern}
\title{Search Font Awesome glyph names for a pattern}
\usage{
fa_grep(pattern)
}
\arguments{
\item{pattern}{pattern to search for in the names of FontAwesome fonts}
\item{pattern}{pattern to search for in the names of Font Awesome fonts}
}
\description{
Search FontAwesome names for a pattern
Search Font Awesome glyph names for a pattern
}

4
man/fa_list.Rd

@ -2,10 +2,10 @@
% Please edit documentation in R/fontawesome.R
\name{fa_list}
\alias{fa_list}
\title{List all FontAwesome names}
\title{List all Font Awesome glyphs}
\usage{
fa_list()
}
\description{
List all FontAwesome names
List all Font Awesome glyphs
}

11
man/install_fa_fonts.Rd

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fontawesome.R
\name{install_fa_fonts}
\alias{install_fa_fonts}
\title{Install Font Awesome 5 Fonts}
\usage{
install_fa_fonts()
}
\description{
Install Font Awesome 5 Fonts
}

4
man/waffle.Rd

@ -7,8 +7,8 @@
waffle(parts, rows = 10, keep = TRUE, xlab = NULL, title = NULL,
colors = NA, size = 2, flip = FALSE, reverse = FALSE,
equal = TRUE, pad = 0, use_glyph = FALSE, glyph_size = 12,
glyph_font = "FontAwesome", glyph_font_family = "FontAwesome",
legend_pos = "right")
glyph_font = "Font Awesome 5 Free Solid",
glyph_font_family = "FontAwesome5Free-Solid", legend_pos = "right")
}
\arguments{
\item{parts}{named vector of values or a data frame to use for the chart}

Loading…
Cancel
Save