diff --git a/types/d3-color/d3-color-tests.ts b/types/d3-color/d3-color-tests.ts index 47f191073b..2d324e7886 100644 --- a/types/d3-color/d3-color-tests.ts +++ b/types/d3-color/d3-color-tests.ts @@ -36,6 +36,7 @@ cRGB = cRGB.darker(0.2); cRGB = cRGB.rgb(); displayable = cRGB.displayable(); cString = cRGB.toString(); +cString = cRGB.hex(); console.log('Channels = (r : %d, g: %d, b: %d)', cRGB.r, cRGB.g, cRGB.b); console.log('Opacity = %d', cRGB.opacity); @@ -51,6 +52,7 @@ cHSL = cHSL.darker(0.2); cRGB = cHSL.rgb(); displayable = cHSL.displayable(); cString = cHSL.toString(); +cString = cHSL.hex(); console.log('Channels = (h : %d, s: %d, l: %d)', cHSL.h, cHSL.s, cHSL.l); console.log('Opacity = %d', cHSL.opacity); @@ -70,9 +72,14 @@ cLab = cLab.darker(0.2); cRGB = cLab.rgb(); displayable = cLab.displayable(); cString = cLab.toString(); +cString = cLab.hex(); console.log('Channels = (l : %d, a: %d, b: %d)', cLab.l, cLab.a, cLab.b); console.log('Opacity = %d', cLab.opacity); +// Signature tests for Gray +cLab = d3Color.gray(120); +cLab = d3Color.gray(120, 0.5); + // Signature tests for HCL let cHcl: d3Color.HCLColor; @@ -89,9 +96,16 @@ cHcl = cHcl.darker(0.2); cRGB = cHcl.rgb(); displayable = cHcl.displayable(); cString = cHcl.toString(); +cString = cHcl.hex(); console.log('Channels = (h : %d, c: %d, l: %d)', cHcl.h, cHcl.c, cHcl.l); console.log('Opacity = %d', cHcl.opacity); +cHcl = d3Color.lch(40, 50, 120); +cHcl = d3Color.lch(40, 50, 120, 0.5); +cHcl = d3Color.lch('steelblue'); +cHcl = d3Color.lch('rgba(20, 100, 200, 0.5)'); +cHcl = d3Color.lch(c); + // Signature tests for Cubehelix let cCubehelix: d3Color.CubehelixColor; @@ -108,6 +122,7 @@ cCubehelix = cCubehelix.darker(0.2); cRGB = cCubehelix.rgb(); displayable = cCubehelix.displayable(); cString = cCubehelix.toString(); +cString = cCubehelix.hex(); console.log('Channels = (h : %d, s: %d, l: %d)', cCubehelix.h, cCubehelix.s, cCubehelix.l); console.log('Opacity = %d', cCubehelix.opacity); diff --git a/types/d3-color/index.d.ts b/types/d3-color/index.d.ts index 825b82d9c4..56812a6bdb 100644 --- a/types/d3-color/index.d.ts +++ b/types/d3-color/index.d.ts @@ -1,12 +1,13 @@ -// Type definitions for D3JS d3-color module 1.0 +// Type definitions for D3JS d3-color module 1.2 // Project: https://github.com/d3/d3-color/ -// Definitions by: Tom Wanzek -// Alex Ford -// Boris Yankov -// denisname +// Definitions by: Tom Wanzek , +// Alex Ford , +// Boris Yankov , +// denisname , +// Hugues Stefanski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 1.0.3 +// Last module patch version validated against: 1.2.0 // --------------------------------------------------------------------------- // Shared Type Definitions and Interfaces @@ -27,11 +28,21 @@ export interface ColorCommonInstance { brighter(k?: number): this; darker(k?: number): this; rgb(): RGBColor; + /** + * Returns a hexadecimal string representing this color. + * If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255. + */ + hex(): string; } export interface Color { displayable(): boolean; // Note: While this method is used in prototyping for colors of specific colorspaces, it should not be called directly, as 'this.rgb' would not be implemented on Color toString(): string; // Note: While this method is used in prototyping for colors of specific colorspaces, it should not be called directly, as 'this.rgb' would not be implemented on Color + /** + * Returns a hexadecimal string representing this color. + * If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255. + */ + hex(): string; } export interface ColorFactory extends Function { @@ -47,6 +58,9 @@ export interface RGBColor extends Color { opacity: number; brighter(k?: number): this; darker(k?: number): this; + /** + * Returns the RGB equivalent of this color. + */ rgb(): this; } @@ -91,6 +105,11 @@ export interface LabColorFactory extends Function { readonly prototype: LabColor; } +/** + * Constructs a new Lab color with the specified l value and a = b = 0. + */ +export type GrayColorFactory = (l: number, opacity?: number) => LabColor; + export interface HCLColor extends Color { h: number; c: number; @@ -108,6 +127,12 @@ export interface HCLColorFactory extends Function { readonly prototype: HCLColor; } +export interface LCHColorFactory { + (l: number, c: number, h: number, opacity?: number): HCLColor; + (cssColorSpecifier: string): HCLColor; + (color: ColorSpaceObject | ColorCommonInstance): HCLColor; +} + export interface CubehelixColor extends Color { h: number; s: number; @@ -137,6 +162,10 @@ export const hsl: HSLColorFactory; export const lab: LabColorFactory; +export const gray: GrayColorFactory; + export const hcl: HCLColorFactory; +export const lch: LCHColorFactory; + export const cubehelix: CubehelixColorFactory; diff --git a/types/d3-geo/index.d.ts b/types/d3-geo/index.d.ts index a41f67618a..5dd835026d 100644 --- a/types/d3-geo/index.d.ts +++ b/types/d3-geo/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for D3JS d3-geo module 1.10 // Project: https://github.com/d3/d3-geo/ -// Definitions by: Hugues Stefanski , Tom Wanzek , Alex Ford , Boris Yankov +// Definitions by: Hugues Stefanski , Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/d3-hsv/index.d.ts b/types/d3-hsv/index.d.ts index 1728af0874..7452dbcc2b 100644 --- a/types/d3-hsv/index.d.ts +++ b/types/d3-hsv/index.d.ts @@ -68,6 +68,12 @@ export interface HSVColor extends Color { * Returns the RGB equivalent of this color. */ rgb(): RGBColor; + + /** + * Returns a hexadecimal string representing this color. + * If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255. + */ + hex(): string; } export const hsv: HSVColorFactory;