From d0bb4bbcc629e65c9895b1181cf26d8ffe76aca2 Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 11 Jan 2024 08:28:24 +0000 Subject: [PATCH] Improve support for `region` parameter --- DESCRIPTION | 2 +- NEWS.md | 3 + R/SetRegion.R | 8 +- R/TernaryPlot.R | 4 +- R/dot-TrianglePlot.R | 5 +- tests/testthat/_snaps/Contours/contours.svg | 768 +++++++++--------- .../_snaps/Contours/filledcontours.svg | 768 +++++++++--------- tests/testthat/test-SetRegion.R | 9 +- 8 files changed, 789 insertions(+), 778 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c769166d..f502645e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Ternary -Version: 2.3.0 +Version: 2.3.0.9000 Title: Create Ternary and Holdridge Plots Description: Plots ternary diagrams (simplex plots / Gibbs triangles) and Holdridge life zone plots using the diff --git a/NEWS.md b/NEWS.md index 280df5f3..42c6e830 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# Ternary v2.3.0.9000 (development) +- Improve support for `region` parameter. + # Ternary v2.3.0 (2024-01-08) - `region` parameter plots a sub-region of the ternary space. - Support `...` in `TernaryContour(Func = function(...))` diff --git a/R/SetRegion.R b/R/SetRegion.R index b5cdabae..7d0697d7 100644 --- a/R/SetRegion.R +++ b/R/SetRegion.R @@ -205,8 +205,12 @@ ternRegionA <- structure( i <- c(i, seq(max(i) + by, by = by, length.out = longest - n)) i }) - prettyRegion <- rbind(min = vapply(prettyRegion, `[`, 0, 1), - max = vapply(prettyRegion, `[`, 0, longest)) + prettyRegion <- structure( + rbind(min = vapply(prettyRegion, `[`, 0, 1), + max = vapply(prettyRegion, `[`, 0, longest)), + tickLabels = prettyRegion, + class = "ternRegion" + ) if (.RegionIsValid(prettyRegion)) { region <- prettyRegion } diff --git a/R/TernaryPlot.R b/R/TernaryPlot.R index 5c3ebed8..3072cca4 100644 --- a/R/TernaryPlot.R +++ b/R/TernaryPlot.R @@ -234,7 +234,7 @@ TernaryPlot <- function(atip = NULL, btip = NULL, ctip = NULL, .PlotBackground(tern) - panel.first + panel.first # Execute user-supplied expression .PlotMinorGridLines( tern$grid.lines, @@ -251,7 +251,7 @@ TernaryPlot <- function(atip = NULL, btip = NULL, ctip = NULL, lwd = tern$grid.lwd ) - panel.last + panel.last # Execute user-supplied expression .PlotAxisTicks(tern) diff --git a/R/dot-TrianglePlot.R b/R/dot-TrianglePlot.R index 2797f234..27a4a88d 100644 --- a/R/dot-TrianglePlot.R +++ b/R/dot-TrianglePlot.R @@ -160,8 +160,9 @@ } region <- getOption("ternRegion") - if (isTRUE(axis.labels) && !all(region == ternRegionDefault)) { - axis.labels <- .SimpleApply(region, 2, pretty, n = grid.lines) + region.labels <- attr(region, "tickLabels") + if (isTRUE(axis.labels) && !is.null(region.labels)) { + axis.labels <- region.labels grid.lines <- length(axis.labels[[1]]) - 1L } else { grid.lines <- .ValidateGridLines(grid.lines) diff --git a/tests/testthat/_snaps/Contours/contours.svg b/tests/testthat/_snaps/Contours/contours.svg index 980932e4..619c9047 100644 --- a/tests/testthat/_snaps/Contours/contours.svg +++ b/tests/testthat/_snaps/Contours/contours.svg @@ -1460,174 +1460,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + 20 20 20 -25 -25 -25 -30 -30 -30 -35 -35 -35 +24 +24 +24 +28 +28 +28 +32 +32 +32 +36 +36 +36 40 40 40 -45 -45 -45 -50 -50 -50 -55 -55 -55 +44 +44 +44 +48 +48 +48 +52 +52 +52 +56 +56 +56 60 60 60 @@ -2262,258 +2304,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + 40 0 0 -45 -5 -5 -50 -10 -10 -55 -15 -15 -60 -20 -20 -65 -25 -25 +46 +6 +6 +52 +12 +12 +58 +18 +18 +64 +24 +24 70 30 30 -75 -35 -35 -80 -40 -40 -85 -45 -45 -90 -50 -50 -95 -55 -55 +76 +36 +36 +82 +42 +42 +88 +48 +48 +94 +54 +54 100 60 60 diff --git a/tests/testthat/_snaps/Contours/filledcontours.svg b/tests/testthat/_snaps/Contours/filledcontours.svg index 53e7ce09..62169d22 100644 --- a/tests/testthat/_snaps/Contours/filledcontours.svg +++ b/tests/testthat/_snaps/Contours/filledcontours.svg @@ -13402,174 +13402,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + 20 20 20 -25 -25 -25 -30 -30 -30 -35 -35 -35 +24 +24 +24 +28 +28 +28 +32 +32 +32 +36 +36 +36 40 40 40 -45 -45 -45 -50 -50 -50 -55 -55 -55 +44 +44 +44 +48 +48 +48 +52 +52 +52 +56 +56 +56 60 60 60 @@ -18807,258 +18849,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + 40 0 0 -45 -5 -5 -50 -10 -10 -55 -15 -15 -60 -20 -20 -65 -25 -25 +46 +6 +6 +52 +12 +12 +58 +18 +18 +64 +24 +24 70 30 30 -75 -35 -35 -80 -40 -40 -85 -45 -45 -90 -50 -50 -95 -55 -55 +76 +36 +36 +82 +42 +42 +88 +48 +48 +94 +54 +54 100 60 60 diff --git a/tests/testthat/test-SetRegion.R b/tests/testthat/test-SetRegion.R index 4e82a707..afdfa704 100644 --- a/tests/testthat/test-SetRegion.R +++ b/tests/testthat/test-SetRegion.R @@ -98,7 +98,11 @@ test_that(".SetRegion() prettifies", { expect_equal(getOption("ternRegion"), structure(region, class = "ternRegion")) .SetRegion(regionList, prettify = 10) - expect_equal(getOption("ternRegion"), structure(pretty, class = "ternRegion")) + expect_equal(getOption("ternRegion"), structure( + pretty, + tickLabels = list(a = 10:20, b = 10:20, c = 70:80), + class = "ternRegion") + ) }) test_that(".SetRegion() handles bad input", { @@ -116,8 +120,6 @@ test_that(".SetRegion() handles bad input", { ) expect_equal(getOption("ternRegion"), ternRegionDefault) - .SetRegion(ternRegion20) - .SetRegion(ternRegion20) expect_warning( expect_equal( @@ -128,6 +130,7 @@ test_that(".SetRegion() handles bad input", { ) expect_equal(getOption("ternRegion"), ternRegion20) + .SetRegion(ternRegion20) expect_warning( expect_equal( .SetRegion(list(min = rep(0, 3), max = rep(0, 3)), set = 0),