Skip to content

Commit 7ce0e62

Browse files
committed
autoplot() trimming
trim to spectrum only if adding summaries, otherwise trim wb to range argument value.
1 parent 0597815 commit 7ce0e62

File tree

5 files changed

+122
-67
lines changed

5 files changed

+122
-67
lines changed

R/autoplot-response-spct.r

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ e_rsp_plot <- function(spct,
7575
spct <- photobiology::trim_wl(spct, range = range)
7676
}
7777
if (!is.null(w.band)) {
78-
w.band <- photobiology::trim_wl(w.band, range = photobiology::wl_range(spct))
78+
if ("summaries" %in% annotations) {
79+
# boxes or segments display summarised wavelengths
80+
w.band <- photobiology::trim_wl(w.band,
81+
range = photobiology::wl_range(spct))
82+
} else {
83+
# boxes and segments display wavebands' definitions if they fit in plot
84+
w.band <- photobiology::trim_wl(w.band, range = range)
85+
}
7986
}
8087

8188
exposure.label <- NA
@@ -328,8 +335,14 @@ q_rsp_plot <- function(spct,
328335
spct <- photobiology::trim_wl(spct, range = range)
329336
}
330337
if (!is.null(w.band)) {
331-
w.band <- photobiology::trim_wl(w.band,
332-
range = photobiology::wl_range(spct))
338+
if ("summaries" %in% annotations) {
339+
# boxes or segments display summarised wavelengths
340+
w.band <- photobiology::trim_wl(w.band,
341+
range = photobiology::wl_range(spct))
342+
} else {
343+
# boxes and segments display wavebands' definitions if they fit in plot
344+
w.band <- photobiology::trim_wl(w.band, range = range)
345+
}
333346
}
334347

335348
exposure.label <- NA
@@ -591,37 +604,50 @@ autoplot.response_spct <-
591604
idfactor <- check_idfactor_arg(object, idfactor)
592605
object <- rename_idfactor(object, idfactor)
593606

