@deck.gl/carto 8.7.7 → 8.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/carto",
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
- "version": "8.7.7",
5
+ "version": "8.7.10",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -57,5 +57,5 @@
57
57
  "@deck.gl/layers": "^8.0.0",
58
58
  "@loaders.gl/core": "^3.1.5"
59
59
  },
60
- "gitHead": "5a7e586411cb538d3319e35f8e07d61c9a3efb6d"
60
+ "gitHead": "0d3e70aefb845cd7b37ce030a67d8a6540420c5c"
61
61
  }
@@ -7,7 +7,8 @@ import {
7
7
  scalePoint,
8
8
  scaleQuantile,
9
9
  scaleQuantize,
10
- scaleSqrt
10
+ scaleSqrt,
11
+ scaleThreshold
11
12
  } from 'd3-scale';
12
13
  import {format as d3Format} from 'd3-format';
13
14
  import moment from 'moment-timezone';
@@ -27,10 +28,13 @@ const SCALE_FUNCS = {
27
28
  point: scalePoint,
28
29
  quantile: scaleQuantile,
29
30
  quantize: scaleQuantize,
30
- sqrt: scaleSqrt
31
+ sqrt: scaleSqrt,
32
+ custom: scaleThreshold
31
33
  };
32
34
  export type SCALE_TYPE = keyof typeof SCALE_FUNCS;
33
35
 
