From 3ddad21b72b3d7bddba8261ee2bfa7c424d62f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr> Date: Thu, 20 Apr 2023 17:43:14 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20so.ii=201.0.26.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/tag-message | 10 ++-- so.ii/DESCRIPTION | 2 +- so.ii/R/adjust_terra_scale.R | 52 ++++++++++++++++++- .../{current_version.r => current_version.R} | 0 so.ii/R/{data.r => data.R} | 0 so.ii/R/{kable_units.r => kable_units.R} | 0 so.ii/R/{map_so_ii.r => map_so_ii.R} | 2 +- so.ii/R/{plot_legend.r => plot_legend.R} | 0 so.ii/man/clc_color.Rd | 2 +- so.ii/man/current_version.Rd | 2 +- so.ii/man/so_ii_catchment.Rd | 2 +- so.ii/man/so_ii_catnat.Rd | 2 +- so.ii/man/so_ii_clc.Rd | 2 +- so.ii/man/so_ii_clc_crop.Rd | 2 +- so.ii/man/so_ii_collectivity.Rd | 2 +- so.ii/man/so_ii_hydro.Rd | 2 +- so.ii/man/so_ii_inset.Rd | 2 +- so.ii/man/so_ii_limit.Rd | 2 +- so.ii/man/so_ii_montpellier.Rd | 2 +- so.ii/man/so_ii_onrn.Rd | 2 +- so.ii/man/so_ii_population.Rd | 2 +- so.ii/man/so_ii_scope.Rd | 2 +- 22 files changed, 72 insertions(+), 22 deletions(-) rename so.ii/R/{current_version.r => current_version.R} (100%) rename so.ii/R/{data.r => data.R} (100%) rename so.ii/R/{kable_units.r => kable_units.R} (100%) rename so.ii/R/{map_so_ii.r => map_so_ii.R} (99%) rename so.ii/R/{plot_legend.r => plot_legend.R} (100%) diff --git a/dev/tag-message b/dev/tag-message index 2e0bd93..01c6fcd 100644 --- a/dev/tag-message +++ b/dev/tag-message @@ -1,17 +1,17 @@ -so.ii Version: 1.0.25.0 +so.ii Version: 1.0.26.0 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ **Note de version** * modification de map_so_ii - * nouvelle fonction interne adjust_terra_scale + * nouvelle fonction interne calculate_terra_xy **Détails** * La librairie terra a changé sa façon de faire la barre d'échelle avec sbar à partir de la version 1.7, de façon incompatible avec l'usage interne. - Une nouvelle fonction non exportée adjust_terra_scale est créé pour ne plus - dépendre des fonctionnalités de terra::sbar qui posent problème, lorsque - les cartes sont en "lonlat". + Une nouvelle fonction non exportée calculate_terra_xy est créée pour ne plus + dépendre des fonctionnalités de terra::sbar qui posent problème, et ne + permettaient plus de faire un positionnement par mots clés. # git tag -a v1.0.25.0 -F dev/tag-message # git push --tags diff --git a/so.ii/DESCRIPTION b/so.ii/DESCRIPTION index cf26285..db2020b 100644 --- a/so.ii/DESCRIPTION +++ b/so.ii/DESCRIPTION @@ -1,6 +1,6 @@ Package: so.ii Title: Utilities very useful to share within so_ii team -Version: 1.0.25.0 +Version: 1.0.26.0 Authors@R: c( person(given = "Frédéric", diff --git a/so.ii/R/adjust_terra_scale.R b/so.ii/R/adjust_terra_scale.R index a749b0e..7bcbe79 100644 --- a/so.ii/R/adjust_terra_scale.R +++ b/so.ii/R/adjust_terra_scale.R @@ -12,7 +12,7 @@ adjust_terra_scale = function(d = NULL, lonlat = TRUE) { cbind(lon2, lat2)/toRad } - graph_box = graphics::par()$usr + graph_box = graphics::par()[["usr"]] if (lonlat) { lat = mean(graph_box[3:4]) if (is.null(d)) { @@ -34,3 +34,53 @@ adjust_terra_scale = function(d = NULL, lonlat = TRUE) { } return(c(dd, d)) } + +calculate_terra_xy = function (xy, dx = 0, dy = 0, defpos = "bottomleft") +{ + graph_box = graphics::par()[["usr"]] + if (is.null(xy)) { + xy = defpos + } + if (!is.character(xy)) { + return(cbind(xy[1], xy[2])) + } + xy = tolower(xy) + parrange = c(graph_box[2] - graph_box[1], graph_box[4] - graph_box[3]) + pad = c(5, 5)/100 + if (xy == "bottom") { + xy = c(graph_box[1] + 0.5 * parrange[1] - 0.5 * dx, graph_box[3] + + (pad[2] * parrange[2])) + c(0, dy) + } + else if (xy == "bottomleft") { + xy = c(graph_box[1] + (pad[1] * parrange[1]), graph_box[3] + + (pad[2] * parrange[2])) + c(0, dy) + } + else if (xy == "bottomright") { + xy = c(graph_box[2] - (pad[1] * parrange[1]), graph_box[3] + + (pad[2] * parrange[2])) - c(dx, -dy) + } + else if (xy == "topright") { + xy = c(graph_box[2] - (pad[1] * parrange[1]), graph_box[4] - + (pad[2] * parrange[2])) - c(dx, dy) + } + else if (xy == "top") { + xy = c(graph_box[1] + 0.5 * parrange[1] - 0.5 * dx, graph_box[4] - + (pad[2] * parrange[2])) - c(0, dy) + } + else if (xy == "topleft") { + xy = c(graph_box[1] + (pad[1] * parrange[1]), graph_box[4] - + (pad[2] * parrange[2])) - c(0, dy) + } + else if (xy == "left") { + xy = c(graph_box[1] + (pad[1] * parrange[1]), graph_box[3] + + 0.5 * parrange[2] - 0.5 * dy) + } + else if (xy == "right") { + xy = c(graph_box[2] - (pad[1] * parrange[1]) - dx, graph_box[3] + + 0.5 * parrange[2] - 0.5 * dy) + } + else { + stop("xy must be a coordinate pair (two numbers) or one of \"bottomleft\", \"bottom\", \"bottomright\", topleft\", \"top\", \"topright\"") + } + xy +} \ No newline at end of file diff --git a/so.ii/R/current_version.r b/so.ii/R/current_version.R similarity index 100% rename from so.ii/R/current_version.r rename to so.ii/R/current_version.R diff --git a/so.ii/R/data.r b/so.ii/R/data.R similarity index 100% rename from so.ii/R/data.r rename to so.ii/R/data.R diff --git a/so.ii/R/kable_units.r b/so.ii/R/kable_units.R similarity index 100% rename from so.ii/R/kable_units.r rename to so.ii/R/kable_units.R diff --git a/so.ii/R/map_so_ii.r b/so.ii/R/map_so_ii.R similarity index 99% rename from so.ii/R/map_so_ii.r rename to so.ii/R/map_so_ii.R index f0d1c11..54ff95b 100644 --- a/so.ii/R/map_so_ii.r +++ b/so.ii/R/map_so_ii.R @@ -297,7 +297,7 @@ map_so_ii = function( # area = sf::st_area(sf::st_as_sfc(sf::st_bbox(scope))) # d = max(pretty(units::set_units(sqrt(area) / 5, "km"))) d = adjust_terra_scale() - xy = "bottomleft" + xy = calculate_terra_xy("bottomleft") # Magical adjustment when scope vary to have text readable # 0.4788987 should correspond to longitude range for so.ii scope adj = diff(graphics::par()$usr[3:4]) diff --git a/so.ii/R/plot_legend.r b/so.ii/R/plot_legend.R similarity index 100% rename from so.ii/R/plot_legend.r rename to so.ii/R/plot_legend.R diff --git a/so.ii/man/clc_color.Rd b/so.ii/man/clc_color.Rd index 35203a5..8e050f7 100644 --- a/so.ii/man/clc_color.Rd +++ b/so.ii/man/clc_color.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{clc_color} \alias{clc_color} diff --git a/so.ii/man/current_version.Rd b/so.ii/man/current_version.Rd index 14579d8..36d3727 100644 --- a/so.ii/man/current_version.Rd +++ b/so.ii/man/current_version.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/current_version.r +% Please edit documentation in R/current_version.R \encoding{UTF-8} \name{current_version} \alias{current_version} diff --git a/so.ii/man/so_ii_catchment.Rd b/so.ii/man/so_ii_catchment.Rd index 0cfe4eb..91ae6bc 100644 --- a/so.ii/man/so_ii_catchment.Rd +++ b/so.ii/man/so_ii_catchment.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_catchment} \alias{so_ii_catchment} diff --git a/so.ii/man/so_ii_catnat.Rd b/so.ii/man/so_ii_catnat.Rd index 50b2aab..f5fc0ba 100644 --- a/so.ii/man/so_ii_catnat.Rd +++ b/so.ii/man/so_ii_catnat.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_catnat} \alias{so_ii_catnat} diff --git a/so.ii/man/so_ii_clc.Rd b/so.ii/man/so_ii_clc.Rd index 2f08e4b..49981ae 100644 --- a/so.ii/man/so_ii_clc.Rd +++ b/so.ii/man/so_ii_clc.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_clc} \alias{so_ii_clc} diff --git a/so.ii/man/so_ii_clc_crop.Rd b/so.ii/man/so_ii_clc_crop.Rd index 2db0c12..4763a94 100644 --- a/so.ii/man/so_ii_clc_crop.Rd +++ b/so.ii/man/so_ii_clc_crop.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_clc_crop} \alias{so_ii_clc_crop} diff --git a/so.ii/man/so_ii_collectivity.Rd b/so.ii/man/so_ii_collectivity.Rd index 28fb458..f8fa348 100644 --- a/so.ii/man/so_ii_collectivity.Rd +++ b/so.ii/man/so_ii_collectivity.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_collectivity} \alias{so_ii_collectivity} diff --git a/so.ii/man/so_ii_hydro.Rd b/so.ii/man/so_ii_hydro.Rd index 8af21fd..c65afba 100644 --- a/so.ii/man/so_ii_hydro.Rd +++ b/so.ii/man/so_ii_hydro.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_hydro} \alias{so_ii_hydro} diff --git a/so.ii/man/so_ii_inset.Rd b/so.ii/man/so_ii_inset.Rd index 0269d1a..cf1555f 100644 --- a/so.ii/man/so_ii_inset.Rd +++ b/so.ii/man/so_ii_inset.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_inset} \alias{so_ii_inset} diff --git a/so.ii/man/so_ii_limit.Rd b/so.ii/man/so_ii_limit.Rd index 64c439b..8655e30 100644 --- a/so.ii/man/so_ii_limit.Rd +++ b/so.ii/man/so_ii_limit.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_limit} \alias{so_ii_limit} diff --git a/so.ii/man/so_ii_montpellier.Rd b/so.ii/man/so_ii_montpellier.Rd index 1d7aa74..872b883 100644 --- a/so.ii/man/so_ii_montpellier.Rd +++ b/so.ii/man/so_ii_montpellier.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_montpellier} \alias{so_ii_montpellier} diff --git a/so.ii/man/so_ii_onrn.Rd b/so.ii/man/so_ii_onrn.Rd index 0991fd9..f2d450b 100644 --- a/so.ii/man/so_ii_onrn.Rd +++ b/so.ii/man/so_ii_onrn.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_onrn} \alias{so_ii_onrn} diff --git a/so.ii/man/so_ii_population.Rd b/so.ii/man/so_ii_population.Rd index 7719fce..2198caa 100644 --- a/so.ii/man/so_ii_population.Rd +++ b/so.ii/man/so_ii_population.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_population} \alias{so_ii_population} diff --git a/so.ii/man/so_ii_scope.Rd b/so.ii/man/so_ii_scope.Rd index 270cf44..5b275d3 100644 --- a/so.ii/man/so_ii_scope.Rd +++ b/so.ii/man/so_ii_scope.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r +% Please edit documentation in R/data.R \docType{data} \name{so_ii_scope} \alias{so_ii_scope} -- GitLab