From 901df63795d8369974d027a0c09e623883ea4323 Mon Sep 17 00:00:00 2001 From: bwlewis Date: Tue, 13 Mar 2018 10:51:08 -0400 Subject: [PATCH] issue #76 line colors are now additive --- R/scatterplot.R | 17 ++++++++++------- man/points3d.Rd | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/R/scatterplot.R b/R/scatterplot.R index e33ee11..243c99d 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -487,8 +487,7 @@ setMethod("vertices", signature(...="scatterplotThree"), #' @param z (Optional) vector of z-coordinate values, not required if #' \code{x} is a matrix. #' @param color Either a single hex or named color name (all points same color), -#' or a vector of hex or named color names as long as the number of data -#' points to plot. +#' or a vector of hex or named color names as long as the number of points in \code{x}. #' @param pch Optional point glyphs or text strings, see \code{\link{scatterplot3js}}. #' @param size The plot point radius, either as a single number or a #' vector of sizes of length \code{nrow(x)}. @@ -618,26 +617,30 @@ lines3d <- function(s, from, to, lwd=1, alpha=1, color) { stopifnot("scatterplotThree" %in% class(s)) options <- s$x + lf <- length(from) + if(lf != length(to)) stop("`from` and `to` must be the same length") N <- length(options$vertices) # number of animation frames, update last one from <- Map(indexline, list(from)) to <- Map(indexline, list(to)) + lcol <- NULL if (! missing(color)) # discard alpha, normalize line colors { lcol <- list(color) lc <- Map(function(x) col2rgb(x, alpha=FALSE), lcol) - lcol <- Map(function(x) apply(x, 2, function(x) rgb(x[1], x[2], x[3], maxColorValue=255)), lc) + lcol <- unlist(Map(function(x) apply(x, 2, function(x) rgb(x[1], x[2], x[3], maxColorValue=255)), lc)) + lcol <- rep_len(lcol, lf) } if (is.null(options$from)) { - options$from <- from - options$to <- to - if (!missing(color)) options$lcol <- lcol + options$from <- list(unlist(from)) + options$to <- list(unlist(to)) + if (! missing(color)) options$lcol <- list(unlist(lcol)) } else { if(is.list(options$from[[N]])) options$from[[N]] <- c(unlist(options$from[[N]]), unlist(from)) else options$from[[N]] <- c(options$from[[N]], unlist(from)) if(is.list(options$to[[N]])) options$to[[N]] <- c(unlist(options$to[[N]]), unlist(to)) else options$to[[N]] <- c(options$to[[N]], unlist(to)) - if (!missing(color)) options$lcol[[N]] <- unlist(lcol) + if (! missing(color)) options$lcol[[N]] <- c(unlist(options$lcol[[N]]), unlist(lcol)) } options$lwd <- lwd options$linealpha <- alpha diff --git a/man/points3d.Rd b/man/points3d.Rd index 941945b..361ef1e 100644 --- a/man/points3d.Rd +++ b/man/points3d.Rd @@ -20,8 +20,7 @@ coordinate axes. Column labels, if present, are used as axis labels.} \code{x} is a matrix.} \item{color}{Either a single hex or named color name (all points same color), -or a vector of hex or named color names as long as the number of data -points to plot.} +or a vector of hex or named color names as long as the number of points in \code{x}.} \item{pch}{Optional point glyphs or text strings, see \code{\link{scatterplot3js}}.}