![JAR search and dependency download from the Maven repository](/logo.png)
vegas.data.ValueTransformer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vegas_2.11 Show documentation
Show all versions of vegas_2.11 Show documentation
The missing matplotlib for Scala and Spark
The newest version!
package vegas.data
import java.text.SimpleDateFormat
/**
* Base trait for transforming Any values into primitive types that are accepted by vega-lite. Default implementation
* does a pass through for primitives, converts dates to ISO8601, and uses toString for everything else.
*/
trait ValueTransformer {
def transform(values: Map[String, Any]): Map[String, Any] = values.map { case(k,v) => (k, transformValue(v)) }
/**
* Transforms Any values into one of the supported primitive types
*/
def transformValue(value: Any): Any
}
object DefaultValueTransformer extends ValueTransformer {
val df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
def transformValue(v: Any): Any = v match {
case null => null
case st if SimpleTypeUtils.isSimpleType(st) => st
case d: java.sql.Date => d.toString
case d: java.util.Date => df.format(d)
case Some(x: Any) => transformValue(x)
case None => null
case _ => v.toString
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy