|
28 | 28 | #' (E: meridian, N: parallel) degree value, label, start and end coordinates and angle;
|
29 | 29 | #' see example. The \code{plot12} is a logical attribute that is \code{TRUE}
|
30 | 30 | #' for meridians crossing the bottom or parallels crossing the left side of the plot.
|
| 31 | +#' The four attributes \code{bottom}, \code{top}, \code{left}, \code{right} indicate |
| 32 | +#' whether graticules touch that side at its begin, end, with both sides, or not at all (none). |
31 | 33 | #' @examples
|
32 | 34 | #' library(sf)
|
33 | 35 | #' library(maps)
|
@@ -191,12 +193,31 @@ graticule_attributes = function(df) {
|
191 | 193 | function(x) { y = x[[length(x)]]; n = nrow(y); apply(y[(n-1):n,], 2, diff) } ))
|
192 | 194 | df$angle_end = apply(dxdy, 1, function(x) atan2(x[2], x[1])*180/pi)
|
193 | 195 | bb = st_bbox(df)
|
194 |
| - selE = df$type == "E" & df$y_start < min(df$y_start) + 0.001 * (bb[3] - bb[1]) |
195 |
| - selN = df$type == "N" & df$x_start < min(df$x_start) + 0.001 * (bb[4] - bb[2]) |
| 196 | + |
| 197 | + selE = df$type == "E" & df$y_start < min(df$y_start) + 0.001 * (bb[4] - bb[2]) |
| 198 | + selN = df$type == "N" & df$x_start < min(df$x_start) + 0.001 * (bb[3] - bb[1]) |
196 | 199 | df$plot12 = selE | selN
|
| 200 | + |
| 201 | + begin_end_both_none = function(begin, end) |
| 202 | + ifelse(begin & end, "both", ifelse(begin, "begin", ifelse(end, "end", "none"))) |
| 203 | + |
| 204 | + df$bottom = begin_end_both_none( |
| 205 | + df$y_start < min(df$y_start) + 0.001 * (bb[4] - bb[2]), |
| 206 | + df$y_end < min(df$y_start) + 0.001 * (bb[4] - bb[2])) |
| 207 | + df$top = begin_end_both_none( |
| 208 | + df$y_start > max(df$y_start) - 0.001 * (bb[4] - bb[2]), |
| 209 | + df$y_end > max(df$y_start) - 0.001 * (bb[4] - bb[2])) |
| 210 | + df$left = begin_end_both_none( |
| 211 | + df$x_start < min(df$x_start) + 0.001 * (bb[3] - bb[1]), |
| 212 | + df$x_end < min(df$x_start) + 0.001 * (bb[3] - bb[1])) |
| 213 | + df$right = begin_end_both_none( |
| 214 | + df$x_start > max(df$x_start) - 0.001 * (bb[3] - bb[1]), |
| 215 | + df$x_end > max(df$x_start) - 0.001 * (bb[3] - bb[1])) |
| 216 | + |
197 | 217 | df
|
198 | 218 | }
|
199 | 219 |
|
| 220 | + |
200 | 221 | trim_bb = function(bb = c(-180, -90, 180, 90), margin, wrap = c(-180, 180)) {
|
201 | 222 | stopifnot(margin > 0 && margin <= 1.0)
|
202 | 223 | fr = 1.0 - margin
|
|
0 commit comments