Transforms

Transforms process a data stream to filter data, calculate new fields, or derive new data streams. Transforms are typically specified within the transform array of a data definition. In addition, transforms that do not filter or generate new data objects can be used within the transform array of a mark definition to specify post-encoding transforms.

The following example defines a new data set with transforms to filter values and then compute a stacked layout (e.g., for a stacked bar chart):

{
  "data": [
    {
      "name": "table",
      "transform": [
        { "type": "filter", "expr": "datum.value > 5" },
        { "type": "stack", "field": "value", "groupby": ["category"] }
      ]
    }
  ]
}

All transforms require a type property, specifying the name of the transform. The supported transform types are listed below In addition, many transform also acc

Basic Transforms

Transforms for processing streams of data objects.

  • aggregate - Group and summarize a data stream.
  • bin - Discretize numeric values into uniform bins.
  • collect - Collect and sort all data objects in a stream.
  • countpattern - Count the frequency of patterns in text strings.
  • cross - Perform a cross-product of a data stream with itself.
  • density - Generate values drawn from a probability distribution.
  • extent - Compute minimum and maximum values over a data stream.
  • filter - Filter a data stream using a predicate expression.
  • fold - Collapse selected data fields into key and value properties.
  • formula - Extend data objects with derived fields using a formula expression.
  • impute - Perform imputation of missing values.
  • lookup - Extend data objects by looking up key values on another stream.
  • rank - Assign increasing rank-order scores to data objects.
  • sample - Randomly sample data objects in a stream.
  • sequence - Generate a new stream containing a sequence of numeric values.

Geographic Transforms

Transforms for projecting geographic data and generating geographic guides.

  • geopath - Map GeoJSON features to SVG path strings.
  • geopoint - Map (longtidue, latitude) coordinates to (x, y) points.
  • geoshape - Map GeoJSON features to a shape instance for procedural drawing.
  • graticule - Generate a reference grid for cartographic maps.

Layout Transforms

Transforms for calculating spatial coordinates to achieve various layouts.

  • linkpath - Route visual links between node elements.
  • pie - Compute angular layout for pie and donut charts.
  • stack - Compute stacked layouts for groups of values.
  • force - Compute a force-directed layout via physical simulation.
  • voronoi - Compute a Voronoi diagram for a set of points.
  • wordcloud - Compute a word cloud layout of text strings.

Hierarchy Transforms

Transforms for processing hierarchy (tree) data and performing tree layout.

  • nest - Generate a tree structure by grouping objects by field values.
  • stratify - Generate a tree structure using explicit key values.
  • treelinks - Generate link data objects for a tree structure.
  • pack - Tree layout based on circular enclosure.
  • partition - Tree layout based on spatial adjacency of nodes.
  • tree - Tree layout for a node-link diagram.
  • treemap - Tree layout based on recursive rectangular subdivision.

Cross-Filter Transforms

Transforms for supporting fast incremental filtering of multi-dimensional data.

  • crossfilter - Maintain a filter mask for multiple dimensional queries.
  • resolvefilter - Resolve crossfilter output to generate filtered data streams.