Tracker: Color scales, SQL domains/ranges, legends, and HDR across vis.gl

Open
#11,147 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start with the linked math.gl drafts #575 and #576 and the deck.gl foundations #11089 and #11100; then map the proposed milestones across math.gl, loaders.gl, luma.gl, and deck.gl. The acceptance criteria define completion: one resolved scale must drive GPU-ready colors and synchronized legends, including data-derived domains and explicit SDR/HDR behavior. This tracker spans several repositories and leaves the SQL grammar open for design.

Written by the indexing model from the issue text.

Description

Goal

Build a portable, first-class color-scale system across vis.gl, with SQL expression syntax for data-driven mappings, inspectable resolved scale descriptors, GPU-ready SDR/HDR outputs, and an automatic ColorScaleWidget in @deck.gl/widgets.

Non-negotiable invariant: the legend, tooltips, and rendered attributes must all use the same resolved scale, including actual domain, thresholds, interpolation/color space, null/under/over handling, and progressive updates. The widget must not reverse-engineer a palette from final RGBA buffers.

Motivating API (illustrative syntax, not an agreed implementation)

new ScatterplotLayer({
  id: 'temperatures',
  data: arrowTable,
  _queryProps: {
    getPosition: 'FLOAT32x2(longitude, latitude)',
    getRadius: 'SCALE_SQRT(population, DOMAIN(population), RANGE(2, 20))',
    getFillColor: "SCALE_COLOR(temperature, DOMAIN_QUANTILE(temperature, 0.02, 0.98), PALETTE('viridis'))"
  }
});

new ColorScaleWidget({
  layers: ['temperatures'], // optional: auto-discover by default
  placement: 'bottom-right'
});

Alternative fixed/explicit scale specifications:

SCALE_COLOR(temperature, DOMAIN(-20, 50), PALETTE('viridis'))
SCALE_DIVERGING(anomaly, DOMAIN_SYMMETRIC(anomaly, 0), PALETTE('RdBu'))
SCALE_ORDINAL(category, PALETTE('Tableau10'))
SCALE_QUANTILE(income, 5, PALETTE('Blues'))
SCALE_THRESHOLD(risk, ARRAY[20, 50, 80], PALETTE('YlOrRd', 4))
SCALE_LOG(volume, DOMAIN(1, 1000000), RANGE(1, 15))
SCALE_COLOR(elevation, DOMAIN(-8000, 0, 3000, 9000),
            PALETTE('#102a62', '#d9c9a5', '#588b50', '#ffffff'))

The exact SQL names and grammar remain to be designed. No WHERE, LIMIT, OFFSET, GROUP BY, or ORDER BY inside row-preserving accessor expressions. Data-derived domains are aggregate dependencies planned once across the input table, then reused by per-row scale evaluation. A table-level query controls row selection separately.

Functional scope

  • Continuous numeric: linear, sqrt/power, log and symlog, explicit/nice domains, clamping vs extrapolation.
  • Sequential/diverging color: named D3/ColorBrewer/other permissively licensed palettes, explicit color stops, diverging pivot, interpolation mode.
  • Discrete: ordinal/categorical with stable category mapping, quantize (equal-width), quantile (equal-frequency), threshold (explicit breaks), piecewise ramps.
  • Domain operators: fixed DOMAIN(min,max), data-derived DOMAIN(column), include-zero, symmetric-around-pivot, percentile-trimmed domains, nice bounds. Distinguish quantile-derived endpoints from quantile classification.
  • Null/missing/exception policy: explicit nullColor, under/over colors, NaN/inf handling and clamping; consistent across CPU/GPU/legend. Avoid silently inferring categories based on nondeterministic stream arrival order.
  • Reuse: named and/or interned compiled scales; shared statistics across layer attributes and legends. Resolve once per input version; avoid repeating aggregate scans per output row.
  • Progressive input: update domains on incoming batches/snapshots, correctly recolor existing data when required; allow fixed/frozen domains for stable legends. Separate append and replacement semantics.

Resolved scale / legend contract

Separate a serializable ScaleSpec from a runtime ResolvedColorScale. Candidate conceptual shape:

