Skip to content

Commit

Permalink
Require a 'header' value for new_panel()
Browse files Browse the repository at this point in the history
This ensures we can draw the header even if it should be blank.
  • Loading branch information
joshuaulrich committed Aug 20, 2023
1 parent e2c9ecb commit 8a01735
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ plot.xts <- function(x,
# create a local environment for each panel
lenv <- cs$new_environment()
lenv$xdata <- cs$Env$xdata[subset,i]
lenv$header <- cs$Env$column_names[i]
lenv$type <- cs$Env$type
if(yaxis.same){
lenv$ylim <- cs$Env$constant_ylim
Expand Down Expand Up @@ -493,12 +492,12 @@ plot.xts <- function(x,
this_panel <-
cs$new_panel(lenv$ylim,
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,
header = lenv$header,
envir = lenv)
is_ylim_fixed = lenv$is_ylim_fixed)

# plot data
this_panel$add_action(exp, env = lenv, update_ylim = TRUE)
Expand All @@ -515,6 +514,7 @@ plot.xts <- function(x,
cs$new_panel(ylim = yrange,
asp = 3,
envir = cs$Env,
header = "",
is_ylim_fixed = yfixed,
use_get_ylim = TRUE,
draw_left_yaxis = yaxis.left,
Expand Down Expand Up @@ -589,7 +589,6 @@ addPanel <- function(FUN, main="", on=NA, type="l", col=NULL, lty=1, lwd=1, pch=
addSeries <- function(x, main="", on=NA, type="l", col=NULL, lty=1, lwd=1, pch=1, ...){
plot_object <- current.xts_chob()
lenv <- plot_object$new_environment()
lenv$header <- main
lenv$plot_lines <- function(x, ta, on, type, col, lty, lwd, pch, ...){
xdata <- x$Env$xdata
xsubset <- x$Env$xsubset
Expand Down Expand Up @@ -653,7 +652,7 @@ addSeries <- function(x, main="", on=NA, type="l", col=NULL, lty=1, lwd=1, pch=1
this_panel <- plot_object$new_panel(lenv$ylim,
asp = 1,
envir = lenv,
header = lenv$header)
header = main)

# plot data
this_panel$add_action(exp, env = lenv, update_ylim = FALSE)
Expand Down Expand Up @@ -705,7 +704,6 @@ addEventLines <- function(events, main="", on=0, lty=1, lwd=1, col=1, ...){
}

lenv <- plot_object$new_environment()
lenv$header <- main
lenv$plot_event_lines <- function(x, events, on, lty, lwd, col, ...){
xdata <- x$Env$xdata
xsubset <- x$Env$xsubset
Expand Down Expand Up @@ -758,7 +756,7 @@ addEventLines <- function(events, main="", on=0, lty=1, lwd=1, col=1, ...){
this_panel <- plot_object$new_panel(lenv$ylim,
asp = 1,
envir = lenv,
header = lenv$header)
header = main)

# plot data
this_panel$add_action(exp, env = lenv, update_ylim = FALSE)
Expand Down Expand Up @@ -835,7 +833,10 @@ addLegend <- function(legend.loc="topright", legend.names=NULL, col=NULL, ncol=1
if(is.na(on[1])){

# add legend to a new panel
this_panel <- plot_object$new_panel(c(0, 1), asp = 0.8, envir = lenv)
this_panel <- plot_object$new_panel(ylim = c(0, 1),
asp = 0.8,
envir = lenv,
header = "")

# legend data
this_panel$add_action(exp, env = lenv, update_ylim = FALSE)
Expand Down Expand Up @@ -879,7 +880,6 @@ addPolygon <- function(x, y=NULL, main="", on=NA, col=NULL, ...){

plot_object <- current.xts_chob()
lenv <- plot_object$new_environment()
lenv$header <- main
lenv$plot_lines <- function(x, ta, on, col, ...){
xdata <- x$Env$xdata
xsubset <- x$Env$xsubset
Expand Down Expand Up @@ -936,7 +936,7 @@ addPolygon <- function(x, y=NULL, main="", on=NA, col=NULL, ...){
this_panel <- plot_object$new_panel(ylim = lenv$ylim,
asp = 1,
envir = lenv,
header = lenv$header)
header = main)

# plot data
this_panel$add_action(exp, env = lenv, update_ylim = FALSE)
Expand Down Expand Up @@ -1200,12 +1200,12 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
function(ylim,
asp,
envir,
header,
...,
is_ylim_fixed = TRUE,
use_get_ylim = FALSE,
draw_left_yaxis = NULL,
draw_right_yaxis = NULL,
header = "",
title_timespan = FALSE)
{
panel <- new.env(TRUE, envir)
Expand Down

0 comments on commit 8a01735

Please sign in to comment.