Skip to content

Commit

Permalink
fix(options): fix colorMap validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Sep 7, 2024
1 parent 4da9523 commit ae94970
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/lib/options/__tests__/validate-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,28 @@ test('Tests to validate valueDecimals option', () => {
const invalidOpts = validateOptions(options);
expect(invalidOpts.valueDecimals).toBeUndefined();
});

test('Tests to validate colorMap option', () => {
// Valid options
const options: any = { colorMap: ['blue', 'red'] };
const validatedOpts = validateOptions(options);
expect(validatedOpts.colorMap).toStrictEqual(['blue', 'red']);

// Valid options
const options2: any = {
colorMap: {
India: 'orange',
'United States': 'blue',
},
};
const validatedOpts2 = validateOptions(options2);
expect(validatedOpts2.colorMap).toStrictEqual({
India: 'orange',
'United States': 'blue',
});

// Invalid options
options.colorMap = 'invalid';
const invalidOpts = validateOptions(options);
expect(invalidOpts.colorMap).toBeUndefined();
});
4 changes: 3 additions & 1 deletion src/lib/options/validate-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export function validateOptions(options: Partial<Options>): Partial<Options> {
newOptions.dataTransform = options.dataTransform;
}

validateColorMap(options.colorMap);
if (validateColorMap(options.colorMap)) {
newOptions.colorMap = options.colorMap;
}

return newOptions;
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/gallery/_gallery-demos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export const labelsPosition: ChartProps = {
};

export const labelsPositionNone: ChartProps = {
label: 'Labels Position',
label: 'Hidden Labels',
dataUrl: '/data/population.csv',
dataTransform: (data) =>
data.map((d) => ({
Expand Down

0 comments on commit ae94970

Please sign in to comment.