Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Brush

Hierarchy

  • Brush

A Brush holds color information and describes how to draw the inside of a Shape or the stroke of a shape or a TextBlock or the background of any GraphObject.

A Brush must not be modified once it has been assigned to a GraphObject, such as the Shape.fill or TextBlock.stroke or GraphObject.background. However, a Brush may be shared by multiple GraphObjects.

Index

Constructors

  • new Brush(type?: string | EnumValue, init?: Partial<Brush>): Brush
  • Construct a Brush class that holds the given color information.

    Parameters

    • Optional type: string | EnumValue

      Optional, one of the values Brush.Solid, Brush.Linear, Brush.Radial, Brush.Pattern, or a well-formed CSS string describing a solid color brush. No parameter defaults to a Brush.Solid with a color description of 'black'.

    • Optional init: Partial<Brush>

      Optional initialization properties.

    Returns Brush

Properties

  • Gets or sets the color of a solid Brush. The default value is 'black'. The value must be a valid CSS color string.

  • Gets or sets a Map holding all of the color stops used in this gradient, where the key is a number, the fractional distance between 0 and 1 (inclusive), and where the corresponding value is a color string.

    Call addColorStop in order to add color stops to this brush. This property value may be null if no gradient stops have been defined.

  • Gets or sets the radius of a radial brush at the end location. The default value is NaN.

  • Gets or sets the radius of a radial brush at the start location. The default value is 0.

Methods

  • addColorStop(loc: number, color: string): Brush
  • Specify a particular color at a particular fraction of the distance. If the type is Brush.Solid, change the type to Brush.Linear. You should not have duplicate color stop values at the same fractional distance.

    Parameters

    • loc: number

      A number between 0 and 1 (inclusive).

    • color: string

      A valid CSS color string.

    Returns Brush

    this Brush

  • Create a copy of this Brush with the same values.

    Returns Brush

  • darkenBy(fraction?: number, mode?: EnumValue): Brush
  • Modifies all colors within this Brush, darkening them by some fraction.

    since

    1.7

    Parameters

    • Optional fraction: number

      Fraction to darken the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

    • Optional mode: EnumValue

      Color space to use for adjusting. Must be Brush.Lab or Brush.HSL, defaults to Brush.Lab.

    Returns Brush

    This Brush with modified color values.

  • isDark(): boolean
  • This function determines whether this Brush is "dark."

    since

    2.0

    Returns boolean

  • lightenBy(fraction?: number, mode?: EnumValue): Brush
  • Modifies all colors within this Brush, lightening them by some fraction.

    since

    1.7

    Parameters

    • Optional fraction: number

      Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

    • Optional mode: EnumValue

      Color space to use for adjusting. Must be Brush.Lab or Brush.HSL, defaults to Brush.Lab.

    Returns Brush

    This Brush with modified color values.

  • darken(color: string): string
  • This static function takes a color and darkens it by 20% in the Lab color space. This is a convenience function which calls Brush.darkenBy.

    since

    1.7

    Parameters

    • color: string

      A valid CSS color string.

    Returns string

    A CSS string for the darkened color in RGBA.

  • darkenBy(color: string, fraction?: number, mode?: EnumValue): string
  • This static function takes a color and darkens it.

    since

    1.7

    Parameters

    • color: string

      A valid CSS color string

    • Optional fraction: number

      Fraction to darken the color by. Defaults to 0.2, must be between 0 and 1 (inclusive).

    • Optional mode: EnumValue

      Color space to use for adjusting. Must be Brush.Lab or Brush.HSL, defaults to Brush.Lab.

    Returns string

    A CSS string for the darkened color in RGBA or HSLA.

  • This static function takes a color and determines whether it is "dark." Does not account for transparency.

    Example usage:

    myDiagram.nodeTemplate =
    $(go.Node, "Auto",
    $(go.Shape, "RoundedRectangle", { strokeWidth: 0 },
    new go.Binding("fill", "color")),
    $(go.TextBlock,
    { margin: 8 },
    new go.Binding("stroke", "color", function (c) {
    // Dark nodes use white text, light nodes use black text
    return go.Brush.isDark(c) ? "white" : "black";
    }),
    new go.Binding("text", "key")
    )
    );
    since

    2.0

    Parameters

    • color: BrushLike

      A valid CSS color string or a Brush.

    Returns boolean

  • isValidColor(color: string): boolean
  • This static function returns true if a given color string is well-formed for drawing.

    since

    1.7

    Parameters

    • color: string

      A color string to validate.

    Returns boolean

  • lighten(color: string): string
  • This static function takes a color and lightens it by 20% in the Lab color space. This is a convenience function which calls Brush.lightenBy.

    since

    1.7

    Parameters

    • color: string

      A valid CSS color string.

    Returns string

    A CSS string for the lightened color in RGBA.

  • lightenBy(color: string, fraction?: number, mode?: EnumValue): string
  • This static function takes a color and lightens it.

    since

    1.7

    Parameters

    • color: string

      A valid CSS color string.

    • Optional fraction: number

      Fraction to lighten the colors by. Defaults to 0.2, must be between 0 and 1 (inclusive).

    • Optional mode: EnumValue

      Color space to use for adjusting. Must be Brush.Lab or Brush.HSL, defaults to Brush.Lab.

    Returns string

    A CSS string for the lightened color in RGBA or HSLA.

  • mix(color1: string, color2: string, fraction?: number): string
  • This static function takes two colors and mixes them together, using the (optionally) specified amount of the second color.

    since

    2.0

    Parameters

    • color1: string

      A valid CSS color string.

    • color2: string

      Another valid CSS color string to mix.

    • Optional fraction: number

      Fraction specifying how much color2 to mix into color1. Defaults to .5, must be between 0 and 1 (inclusive).

    Returns string

  • randomColor(min?: number, max?: number): string
  • This static function can be used to generate a random color.

    Parameters

    • Optional min: number

      A number between 0 and 255, defaults to 128.

    • Optional max: number

      A number between 0 and 255, defaults to 255.

    Returns string

    A color value in # hexadecimal format.

Constants

For lightening and darkening, used as a color-space value.

For lightening and darkening, used as a color-space value.

For linear gradient brushes, used as the value for Brush.type.

For pattern brushes, used as the value for Brush.type.

For radial gradient brushes, used as the value for Brush.type.

For simple, solid color brushes, used as the value for Brush.type.