36
+ const UNKNOWN_COLOR = '#868d91';
37
+
34
38
  export const AGGREGATION = {
35
39
  average: 'MEAN',
36
40
  maximum: 'MAX',
@@ -179,7 +183,11 @@ function domainFromAttribute(attribute, scaleType: SCALE_TYPE) {
179
183
 
180
184
  function domainFromValues(values, scaleType: SCALE_TYPE) {
181
185
  if (scaleType === 'ordinal') {
182
- return [...new Set(values)].sort();
186
+ return groupSort(
187
+ values,
188
+ g => -g.length,
189
+ d => d
190
+ );
183
191
  } else if (scaleType === 'quantile') {
184
192
  return values.sort((a, b) => a - b);
185
193
  } else if (scaleType === 'log') {
@@ -226,13 +234,31 @@ export function getColorValueAccessor({name}, colorAggregation, data: any) {
226
234
  export function getColorAccessor(
227
235
  {name},
228
236
  scaleType: SCALE_TYPE,
229
- {colors},
237
+ {colors, colorMap},
230
238
  opacity: number | undefined,
231
239
  data: any
232
240
  ) {
233
241
  const scale = SCALE_FUNCS[scaleType as any]();
234
- scale.domain(calculateDomain(data, name, scaleType));
235
- scale.range(colors);
242
+ let domain: (string | number)[] = [];
243
+ let scaleColor: string[] = [];
244
+
245
+ if (Array.isArray(colorMap)) {
246
+ colorMap.forEach(([value, color]) => {
247
+ domain.push(value);
248
+ scaleColor.push(color);
249
+ });
250
+ } else {
251
+ domain = calculateDomain(data, name, scaleType);
252
+ scaleColor = colors;
253
+ }
254
+
255
+ if (scaleType === 'ordinal') {
256
+ domain = domain.slice(0, scaleColor.length);
257
+ }
258
+
259
+ scale.domain(domain);
260
+ scale.range(scaleColor);
261
+ scale.unknown(UNKNOWN_COLOR);
236
262
  const alpha = opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
237
263
 
238
264
  const accessor = properties => {
@@ -116,6 +116,8 @@ type FetchLayerDataParams = {
116
116
  clientId?: string;
117
117
  format?: Format;
118
118
  formatTiles?: TileFormat;
119
+ aggregationExp?: string;
120
+ aggregationResLevel?: number;
119
121
  };
120
122
 
121
123
  /**
@@ -127,7 +129,9 @@ function getParameters({
127
129
  geoColumn,
128
130
  columns,
129
131
  schema,
130
- clientId
132
+ clientId,
133
+ aggregationExp,
134
+ aggregationResLevel
131
135
  }: Omit<FetchLayerDataParams, 'connection' | 'credentials'>) {
132
136
  const parameters = [encodeParameter('client', clientId || DEFAULT_CLIENT)];
133
137
  if (schema) {
@@ -137,12 +141,18 @@ function getParameters({
137
141
  const sourceName = type === MAP_TYPES.QUERY ? 'q' : 'name';
138
142
  parameters.push(encodeParameter(sourceName, source));
139
143
 
140
- if (GEO_COLUMN_SUPPORT.includes(type) && geoColumn) {
144
+ if (geoColumn) {
141
145
  parameters.push(encodeParameter('geo_column', geoColumn));
142
146
  }
143
- if (COLUMNS_SUPPORT.includes(type) && columns) {
147
+ if (columns) {
144
148
  parameters.push(encodeParameter('columns', columns.join(',')));
145
149
  }
150
+ if (aggregationExp) {
151
+ parameters.push(encodeParameter('aggregationExp', aggregationExp));
152
+ }
153
+ if (aggregationResLevel) {
154
+ parameters.push(encodeParameter('aggregationResLevel', aggregationResLevel));
155
+ }
146
156
 
147
157
  return parameters.join('&');
148
158
  }
@@ -155,10 +165,21 @@ export async function mapInstantiation({
155
165
  geoColumn,
156
166
  columns,
157
167
  schema,
158
- clientId
168
+ clientId,
169
+ aggregationExp,
170
+ aggregationResLevel
159
171
  }: FetchLayerDataParams): Promise<MapInstantiation> {
160
172
  const baseUrl = `${credentials.mapsUrl}/${connection}/${type}`;
161
- const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns, schema, clientId})}`;
173
+ const url = `${baseUrl}?${getParameters({
174
+ type,
175
+ source,
176
+ geoColumn,
177
+ columns,
178
+ schema,
179
+ clientId,
180
+ aggregationExp,
181
+ aggregationResLevel
182
+ })}`;
162
183
  const {accessToken} = credentials;
163
184
 
164
185
  if (url.length > MAX_GET_LENGTH && type === MAP_TYPES.QUERY) {
@@ -187,7 +208,11 @@ function checkFetchLayerDataParameters({
187
208
  type,
188
209
  source,
189
210
  connection,
190
- credentials
211
+ credentials,
212
+ geoColumn,
213
+ columns,
214
+ aggregationExp,
215
+ aggregationResLevel
191
216
  }: FetchLayerDataParams) {
192
217
  assert(connection, 'Must define connection');
193
218
  assert(type, 'Must define a type');
@@ -196,6 +221,29 @@ function checkFetchLayerDataParameters({
196
221
  assert(credentials.apiVersion === API_VERSIONS.V3, 'Method only available for v3');
197
222
  assert(credentials.apiBaseUrl, 'Must define apiBaseUrl');
198
223
  assert(credentials.accessToken, 'Must define an accessToken');
224
+
225
+ if (columns) {
226
+ assert(
227
+ COLUMNS_SUPPORT.includes(type),
228
+ `The columns parameter is not supported by type ${type}`
229
+ );
230
+ }
231
+ if (geoColumn) {
232
+ assert(
233
+ GEO_COLUMN_SUPPORT.includes(type),
234
+ `The geoColumn parameter is not supported by type ${type}`
235
+ );
236
+ } else {
237
+ assert(!aggregationExp, 'Have aggregationExp, but geoColumn parameter is missing');
238
+ assert(!aggregationResLevel, 'Have aggregationResLevel, but geoColumn parameter is missing');
239
+ }
240
+
241
+ if (!aggregationExp) {
242
+ assert(
243
+ !aggregationResLevel,
244
+ 'Have aggregationResLevel, but aggregationExp parameter is missing'
245
+ );
246
+ }
199
247
  }
200
248
 
201
249
  export interface FetchLayerDataResult {
@@ -213,7 +261,9 @@ export async function fetchLayerData({
213
261
  format,
214
262
  formatTiles,
215
263
  schema,
216
- clientId
264
+ clientId,
265
+ aggregationExp,
266
+ aggregationResLevel
217
267
  }: FetchLayerDataParams): Promise<FetchLayerDataResult> {
218
268
  // Internally we split data fetching into two parts to allow us to
219
269
  // conditionally fetch the actual data, depending on the metadata state
@@ -227,7 +277,9 @@ export async function fetchLayerData({
227
277
  format,
228
278
  formatTiles,
229
279
  schema,
230
- clientId
280
+ clientId,
281
+ aggregationExp,
282
+ aggregationResLevel
231
283
  });
232
284
 
233
285
  const data = await requestData({url, format: mapFormat, accessToken});
@@ -249,7 +301,9 @@ async function _fetchDataUrl({
249
301
  format,
250
302
  formatTiles,
251
303
  schema,
252
- clientId
304
+ clientId,
305
+ aggregationExp,
306
+ aggregationResLevel
253
307
  }: FetchLayerDataParams) {
254
308
  const defaultCredentials = getDefaultCredentials();
255
309
  // Only pick up default credentials if they have been defined for
@@ -258,7 +312,16 @@ async function _fetchDataUrl({
258
312
  ...(defaultCredentials.apiVersion === API_VERSIONS.V3 && defaultCredentials),
259
313
  ...credentials
260
314
  };
261
- checkFetchLayerDataParameters({type, source, connection, credentials: localCreds});
315
+ checkFetchLayerDataParameters({
316
+ type,
317
+ source,
318
+ connection,
319
+ credentials: localCreds,
320
+ geoColumn,
321
+ columns,
322
+ aggregationExp,
323
+ aggregationResLevel
324
+ });
262
325
 
263
326
  if (!localCreds.mapsUrl) {
264
327
  localCreds.mapsUrl = buildMapsUrlFromBase(localCreds.apiBaseUrl);
@@ -272,7 +335,9 @@ async function _fetchDataUrl({
272
335
  geoColumn,
273
336
  columns,
274
337
  schema,
275
- clientId
338
+ clientId,
339
+ aggregationExp,
340
+ aggregationResLevel
276
341
  });
277
342
  let url: string | null = null;
278
343
  let mapFormat: Format | undefined;