goog.color
Namespace.Hsl
HSL color representation. An array containing three elements [h, s, l]: h (hue) must be an integer in [0, 360], cyclic. s (saturation) must be a number in [0, 1]. l (lightness) must be a number in [0, 1].
.Hsv
HSV color representation. An array containing three elements [h, s, v]: h (hue) must be an integer in [0, 360], cyclic. s (saturation) must be a number in [0, 1]. v (value/brightness) must be an integer in [0, 255].
.Rgb
RGB color representation. An array containing three elements [r, g, b], each an integer in [0, 255], representing the red, green, and blue components of the color respectively.
goog.color.alpha
Namespace.blend(rgb1, rgb2, factor)
Blend two colors together, using the specified factor to indicate the weight given to the first color
rgb1
{goog.color.Rgb
}
rgb2
{goog.color.Rgb
}
factor
{number
}
goog.color.Rgb
}
.darken(rgb, factor)
Adds black to the specified color, darkening it
rgb
{goog.color.Rgb
}
factor
{number
}
goog.color.Rgb
}
.hexToHsl(hex)
Converts a hex representation of a color to HSL.
hex
{string
}
goog.color.Hsv
}
.hexToHsv(hex)
Converts a hex representation of a color to HSV
hex
{string
}
goog.color.Hsv
}
.hexToRgb(hexColor)
Converts a hex representation of a color to RGB.
hexColor
{string
}
goog.color.Rgb
}
.hexToRgbStyle(hexColor)
Converts a hex representation of a color to RGB.
hexColor
{string
}
string
}
.highContrast(prime, suggestions)
Find the "best" (highest-contrast) of the suggested colors for the prime color. Uses W3C formula for judging readability and visual accessibility: http://www.w3.org/TR/AERT#color-contrast
prime
{goog.color.Rgb
}
suggestions
{Array
.<goog.color.Rgb
>}
goog.color.Rgb
}
.hslArrayToHex(hsl)
Converts from an hsl array to a hex string
hsl
{goog.color.Hsl
}
string
}
.hslArrayToRgb(hsl)
Converts a color from HSL color space to RGB color space.
hsl
{goog.color.Hsl
}
goog.color.Rgb
}
.hslDistance(hsl1, hsl2)
Calculates the Euclidean distance between two color vectors on an HSL sphere. A demo of the sphere can be found at: http://en.wikipedia.org/wiki/HSL_color_space In short, a vector for color (H, S, L) in this system can be expressed as (S*L'*cos(2*PI*H), S*L'*sin(2*PI*H), L), where L' = abs(L - 0.5), and we simply calculate the 1-2 distance using these coordinates
hsl1
{goog.color.Hsl
}
hsl2
{goog.color.Hsl
}
number
}
.hslToHex(h, s, l)
Converts from h,s,l values to a hex string
h
{number
}
s
{number
}
l
{number
}
string
}
.hslToRgb(h, s, l)
Converts a color from HSL color space to RGB color space. Modified from {@link http://www.easyrgb.com/math.html}
h
{number
}
s
{number
}
l
{number
}
goog.color.Rgb
}
.hsvArrayToHex(hsv)
Converts from an HSV array to a hex string
hsv
{goog.color.Hsv
}
string
}
.hsvArrayToRgb(hsv)
Converts an HSV triplet to an RGB array.
hsv
{goog.color.Hsv
}
goog.color.Rgb
}
.hsvToHex(h, s, v)
Converts from h,s,v values to a hex string
h
{number
}
s
{number
}
v
{number
}
string
}
.hsvToRgb(h, s, brightness)
Converts an HSV triplet to an RGB array. V is brightness because b is reserved for blue in RGB.
h
{number
}
s
{number
}
brightness
{number
}
goog.color.Rgb
}
.isValidColor(str)
Determines if the given string can be parsed as a color. {@see goog.color.parse}.
str
{string
}
boolean
}
.lighten(rgb, factor)
Adds white to the specified color, lightening it
rgb
{goog.color.Rgb
}
factor
{number
}
goog.color.Rgb
}
.names
A map that contains a lot of colors that are recognised by various browsers. This list is way larger than the minimal one dictated by W3C. The keys of this map are the lowercase "readable" names of the colors, while the values are the "hex" values.
.normalizeHex(hexColor)
Normalize an hex representation of a color
hexColor
{string
}
string
}
.parse(str)
Parses a color out of a string.
str
{string
}
Object
}
.parseRgb(str)
Parses red, green, blue components out of a valid rgb color string. Throws Error if the color string is invalid.
str
{string
}
goog.color.Rgb
}
.prependHashIfNecessaryHelper(str)
Takes a string a prepends a '#' sign if one doesn't exist. Small helper method for use by goog.color and friends.
str
{string
}
string
}
.prependZeroIfNecessaryHelper(hex)
Takes a hex value and prepends a zero if it's a single digit. Small helper method for use by goog.color and friends.
hex
{string
}
string
}
.rgbArrayToHex(rgb)
Converts a color from RGB to hex representation.
rgb
{goog.color.Rgb
}
string
}
.rgbArrayToHsl(rgb)
Converts a color from RGB color space to HSL color space.
rgb
{goog.color.Rgb
}
goog.color.Hsl
}
.rgbArrayToHsv(rgb)
Converts from an array of RGB values to an array of HSV values.
rgb
{goog.color.Rgb
}
goog.color.Hsv
}
.rgbToHex(r, g, b)
Converts a color from RGB to hex representation.
r
{number
}
g
{number
}
b
{number
}
string
}
.rgbToHsl(r, g, b)
Converts a color from RGB color space to HSL color space. Modified from {@link http://en.wikipedia.org/wiki/HLS_color_space}.
r
{number
}
g
{number
}
b
{number
}
goog.color.Hsl
}
.rgbToHsv(red, green, blue)
Converts from RGB values to an array of HSV values.
red
{number
}
green
{number
}
blue
{number
}
goog.color.Hsv
}