File tree Expand file tree Collapse file tree
src/plugins/charts/public/services/colors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717 * under the License.
1818 */
1919
20- import d3 from 'd3' ;
2120import _ from 'lodash' ;
21+ import { hsl } from 'color' ;
2222
2323import { seedColors } from './seed_colors' ;
2424
@@ -49,7 +49,7 @@ const fraction = function (goal: number) {
4949 * If the number is greater than the length of seed colors available,
5050 * new colors are generated up to the value of the input number.
5151 */
52- export function createColorPalette ( num ?: any ) : string [ ] {
52+ export function createColorPalette ( num : number ) : string [ ] {
5353 if ( ! _ . isNumber ( num ) ) {
5454 throw new TypeError ( 'ColorPaletteUtilService expects a number' ) ;
5555 }
@@ -58,7 +58,7 @@ export function createColorPalette(num?: any): string[] {
5858 const seedLength = seedColors . length ;
5959
6060 _ . times ( num - seedLength , function ( i ) {
61- colors . push ( d3 . hsl ( ( fraction ( i + seedLength + 1 ) * 360 + offset ) % 360 , 0.5 , 0.5 ) . toString ( ) ) ;
61+ colors . push ( hsl ( ( fraction ( i + seedLength + 1 ) * 360 + offset ) % 360 , 0.5 , 0.5 ) . hex ( ) ) ;
6262 } ) ;
6363
6464 return colors ;
Original file line number Diff line number Diff line change @@ -37,26 +37,32 @@ describe('Color Palette', () => {
3737
3838 it ( 'should throw an error if input is not a number' , ( ) => {
3939 expect ( ( ) => {
40+ // @ts -expect-error
4041 createColorPalette ( string ) ;
4142 } ) . toThrowError ( ) ;
4243
4344 expect ( ( ) => {
45+ // @ts -expect-error
4446 createColorPalette ( bool ) ;
4547 } ) . toThrowError ( ) ;
4648
4749 expect ( ( ) => {
50+ // @ts -expect-error
4851 createColorPalette ( nullValue ) ;
4952 } ) . toThrowError ( ) ;
5053
5154 expect ( ( ) => {
55+ // @ts -expect-error
5256 createColorPalette ( emptyArr ) ;
5357 } ) . toThrowError ( ) ;
5458
5559 expect ( ( ) => {
60+ // @ts -expect-error
5661 createColorPalette ( emptyObject ) ;
5762 } ) . toThrowError ( ) ;
5863
5964 expect ( ( ) => {
65+ // @ts -expect-error
6066 createColorPalette ( ) ;
6167 } ) . toThrowError ( ) ;
6268 } ) ;
Original file line number Diff line number Diff line change 1818 */
1919
2020import _ from 'lodash' ;
21- import d3 from 'd3 ' ;
21+ import Color from 'color ' ;
2222
2323import { coreMock } from '../../../../../core/public/mocks' ;
2424import { COLOR_MAPPING_SETTING } from '../../../common' ;
@@ -61,7 +61,7 @@ describe('Mapped Colors', () => {
6161 mappedColors . mapKeys ( arr ) ;
6262
6363 const colorValues = _ ( mappedColors . mapping ) . values ( ) ;
64- expect ( colorValues . includes ( seedColors [ 0 ] ) ) . toBe ( false ) ;
64+ expect ( colorValues ) . not . toContain ( seedColors [ 0 ] ) ;
6565 expect ( colorValues . uniq ( ) . size ( ) ) . toBe ( arr . length ) ;
6666 } ) ;
6767
@@ -78,8 +78,8 @@ describe('Mapped Colors', () => {
7878 } ) ;
7979
8080 it ( 'should treat different formats of colors as equal' , ( ) => {
81- const color = d3 . rgb ( seedColors [ 0 ] ) ;
82- const rgb = `rgb(${ color . r } , ${ color . g } , ${ color . b } )` ;
81+ const color = new Color ( seedColors [ 0 ] ) ;
82+ const rgb = `rgb(${ color . red ( ) } , ${ color . green ( ) } , ${ color . blue ( ) } )` ;
8383 const newConfig = { bar : rgb } ;
8484 config . set ( COLOR_MAPPING_SETTING , newConfig ) ;
8585
Original file line number Diff line number Diff line change 1818 */
1919
2020import _ from 'lodash' ;
21- import d3 from 'd3 ' ;
21+ import Color from 'color ' ;
2222
2323import { CoreSetup } from 'kibana/public' ;
2424
2525import { COLOR_MAPPING_SETTING } from '../../../common' ;
2626import { createColorPalette } from './color_palette' ;
2727
28- const standardizeColor = ( color : string ) => d3 . rgb ( color ) . toString ( ) ;
28+ const standardizeColor = ( color : string ) => new Color ( color ) . hex ( ) . toLowerCase ( ) ;
2929
3030/**
3131 * Maintains a lookup table that associates the value (key) with a hex color (value)
You can’t perform that action at this time.
0 commit comments