type ResolvedColorScale = {
  id: string;
  layerId?: string;
  attribute?: string;                // e.g. getFillColor
  type: 'continuous' | 'diverging' | 'ordinal' |
        'quantize' | 'quantile' | 'threshold';
  domain: readonly (number | string)[];
  colors: readonly (string | readonly number[])[];
  thresholds?: readonly number[];
  pivot?: number;
  palette?: string;
  interpolation?: 'srgb' | 'linear-srgb' | 'oklab' | 'jzazbz';
  nullColor?: string;
  clamp?: boolean;
  label?: string;
  units?: string;
  encoding?: ColorEncoding;
  // Runtime only; *the widget samples the actual evaluator*:
  sample(value: number | string): readonly number[];
};

Do not bake sample() into the JSON transport format. Scale descriptors should support color sampling, deterministic tick/class boundary generation, value formatting and tooltip interpretation; a registry keyed by stable layer+attribute (and optionally user-defined scale id) should survive deck.gl layer-instance replacement. Define change notifications so widgets refresh on new resolved statistics.

ColorScaleWidget requirements (@deck.gl/widgets)
  • Automatically discover scales produced by layers; optionally filter by layer IDs / color accessor names.
  • Render continuous gradients with numeric ticks, diverging ramps and zero/pivot ticks, quantile/quantize/threshold actual break labels, and bounded categorical swatches with category names.
  • Support multiple layer scales, title, units, formatting, no-data/under/over indicators, theme, accessibility, and reactive update when a scale changes.
  • Read only resolved scale metadata; no independent scan of layer data and no reverse inference from a final color buffer.
  • Initial version read-only. Movable/collapsible display and optional histogram later; interactive palette editor is a separate phase.
  • Reference the existing @deck.gl-community/widgets ColorLegendWidget (categorical / continuous / palette JSON payload) and kepler.gl's color scale/legend UX rather than duplicating unnecessary UI.

