-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
538 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { string2rbg } from '../../../src/utils/color'; | ||
|
||
describe('string2rbg', () => { | ||
test('change css named color string to rgba', () => { | ||
expect(string2rbg('red')).toEqual([255, 0, 0, 1]); | ||
expect(string2rbg('blue')).toEqual([0, 0, 255, 1]); | ||
expect(string2rbg('yellow')).toEqual([255, 255, 0, 1]); | ||
}); | ||
|
||
test('change css hex color string to rgba', () => { | ||
expect(string2rbg('#FFF')).toEqual([255, 255, 255, 1]); | ||
expect(string2rbg('#FFFA')).toEqual([255, 255, 255, 0.6666666666666666]); | ||
expect(string2rbg('#FFFFFFAA')).toEqual([255, 255, 255, 0.6666666666666666]); | ||
}); | ||
|
||
test('change css rgba color string to rgba', () => { | ||
expect(string2rbg('rgb(0, 145, 20)')).toEqual([0, 145, 20, 1]); | ||
expect(string2rbg('rgba(0, 145, 20, 0.5)')).toEqual([0, 145, 20, 0.5]); | ||
}); | ||
|
||
test('change css hsl color string to rgba', () => { | ||
expect(string2rbg('hsl(60, 100%, 20%)')).toEqual([101.99999999999997, 102, 0, 1]); | ||
expect(string2rbg('hsl(60, 0%, 100%)')).toEqual([255, 255, 255, 1]); | ||
expect(string2rbg('hsl(20, 20%, 100%)')).toEqual([255, 255, 255, 1]); | ||
expect(string2rbg('hsl(359, 20%, 100%)')).toEqual([255, 255, 255, 1]); | ||
expect(string2rbg('hsl(420, 20%, 80%)')).toEqual([214.2, 214.2, 193.80000000000004, 1]); | ||
expect(string2rbg('hsla(60, 100%, 20%, 0.4)')).toEqual([101.99999999999997, 102, 0, 0.4]); | ||
}); | ||
|
||
test('change invalid css hsl color string to null', () => { | ||
expect(string2rbg('read')).toBeNull(); | ||
expect(string2rbg('glue')).toBeNull(); | ||
expect(string2rbg('hwb(60, 3%, 60%)')).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Interpolators | ||
|
||
Built-in interpolator factories for continuous scale. | ||
|
||
## Usage | ||
|
||
<a name="createInterpolateNumber" href="#createInterpolateNumber">#</a> **createInterpolateNumber**<i>(a: number, b: number) => Interpolate</i> | ||
|
||
The default interpolate factory for continuous scales which returns a number interpolator. | ||
|
||
```ts | ||
import { Linear, createInterpolateNumber } from '@antv/scale'; | ||
|
||
const x = new Linear({ interpolate: createInterpolateNumber }); | ||
|
||
x.map(0.5); // 0.5; | ||
|
||
createInterpolateNumber(0, 1)(0.5); // 0.5; | ||
``` | ||
|
||
<a name="createInterpolateColor" href="#createInterpolateColor">#</a> **createInterpolateColor**<i>(a: string, b: string) => Interpolate</i> | ||
|
||
The css color interpolate factory for continuous scales which returns a color interpolator. | ||
|
||
```ts | ||
import { Linear, createInterpolateColor } from '@antv/scale'; | ||
|
||
const x = new Linear({ | ||
interpolate: createInterpolateColor, | ||
range: ['red', 'blue'], | ||
}); | ||
|
||
x.map(0.5); // rgba(127.5, 0, 127.5, 1); | ||
|
||
createInterpolateNumber('red', 'blue')(0.5); // rgba(127.5, 0, 127.5, 1); | ||
``` | ||
|
||
<a name="createInterpolateNumber" href="#createInterpolateNumber">#</a> **createInterpolateNumber**<i>(a: number, b: number) => Interpolate</i> | ||
|
||
The value interpolate factory which can interpolate numbers and colors depending on input type. | ||
|
||
```ts | ||
import { Linear, createInterpolateValue } from '@antv/scale'; | ||
|
||
const x = new Linear({ | ||
interpolate: createInterpolateValue, | ||
}); | ||
|
||
x.map(0.5); // 0.5; | ||
createInterpolateValue(0, 1)(0.5); // 0.5; | ||
|
||
x.update({ | ||
range: ['hsl(0, 100%, 50%)', 'hsl(240, 100%, 50%)'], | ||
}); | ||
|
||
x.map(0.5); // rgba(127.5, 0, 127.5, 1) | ||
createInterpolateValue('hsl(0, 100%, 50%)', 'hsl(240, 100%, 50%)')(0.5); // 0.5; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.