Skip to content

Commit

Permalink
[misc] add a hex icon (#1225)
Browse files Browse the repository at this point in the history
* [misc] add hex icon

* [vignettes] align title and vignette index entry
  • Loading branch information
JanMarvin authored Dec 29, 2024
1 parent 26f1308 commit e31e721
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ knitr::opts_chunk$set(
)
```

# openxlsx2
# openxlsx2 <img src="man/figures/logo.png" align="right" height="139" />

<!-- badges: start -->
[![R-CMD-check](https://github.com/JanMarvin/openxlsx2/workflows/R-CMD-check/badge.svg)](https://github.com/JanMarvin/openxlsx2/actions)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# openxlsx2
# openxlsx2 <img src="man/figures/logo.png" align="right" height="139" />

<!-- badges: start -->

Expand Down
81 changes: 81 additions & 0 deletions inst/extdata/hex_icon.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# install.packages(c("hexSticker", "showtext"))
library(openxlsx2)
library(ggplot2)
library(hexSticker)
library(showtext)

## create the background in a spreadsheet matrix
wb <- wb_workbook()$add_worksheet(grid_lines = FALSE)$
set_row_heights(rows = 1:5 + 1L, heights = 15)$
set_col_widths(cols = 1:5 + 1L, width = 2.15)

mm <- matrix(0, 5, 5)
# Fill the secondary diagonals with unique values
for (k in 1:10) { # Loop over all diagonals relative to the main diagonal
idx <- which(row(mm) + col(mm) - 1 == k, arr.ind = TRUE)
mm[idx] <- k # Assign the value k or any sequence
}

tm <- mm - 4
tm[tm < 1] <- 0

# Palette from https://loading.io/color/feature/Greens-5/
# Loading.io Free License
#
# With Loading.io Free license ( LD-FREE / FREE / Free License ), items are
# dedicated to the public domain by waiving all our right worldwide under
# copyright law. You can use items under LD-FREE freely for any purpose. No
# attribution is required.
greens <- c("#edf8e9", "#bae4b3", "#74c476", "#31a354", "#006d2c")

for (i in 1:5) {
coords <- as.data.frame(which(tm == i, arr.ind = TRUE))
dims <- paste0(
mapply(coords$row, coords$col, FUN = function(x, y) {
wb_dims(rows = x, cols = y, from_dims = "B2")
}), collapse = ",")
wb$add_fill(dims = dims, color = wb_color(greens[i]))
}

# screenshot the area and save to file
if (interactive()) wb$open()

df <- as.data.frame(as.table(tm))
colnames(df) <- c("x", "y", "value")

# Define the green color palette, with white for 0
greens <- c("0" = "white", setNames(greens, 1:5)) # or "transparent"

# Create the ggplot
gg <- ggplot(df, aes(x = x, y = y, fill = as.character(value))) +
geom_tile() + # Add black borders to tiles
scale_y_discrete(limits = rev) + # Reverse the y-axis to align with bottom-left orientation
scale_fill_manual(values = greens, guide = "none") + # Use custom color mapping
coord_fixed() + # Keep tiles square
theme_void() + # Minimalist theme
theme(legend.position = "none") + # Remove legend
labs(x = NULL, y = NULL) # Remove axis labels

## Loading Google fonts (http://www.google.com/fonts)
# All Noto fonts are licensed under the Open Font License.
# You can use them in all your products & projects — print or digital,
# commercial or otherwise.
font_add_google("Noto sans", "noto")

s <- sticker(gg, package = "openxlsx2",
s_x = 1, s_y = 1, s_width = 1, s_height = 1,
h_fill = greens[1], h_color = greens[length(greens)], h_size = 1,
p_size = 25, p_color = greens[length(greens)], p_x = 1, p_y = 1.1,
p_family = "noto", p_fontface = "bold",
filename = "man/figures/logo.png")

s

# imgurl <- "inst/img/openxlsx2.png"
# s <- sticker(imgurl, package = "openxlsx2",
# s_x = 1, s_y = 1, s_width = .6, spotlight = FALSE,
# h_fill = "#FFF", h_color = greens[5], h_size = 1,
# p_size = 25, p_color = greens[5], p_x = 1, p_y = 1.1,
# p_family = "noto", p_fontface = "bold",
# filename = "man/figures/logo.png")
# s
Binary file added inst/img/openxlsx2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vignettes/openxlsx2_read_to_df.Rmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "openxlsx2 read to data frame manual"
title: "openxlsx2 read to data frame"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{openxlsx2 read to dataframe}
%\VignetteIndexEntry{openxlsx2 read to data frame}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down

0 comments on commit e31e721

Please sign in to comment.