File tree 1 file changed +4
-9
lines changed
1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,8 @@ export type ChartColor = keyof typeof chartColors | (string & {})
42
42
export type KV = { key : string ; value : number ; color ?: ChartColor }
43
43
44
44
export function getColor ( ...colors : ( ChartColor | string | null | undefined ) [ ] ) : string {
45
- for ( const color of colors ) {
46
- if ( color != null ) {
47
- return chartColors [ color as keyof typeof chartColors ] || color
48
- }
49
- }
50
- return chartColors . blue
45
+ const color = colors . find ( ( color ) => color != null )
46
+ return chartColors [ color as keyof typeof chartColors ] || color || chartColors . blue
51
47
}
52
48
53
49
const { gray : _gray , ...rest } = chartColors
@@ -59,11 +55,10 @@ export function scheme<T extends { key: string; color?: ChartColor }>(
59
55
) : ( d : T ) => string {
60
56
const map = new Map < string , string > ( )
61
57
62
- for ( let i = 0 ; i < data . length ; i ++ ) {
63
- const d = data [ i ]
58
+ data . forEach ( ( d , i ) => {
64
59
const color = getColor ( d . color , colors ?. [ i % ( colors ?. length ?? 1 ) ] )
65
60
map . set ( d . key , color )
66
- }
61
+ } )
67
62
68
63
return ( d : T ) : string => {
69
64
return map . get ( d . key ) ?? unknown
You can’t perform that action at this time.
0 commit comments