Last updated

API / geotoolkit / util / DiscreteGradientColorProvider / DiscreteGradientColorProvider

Class: DiscreteGradientColorProvider

util.DiscreteGradientColorProvider.DiscreteGradientColorProvider

This class implements a colorprovider that use discretization to emulate a gradient.
It's main purpose is to simplify a gradient by reducing the amount of possible colors (mostly for performance reasons).

The discretization process can be controlled through the given 'bins' parameter that defines how many discrete colors will be used.

Example

// Discrete Gradient Color Provider allows for limited number of bins
const discreteCP = new DiscreteGradientColorProvider({
'values' : [  -2  ,   -1  ,     0   ,   1  ,     2    ],
'colors' : ['orange', 'yellow', 'blue', 'green', 'gray']
'bins': 16
});

Hierarchy

Table of contents

Constructors
Methods
Css Properties
Name Type Description
binsnumberNumber of bins
maxnumber
maxnumberEnd value for the scale
minnumber
minnumberStart value for the scale
reversedbooleanBoolean to define the sorting direction
scaleKnownScales
scaleKnownScalesA predefined set of colors

Contents

Constructors

new DiscreteGradientColorProvider(values, colors, bins)

new DiscreteGradientColorProvider(values?, colors?, bins?)

Creates color provider

Parameters

Name Type Description
Optional valuesnumber[] | Optionslist of values
Optional colors(string | RgbaColor)[]list of colors
Optional binsnumbernumber of bins

Overrides

DefaultColorProvider.constructor

Methods

addColor

addColor(value, color): DiscreteGradientColorProvider

Add color to the collection Compatibility: old JSON format {'value': 0, 'red': 255, 'green': 255, 'blue': 255, 'alpha': 1} is supported, but new parameter list is recommended

Parameters

Name Type Description
valuenumberindex of this color on the colorbar
colorstring | RgbaColorCSS color string or RgbaColor object

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.addColor

addColor(json): DiscreteGradientColorProvider

Deprecated

Parameters

Name Type
jsonObject
Optional json.alphanumber
Optional json.bluenumber
json.colorstring | RgbaColor
Optional json.greennumber
Optional json.rednumber
json.valuenumber

Returns

DiscreteGradientColorProvider

Inherited from

DefaultColorProvider.addColor


clone

clone(): ColorProvider

Returns clone of color provider

Returns

ColorProvider

Inherited from

DefaultColorProvider.clone


copyConstructor

Protected copyConstructor(src): DiscreteGradientColorProvider

Copy constructor

Parameters

Name Type Description
srcColorProviderSource to copy from

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.copyConstructor


dispose

dispose(): void

Dispose.

Returns

void

Inherited from

DefaultColorProvider.dispose


exportToImage

exportToImage(width, height, isVertical, surface?): Surface

returns surface that represents color map

Parameters

Name Type Description
widthnumberThe image width
heightnumberThe image height
isVerticalbooleanTrue if image is oriented vertically
Optional surfaceSurfaceoutput surface

Returns

Surface

surface The canvas surface

Inherited from

DefaultColorProvider.exportToImage


getClassName

getClassName(): string

Returns

string

Inherited from

DefaultColorProvider.getClassName


getColor

getColor(value): RgbaColor

Return color for the current value

Parameters

Name Type Description
valuenumbervalue

Returns

RgbaColor

color

Inherited from

DefaultColorProvider.getColor


getColorNumber

getColorNumber(): number

Returns how many colors can be provided

Returns

number


getColors

getColors(): RgbaColor[]

Returns

RgbaColor[]

an array of the colors

Inherited from

DefaultColorProvider.getColors


getColorsProperties

Protected getColorsProperties(): ColorsOptions

Returns colors and values to be serialized

Returns

ColorsOptions

colors and values

Inherited from

DefaultColorProvider.getColorsProperties


getDataMaxValue

Protected getDataMaxValue(): number

Returns the maximum data value set in this collection

Returns

number

Inherited from

DefaultColorProvider.getDataMaxValue


getDataMinValue

Protected getDataMinValue(): number

Returns the minimum data value set in this collection

Returns

number

Inherited from

DefaultColorProvider.getDataMinValue


getMaxValue

getMaxValue(): number

Returns the maximum value set in this collection

Returns

number

Inherited from

DefaultColorProvider.getMaxValue


getMinValue

getMinValue(): number

Returns minimum value set in the collection

Returns

number

Inherited from

DefaultColorProvider.getMinValue


getNamedColor

getNamedColor(colorName): string | NamedColorValue

Returns known color value

Parameters

Name Type Description
colorNamestringcolor name, if not specified then returns list of known colors

Returns

string | NamedColorValue

color

Inherited from

DefaultColorProvider.getNamedColor


getNamedColors

getNamedColors(): NamedColor[]

Returns known colors

Returns

NamedColor[]

array of color pair

Inherited from

DefaultColorProvider.getNamedColors


getProperties

getProperties(): OptionsOut

get Properties

Returns

OptionsOut

Overrides

DefaultColorProvider.getProperties


getRaster

getRaster(xMin?, yMin?, xMax?, yMax?): Raster

Returns a new instance of Raster

Parameters

Name Type Description
Optional xMinnumberx Min position to get color
Optional yMinnumbery Min position to get color
Optional xMaxnumberx Max position to get color
Optional yMaxnumbery Max position to get color

Returns

Raster

Inherited from

DefaultColorProvider.getRaster


getScale

getScale(): KnownScales

Returns

KnownScales

scale scale being used

Inherited from

DefaultColorProvider.getScale


getStopPoints

