R/vizLibRJava.R

Defines functions helloJavaWorld createVizFromSyntaxJava getSyntaxJava

#################################################################
# IBM Confidential
# OCO Source Materials
# WDP Shaper
# (c) Copyright IBM Corp. 2017
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
#################################################################

getSyntaxJava <- function(jsonDataSetStr, fieldNamesToVisualize) {
  numFieldNames <- length(fieldNamesToVisualize)
  # If there is only 1 column name, it still needs to be put inside Java array
  # otherwise, the call to getBrunelVisualizationSyntax will fail
  if (numFieldNames < 2) {
    fieldNamesToVisualize <- .jcall("org/brunel/data/io/CSV", "S", "identifier", fieldNamesToVisualize)
    fieldNamesToVisualize <- .jarray(fieldNamesToVisualize)
  } else {
    for (i in 1:numFieldNames) {
      fieldNamesToVisualize[i] <- .jcall("org/brunel/data/io/CSV", "S", "identifier", fieldNamesToVisualize[i])
    }
  }
  out <- .jcall("com/ibm/wml/dataviz/BrunelDataVizUtils", "S", "getBrunelVisualizationSyntax", jsonDataSetStr, fieldNamesToVisualize)
  return(out)
}

createVizFromSyntaxJava <- function(jsonDataSetStr, syntax, width, height) {
  # out <- .jcall("com/ibm/wml/dataviz/BrunelDataVizUtils", "S", "createBrunelVisualizationFromSyntax", jsonDataSetStr, syntax);
  out <- .jcall("com/ibm/wml/dataviz/BrunelDataVizUtils", "S", "createBrunelVisualizationFromSyntax", jsonDataSetStr, syntax, as.integer(width), as.integer(height))
  return(out)
}

# A Test function to quickly test that rJava is working in this project
helloJavaWorld <- function() {
  hjw <- .jnew("HelloJavaWorld") # create instance of HelloJavaWorld class
  out <- .jcall(hjw, "S", "sayHello") # invoke sayHello method
  return(out)
}
kevin-sorat/v2viz documentation built on Oct. 24, 2017, 8:03 a.m.