ndtv icon indicating copy to clipboard operation
ndtv copied to clipboard

add function for applying post-processing layout transformations

Open skyebend opened this issue 8 years ago • 0 comments

(transfered from statnet trac ticket #1212) there are several function like layout.normalize that transform coords. But can be difficult to include within the layout process. Would be useful to be able to 'lapply' them to all of the slices after a layout has been created

perhaps coordApply ?

below is a draft I wrote for layout.normalize, could easily be adapted to be more general.

# function to re-process all the coordinates and scale them to the same interval
rescaleAnimation<-function(nd){
  # get the slicing params
  slice.par<-nd%n%'slice.par'
  starts<-seq(from=slice.par$start, to=slice.par$end,by = slice.par$interval)
  ends<-seq(from=slice.par$start+slice.par$aggregate.dur,to=slice.par$end+slice.par$aggregate.dur, by = slice.par$interval)
  for(s in seq_along(starts)){
    message('rescaling step ',s)
    coords<-cbind(get.vertex.attribute.active(nd,'animation.x',onset=starts[s],terminus=ends[s]),
                  get.vertex.attribute.active(nd,'animation.y',onset=starts[s],terminus=ends[s]))
    coords<-layout.normalize(coords)
    activate.vertex.attribute(nd,'animation.x',coords[,1],onset=starts[s],terminus=ends[s])
    activate.vertex.attribute(nd,'animation.y',coords[,2],onset=starts[s],terminus=ends[s])
  }
  return(nd)
}

skyebend avatar Apr 21 '16 21:04 skyebend