From 415972a8af1e742b23894e706042f59f6276dcb6 Mon Sep 17 00:00:00 2001 From: Hugues Stefanski Date: Mon, 7 May 2018 21:38:32 +0200 Subject: [PATCH] #25583 : added gray method --- types/d3-color/d3-color-tests.ts | 6 ++++ types/d3-color/index.d.ts | 60 +++++++++++++++++++------------- types/d3-geo/index.d.ts | 2 +- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/types/d3-color/d3-color-tests.ts b/types/d3-color/d3-color-tests.ts index 135456a005..d8ea79b637 100644 --- a/types/d3-color/d3-color-tests.ts +++ b/types/d3-color/d3-color-tests.ts @@ -76,6 +76,10 @@ 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; @@ -126,6 +130,8 @@ if (color instanceof d3Color.rgb) { cHSL = color; } else if (color instanceof d3Color.lab) { cLab = color; +} else if (color instanceof d3Color.gray) { + cLab = color; } else if (color instanceof d3Color.hcl) { cHcl = color; } else if (color instanceof d3Color.cubehelix) { diff --git a/types/d3-color/index.d.ts b/types/d3-color/index.d.ts index 1682fe653f..465618b5e8 100644 --- a/types/d3-color/index.d.ts +++ b/types/d3-color/index.d.ts @@ -1,9 +1,10 @@ // 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.2.0 @@ -27,10 +28,10 @@ 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. - */ + /** + * 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; } @@ -78,10 +79,10 @@ export interface HSLColor extends Color { 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. - */ + /** + * 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; } @@ -100,10 +101,10 @@ export interface LabColor extends Color { 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. - */ + /** + * 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; } @@ -114,6 +115,15 @@ export interface LabColorFactory extends Function { readonly prototype: LabColor; } +/** + * Constructs a new Lab color with the specified l value and a = b = 0. + */ +export interface GrayColorFactory extends Function { + (l: number, opacity?: number): LabColor; + readonly prototype: LabColor; + +} + export interface HCLColor extends Color { h: number; c: number; @@ -122,10 +132,10 @@ export interface HCLColor extends Color { 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. - */ + /** + * 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; } @@ -144,10 +154,10 @@ export interface CubehelixColor extends Color { 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. - */ + /** + * 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; } @@ -170,6 +180,8 @@ export const hsl: HSLColorFactory; export const lab: LabColorFactory; +export const gray: GrayColorFactory; + export const hcl: HCLColorFactory; 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