Skip to content

Commit 04fb98f

Browse files
committed
fix: address comments
1 parent 5f9293f commit 04fb98f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

projects/common/src/color/color-palette.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ describe('Color palette', () => {
4848

4949
test('should generate color for a string as expected from a limited set', () => {
5050
const palette = new ColorPalette(['#fffbeb', '#140300', '#789ab7']);
51-
expect(palette.getColorCombinationForId(2, 'test')).toEqual({
51+
expect(palette.getColorCombinationForId('test', 2)).toEqual({
5252
background: 'rgb(255, 251, 235)',
5353
foreground: '#080909'
5454
});
55+
expect(palette.getColorCombinationForId('test')).toEqual({
56+
background: 'rgb(20, 3, 0)',
57+
foreground: '#FFFFFF'
58+
});
59+
5560
});
5661
});

projects/common/src/color/color-palette.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export class ColorPalette {
1616
return this.forNColors(count).map(color => ({ background: color, foreground: this.getContrast(color) }));
1717
}
1818

19-
public getColorCombinationForId(colorCount: number, id: string): ColorCombination {
20-
return this.getColorCombinations(colorCount)[Math.abs(hashCode(id)) % colorCount];
19+
public getColorCombinationForId(id: string, colorPaletteSize?: number): ColorCombination {
20+
const colorSetSize = colorPaletteSize ?? this.basisColors.length;
21+
22+
return this.getColorCombinations(colorSetSize)[Math.abs(hashCode(id)) % colorSetSize];
2123
}
2224

2325
private getContrast(rgbColorString: string): string {

0 commit comments

Comments
 (0)