Skip to content

Commit

Permalink
Allow to center and scale label positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 19, 2024
1 parent e4373a3 commit bb924cb
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 22 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# isopleuros 1.2.0.9000
## Enhancements
* Allow to center and scale label positions.

# isopleuros 1.2.0
## Enhancements
Expand Down
18 changes: 16 additions & 2 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ setGeneric(
#' @param x,y,z A [`numeric`] vector giving the x, y and z ternary coordinates
#' of a set of points. If `y` and `z` are missing, an attempt is made to
#' interpret `x` in a suitable way (see [grDevices::xyz.coords()]).
#' @param center A [`logical`] scalar: should the data be centered?
#' @param scale A [`logical`] scalar: should the data be scaled?
#' @param center A [`logical`] scalar specifying wether the data should be
#' centered, or a [`numeric`] vector giving the center.
#' @param scale A [`logical`] scalar specifying wether the data should be
#' scaled, or a [`numeric`] vector giving the scale factor.
#' @param type A [`character`] string indicating the type of plotting; actually
#' any of the types as in [graphics::plot.default()].
#' @param ... Further graphical parameters (see [graphics::par()]) may also be
Expand Down Expand Up @@ -398,6 +400,10 @@ setGeneric(
#' @param x,y,z A [`numeric`] vector giving the x, y and z ternary coordinates
#' of a set of points. If `y` and `z` are missing, an attempt is made to
#' interpret `x` in a suitable way (see [grDevices::xyz.coords()]).
#' @param center A [`logical`] scalar specifying wether the data should be
#' centered, or a [`numeric`] vector giving the center.
#' @param scale A [`logical`] scalar specifying wether the data should be
#' scaled, or a [`numeric`] vector giving the scale factor.
#' @param labels A [`character`] vector or [`expression`] specifying the text
#' to be written.
#' @param ... Further arguments to be passed to [graphics::text()].
Expand All @@ -420,6 +426,10 @@ setGeneric(
#' @param x,y,z A [`numeric`] vector giving the x, y and z ternary coordinates
#' of a set of points. If `y` and `z` are missing, an attempt is made to
#' interpret `x` in a suitable way (see [grDevices::xyz.coords()]).
#' @param center A [`logical`] scalar specifying wether the data should be
#' centered, or a [`numeric`] vector giving the center.
#' @param scale A [`logical`] scalar specifying wether the data should be
#' scaled, or a [`numeric`] vector giving the scale factor.
#' @param labels A [`character`] vector or [`expression`] specifying the text
#' to be written.
#' @param type A [`character`] string specifying the shape of the field.
Expand Down Expand Up @@ -488,6 +498,10 @@ setGeneric(
#' @param x,y,z A [`numeric`] vector giving the x, y and z ternary coordinates
#' of a set of points. If `y` and `z` are missing, an attempt is made to
#' interpret `x` in a suitable way (see [grDevices::xyz.coords()]).
#' @param center A [`logical`] scalar specifying wether the data should be
#' centered, or a [`numeric`] vector giving the center.
#' @param scale A [`logical`] scalar specifying wether the data should be
#' scaled, or a [`numeric`] vector giving the scale factor.
#' @param ... Further arguments to be passed to [graphics::polygon()].
#' @return
#' `ternary_hull()` is called it for its side-effects.
Expand Down
9 changes: 5 additions & 4 deletions R/ternary_hull.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ NULL
setMethod(
f = "ternary_hull",
signature = c(x = "numeric", y = "numeric", z = "numeric"),
definition = function(x, y, z, ...) {
coords <- coordinates_ternary(x, y, z)
definition = function(x, y, z, center = FALSE, scale = FALSE, ...) {
coords <- coordinates_ternary(x, y, z, center = center, scale = scale)
hull <- grDevices::chull(coords)
graphics::polygon(x = coords$x[hull], y = coords$y[hull], ...)

Expand All @@ -24,9 +24,10 @@ setMethod(
setMethod(
f = "ternary_hull",
signature = c(x = "ANY", y = "missing", z = "missing"),
definition = function(x, ...) {
definition = function(x, center = FALSE, scale = FALSE, ...) {
xyz <- grDevices::xyz.coords(x)
coords <- methods::callGeneric(x = xyz$x, y = xyz$y, z = xyz$z, ...)
coords <- methods::callGeneric(x = xyz$x, y = xyz$y, z = xyz$z,
center = center, scale = scale, ...)
invisible(coords)
}
)
9 changes: 5 additions & 4 deletions R/ternary_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ NULL
setMethod(
f = "ternary_labels",
signature = c(x = "numeric", y = "numeric", z = "numeric"),
definition = function(x, y, z, labels = seq_along(x),
type = c("text", "shadow"), ...) {
definition = function(x, y, z, center = FALSE, scale = FALSE,
labels = seq_along(x), type = c("text", "shadow"), ...) {
## Validation
type <- match.arg(type, several.ok = FALSE)

## Compute label positions
coords <- coordinates_ternary(x, y, z)
coords <- coordinates_ternary(x, y, z, center = center, scale = scale)
labs <- compute_labels(x = coords$x, y = coords$y, labels = labels, ...)

## Draw labels
Expand All @@ -36,9 +36,10 @@ setMethod(
setMethod(
f = "ternary_labels",
signature = c(x = "ANY", y = "missing", z = "missing"),
definition = function(x, labels = seq_along(x$x), ...) {
definition = function(x, center = FALSE, scale = FALSE, labels = seq_along(x$x), ...) {
x <- grDevices::xyz.coords(x)
coords <- methods::callGeneric(x = x$x, y = x$y, z = x$z,
center = center, scale = scale,
labels = labels, ...)
invisible(coords)
}
Expand Down
11 changes: 7 additions & 4 deletions R/ternary_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ NULL
setMethod(
f = "ternary_text",
signature = c(x = "numeric", y = "numeric", z = "numeric"),
definition = function(x, y, z, labels = seq_along(x), ...) {
coords <- coordinates_ternary(x, y, z)
definition = function(x, y, z, center = FALSE, scale = FALSE,
labels = seq_along(x), ...) {
coords <- coordinates_ternary(x, y, z, center = center, scale = scale)
graphics::text(x = coords, labels = labels, ...)

invisible(list(x = x, y = y, z = z))
Expand All @@ -22,10 +23,12 @@ setMethod(
setMethod(
f = "ternary_text",
signature = c(x = "ANY", y = "missing", z = "missing"),
definition = function(x, labels = seq_along(x$x), ...) {
definition = function(x, center = FALSE, scale = FALSE, labels = seq_along(x$x), ...) {
x <- grDevices::xyz.coords(x)
force(labels)
coords <- methods::callGeneric(x = x$x, y = x$y, z = x$z, labels = labels, ...)
coords <- methods::callGeneric(x = x$x, y = x$y, z = x$z,
center = center, scale = scale,
labels = labels, ...)
invisible(coords)
}
)
10 changes: 8 additions & 2 deletions man/ternary_hull.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions man/ternary_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/ternary_points.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions man/ternary_text.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb924cb

Please sign in to comment.