Nutrient Web SDK

v0.0.0-dev

Class Color

Color objects are used in annotations for defining colors. We're using an rgb representation internally with the r, g, b values clipped between 0 and 255 inclusive, and a transparent flag that can be used to indicate that the color is transparent, in which case the provided r, g, and b values are ignored and set to 0 in the instantiated Color.

It is an Immutable.Record and thus can be updated using set(key, value), for example: color.set("r", 255).

However, in order to obtain a transparent color the static TRANSPARENT value should be used instead.

The difference between using Color.TRANSPARENT and null as values for annotation color properties may depend on the context; if the annotation is being created or updated:

  • If an annotation with a non-transparent color value is updated to have a color value of Color.TRANSPARENT, the color value will be updated and be transparent.
  • But if that same annotation is updated to have a color value of null, the color change will not be saved to the document, although it may appear as transparent in the viewer.

To avoid inconsistencies, it is recommended to always use Color.TRANSPARENT instead of null when updating annotations.

Class

Example

Create and update a color.

var color = new NutrientViewer.Color({ r: 245, g: 0, b: 0 });
color = color.set("r", 255);
color.r; // => 255

Default Value

{ r: 0, g: 0, b: 0, transparent: false }

Hierarchy

RecordColor

Constructors

  • Parameters

    color{ b?: number; g?: number; r?: number; transparent?: boolean }

Properties

b

Readonly
number

The blue value of the color.

Default Value

0

g

Readonly
number

The green value of the color.

Default Value

0

r

Readonly
number

The red value of the color.

Default Value

0

transparent

Readonly
boolean

Transparency of the color.

Default Value

false

BLACK

Static

Simple black (CSS: rgb(0, 0, 0))

BLUE

Static

Blue (CSS: rgb(34, 147, 251))

DARK_BLUE

Static

Blue (CSS: rgb(36, 131, 199))

DARK_GREY

Static

Dark grey (CSS: rgb(64, 64, 64))

GREEN

Static

Green (CSS: rgb(110, 176, 0))

GREY

Static

Grey (CSS: rgb(128, 128, 128))

Light blue (CSS: rgb(141, 184, 255))

Light green (CSS: rgb(162, 250, 123))

Light grey (CSS: rgb(192, 192, 192))

Light orange (CSS: rgb(255, 139, 94))

LIGHT_RED

Static

Light red (CSS: rgb(247, 141, 138))

Light yellow (CSS: rgb(252, 238, 124))

MAUVE

Static

Mauve (CSS: rgb(245, 135, 255))

ORANGE

Static

Orange (CSS: rgb(243, 149, 0))

PINK

Static

Pink (CSS: rgb(255, 114, 147))

PURPLE

Static

Purple (CSS: rgb(255, 0, 255))

RED

Static

Red (CSS: rgb(248, 36, 0))

Transparent (CSS: transparent)

WHITE

Static

Simple white (CSS: rgb(255, 255, 255))

YELLOW

Static

Yellow (CSS: rgb(255, 255, 0))

