R/hgch-click.R

Defines functions click_functions

click_functions <- function(viz, frtype = NULL, id_click = NULL) {
  if (is.null(id_click)) return()
  click_func <- paste0("function(event) {Shiny.onInputChange('", id_click, "', {id:event.point.name, timestamp: new Date().getTime()});}")

  if (frtype %in% c("CatCatNum", "CatCat", "CatDat", "CatDatNum", "DatNumNum")) {
    click_func <- paste0("function(event) {Shiny.onInputChange('", id_click, "', {cat:event.point.category, id:this.name, timestamp: new Date().getTime()});}")
  }

  if (frtype %in% c("DatNum")) {
    click_func <- paste0("function(event) {Shiny.onInputChange('", id_click, "', {id:event.point.category, timestamp: new Date().getTime()});}")
  }

  if (viz %in% "treemap") {
    if (frtype %in% c("CatCatNum", "CatCat")) {
      click_func <- paste0("function(event) {Shiny.onInputChange('", id_click, "', {cat:event.point.node.parent, id:event.point.node.name, timestamp: new Date().getTime()});}")
    }
  }

  if (viz %in% "sankey") {
    click_func <- paste0("function(event) {Shiny.onInputChange('", id_click, "', {node:event.point.name, cat:event.point.to, id:event.point.from, timestamp: new Date().getTime()});}")
  }

  click_func
}
randommonkey/hgchmagic documentation built on Aug. 23, 2023, 5:56 a.m.