getStopPoints(): { color: string ; value: number }[]

Returns

{ color: string ; value: number }[]

an array of the {color,values} couples

Inherited from

DefaultColorProvider.getStopPoints


getValues

getValues(): number[]

Always return a reference to sorted array of values. Don't change this array.

Returns

number[]

an array of the values

Inherited from

DefaultColorProvider.getValues


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

DefaultColorProvider.hasEventListener


hasNamedColor

hasNamedColor(colorName): boolean

Check if specified named color exists

Parameters

Name Type Description
colorNamestringcolor name

Returns

boolean

true if color exists

Inherited from

DefaultColorProvider.hasNamedColor


invalidate

invalidate(): DiscreteGradientColorProvider

Invalidate Default ColorProvider and notify visuals for update

Returns

DiscreteGradientColorProvider

Inherited from

DefaultColorProvider.invalidate


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

DefaultColorProvider.isDisposed


isNotificationEnabled

isNotificationEnabled(): boolean

Return state of notification

Returns

boolean

current notification state

Inherited from

DefaultColorProvider.isNotificationEnabled


isReversed

isReversed(): boolean

return true if the min / max is reversed

Returns

boolean

Inherited from

DefaultColorProvider.isReversed


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

DefaultColorProvider.isSilent


notify

notify<E>(type, source, args?): DiscreteGradientColorProvider

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourceColorProviderof the event
Optional argsEventMap[E]arguments of the event

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.notify


off

off<E>(type?, callback?): DiscreteGradientColorProvider

Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: DiscreteGradientColorProvider, args: EventMap[E]) => voidfunction to be called

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.off


on

on<E>(type, callback): DiscreteGradientColorProvider

Attach listener on event that will be called whenever the specified event is delivered to the target

If the callback function is already in the list of event listeners for this target, the function is not added a second time.

If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: DiscreteGradientColorProvider, args: EventMap[E]) => voidto be called

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.on


removeColor

removeColor(value): DiscreteGradientColorProvider

Remove color from the collection

Parameters

Name Type Description
valuenumbervalue to remove color

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.removeColor


reverse

reverse(): DiscreteGradientColorProvider

reverse the axis

Returns

DiscreteGradientColorProvider

Overrides

DefaultColorProvider.reverse


scaleTo

scaleTo(start, end): DiscreteGradientColorProvider

set the min/max of the color provider, interpolating all values on the way.

Throws

if start or end is NaN

Parameters

Name Type Description
startnumberStart value to use
endnumberEnd value to use

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.scaleTo


setColorNumber

setColorNumber(colorNumber): DiscreteGradientColorProvider

Sets how many colors can be provided

Parameters

Name Type Description
colorNumbernumbernumber of colors that can be provided

Returns

DiscreteGradientColorProvider

this


setColors

setColors(values, colors?): DiscreteGradientColorProvider

Parameters

Name Type Description
valuesColorsnew values
Optional colors(string | RgbaColor)[]new colors

Returns

DiscreteGradientColorProvider

this

Overrides

DefaultColorProvider.setColors


setNamedColor

setNamedColor(colorName, colorValue): DiscreteGradientColorProvider

Set color value

Example

import {KnownColors} from '@int/geotoolkit/util/ColorProvider';
colorProvider.setNamedColor(KnownColors.NaN, { // set color for NaN values
'title': 'absent', // title to use when displaying, e.g. by ColorBar shape
'enabled': true, // enable state (default is not false)
'value': 'black' // color to use for NaNs
});

Example

// use 'red' color for values greater than maxValue (default '+∞' title is used)
colorProvider.setNamedColor(KnownColors.PositiveInfinity, 'red');

Parameters

Name Type Description
colorNamestringcolor name
colorValuestring | NamedColorValuecolor or title/value settings object

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.setNamedColor


setNotification

setNotification(enable, force?): DiscreteGradientColorProvider

Enable / disable notification

Parameters

Name Type Description
enablebooleanenable or disable notifications
Optional forcebooleantrue if parent should be invalidated immediately

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.setNotification


setProperties

setProperties(properties?): DiscreteGradientColorProvider

set Properties of the object

Parameters

Name Type Description
Optional propertiesOptionscolor provider properties

Returns

DiscreteGradientColorProvider

this

Overrides

DefaultColorProvider.setProperties


setScale

setScale(scale, min?, max?): DiscreteGradientColorProvider

Replace all colors in the collection by this scale

Parameters

Name Type Description
scalestringScale to use
Optional minnumberMinimum to use
Optional maxnumberMaximum to use

Returns

DiscreteGradientColorProvider

this

Overrides

DefaultColorProvider.setScale


setSilent

setSilent(bool): DiscreteGradientColorProvider

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

DiscreteGradientColorProvider

this

Inherited from

DefaultColorProvider.setSilent


fromObject

Static fromObject(object): DiscreteGradientColorProvider

Create or get DiscreteGradientColorProvider from an object

Parameters

Name Type Description
objectDiscreteGradientColorProvider | Optionsgradient provider properties or instance

Returns

DiscreteGradientColorProvider

provider

Overrides

DefaultColorProvider.fromObject


getClassName

Static getClassName(): string

Returns

string

Inherited from

DefaultColorProvider.getClassName


getColorProviderType

Static getColorProviderType(objectType?): ClassType<any>

Return ColorProvider constructor from the object class name or type.

Deprecated

since 4.1 Use ColorProvider implementation directly

Parameters

Name Type Description
Optional objectTypestringColorProvider class name

Returns

ClassType<any>

ColorProvider constructor

Inherited from

DefaultColorProvider.getColorProviderType