Skip to content

Commit

Permalink
Merge pull request #36 from nrennie/update-linting
Browse files Browse the repository at this point in the history
Add link to issues in DESCRIPTION and update linting
  • Loading branch information
nrennie committed Dec 20, 2023
2 parents 89efc5b + 1be7f53 commit ff34410
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 52 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggflowchart
Title: Flowcharts with 'ggplot2'
Version: 1.0.0.9006
Version: 1.0.0.9007
Authors@R:
person(given = "Nicola",
family = "Rennie",
Expand Down Expand Up @@ -31,4 +31,5 @@ RoxygenNote: 7.2.3
VignetteBuilder: knitr
Config/Needs/website: nrennie/nrenniepkgdown
URL: https://nrennie.github.io/ggflowchart/
BugReports: https://github.com/nrennie/ggflowchart/issues
Config/testthat/edition: 3
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ggflowchart 1.0.0.9000+ 2023_07_14
## ggflowchart 1.0.0.9000+ 2023_12_20

* Add vignette on how to style nodes
* Add initial unit testing
Expand All @@ -7,6 +7,8 @@
* Add contributor guidelines
* Add option to parse text in nodes.
* Update README
* Update linting
* Add link to issues in Description
* Add `alpha` as argument
* Same level arrows support (issue #5)
* Add option for custom layout (issue #11)
Expand Down
118 changes: 73 additions & 45 deletions R/get_edges.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,93 +24,121 @@ get_edges <- function(data, plot_nodes, node_layout) {
data = data,
plot_nodes = plot_nodes,
node_layout = node_layout
)
)
# compute start and end points for each type of edge
# Downwards (default)
plot_edge_down <- edge_type_data %>%
dplyr::filter(.data$arrow_direction == "down") %>%
dplyr::select(c(.data$from, .data$to)) %>%
dplyr::mutate(id = paste("down", dplyr::row_number())) %>%
tidyr::pivot_longer(cols = c("from", "to"),
names_to = "s_e",
values_to = "name") %>%
tidyr::pivot_longer(
cols = c("from", "to"),
names_to = "s_e",
values_to = "name"
) %>%
dplyr::left_join(
dplyr::select(plot_nodes, -c(.data$x_nudge, .data$y_nudge)),
by = "name"
) %>%
dplyr::select(-c(.data$y,
.data$xmin,
.data$xmax)) %>%
) %>%
dplyr::select(-c(
.data$y,
.data$xmin,
.data$xmax
)) %>%
dplyr::mutate(y = ifelse(.data$s_e == "from",
.data$ymin,
.data$ymax)) %>%
dplyr::select(-c(.data$ymin,
.data$ymax))
.data$ymin,
.data$ymax
)) %>%
dplyr::select(-c(
.data$ymin,
.data$ymax
))
# Upwards
plot_edge_up <- edge_type_data %>%
dplyr::filter(.data$arrow_direction == "up") %>%
dplyr::select(c(.data$from, .data$to)) %>%
dplyr::mutate(id = paste("up", dplyr::row_number())) %>%
tidyr::pivot_longer(cols = c("from", "to"),
names_to = "s_e",
values_to = "name") %>%
tidyr::pivot_longer(
cols = c("from", "to"),
names_to = "s_e",
values_to = "name"
) %>%
dplyr::left_join(
dplyr::select(plot_nodes, -c(.data$x_nudge, .data$y_nudge)),
by = "name"
) %>%
dplyr::select(-c(.data$y,
.data$xmin,
.data$xmax)) %>%
) %>%
dplyr::select(-c(
.data$y,
.data$xmin,
.data$xmax
)) %>%
dplyr::mutate(y = ifelse(.data$s_e == "from",
.data$ymax,
.data$ymin)) %>%
dplyr::select(-c(.data$ymin,
.data$ymax))
.data$ymax,
.data$ymin
)) %>%
dplyr::select(-c(
.data$ymin,
.data$ymax
))
# Left to right
plot_edge_lr <- edge_type_data %>%
dplyr::filter(.data$arrow_direction == "lr") %>%
dplyr::select(c(.data$from, .data$to)) %>%
dplyr::mutate(id = paste("lr", dplyr::row_number())) %>%
tidyr::pivot_longer(cols = c("from", "to"),
names_to = "s_e",
values_to = "name") %>%
tidyr::pivot_longer(
cols = c("from", "to"),
names_to = "s_e",
values_to = "name"
) %>%
dplyr::left_join(
dplyr::select(
plot_nodes, -c(.data$x_nudge, .data$y_nudge)
),
),
by = "name"
) %>%
dplyr::select(-c(.data$x,
.data$ymin,
.data$ymax)) %>%
dplyr::select(-c(
.data$x,
.data$ymin,
.data$ymax
)) %>%
dplyr::mutate(x = ifelse(.data$s_e == "from",
.data$xmax,
.data$xmin)) %>%
dplyr::select(-c(.data$xmin,
.data$xmax))
.data$xmax,
.data$xmin
)) %>%
dplyr::select(-c(
.data$xmin,
.data$xmax
))
# right to left
plot_edge_rl <- edge_type_data %>%
dplyr::filter(.data$arrow_direction == "rl") %>%
dplyr::select(c(.data$from, .data$to)) %>%
dplyr::mutate(id = paste("rl", dplyr::row_number())) %>%
tidyr::pivot_longer(cols = c("from", "to"),
names_to = "s_e",
values_to = "name") %>%
tidyr::pivot_longer(
cols = c("from", "to"),
names_to = "s_e",
values_to = "name"
) %>%
dplyr::left_join(
dplyr::select(plot_nodes, -c(.data$x_nudge, .data$y_nudge)),
by = "name"
) %>%
dplyr::select(-c(.data$x,
.data$ymin,
.data$ymax)) %>%
dplyr::select(-c(
.data$x,
.data$ymin,
.data$ymax
)) %>%
dplyr::mutate(x = ifelse(.data$s_e == "from",
.data$xmin,
.data$xmax)) %>%
dplyr::select(-c(.data$xmin,
.data$xmax))
.data$xmin,
.data$xmax
)) %>%
dplyr::select(-c(
.data$xmin,
.data$xmax
))
# join data set together
plot_edges <- rbind(
plot_edge_up, plot_edge_down, plot_edge_rl, plot_edge_lr
)
)
return(plot_edges)
}
4 changes: 2 additions & 2 deletions R/ggflowchart.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ggflowchart <- function(data,
data = data,
layout = layout,
node_data = node_data
)
)
# add edge attributes
if (layout == "custom") {
node_layout <- add_node_attr(
Expand Down Expand Up @@ -220,7 +220,7 @@ ggflowchart <- function(data,
ggplot2::theme_void() +
ggplot2::theme(
plot.margin = ggplot2::unit(c(0.5, 0.5, 0.5, 0.5), unit = "cm")
)
)
# add arrow edge labels
if (!is.null(edge_labels)) {
p <- p +
Expand Down
7 changes: 4 additions & 3 deletions vignettes/layout-options.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ library(dplyr)
# generate edges
data <- tibble::tribble(
~from, ~to,
~from, ~to,
"A", "B",
"A", "C",
"A", "D"
)
)
# use a different layout from {igraph}
g <- igraph::graph_from_data_frame(
select(data, c(from, to)),
directed = TRUE)
directed = TRUE
)
coords <- igraph::layout_as_star(g)
colnames(coords) <- c("x", "y")
node_data <- tibble::as_tibble(coords) %>%
Expand Down

0 comments on commit ff34410

Please sign in to comment.