Skip to content

LegendLayer.setSource

Summary

LegendLayer.setSource switches the legend data source and marks legend state dirty for redraw. The layer unsubscribes from previous source signals and subscribes to the new source when available. Use this when changing point-cloud scalar fields, glyph mappings, or nodelink node/edge scalar views interactively.

Syntax

LegendLayer.setSource(source: OverlayLegendSource): void
layer.setSource(source);

Parameters

Name Type Required Description
source OverlayLegendSource Yes New legend source object or explicit scale/colormap descriptor.

Returns

void - No return value.

Type Details

OverlayLegendExplicitSource

type OverlayLegendExplicitSource = {
    scaleTransform: ScaleTransformDescriptor | ScaleTransform;
    colormap: Colormap | BuiltinColormapName;
    colormapStops?: ReadonlyArray<Color4>;
};

OverlayLegendNodeLinkSource

type OverlayLegendNodeLinkSource = {
    nodelink: NodeLink;
    component?: "node" | "edge";
};

OverlayLegendSource

type OverlayLegendSource = PointCloud | GlyphField | NodeLink | OverlayLegendNodeLinkSource | DataMaterial | OverlayLegendExplicitSource;

Passing a NodeLink directly binds to node scalars. Use { nodelink, component: "edge" } when the legend should track edge scale and edge colormap state.

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const legend = wgpu.createOverlay.legend({
    source: { scaleTransform: { mode: "linear", domainMin: 0, domainMax: 1 }, colormap: "viridis" }
});
legend.setSource({
    scaleTransform: { mode: "linear", domainMin: -2, domainMax: 2 },
    colormap: "plasma"
});

See Also