Models

Once you've specified a Data Source, you can easily access a widget model using any of the functions in this a page. This is a basic usage example for a category model that can be used to build a bar chart.

import {vectorTableSource} from 'carto-api-client';

const data = await vectorTableSource({...})

const formula = await data.widgetSource.getCategories({
    column: 'column_A',
    operation: 'count',
    operationColumn: 'column_B'
});

All models support a set of base options, but there are several types of widget models, each of them returning a different data model more suitable for a type of data visualization:

Model base options

All models support the following options:

interface BaseRequestOptions {
  spatialFilter?: GeoJSON.Polygon | GeoJSON.MultiPolygon; // GeoJSON Polygon or MultiPolygon geometry
  abortController?: AbortController;
  filterOwner?: string;
}
  • spatialFilter (optional): used for filtering a widget based on a geometry, such as a user input or the current deck.gl map view state. Learn more about filters.

  • abortController (optional): allows you to cancel ongoing requests, saving data warehouse resources and free up computing and queuing capacity.

  • filterOwner (optional): this widget will be excluded from all column filters with a matching owner property. In other words, filters with a matching owner property won't filter this widget's data. The most common use case for this is when filters are originated based on user interactions with the widget. Learn more about column-based filtering.

Last updated