FIMViz.jsAPI
    Preparing search index...

    Class ColorScale

    Index
    • Parameters

      • Optionalopts: {
            continuous?: boolean;
            max?: number;
            min?: number;
            missingColor?: string;
            palette?: string | string[];
            source?: "palette" | "custom" | "gdal";
            stops?: {
                color: string;
                label?: string;
                max?: number;
                min?: number;
                range?: [number, number];
                value?: number;
            }[];
            unit?: string;
        } = {}
        • Optionalcontinuous?: boolean
        • Optionalmax?: number
        • Optionalmin?: number
        • OptionalmissingColor?: string

          the colour for a value that ISN'T one: null/undefined/ NaN/''. null (the default) means "no colour" — the consumer decides what absent looks like (a vector layer leaves the feature at its base style; a raster leaves the pixel transparent). Set it to render missing data explicitly, e.g. a grey "no data" swatch.

        • Optionalpalette?: string | string[]

          a PALETTES/registered name, or a custom array of >=2 hex colors

        • Optionalsource?: "palette" | "custom" | "gdal"
        • Optionalstops?: {
              color: string;
              label?: string;
              max?: number;
              min?: number;
              range?: [number, number];
              value?: number;
          }[]

          explicit stops; presence switches to explicit mode

        • Optionalunit?: string

      Returns ColorScale

    _colorStopColors: string[]
    _colorStopValues: number[]
    _continuous: boolean
    _listeners: any[]
    _max: number
    _min: number
    _stops: { color: any; label: any }[]
    colorFor: (value: number) => string
    missingColor: string
    palette: string | any[]
    source: "palette" | "custom" | "gdal"
    unit: string
    • get continuous(): boolean

      Is interpolation on? A read-only flag — write it with set({ continuous }).

      Returns boolean

    • Resolve any value → css color string. colorFor wins; a value that isn't one resolves to missingColor (or null); null when nothing matches.

      Parameters

      • value: number

      Returns string

    • Parameters

      • i: number

        band index (as returned by getStops())

      Returns { max: number; min: number }

    • Hot-path [r,g,b] for the render loop; null → pixel is transparent (no matching stop, or an absent value with no missingColor).

      Parameters

      • value: number

      Returns [number, number, number]

    • [{ min?, max?, value?, color, label }] — explicit→stored | palette→derived | colorStops→one { value, color } per control point (setColorStops).

      Returns ColorStop[]

    • THE knob writer. One mutation idiom for every whole-object knob:

      cs.set({ palette: 'viridis', min: 0, max: 46, continuous: true, unit: 'm' });

      Sync and chainable (returns this) — a ColorScale is a pure value type, so nothing here awaits. Fires onChange ONCE for the whole batch, not once per key, so a repaint hook wired via onChange doesn't redraw N times for one logical edit.

      Recognised keys: palette, min, max, continuous, unit, stops, colorStops ({values, colors}). stops/colorStops are MODE switches and remain available as the explicit setStops()/setColorStops() methods too; the INDEX-addressed ops (setColor(i,·), setRange(i,·), setLabel(i,·)) are not knobs and stay as their own verbs.

      An unknown key throws, naming the recognised set, rather than being silently ignored.

      Parameters

      • Optionalpatch: {
            colorStops?: { colors: string[]; values: number[] };
            continuous?: boolean;
            max?: number;
            min?: number;
            palette?: string | string[];
            stops?: any[];
            unit?: string;
        } = {}

      Returns ColorScale

    • Define a CONTINUOUS color gradient via explicit control points — arbitrary breakpoint VALUES (need not be evenly spaced, or even given in order — sorted internally), each paired with its own color. Distinct from setStops(): that's discrete, flat bands (one solid color per range/value, no interpolation); this interpolates smoothly between the nearest bracketing pair when set({continuous:true}) is set (the intended pairing) — setColorStops([-1, 0, 1], ['#015498', '#ffffff', '#21bf90']).set({ continuous: true }) gives a diverging blue→white→green gradient skewed however the control points are spaced, not an even 3-way split of some [min,max]. Values outside the outermost control point clamp to that end's color (no extrapolation). With continuous false, a value takes the NEAREST control point's color instead of interpolating — flat, but not "banded" in the setStops() sense, since these are point positions, not ranges.

      set({min,max})'s domain keeps governing peripheral things (a legend axis label, a stats-classification range) but the actual color mapping is driven entirely by these control points, not by min/max — the two are complementary, not conflicting: set both if you want a labeled axis range that differs from where the color control points themselves sit.

      Parameters

      • values: number[]

        breakpoint values; >= 2 required

      • colors: string[]

        one "#rrggbb" hex color per value, same length as values

      Returns ColorScale

    • Parameters

      • stops: {
            color: string;
            label?: string;
            max?: number;
            min?: number;
            range?: [number, number];
            value?: number;
        }[]

      Returns ColorScale

    • A plain, structured-cloneable description of this scale — enough to rebuild an equivalent one with new ColorScale(spec). It captures whichever of the three modes is active.

      This is a COPY, not a handle: rebuilding from it gives an independent scale, so two layers built from one spec can diverge. colorFor (a function) and onChange listeners are deliberately not included — neither survives serialization.

      Returns {
          colorStops: { colors: string[]; values: number[] };
          continuous: boolean;
          max: number;
          min: number;
          palette: string | string[];
          source: string;
          stops: any[];
          unit: string;
      }

    • Parameters

      • legend: { color: string; label?: string; range?: [number, number]; value?: number }[]
      • Optionalunit: string = ""

      Returns ColorScale

    • Rebuild a scale from toJSON() output. Restores the continuous-control-point mode too, which the constructor alone cannot express.

      Parameters

      • spec: any = {}

      Returns ColorScale

    • The registered GDAL legend parser, or null if nothing has registered one yet.

      Returns Function

    • Every palette name available to { palette } — the built-ins plus anything registered.

      Returns string[]

    • Register the GDAL_METADATA XML parser used to auto-detect an embedded legend. Called by layers/depthMap.js on import.

      Parameters

      • fn: (xmlStr: string) => { legend: any[]; unit: string }

      Returns void

    • Add a palette by name. colors: >= 2 hex strings.

      Parameters

      • name: string
      • colors: string[]

      Returns void