Methods

  • Returns a darker version of the current Color.

    Parameters

    percentnumber

    The percentage of lightness between 0 and 100.

    Returns

    A Color with the new values.

    Example

    const color = NutrientViewer.Color.RED.darker(50);
    
  • Returns true if the provided color or object and the current Color have the same RGB values.

    Parameters

    colorNutrientViewer.Color | { b: number; g: number; r: number; transparent: boolean }

    Color instance or RGB object.

    Returns

    boolean

    True if equal, false otherwise.

    Example

    const color = NutrientViewer.Color.RED.equals({ r: 248, g: 36, b: 0 });
    
  • Returns a lighter version of the current Color.

    Parameters

    percentnumber

    The percentage of lightness between 0 and 100.

    Returns

    A Color with the new values.

    Example

    const color = NutrientViewer.Color.RED.lighter(50);
    
  • Returns

    number
  • Modifies the saturation of the Color and returns a new one.

    Parameters

    percentnumber

    The percentage of saturation between 0 and 100.

    Returns

    A Color with the new values.

    Example

    const color = NutrientViewer.Color.RED.saturate(50);
    
  • Parameters

    RGBComponentnumber

    Returns

    number
  • Converts the color to a CSS value (e.g. rgb(255, 0, 0)).

    Returns

    string

    A CSS color value in rgb format.

    Example

    NutrientViewer.Color.RED.toCSSValue(); // => 'rgb(248, 36, 0)'
    
  • Converts the color to a Hex value (e.g. #000000).

    Returns

    string

    A CSS color value in hex format.

    Example

    NutrientViewer.Color.RED.toHex(); // => '#f82400'
    

fromHex

Static
  • Converts a hex color value to a Color instance.

    Parameters

    hexColorstring

    The hex color value to convert.

    Returns

    A Color instance.

Immutable Record API

30
string

The name provided to Record(values, name) can be accessed with displayName.

  • Returns

    IterableIterator<["r" | "g" | "b" | "transparent", number | boolean]>
  • Returns

    this

    See Also

    • Map#asImmutable

  • Returns

    this

    See Also

    • Map#asMutable

  • Returns a new instance of this Record type with all values set to their default values.

    Returns

    this
  • Returns a new instance of this Record type with the value for the specific key set to its default value.

    Type Parameters

    Kextends "r" | "g" | "b" | "transparent"

    Parameters

    keyK

    Returns

    this
  • Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

    If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

    Type Parameters

    Kextends "r" | "g" | "b" | "transparent"

    Parameters

    keyK
    notSetValueunknown
    Optional

    Returns

    { b: number; g: number; r: number; transparent: boolean }[K]
  • Type Parameters

    T

    Parameters

    keystring
    notSetValueT

    Returns

  • Parameters

    keyPathIterable<unknown>

    Returns

    unknown
  • Parameters

    keystring

    Returns

    key is "r" | "g" | "b" | "transparent"
  • Returns

    number
  • Parameters

    keyPathIterable<unknown>

    Returns

    boolean
  • Parameters

    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ b: number; g: number; r: number; transparent: boolean }>
    )[]

    Returns

    this
  • Parameters

    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ b: number; g: number; r: number; transparent: boolean }>
    )[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collectionsunknown[]

    Returns

    this
  • Parameters

    merger(oldVal: unknown, newVal: unknown, key: unknown) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ b: number; g: number; r: number; transparent: boolean }>
    )[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collectionsunknown[]

    Returns

    this
  • Parameters

    merger(
    oldVal: unknown,
    newVal: unknown,
    key: "r" | "g" | "b" | "transparent"
    ) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ b: number; g: number; r: number; transparent: boolean }>
    )[]

    Returns

    this
  • Type Parameters

    Kextends "r" | "g" | "b" | "transparent"

    Parameters

    keyK

    Returns

    this
  • Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Type Parameters

    Kextends "r" | "g" | "b" | "transparent"

    Parameters

    keyK
    value{ b: number; g: number; r: number; transparent: boolean }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    valueunknown

    Returns

    this
  • Deeply converts this Record to equivalent native JavaScript Object.

    Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.

    Returns

    { b: number; g: number; r: number; transparent: boolean }
    • b: number

      The blue value of the color.

      Default Value

      0
    • g: number

      The green value of the color.

      Default Value

      0
    • r: number

      The red value of the color.

      Default Value

      0
    • transparent: boolean

      Transparency of the color.

      Default Value

      false
  • Shallowly converts this Record to equivalent native JavaScript Object.

    Returns

    { b: number; g: number; r: number; transparent: boolean }
    • b: number

      The blue value of the color.

      Default Value

      0
    • g: number

      The green value of the color.

      Default Value

      0
    • r: number

      The red value of the color.

      Default Value

      0
    • transparent: boolean

      Transparency of the color.

      Default Value

      false
  • Shallowly converts this Record to equivalent JavaScript Object.

    Returns

    { b: number; g: number; r: number; transparent: boolean }
    • b: number

      The blue value of the color.

      Default Value

      0
    • g: number

      The green value of the color.

      Default Value

      0
    • r: number

      The red value of the color.

      Default Value

      0
    • transparent: boolean

      Transparency of the color.

      Default Value

      false
  • Returns

    Keyed<"r" | "g" | "b" | "transparent", number | boolean>
  • Type Parameters

    Kextends "r" | "g" | "b" | "transparent"

    Parameters

    keyK
    updater(
    value: { b: number; g: number; r: number; transparent: boolean }[K]
    ) => { b: number; g: number; r: number; transparent: boolean }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown

    Returns

    this
  • Returns

    boolean

    See Also

    • Map#wasAltered

  • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

    Parameters

    mutator(mutable: this) => unknown

    Returns

    this

    See Also

    • Map#withMutations