#25583 : added gray method

This commit is contained in:
Hugues Stefanski
2018-05-07 21:38:32 +02:00
parent 22c541a2ba
commit 415972a8af
3 changed files with 43 additions and 25 deletions

View File

@@ -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) {

View File

@@ -1,9 +1,10 @@
// Type definitions for D3JS d3-color module 1.2
// Project: https://github.com/d3/d3-color/
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
// Alex Ford <https://github.com/gustavderdrache>
// Boris Yankov <https://github.com/borisyankov>
// denisname <https://github.com/denisname>
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>,
// Alex Ford <https://github.com/gustavderdrache>,
// Boris Yankov <https://github.com/borisyankov>,
// denisname <https://github.com/denisname>,
// Hugues Stefanski <https://github.com/ledragon>
// 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;

View File

@@ -1,6 +1,6 @@
// Type definitions for D3JS d3-geo module 1.10
// Project: https://github.com/d3/d3-geo/
// Definitions by: Hugues Stefanski <https://github.com/Ledragon>, Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
// Definitions by: Hugues Stefanski <https://github.com/ledragon>, Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3