Skip to content

Commit

Permalink
add gt_theme_pl
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Weatherman authored and Andrew Weatherman committed Apr 12, 2024
1 parent 5d38be9 commit eebfbe4
Show file tree
Hide file tree
Showing 49 changed files with 753 additions and 67 deletions.
Binary file modified .DS_Store
Binary file not shown.
515 changes: 512 additions & 3 deletions .Rhistory

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .Rproj.user/F7318DF6/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": true
}
],
"path": "~/cbbplotR"
"path": "~/cbbplotR/data-raw"
}
2 changes: 1 addition & 1 deletion .Rproj.user/F7318DF6/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": -1
"activeTab": 3
}
12 changes: 6 additions & 6 deletions .Rproj.user/F7318DF6/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left": {
"splitterpos": 162,
"topwindowstate": "HIDE",
"panelheight": 735,
"windowheight": 773
"topwindowstate": "NORMAL",
"panelheight": 734,
"windowheight": 772
},
"right": {
"splitterpos": 408,
"splitterpos": 479,
"topwindowstate": "NORMAL",
"panelheight": 735,
"windowheight": 773
"panelheight": 734,
"windowheight": 772
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/F7318DF6/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 3,
"TabSet1": 0,
"TabSet2": 0,
"TabZoom": {}
}
2 changes: 1 addition & 1 deletion .Rproj.user/F7318DF6/sources/prop/297CAAA6
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"source_window_id": "",
"Source": "Source",
"cursorPosition": "49,25",
"scrollLine": "0"
"scrollLine": "38"
}
6 changes: 6 additions & 0 deletions .Rproj.user/F7318DF6/sources/prop/INDEX
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
~%2FDesktop%2Fbest_road_teams.R="5F256B0B"
~%2FDesktop%2Fgt_fxs.R="0D2F828C"
~%2FDesktop%2Fpl_gt.R="4A42A659"
~%2FDesktop%2Fpre_tourn_seeds.R="07083CE3"
~%2FDesktop%2Fq1q2.R="D2662DE5"
~%2Fadd_espn_teams.R="A44767F0"
~%2FcbbplotR%2F.github%2Fworkflows%2Fpkgdown.yaml="630E5F39"
~%2FcbbplotR%2FDESCRIPTION="262F9DD4"
Expand All @@ -17,6 +22,7 @@
~%2FcbbplotR%2FR%2Fggplot-utils.R="FDE63583"
~%2FcbbplotR%2FR%2Fggpreview.R="E019B05A"
~%2FcbbplotR%2FR%2Fgt-utils.R="4D9E33EF"
~%2FcbbplotR%2FR%2Fmid_major_composite.R="F29713F8"
~%2FcbbplotR%2FR%2Fscales.R="4011F6F5"
~%2FcbbplotR%2FR%2Ftheme-elements.R="742F2AC5"
~%2FcbbplotR%2FR%2Futils-pipe.R="3CCA13E3"
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cbbplotR
Title: CBB Logo Plots in 'ggplot2'
Version: 0.2.0
Version: 0.3.0
Authors@R:
person("Andrew", "Weatherman", , "[email protected]", role = c("aut", "cre"))
Description: A set of functions to visualize college basketball team and conference
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(gt_cbb_teams)
export(gt_color_results)
export(gt_set_font)
export(gt_theme_athletic)
export(gt_theme_pl)
export(scale_color_cbb_conferences)
export(scale_color_cbb_teams)
export(scale_colour_cbb_conferences)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# cbbplotR 0.3.0
- Added [`gt_theme_pl`](https://cbbplotr.aweatherman.com/reference/gt_theme_pl.html)
- Added ability to customize the amount of vertical alignment in `gt_cbb_teams` and `gt_cbb_conferences`.

# cbbplotR 0.2.0

- Added the ability to select 'dark' team logos in [`gt_cbb_teams`](https://cbbplotr.aweatherman.com/reference/gt_cbb_teams.html)
Expand Down
Binary file added R/.DS_Store
Binary file not shown.
128 changes: 123 additions & 5 deletions R/gt-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,34 +232,39 @@ gt_bold_rows <- function(gt_object,
#' @param logo_height The height of the logo or wordmark in the HTML string
#' @param include_name Should the conference name be included in the column?
#' Defaults to FALSE as wordmarks are distinctive.
#' @param vertical_align The CSS styler for vertical align; defaults to -30%.
#' @import dplyr
#' @importFrom glue glue
#' @importFrom rlang ensym as_string
#' @importFrom magrittr %>%
#'
#' @export
gt_cbb_teams <- function(data, team_column, logo_column = 'team', logo_color = 'normal',
logo_type = 'logo', logo_height = 25, include_name = TRUE) {
logo_type = 'logo', logo_height = 25, name_type = 'full',
include_name = TRUE, vertical_align = '-30%') {

# load the team matches
cbbplotR:::.team_name_matches()
team_matches <- readRDS(cbbplotR:::team_matches_path())
matching_dict <- if(logo_color == 'normal') cbb_logo_links else cbb_dark_logo_links
matching_dict <- if(logo_type == 'logo') matching_dict else cbb_wordmark_links
abbr_dict <- team_abbr_dict

team_column_sym <- rlang::ensym(team_column)

data <- data %>%
dplyr::rowwise() %>%
dplyr::mutate(
converted_team = team_matches[[as.character(.data[[team_column_sym]])]],
team_abbr = abbr_dict[converted_team],
name_used = ifelse(name_type == 'abbr', team_abbr, converted_team),
logo = matching_dict[converted_team]
) %>%
dplyr::mutate(
{{logo_column}} := glue("<img src='{logo}' style='height: {logo_height}px; width: auto; vertical-align: middle;'> {ifelse(include_name, converted_team, '')}")
{{logo_column}} := glue("<img src='{logo}' style='height: {logo_height}px; width: auto; vertical-align: {vertical_align};'> {ifelse(include_name, name_used, '')}")
) %>%
dplyr::ungroup() %>%
dplyr::select(-c(logo, converted_team))
dplyr::select(-c(logo, converted_team, team_abbr, name_used))

return(data)
}
Expand All @@ -284,14 +289,16 @@ gt_cbb_teams <- function(data, team_column, logo_column = 'team', logo_color = '
#' @param logo_height The height of the logo or wordmark in the HTML string
#' @param include_name Should the conference name be included in the column?
#' Defaults to FALSE as wordmarks are distinctive.
#' @param vertical_align The CSS styler for vertical align; defaults to -30%.
#' @import dplyr
#' @importFrom glue glue
#' @importFrom rlang ensym as_string
#' @importFrom magrittr %>%
#'
#' @export
gt_cbb_conferences <- function(data, conf_column, logo_column = 'conf',
logo_height = 20, include_name = FALSE) {
logo_height = 20, include_name = FALSE,
vertical_align = '-30%') {

# load conference matches
cbbplotR:::.conf_name_matches()
Expand All @@ -306,7 +313,7 @@ gt_cbb_conferences <- function(data, conf_column, logo_column = 'conf',
logo = conf_wordmark_links[converted_conf]
) %>%
mutate(
{{logo_column}} := glue("<img src='{logo}' style='height: {logo_height}px; width: auto; vertical-align: middle;'> {ifelse(include_name, converted_conf, '')}")
{{logo_column}} := glue("<img src='{logo}' style='height: {logo_height}px; width: auto; vertical-align: {vertical_align};'> {ifelse(include_name, converted_conf, '')}")
) %>%
ungroup() %>%
select(-c(logo, converted_conf))
Expand Down Expand Up @@ -410,3 +417,114 @@ gt_theme_athletic <- function(gt_object, ...) {
return(table)

}


#' Premier League `gt` Table Theme
#'
#' A theme for styling `gt` tables similar to the Premier League
#' official table.
#'
#' @returns Returns data with an appended HTML column.
#' @param gt_object An existing gt table object of class `gt_tbl`
#' @param ... Optional additional arguments to `gt::table_options()`
#' @import gt
#' @importFrom magrittr %>%
#'
#' @export
gt_theme_pl <- function(gt_object, ...) {

table_id <- subset(gt_object[['_options']], parameter == 'table_id')$value[[1]]

if (is.na(table_id)) {
table_id <- gt::random_id()
opt_position <- which("table_id" %in% gt_object[["_options"]][["parameter"]])[[1]]
gt_object[["_options"]][["value"]][[opt_position]] <- table_id
}

gt_object %>%
gt::tab_style(
locations = gt::cells_body(
columns = gt::everything()
),
style = gt::cell_text(
font = gt::google_font('DM Sans'),
color = '#37003c',
size = px(14)
)
) %>%
gt::tab_style(
locations = gt::cells_column_labels(
columns = gt::everything()
),
style = gt::cell_text(
font = gt::google_font('DM Sans'),
color = '#87668a',
weight = 650,
size = px(12),
transform = 'capitalize'
)
) %>%
gt::tab_style(
locations = gt::cells_title('title'),
style = gt::cell_text(
font = gt::google_font('DM Sans'),
weight = 650
)
) %>%
gt::tab_style(
locations = gt::cells_title('subtitle'),
style = gt::cell_text(
font = gt::google_font('DM Sans'),
weight = 500
)
) %>%
gt::tab_style(
locations = gt::cells_source_notes(),
style = gt::cell_text(
font = gt::google_font('DM Sans'),
)
) %>%
gt::tab_options(
heading.align = "left",
column_labels.border.top.style = "none",
table.border.top.style = "none",
table_body.border.top.style = "none",
table_body.border.bottom.color = "white",
heading.border.bottom.style = "none",
data_row.padding = px(3),
column_labels.font.size = px(12),
table.border.bottom.style = "none",
source_notes.font.size = 10,
source_notes.border.lr.style = "none",
column_labels.border.bottom.style = "solid",
column_labels.border.bottom.width = px(1),
column_labels.border.bottom.color = "#37003c",
...
) %>%
gt::opt_css(
paste0("#", table_id,
" .gt_col_heading
{
padding-bottom: 3px;
}",
"#", table_id,
" .gt_heading
{
padding-bottom: 0px;
padding-top: 6px
}",
"#", table_id,
" .gt_subtitle
{
padding-top: 2px;
padding-bottom: 6px;
}",
"#", table_id,
" .gt_sourcenote
{
line-height: 1.2
}"),
add = TRUE
)

}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ reference:
- gt_set_font
- gt_bold_rows
- gt_theme_athletic
- gt_theme_pl
- title: Other Functions
desc: Miscellaneous functions
contents:
Expand Down
4 changes: 3 additions & 1 deletion data-raw/get_internal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ cbb_wordmark_links <- cbbdata::cbd_teams() %>% mutate(wordmark = ifelse(is.na(wo

cbb_espn_ids <- cbbdata::cbd_teams() %>% pull('espn_id') %>%
rlang::set_names(cbbdata::cbd_teams()$common_team)
#

abbr_dict <- cbd_teams() %>% pull('espn_abbreviation') %>% set_names(cbd_teams() %>% pull('common_team'))

#
dat <- read_csv('/Users/andrewweatherman/conf_logo.csv')
#
Expand Down
Binary file added data/team_abbr_dict.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

6 changes: 3 additions & 3 deletions docs/authors.html

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

2 changes: 1 addition & 1 deletion docs/index.html

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

8 changes: 7 additions & 1 deletion docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
getting_started: getting_started.html
last_built: 2024-01-05T22:40Z
last_built: 2024-04-12T16:59Z
urls:
reference: https://andreweatherman.github.io/cbbplotR/reference
article: https://andreweatherman.github.io/cbbplotR/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/cbbplotR-package.html

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

Loading

0 comments on commit eebfbe4

Please sign in to comment.