Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Aggregation: Support *ScaleType and *Percentile props #9130

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/aggregation-layers/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export type AggregateAccessor<DataT = any> = (
data: any;
}
) => number;

export type ScaleType = 'linear' | 'quantize' | 'quantile' | 'ordinal';
25 changes: 22 additions & 3 deletions modules/aggregation-layers/src/common/utils/color-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import type {Color} from '@deck.gl/core';
import type {Device, Texture} from '@luma.gl/core';
import type {NumericArray, TypedArray, TypedArrayConstructor} from '@math.gl/types';
import type {ScaleType} from '../types';

export const defaultColorRange: Color[] = [
[255, 255, 178],
Expand Down Expand Up @@ -63,15 +64,33 @@ export function colorRangeToFlatArray(
return flatArray;
}

export function colorRangeToTexture(device: Device, colorRange: Color[] | NumericArray): Texture {
export const COLOR_RANGE_FILTER: Record<ScaleType, 'linear' | 'nearest'> = {
linear: 'linear',
quantile: 'nearest',
quantize: 'nearest',
ordinal: 'nearest'
} as const;

export function updateColorRangeTexture(texture: Texture, type: ScaleType) {
texture.setSampler({
minFilter: COLOR_RANGE_FILTER[type],
magFilter: COLOR_RANGE_FILTER[type]
});
}

export function createColorRangeTexture(
device: Device,
colorRange: Color[] | NumericArray,
type: ScaleType = 'linear'
): Texture {
const colors = colorRangeToFlatArray(colorRange, false, Uint8Array);

return device.createTexture({
format: 'rgba8unorm',
mipmaps: false,
sampler: {
minFilter: 'linear',
magFilter: 'linear',
minFilter: COLOR_RANGE_FILTER[type],
magFilter: COLOR_RANGE_FILTER[type],
addressModeU: 'clamp-to-edge',
addressModeV: 'clamp-to-edge'
},
Expand Down
219 changes: 0 additions & 219 deletions modules/aggregation-layers/src/common/utils/scale-utils.js

This file was deleted.

Loading
Loading