Skip to content

Commit

Permalink
Remove 'use_get_ylim' and use 'is_ylim_fixed'
Browse files Browse the repository at this point in the history
Multi-panel plots were the only time 'use_get_ylim' was TRUE. And the
only time it had any effect was when 'is_ylim_fixed' was also FALSE,
which was only true when 'yaxis.same' was TRUE.

This was one of two times we had to re-calculate the 'ylim' based on
every panel. The other time was when 'ylim' is NULL and 'multi.panel'
was FALSE. And 'is_ylim_fixed' is also FALSE in that case, so we know
to re-calculate 'ylim' whenever 'is_ylim_fixed' is FALSE.

See #103.
  • Loading branch information
joshuaulrich committed Oct 6, 2023
1 parent 37eb2c7 commit 701f0fa
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ plot.xts <- function(x,
asp = asp,
envir = lenv,
header = cs$Env$column_names[i],
use_get_ylim = TRUE,
draw_left_yaxis = yaxis.left,
draw_right_yaxis = yaxis.right,
is_ylim_fixed = lenv$is_ylim_fixed)
Expand All @@ -492,7 +491,6 @@ plot.xts <- function(x,
envir = cs$Env,
header = "",
is_ylim_fixed = yfixed,
use_get_ylim = TRUE,
draw_left_yaxis = yaxis.left,
draw_right_yaxis = yaxis.right)

Expand Down Expand Up @@ -1161,7 +1159,6 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
header,
...,
is_ylim_fixed = TRUE,
use_get_ylim = FALSE,
draw_left_yaxis = NULL,
draw_right_yaxis = NULL,
title_timespan = FALSE)
Expand All @@ -1172,7 +1169,6 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
panel$ylim <- ylim
panel$ylim_render <- ylim
panel$is_ylim_fixed <- is_ylim_fixed
panel$use_get_ylim <- use_get_ylim
panel$draw_left_yaxis <- ifelse(is.null(draw_left_yaxis), Env$theme$lylab, draw_left_yaxis)
panel$draw_right_yaxis <- ifelse(is.null(draw_right_yaxis), Env$theme$rylab, draw_right_yaxis)
panel$header <- header
Expand Down Expand Up @@ -1216,9 +1212,9 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
### y-axis
yaxis_expr <- expression({

if (use_get_ylim) {
# re-calculate and override panel ylim
ylim <- get_ylim()
if (!is_ylim_fixed) {
# use the ylim based on all panels' data
ylim <- ylim_render
}

# y-axis grid line locations
Expand Down Expand Up @@ -1280,18 +1276,15 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
if (!panel$is_ylim_fixed) {
# set ylim to +/-Inf when fixed = FALSE so update_panel() recalculates ylim
panel$ylim_render <- c(Inf, -Inf)
panel$is_ylim_fixed <- FALSE
}
}

update_panel <- function(panel_n)
{
# recalculate the panel's ylim based on actions added to the panel

# reset all ylim values, by looking for range(env[[1]]$xdata)
# xdata should be either coming from Env or if lenv, lenv
for (panel_n in seq_along(Env$panels)) {
panel <- get_panel(panel_n)
is_fixed <- panel$is_ylim_fixed # cache original value

if (!is_fixed) {
if (!panel$is_ylim_fixed) {
for (action in panel$actions) {

action_update_ylim <- attr(action, "update_ylim")
Expand All @@ -1309,16 +1302,10 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10

# set to new ylim values
panel$ylim_render <- new_ylim
panel$is_ylim_fixed <- is_fixed # use original value
}
}
}
}
# reset all ylim values, by looking for range(env[[1]]$xdata)
# xdata should be either coming from Env or if lenv, lenv
for (panel_n in seq_along(Env$panels)) {
update_panel(panel_n)
}

update_xaxis <- function(panel, x_axis)
{
Expand Down

0 comments on commit 701f0fa

Please sign in to comment.