Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color ignored in scatterplot3js, lwd ignored in lines3d #76

Open
ugroempi opened this issue Jan 31, 2018 · 11 comments
Open

color ignored in scatterplot3js, lwd ignored in lines3d #76

ugroempi opened this issue Jan 31, 2018 · 11 comments
Assignees
Labels

Comments

@ugroempi
Copy link

The code below shows that the color specification is ignored by the display following scatterplot3js; after adding a point in different color, the original "orange" is also respected. Option lwd in lines3d apparently does not have any effect on the line width.

Best, Ulrike

m <- cbind(x=1:10,y=1:10,z=(1:10)/((1:10)^2))
(s <- scatterplot3js(m, color="orange"))
(s <- threejs::points3d(s, 1,1,1,color="blue"))
lines3d(s, 1, 10, lwd=5, color="blue")

@bwlewis
Copy link
Owner

bwlewis commented Jan 31, 2018

definitely some bugs here. Oddly however my bugs seem different! line width and line color are working for me (RStudio 1.0.143 and Firefox 57.04 and Chromium on Linux). But, the first plot is broken (black instead of orange discs), and if I repeat lines3d more than once all lines disappear.

investigating...

@ugroempi
Copy link
Author

I used Firefox 58.0 (using js stuff with RStudio often gives me problems, so I usually switch the viewer off).

The color in lines3d works for me, the line width doesn't. And I also get that a second lines3d is unsuccessful and removes a previous line.

@bwlewis bwlewis self-assigned this Jan 31, 2018
@bwlewis bwlewis added the bug label Jan 31, 2018
bwlewis added a commit that referenced this issue Feb 23, 2018
…back to render globe map in globejs

map previously didn't render until interaction
@bwlewis
Copy link
Owner

bwlewis commented Feb 23, 2018

I fixed some color setting bugs identified in this thread. Your code, repeated below, is now working for me in at least the following browsers: Chromium Version 64.0.3282.140, Firefox 58.0.2, and in RStudio 1.0.143.

library(threejs)
m <- cbind(x=1:10,y=1:10,z=(1:10)/((1:10)^2))
print(s <- scatterplot3js(m, color="orange"))         # 10 orange circles
print(s <- threejs::points3d(s, 1,1,1,color="blue"))  # plus one blue circle
print(lines3d(s, 1, 10, lwd=5, color="blue"))         # plus one blue line

NOTE! The repeated use of lines3d is still a fix in progress, so this is only an interim fix...

@bwlewis
Copy link
Owner

bwlewis commented Feb 23, 2018

ok, the repeated call to lines3d should also be fixed now (see issue #79).

Let me know if things are working for you...

@ugroempi
Copy link
Author

ugroempi commented Feb 25, 2018

In terms of colors, things now work work for me. The lwd option for lines3d still does not have any effect. A repeated call to lines3d works by opening a new instance with only the new line, not what I would expect (Firefox 58.0.2, created with the conventional R GUI, R version 3.3.3). I'll try from my home machine (newer R version) later.
Update: same behavior under R 3.4.1 (using R GUI or RStudio with Firefox; RStudio with RStudio viewer is more erratic, it doesn't do the first plot, does the second one properly, and doesn't do lines at all).

Best, Ulrike

@bwlewis
Copy link
Owner

bwlewis commented Mar 2, 2018

I think this is working, here is what I get with the following program:

library(threejs)
m = cbind(x=1:10,y=1:10,z=(1:10)/((1:10)^2))
x = scatterplot3js(m) # 10 points
y = lines3d(x, 1, 10, lwd=5, color="blue") # add line between points 1 and 10
# add another line between points 3 and 10 and change the (global) lwd
z = lines3d(y, 3, 10, lwd=2, color=c("blue", "green"))
print(x)
print(y)
print(z)

image
image
image

@ugroempi
Copy link
Author

ugroempi commented Mar 2, 2018

Yes, indeed most of it also works for me! The lines3d did not work because of a simple mistake on my end (forgot to change s). The need to reset the color for the already drawn line is a surprise, but OK, once understood, can be used. The line width still does not work for me: both versions are quite thin and not different in width.

I don't understand the decision that previously drawn lines have to have their colors and widths respecified when adding further lines (this is what I conclude from your example); it is nice that this is possible, but in my view it is a nuisance that it is necessary (and I wouldn't have understood this from the documentation). As there is only a scalar lwd, the current behavior means that all lines have to have the same width; it would be useful to also allow vector-valued lwd (like color) or to keep color and line width for already existing lines.

Best, Ulrike

Code:
library(threejs)
m <- cbind(x=1:10,y=1:10,z=(1:10)/((1:10)^2))
s <- scatterplot3js(m, color="orange")
print(s)
print(s <- threejs::points3d(s, 1,1,1,color="blue")) # plus one blue circle
print(s <- lines3d(s, 1, 10, lwd=5, color="blue")) # plus one blue line
print(s <- lines3d(s, 2, 7, lwd=20, color=c("blue","green")) # plus one green line, make thick

@ugroempi ugroempi closed this as completed Mar 2, 2018
@ugroempi ugroempi reopened this Mar 2, 2018
@bwlewis
Copy link
Owner

bwlewis commented Mar 3, 2018

Ah, I see. It's a great point. I'm only adding one line yet specifying two colors. I agree that this is dumb and will change it...

bwlewis added a commit that referenced this issue Mar 13, 2018
@bwlewis
Copy link
Owner

bwlewis commented Mar 13, 2018

OK, after all this time, this should finally be fixed. Sorry for the slow progress. An example that illustrates the bug fixes/changes:

m = cbind(x=1:10,y=1:10,z=(1:10)/((1:10)^2))
(x = threejs::scatterplot3js(m, from=c(1,2), to=c(10,10), lcol=c("blue", "green"))) # 10 points, two lines
(y = threejs::lines3d(x, from=3, to=10, lwd=2, color="orange")) # another line, not the single color for the new one
(z = threejs::points3d(y, 5, 5, 0.5, size=2, color="green")) # same behavior for adding points
(a = threejs::points3d(z, 2, 8, 0.5, size=2, color="orange"))

@ugroempi
Copy link
Author

Nice, the colors now work for me. lwd still has no effect whatsoever (R 3.4.1 and Firefox).

@SergioCavaleiroCosta
Copy link

I am having troubles too.
I am currently running scatterplot3js inside shinydashboard with the example provided,

output$scatterTest <- renderScatterplotThree({
      N     = 20000
      theta = runif(N)*2*pi
      phi   = runif(N)*2*pi
      R     = 1.5
      r     = 1.0
      
      x = (R + r*cos(theta))*cos(phi)
      y = (R + r*cos(theta))*sin(phi)
      z = r*sin(theta)
      
      d = 6
      h = 6
      t = 2*runif(N) - 1
      w = t^2*sqrt(1-t^2)
      x1 = d*cos(theta)*sin(phi)*w
      y1 = d*sin(theta)*sin(phi)*w
      
      i = order(phi)
      j = order(t)
      col = c(rainbow(length(phi))[order(i)],
              rainbow(length(t), start=0, end=2/6)[order(j)])
      
      M = cbind(x=c(x, x1), y=c(y, y1), z=c(z, h*t))
      scatterplot3js(M, size=0.1, color="orange", bg="black", pch=".")
})

but points are all black regardless of the picked color.

screen shot 2018-06-17 at 13 00 52

Nevertheless, if I use color=rainbow(length(z)) it works has expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants