Skip to content

Commit

Permalink
controls appearance: support for axis text options
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Mar 12, 2024
1 parent 3f6809f commit 90d94ae
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
116 changes: 114 additions & 2 deletions R/module-controls-appearance.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ controls_appearance_ui <- function(id) {
"plus", "cross", "asterisk"
)

tagList(
tags$div(
style = css(
maxHeight = "80vh",
overflowY = "auto",
overflowX = "hidden",
padding = "5px 7px"
),
tags$div(
id = ns("controls-fill-color"), style = "display: block;",
shinyWidgets::colorPickr(
Expand Down Expand Up @@ -121,7 +127,9 @@ controls_appearance_ui <- function(id) {
selected = "center",
justified = TRUE,
size = "sm"
)
),
input_axis_text("x", ns = ns),
input_axis_text("y", ns = ns)
)
}

Expand Down Expand Up @@ -169,6 +177,20 @@ controls_appearance_server <- function(id,
theme = input$theme,
legend_position = legend_position,
legend_justification = legend_justification,
axis_text_x = get_axis_text(
input$x_axis_text_face,
input$x_axis_text_size,
input$x_axis_text_angle,
input$x_axis_text_hjust,
input$x_axis_text_vjust
),
axis_text_y = get_axis_text(
input$y_axis_text_face,
input$y_axis_text_size,
input$y_axis_text_angle,
input$y_axis_text_hjust,
input$y_axis_text_vjust
),
shape = shape
)
})
Expand All @@ -191,3 +213,93 @@ controls_appearance_server <- function(id,
}
)
}



get_axis_text <- function(face, size, angle, hjust, vjust, lineheight = 1) {
options <- dropNulls(list(
face = if (face != "plain") face,
size = if (size != 10) size,
angle = if (angle != 0) angle,
hjust = if (hjust != 0) hjust,
vjust = if (vjust != 0) vjust,
lineheight = if (lineheight != 1) lineheight
))
if (length(options) > 0) {
call2("element_text", !!!options)
} else {
NULL
}
}


input_axis_text <- function(axis = c("x", "y"), ns = identity) {
axis <- match.arg(axis)
tagList(
tags$b(toupper(axis), "axis text options:"),
tags$div(
style = css(
display = "grid",
gridTemplateColumns = "repeat(3, 1fr)",
gridColumnGap = "2px"
),
shinyWidgets::virtualSelectInput(
inputId = ns(paste0(axis, "_axis_text_face")),
label = "Font face:",
choices = setNames(
c("plain", "italic", "bold", "bold.italic"),
c("Plain", "Italic", "Bold", "Bold/Italic")
),
width = "100%"
),
numericInput(
inputId = ns(paste0(axis, "_axis_text_size")),
label = "Size:",
value = 10,
min = 0,
width = "100%"
),
numericInput(
inputId = ns(paste0(axis, "_axis_text_angle")),
label = "Angle:",
value = 0,
min = 0,
max = 360,
width = "100%"
)
),
tags$div(
style = css(
display = "grid",
gridTemplateColumns = "repeat(2, 1fr)",
gridColumnGap = "2px"
),
numericInput(
inputId = ns(paste0(axis, "_axis_text_hjust")),
label = "Horizontal justification:",
value = 0,
min = 0,
step = 0.1,
max = 1,
width = "100%"
),
numericInput(
inputId = ns(paste0(axis, "_axis_text_vjust")),
label = "Vertical justification:",
value = 0,
min = 0,
step = 0.1,
max = 1,
width = "100%"
)#,
# numericInput(
# inputId = ns(paste0(axis, "_axis_text_lineheight")),
# label = "Line height:",
# value = 1,
# step = 0.1,
# width = "100%"
# )
)
)
}

4 changes: 3 additions & 1 deletion R/module-controls.R
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ controls_server <- function(id,
plot.subtitle = theme_labs$subtitle,
plot.caption = theme_labs$caption,
axis.title.y = theme_labs$y,
axis.title.x = theme_labs$x
axis.title.x = theme_labs$x,
axis.text.y = theme_appearance$axis_text_y,
axis.text.x = theme_appearance$axis_text_x
)
)
)
Expand Down
5 changes: 5 additions & 0 deletions inst/assets/esquisse/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
padding: 2px !important;
}

.esquisse-controls-appearance .sw-dropdown-in {
padding: 0 !important;
margin: 0 !important;
}


.esquisse-labs-options {
display: grid;
Expand Down

0 comments on commit 90d94ae

Please sign in to comment.