Class Data

java.lang.Object
smile.plot.vega.Data

public class Data extends Object
The basic data model used by Vega-Lite is tabular data. Individual data sets are assumed to contain a collection of records, which may contain any number of named data fields.

A dataset may be either inline data (values) or a URL from which to load the data (url). Or we can create an empty, named data source (name), which can be bound at runtime or populated from top-level datasets.

  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toPrettyString

      public String toPrettyString()
      Returns the specification in pretty print.
      Returns:
      the specification in pretty print.
    • name

      public Data name(String name)
      Sets a placeholder name and bind data at runtime.
      Parameters:
      name - the dataset name.
      Returns:
      this object.
    • url

      public Data url(String url)
      Sets the url of the data source.
      Parameters:
      url - A URL from which to load the data set.
      Returns:
      this object.
    • format

      public Data format(String format)
      Sets the format for parsing the data.
      Parameters:
      format - "json", "csv", "tsv", or "dsv".
      Returns:
      this object.
    • format

      public Data format(String format, Map<String,String> type)
      Sets the format for parsing the data.
      Parameters:
      format - "json", "csv", "tsv", or "dsv".
      type - Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.
      Returns:
      this object.
    • values

      public Data values(String json)
      Sets an array describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.
      Parameters:
      json - JSON content to parse.
      Returns:
      this object.
    • values

      public <T> Data values(T[] data)
      Sets an array describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.
      Parameters:
      data - an array of data.
      Returns:
      this object.
    • values

      public <T> Data values(List<T> data)
      Sets a list describing the data source. Set to null to ignore the parent's data source. If no data is set, it is derived from the parent.
      Parameters:
      data - a list of data.
      Returns:
      this object.
    • json

      public Data json(String url, String property)
      Loads a JSON file. Assumes row-oriented data, where each row is an object with named attributes.
      Parameters:
      url - A URL from which to load the data set.
      property - The JSON property containing the desired data. This parameter can be used when the loaded JSON file may have surrounding structure or meta-data. For example "values.features" is equivalent to retrieving json.values.features from the loaded JSON object.
      Returns:
      this object.
    • topojson

      public Data topojson(String url, String conversion, String name)
      Loads a JSON file using the TopoJSON format. The input file must contain valid TopoJSON data. The TopoJSON input is then converted into a GeoJSON format. There are two mutually exclusive properties that can be used to specify the conversion process: "feature" or "mesh".
      Parameters:
      url - A URL from which to load the data set.
      conversion - "feature" or "mesh".
      name - The name of the TopoJSON object set to convert to a GeoJSON feature collection (or mesh).
      Returns:
      this object.
    • csv

      public Data csv(String url, Map<String,String> type)
      Loads a comma-separated values (CSV) file
      Parameters:
      url - A URL from which to load the data set.
      type - Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.
      Returns:
      this object.
    • tsv

      public Data tsv(String url, Map<String,String> type)
      Loads a tab-separated values (TSV) file
      Parameters:
      url - A URL from which to load the data set.
      type - Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.
      Returns:
      this object.
    • dsv

      public Data dsv(String url, String delimiter)
      Loads a delimited text file with a custom delimiter. This is a general version of CSV and TSV.
      Parameters:
      url - A URL from which to load the data set.
      delimiter - The delimiter between records. The delimiter must be a single character (i.e., a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not.
      Returns:
      this object.
    • dsv

      public Data dsv(String url, String delimiter, Map<String,String> type)
      Loads a delimited text file with a custom delimiter. This is a general version of CSV and TSV.
      Parameters:
      url - A URL from which to load the data set.
      delimiter - The delimiter between records. The delimiter must be a single character (i.e., a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not.
      type - Explicit data type. Each key corresponds to a field name, and the value to the desired data type (one of "number", "boolean", "date", or null (do not parse the field)). If set to null, disable type inference based on the spec and only use type inference based on the data.
      Returns:
      this object.