R/move_layer_down_grob.R

Defines functions move_layerDown_grob

move_layerDown_grob <- function(loon.grob, currentLayer, parent) {

  parent_layer <- grid::getGrob(loon.grob, parent)
  layersName <- parent_layer$childrenOrder

  if(currentLayer %in% layersName) {

    layer_order <- which(layersName %in% currentLayer)
  } else {

    parent <- getParent(gTree = parent_layer, currentLayer = currentLayer)
    parent_layer <- grid::getGrob(parent_layer, parent)

    layersName <- parent_layer$childrenOrder
    layer_order <- which(layersName %in% currentLayer)
  }

  if(layer_order == 1) {

    warning(paste("Warning: layer" , currentLayer, "cannot be lowered any further."))
    loon.grob
  } else {

    grid::setGrob(
      gTree = loon.grob,
      gPath = parent,
      newGrob = reorderGrob(
        parent_layer,
        order = layer_reorder(layer_order, len_layersName = length(layersName), way = "down")
      )
    )
  }
}

Try the loon.shiny package in your browser

Any scripts or data that you put into this service are public.

loon.shiny documentation built on Oct. 8, 2022, 5:05 p.m.