Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trim imports #25

Merged
merged 9 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ Depends:
R (>= 4.0.0)
Imports:
ggplot2,
glue,
grid,
rlang,
scales
vctrs,
grid
Suggests:
covr,
RColorBrewer,
testthat (>= 3.0.0),
withr
testthat (>= 3.0.0)
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
Collate:
'a-legend-draw.R'
'data.R'
'geom-path-trace.R'
'geom-point-trace.R'
'ggtrace-package.R'
'utilities-ggplot2.R'
37 changes: 10 additions & 27 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
# Generated by roxygen2: do not edit by hand

export("%||%")
export(":=")
export(.data)
S3method(single_value,default)
S3method(single_value,factor)
export(GeomLineTrace)
export(GeomPathTrace)
export(GeomPointTrace)
export(as_label)
export(as_name)
export(GeomStepTrace)
export(draw_key_path_trace)
export(draw_key_point_trace)
export(enexpr)
export(enquo)
export(enquos)
export(expr)
export(geom_line_trace)
export(geom_path_trace)
export(geom_point_trace)
export(sym)
export(syms)
export(geom_step_trace)
import(ggplot2)
importFrom(grid,gpar)
importFrom(grid,grobName)
importFrom(grid,grobTree)
importFrom(grid,pointsGrob)
importFrom(rlang,"%||%")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,abort)
importFrom(rlang,as_label)
importFrom(rlang,as_name)
importFrom(rlang,enexpr)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,expr)
importFrom(rlang,is_call)
importFrom(rlang,is_function)
importFrom(rlang,is_missing)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(rlang,warn)
importFrom(vctrs,vec_group_id)
73 changes: 66 additions & 7 deletions R/a-legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#' p + geom_line(key_glyph = draw_key_rect)
#' }
#' @return A grid grob.
#' @name draw_key
NULL

#' @rdname draw_key
#' @export
draw_key_point_trace <- function(data, params, size) {

Expand All @@ -33,28 +37,83 @@ draw_key_point_trace <- function(data, params, size) {
data$trace_shape <- translate_trace_shape(data$shape)
data <- calculate_trace_size(data)

# Replace NULL values in data
data$colour[is.null(data$colour)] <- "black"
data$fill[is.null(data$fill)] <- "white"
data$linetype[is.null(data$linetype)] <- 1
data$size[is.null(data$size)] <- 1.5

# Trace grob
pt_stroke <- 0.5

g_trace <- grid::pointsGrob(
trace_grob <- grid::pointsGrob(
0.5, 0.5,
pch = data$trace_shape,
gp = grid::gpar(
col = alpha(data$colour %||% "black", 1),
lty = data$linetype %||% 1,
col = alpha(data$colour, 1),
lty = data$linetype,
fontsize = data$trace_fontsize,
lwd = data$trace_lwd
)
)

g_points <- grid::pointsGrob(
# Points grob
points_grob <- grid::pointsGrob(
0.5, 0.5,
pch = data$shape,
gp = grid::gpar(
col = alpha(data$fill %||% "white", data$alpha),
fontsize = (data$size %||% 1.5) * .pt + pt_stroke * .stroke / 2,
col = alpha(data$fill, data$alpha),
fontsize = data$size * .pt + pt_stroke * .stroke / 2,
lwd = pt_stroke * .stroke / 2
)
)

grid::grobTree(g_trace, g_points)
grid::grobTree(trace_grob, points_grob)
}

#' @export
#' @rdname draw_key
draw_key_path_trace <- function(data, params, size) {

# Replace NULL values in data
if (is.null(data$linetype)) {
data$linetype <- 1

} else {
data$linetype[is.na(data$linetype)] <- 1
}

data$colour[is.null(data$colour)] <- "black"
data$fill[is.null(data$fill)] <- "white"
data$size[is.null(data$size)] <- 0.5

# Trace grob
trace_grob <- grid::segmentsGrob(
0.1, 0.5, 0.9, 0.5,

gp = grid::gpar(
col = alpha(data$colour, 1),
lwd = data$size * .pt + data$stroke * .pt * 2,
lty = 1,
lineend = "butt"
),

arrow = params$arrow
)

# Segments grob
points_grob <- grid::segmentsGrob(
0.1, 0.5, 0.9, 0.5,

gp = grid::gpar(
col = alpha(data$fill, 1),
lwd = data$size * .pt,
lty = data$linetype,
lineend = "butt"
),

arrow = params$arrow
)

grid::grobTree(trace_grob, points_grob)
}
Loading