dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
85 stars 20 forks source link

hover3d bug #362

Closed dmurdoch closed 1 year ago

dmurdoch commented 1 year ago

This code (based on code from Martin Maechler) isn't working:

crgb <- col2rgb(cc <- colors())
   colnames(crgb) <- cc
   t(crgb)  # The whole table
   ccodes <- c(256^(2:0) %*% crgb)  # = internal codes
   ## How many names are 'aliases' of each other:
   table(tcc <- table(ccodes))
   length(uc <- unique(sort(ccodes))) # 502
   ## All the multiply named colors:
   mult <- uc[tcc >= 2]
   cl <- lapply(mult, function(m) cc[ccodes == m])
   names(cl) <- apply(col2rgb(sapply(cl, function(x)x[1])),
                      2, function(n)paste(n, collapse = ","))
   utils::str(cl)

tc <- t(crgb[, !duplicated(ccodes)])
cNms <- rownames(tc)
## The 8 corners of the color cube:
isC <- rowSums(tc == 0 | tc == 255) == 3
cNms[isC] # "white" "black" "blue" "cyan" "green" "magenta" "red" "yellow"
table(is.gray <- tc[,1] == tc[,2] & tc[,2] == tc[,3])# (397, 105)

if(require("rgl")) { ## Look at the color cube dynamically :
   # default type "p":  no rendering => better colors
   plot3d (tc, col = cNms, size = 11)
   hover3d(tc, labels=cNms, adj = -1/4)
 }

In R, no label appears. In rglwidget() display, sometimes it gives an error about the id being an object.