594-
if (photobiology::getMultipleWl(object) > 1L
595-
&& plot.data != "as.is") {
596-
return(
597-
autoplot(object = photobiology::subset2mspct(object),
598-
w.band = w.band,
599-
range = range,
600-
pc.out = pc.out,
601-
label.qty = label.qty,
602-
span = span,
603-
wls.target = wls.target,
604-
annotations = annotations,
605-
by.group = by.group,
606-
geom = geom,
607-
time.format = time.format,
608-
tz = tz,
609-
text.size = text.size,
610-
# chroma.type = chroma.type,
611-
idfactor = ifelse(is.null(idfactor), TRUE, idfactor),
612-
facets = facets,
613-
plot.data = plot.data,
614-
ylim = ylim,
615-
object.label = object.label,
616-
na.rm = na.rm)
617-
)
607+
if (photobiology::getMultipleWl(object) > 1L) {
608+
if (plot.data == "as.is") {
609+
if (facets) {
610+
# with a single spectrum per panel we include summaries
611+
annotations.default <-
612+
c("boxes", "labels", "summaries", "colour.guide", "peaks")
613+
} else {
614+
# We skip "summaries", which also affects trimming of wavebands
615+
annotations.default <- c("boxes", "labels", "colour.guide", "peaks")
616+
}
617+
} else {
618+
# compute parallel summaries across spectra
619+
return(
620+
autoplot(object = photobiology::subset2mspct(object),
621+
w.band = w.band,
622+
range = range,
623+
pc.out = pc.out,
624+
label.qty = label.qty,
625+
span = span,
626+
wls.target = wls.target,
627+
annotations = annotations,
628+
by.group = by.group,
629+
geom = geom,
630+
time.format = time.format,
631+
tz = tz,
632+
text.size = text.size,
633+
# chroma.type = chroma.type,
634+
idfactor = ifelse(is.null(idfactor), TRUE, idfactor),
635+
facets = facets,
636+
plot.data = plot.data,
637+
ylim = ylim,
638+
object.label = object.label,
639+
na.rm = na.rm)
640+
)
641+
}
642+
} else {
643+
# with a single spectrum we include summaries
644+
annotations.default <-
645+
c("boxes", "labels", "summaries", "colour.guide", "peaks")
618646
}
619647

620648
annotations.default <-
621-
getOption("photobiology.plot.annotations",
622-
default = c("boxes", "labels", "summaries", "colour.guide", "peaks"))
623-
annotations <- decode_annotations(annotations,
624-
annotations.default)
649+
getOption("photobiology.plot.annotations", default = annotations.default)
650+
annotations <- decode_annotations(annotations, annotations.default)
625651

626652
# Change units if needed, and update normalization
627653
object <- switch(unit.out,

R/autoplot-source-spct.r

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ e_plot <- function(spct,
8080
spct <- photobiology::trim_wl(spct, range = range)
8181
}
8282
if (!is.null(w.band)) {
83-
w.band <- photobiology::trim_wl(w.band, range = range(spct))
83+
if ("summaries" %in% annotations) {
84+
# boxes or segments display summarised wavelengths
85+
w.band <- photobiology::trim_wl(w.band,
86+
range = photobiology::wl_range(spct))
87+
} else {
88+
# boxes and segments display wavebands' definitions if they fit in plot
89+
w.band <- photobiology::trim_wl(w.band, range = range)
90+
}
8491
}
8592
duration.label <- NA
8693
if (photobiology::is_scaled(spct)) {
@@ -387,7 +394,14 @@ q_plot <- function(spct,
387394
spct <- photobiology::trim_wl(spct, range = range)
388395
}
389396
if (!is.null(w.band)) {
390-
w.band <- photobiology::trim_wl(w.band, range = range(spct))
397+
if ("summaries" %in% annotations) {
398+
# boxes or segments display summarised wavelengths
399+
w.band <- photobiology::trim_wl(w.band,
400+
range = photobiology::wl_range(spct))
401+
} else {
402+
# boxes and segments display wavebands' definitions if they fit in plot
403+
w.band <- photobiology::trim_wl(w.band, range = range)
404+
}
391405
}
392406

393407
duration.label <- NA
@@ -789,37 +803,52 @@ autoplot.source_spct <-
789803
idfactor <- check_idfactor_arg(object, idfactor)
790804
object <- rename_idfactor(object, idfactor)
791805

792-
if (photobiology::getMultipleWl(object) > 1L && plot.data != "as.is") {
793-
return(
794-
ggplot2::autoplot(object = photobiology::subset2mspct(object),
795-
w.band = w.band,
796-
range = range,
797-
unit.out = unit.out,
798-
pc.out = pc.out,
799-
label.qty = label.qty,
800-
span = span,
801-
wls.target = wls.target,
802-
annotations = annotations,
803-
by.group = by.group,
804-
geom = geom,
805-
time.format = time.format,
806-
tz = tz,
807-
text.size = text.size,
808-
chroma.type = chroma.type,
809-
idfactor = idfactor,
810-
facets = facets,
811-
plot.data = plot.data,
812-
ylim = ylim,
813-
object.label = object.label,
814-
na.rm = na.rm)
815-
)
806+
if (photobiology::getMultipleWl(object) > 1L) {
807+
if (plot.data == "as.is") {
808+
if (facets) {
809+
# with a single spectrum per panel we include summaries
810+
annotations.default <-
811+
c("boxes", "labels", "summaries", "colour.guide", "peaks")
812+
} else {
813+
# We skip "summaries", which also affects trimming of wavebands
814+
annotations.default <- c("boxes", "labels", "colour.guide", "peaks")
815+
}
816+
} else {
817+
# compute parallel summaries across spectra
818+
return(
819+
autoplot(object = photobiology::subset2mspct(object),
820+
w.band = w.band,
821+
range = range,
822+
unit.out = unit.out,
823+
pc.out = pc.out,
824+
label.qty = label.qty,
825+
span = span,
826+
wls.target = wls.target,
827+
annotations = annotations,
828+
by.group = by.group,
829+
geom = geom,
830+
time.format = time.format,
831+
tz = tz,
832+
text.size = text.size,
833+
chroma.type = chroma.type,
834+
idfactor = idfactor,
835+
facets = facets,
836+
plot.data = plot.data,
837+
ylim = ylim,
838+
object.label = object.label,
839+
na.rm = na.rm)
840+
)
841+
}
842+
} else {
843+
# with a single spectrum we include summaries
844+
annotations.default <-
845+
c("boxes", "labels", "summaries", "colour.guide", "peaks")
816846
}
817847

818848
annotations.default <-
819-
getOption("photobiology.plot.annotations",
820-
default = c("boxes", "labels", "summaries", "colour.guide", "peaks"))
821-
annotations <- decode_annotations(annotations,
822-
annotations.default)
849+
getOption("photobiology.plot.annotations", default = annotations.default)
850+
annotations <- decode_annotations(annotations, annotations.default)
851+
823852
# Change units if needed, and update normalization
824853
object <- switch(unit.out,
825854
photon = photobiology::e2q(object, action = "replace"),

tests/testthat/_snaps/autoplot-response-spct/response-mspct-default-range-shrink.svg

Lines changed: 2 additions & 2 deletions
Loading

tests/testthat/_snaps/autoplot-source-spct/source-mspct-default-range-shrink-long.svg

Lines changed: 2 additions & 2 deletions
Loading

tests/testthat/_snaps/autoplot-source-spct/source-mspct-default-range-shrink.svg

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)