Skip to content

Commit

Permalink
fixes key.width issue
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Nov 29, 2023
1 parent 9d2a86e commit e52494b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
14 changes: 9 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
kw_dflt = function(x, key.pos) {
if (is.null(key.pos) || key.pos <= 0)
lcm(0)
if (is.null(key.pos) || key.pos == 0) # no key:
return(lcm(0))

font_scale = par("ps") / 12
if (key.pos == -1)
lcm(1.8 * font_scale)
else if (key.pos %in% c(2, 4) && (is.character(x[[1]]) || is.factor(x[[1]]))) {
strings = if (is.factor(x[[1]]))
levels(x[[1]])
else
x[[1]]
lcm(cm(max(strwidth(strings, "inches"))) * 1.3 + par("ps")/12) # cm
lcm(cm(max(strwidth(strings, "inches"))) * 1.3 + font_scale) # cm
#lcm(cm(max(strwidth(strings, "inches"))) * 1.3) # cm
} else
# lcm(1.8 * par("ps")/12)
lcm(1.8)
lcm(1.8 * font_scale)
}


Expand Down
8 changes: 5 additions & 3 deletions tests/plot.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Expand Down Expand Up @@ -88,9 +88,11 @@ Type 'q()' to quit R.
+ plot(nc, axes = TRUE)
+ plot(nc, col="lightgrey")
+ plot(st_centroid(nc), add = TRUE, col = 1)
+ nc %>%
+ if ("geometry" %in% names(nc)) {
+ nc %>%
+ select(geometry) %>%
+ plot()
+ }
+
+ nc$f = cut(nc[[1]], 5)
+ plot(nc["f"], key.pos = 1)
Expand Down Expand Up @@ -150,4 +152,4 @@ There were 13 warnings (use warnings() to see them)
>
> proc.time()
user system elapsed
4.822 0.828 4.857
3.111 1.417 3.015
12 changes: 6 additions & 6 deletions tests/read.Rout.save
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand Down Expand Up @@ -327,10 +327,10 @@ First 3 features:
>
> if ("GML" %in% st_drivers()$name) {
+ gml = system.file("gml/fmi_test.gml", package = "sf")
+ print(dim(st_read(gml, quiet = TRUE)))
+ print(dim(st_read(gml, quiet = TRUE, use_stream = FALSE)))
+ gml = system.file("gml/20170930_OB_530964_UKSH.xml.gz", package = "sf")
+ print(dim(st_read(gml, layer = "Parcely", quiet = TRUE)))
+ print(dim(st_read(gml, layer = "Parcely", int64_as_string=TRUE, quiet = TRUE)))
+ print(dim(st_read(gml, layer = "Parcely", quiet = TRUE, use_stream = FALSE)))
+ print(dim(st_read(gml, layer = "Parcely", int64_as_string=TRUE, quiet = TRUE, use_stream = FALSE)))
+ }
[1] 22 11
[1] 644 25
Expand Down Expand Up @@ -376,4 +376,4 @@ Error : wkt parse error.
>
> proc.time()
user system elapsed
2.288 0.818 2.281
1.255 1.397 1.179

0 comments on commit e52494b

Please sign in to comment.