Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Fixed bug in strip text and axis text in cat_plot_html
Browse files Browse the repository at this point in the history
  • Loading branch information
sda030 committed Aug 23, 2024
1 parent c374d40 commit 322f610
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions R/make_content.cat_plot_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ make_content.cat_plot_html <-
length(indep_vars) == 0 &&
dplyr::n_distinct(data$.variable_label) == 1

if(isTRUE(hide_axis_text)) {
data$.variable_label <- ""

Check warning on line 19 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L18-L19

Added lines #L18 - L19 were not covered by tests
}

max_nchar_cat <- max(nchar(levels(data$.category)), na.rm = TRUE)

percentage <- dots$data_label %in% c("percentage", "percentage_bare")
Expand All @@ -27,6 +31,7 @@ make_content.cat_plot_html <-
within = data[, c(".variable_label")],
fun = mean, na.rm=TRUE)
}

p <-
dplyr::mutate(data,
.id = seq_len(nrow(data)),
Expand Down Expand Up @@ -105,34 +110,46 @@ make_content.cat_plot_html <-
(dplyr::n_distinct(data$.variable_label) > 1 ||
(dplyr::n_distinct(data$.variable_label) == 1 &&
isFALSE(dots$hide_axis_text_if_single_variable))))) {
lab <- ".label"
p$data[[lab]] <- string_wrap(p$data[[lab]], width = dots$x_axis_label_width)
if(!dots$inverse) {

if(isFALSE(dots$inverse)) {
lab <- ".variable_label"
if(is.factor(p$data[[lab]])) {
levels(p$data[[lab]]) <- string_wrap(levels(p$data[[lab]]), width = dots$strip_width)

Check warning on line 117 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L114-L117

Added lines #L114 - L117 were not covered by tests
} else {
p$data[[lab]] <- string_wrap(p$data[[lab]], width = dots$strip_width)

Check warning on line 119 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L119

Added line #L119 was not covered by tests
}

p <- p +
ggiraph::facet_grid_interactive(
rows = ggplot2::vars(.data$.variable_label),
labeller = ggiraph::labeller_interactive(
.mapping = ggplot2::aes(
data_id = .data$.variable_label,
tooltip = .data$.variable_label#,
# label = .data[[lab]]
data_id = .data[[lab]],
tooltip = .data[[lab]]

Check warning on line 128 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L127-L128

Added lines #L127 - L128 were not covered by tests
)
),
interactive_on = "text",
switch = "y", scales = "free", space = "free_y"
)
} else {

} else if(isTRUE(dots$inverse)) {

Check warning on line 135 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L135

Added line #L135 was not covered by tests

for(lab in indep_vars) {
if(is.factor(p$data[[lab]])) {
levels(p$data[[lab]]) <- string_wrap(levels(p$data[[lab]]), width = dots$strip_width)

Check warning on line 139 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L137-L139

Added lines #L137 - L139 were not covered by tests
} else {
p$data[[lab]] <- string_wrap(p$data[[lab]], width = dots$strip_width)

Check warning on line 141 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L141

Added line #L141 was not covered by tests
}

}

p <- p +
ggiraph::facet_grid_interactive(
rows = ggplot2::vars(.data[[indep_vars]]),
labeller = ggiraph::labeller_interactive(
.mapping = ggplot2::aes(
data_id = .data[[indep_vars]],
tooltip = .data[[indep_vars]]#,
# label = string_wrap(.data[[if(prop_family) indep_vars else ".label"]], # ????????????????????
# width = dots$x_axis_label_width
# )
tooltip = .data[[indep_vars]]

Check warning on line 152 in R/make_content.cat_plot_html.R

View check run for this annotation

Codecov / codecov/patch

R/make_content.cat_plot_html.R#L152

Added line #L152 was not covered by tests
)
),
interactive_on = "text",
Expand Down

0 comments on commit 322f610

Please sign in to comment.