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

Second axis with asis mode #84

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
skip non asis
  • Loading branch information
JanMarvin committed May 4, 2024
commit 5cccc295179b457e995f9ebf2a04e88b0faf1bd6
69 changes: 39 additions & 30 deletions R/ms_chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,47 +184,56 @@ ms_combochart <- function(...) {

inputs <- list(...)

out <- inputs[[1]]

sec_cntr_x <- 0
sec_cntr_y <- 0

for (i in seq_along(inputs)[-1]) {
for (i in seq_along(inputs)) {

if (!inherits(inputs[[i]], "ms_chart")) {
warning("skipping element: ", inputs[[i]])
warning("Skipping non ms_chart element: ", i)
next
}

is_sec_x <- isTRUE(attr(inputs[[i]], "secondary_x"))
is_sec_y <- isTRUE(attr(inputs[[i]], "secondary_y"))

sec_cntr_x <- sum(sec_cntr_x, is_sec_x)
sec_cntr_y <- sum(sec_cntr_y, is_sec_y)

# avoid additional labels. only one axis label and one title per chart
# title and x axis have to be defined in the first mschart
lbl <- inputs[[i]]$labels
xlab <- lbl$x
ylab <- lbl$y

# disable additional x and y axis for add and secondary_y
if ((i > 1 && !is_sec_y&& !is_sec_x) || (sec_cntr_y > 1 && is_sec_y)) {
inputs[[i]]$x_axis <- axis_options(axis_position = "b", delete = 1L)
inputs[[i]]$y_axis <- axis_options(axis_position = "l", delete = 1L)
ylab <- NULL
} else if ((i > 1 && !is_sec_y && !is_sec_x) || (sec_cntr_x > 1 && is_sec_x)) {
inputs[[i]]$x_axis <- axis_options(axis_position = "t", delete = 1L)
inputs[[i]]$y_axis <- axis_options(axis_position = "l", delete = 1L)
xlab <- NULL
if (!inputs[[i]]$asis) {
warning("Skipping non asis element: ", i)
next
}

inputs[[i]]$labels$title <- list(title = NULL, x = xlab, y = ylab)
if (i == 1)
out <- inputs[[1]]

if (is.null(out$secondary)) {
out$secondary <- list(inputs[[i]])
} else {
out$secondary <- append(out$secondary, list(inputs[[i]]))
if (i > 1) {

is_sec_x <- isTRUE(attr(inputs[[i]], "secondary_x"))
is_sec_y <- isTRUE(attr(inputs[[i]], "secondary_y"))

sec_cntr_x <- sum(sec_cntr_x, is_sec_x)
sec_cntr_y <- sum(sec_cntr_y, is_sec_y)

# avoid additional labels. only one axis label and one title per chart
# title and x axis have to be defined in the first mschart
lbl <- inputs[[i]]$labels
xlab <- lbl$x
ylab <- lbl$y

# disable additional x and y axis for add and secondary_y
if (sec_cntr_y > 1 && is_sec_y) {
inputs[[i]]$x_axis <- axis_options(axis_position = "b", delete = 1L)
inputs[[i]]$y_axis <- axis_options(axis_position = "l", delete = 1L)
ylab <- NULL
} else if (sec_cntr_x > 1 && is_sec_x) {
inputs[[i]]$x_axis <- axis_options(axis_position = "t", delete = 1L)
inputs[[i]]$y_axis <- axis_options(axis_position = "l", delete = 1L)
xlab <- NULL
}

inputs[[i]]$labels$title <- list(title = NULL, x = xlab, y = ylab)

if (is.null(out$secondary)) {
out$secondary <- list(inputs[[i]])
} else {
out$secondary <- append(out$secondary, list(inputs[[i]]))
}
}
}

Expand Down