Skip to content

Commit

Permalink
docs: Update usage docs
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Sep 27, 2024
1 parent f77ec94 commit 0520a7d
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ npm install --save @carto/api-client

## Documentation

WORK IN PROGRESS.

### Fetching data

Import `vectorTableSource`, `vectorQuerySource`, and other data source functions
Expand All @@ -27,25 +25,23 @@ from the `@carto/api-client` package. These are drop-in replacements for the equ
```javascript
import { vectorTableSource } from '@carto/api-client';

const data = vectorTableSource({
const data = await vectorTableSource({
accessToken: '••••',
connectionName: 'carto_dw',
tableName: 'carto-demo-data.demo_tables.retail_stores'
});

const { widgetSource } = await data;

// → {name: string; value: number}[]
const categories = await widgetSource.getCategories({
const categories = await data.widgetSource.getCategories({
column: 'store_type',
operation: 'count',
});

// → {value: number}
const formula = await widgetSource.getFormula({operation: 'count'});
const formula = await data.widgetSource.getFormula({operation: 'count'});

// → {totalCount: number; rows: Record<string, number | string>[]}
const table = await widgetSource.getTable({
const table = await data.widgetSource.getTable({
columns: ['a', 'b', 'c'],
sortBy: ['a'],
rowsPerPage: 20
Expand All @@ -62,7 +58,7 @@ property to the source factory function.
```javascript
import {vectorTableSource} from '@carto/api-client';

const data = vectorTableSource({
const data = await vectorTableSource({
accessToken: '••••',
connectionName: 'carto_dw',
tableName: 'carto-demo-data.demo_tables.retail_stores',
Expand All @@ -79,7 +75,7 @@ results should not be affected by a filter that the widget itself created.

```javascript
// → {name: string; value: number}[]
const categories = await widgetSource.getCategories({
const categories = await data.widgetSource.getCategories({
filterOwner: 'widget-id',
column: 'store_type',
operation: 'count',
Expand All @@ -92,7 +88,7 @@ To filter the widget source to a spatial region, pass a `spatialFilter` paramete

```javascript
// → {name: string; value: number}[]
const categories = await widgetSource.getCategories({
const categories = await data.widgetSource.getCategories({
column: 'store_type',
operation: 'count',
spatialFilter: {
Expand All @@ -114,22 +110,10 @@ To create a spatial filter from the current [deck.gl `viewState`](https://deck.g

```javascript
import {WebMercatorViewport} from '@deck.gl/core';
import {createViewportSpatialFilter} from '@carto/api-client';

function createViewStatePolygon(viewState) {
const viewport = new WebMercatorViewport(viewState);
return {
type: 'Polygon',
coordinates: [
[
viewport.unproject([0, 0]),
viewport.unproject([viewport.width, 0]),
viewport.unproject([viewport.width, viewport.height]),
viewport.unproject([0, viewport.height]),
viewport.unproject([0, 0]),
],
],
};
}
const viewport = new WebMercatorViewport(viewState);
const spatialFilter = createViewportSpatialFilter(viewport.getBounds());
```

### Specifying columns to fetch
Expand Down

0 comments on commit 0520a7d

Please sign in to comment.