Skip to content

Commit

Permalink
feat: add support for custom color palettes
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Jan 11, 2024
1 parent 33a2576 commit d7c1b7b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/tracks/gosling-track/gosling-track-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,19 @@ export class GoslingTrackModel {
break;
case 'color':
case 'stroke':
let interpolate = interpolateViridis;
if (Array.isArray(range) && range.every(d => typeof d === 'string')) {
// Support for custom color palettes, i.e. ["green", "red", "blue"]
this.channelScales[channelKey] = scaleLinear(range as string[]).domain(
scaleLinear(domain as [number, number]).ticks(range.length)
);
break;
}
let interpolated = interpolateViridis;

if (Object.keys(PREDEFINED_COLOR_STR_MAP).includes(range as string)) {
interpolate = PREDEFINED_COLOR_STR_MAP[range as string];
interpolated = PREDEFINED_COLOR_STR_MAP[range as string];
}
this.channelScales[channelKey] = scaleSequential(interpolate).domain(
this.channelScales[channelKey] = scaleSequential(interpolated).domain(
domain as [number, number]
);
break;
Expand Down

0 comments on commit d7c1b7b

Please sign in to comment.