Skip to content

Commit

Permalink
Support *ScaleType and *Percentile props
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Sep 3, 2024
1 parent 1f1b155 commit 2cd0deb
Show file tree
Hide file tree
Showing 20 changed files with 768 additions and 602 deletions.
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

0 comments on commit 2cd0deb

Please sign in to comment.