Skip to content

Commit

Permalink
Merge branch 'master' into felix/carto-correct-geo
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Oct 24, 2023
2 parents e935b09 + b46d59b commit fb86d4d
Show file tree
Hide file tree
Showing 59 changed files with 510 additions and 2,423 deletions.
4 changes: 2 additions & 2 deletions examples/layer-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"start-local": "vite --config ../vite.config.local.mjs"
},
"dependencies": {
"@loaders.gl/ply": "^3.4.13",
"@loaders.gl/gltf": "^3.4.13",
"@loaders.gl/ply": "4.0.0-beta.5",
"@loaders.gl/gltf": "4.0.0-beta.5",
"@luma.gl/debug": "^8.5.2",
"colorbrewer": "^1.0.0",
"d3-request": "^1.0.6",
Expand Down
10 changes: 5 additions & 5 deletions examples/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/3d-tiles": "^3.4.13",
"@loaders.gl/core": "^3.4.13",
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/draco": "^3.4.13",
"@loaders.gl/gltf": "^3.4.13",
"@loaders.gl/3d-tiles": "4.0.0-beta.5",
"@loaders.gl/core": "4.0.0-beta.5",
"@loaders.gl/csv": "4.0.0-beta.5",
"@loaders.gl/draco": "4.0.0-beta.5",
"@loaders.gl/gltf": "4.0.0-beta.5",
"@luma.gl/constants": "^8.5.12",
"brace": "^0.11.1",
"deck.gl": "^8.8.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"deck.gl": "^8.8.0",
"@loaders.gl/3d-tiles": "^3.4.13",
"@loaders.gl/3d-tiles": "4.0.0-beta.5",
"maplibre-gl": "^2.4.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/globe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/csv": "4.0.0-beta.5",
"@material-ui/core": "^4.10.2",
"@material-ui/icons": "^4.9.1",
"deck.gl": "^8.8.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/i3s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/i3s": "^3.4.13",
"@loaders.gl/i3s": "4.0.0-beta.5",
"deck.gl": "^8.8.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/website/mask-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/csv": "4.0.0-beta.5",
"@material-ui/core": "^4.10.2",
"@material-ui/icons": "^4.9.1",
"deck.gl": "^8.8.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/website/mesh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/obj": "^3.4.13",
"@math.gl/core": "4.0.0-alpha.4",
"@loaders.gl/obj": "4.0.0-beta.5",
"@math.gl/core": "^4.0.0",
"deck.gl": "^8.8.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/website/point-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/las": "^3.4.13",
"@loaders.gl/las": "4.0.0-beta.5",
"deck.gl": "^8.8.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/website/radio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/csv": "4.0.0-beta.5",
"@material-ui/core": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.57",
"d3-scale": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/safegraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/csv": "4.0.0-beta.5",
"d3-scale": "^2.0.0",
"deck.gl": "^8.8.0",
"mapbox-gl": "^1.13.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/website/text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "vite build"
},
"dependencies": {
"@loaders.gl/csv": "^3.4.13",
"@loaders.gl/csv": "4.0.0-beta.5",
"d3-scale": "^2.0.0",
"deck.gl": "^8.8.0",
"maplibre-gl": "^2.4.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/aggregation-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@luma.gl/constants": "9.0.0-alpha.37",
"@luma.gl/core": "9.0.0-alpha.37",
"@luma.gl/shadertools": "9.0.0-alpha.37",
"@math.gl/web-mercator": "4.0.0-alpha.4",
"@math.gl/web-mercator": "^4.0.0",
"d3-hexbin": "^0.2.1"
},
"peerDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions modules/carto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@loaders.gl/gis": "^3.4.13",
"@loaders.gl/loader-utils": "^3.4.13",
"@loaders.gl/mvt": "^3.4.13",
"@loaders.gl/tiles": "^3.4.13",
"@loaders.gl/gis": "4.0.0-beta.5",
"@loaders.gl/loader-utils": "4.0.0-beta.5",
"@loaders.gl/mvt": "4.0.0-beta.5",
"@loaders.gl/tiles": "4.0.0-beta.5",
"@luma.gl/core": "9.0.0-alpha.37",
"@luma.gl/constants": "^8.5.20",
"@math.gl/web-mercator": "4.0.0-alpha.4",
"@math.gl/web-mercator": "^4.0.0",
"cartocolor": "^4.0.2",
"d3-array": "^3.2.0",
"d3-color": "^3.1.0",
Expand All @@ -53,7 +53,7 @@
"quadbin": "^0.1.9"
},
"devDependencies": {
"@loaders.gl/schema": "^3.4.13",
"@loaders.gl/schema": "4.0.0-beta.5",
"@types/d3-array": "^3.0.2",
"@types/d3-color": "^1.4.2",
"@types/d3-scale": "^3.0.0"
Expand All @@ -64,7 +64,7 @@
"@deck.gl/extensions": "^8.0.0",
"@deck.gl/geo-layers": "^8.0.0",
"@deck.gl/layers": "^8.0.0",
"@loaders.gl/core": "^3.4.13"
"@loaders.gl/core": "4.0.0-beta.5"
},
"gitHead": "13ace64fc2cee08c133afc882fc307253489a4e4"
}
1 change: 0 additions & 1 deletion modules/carto/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export {CartoAPIError} from './carto-api-error';
export type {APIErrorContext} from './carto-api-error';
export {FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';
export type {QueryParameters} from './maps-api-common';
export {getDataV2, CONNECTIONS} from './maps-client';
export {fetchLayerData, fetchMap, mapInstantiation} from './maps-v3-client';
63 changes: 37 additions & 26 deletions modules/carto/src/api/layer-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import QuadbinTileLayer from '../layers/quadbin-tile-layer';
import RasterTileLayer from '../layers/raster-tile-layer';
import VectorTileLayer from '../layers/vector-tile-layer';
import {MapType, TILE_FORMATS, TileFormat} from './maps-api-common';
import {assert, createBinaryProxy} from '../utils';
import {assert, createBinaryProxy, scaleIdentity} from '../utils';
import {
CustomMarkersRange,
MapDataset,
Expand All @@ -41,7 +41,8 @@ const SCALE_FUNCS = {
quantile: scaleQuantile,
quantize: scaleQuantize,
sqrt: scaleSqrt,
custom: scaleThreshold
custom: scaleThreshold,
identity: scaleIdentity
};
export type SCALE_TYPE = keyof typeof SCALE_FUNCS;

Expand Down Expand Up @@ -313,7 +314,7 @@ export function opacityToAlpha(opacity?: number) {
return opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
}

function getAccessorKeys(name: string, aggregation: string | undefined): string[] {
function getAccessorKeys(name: string, aggregation?: string | undefined): string[] {
let keys = [name];
if (aggregation) {
// Snowflake will capitalized the keys, need to check lower and upper case version
Expand All @@ -339,33 +340,13 @@ export function getColorValueAccessor({name}, colorAggregation, data: any) {
}

export function getColorAccessor(
{name},
{name, colorColumn}: VisualChannelField,
scaleType: SCALE_TYPE,
{aggregation, range: {colors, colorMap}},
{aggregation, range},
opacity: number | undefined,
data: any
) {
const scale = SCALE_FUNCS[scaleType as any]();
let domain: (string | number)[] = [];
let scaleColor: string[] = [];

if (Array.isArray(colorMap)) {
colorMap.forEach(([value, color]) => {
domain.push(value);
scaleColor.push(color);
});
} else {
domain = calculateDomain(data, name, scaleType, colors.length);
scaleColor = colors;
}

if (scaleType === 'ordinal') {
domain = domain.slice(0, scaleColor.length);
}

scale.domain(domain);
scale.range(scaleColor);
scale.unknown(UNKNOWN_COLOR);
const scale = calculateLayerScale(colorColumn || name, scaleType, range, data);
const alpha = opacityToAlpha(opacity);

let accessorKeys = getAccessorKeys(name, aggregation);
Expand All @@ -380,6 +361,36 @@ export function getColorAccessor(
return normalizeAccessor(accessor, data);
}

function calculateLayerScale(name, scaleType, range, data) {
const scale = SCALE_FUNCS[scaleType]();
let domain: (string | number)[] = [];
let scaleColor: string[] = [];

if (scaleType !== 'identity') {
const {colorMap, colors} = range;

if (Array.isArray(colorMap)) {
colorMap.forEach(([value, color]) => {
domain.push(value);
scaleColor.push(color);
});
} else {
domain = calculateDomain(data, name, scaleType, colors.length);
scaleColor = colors;
}

if (scaleType === 'ordinal') {
domain = domain.slice(0, scaleColor.length);
}
}

scale.domain(domain);
scale.range(scaleColor);
scale.unknown(UNKNOWN_COLOR);

return scale;
}

const FALLBACK_ICON =
'data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==';

Expand Down
Loading

0 comments on commit fb86d4d

Please sign in to comment.