HDR and wide-gamut color (coordinate with #11146)

Separate (1) primaries / gamut: sRGB, Display-P3, Rec.2020; (2) transfer: linear, sRGB, PQ, HLG; (3) storage: RGBA8/16 UNORM, RGBA16F/32F; (4) interpolation space: sRGB, linear-sRGB, OKLab, potentially HDR-aware Jzazbz/ICtCp; and (5) display tone mapping.

  • RGBA8(...) / RGBA16(...): normalized float channels in [0,1], clamp then round to 255/65535, whole-vector null propagation.
  • RGBA16F(...) / RGBA32F(...): preserve extended-range, scene-linear channel values above 1; no silent clamping or SDR tone mapping at scale evaluation.
  • Scene-linear reference white / luminance metadata where needed; consistent alpha (including premultiplication) and color-space contracts.
  • Float16/Float32 GPU attributes, palette textures and intermediate render targets must not truncate HDR before the presentation boundary. Preserve existing compact byte path.
  • ColorScaleWidget uses faithful HDR presentation where supported, or an explicitly tone-mapped SDR preview with accurate labels and an indication of fallback.
  • Do not duplicate the rendering backlog: see #11146 Tracker: HDR color support for normalization, blending, output targets, presentation and cross-backend validation. This tracker owns the scale semantics and legend integration with that work.

Cross-repository PR checklist

Each unchecked item is a proposed PR or reviewable milestone, not a claim that work is already implemented.

visgl/math.gl — portable scale engine
  • PR: scale specification and typed descriptor vocabulary — draft math.gl #575 (implementation proposed; not merged): ScaleSpec, resolved scale, domain/range/palette/encoding metadata, serialization and sampling contract.
  • PR: SQL grammar + AST — stacked draft math.gl #576 (implementation proposed; not merged): DOMAIN, RANGE, PALETTE, typed constructors and SCALE_* syntax, with semantic validation and documented SQL examples.
  • PR: Arrow domain aggregations: min/max, include zero, symmetric extent; share/intern repeated reductions across columns. — draft math.gl #580; pending CI/review
  • PR: robust/classification domains: quantile, approximate quantile for large sources, quantize, thresholds, category domain discovery; deterministic category ordering. — draft math.gl #580 + #581; pending CI/review
  • PR: CPU/Arrow scale evaluators: numeric and color outputs, continuous/diverging/ordinal/discrete/piecewise, typed fixed-size list outputs and null handling. — draft math.gl #580; pending CI/review
  • PR: color science + palettes: named palette registry, color interpolation (sRGB/linear-sRGB/OKLab), explicit stops and gamut behavior, SDR/HDR numerical tests. — draft math.gl #580 + #582; pending CI/review
  • PR: HDR scale metadata/evaluation: Float16/32 scene-linear stops and extended values, wide-gamut metadata, optional HDR-aware interpolation, sampleable resolved descriptors. — draft math.gl #582 (partial HDR primitives); pending CI/review
visgl/loaders.gl — source/stream/query integration
  • PR: scale-aware query planning: collect domain dependencies from expressions, perform shared aggregates, and keep table-level queries separate from row-preserving attribute projections.
  • PR: pushdown and streaming: reuse physical scan/pruning, avoid redundant scans, maintain progressive domain state and clearly defined append vs replacement output contracts.
  • PR: large-data scale benchmarks/tests: Parquet/Arrow/CSV, approximate distributions, nulls, cancellation, deterministic results and stability across chunks.
visgl/luma.gl — GPU scale execution
  • PR: GPU scale primitives: WGSL scale normalization, transforms, typed vector/color output and palette lookup (uniforms, storage or texture LUT as appropriate).
  • PR: wide-gamut/HDR GPU scale outputs: Float16/Float32 attributes and palette textures, no premature clipping, numerical CPU/GPU comparison and HDR pathway integration with deck.gl #11146.
  • PR: performance + correctness benchmarks: large columnar inputs, row validity, stable layouts, color consistency across WebGL2/WebGPU where supported.
visgl/deck.gl — layers, registry, and widget
  • PR: scale registry and layer binding: publish resolved scale metadata by stable layer ID + attribute; observable changes for widgets, tooltips, and shared scales.
  • PR: SQL scale expressions in column/accessor props: integrate math.gl scales with _queryProps/Arrow evaluation, compile once, share domain results, respect row cardinality and typed GPU upload.
  • PR: ColorScaleWidget MVP: automatic discovery, continuous/diverging/categorical/quantile/quantize/threshold views, ticks, labels, units, multiple scales, accessible widget styling.
  • PR: progressive scale+legend synchronization: consistent domain changes, update notifications, fixed/frozen domains, transitions, no stale legend vs map.
  • PR: HDR legend presentation: correctly sampled gradients, HDR rendering where available, explicit SDR tone-mapped previews, color-space labeling, test coverage.
  • PR: end-to-end examples + tests: thematic maps, scientific continuous/diverging/threshold, categoricals, streaming/legends and SDR/HDR demonstrations.
Existing foundations (links, not completion of this tracker)
  • deck.gl #11089 — Arrow table / columnsQuery integration (open at tracker creation).
  • deck.gl #11100 — derived prop lifecycle infrastructure (open at tracker creation).
  • deck.gl #11098 — typed vector/color constructor experiment (closed, not merged).
  • deck.gl #11101 — _queryProps aggregate prototype (closed, not merged).
  • deck.gl #11102 — _queryProps accessor prototype (closed, not merged).
  • deck.gl #11146 — separate HDR color support tracker (open).
  • deck.gl-community #722 — existing ColorLegendWidget foundation.

Acceptance criteria

  • A scale from one SQL/AST specification drives both GPU-ready color attributes and an equivalent legend, with reproducible ticks, breaks, labels, palette interpolation and null/under/over semantics.
  • Fixed, data-derived, percentile, diverging and categorical scales work without per-row redundant scans.
  • Widget automatically discovers multiple layer color scales and stays synchronized after layers are reconstructed or progressive domains change.
  • SDR (UNORM) and HDR (FP16/FP32) scales have explicit color encoding, gamut and output behavior with no silent HDR clipping; widget shows correct HDR or labeled SDR fallback.
  • Tests verify CPU vs GPU mapping, Arrow input batching/chunking, stable categorical assignments, and legend-to-rendered-scale agreement.
References

This is a coordination tracker: implementation details and final SQL syntax should be refined in small focused PRs across the four repositories.

Dominant language
TypeScript
Stars
14.8k
Forks
2.3k
Avg merge
1d 9h
Merged PRs (30d)
230

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from visgl/deck.gl

All issues in visgl/deck.gl

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.