API / geotoolkit / util / DefaultColorProvider / DefaultColorProvider
util.DefaultColorProvider.DefaultColorProvider
This class is the default implementation of a colorprovider.
It uses a map of sorted values and colors.
When retrieving the Color for a specified value, if the value is not found in the collection it gets the minimum and maximum value relative to the specified value.
Then it gets the colors corresponding to these values, interpolates the colors and returns the color according to the relative position of the value between the minimum and maximum values.
Example
// 1). Default Color Provider allows for linear gradient with stops
const colorprovider = new DefaultColorProvider({
'values' : [ -2 , -1 , 0 , 1 , 2 ],
'colors' : ['orange', 'yellow', 'blue', 'green', 'gray']
});
// 2). To use 'JET' colormap like in MATLAB you can use the following code to create color provider for specified min and max values.
const min = -100, max = 100;
const colors: string[] = ['#00007F','#0000FF','#007FFF','#00FFFF','#7FFF7F','#FFFF00','#FF7F00','#FF0000','#7F0000'];
const values: number[] = [];
const delta = (max-min) / (colors.length-1);
for (let i = 0; i < colors.length; ++i) {
values.push(min + i * delta);
}
const colorprovider = new DefaultColorProvider({
'values': values,
'colors': colors
});↳
DefaultColorProvider
Constructors
Methods
Css Properties
| Name | Type | Description |
|---|---|---|
max | number | |
max | number | End value for the scale |
min | number | |
min | number | Start value for the scale |
reversed | boolean | Boolean to define the sorting direction |
scale | KnownScales | |
scale | KnownScales | A predefined set of colors |
Constructors
• new DefaultColorProvider(values?, colors?)
Create color provider
| Name | Type | Description |
|---|---|---|
Optional values | number[] | Options | The values or a json |
Optional colors | (string | RgbaColor)[] | The colors |
ColorProvider.constructor
Methods
▸ addColor(value, color): DefaultColorProvider
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
| Name | Type | Description |
|---|---|---|
value | number | index of this color on the colorbar |
color | string | RgbaColor | CSS color string or RgbaColor object |
this
▸ addColor(json): DefaultColorProvider
Deprecated
| Name | Type |
|---|---|
json | Object |
Optional json.alpha | number |
Optional json.blue | number |
json.color | string | RgbaColor |
Optional json.green | number |
Optional json.red | number |
json.value | number |
▸ clone(): ColorProvider
Returns clone of color provider
▸ Protected copyConstructor(src): DefaultColorProvider
Copy constructor
| Name | Type | Description |
|---|---|---|
src | ColorProvider | Source to copy from |
this
▸ dispose(): void
Dispose.
void
▸ exportToImage(width, height, isVertical, surface?): Surface
returns surface that represents color map
| Name | Type | Description |
|---|---|---|
width | number | The image width |
height | number | The image height |
isVertical | boolean | True if image is oriented vertically |
Optional surface | Surface | output surface |
surface The canvas surface
▸ getClassName(): string
string
▸ getColor(value): RgbaColor
Return color for the current value
| Name | Type | Description |
|---|---|---|
value | number | value |
color
▸ getColors(): RgbaColor[]
an array of the colors
▸ Protected getColorsProperties(): ColorsOptions
Returns colors and values to be serialized
colors and values
▸ Protected getDataMaxValue(): number
Returns the maximum data value set in this collection
number
▸ Protected getDataMinValue(): number
Returns the minimum data value set in this collection
number
▸ getMaxValue(): number
Returns the maximum value set in this collection
number
▸ getMinValue(): number
Returns minimum value set in the collection
number
▸ getNamedColor(colorName): string | NamedColorValue
Returns known color value
| Name | Type | Description |
|---|---|---|
colorName | string | color name, if not specified then returns list of known colors |
string | NamedColorValue
color
▸ getNamedColors(): NamedColor[]
Returns known colors
array of color pair
▸ getProperties(): OptionsOut
get Properties
▸ getRaster(xMin?, yMin?, xMax?, yMax?): Raster
Returns a new instance of Raster
| Name | Type | Description |
|---|---|---|
Optional xMin | number | x Min position to get color |
Optional yMin | number | y Min position to get color |
Optional xMax | number | x Max position to get color |
Optional yMax | number | y Max position to get color |
▸ getScale(): KnownScales
scale scale being used
▸ getStopPoints(): { color: string ; value: number }[]
{ color: string ; value: number }[]
an array of the {color,values} couples
▸ getValues(): number[]
Always return a reference to sorted array of values. Don't change this array.
number[]
an array of the values
▸ hasEventListener(type, callback?): boolean
Check if a list of event listeners for this type contains this listener
| Name | Type | Description |
|---|---|---|
type | string | type of event or property |
Optional callback | Function | to be called, if null, check if any callback is registered |
boolean
ColorProvider.hasEventListener
▸ hasNamedColor(colorName): boolean
Check if specified named color exists
| Name | Type | Description |
|---|---|---|
colorName | string | color name |
boolean
true if color exists
▸ invalidate(): DefaultColorProvider
Invalidate Default ColorProvider and notify visuals for update
▸ isDisposed(): boolean
Returns whether this object has been disposed
boolean
▸ isNotificationEnabled(): boolean
Return state of notification
boolean
current notification state
ColorProvider.isNotificationEnabled
▸ isReversed(): boolean
return true if the min / max is reversed
boolean
▸ isSilent(): boolean
Return true if the event dispatcher doesn't notify any events
boolean
▸ notify<E>(type, source, args?): DefaultColorProvider
Notify listeners
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | event types |
source | ColorProvider | of the event |
Optional args | EventMap[E] | arguments of the event |
this
▸ off<E>(type?, callback?): DefaultColorProvider
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.
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
Optional type | E | type of the event |
Optional callback | (eventType: E, sender: DefaultColorProvider, args: EventMap[E]) => void | function to be called |
this
▸ on<E>(type, callback): DefaultColorProvider
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.
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | type of event or property |
callback | (eventType: E, sender: DefaultColorProvider, args: EventMap[E]) => void | to be called |
this
▸ removeColor(value): DefaultColorProvider
Remove color from the collection
| Name | Type | Description |
|---|---|---|
value | number | value to remove color |
this
▸ reverse(): DefaultColorProvider
reverse the axis
▸ scaleTo(start, end): DefaultColorProvider
set the min/max of the color provider, interpolating all values on the way.
Throws
if start or end is NaN
| Name | Type | Description |
|---|---|---|
start | number | Start value to use |
end | number | End value to use |
this
▸ setColors(values, colors?): DefaultColorProvider
Replace all colors in the collection by this set
| Name | Type | Description |
|---|---|---|
values | Colors | new values or properties object |
Optional colors | (string | RgbaColor)[] | new colors |
this
▸ setNamedColor(colorName, colorValue): DefaultColorProvider
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');| Name | Type | Description |
|---|---|---|
colorName | string | color name |
colorValue | string | NamedColorValue | color or title/value settings object |
this
▸ setNotification(enable, force?): DefaultColorProvider
Enable / disable notification
| Name | Type | Description |
|---|---|---|
enable | boolean | enable or disable notifications |
Optional force | boolean | true if parent should be invalidated immediately |
this
▸ setProperties(properties?): DefaultColorProvider
set Properties
| Name | Type | Description |
|---|---|---|
Optional properties | Options | Json object with properties |
this
▸ setScale(scale, start?, end?): DefaultColorProvider
Replace all colors in the collection by this scale
| Name | Type | Description |
|---|---|---|
scale | string | Scale to use |
Optional start | number | Start value to use |
Optional end | number | End value to use |
this
▸ setSilent(bool): DefaultColorProvider
Set silent mode
| Name | Type | Description |
|---|---|---|
bool | boolean | flag to enable silent mode |
this
▸ Static fromObject(object): DefaultColorProvider
Create or get DefaultColorProvider from an object
| Name | Type | Description |
|---|---|---|
object | Options | to get provider from |
provider
▸ Static getClassName(): string
string
▸ Static getColorProviderType(objectType?): ClassType<any>
Return ColorProvider constructor from the object class name or type.
Deprecated
since 4.1 Use ColorProvider implementation directly
| Name | Type | Description |
|---|---|---|
Optional objectType | string | ColorProvider class name |
ClassType<any>
ColorProvider constructor