Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemhosny committed Oct 5, 2024
1 parent 5b78f0e commit b6d08b0
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/lib/options/options.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ export interface Options {

export type TransformFn = (data: Data[] | WideData[]) => Data[] | WideData[];

export type ParamFunction = (currentDate: string, dateSlice: Data[], allDates: string[]) => string;
export type ParamFunction = (currentDate: string, dateSlice: Data[], allDates: string[]) => string;
2 changes: 1 addition & 1 deletion src/lib/options/options.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ export const optionsReducer: Reducer<Options, OptionsAction> = (state = defaultO
default:
return state;
}
};
};
92 changes: 79 additions & 13 deletions src/lib/options/palette.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,85 @@
// color palette src = https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py

const deep = ["#4C72B0", "#DD8452", "#55A868", "#C44E52", "#8172B3", "#937860", "#DA8BC3", "#8C8C8C", "#CCB974", "#64B5CD"];
const muted = ["#4878D0", "#EE854A", "#6ACC64", "#D65F5F", "#956CB4", "#8C613C", "#DC7EC0", "#797979", "#D5BB67", "#82C6E2"];
const pastel = ["#A1C9F4", "#FFB482", "#8DE5A1", "#FF9F9B", "#D0BBFF", "#DEBB9B", "#FAB0E4", "#CFCFCF", "#FFFEA3", "#B9F2F0"];
const bright = ["#023EFF", "#FF7C00", "#1AC938", "#E8000B", "#8B2BE2", "#9F4800", "#F14CC1", "#A3A3A3", "#FFC400", "#00D7FF"];
const dark = ["#001C7F", "#B1400D", "#12711C", "#8C0800", "#591E71", "#592F0D", "#A23582", "#3C3C3C", "#B8850A", "#006374"];
const colorblind = ["#0173B2", "#DE8F05", "#029E73", "#D55E00", "#CC78BC", "#CA9161", "#FBAFE4", "#949494", "#ECE133", "#56B4E9"];
const deep = [
'#4C72B0',
'#DD8452',
'#55A868',
'#C44E52',
'#8172B3',
'#937860',
'#DA8BC3',
'#8C8C8C',
'#CCB974',
'#64B5CD',
];
const muted = [
'#4878D0',
'#EE854A',
'#6ACC64',
'#D65F5F',
'#956CB4',
'#8C613C',
'#DC7EC0',
'#797979',
'#D5BB67',
'#82C6E2',
];
const pastel = [
'#A1C9F4',
'#FFB482',
'#8DE5A1',
'#FF9F9B',
'#D0BBFF',
'#DEBB9B',
'#FAB0E4',
'#CFCFCF',
'#FFFEA3',
'#B9F2F0',
];
const bright = [
'#023EFF',
'#FF7C00',
'#1AC938',
'#E8000B',
'#8B2BE2',
'#9F4800',
'#F14CC1',
'#A3A3A3',
'#FFC400',
'#00D7FF',
];
const dark = [
'#001C7F',
'#B1400D',
'#12711C',
'#8C0800',
'#591E71',
'#592F0D',
'#A23582',
'#3C3C3C',
'#B8850A',
'#006374',
];
const colorblind = [
'#0173B2',
'#DE8F05',
'#029E73',
'#D55E00',
'#CC78BC',
'#CA9161',
'#FBAFE4',
'#949494',
'#ECE133',
'#56B4E9',
];

export const palettes = {
deep,
muted,
pastel,
bright,
dark,
colorblind
deep,
muted,
pastel,
bright,
dark,
colorblind,
} as const;

export type Palette = keyof typeof palettes;
export type Palette = keyof typeof palettes;
9 changes: 5 additions & 4 deletions src/lib/options/validate-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ function validateDataTransform(value: Options['dataTransform'] | undefined): boo
return false;
}

function validateColorMap(value: string[] | { [key: string]: string } | Palette | undefined): boolean {
function validateColorMap(
value: string[] | { [key: string]: string } | Palette | undefined,
): boolean {
if (value === null || value === undefined) return false;

// Check if value is one of the defined Palettes
if (typeof value === 'string')
return Object.keys(palettes).includes(value);
if (typeof value === 'string') return Object.keys(palettes).includes(value);

// Check if color map is array of string
if (is(value, 'array', 'string')) return true;
Expand Down Expand Up @@ -195,4 +196,4 @@ function is(value: any, type: types, arrayType?: types): boolean {

function includes(arr: any[], x: any) {
return x != null && arr.includes(x);
}
}
2 changes: 1 addition & 1 deletion src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function getColor(d: Data, store: Store) {
return colorMap[index];
} else if (typeof colorMap === 'object' && colorMap !== null) {
if (currentValue in colorMap) {
return colorMap[currentValue];
return colorMap[currentValue];
}
}
}
Expand Down

0 comments on commit b6d08b0

Please sign in to comment.