bwlewis / rthreejs

Three.js widgets for R and shiny
http://bwlewis.github.io/rthreejs
Other
303 stars 64 forks source link

animation demos for vertex.shape="sphere" don't respond to click #63

Closed jzicker closed 7 years ago

jzicker commented 7 years ago

I changed the vertex.shape="sphere from the default and now the vertices don't respond when clicked on.

bwlewis commented 7 years ago

Indeed, trying to fix this now.

bwlewis commented 7 years ago

should be fixed now, re-open if you're still running in to trouble with this.

jzicker commented 7 years ago

It does seem to be getting the node ID in the js in chrome browser. My code changes colors of nodes which renders if simple circles. If vertex.shape = "sphere" then the colors don't change/render upon click. I tried to find in code where this occurs but didn't track it down all the way.

bwlewis commented 7 years ago

do the click animation demos in the package work for you?

On Jun 26, 2017 11:45, "jzicker" notifications@github.com wrote:

It does seem to be getting the node ID in the js in chrome browser. My code changes colors of nodes which renders if simple circles. If vertex.shape = "sphere" then the colors don't change/render upon click. I tried to find in code where this occurs but didn't track it down all the way.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/bwlewis/rthreejs/issues/63#issuecomment-311098696, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIsnkvaJp6wCn9OpTgNqtYkNdIpJoqeks5sH9H-gaJpZM4Novpn .

bwlewis commented 7 years ago

sorry, i meant the demos modified to use spheres?

i can get clicks to work with spheres now (but not generic symbols).

however, sphere rendering is very slow.

On Jun 26, 2017 12:11, "Bryan W. Lewis" blewis@illposed.net wrote:

do the click animation demos in the package work for you?

On Jun 26, 2017 11:45, "jzicker" notifications@github.com wrote:

It does seem to be getting the node ID in the js in chrome browser. My code changes colors of nodes which renders if simple circles. If vertex.shape = "sphere" then the colors don't change/render upon click. I tried to find in code where this occurs but didn't track it down all the way.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/bwlewis/rthreejs/issues/63#issuecomment-311098696, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIsnkvaJp6wCn9OpTgNqtYkNdIpJoqeks5sH9H-gaJpZM4Novpn .

bwlewis commented 7 years ago

Here is an example shiny app that shows that globes and circles work, but not generic symbols:

library("shiny")
library("threejs")

data("LeMis")

shiny::runApp(list(
ui = fluidPage(
  titlePanel("Shiny three.js graph example"),
  sidebarLayout(
    sidebarPanel(
      selectInput("select", label = h3("Vertex shape"),
                  choices = list("Spheres" = "o", "Circles" = "@", "Labels" = "Labels"), selected = 1),
      p("Use the mouse zoom to rotate, zoom, and pan.")
    ),
    mainPanel(
        scatterplotThreeOutput("graph")
    )
  )
),
server = function(input, output)
{
  output$graph <- renderScatterplotThree({
    v <- input$select
    if (v == "Labels") v <- V(LeMis)$label

    N  <- length(V(LeMis))
    # Vertex page rank values (a measure of network centrality for each vertex)
    pr <- page_rank(LeMis)$vector
    # order the page rank values
    i <- order(pr, decreasing=TRUE)

    # Vertex cluster membership
    cl <- unclass(membership(cluster_louvain(LeMis)))

    # Find the index of the highest page rank vertex in each cluster
    idx <- aggregate(seq(1:N)[i], by=list(cl[i]), FUN=head, 1)$x
    # Create a default force-directed layout for the whole networl
    l1 <- norm_coords(layout_with_fr(LeMis, dim=3))
    # Collapse the layout to just the idx vertices
    l0 <- Reduce(rbind,Map(function(i) l1[idx[i],], cl))

    # Create grouped vertex colors, setting all but idx vertices transparent
    col <- rainbow(length(idx), alpha=0)[cl]
    col[idx] <- rainbow(length(idx), alpha=1)

    # animation layouts, one for each of the idx vertices, and
    # animation color schemes, one scheme for each idx vertex
    click <- Map(function(i)
    {
      x <- l0
      x[cl == i, ] <- l1[cl == i, ]
      c <- col
      c[cl == i] <- rainbow(length(idx), alpha=1)[i]
      list(layout=x, vertex.color=c, vertex.shape=v)
    }, seq(idx))
    names(click) <- paste(idx)

    graphjs(LeMis, layout=l0, click=click, vertex.shape=v, vertex.color=col, fps=20, font.main="96px Arial")

  })
}))

But, if I missed something please re-open with an example of how it's broken.

jzicker commented 7 years ago

I will work on sending graph data and example. My example changes the colors of the sphere vertices. It still isn't working. Here is code without data for graph g

create click animation list to color neigherbor nodes

N<-length(V(g)) idx<-c(1:N)

create default layout

l1 <- norm_coords(layout_with_fr(g, dim=3))

create click animation list coloring graph neighbor nodes

click1 <- Map(function(i) { n1<-V(g)[nei(i)] V(g)$color<-"gray80" V(g)$color[n1]<-"darkgreen" V(g)$color[i]<-"red" list(layout=l1, vertex.color=V(g)$color, vertex.shape="o") }, idx) names(click1) <- paste(seq(idx))

V(g)$color<-"darkgreen"

g1<-graphjs(g, layout=l1,click=click1, vertex.shape="o", fps=20,vertex.label = V(g)$name) print(g1)

bwlewis commented 7 years ago

I'll re-open until this can be resolved.

jzicker commented 7 years ago

latest commits fixed my issue. I also tried brush=TRUE which worked for me as well. Thank you so much.

bwlewis commented 7 years ago

Great, glad things are working @jzicker. Thanks for your very helpful bug reports, patience and experiments!